function fncAbrePopup( file, window, larg, altura)
{
    msgWindow=open(file,window,'directories=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=auto,copyhistory=no,resizable=no,width=' + larg + ',height=' + altura + ',top=0, left=0');
    msgWindow.moveTo(screen.width/2-larg/2,screen.height/2-altura/2-20);   
	msgWindow.focus();
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function instr(texto,c,posInicial)
{
	if (posInicial<0) posInicial=0;				
	for(var i=posInicial; i<texto.length;i++)
	{
		if(texto.charAt(i)==c) return i;
	}
	return -1;
} 

function fncValidaEmail(mail) {
	var ponto = 0;
	var arroba = 0;
	var letra = 0;
	var i = 0;
	var l = mail.length;
	var ch = 0;
	if (l < 10)
		return (false);
	for (i = 0; i < l; i++) {
		ch = mail.charCodeAt(i);
		if (ch == 46) {
			ponto += 1;
		} else {
			if (ch == 64) {
				arroba += 1;
			} else {
				if (((ch >= 65) && (ch <= 90)) || ((ch >= 97) && (ch <= 122))) {
					letra += 1;
				} else {
					if ((ch != 45) && (ch != 95)) {
						if ((ch < 48) || (ch > 57)) {
							return (false);
						}
					}
				}
			}
		}
	}
	if ((arroba == 1) && (ponto > 0) && (letra > 9)) {
		return (true);
	} else {
		return (false);
	}
}

function IsNumeric(sText)
{
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char; 
	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) 
			{
				IsNumber = false;
			}
	}
	return IsNumber;
}

function dateValid(objName) {
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var datefield = objName;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	//strDate = datefield.value;
	strDate = objName;
	if (strDate.length < 1) return true;	
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) return false;
			else {
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
		}
	}
	if (booFound == false)	return false;
	if( parseInt(strYear, 10) > 2020 ) return false;
	intday = parseInt(strDay, 10);
	if (isNaN(intday)) return false;
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) return false;
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) return false;
	if (intMonth>12 || intMonth<1) return false;
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1))
		return false;
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) 
		return false;
	if (intMonth == 2) {
		if (intday < 1) 
			return false;
		if (LeapYear(intYear)) {
			if (intday > 29) return false;
		} else {
			if (intday > 28) return false;
		}
	}
	return true;
}

function LeapYear(intYear) {
	if (intYear % 100 == 0){
		if (intYear % 400 == 0) { return true; }
	}else {
		if ((intYear % 4) == 0) { return true; }
	}
	return false;
}

function fncNumeros(e){
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		tecla = e.keyCode;
	}
	else
	{
		tecla = e.charCode;
	}
	if ((tecla > 47 && tecla < 58) || tecla == 0 || tecla == 13){
		return true;
	}
	else{
			if (tecla != 8){
				return false;
				event.keyCode = 0;
				}
			else{
				return true;
			}
	}
}

function fncPerguntas(id)
{
	if(document.getElementById(id).style.display == 'none')
	{
		document.getElementById(id).style.display = 'block';
	}
	else
	{
		document.getElementById(id).style.display = 'none';
	}
}

function fncValidarContato()
{
	form = document.getElementById('frm_contato');	
	if(trim(form.nm_contato.value) == '')
	{
		alert('Por favor, preencher o campo Nome.');
		form.nm_contato.focus();
		return false;	
	}
	
	if(!fncValidaEmail(form.dc_email.value))
	{
		alert('Por favor, preencher um e-mail válido.');
		form.dc_email.focus();
		return false;	
	}
	
	if(trim(form.dc_mensagem.value) == '')
	{
		alert('Por favor, preencher a mensagem.');
		form.dc_mensagem.focus();
		return false;	
	}
	
	if(form.dc_mensagem.value.length > 2000)
	{
		alert('Por favor, preencher a mensagem com menos de 2000 caracteres.\nNo momento a mensagem tem '+ form.dc_mensagem.value.length +' caracteres.');
		form.dc_mensagem.focus();
		return false;	
	}
}

function ValidaNewsletter(){
	if(!fncValidaEmail(newsletter.nm_participante.value))
	{
		alert('Por favor, preencher um e-mail válido.');
		newsletter.nm_participante.focus();
		return false;	
	}
}

function CadastraNewsletter(){
	if(frm_newsletter.nm_contato.value == "")
	{
		alert('Por favor, informe seu nome.');
		frm_newsletter.nm_contato.focus();
		return false;	
	}
		
	if(!fncValidaEmail(frm_newsletter.dc_email.value))
	{
		alert('Por favor, preencher um e-mail válido.');
		frm_newsletter.dc_email.focus();
		return false;	
	}
}


