/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Cyanide_7 |  */
var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
  var keyCode = (isNN) ? e.which : e.keyCode; 
  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
  if(input.value.length >= len && !containsElement(filter,keyCode)) {
    input.value = input.value.slice(0, len);
    input.form[(getIndex(input)+1) % input.form.length].focus();
  }

  function containsElement(arr, ele) {
    var found = false, index = 0;
    while(!found && index < arr.length)
    if(arr[index] == ele)
    found = true;
    else
    index++;
    return found;
  }

  function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
    if (input.form[i] == input)index = i;
    else i++;
    return index;
  }
  return true;
}
    function validate(evt) {
      var theEvent = evt || window.event;
      var key = theEvent.keyCode || theEvent.which;
      key = String.fromCharCode( key );
      var regex = /[0-9]|\./;
      if( !regex.test(key) ) {
        theEvent.returnValue = false;
        theEvent.preventDefault();
      }
    }
    
    var now = new Date();
// fixDate(now);
 now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);

function setCookie(name, value, expires, path, domain, secure) {
          var curCookie = name + "=" + escape(value) +
          ((expires) ? "; expires=" + expires.toGMTString() : "") +
          ((path) ? "; path=" + path : "") +
          ((domain) ? "; domain=" + domain : "") +
          ((secure) ? "; secure" : "");
          document.cookie = curCookie;
 }
 function getCookie(name) {
        var dc = document.cookie;
        var prefix = name + "=";
        var begin = dc.indexOf("; " + prefix);
        if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
        } else
        begin += 2;
        var end = document.cookie.indexOf(";", begin);
        if (end == -1)
        end = dc.length;
        return unescape(dc.substring(begin + prefix.length, end));
 }


			
	setCookie('janela_resolucao', screen.width, now);	


// format valores no formulario cpf
 

function FormataCPF(pForm,pCampo,pTamMax,pPos1,pPos2,pPosTraco,pTeclaPres)
{
	if(navigator.appName=="Netscape" || navigator.appName=="Mozilla Firefox"){
		
		} else {
		
	var wTecla, wVr, wTam;	
	var nerros=true;
	
    wTecla = pTeclaPres.keyCode;
	wVr = pForm[pCampo].value;
	wVr = wVr.toString().replace( "-", "" );
	wVr = wVr.toString().replace( ".", "" );
	wVr = wVr.toString().replace( ".", "" );
	wVr = wVr.toString().replace( "/", "" );
	wTam = wVr.length ;
	
	if (wTam < pTamMax && wTecla != 8) 
	{ 
	   wTam = wVr.length + 1 ; 
	}

	if (wTecla == 8 ) 
	{ 
	   wTam = wTam - 1 ; 
	}
			
	if ( wTecla == 8 || wTecla == 88 || (wTecla >= 48 && wTecla <= 57) || (wTecla >= 96 && wTecla <= 105) )
	{
		if ( wTam <= 2 )
		{
	 		pForm[pCampo].value = wVr ;
		}
		if (wTam > pPosTraco && wTam <= pTamMax) 
		{
	       wVr = wVr.substr(0, wTam - pPosTraco) + '-' + wVr.substr(wTam - pPosTraco, wTam);
		}
		if ( wTam == pTamMax)
		{
		      wVr = wVr.substr( 0, wTam - pPos1 ) + '.' + wVr.substr(wTam - pPos1, 3) + '.' + wVr.substr(wTam - pPos2, wTam);
		}
		pForm[pCampo].value = wVr;
		pForm[pCampo].value = toInteger(pForm[pCampo].value);
		nerros=true;
	}
	else
	{
		
		pForm[pCampo].value = toInteger(pForm[pCampo].value);
		nerros = false;
		
		
	}

	if (wTecla == 9) nerros = true;
	return nerros;
}
}
// format valores no formulario

