/*----------------------------------------------------------------------------------------------------------------------------------*//*
/*-Descricao das funcoes aqui encontradas-------------------------------------------------------------------------------------------*//*
function Tecla(e)													Não permite a digitacao de caracteres em campos que precisam ser numéricos. Usar da seguinte 
																					forma : onKeyPress="return Tecla(event);"
function FormataCNPJ()										onblur="FormataCNPJ(this);"
function FormataIE()											onblur="FormataIE(this);"
function FormataEmail()										onblur="FormataEmail(this);" 
function FormataCEP()											onblur="FormataCEP(this);"
function FormataTelefone()								onKeyPress="return(FormataTelefone(this,event))"
function limpa_string(S){  								Deixa so os digitos de numero
function Formatanumero()									onblur="FormataNumero(this,2);"							
function InsereLinha(<id_tabela>,<texto_excluir>)


function FormataCPF()											onblur="FormataCPF(this);" falta fazer
function FormataRG()											onblur="FormataCPF(this);" falta fazer
/*------------------------------------------------------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------------------------------------------------------*/
function Transforma_Valor_Para_Americano(Texto) {									
	var vl = 0;	
	var Aux = String;
	Aux = Texto;																		
	if (Aux != "") {
			vl = Aux.replace(".", "");
			vl = parseFloat(vl.replace(",", "."));											
	}
	else {
			vl = 0;
	}
	return vl;
}							
/*------------------------------------------------------------------------------------------------------------------------------------*/
function FormataNumero(Controle, CasasDecimais, obrigatorio) {	
	var Valor = Controle.value;	
	var Numero = '';	
  var ContaSeparadorMilhar = 0;
	if ((obrigatorio != true) && (obrigatorio != false)) obrigatorio = true;
  if (CasasDecimais == '') CasasDecimais = 0;	
  if ((Valor.indexOf(',') != -1) || (CasasDecimais == 0)) {	
    //Numero no formato 9.999,99 (tira o separador de milhar e troca vírgula por ponto)  
		do
      Valor = Valor.replace('.', '');		
    while (Valor.indexOf('.') != -1);
    Valor = Valor.replace(',', '.');		
  }
	if ((CasasDecimais ==0) && (Valor == ''))
		Valor = ''
	else
	  Valor = Math.round(Valor * Math.pow(10, CasasDecimais));
  Valor = Valor + '';
  //Valida se só existem números compondo o valor
  for (intI = 0; intI <= Valor.length; intI++) {
    if ('0123456789'.indexOf(Valor.substring(intI, intI + 1)) == -1) {
      Controle.focus();
      alert('O valor informado não é válido, deve conter números e vírgula apenas.');
      return false;
    }
  }      
  //Separa a parte inteira da decimal
  for (var intI = 0; intI < CasasDecimais - Valor.length; intI++) Valor = '0' + Valor;
  var Inteira = Valor.substring(0, Valor.length - CasasDecimais);
  var Decimal = Valor.substring(Valor.length - CasasDecimais);      	
  //Formata
  for (var intI = Inteira.length - 1; intI >= 0; intI--) {
    Numero = Inteira.substring(intI, intI + 1) + Numero;  
    ContaSeparadorMilhar = ContaSeparadorMilhar + 1;
    if (ContaSeparadorMilhar == 3) {
      ContaSeparadorMilhar = 0;
      if (intI != 0) Numero = '.' + Numero;
    }
  }       
	
	if (CasasDecimais > 0) {
	  Numero = Numero + ',' + Decimal;
	}
	if (Numero.substring(0, 1) == ',') Numero = '0' + Numero;
	if ((obrigatorio == false) && (Numero == "0,00")) {
		Numero="";
	}
  Controle.value = Numero;
  return false;      
}
/*------------------------------------------------------------------------------------------------------------------------------------*/
function FormataTelefone(objeto, evento) {
	var key = '';
	var len = 0;
	var strCheck = '0123456789';
	var aux = '';
	var whichCode = (window.Event) ? evento.which : evento.keyCode;
	if (whichCode == 13 || whichCode == 8 || whichCode == 0)  return true;  // Enter backspace ou FN qualquer um que não seja alfa numerico
	key = String.fromCharCode(whichCode);
	if (strCheck.indexOf(key) == -1)	return false;  //NÃO E VALIDO
	aux =  limpa_string(objeto.value);
	len = aux.length;
	if(len>=10)	return false;	//impede de digitar um telefone maior que 10
	aux += key;
	objeto.value = Telefone_Mont_Format(aux);
	return false;
}
function  Telefone_Mont_Format(Telefone){
	var aux = len = '';
	len = Telefone.length;
	if(len<=9) tmp = 5;
	else tmp = 6;
	aux = '';
	for(i = 0; i < len; i++) {
		if(i==0) 	aux = '(';
		aux += Telefone.charAt(i);
		if(i+1==2) aux += ')';
		if(i+1==tmp) aux += '-';
	}
	return aux ;
}
/*------------------------------------------------------------------------------------------------------------------------------------*/
function FormataCEP(objeto){ 
  vr  = limpa_string(objeto.value); 
  tam = vr.length;
	if (tam > 0) {
 		if (tam == 8) { 					
			objeto.value = objeto.value.substr(0,5) + "-" + objeto.value.substr(5,3);
		} else {
		  alert('Campo CEP inválido!');
			objeto.select();
			objeto.focus();
			return false; 
		}
	}
	return true;   
} 
/*------------------------------------------------------------------------------------------------------------------------------------*/
function FormataIE(objeto){   
	vr = limpa_string(objeto.value);
	tam = vr.length; 
	if (tam > 0) {
		if (tam == 12) {  	
			objeto.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '.' + vr.substr(9,3); 		
		} else {
	  	alert('Campo IE inválido!');
	  	objeto.select();
	  	objeto.focus();
	  	return false;
		}
	}
	return true;   
} 
/*------------------------------------------------------------------------------------------------------------------------------------*/
function FormataCNPJ(objeto){  
	vr = objeto.value; 
	tam = vr.length; 
	if (tam > 0) {
		if (valida_CNPJ(vr)) {
	  	vr = limpa_string(vr);
			if (vr.indexOf(".") == -1 ) { 
  			if (tam <= 2) objeto.value = vr; 
				if ((tam > 2) && (tam <= 6)) objeto.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, tam ); 
				if ((tam >= 7) && (tam <= 10)) objeto.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '/'; 
				if ((tam >= 11) && (tam <= 18)) objeto.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '/' + vr.substr( 8, 4 ) + '-' + vr.substr( 12, 2 ) ; 
			}
		} else {
	  	alert("Campo CNPJ inválido!");
			objeto.select();
			objeto.focus();
			return false; 
		}
	}
	return true;   
} 
/*------------------------------------------------------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------------------------------------------------------*/
function valida_CNPJ(s) {
 var i;
 s = limpa_string(s);
 var c = s.substr(0,12);
 var dv = s.substr(12,2);
 var d1 = 0;
 for (i = 0; i < 12; i++) d1 += c.charAt(11-i)*(2+(i % 8));
 if (d1 == 0) return false;
 d1 = 11 - (d1 % 11);
 if (d1 > 9) d1 = 0;
 if (dv.charAt(0) != d1) return false;
 d1 *= 2;
 for (i = 0; i < 12; i++)  d1 += c.charAt(11-i)*(2+((i+1) % 8));
 d1 = 11 - (d1 % 11);
 if (d1 > 9) d1 = 0;
 if (dv.charAt(1) != d1) return false;
 return true;
}
/*------------------------------------------------------------------------------------------------------------------------------------*/
function FormataEmail(objeto){ 
  if (objeto.value != "") {  		
		prim = objeto.value.indexOf("@"); 
		if (prim < 2) { 
			alert("O e-mail informado parece não estar correto.");
			objeto.select();objeto.focus();
			return false;
		}
		if(objeto.value.indexOf("@",prim + 1) != -1) {
			alert("O e-mail informado parece não estar correto.");
			objeto.select();objeto.focus();
			return false;
		}
		if(objeto.value.indexOf(".") < 1) {
			alert("O e-mail informado parece não estar correto.");
			objeto.select();objeto.focus();
			return false;
		}
		if(objeto.value.indexOf(" ") != -1) {
			alert("O e-mail informado parece não estar correto.");
			objeto.select();objeto.focus();
			return false;
		}
		if(objeto.value.indexOf("zipmeil.com") > 0) {
			alert("O e-mail informado parece não estar correto.");
			objeto.select();objeto.focus();
			return false;
		}
		if(objeto.value.indexOf("hotmeil.com") > 0) {
			alert("O e-mail informado parece não estar correto.");
			objeto.select();objeto.focus();
			return false;
		}
		if(objeto.value.indexOf(".@") > 0) {
			alert("O e-mail informado parece não estar correto.");
			objeto.select();objeto.focus();
			return false;
		}
		if(objeto.value.indexOf("@.") > 0) {
			alert("O e-mail informado parece não estar correto.");
			objeto.select();objeto.focus();
			return false;
		}
		if(objeto.value.indexOf(".com.br.") > 0) {
			alert("O e-mail informado parece não estar correto.");
			objeto.select();objeto.focus();
			return false;
		}
		if(objeto.value.indexOf("/") > 0) {
			alert("O e-mail informado parece não estar correto.");
			objeto.select();objeto.focus();
			return false;
		}
		if(objeto.value.indexOf("[") > 0) {
			alert("O e-mail informado parece não estar correto.");
			objeto.select();objeto.focus();
			return false;
		}
		if(objeto.value.indexOf("]") > 0) {
			alert("O e-mail informado parece não estar correto.");
			objeto.select();objeto.focus();
			return false;
		}
		if(objeto.value.indexOf("(") > 0) {
			alert("O e-mail informado parece não estar correto.");
			objeto.select();objeto.focus();
			return false;
		}
		if(objeto.value.indexOf(")") > 0) {
			alert("O e-mail informado parece não estar correto.");
			objeto.select();objeto.focus();
			return false;
		}
		if(objeto.value.indexOf("..") > 0) {
			alert("O e-mail informado parece não estar correto.");
			objeto.select();objeto.focus();
			return false;
		}
	}
	return true;
}
/*------------------------------------------------------------------------------------------------------------------------------------*/
function limpa_string(S){ // Deixa so' os digitos no numero
 var Digitos = "0123456789";
 var temp = "";
 var digito = "";
 for (var i=0; i<S.length; i++) {
  digito = S.charAt(i);
  if (Digitos.indexOf(digito)>=0) {
   temp=temp+digito }
 } //for
 return temp
}
/*------------------------------------------------------------------------------------------------------------------------------------*/

