function submitEnquete(){
	//alert('oi');
	width = (navegador() == 'ie') ? 300 : 300;
		height = (navegador() == 'ie') ? 270 : 280;
		janela = window.open('','janela','width='+width+',height='+height);
		if(!janela){
			
			alert('Não foi possível abrir a janela do resultado da enquete.\nVerifique se você não possui algum bloeuqador de pop-up e tente novamente.');
	
			
		} else {

			document.frm_enquete.action = "enquete.php";
			document.frm_enquete.method = "POST";
			document.frm_enquete.target = "janela";
			document.frm_enquete.submit();
	
		}

}

function submitBusca(){

	document.frm_busca.action = "busca.php";
	document.frm_busca.method = "GET";
	document.frm_busca.submit();

}

function trim(val){
	return( val.replace( /^\s+|\s+$/gi, "" ).replace( /\s{2,}/gi, " " ) )
}

function navegador() {
	
	var browserName=navigator.appName; 
	if (browserName=="Netscape")
	 browser = "netscape";
	else { 
	 if (browserName=="Microsoft Internet Explorer")
	  browser = "ie";
	 else
		browser = "outro";
	}
	return browser;

}

function submitNewsletter(){

	// Faz a validação dos campos
	if(document.frm_newsletter.nome_newsletter_mail.value == '' || document.frm_newsletter.email_newsletter_mail.value == ''){
		
		alert("Preencha os campos do cadastro corretamente.");
		
	} else {
	
		width = (navegador() == 'ie') ? 300 : 300;
		height = (navegador() == 'ie') ? 170 : 150;
		janela = window.open('','janela','width='+width+',height='+height);
		if(!janela){
			
			alert('Não foi possível abrir a janela de inscrição na newsletter.\nVerifique se você não possui algum bloeuqador de pop-up e tente novamente.');
	
			
		} else {
			
			document.frm_newsletter.action = "newsletter.php?acao=cadastra";
			document.frm_newsletter.target = "janela";
			document.frm_newsletter.method = "POST";
			document.frm_newsletter.submit();
			
			document.frm_newsletter.nome_newsletter_mail.value = '';
			document.frm_newsletter.email_newsletter_mail.value = '';
		}
		
	}
	
}

  function mascara(Formulario, Campo, Mascara, evtKeyPress){
	
	var i, j, Valor, TamanhoCampo, TamanhoMascara, MascaraOk, Codigo, Tecla;
	
	Tecla = KeyCode(evtKeyPress);
	
	if (Tecla==8) return true;
	
 	Valor = Formulario[Campo].value; 
 	Valor = Valor.toString().replace( ':', '' );
 	Valor = Valor.toString().replace( '-', '' ); 
 	Valor = Valor.toString().replace( '-', '' ); 
 	Valor = Valor.toString().replace( '.', '' ); 
 	Valor = Valor.toString().replace( '.', '' ); 
 	Valor = Valor.toString().replace( '/', '' ); 
 	Valor = Valor.toString().replace( '/', '' ); 
 	Valor = Valor.toString().replace( '(', '' ); 
 	Valor = Valor.toString().replace( '(', '' ); 
 	Valor = Valor.toString().replace( ')', '' ); 
 	Valor = Valor.toString().replace( ')', '' ); 
 	Valor = Valor.toString().replace( ' ', '' ); 
 	Valor = Valor.toString().replace( ' ', '' ); 
 	TamanhoCampo = Valor.length; 
 	TamanhoMascara = Mascara.length; 
 	
 	i = 0; j = 0; Codigo = ''; 
 	TamanhoMascara = TamanhoCampo; 
 	
 	while ( i <= TamanhoMascara ){
 	
 		MascaraOk = ((Mascara.charAt(i) == '-') || 
 		             (Mascara.charAt(i) == '.') || 
 		             (Mascara.charAt(i) == '/') || 
 		             (Mascara.charAt(i) == '(') || 
 		             (Mascara.charAt(i) == ')') || 
 		             (Mascara.charAt(i) == ':') ||
 		             (Mascara.charAt(i) == ' ')
 		            );
 		            
 		if (MascaraOk){     
 			Codigo += Mascara.charAt(i);          
 			TamanhoMascara++;
 		} 
 		else {
 			Codigo += Valor.charAt(j);
 			j++;
 		}   
 		i++;
 	}
 	
 	Formulario[Campo].value = Codigo;

 	if (Tecla != 8){
 		if (Mascara.charAt(i-1) == "9" && Mascara.length > Valor.length){
 			return ((Tecla > 47) && (Tecla < 58));
 		}else{
 			return true;
 		}
 	}else{
		return true;
 	}
 }
 
 function KeyCode(e)
 {
 	if(document.all){
	    return e.keyCode;
	}
    else if(navigator.appName == 'Netscape'){
    	return e.which;
    }
 }
 
