function mascaraTelefone(objeto){
     if (objeto.value.indexOf("-") == -1 && objeto.value.length > 5){ 
     objeto.value = ""; }
     if (objeto.value.length == 3){
     objeto.value +="-";
     }
   }

function mascara_cpf(cpf,teclapres) {
      var mycpf = '';     
      var tecla = teclapres.keyCode;   
	  if ( tecla > 47 && tecla < 58 ){      
       mycpf = mycpf + cpf.value;
       if (mycpf.length == 3) {
          mycpf = mycpf + '.';
          cpf.value = mycpf;
        }
       if (mycpf.length == 7) {
          mycpf = mycpf + '.';
          cpf.value = mycpf;
        }
       if (mycpf.length == 11) {
          mycpf = mycpf + '-';
          cpf.value = mycpf;
        }
       if (mycpf.length == 14) {
        }
      } else event.keyCode = 0;
 }
 
 function mascara_cep(cep)
     {
       var mycep = '';
       mycep = mycep + cep.value;
       if (mycep.length == 5) {
          mycep = mycep + '-';
          cep.value = mycep;
        }
       if (mycep.length == 9) {
        }
     }     
     
 	function mascara_decimal(campo,tammax,teclapres,quantdig,separador) {
		var tecla = teclapres.keyCode;
		vr = document.all[campo].value;
		vr = vr.replace( "/", "" );
		vr = vr.replace( "/", "" );
		vr = vr.replace( ",", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
		tam = vr.length;


		if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

		if (tecla == 8 ){	tam = tam - 1 ; }
			
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
			if ( tam <= quantdig ){ 
	 			document.all[campo].value = vr ; }
	 		if (tam > quantdig && tam!=tammax){
	 			document.all[campo].value = vr.substr( 0, tam - quantdig ) + separador + vr.substr( tam - quantdig, tam ) ; }
		}
			
	}
	
function Tecla(e,negativo){
	if (document.all) // Internet Exploresr
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;
		if (tecla > 47 && tecla < 58) // numeros de 0 a 9
			return true;
		else
			{
				if ((tecla!=8 && tecla!=45) || (tecla==45 && negativo==false)) // backspace
					event.keyCode = 0;
				else
					return true;
			}
}

function Texto(e,negativo){
/*	if (document.all) // Internet Exploresr
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;
		//if (tecla < 47 || tecla > 58)
		if ((tecla > 93 && tecla < 123) || (tecla > 44 && tecla < 58) || (tecla == 231) || (tecla == 32) || (tecla == 126) || (tecla == 180) || (tecla > 223 && tecla < 228) || (tecla == 233) || (tecla == 234) || (tecla == 237) || (tecla == 243) || (tecla == 244) || (tecla == 245) || (tecla == 250) || (tecla == 251) || (tecla > 64 && tecla < 91)) // numeros e a..z
			return true;
		else
			{
				if ((tecla!=8 && tecla!=45) || (tecla==45 && negativo==false)) // backspace
					event.keyCode = 0;
				else
					return true;
			} */
}

function mascara_data(pData){ 
    var tecla = event.keyCode
	if(tecla!=8 ){
		var mydata = ''; 
		mydata = mydata + document.all(pData).value; 
		if (mydata.length == 2){ 
		mydata = mydata + '/'; 
		document.all(pData).value = mydata; 
		} 
		if (mydata.length == 5){ 
		mydata = mydata + '/'; 
		document.all(pData).value = mydata; 
		} 
		if (mydata.length == 10){ 
		verifica_data(pData); 
		} 
	}
} 

function FormataCNPJ(Campo, teclapres){

	var tecla = teclapres.keyCode;

	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1 ;

	
	if (tecla != 9 && tecla != 8){
		if (tam > 2 && tam < 6)
			Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
		if (tam >= 6 && tam < 9)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
		if (tam >= 9 && tam < 13)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
		if (tam >= 13 && tam < 15)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
		}
}

