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 fncHomeAlinhaDestaques()
{
	destaque 		= document.getElementById('td_destaque').offsetHeight;
	conhecimento 	= document.getElementById('td_conhecimento').offsetHeight;
	solucoes		= document.getElementById('td_solucoes').offsetHeight;
	blog			= document.getElementById('td_blog').offsetHeight;
	//alert('Destaque: ' + destaque + '\nConhecimento: ' + conhecimento + '\nSoluções: ' + solucoes + '\nBlog: ' + blog);
	if(conhecimento < destaque)
		document.getElementById('td_conhecimento_ajuste').style.height = destaque - conhecimento + 13 + 'px';
	if(solucoes < destaque)
		document.getElementById('td_solucoes_ajuste').style.height = destaque - solucoes + 1 + 'px';
	if(blog < destaque)
		document.getElementById('td_blog_ajuste').style.height = destaque - blog + 13 + 'px';
}

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=1, left=1');
    msgWindow.moveTo(screen.width/2-larg/2,screen.height/2-altura/2-20);   
	msgWindow.focus();
}

function fncAbrePopup2( file, window, larg, altura)
{
    msgWindow=open(file,window,'directories=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=no,width=' + larg + ',height=' + altura + ',top=1, left=1');
    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){
	//alert(e.keyCode + ' - ' + e.charCode);
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		tecla = e.keyCode;
	}
	else
	{
		tecla = e.charCode;
	}
	if ((tecla > 47 && tecla < 58) || ((tecla >= 96 && tecla <= 105)) || tecla == 9 || 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 opina()
{
  fncAbrePopup2("","Enquete",320,400);
}
function result(x,y,opr)
{
	if(x==54)
	{ 
		h = 460; 
	}
	else
	{
		h = 400; 
	}
	fncAbrePopup2("/templates/opiniao/resultados.asp?cd_pesquisa_veiculacao=" + x + "&cd_pesquisa=" + y + "&opr=" + opr,'Resultados',320,h);
}

function fncFecharPopupDHTML()
{
	document.getElementById('lr_popup_dhtml').style.visibility = 'hidden';
}

function fncAbrirPopupDHTML()
{
	document.getElementById('lr_popup_dhtml').style.visibility = 'visible';
}

function fncCentralizaPopupDHTML()
{
	if(navigator.appName == "Netscape")
	{
	 	if(document.body.clientWidth < 673)
		{
			document.getElementById('lr_popup_dhtml').style.left = '208px';
		}
		else
		{
			document.getElementById('lr_popup_dhtml').style.left = 208 - 3 + (document.body.clientWidth - 752)/2 + 'px';
		}
	}
	if(navigator.appName == "Microsoft Internet Explorer")
	{
	 	document.getElementById('lr_popup_dhtml').style.left = 208 - 3 + (document.body.clientWidth - 752)/2 + 'px';
	}
	fncAbrirPopupDHTML();
}

function validaNewsletter()
{
	document.getElementById('frm_newsletter_cadastra').email.value = document.getElementById('frm_newsletter_cadastra').email.value.toLowerCase();
	
	if(document.getElementById('frm_newsletter_cadastra').nome.value == "")
	{
		alert('Preencha seu nome.');
		document.getElementById('frm_newsletter_cadastra').nome.focus();
		return false;
	}
	if(!fncValidaEmail(document.getElementById('frm_newsletter_cadastra').email.value))
	{
		alert('Preencha seu e-mail corretamente.');
		document.getElementById('frm_newsletter_cadastra').email.focus();
		return false;
	}
	if(!dateValid(document.getElementById('frm_newsletter_cadastra').dia.value+"/"+document.getElementById('frm_newsletter_cadastra').mes.value+"/"+document.getElementById('frm_newsletter_cadastra').ano.value))
	{
		alert('Por favor, informe a sua data de nascimento correta.');
		document.getElementById('frm_newsletter_cadastra').dia.focus();
		return false;
	}
	if(document.getElementById('frm_newsletter_cadastra').uf.value == "")
	{
		alert('Selecione seu estado');
		document.getElementById('frm_newsletter_cadastra').uf.focus();
		return false;
	}
	if(document.getElementById('frm_newsletter_cadastra').cidade.value == "")
	{
		alert('Preencha a sua cidade.');
		document.getElementById('frm_newsletter_cadastra').cidade.focus();
		return false;
	}
}


function validaLoginTopo()
{
	formLoginTopo = document.getElementById('loginTopo');
	
	if(!fncValidaEmail(trim(formLoginTopo.dc_email.value))) 
	{
		alert('Por favor, preencha seu e-mail corretamente.');
		formLoginTopo.dc_email.focus();
		return false;	
	}
	
	if(trim(formLoginTopo.dc_senha.value) == '')
	{
		alert('Por favor, preencha sua senha.');
		formLoginTopo.dc_senha.focus();
		return false;		
	}
	
	/*formLoginTopo.dc_email.readonly = 'readonly';
	formLoginTopo.dc_email.style.color = '#CCCCCC';
	formLoginTopo.dc_senha.readonly = 'readonly';
	formLoginTopo.dc_senha.style.color = '#CCCCCC';*/
	
	formLoginTopo.url.value = window.location;
	
	return true;
	
}