function Tecla(e){ 
  document.all;
	if (document.all) // Internet Explorer
	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) // backspace
			event.keyCode = 0; //return false;
		else
			return true;
	}	
}

/*------------------------------------------------------------------------------------------------------------------------------------*/
function TiraVirgula(e,campo){ 		
  var CasasDecimais;
	CasasDecimais = 0;
  if (campo.value.indexOf(",", 0) >= 0) {
		alert('Quantidade de parcelas informada é inválida.\n');
		/*
		conteudo = campo.value;
		conteudo = Transforma_Valor_Para_Americano(conteudo);		
		conteudo = Math.round(conteudo * Math.pow(10, CasasDecimais));
		conteudo = conteudo + '';										
		//Separa a parte inteira da decimal									
		for (var intI = 0; intI < CasasDecimais - conteudo.length; intI++) conteudo = '0' + conteudo;																				
			var Inteira = conteudo.substring(0, conteudo.length - CasasDecimais);
		campo.value =Inteira;
		*/
		campo.value = 0;
	}else{
	  return true;
	}
}
/*-------------------------------------------------------------------------------------------------------------------------------------*/
function tira_ponto(){
  if (document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;	

		if (tecla == 46) tecla = 44;				
		if (tecla > 47 && tecla < 58)  // numeros de 0 a 9 e ',' e '.'
		  if (tecla == 44) 
				if (campo.value.indexOf(",", 0) >= 0) 
					return false;
				else
					return true;
			else
				return true;
	else {
		if (tecla != 8) // backspace
			event.keyCode = 0; //return false;
		else
			return true;
	}	
}

function TeclaComPontuacao(e,campo){ 
	if (document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;	

		if (tecla == 46) tecla = 44;
				
		if ((tecla > 47 && tecla < 58) || (tecla == 44))  // numeros de 0 a 9 e ',' e '.'
		  if (tecla == 44) 
				if (campo.value.indexOf(",", 0) >= 0) 
					return false;
				else
					return true;
			else
				return true;
	else {
		if (tecla != 8) // backspace
			event.keyCode = 0; //return false;
		else
			return true;
	}	
}
/*-------------------------------------------------------------------------------------------------------------------------------------*/
function ValidaData(dateStr) {
				var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
				var matchArray = dateStr.match(datePat); // o formato está ok?

				if (matchArray == null) {
						alert("Informe a data");
						return false;
				}

				month = matchArray[3]; // p@rse date into variables
				day   = matchArray[1];
				year  = matchArray[5];
				
				if (month < 1 || month > 12) { // check month range
						alert("O mês deve estar entre 1 e 12");
						return false;
				}
				
				if (day < 1 || day > 31) {
						alert("O dia deve estar entre 1 e 31");
						return false;
				}
				
				if ((month==4 || month==6 || month==9 || month==11) && day==31) {
						if (month == 4) {
								auxMes = 'abril';
						}
						else {
								if (month == 6) {
										auxMes = 'junho';
								}
								else {
										if (month == 9){
												auxMes = 'setembro';
										}
										else {
												if (month == 11) {
														auxMes = 'novembro';
												}
												else {
														auxMes = month;
												}
										}
								}
						}
						alert("O mês de "+auxMes+" não tem 31 dias!")
						return false;
				}
				
				if (month == 2) { // check for february 29th
						var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
						if (day > 29 || (day==29 && !isleap)) {
								alert("Fevereiro de " + year + " não tem " + day + " dias!");
								return false;
						}
				}
				return true; // data é valida
}
/*-------------------------------------------------------------------------------------------------------------------------------------*/
function TrocaCaracteres(campo){	
					for (i = 0; i < campo.value.length; i++) {							
							if (campo.value.charAt(i) == ".") {
									campo.value = campo.value.replace(".", ",");									
							}
					}
}
/*-------------------------------------------------------------------------------------------------------------------------------------*/
function ValorReal(Texto) {
					Texto = Texto.replace(".", "");
					Texto = parseFloat(Texto.replace(",", "."));
					
					return Texto;
}
/*-------------------------------------------------------------------------------------------------------------------------------------*/
var NS4 = (document.layers);    // Which browser?
var IE4 = (document.all);
var win = window;    // window to search.
var n   = 0;
function findInPage(str) {
  var txt, i, found;
  if (str == "")
    return false;
  // Find next occurance of the given string on the page, wrap around to the
  // start of the page if necessary.
  if (NS4) {
    // Look for match starting at the current point. If not found, rewind
    // back to the first match.
    if (!win.find(str))
      while(win.find(str, false, true))
        n++;
    else
      n++;
    // If not found in either direction, give message.
    if (n == 0)
      alert("Nenhuma informação foi encontrada.");
  }
  if (IE4) {
    txt = win.document.body.createTextRange();
    // Find the nth match from the top of the page.
    for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
      txt.moveStart("character", 1);
      txt.moveEnd("textedit");
    }
    // If found, mark it and scroll it into view.
    if (found) {
      txt.moveStart("character", -1);
      txt.findText(str);
      txt.select();
      txt.scrollIntoView();
      n++;
    }
    // Otherwise, start over at the top of the page and find first match.
    else {
      if (n > 0) {
        n = 0;
        findInPage(str);
      }
      // Not found anywhere, give message.
      else
        alert("Nenhuma informação foi encontrada.");
    }
  }
  return false;
}
function confere(valor){
  if (checaCPF(valor.value)) {  
  }else {
	 	 errors="1";
     if (errors) alert('O CPF informado é inválido.');		
		 valor.focus();
   }	
}

 function checaCPF (CPF) {	
	if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
		CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
		CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
		CPF == "88888888888" || CPF == "99999999999")
		return false;
	soma = 0;
	for (i=0; i < 9; i ++)
		soma += parseInt(CPF.charAt(i)) * (10 - i);
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		resto = 0;
	if (resto != parseInt(CPF.charAt(9)))
		return false;
	soma = 0;
	for (i = 0; i < 10; i ++)
		soma += parseInt(CPF.charAt(i)) * (11 - i);
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		resto = 0;
	if (resto != parseInt(CPF.charAt(10)))
		return false;
       // alert('Correto');
	return true;
 }