function FormataMoeda(fld, e) { 
	//alert("pqp d js!!!");
	var milSep = ".";
	var decSep = ",";
	var sep = 0; 
	var key = ''; 
	var i = j = 0; 
	var len = len2 = 0; 
	var strCheck = '0123456789'; 
	var aux = aux2 = ''; 
	var whichCode = (window.Event) ? e.which : e.keyCode; 
	
    // Apenas números, backspace ou delete
    if((whichCode > 47 && whichCode < 58) ||
        whichCode == 0 ||
        whichCode == 8)
    {
	
//	if (whichCode == 13) return true;  
		key = String.fromCharCode(whichCode);
//	if (strCheck.indexOf(key) == -1) return false;  
		len = fld.value.length; 
	
	//alert("fld.value.length="+fld.value.length+" fld.size="+fld.size);
		
    if(fld.value.length == fld.size){
       fld.value = fld.value.charAt(2) + fld.value.charAt(1) + fld.value.charAt(3) + 
    				fld.value.charAt(4) + fld.value.charAt(6) + fld.value.charAt(5) +
    				fld.value.charAt(7) + fld.value.charAt(8) + key;
        //fld.value = '';
	//alert("entrou no if");
	}
	else if (fld.value.length < fld.size) {
		//alert("entrou no else");
		for(i = 0; i < len; i++) 
			if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break; 
		aux = ''; 
		for(; i < len; i++) 
			if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i); 
		aux += key; 
		len = aux.length; 
		if (len == 0) fld.value = ''; 
		if (len == 1) fld.value = '0'+ decSep + '0' + aux; 
		if (len == 2) fld.value = '0'+ decSep + aux; 
		if (len > 2) { 
		aux2 = ''; 
		for (j = 0, i = len - 3; i >= 0; i--) { 
			if (j == 3) { 
				aux2 += milSep; 
				j = 0; 
			} 
			aux2 += aux.charAt(i); 
			j++; 
		} 
		fld.value = ''; 
		len2 = aux2.length; 
		for (i = len2 - 1; i >= 0; i--) 
			fld.value += aux2.charAt(i); 
			fld.value += decSep + aux.substr(len - 2, len); 
		} 
	}
	//alert("sai do if-else");
	// Se tecla backspace ou delete
	if (whichCode == 8 || whichCode == 0)
	{
	   fld.value = '';
	   fld.focus();
	}
    }
	return false; 
} 



function isCpf(s){
   var i;
   var cpf = s.value;
   cpf = remCaracteres(cpf, ".-")
   var c = cpf.substr(0,9);
   var dv = cpf.substr(9,2);
   var d1 = 0;
   for (i = 0; i < 9; i++)
   {
    d1 += c.charAt(i)*(10-i);
   }
   if (d1 == 0 && s.value != ""){
    alert("CPF Invalido");
    s.value = "";
    s.focus();
    return false;
   }
   d1 = 11 - (d1 % 11);
   if (d1 > 9) d1 = 0;
   if ((dv.charAt(0) != d1) && s.value != "")
   {
    alert("CPF Invalido");
    s.value = "";
    s.focus();
    return false;
   }
   d1 *= 2;
   for (i = 0; i < 9; i++)
   {
    d1 += c.charAt(i)*(11-i);
   }
   d1 = 11 - (d1 % 11);
   if (d1 > 9) d1 = 0;
   if (dv.charAt(1) != d1 && s.value != "")
   {
    alert("CPF Invalido");
    s.value = "";
    s.focus();
   }
   return true;
}

