// --- Favoritos
function add_favorites() {
	try
	{
		window.external.AddFavorite(location.href, document.title);
	}
	catch (e)
	{
		alert("O seu browser não suporta essa funcionalidade, deve efectuar o bookmark manualmente.");
	}
}

// --- Impressão
function printThisPage() {
	document.getElementById("topo_menu").style.display="none";
	document.getElementById("topo_pesquisa").style.display="none";
	document.getElementById("lado_tabela").style.display="none";
	document.getElementById("fundo_banners").style.display="none";
	document.getElementById("fundo_tabela").style.display="none";

	self.print();

	document.getElementById("topo_menu").style.display="";
	document.getElementById("topo_pesquisa").style.display="";
	document.getElementById("lado_tabela").style.display="";
	document.getElementById("fundo_banners").style.display="";
	document.getElementById("fundo_tabela").style.display="";
}

// --- Forum - Mensagem
function form_message_submit() {
	nome = document.form1.nome.value;
	email = document.form1.email.value;
	titulo = document.form1.titulo.value;
	mensagem = document.form1.mensagem.value;

	if (nome=="" || email=="" || titulo=="" || mensagem=="") {
		alert("Todos os campos são de preenchimento obrigatório.");
	    return;
	} else
		document.form1.submit();
} 

// --- Pesquisa
function pesquisa() {
	texto = document.pesquisa.texto.value;
	if (texto.length < 3) {
	    alert("Para efectuar uma pesquisa necessita de inserir pelo menos uma palavra de 3 caracteres.");
	} else {
	   document.forms["pesquisa"].submit();
	}
}

// ---- ImageOver wrap
function hsrc_init() {
  if (!document.getElementById) return
  var imgOriginSrc;
  var imgTemp = new Array();
  var imgarr = document.getElementsByTagName('img');
  for (var i = 0; i < imgarr.length; i++) {
    if (imgarr[i].getAttribute('hsrc')) {
        imgTemp[i] = new Image();
        imgTemp[i].src = imgarr[i].getAttribute('hsrc');
        imgarr[i].onmouseover = function() {
            imgOriginSrc = this.getAttribute('src');
            this.setAttribute('src',this.getAttribute('hsrc'))
        }
        imgarr[i].onmouseout = function() {
            this.setAttribute('src',imgOriginSrc)
        }
    }
  }
}

// -- Socio registo
function socio_validar() {
	tf = document.forms["form1"];
	tf.submit();

	if ( tf.comercial.value  == ""  ) {
		alert("Nome comercial é campo obrigatorio.");
		return;
	}
	if ( tf.firma.value  == ""  ) {
		alert("Nome da Firma é campo obrigatorio.");
		return;
	}
	if ( tf.responsavel.value  == ""  ) {
		alert("Nome do responsavel é campo obrigatorio.");
		return;
	}
	if ( tf.morada.value  == ""  ) {
		alert("Morada é campo obrigatorio.");
		return;
	}
	if ( tf.codigo_postal.value  == ""  ) {
		alert("Codigo Postal é campo obrigatorio.");
		return;
	}
	if ( tf.telefone.value  == ""  ) {
		alert("Telefone é campo obrigatorio.");
		return;
	}
	if ( tf.fax.value  == ""  ) {
		alert("Fax é campo obrigatorio.");
		return;
	}
	if ( tf.email.value  == ""  ) {
		alert("E-mail é campo obrigatorio.");
		return;
	}
	if ( tf.contribuinte.value  == ""  ) {
		alert("Contribuinte é campo obrigatorio.");
		return;
	}
	if ( tf.capital_social.value  == ""  ) {
		alert("Capital Social é campo obrigatorio.");
		return;
	}
	if ( tf.alvara.value  == ""  ) {
		alert("Alvara é campo obrigatorio.");
		return;
	}

	tf.submit();
}

function checkForm( obj, args ) {
	
	var form_size = args.length;
	var item_name = "";
	var item_value = "";

	var emailRegex  = /^[^@]+@[^@]+.[a-z]{2,}$/i;

	for (i=0; i<form_size;i++ )
	{
		item_name = args[i].name ? args[i].name : args[i].id;
		item_value = args[i].value;

		if ( item_value == '' ) {
			args[i].className = 'form_erro';
			return false;
		} else {
			args[i].className = 'form_campo';
		}

		// Validar email
		if ( item_name.indexOf("email") > 0 )
		{
			if ( item_value.search( emailRegex ) == -1) {
				args[i].className = 'form_erro';
				return false;
			}
		}
	}

	return true;
}

// ------------------ Download da imagem no tamanho maximo
function get_image( imagem ) {
	var winl = screen.width;
	var wint =screen.height;

	win=window.open("image.php?fx="+imagem, 'janela', "top=0,left=0,scrollbars=0,width="+wint+",height="+winl);	
	if ( typeof(window.focus) != "undefined" ) {
	    win.focus();
	}
}

function resize_window(obj) {
	comp	= obj.width < 400 ? 400 : obj.width;
	altura	= obj.height < 400 ? 400 : obj.height;
	
	window.resizeTo(comp, altura);
}

// _--------------------- chat
function open_chat_old( ) {
	var winl = ( screen.width - 700 ) / 2;
	var wint =( screen.height - 500 ) / 2;

	win=window.open("chat/index.php", 'janelachat', "width=700,height=500,scrollbars=0,top="+wint+",left="+winl);	
	if ( typeof(window.focus) != "undefined" ) {
	    win.focus();
	}
}