function FormataValorDisplay(pForm, pCampo, pTamMax, pVirgula) 
{
	wVr = pForm[pCampo].value;
	wVr = wVr.toString().replace( "/", "" );
	wVr = wVr.toString().replace( "/", "" );
	wVr = wVr.toString().replace( ",", "" );
	wVr = wVr.toString().replace( ".", "" );
	wVr = wVr.toString().replace( ".", "" );
	wVr = wVr.toString().replace( ".", "" );
	wVr = wVr.toString().replace( ".", "" );
	wTam = wVr.length;

      if (pVirgula == 1) {
		if ( wTam <= 2 ){ 
	 		pForm[pCampo].value = wVr ; }
	 	if ( (wTam > 2) && (wTam <= 5) ){
		   pForm[pCampo].value = wVr.substr( 0, wTam - 2 ) + ',' + wVr.substr( wTam - 2, wTam ) ; }
	 	if ( (wTam >= 6) && (wTam <= 8) ){
    	   pForm[pCampo].value = wVr.substr( 0, wTam - 5 ) + '.' + wVr.substr( wTam - 5, 3 ) + ',' + wVr.substr( wTam - 2, wTam ) ; }
	 	if ( (wTam >= 9) && (wTam <= 11) ) {
	 		pForm[pCampo].value = wVr.substr( 0, wTam - 8 ) + '.' + wVr.substr( wTam - 8, 3 ) + '.' + wVr.substr( wTam - 5, 3 ) + ',' + wVr.substr( wTam - 2, wTam ) ; }
	 	if ( (wTam >= 12) && (wTam <= 14) ){
	 		pForm[pCampo].value = wVr.substr( 0, wTam - 11 ) + '.' + wVr.substr( wTam - 11, 3 ) + '.' + wVr.substr( wTam - 8, 3 ) + '.' + wVr.substr( wTam - 5, 3 ) + ',' + wVr.substr( wTam - 2, wTam ) ; }
	 	if ( (wTam >= 15) && (wTam <= 17) ){
	 		pForm[pCampo].value = wVr.substr( 0, wTam - 14 ) + '.' + wVr.substr( wTam - 14, 3 ) + '.' + wVr.substr( wTam - 11, 3 ) + '.' + wVr.substr( wTam - 8, 3 ) + '.' + wVr.substr( wTam - 5, 3 ) + ',' + wVr.substr( wTam - 2, wTam ) ;}
     } else { 
		if ( wTam <= 3 ){ 
	 		pForm[pCampo].value = wVr ; }
	 	if ( (wTam > 3) && (wTam <= 6) ){
		   pForm[pCampo].value = wVr.substr( 0, wTam - 3 ) + '.' + wVr.substr( wTam - 3, wTam ) ; }
	 	if ( (wTam >= 7) && (wTam <= 9) ) {
    	   pForm[pCampo].value = wVr.substr( 0, wTam - 6 ) + '.' + wVr.substr( wTam - 6, 3 ) + '.' + wVr.substr( wTam - 3, wTam ) ; }
	 	if ( (wTam >= 10) && (wTam <= 12) ) {
	 		pForm[pCampo].value = wVr.substr( 0, wTam - 9 ) + '.' + wVr.substr( wTam - 9, 3 ) + '.' + wVr.substr( wTam - 6, 3 ) + '.' + wVr.substr( wTam - 3, wTam ) ; }
	 	if ( (wTam >= 13) && (wTam <= 15) ){
	 		pForm[pCampo].value = wVr.substr( 0, wTam - 12 ) + '.' + wVr.substr( wTam - 12, 3 ) + '.' + wVr.substr( wTam - 9, 3 ) + '.' + wVr.substr( wTam - 6, 3 ) + '.' + wVr.substr( wTam - 3, wTam ) ; }
	 	if ( (wTam >= 16) && (wTam <= 18) ){
	 		pForm[pCampo].value = wVr.substr( 0, wTam - 15 ) + '.' + wVr.substr( wTam - 15, 3 ) + '.' + wVr.substr( wTam - 12, 3 ) + '.' + wVr.substr( wTam - 9, 3 ) + '.' + wVr.substr( wTam - 6, 3 ) + '.' + wVr.substr( wTam - 3, wTam ) ;}
	 }
}