function validaCNPJ(obj) {
                 //CNPJ = document.validacao.CNPJID.value;
                 CNPJ = obj;
                 erro = new String;
                 if (CNPJ.replace(/^\s*|\s*$/g,"") == "") return true;
                 if (CNPJ.length < 18) erro += "É necessario preencher corretamente o número do CNPJ! "; 
                 if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
                 if (erro.length == 0) erro += "É necessário preencher corretamente o número do CNPJ! ";
                 }
                 //substituir os caracteres que não são números
               if(document.layers && parseInt(navigator.appVersion) == 4){
                       x = CNPJ.substring(0,2);
                       x += CNPJ. substring (3,6);
                       x += CNPJ. substring (7,10);
                       x += CNPJ. substring (11,15);
                       x += CNPJ. substring (16,18);
                       CNPJ = x; 
               } else {
                       CNPJ = CNPJ. replace (".","");
                       CNPJ = CNPJ. replace (".","");
                       CNPJ = CNPJ. replace ("-","");
                       CNPJ = CNPJ. replace ("/","");
               }
               var nonNumbers = /\D/;
               if (nonNumbers.test(CNPJ)) erro += "A verificação de CNPJ suporta apenas números! "; 
               var a = [];
               var b = new Number;
               var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
               for (i=0; i<12; i++){
                       a[i] = CNPJ.charAt(i);
                       b += a[i] * c[i+1];
				}
               if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
               b = 0;
               for (y=0; y<13; y++) {
                       b += (a[y] * c[y]); 
               }
               if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
               if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
                       erro +="- CNPJ invalido !!!";
               }
               if (erro.length > 0){
                       alert(erro);
                       return false;
               } 
               return true;
       }

function verifica_data(pData) { 
if(document.all(pData).value != ""){ 
	if (document.all(pData).value.length < 10) {
			situacao = "false";
	}
	var dia = document.all(pData).value.substring(0,2); 
	var mes = document.all(pData).value.substring(3,5); 
	var ano = document.all(pData).value.substring(6,10); 

	situacao = ""; 
	// verifica o dia valido para cada mes 
	if (isNaN(dia)) {
	 situacao = "false"; 
	}
	if ((dia < 01)||(dia < 01 || dia > 30) && ( mes == 04 || mes == 06 || mes == 09 || mes == 11 ) || dia > 31) { 
	situacao = "false"; 
	} 

	// verifica se o mes e valido 
	if (isNaN(mes)) {
	 situacao = "false"; 
	}
	if (mes < 01 || mes > 12 ) { 
	situacao = "false"; 
	} 

	// verifica se e ano bissexto 
	if (isNaN(ano)) {
	 situacao = "false"; 
	}
	if (ano < 1900 ) {
		situacao = "false";
	}
	if (ano > 2010){
		situacao = "false";
	}
	if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) { 
	situacao = "false";
	} 

	if (document.all(pData).value == "") { 
	situacao = "false"; 
	} 

	            
	if (situacao == "false") { 
	alert("Data invalida!"); 
	document.all(pData).value="";
	document.all(pData).focus();            
	} 
}
} 

function MudaClasse( linha, tipo ) {
	if( tipo == "on" ) {
		eval( "document.all."+linha+".className='input1';");
	} else {
		eval( "document.all."+linha+".className='input';");
	}
}

function SelecionaTodosChecks(spanChk){
   var oItem = spanChk.children;
   var theBox= (spanChk.type=="checkbox") ? spanChk : spanChk.children.item[0];
   xState=theBox.checked;
   elm=theBox.form.elements;
   for(i=0;i<elm.length;i++)
     if(elm[i].type=="checkbox" && 
              elm[i].id!=theBox.id)
     {
       if(elm[i].checked!=xState)
         elm[i].click();
    }
 }

function Checkall(tf, field, obj) {
 var Cont = 0;
   
   if (tf[field].length) {
      for (var i=0; i < tf[field].length; i++) {
         tf[field][i].checked = obj.checked;
      }
   }else
      tf[field].checked = obj.checked;
   
   if (tf[obj.name].length) {
	   for (var i=0; i < tf[obj.name].length; i++) {
	   	tf[obj.name][i].checked = obj.checked;
	   }
   }else 
   	 tf[obj.name].checked = obj.checked;
   
   return;
}

function OpenChatWin(pagina, janela, w, h)
{
	window.open(pagina, janela, 'width='+w+',height='+h+',scrollbars=yes,toolbar=yes,location=no,status=yes,menubar=yes,resizable=no,left=0,top=0');
}

function confirmaExclusaoMsg()
{
    if(window.confirm("Deseja realmente excluír esta mensagem?")) 
        return true;
    else 
        return false;
}