function readCookie(name) {
	var namearg = name + "=";
	var nlen = namearg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + nlen;
		if (document.cookie.substring(i, j) == namearg) {
			var endpos = document.cookie.indexOf (";", j);
			if (endpos == -1) endpos = document.cookie.length;
			return unescape(document.cookie.substring(j, endpos));
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return 0;
}

function writeCookie(name, value, expiry) {
	var expdate = new Date();
	if(expiry) { //horas
		expdate.setTime(expdate.getTime() + 1000 * 60 * 60 * expiry);
		document.cookie = name + "=" + escape(value) + "; expires=" + expdate.toGMTString();
	}
	else {
		document.cookie = name + "=" + escape(value);
	}
}

function OpenWindowRede()
{
	var w = window.open('http://www.fund-luso-brasileira.org/RedePesquisa/Default.aspx?Tag=SEARCH_NET','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=650,height=610,resizable=0,top=100,left=100');
}

function deleteCookie(name) {
   if (readCookie(name)) {
     document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
   }
}


function Votar(CdSondagem)
{
	var url, CookieName;


	CookieName = 'CCILBSondagem' + CdSondagem
	if(stateChecker(document.frmSondagem.SondagemResposta) != -1)
	{
		if(readCookie(CookieName) == 1)
			url = "/sondagem.asp?CdSondagem=" + CdSondagem + "&Somar=0&Try=1&CdResposta=" + stateChecker(document.frmSondagem.SondagemResposta)
		else
		{
			url = "/sondagem.asp?CdSondagem=" + CdSondagem + "&Somar=1&Try=0&CdResposta=" + stateChecker(document.frmSondagem.SondagemResposta)
			writeCookie(CookieName, 1, 100)
		}
		window.open(url, "sondagem", "screenX=150,screenY=150,left=150,top=150,width=400,height=250,resizable=0,scrollbars=1,dependent=0")
	}
}

function Resultados(CdSondagem)
{
	var url, CookieName;

	url = "/sondagem.asp?CdSondagem=" + CdSondagem
	window.open(url, "sondagem", "screenX=150,screenY=150,left=150,top=150,width=400,height=250,resizable=0,scrollbars=1,dependent=0")
}


function stateChecker(Objecto) 
{   

	for (i=0;i< Objecto.length;i++) 
		if (Objecto[i].checked) 
			return Objecto[i].value;

	return -1;
}

function EnviarContacto() 
{   
	if(document.frmContacto.Nome.value == '')
	{
		alert('Por favor preencha o seu nome');
		return;
	}

	if(document.frmContacto.EMail.value == '')
	{
		alert('Por favor preencha o seu EMail');
		return;
	}
	document.frmContacto.submit();
}

function EnviarInscricao() 
{   

	if(document.frmInscricao.Empresa.value == '')
	{
		alert('Por favor preencha o nome da empresa');
		return;
	}

	if(document.frmInscricao.Morada.value == '')
	{
		alert('Por favor preencha a morada');
		return;
	}

	if(document.frmInscricao.Morada.value == '')
	{
		alert('Por favor preencha a morada');
		return;
	}
	if(document.frmInscricao.CodPostal4D.value == '')
	{
		alert('Por favor preencha o código postal');
		return;
	}
	if(document.frmInscricao.Localidade.value == '')
	{
		alert('Por favor preencha a localidade');
		return;
	}
	if(document.frmInscricao.Localidade.value == '')
	{
		alert('Por favor preencha a localidade');
		return;
	}
	if(document.frmInscricao.Pais.value == '')
	{
		alert('Por favor preencha o país');
		return;
	}
	if(document.frmInscricao.Telefone.value == '')
	{
		alert('Por favor preencha o telefone');
		return;
	}
	if(document.frmInscricao.EMail.value == '')
	{
		alert('Por favor preencha o e-mail');
		return;
	}
	if(document.frmInscricao.NIF.value == '')
	{
		alert('Por favor preencha o número de contribuinte');
		return;
	}

	document.frmInscricao.submit();
}

function Login()
{
	if(document.frmLogin.Username.value == '' || document.frmLogin.Password.value == '')
	{
		alert('Por favor digite o seu login e password')
		return;
	}	
	document.frmLogin.submit();
}

function Pesquisar()
{
	if(document.frmSearch.search.value != '' && document.frmSearch.search.value != 'Pesquisa')
		document.frmSearch.submit();
}

function NewsletterSubmit()
{
	if(document.frmNewsletter.email.value != '' && document.frmNewsletter.email.value != 'o seu e-mail')
	{
		if(emailCheck(document.frmNewsletter.email.value))
			document.frmNewsletter.submit();
		else
			alert('Endereço de email inválido');
	}
}

function NextPageAssociado()
{ 
	document.frmAssociado.Pagina.value = eval(document.frmAssociado.Pagina.value + "+ 1");
	document.frmAssociado.submit();
}

function PreviousPageAssociado()
{ 
	document.frmAssociado.Pagina.value = eval(document.frmAssociado.Pagina.value + "- 1");
	document.frmAssociado.submit();
}

function emailCheck (emailStr) 
{ 
	var checkTLD=0; 
	var knownDomsPat=/ ^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|pt|br)$/; 
	var emailPat=/^(.+)@(.+)$/; 
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]"; 
	var validChars="\[^\\s" + specialChars + "\]"; 
	var quotedUser="(\"[^\"]*\")"; 
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/; 
	var atom=validChars + '+'; 
	var word="(" + atom + "|" + quotedUser + ")"; 
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); 
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$"); 
	var matchArray=emailStr.match(emailPat); 
	if (matchArray==null) return false; 
	return true
}

function Print()
{ 
	window.open(window.location + "&Print=1", "", "screenX=150,screenY=150,left=150,top=150,width=700,height=400,resizable=0,scrollbars=1,dependent=0")
}

function SendLink(CdC)
{
	var url = escape(window.location);
	
	window.location = '/pag/enviar.asp?CdC=' + CdC + '&Url=' + url
}

function checklink()
{
	if(document.frmSend.nomeE.value == '' || document.frmSend.nomeD.value == '' || document.frmSend.emailE.value == '' || document.frmSend.emailE.value == '' || document.frmSend.msg.value == '')
		alert('Por favor preencha todos os dados')
	else	document.frmSend.submit();
}


function PesquisaAssociado()
{
	document.frmAssociado.Pagina.value = 1;
	document.frmAssociado.submit();
}

function EnviarBolsa() 
{   

	if(document.frmInscricao.Empresa.value == '')
	{
		alert('Por favor preencha o nome da empresa');
		return;
	}

	if(document.frmInscricao.Morada.value == '')
	{
		alert('Por favor preencha a morada');
		return;
	}

	if(document.frmInscricao.Morada.value == '')
	{
		alert('Por favor preencha a morada');
		return;
	}
	if(document.frmInscricao.CodPostal4D.value == '')
	{
		alert('Por favor preencha o código postal');
		return;
	}
	if(document.frmInscricao.Localidade.value == '')
	{
		alert('Por favor preencha a localidade');
		return;
	}
	if(document.frmInscricao.Localidade.value == '')
	{
		alert('Por favor preencha a localidade');
		return;
	}
	if(document.frmInscricao.Pais.value == '')
	{
		alert('Por favor preencha o país');
		return;
	}
	if(document.frmInscricao.Telefone.value == '')
	{
		alert('Por favor preencha o telefone');
		return;
	}
	if(document.frmInscricao.EMail.value == '')
	{
		alert('Por favor preencha o e-mail');
		return;
	}

	document.frmInscricao.submit();
}