//verifica cpf
function VCPF(pForm, pCampo)
 {
	var wVr, wVrCPF, wVrSEQ, wTam, wSoma, wSoma2, i, j, wDig1, wDig2,aux,
	    wVETOR_CC = new Array(11),
	    wVETOR_PESO = new Array(11);
 	var Erro = false;
	wVrCPF = pForm[pCampo].value;
	aux = pForm[pCampo].value;
	
  
	wVr= aux.toString().substring(0,3) + aux.toString().substring(4,7) + aux.toString().substring(8,11) + aux.toString().substring(12,14) ;     
//	wVr = wVr.toString().replace(".","");
//	wVr = wVr.toString().replace(".","");
//	wVr = wVr.toString().replace(".","");
//	wVr = wVr.toString().replace("-","");
	wTam = wVr.length + 1;

    if (wTam < 11) {
	  alert("Nº de dígitos do CPF menor que o normal. Redigite !!!");
	  pForm[pCampo].value = "";
	  pForm[pCampo].focus();
	  return false;
	}
    
	for (i = 0; i < wVr.length; i++) {
	   if (isNaN(parseInt(wVr.charAt(i))) ) {
  	     alert("O CPF contém dígitos inválidos. Corrija-o !!!");
	     pForm[pCampo].value = "";
	     pForm[pCampo].focus();
	     return false;
	   }
	}
	
	//comentado abaixo por claudio para testes
	//if (wVr == '11111111111' || wVr == '22222222222' || wVr == '33333333333' || wVr == '44444444444' || wVr == '55555555555' || 
	//    wVr == '66666666666' || wVr == '77777777777' || wVr == '88888888888' || wVr == '99999999999') {
  	//     alert("CPF Inválido. Redigite-o !!!");
	//     pForm[pCampo].value = "";
	//     pForm[pCampo].focus();
	//     return false;
    //	}
    
    wSoma = 0;
	wSoma2 = 0;
    j = 2;
    for (i = 0; i < 11; i++) {
	   wVETOR_CC[i] = wVr.charAt(i);
	   wVETOR_PESO[i] = j;
	   j++; 
	} 
    i = 0;	  
    while (i < 9)  {
	   i++;
	   if (i < 10) {
          wSoma += wVETOR_CC[9 - i] * wVETOR_PESO[i - 1]; }
	   wSoma2 += wVETOR_CC[10 - i] * wVETOR_PESO[i - 1];
	}
	wDig1 = (wSoma * 10) % 11;
	wDig2 = (wSoma2 * 10) % 11;
	if (wDig1 == 10) { 
	    wDig1 = 0;
	}	
	if (wDig2 == 10) { 
	    wDig2 = 0;
	}		
    if (parseInt(wVr.charAt(9)) != wDig1 || parseInt(wVr.charAt(10)) != wDig2) {
  	     alert("CPF com Dígito Verificador inválido. Redigite-o !!!");
//	     pForm[pCampo].value = "";
	     pForm[pCampo].focus();
	     return false;
    }	
    pForm[pCampo].value = wVrCPF;
//    pForm[pCampo + 1].value = wVrSEQ;

	return true;  // VerificaChaveAcesso(pForm, 1, 2, 3);
}
// aqui começa

function FormataCGC(pForm,pCampo,pTeclaPres){
	var wTecla, wVr, wTam;	

	var nerros=true;
	
	wTecla = pTeclaPres.keyCode;
	wVr = pForm[pCampo].value;
	wVr = wVr.toString().replace( "-", "" );
	wVr = wVr.toString().replace( ".", "" );
	wVr = wVr.toString().replace( ".", "" );
	wVr = wVr.toString().replace( "/", "" );
	wVr = wVr.toString().replace( "-", "" );
	wTam = wVr.length ;


	
	if (wTam < 14 && wTecla != 8) { 
	   wTam = wVr.length + 1 ; 
	}

	if (wTecla == 8 ) { 
	   wTam = wTam - 1 ; 
	}

	if ( wTecla == 8 || wTecla == 88 || wTecla >= 48 && wTecla <= 57 || wTecla >= 96 && wTecla <= 105 ){
		if ( wTam <= 2 ){
	 		pForm[pCampo].value = wVr ;
		}
		if (wTam > 2 && wTam <= 14) {
		   wVr = wVr.substr(0, wTam - 2) + '-' + wVr.substr(wTam - 2, wTam);
		}
		if ( wTam == 14){
	       wVr = wVr.substr( 0, wTam - 12 ) + '.' + wVr.substr(wTam - 12, 3) + '.' + wVr.substr(wTam - 9, 3) + "/" + wVr.substr(wTam - 6, wTam);
		}
		pForm[pCampo].value = wVr;
		pForm[pCampo].value = toInteger(pForm[pCampo].value);
		nerros=true;
}
	else
	{
		
		pForm[pCampo].value = toInteger(pForm[pCampo].value);
		nerros = false;
	}
	
	if (wTecla == 9) nerros = true;
	return nerros;

}


