// <!--

	VerifiqueTAB=true;
	
	function Mostra(quem, tammax) {
		if ( (quem.value.length == tammax) && (VerifiqueTAB) ) {
			var i=0,j=0, indice=-1;
			for (i=0; i<document.forms.length; i++) {
				for (j=0; j<document.forms[i].elements.length; j++) {
					if (document.forms[i].elements[j].name == quem.name) {
						indice=i;
						break;
					}
				}
				if (indice != -1)
			         break;
			}
			for (i=0; i<=document.forms[indice].elements.length; i++) {
				if (document.forms[indice].elements[i].name == quem.name) {
					while ( (document.forms[indice].elements[(i+1)].type == "hidden") &&
							(i < document.forms[indice].elements.length) ) {
								i++;
					}
					document.forms[indice].elements[(i+1)].focus();
					VerifiqueTAB=false;
					break;
				}
			}
		}
	}

	function PararTAB(quem) {
		 VerifiqueTAB=false;
	}

	function ChecarTAB() {
		VerifiqueTAB=true;
	}
	
	function SetaFoco(quem) {
		var i=0, j=0;

		for (j=0; j<document.forms.length; j++) {
			for (i=0; i<document.forms[j].elements.length; i++) {
				if (document.forms[j].elements[i].name == (quem == null ? "FOCO" : quem)) {
					document.forms[j].elements[i].focus();
					break;
				}
			}
		}
	}
		
	function ApagaSenha() {
		setTimeout('ExecApagaSenha()',30);
	}
	
	function ExecApagaSenha() {
		var i=0, j=0;
		for (j=0; j<document.forms.length; j++) {
			for (i=0; i<document.forms[j].elements.length; i++) {
				if (document.forms[j].elements[i].type == "password") {
					document.forms[j].elements[i].value="";
					break;
				}
			}
		}
	}

	function carregabrw() { 
		window.open('','BANKLINE','resizable=yes,location=yes,directories=no,status=yes,toolbar=yes,menubar=yes,scrollbars=yes,width=600,height=400,left=50,top=40'); setTimeout("limpa()",30); 
	}
	
	function execlimpa() { 
		var i=0, j=0;
		for (j=0; j<document.forms.length; j++) {
			for (i=0; i<document.forms[j].elements.length; i++) {
				if ( (document.forms[j].elements[i].type == "password") && 
                                     (document.forms[j].elements[i].value == "") ) {
                                    return false;
                                }
                        }
                }
		setTimeout("limpa()",30);
                return true; 
	}
	
	function limpa() { 
		var i=0, j=0;
		for (j=0; j<document.forms.length; j++) {
			for (i=0; i<document.forms[j].elements.length; i++) {
				if ( (document.forms[j].elements[i].type == "password") ||
				     (document.forms[j].elements[i].type == "text") ) {
					document.forms[j].elements[i].value="";
				}
			}
		}
	}

    function vazio (campo)  {
        if (campo == "" || campo==null)
             return true;
        return false;
    }

    function numerico (campo)  {
         var len = campo.length 
         for (var i=0; i<len; i++)
             if (campo.charAt (i) < "0" || campo.charAt (i) > "9")
                 return false;
         return true;
    }

    function valida_tamanho_mes(campo) {
	    if (campo < 1  || campo > 12 ) 
		return false;
	return true;
    }

    function valida_tamanho_ano(campo) {

   	var d, s;
   	d = new Date();
   	s = d.getFullYear();

    	    if (campo < 1985  || campo > s ) 
		return false;
	return true;
    }

    function ChecaMes () {
	  if (vazio (document.form_data.mes.value)) {
		alert ("Mês inválido !");
		return false;
	  }
	  if (!numerico (document.form_data.mes.value)) {
		alert ("Mês inválido !");
		return false;
	  }
	  if (!valida_tamanho_mes (document.form_data.mes.value)) {
		alert ("Mês inválido !");
		return false;
	  }
	  return true;
    }

    function ChecaAno () {
	  if (vazio (document.form_data.ano.value)) {
		alert ("Ano inválido !");
		return false;
	  }
	  if (!numerico (document.form_data.ano.value)) {
		alert ("Ano inválido !");
		return false;
	  }
	  if (!valida_tamanho_ano(document.form_data.ano.value)) {
		alert ("Ano inválido !");
		return false;
	  }
	  return true;
    }











		function PutMilion (numero)
		{
		  var i=0;
		  numero=numero.toString();
		  numero=numero.replace(/[.]/g,"");
		  numero=numero.replace(/[,]/g,"");
		  tamanho = numero.length;
		  numerosemdecimais = numero.substring(0, tamanho - 2);
		  tamanhosemdecimais = tamanho - 2;
		  decimais = numero.substring(tamanho - 2, tamanho);
		  numeropontosdecimais = parseInt((tamanho - 2) / 3);
		  numero2 = "";
		  for(i=0; i<numeropontosdecimais*3; i+=3)
		    numero2 = "." + numerosemdecimais.substring(tamanhosemdecimais - i - 3, tamanhosemdecimais - i) + numero2;
		  numero2 = numerosemdecimais.substring(0, tamanhosemdecimais - i) + numero2;
		  numero2 = numero2 + "," + decimais;
		  if(numero2.substr(0,1) == '.')
		  {
		     tamanho = numero2.length;
		     numero2 = numero2.substr(1, tamanho - 1);
		  }
		  return (numero2);
		}

		function PutCents (numero)
		{
			var i=0;
			numero=numero.toString();
			numero=numero.replace(/[.]/g,",");
			while ((numero.charAt(i) != ",") && (i < numero.length)) { i++; }
			if ((numero.length-i) > 2) { numero=numero.substr(0,i+3); }
			else
			{
				switch (numero.length - i)
				{
					case 0: numero+=",00"; break;
					case 1: numero+="00"; break;
					case 2: numero+="0"; break;
				}
			}
			return (numero);
				
		}

		function ChkString (string1, string2)
		{
			var Ok=false;
			string1=string1.toString();
			string2=string2.toString();
			if (string1.length == string2.length)
			{
				for (var i=0; ((string1.charAt(i) == string2.charAt(i)) && (i < string1.length)); i++) {}
				if (i == string1.length) { Ok=true; }
			}
			return Ok;
		}

		function ChkNumber (campo, status)
		{
			var numero, digitos="0123456789,.", Ok=true, virgula=false;
			if (campo.value == "") { Ok=false; }
			else
			{
				numero=campo.value;
				numero=numero.toString();
				numero=numero.replace(/[.]/g,"");
				if (numero.length > 12) { Ok=false; }
				else
				{
					if ((digitos.indexOf(numero.charAt(0)) < 1) || (digitos.indexOf(numero.charAt(0)) > 9)) { Ok=false; }
					else
					{
						for (var i=1; ((i < numero.length) && (Ok)); i++)
						{
							if (digitos.indexOf(numero.charAt(i)) < 0) { Ok=false; }
							if (digitos.indexOf(numero.charAt(i)) == 10)
							{
								if (((numero.length-i) <= 3) && (!virgula)) { virgula=true; }
								else { Ok=false; }
							}
						}
					}
				}
				if (Ok) 
				{ 
				  valor = PutCents(numero);
				  campo.value=PutMilion(valor); 
				}
				else
				{
					alert( "Valor digitado não é válido: " + numero);
					campo.value="";
					campo.select();
				}
			}
			if (status) { return Ok; }
		}











		function SelecionaOpcao (campo, opcao)
		{
			var selecionado=false;
			for(var i=0; ((i < campo.length) && (!selecionado)); i++)
			{
				if (ChkString(campo.options[i].value,opcao))
				{
					 campo.options[i].selected=true;
					 selecionado=true;
				}
			}
			if (!selecionado) {campo.options[0].selected=true}
		}


		function dac11(val,tipo) //algoritmo dac11 para cnpj, cpf
		{
			var aux;
			var str_final;
			var dig;
			var mult;
			var soma;
			str_final = "";
			soma=0; aux=0; mult = 2;
			len = parseInt(val.length);
			dig = val.substring(len-2);
			str_final = val.substring(0, len-2);
			str_final_len = parseInt(str_final.length);
			if (str_final_len > 0) {
				//passo 1
				for (i=1; i<=str_final_len; i++) {
					aux = parseInt(str_final.charAt(str_final_len-i))*mult;
					soma = soma + aux;
					mult++;
					if (mult > 9 && tipo == "cnpj") {
						mult = 2;
					}
				}
				soma = soma.toString();
				soma_len = parseInt(soma.length);
				res = 11-soma%11;
				if (res >= 10) {
					res = 0;
				}
				//passo 2
				mult = 2;
				soma = 0;
				str_final = str_final+res.toString();
				str_final_len = parseInt(str_final.length);
				for (i=1; i<=str_final_len; i++) {
					aux = parseInt(str_final.charAt(str_final_len-i))*mult;
					soma = soma + aux;
					mult++;
					if (mult > 9 && tipo == "cnpj") {
						mult = 2;
					}
				}
				soma = soma.toString();
				soma_len = parseInt(soma.length);
				aux = 11-(soma%11);
				if (aux >= 10) {
					aux = 0;
				}
				res = res+aux.toString();
			} else { //Número inválido!
				return 0
			}
			if (res != dig) { //número inválido
				return 0;
			} else { //número correto
				return 1;
			}
		}

		function VerificaEmail (email) {
			invalidChars = " /:,;"
			if ( email == "" )
			{
				alert("Por favor informe seu e-mail.");
				return false;
			}
			for (i=0; i<invalidChars.length; i++)
			{
				badChar = invalidChars.charAt( i )
				if ( email.indexOf(badChar,0) > -1 )
				{ 
					alert("E-mail com caracter(es) inválido(s).");
				   return false;
				}
			}
			atPos = email.indexOf("@",1)
			if (atPos == -1)
			{
		    	alert("Está faltando o @ no e-mail.");
				return false;
			}
			if (email.indexOf("@",atPos+1) > -1)
			{
		    	alert("No e-mail só é permitido um @.");
				return false;
			}
			periodPos = email.indexOf(".",atPos)
			if (periodPos == -1)
			{
			    alert("Falta '.' no e-mail.");
				return false;
			}
			if (periodPos + 3 > email.length)
			{
			    alert("E-mail inválido.");
				return false;
			}
			return true;
		}   

		function VerificaData(dia, mes, ano) {
			var dias = new Array("", "31", "29", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31");
			var Hoje = new Date();
			ano = ano.replace(/[^0-9]/gi, "");
			mes = mes.replace(/[^0-9]/gi, "");
			mes=mes*1;
			dia = dia.replace(/[^0-9]/gi, "");
			dia=dia*1;
			if (((dia.valueOf() >= Hoje.getDate()) && (mes.valueOf() >= (Hoje.getMonth()+1)) && (ano.valueOf() >= Hoje.getFullYear())) ||
				  (ano.valueOf() < 1900) || (ano.valueOf() > Hoje.getFullYear()) || 
				  (mes.valueOf() < 1) || (mes.valueOf() > 12) ||
				  (dia.valueOf() < 1) || (dia.valueOf() > dias[parseInt(mes.valueOf())])) {
				return 0;
			} 
			else
			{
				if	((ano.valueOf() % 4 == 0) && (!(ano.valueOf() % 100 == 0) || (ano.valueOf() % 400 == 0)))
				{
					// Ano bisexto
					if	((mes.valueOf() == 2) && (dia.valueOf() > 29))
					{
						return 0;
					}
				}
				else
				{
					// Ano comum
					if	((mes.valueOf() == 2) && (dia.valueOf() > 28)) {
						return 0;
					}
				}
			}
			return 1;
		}

		function VerificaTel(ddd, tel) {
		var lenDDD=ddd.value.length;
		var lenTel=tel.value.length;
			if ((lenDDD == 0) && (lenTel != 0)) {
				alert ("Por favor informe o DDD.");
				ddd.focus();
				return false;
			}
			if ((lenDDD != 0) && (lenTel == 0)) {
				alert ("Por favor informe o número do telefone.");
				tel.focus();
				return false;
			}
			if ((lenDDD != 0) && (lenTel != 0)) {
				if (ddd.value == "0000") {
					alert ("DDD inválido.");
					ddd.focus();
					return false;
				}
				if (lenTel < 5) {
					alert ("Número de telefone inválido.");
					tel.focus();
					return false;
				}
			}
			return true;
		}

		function PreencheBrancos(valor, tam) {
			while (valor.length < tam) {
				valor = valor + " ";
			}
			return valor;
		}

		function LCh(valor, tam, ch) {
		//	if (isNaN(parseInt(valor)))
		//		valor = ch;
			if ((ch != "") && (valor.length < tam)) {
				while (valor.length < tam) {
					valor = ch + valor;
				}
			}
			return valor;
		}

		function ChkNum (campo, tam, ch)
		{
			var numero, digitos="0123456789", Ok=true;
			if (campo.value != "")
			{
				numero=campo.value;
				// descomentar as duas linhas se quiser corrigir automaticamente o erro
				//numero=numero.toString();
				//numero=numero.replace(/[^0-9]/g,"");
				for (var i=0; ((i < numero.length) && (Ok)); i++)
				{
					if (digitos.indexOf(numero.charAt(i)) < 0) { Ok=false; }
				}
				if (Ok) { campo.value=LCh(numero, tam, ch); }
				else
				{
					alert( "Valor digitado não é válido: " + numero);
					campo.value="";
					campo.select();
				}
			}
			return;
		}

		

		
	function setNoBakeCookie(name,value)
	   {
	   document.cookie = name + "=" + escape(value);         
	   }

	function getCookie(cookieName)
	   {
	   var cookieBeg, cookieEnd;
	   var cookieJar = document.cookie;
	   
	   //look for the cookie//
	   cookieBeg = cookieJar.indexOf(cookieName,0);
	   if(cookieBeg < 0)return null;
	   else cookieBeg +=  cookieName.length + 1;
	   
	   //get value of cookie//
	   cookieEnd = cookieJar.indexOf(";",cookieBeg);
	   if(cookieEnd < 0)cookieEnd = cookieJar.length;
	   
	   //return value of cookie//
	   return unescape(cookieJar.substring(cookieBeg,cookieEnd));
	   }
		//Exemplos
		//setNoBakeCookie("COOKIE1","Hello from HTML TUCOWS!");
		//setNoBakeCookie("COOKIE2","This is a second cookie!");

	
// -->
var	iDD_WIN_SCROLLBARS	= 1;
var	iDD_WIN_RESIZABLE		= 1;	

function DDAbreJanelaPopup( aoTelaPai, asURL, aiLargura, aiAltura, aiOpcoes )
	{
	var oJanela;
	var sOpcoes;
	
	sOpcoes = "";
	if ( parseInt( navigator.appVersion ) < 4 )
		{
		sOpcoes	= "toolbar=no,location=no,address=no,directories=no,status=no,menubar=no,copyhistory=yes,maximized=yes"
					+ ",width=" + aiLargura + ",height=" + aiAltura;
		}
	else
		{
		var lX = screen.width	- aiLargura;		// Posição X da janela
		var lY = screen.height	- aiAltura;			// Posição y da janela

		if ( lX != 0 )
			{
			lX = Math.round( lX / 2 );
			lY = Math.round( lY / 2 ); 
			}

		sOpcoes	= "toolbar=no,location=no,directories=no,status=no,menubar=no"
					+ ",copyhistory=yes,maximized=yes,width=" + aiLargura + ",height=" + aiAltura
					+ ",left=" + lX + ",top=" + lY;
		}

	if ( aiOpcoes & iDD_WIN_SCROLLBARS > 0 )
		sOpcoes += ",scrollbars=yes";
	else
		sOpcoes += ",scrollbars=no";

	if ( aiOpcoes & iDD_WIN_RESIZABLE > 0 )
		sOpcoes += ",resizable=yes";
	else
		sOpcoes += ",resizable=no";

	aoTelaPai.open( asURL, "pop", sOpcoes );
	}

	//Essa função direciona o usuario para a pagina escolhida no tpl
function MudaPagina(sPagina)
	{	
	//alert(sPagina);
		   document.forms[0].action = sPagina;
			document.forms[0].submit();	
	}
	
	/*----------------------------------------------------------------------------------------------------
| FUNÇÃO:
|			verificaCGC( asCGC )
|
| OBJETIVO:
|			Verifica se o CGC recebido como parâmetro é válido
|
| RECEBE:
|			Tipo				Nome									Descrição
|			---------------------------------------------------------------------------------------------
|			String			asCGC								CGC a ser validado
|
| RETORNA:
|			Boleana indicando se CGC válido ou não
|
| Autor:
|			Guilherme S. T. de Castilho	
|
| Data:
|			22/10/2001
|
| Alterações:
-----------------------------------------------------------------------------------------------------*/	

function verificaCGC( asCGC ){

var cChavecdv  = "";
var cCampo     = "";
var cPeso      = "543298765432";
var nPdc       = 13;
var nLooping   = 1;
var nTotdc     = 0;
var nCd        = 1;
var sdc        = 0;
var nResto     = 0;
var bCGCValido     = false;

   if ( asCGC != "" || asCGC != 0 ) {
      
      cChavecdv = asCGC;
      cCampo    = cChavecdv.substring( 12, 15 );
      
      while ( nLooping < 3 ) {
         
         nTotdc = 0;
         
         for( nCd = 0; nCd < 14; nCd++ ) {
            
            sdc = cChavecdv.substring( nCd, nCd + 1 ) * cPeso.substring( nCd, nCd + 1 );
            nTotdc += sdc;
         }
         
         nResto = nTotdc % 11;
         
         if ( nResto < 2 ) {
            
            cChavecdv = cChavecdv.substring( 0 , nPdc - 1 ) + "0" + cChavecdv.substr( nPdc + 1, 1 );
         }                
         else {
         
            nResto = 11 - nResto;
            cChavecdv = cChavecdv.substring( 0, nPdc - 1 ) + parseInt( nResto , 10 ) + cChavecdv.substring( nPdc + 1 , 1 );
         }
         
         cPeso = "6" + cPeso;
         nPdc ++;
         nLooping ++;
      }
      
      if ( cCampo != cChavecdv.substring( 12, 14 ) ) {
           
         bCGCValido = true;
      }
   }
   else {
   
      bCGCValido = true;
   }

   return ( !bCGCValido );
}

function checkmail(email) 
{ 
	var find_ponto=false;
	var find_arroba=false;
	var find_caracter=true;
	var find_colon=true;
	for (var i=0; i< email.length; i++) 
	{
		if (email.charAt(i)=="@") find_arroba=true;
		else if (email.charAt(i)==".") find_ponto=true;
		else if (email.charAt(i)==" ") find_caracter=false;
		else if (email.charAt(i)==",") find_colon=false;
	}
	return (find_ponto & find_arroba & find_caracter & find_colon);
}	


	