<!--
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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { if (val.title != "") nm=val.title; else nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' deve conter um endereço de e-mail.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' deve conter um número.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' deve conter um número entre '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' é obrigatório.\n'; }
  } if (errors) alert('Os seguintes erros foram encontrados:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function valida_arquivo_imagem(campo, titulo) {
	arq = campo.value;
	
	if (arq != "") {
		arq_part = arq.split(".");
		fileExt = arq_part[arq_part.length-1].toLowerCase();
		if ((fileExt != "") && (fileExt != "swf") && (fileExt != "gif") && (fileExt != "jpg") && (fileExt != "jpeg") && (fileExt != "png")) {
			alert('As extensões de arquivos válidas para o campo ' + titulo + ' são: swf, gif, jpg, jpeg, png');
			return false;
		}
		else 
			return true;
	}
	else 
		return true;
}

function mascara_data(data, obj, e){ 		
		var mydata = ''; 
		mydata = mydata + data; 
		if (mydata.length == 2){ 
				mydata = mydata + "/"; 
				if ((TeclouBkSpc(e) == false) )
					obj.value = mydata; 
		} 
		if (mydata.length == 5){ 
				mydata = mydata + "/"; 
				if ((TeclouBkSpc(e) == false) )
					obj.value = mydata; 
		} 
} 
	
function verifica_data (obj) { 

	dia = (obj.value.substring(0,2)); 
	mes = (obj.value.substring(3,5)); 
	ano = (obj.value.substring(6,10)); 

	situacao = ""; 
	// verifica o dia valido para cada mes 
	if ((dia < 01)||(dia < 01 || dia > 30) && (  mes == 04 || mes == 06 || mes == 09 || mes == 11 ) || dia > 31) { 
			situacao = "falsa"; 
	} 

	// verifica se o mes e valido 
	if (mes < 01 || mes > 12 ) { 
			situacao = "falsa"; 
 } 

	// verifica se e ano bissexto 
	if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) { 
			situacao = "falsa"; 
	} 

	if (obj.value == "") { 
			situacao = "OK"; 
	} 

	if (situacao == "falsa") { 
			alert("Data inválida!"); 
			obj.focus(); 
	} 
} 
function TeclouBkSpc(e){ 
	document.all;
	if (document.all) // Internet Explorer
		var tecla = event.keyCode;
	else 
		if(document.layers) // Nestcape
			var tecla = e.which;
			
	if (tecla == 8) // numeros de 0 a 9
		return true;
	else
		return false;	
}
//-->