function VCGC(pForm, pCampo)
{ 
//= pForm[pCampo].value.toString().substring(0,15)
// pForm[pCampo].value.toString().substring(16, 2);
	var Numero; 
	var Digito; 
	var CNPJ ,aux = pForm[pCampo].value

	//Numero = Numero.replace(".","");
	//Numero = Numero.replace(".","");
	//Numero = Numero.replace("/","");
	//Numero = Numero.replace("-","");

	Numero = aux.toString().substring(0,2) + aux.toString().substring(3,6) + aux.toString().substring(7,10) + aux.toString().substring(11,15);
	CNPJ= aux.toString().substring(0,2) + aux.toString().substring(3,6) + aux.toString().substring(7,10) + aux.toString().substring(11,15) + aux.toString().substring(16,18);
	Digito=aux.toString().substring(16,18);

//	CNPJ = CNPJ.replace(".","");
//	CNPJ = CNPJ.replace(".","");
//	CNPJ = CNPJ.replace("/","");
//	CNPJ = CNPJ.replace("-","");

	var CGC = Numero;
	var peso1 = '543298765432';
	var peso2 = '654329876543';
	var soma1 = 0;
	var soma2 = 0;
	var digito1 = 0;
	var digito2 = 0;
          
	 if (CNPJ == '00000000000000'){
	 	alert("CNPJ Inválido. Redigite!");
		pForm[pCampo].value = "";
	  	pForm[pCampo].focus();
	  	return false;
	 } 
	 
	 if ((Numero.length + Digito.length + 1 > 1) && (Numero.length + Digito.length + 1 < 15)) 
	 {
	  alert("Nº de dígitos do CNPJ menor que o normal. Redigite !!!");
	  pForm[pCampo].value = "";
	  pForm[pCampo].focus();
	  return false;
	 }	
 
 	if (Numero.length + Digito.length + 1 > 1){
 		 
		 for (i = 1; i < 12 - Numero.length + 1; i++) 
		 {
		  CGC = eval("'" + 0 + CGC + "'")
		 }
		    
		 for (i = 1; i < CGC.length+1; i++) 
		 {
		  soma1 += CGC.substring(i, i-1) * peso1.substring(i, i-1);
		 } 
		
		 soma1 %= 11;
		
		 if (soma1  < 2) 
		 {
		  digito1 = 0;
		 }
		 else 
		 {
		  digito1 = 11 - soma1; 
		 }
		
		 for (i = 1; i < CGC.length+1; i++) 
		 {
		  soma2 += CGC.substring(i, i-1) * peso2.substring(i, i-1);
		 } 
		 
		 soma2 += digito1 * 2 
		 soma2 %= 11;
		
		 if (soma2  < 2) 
		 {
		  digito2 = 0;
		 }
		 else 
		 {
		  digito2 = 11 - soma2; 
		 }
		
		 if (eval("'" + digito1 + digito2 + "'") != Digito)
		 {
		  //alert("CNPJ inválido. Redigite !!!");
//		  pForm[pCampo].value = "";
//		  pForm[pCampo].focus();
		  return false;
		 }
		 else 
		 {
		  return true;
		 }
	}
}

// aqui termina
// Formata Data
function FormataData(pForm, pCampo,pTeclaPres) {
	var wTecla = pTeclaPres.keyCode;
	wVr = pForm[pCampo].value;
	wVr = wVr.replace( ".", "" );
	wVr = wVr.replace( "/", "" );
	wVr = wVr.replace( "/", "" );
	wTam = wVr.length + 1;

	if ( wTecla != 9 && wTecla != 8 ){
		if ( wTam > 2 && wTam < 5 )
			pForm[pCampo].value = wVr.substr( 0, wTam - 2  ) + '/' + wVr.substr( wTam - 2, wTam );
		if ( wTam >= 5 && wTam <= 10 )
			pForm[pCampo].value = wVr.substr( 0, 2 ) + '/' + wVr.substr( 2, 2 ) + '/' + wVr.substr( 4, 4 ); 
	}			
}


//Formatar Telefone
function FormataTEL(pForm, pCampo, pTeclaPres) {
	var wTecla = pTeclaPres.keyCode;
	var wTam;
	wVr = pForm[pCampo].value;
	wVr = wVr.replace( ".", "" );
//	wVr = wVr.replace( "(", "" );
//	wVr = wVr.replace( ")", "" );
	wVr = wVr.replace( "-", "" );
	wVr = wVr.replace( "/", "" );
	wTam = wVr.length + 1;

	if ( wTecla != 9 && wTecla != 8 ){
		if ( wTam > 0 && wTam < 2 ) 
			pForm[pCampo].value = '(' ;
		if ( wTam > 3 && wTam < 5 ) 
			pForm[pCampo].value = wVr.substr( 0, 8 ) + ')' + wVr.substr( 8, 4 );
		if ( wTam > 7 && wTam < 9 ) 
			pForm[pCampo].value = wVr.substr( 0, 8 ) + '-' + wVr.substr( 8, 4 );
		if ( wTam > 11)
			pForm[pCampo].value = wVr.substr( 0, 8 ) + '-' + wVr.substr( 8, 4 ); 
	}			
}

