function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function fncAbrePopup( url, win, width, height, opt)
{
	var leftPos = (screen.availWidth - width) / 2;
	var topPos = (screen.availHeight - height) / 2;
	opt += 'width=' + width + ',height=' + height + ',left=' + leftPos + ',top=' + topPos;
	popUpWindow = window.open(url, win, opt);
	popUpWindow.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 fncValidarCadastro()
{
	form = document.getElementById('frm_cadastro');
	if(trim(form.nm_pessoa.value) == "")
	{
		alert('Por favor, prencha o seu nome.');
		form.nm_pessoa.focus();
		return false;
	}
	if(!fncValidaEmail(trim(form.ds_email.value)))
	{
		alert('Por favor, prencha o seu e-mail corretamente.');
		form.ds_email.focus();
		return false;
	}
	if(!dateValid(form.dt_dia.value+"/"+form.dt_mes.value+"/"+form.dt_ano.value))
	{
		alert('Por favor, prencha a sua data de nascimento corretamente.');
		form.dt_dia.focus();
		return false;
	}
	if((trim(form.ds_tel_res_ddd.value) == "" && trim(form.ds_tel_res_num.value) != "") || (trim(form.ds_tel_res_ddd.value) != "" && trim(form.ds_tel_res_num.value) == ""))
	{
		alert('Por favor, prencha o seu ddd/telefone residencial corretamente.');
		form.ds_tel_res_ddd.focus();
		return false;
	}
	if((trim(form.ds_tel_res_ddd.value) != "" && trim(form.ds_tel_res_num.value) != ""))
	{
		if(form.ds_tel_res_ddd.value.length < 2 || form.ds_tel_res_num.value.length < 8)
		{
			alert('Por favor, prencha o seu ddd/telefone residencial corretamente.');
			form.ds_tel_res_ddd.focus();
			return false;
		}	
	}
	if((trim(form.ds_cel_ddd.value) == "" && trim(form.ds_cel_num.value) != "") || (trim(form.ds_cel_ddd.value) != "" && trim(form.ds_cel_num.value) == ""))
	{
		alert('Por favor, prencha o seu ddd/celular corretamente.');
		form.ds_cel_ddd.focus();
		return false;
	}
	if((trim(form.ds_cel_ddd.value) != "" && trim(form.ds_cel_num.value) != ""))
	{
		if(form.ds_cel_ddd.value.length < 2 || form.ds_cel_num.value.length < 8)
		{
			alert('Por favor, prencha o seu ddd/celular corretamente.');
			form.ds_cel_ddd.focus();
			return false;
		}	
	}
	if((trim(form.ds_tel_com_ddd.value) == "" && trim(form.ds_tel_com_num.value) != "") || (trim(form.ds_tel_com_ddd.value) != "" && trim(form.ds_tel_com_num.value) == ""))
	{
		alert('Por favor, prencha o seu ddd/telefone comercial corretamente.');
		form.ds_tel_com_ddd.focus();
		return false;
	}
	if((trim(form.ds_tel_com_ddd.value) != "" && trim(form.ds_tel_com_num.value) != ""))
	{
		if(form.ds_tel_com_ddd.value.length < 2 || form.ds_tel_com_num.value.length < 8)
		{
			alert('Por favor, prencha o seu ddd/telefone comercial corretamente.');
			form.ds_tel_com_ddd.focus();
			return false;
		}	
	}
}

function fncValidarFaleConosco()
{
	form = document.getElementById('frm_faleconosco');
	if(trim(form.nm_pessoa.value) == "")
	{
		alert('Por favor, prencha o seu nome.');
		form.nm_pessoa.focus();
		return false;
	}
	if(!fncValidaEmail(trim(form.ds_email.value)))
	{
		alert('Por favor, prencha o seu e-mail corretamente.');
		form.ds_email.focus();
		return false;
	}
	if((trim(form.ds_tel_res_ddd.value) == "" && trim(form.ds_tel_res_num.value) != "") || (trim(form.ds_tel_res_ddd.value) != "" && trim(form.ds_tel_res_num.value) == ""))
	{
		alert('Por favor, prencha o seu ddd/telefone residencial corretamente.');
		form.ds_tel_res_ddd.focus();
		return false;
	}
	if((trim(form.ds_tel_res_ddd.value) != "" && trim(form.ds_tel_res_num.value) != ""))
	{
		if(form.ds_tel_res_ddd.value.length < 2 || form.ds_tel_res_num.value.length < 8)
		{
			alert('Por favor, prencha o seu ddd/telefone residencial corretamente.');
			form.ds_tel_res_ddd.focus();
			return false;
		}	
	}
	if((trim(form.ds_cel_ddd.value) == "" && trim(form.ds_cel_num.value) != "") || (trim(form.ds_cel_ddd.value) != "" && trim(form.ds_cel_num.value) == ""))
	{
		alert('Por favor, prencha o seu ddd/celular corretamente.');
		form.ds_cel_ddd.focus();
		return false;
	}
	if((trim(form.ds_cel_ddd.value) != "" && trim(form.ds_cel_num.value) != ""))
	{
		if(form.ds_cel_ddd.value.length < 2 || form.ds_cel_num.value.length < 8)
		{
			alert('Por favor, prencha o seu ddd/celular corretamente.');
			form.ds_cel_ddd.focus();
			return false;
		}	
	}
	if((trim(form.ds_tel_com_ddd.value) == "" && trim(form.ds_tel_com_num.value) != "") || (trim(form.ds_tel_com_ddd.value) != "" && trim(form.ds_tel_com_num.value) == ""))
	{
		alert('Por favor, prencha o seu ddd/telefone comercial corretamente.');
		form.ds_tel_com_ddd.focus();
		return false;
	}
	if((trim(form.ds_tel_com_ddd.value) != "" && trim(form.ds_tel_com_num.value) != ""))
	{
		if(form.ds_tel_com_ddd.value.length < 2 || form.ds_tel_com_num.value.length < 8)
		{
			alert('Por favor, prencha o seu ddd/telefone comercial corretamente.');
			form.ds_tel_com_ddd.focus();
			return false;
		}	
	}
}