function isDate(OBJ, APAGA)
{ 
  var dia = OBJ.value.substring(0,2);
  
  if (OBJ.value.substring(3,5) < 10)
   var mes = OBJ.value.substring(4,5);
  else
  var mes = OBJ.value.substring(3,5);

  var ano = OBJ.value.substring(6,10);
  
  if(( ano%4==0 && ano%100 !=0 ) || ( ano%400==0 ) )
   fev = 29;
  else
   fev = 28;
   
  var array_mes=new Array(31,fev,31,30,31,30,31,31,30,31,30,31);
  var indice = mes-1;
  if (((dia > array_mes[indice] || dia <= 0) || (mes > 12 || mes <= 0) || (ano < 1910 || ano > 2100)) && (OBJ.value != ""))
  {
   alert("Data Inválida.");
   if(APAGA==true){
   		OBJ.value = "";
   }
   OBJ.focus();
  }

}


function isEmail(email) {
   var objRegExp  = /^[A-Za-z]([\w\.]*)@([A-Za-z0-9\.]*)\.(([A-Za-z]{3}\.[A-Za-z]{2}$)|([A-Za-z]{2}\.[A-Za-z]{2}$)|([A-Za-z]{3}$)|([a-z]{2}$))/i ;
   if((objRegExp.test(email.value) == false) && (email.value != "")) {
    alert("E-mail inválido.");
    email.value = "";
    email.focus();
    return false;
   }
}

function isNumeric(str)
{   
    var len = str.value.length;
    
    for (i=0; i<len; i++)
    {   
       c = str.value.charAt(i);
       if (c < '0' || c > '9')
       {
          alert ("Este campo não deve conter letras ou caracteres especiais");
          str.value = "";
          str.focus();
          return false;
       }
    }    
    return true;
}


 function IsNum(valor)

 {
   var numeros = "0123456789.";
   var num =true;
   var Char;

 
   for (i = 0; i < valor.length && num == true; i++) 
      { 
      Char = valor.charAt(i); 
      if (numeros.indexOf(Char) == -1) 
         {
         	num = false;
         }
      }
   return num;
   
 }
 
 function formataCampo(frm_campo, tipo)
 {  alert("pqp d js!!!");
 	var valor = frm_campo.value;
 	var len = valor.lenght;
 	var novo_valor=''; 	
 	
 	switch (tipo){
 	
 		case "cep":	
 		
 			if (len < 8){
 				for (i=1;i<(8-len);i++){
 					novo_valor&='0';
 				}
 			}
 			novo_valor &= 
 			valor.substr(0,3) & '.' &
 			valor.substr(3,3) & '.' &
 			valor.substr(6,3) & '-' &
 			valor.substr(9,2);
 				
 		break;
 			
 		case "cpf":	
 		
 			if (len < 11){
 				for (i=1;i<(11-len);i++){
 					novo_valor&='0';
 				}
 			}
 			novo_valor &= 
 			valor.substr(0,3) & '.' &
 			valor.substr(3,3) & '.' &
 			valor.substr(6,3) & '-' &
 			valor.substr(9,2);
 				
 		break;
 				
 		case "cnpj":
 		
 			if (len < 14){
 				for (i=1;i<(14-len);i++){
 					novo_valor&='0';
 				}
 			} 		
 			novo_valor &= 
 			valor.substr( 0,2) & '.' &
 			valor.substr( 2,3) & '.' &
 			valor.substr( 5,3) & '/' &
 			valor.substr( 8,4) & '-' &
 			valor.substr(12,2);
 			
 		break;
 		
 	}
 }
 
  function scroll_right(speed){
  	document.getElementById('rolagem').play = setInterval("document.getElementById('rolagem').scrollLeft+="+speed,10);
  }  
  function scroll_left(speed){
  	document.getElementById('rolagem').play = setInterval("document.getElementById('rolagem').scrollLeft-="+speed,10);
  }  
  function scroll_up(speed){
  	document.getElementById('rolagem').play = setInterval("document.getElementById('rolagem').scrollTop-="+speed,10);
  }  
  function scroll_down(speed){
  	document.getElementById('rolagem').play = setInterval("document.getElementById('rolagem').scrollTop+="+speed,10);
  }
  function scroll_stop(){
	clearInterval(document.getElementById('rolagem').play);
  }
  

function area_restrita(){
	var o = document.getElementById('fundo_restrito');
	if(o!=null){
		o.style.height = document.body.scrollHeight + 'px';
		o.style.width = document.body.scrollWidth + 'px';
	}
}  
  