// 
function CampoUpcase (pForm, pCampo, pOperacao) {
   if (pOperacao == "+") {
     pForm[pCampo].value = pForm[pCampo].value.toUpperCase();
   } else {
     pForm[pCampo].value = pForm[pCampo].value.toLowerCase();
   }
}

//
function FormataCEP(pForm, pCampo, pTeclaPres) {
	var wTecla = pTeclaPres.keyCode;
	var wTam;
	wVr = pForm[pCampo].value;
	wVr = wVr.replace( ".", "" );
	wVr = wVr.replace( "-", "" );
	wVr = wVr.replace( "/", "" );
	wTam = wVr.length + 1;

	if ( wTecla != 9 && wTecla != 8 ){
		if ( wTam > 2 && wTam < 6 )
			pForm[pCampo].value = wVr.substr( 0, wTam - 2  ) + '.' + wVr.substr( wTam - 2, wTam );
		if ( wTam >= 6 && wTam <= 9 )
			pForm[pCampo].value = wVr.substr( 0, 2 ) + '.' + wVr.substr( 2, 3 ) + '-' + wVr.substr( 5, 3 ); 
	}			
}



//email
function VerificaEmail(pcampo)  { 

	  pcampo.value = pcampo.value.toLowerCase();					
      	  parametro = pcampo.value;								
	  teste_parametro = "false"; 
	  tamanho_parametro = parametro.length;
	  aposicao = 0; //posicao @
	  pposicao = 0; //poiscao ponto
	  narrobas = 0; // numero de @
	  for (i = 0; i < tamanho_parametro; i++) { /*verifica se existe espaco em branco */
		   if (parametro.charAt(i) == "@") {
		  	     narrobas = narrobas + 1
				 aposicao = i;
		   }
		   if (parametro.charAt(i) == ".") {
		  	     
				 pposicao = i;
		   }
		   
	   }
	   if (aposicao > 0 && aposicao+1 < pposicao && narrobas<2){
     	   teste_parametro = "true"; 
	   }	   
      	  
	  for (i = 0; i < tamanho_parametro; i++) { /*verifica se existe espaco em branco */
		   if (parametro.charAt(i) == " ") {
		  	     teste_parametro = "false"; 
		   }
	   }
		
	   if (tamanho_parametro < 5) {
	   	  teste_parametro = "false"; /*tamanho minimo*/
	   }
	  
			
	   if (parametro.charAt(0) == " " || parametro.charAt(1) == " ") { /*Primeiros chars em branco */
			  teste_parametro = "false"; 
	   }
				
		
		if (teste_parametro == "false" && tamanho_parametro != 0 ) { /*Existe algum problema no preenchiento do nome */
			alert("E-mail inválido!");
			pcampo.focus();
			return false;
		} else {
			return true;
		}
}



function LTrim(str)
/***
        PURPOSE: Remove leading blanks from our string.
        IN: str - the string we want to LTrim

        RETVAL: An LTrimmed string!
***/
{
        var whitespace = new String(" \t\n\r");

        var s = new String(str);

        if (whitespace.indexOf(s.charAt(0)) != -1) {
            // We have a string with leading blank(s)...

            var j=0, i = s.length;

            // Iterate from the far left of string until we
            // don't have any more whitespace...
            while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
                j++;


            // Get the substring from the first non-whitespace
            // character to the end of the string...
            s = s.substring(j, i);
        }

        return s;
}


//RTrim(string) : Returns a copy of a string without trailing spaces.
//==================================================================
function RTrim(str)
/***
        PURPOSE: Remove trailing blanks from our string.
        IN: str - the string we want to RTrim

        RETVAL: An RTrimmed string!
***/
{
        // We don't want to trip JUST spaces, but also tabs,
        // line feeds, etc.  Add anything else you want to
        // "trim" here in Whitespace
        var whitespace = new String(" \t\n\r");

        var s = new String(str);

        if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
            // We have a string with trailing blank(s)...

            var i = s.length - 1;       // Get length of string

            // Iterate from the far right of string until we
            // don't have any more whitespace...
            while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
                i--;


            // Get the substring from the front of the string to
            // where the last non-whitespace character is...
            s = s.substring(0, i+1);
        }

        return s;
}




//Trim(string) : Returns a copy of a string without leading or
//               trailing spaces
//=============================================================
function Trim(str)
/***
        PURPOSE: Remove trailing and leading blanks from our string.
        IN: str - the string we want to Trim

        RETVAL: A Trimmed string!
***/
{
        return RTrim(LTrim(str));
}


function toInteger(checkString)
{
 var newString = "";    
 var count = 0;         
    for (i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i+1);
        if (ch >= "0" && ch <= "9") 
        {
            newString += ch;
        }
        else
        {
         if (ch == "-") newString += ch;
         if (ch == ".") newString += ch;
         if (ch == "/") newString += ch;
        }
    }
    
    return newString; //checkString;
}


//function so_numero(pForm,pCampo,pTeclaPres)
//{
// var wTecla 
//  var nerro = true;
//    wTecla =  pTeclaPres.keyCode;
//	if ( wTecla == 8 || wTecla == 88 || wTecla >= 48 && wTecla <= 57 || wTecla >= 96 && wTecla <= 105)
//	{
//		pForm[pCampo].value = toInteger(pForm[pCampo].value);
//		nerro = true;
//	}
//	else
//	{
//		pForm[pCampo].value = toInteger(pForm[pCampo].value);
//		nerro = false;
//	}
// return nerro;	
//}
function soNumero(texto)
{
	if (isNaN(texto.value)) 
	{
		texto.value="";
		return false;
	}else
		return true;
}

function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
	
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

function soNumeros(v){
    return v.replace(/\D/g,"")
}

//teclas
// 8 - backspace | 13 - enter | 9 - tab | 46 - delete
// 48 ao 57 - 0 ao 9 | 96 ao 105 - numpad 0 ao numpad 9
var keyCodigo = 0;
function soNumeroPress(evento){

	keyCodigo = evento.keyCode;
	if ((keyCodigo == 8 || keyCodigo == 13 || keyCodigo == 9 || keyCodigo == 46) || (keyCodigo >= 48 && keyCodigo <= 57) || (keyCodigo >= 96 && keyCodigo <= 105)) 
	{
		VerifiqueTAB=true; 
		return true;
	}
	else 
	{
		if (detectar('B')=="NP")
		{
			return true;
		}	
		else
		{	 	
			return false;
		}
	}
}

//teclas
// 8 - backspace | 13 - enter | 9 - tab | 46 - delete
// 37 - left arrow | 39 - right arrow
// 48 ao 57 - 0 ao 9 | 96 ao 105 - numpad 0 ao numpad 9
function soNumeroDown(evento){

	keyCodigo = evento.keyCode;
	if ((keyCodigo == 8 || keyCodigo == 13 || keyCodigo == 9 || keyCodigo == 46 || keyCodigo ==37 || keyCodigo ==39) || (keyCodigo >= 48 && keyCodigo <= 57) || (keyCodigo >= 96 && keyCodigo <= 105))
	{ 
		VerifiqueTAB=true; 
		return true;
	}
	else
	{
		if (detectar('B')=="NP")
		{
			return true;
		}	
		else	 	
		{
			return false;
		}
	}
}

//function Mostra(quem, tammax) {
//   if (quem.value.length == tammax) { 
//     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();
//          break;
//       } 
//    } 
//   } 
//} 


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() 
{ 
   VerifiqueTAB=false; 
} 

//<!-- -->

function ChecarTAB(evento) 
{ 
   var voltar=false;
   
   VerifiqueTAB=true; 
   keyCodigo = evento.keyCode;
   
   if ((keyCodigo == 8 || keyCodigo == 13 || keyCodigo == 9 || keyCodigo == 71 ) || (keyCodigo >= 48 && keyCodigo <= 57) || (keyCodigo >= 96 && keyCodigo <= 103) ) 
   {
	voltar=true;
    } 
    else 
    {
	   if (detectar('B')=="NP") voltar=true;
	   else	voltar=false;

    }
	return voltar;
} 



var detect = navigator.userAgent.toLowerCase();
var thestring;	
var versao = parseFloat(navigator.appVersion);
function detectar(tipo)
{ 
	var OS,browser,version,total;
	var retorno
	if (checkIt('konqueror'))
	{
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkIt('omniweb')) browser = "OmniWeb"
	else if (checkIt('opera')) browser = "Opera"
	else if (checkIt('webtv')) browser = "WebTV";
	else if (checkIt('icab')) browser = "iCab"
	else if (checkIt('msie')) browser = "IE"
	else if (!checkIt('compatible'))
	{
		browser = "NP"
		version = detect.charAt(8);
	}
	else browser = "An unknown browser";

	
	
	if (!version) version = detect.charAt(place + thestring.length);
	
	if (!OS)
	{
		if (checkIt('linux')) OS = "Linux";
		else if (checkIt('x11')) OS = "Unix";
		else if (checkIt('mac')) OS = "Mac"
		else if (checkIt('win')) OS = "Windows"
		else OS = "an unknown operating system";
	}
	
	if (tipo=='B')
	  retorno = browser
 	else if (tipo=='O') retorno = OS

    return retorno 	
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

///////////////////////////////novo


	function mOvr(src, cursor, color) {
		if (!src.contains(event.fromElement)) {
			src.style.cursor = cursor;
			src.bgColor = color;
			src.style.fontWeight = 'Normal';
		}
	}

	function mOut(src, cursor, color) {
		if (!src.contains(event.toElement))	{
			src.style.cursor = cursor;
			src.bgColor = color;
			src.style.fontWeight = 'Normal';
		}
	}
	  
	function Ativa_pg(pagina) {
		window.location.href=pagina;
	}

	function abre_copa(arq,alt,lag) {
		if(navigator.appName=="Microsoft Internet Explorer") {
			window.open(arq,'Condi','fullscreen=0,channelmode=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=' + lag + ',height=' + alt + ',top=10,left=10');
		} else {
			window.open(arq,'Condi','location=0,fullscreen=0,menubar=0,toolbar=0,status=0,screenX=10,screenY=10,resizable=0,width=' + lag + ',height=' + alt);
		}
	}


	function abre(arq,alt,lag) {
		if(navigator.appName=="Microsoft Internet Explorer") {
			window.open(arq,'Condi','fullscreen=0,channelmode=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=' + lag + ',height=' + alt + ',top=100,left=100');
		} else {
			window.open(arq,'Condi','location=0,fullscreen=0,menubar=0,toolbar=0,status=0,screenX=100,screenY=100,resizable=1,width=' + lag + ',height=' + alt);
		}
	}
	
	function abre_em(arq,alt,lag,esq,topo) {
		if(navigator.appName=="Microsoft Internet Explorer") {
			window.open(arq,'Condi','fullscreen=0,channelmode=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=' + lag + ',height=' + alt + ',left='+esq+',top='+topo);
		} else {
			window.open(arq,'Condi','location=0,fullscreen=0,menubar=0,toolbar=0,status=0,screenX=100,screenY=100,resizable=1,width=' + lag + ',height=' + alt);
		}
	}
	
	function abre_full(arq) {
		if(navigator.appName=="Microsoft Internet Explorer") {
			window.open(arq,'n_win');
		} else {
			window.open(arq,'n_win');
		}
	}
	function abre2(arq,alt,lag) {
		if(navigator.appName=="Microsoft Internet Explorer") {
			window.open(arq,'Condi','fullscreen=0,channelmode=0,toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=1,menubar=0,width=' + lag + ',height=' + alt + ',top=10,left=10');
		} else {
			window.open(arq,'Condi','location=0,fullscreen=0,menubar=0,toolbar=0,status=0,screenX=0,screenY=0,scrollbars=1,resizable=1,width=' + lag + ',height=' + alt);
		}
	}
	
	function abre_status(arq,alt,lag) {
		if(navigator.appName=="Microsoft Internet Explorer") {
			window.open(arq,'autod','fullscreen=0,channelmode=0,toolbar=0,location=0,directories=0,status=0,scrollbars=yes,resizable=0,menubar=0,width=' + lag + ',height=' + alt + ',top=10,left=10');
		} else {
			window.open(arq,'autod','location=0,fullscreen=0,menubar=0,toolbar=0,status=0,screenX=0,screenY=0,scrollbars=yes,resizable=0,width=' + lag + ',height=' + alt);
		}
	}
	
	function openlink(URL,w,h)
	{
		LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
		settings = 'toolbar=0,scrollbars=0,location=0,status=0,menubar=0,resizable=0,width='+w+',height='+h+',left='+LeftPosition+',top='+TopPosition+''
		day = new Date();
		id = day.getTime();
		eval("page" + id + " = window.open(URL, '"+id+"',settings);");
	}


	function textCounter(field, countfield, maxlimit) {
	/*
	USE:
	<textarea name=message wrap=physical cols=28 rows=4 onKeyDown="textCounter(this.form.message,this.form.remLen,125);" onKeyUp="textCounter(this.form.message,this.form.remLen,125);"></textarea>
	*/
	if (field.value.length > maxlimit) 
		field.value = field.value.substring(0, maxlimit);
	else 
		countfield.value = maxlimit - field.value.length;
}


//*****************************************************************************************************************************
	//NOVAS FUNÇÕES PARA MASCARA DE CPF E CAMPO NUMERICO
//*****************************************************************************************************************************

function isNum( caractere ) 
{ 
         var strValidos = "0123456789" 
         if ( strValidos.indexOf( caractere ) == -1 ) 
                 return false; 
         return true; 
} 

function validaTecla(campo, event) 
{ 
         var BACKSPACE=  8; 
         var key; 
         var tecla; 

         CheckTAB=true; 
         if(navigator.appName.indexOf("Netscape")!= -1) 
                 tecla= event.which; 
         else 
                 tecla= event.keyCode; 


         key = String.fromCharCode( tecla); 

         if ( tecla == 13 ) 
                 return false; 
         if ( tecla == BACKSPACE ) 
                 return true; 
         return ( isNum(key)); 
} 

function troca(str,strsai,strentra)
{
while(str.indexOf(strsai)>-1)
{
str = str.replace(strsai,strentra);
}
return str;
}


function mascaraCPF(campo,tammax,teclapres,caracter)
{
if(teclapres == null || teclapres == "undefined")
{
var tecla = -1;
}
else
{
var tecla = teclapres.keyCode;
}

if(caracter == null || caracter == "undefined")
{
caracter = ".";
}

vr = campo.value;
if(caracter != "")
{
vr = troca(vr,caracter,"");
}
vr = troca(vr,"/","");
vr = troca(vr,",","");
vr = troca(vr,".","");
vr = troca(vr,"-","");

tam = vr.length;
if(tecla > 0)
{
if(tam < tammax && tecla != 8)
{
tam = vr.length + 1;
}

if(tecla == 8)
{
tam = tam - 1;
}
}
if(tecla == -1 || tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105)
{
if(tam <= 2)
{
campo.value = vr;
}
if((tam > 2) && (tam <= 5))
{
campo.value = vr.substr(0, tam - 2) + '-' + vr.substr(tam - 2, tam);
}
if((tam >= 6) && (tam <= 8))
{
campo.value = vr.substr(0, tam - 5) + caracter + vr.substr(tam - 5, 3) + '-' + vr.substr(tam - 2, tam);
}
if((tam >= 9) && (tam <= 11))
{
campo.value = vr.substr(0, tam - 8) + caracter + vr.substr(tam - 8, 3) + caracter + vr.substr(tam - 5, 3) + '-' + vr.substr(tam - 2, tam);
}
if((tam >= 12) && (tam <= 14))
{
campo.value = vr.substr(0, tam - 11) + caracter + vr.substr(tam - 11, 3) + caracter + vr.substr(tam - 8, 3) + caracter + vr.substr(tam - 5, 3) + '-' + vr.substr(tam - 2, tam);
}
if((tam >= 15) && (tam <= 17))
{
campo.value = vr.substr(0, tam - 14) + caracter + vr.substr(tam - 14, 3) + caracter + vr.substr(tam - 11, 3) + caracter + vr.substr(tam - 8, 3) + caracter + vr.substr(tam - 5, 3) + '-' + vr.substr(tam - 2, tam);
}
}
}


// NOVA MÁSCARA

function formatar(src, mask) 
{
  var i = src.value.length;
  var saida = mask.substring(0,1);
  var texto = mask.substring(i)
if (texto.substring(0,1) != saida) 
  {
        src.value += texto.substring(0,1);
  }
}

function validate(field)
{
	var valid = " çÇáàãäâabcdéèëêefghìíïîijklmnòóõöôopqrstùúüûuvwxyzÁÀÃÄÂABCDÉÈËÊEFGHÍÌÏÎIJKLMNÓÒÔÖÔOPQRSTÚÙÜÛUVWXYZ0123456789/'.-,:;=><()+*@%#$!?&\[]{}|_"
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++)
	{
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
		{
			//alert(field.value.substring(i, i+1));
			ok = "no";
		}
	}
	if (ok == "no")
	{
		return false;
    }
    else
    {
 		return true;   
    }
}





