function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function findObj(n, d) { //v3.0
  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.getElementById) x=d.getElementById(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=findObj(n,d.layers[i].document); return x;
}

function MM_findObj(n, d) { //v3.0
  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.getElementById) x=d.getElementById(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); return x;
}

function ShowHideLayers() { //v3.0
  var i,p,v,obj,args=ShowHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_showHideLayers() { //v3.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) {
	  	if ((obj=MM_findObj(args[i]))!=null) { 
			v=args[i+2];
			if (obj.style) { 
				obj=obj.style; 
				v=(v=='show')?'visible':(v='hide')?'hidden':v;
			}
	    	obj.visibility=v;
		}
	}
}

function mascara_data(data){ 
    var mydata = ''; 
    mydata = mydata + data.value; 
    if (mydata.length == 2){ 
        mydata = mydata + '/'; 
        data.value = mydata; 
    } 
    if (mydata.length == 5){ 
        mydata = mydata + '/'; 
        data.value = mydata; 
    } 
    if (mydata.length == 10){ 
        verifica_data(data); 
    } 
}
       
function verifica_data (data) { 

  dia = (data.value.substring(0,2)); 
  mes = (data.value.substring(3,5)); 
  ano = (data.value.substring(6,10)); 

  situacao = ""; 
  // verifica o dia valido para cada mes 
  if ((dia < 1) ||
      ((dia < 1 || dia > 30) && (mes == 4 || mes == 6 || mes == 9 || 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 (data.value == "") { 
      situacao = "falsa"; 
  } 

  if (situacao == "falsa") { 
      alert("Data inválida!"); 
      data.focus(); 
  } 
} 

function mascara_hora(hora){ 
    var myhora = ''; 
    myhora = myhora + hora.value; 
    if (myhora.length == 2){ 
        myhora = myhora + ':'; 
        hora.value = myhora; 
    } 
    if (myhora.length == 5){ 
        verifica_hora(hora); 
    } 
} 
 
function verifica_hora(hora){ 
    hrs = (hora.value.substring(0,2)); 
    min = (hora.value.substring(3,5)); 
    
    situacao = ""; 
    // verifica data e hora 
    if ((hrs < 00 ) || (hrs > 23) || ( min < 00) ||( min > 59)){ 
        situacao = "falsa"; 
    } 
     
    if (hora.value == "") { 
        situacao = "falsa"; 
    } 

    if (situacao == "falsa") { 
        alert("Hora inv?lida!"); 
        hora.focus(); 
    } else
        hora.value += 'h'; 
} 

/*
	MUDA COR DO FUNDO DA LINHA DA TABELA
*/
function mark(face,field_color,text_color)
{
	if (document.documentElement); //if browser is IE5+ or NS6+
	{
		face.style.backgroundColor=field_color;
		face.style.color=text_color;
	}
}

//Limitar digita??o em um textarea
function maxTxt(txarea, t) 
{ 
    total = t; 
    tam = txarea.value.length; 
    str=""; 
    str=str+tam; 
     
    Digitado.innerHTML = str; 
    Restante.innerHTML = total - str; 

    if (tam > total){ 
       aux = txarea.value; 
       txarea.value = aux.substring(0,total); 
	   Digitado.innerHTML = total 
       Restante.innerHTML = 0 
	   alert("Limite de carecteres esgotado!");
    }
} 


function validarData(d1, d2) {
	diap = parseInt(d1.substring(0,2));
	mesp = parseInt(d1.substring(3,5));
	anop = parseInt(d1.substring(6,10));

	diae = parseInt(d2.substring(0,2));
	mese = parseInt(d2.substring(3,5));
	anoe = parseInt(d2.substring(6,10));
	
	if(anop > anoe){
		alert("Data de publica??o maior que a data de expira??o! ("+ formNoticias.data_publicar.value+" X "+formNoticias.data_expirar.value+")");
		return false;
	} else {

		if(mesp > mese) {
			alert("Data de publica??o maior que a data de expira??o! ("+ formNoticias.data_publicar.value+" X "+formNoticias.data_expirar.value+")");
			return false;
		} else {

			if(diap > diae) {
				alert("Data de publica??o maior que a data de expira??o! ("+ formNoticias.data_publicar.value+" X "+formNoticias.data_expirar.value+")");
				return false;
			}
		
		}
	
	}
	return true;
}

function janela(a , b , c , d) { 
	var arquivo= a;
	var janela= b;
	var largura=c;
	var altura=d;
	posx = (screen.width/2)-(largura/2); 
	posy = (screen.height/2)-(altura/2);
	features="width=" + largura + " height=" + altura + " top=" + posy + " left=" + posx + " status=yes scrollbars=yes"; 
	newin = window.open(arquivo,janela,features);
	newin.focus();
} 
function janela_2(a , b , c , d) { 
	var arquivo= a;
	var janela= b;
	var largura=c;
	var altura=d;
	posx = (screen.width/2)-(largura/2); 
	posy = (screen.height/2)-(altura/2);
	features="width=" + largura + " height=" + altura + " top=" + posy + " left=" + posx + " status=yes, scrollbars=yes"; 
	newin = window.open(arquivo,janela,features);
	newin.focus();
} 
/********* CORES TABELAS **********/

function TrocaCor (cor, obj) {
	eval(obj).style.background = cor;
}

function SelecionaTD (obj) {
	TrocaCor ("#F4F4F4", obj)
}

function DeselecionaTD (obj) {
	TrocaCor ("#FFFFFF", obj)
}


function recebeNews(){
	if (document.frmNews.nome.value == ""){
			alert("Por favor preencha o campo Nome.");
			document.frmNews.nome.focus();
	}else if (document.frmNews.email.value == ""){
			alert("Por favor preencha o campo E-mail.");
			document.frmNews.email.focus();
	}else if (!/^([a-zA-Z0-9]+([_\-\.]{0,1}[a-zA-Z0-9]{1,})*)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(document.frmNews.email.value)) {
			alert('Valor do campo E-mail inv?lido, por favor, entre com um endere?o de e-mail v?lido');
			document.frmNews.email.focus();
	}else {
			janela('cadastro_newsletter.jsp?nome='+document.frmNews.nome.value+'&email='+document.frmNews.email.value,'LerNews',370,270);
	}
}
hoje = new Date()
dia = hoje.getDate()
dias = hoje.getDay()
mes = hoje.getMonth()
ano = hoje.getYear()
if (dia < 10) dia += 0;
if (ano < 1000) ano += 1900;
NomeDia = new Array("Domingo","Segunda-Feira","Ter&ccedil;a-Feira","Quarta-Feira","Quinta-Feira","Sexta-Feira","S&aacute;bado");
NomeMes = new Array("Janeiro","Fevereiro","Mar&ccedil;o","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro");
function escreveData()
{
	if (ano == '1900') ano = '2000';
	document.write (" " + dia + " de " + NomeMes[mes] + " de " + ano+".&nbsp;&nbsp;")
}

function isNumeric(strTexto){
	//verifica se uma string é um número inteiro
	//Obs.: utiliza a função isEmpty
	if (isEmpty(strTexto)) {
		return false;
	}
	var strNum = "0123456789";
	for (var i=0; i < strTexto.length; i++) {
		if (strNum.indexOf(strTexto.charAt(i)) < 0)
			return false;			
	}
	return true;
}
	
function isValidPassword(strTexto) {
	//retorna true se uma senha tiver 8 dígitos ou mais
	if (strTexto.length >= 8 && strTexto.length <= 15) 
		return true;
	else
		return false;
}

function IsCEP(cep) {
	//verifica se o CEP está corretamente digitado aceitando apenas números
	var i, strCEP = "0123456789";
	alert (cep.value);
	
	if (cep.length != 8) return false;
					
	for (i=0; i<cep.length; i++) {
		if ( strCEP.indexOf(cep.charAt(i)) < 0 )
			return false;
	}
	return true;
}

function Correio(){
	newwindow = window.open("http://www.correios.com.br/servicos/cep/default.cfm", "wind_cep","width=800,height=450,scrollbars,resizable,0,0,0,0,0,0,0,0,0,0");
	newwindow.focus();
}

//Funcao que coloca o traco no CEP
//Recebe como entrada um CEP valido, jah testado
function formataCEP(strCEP){
	var strvalid = "0123456789", i = 0, strFormatado = "";
	//retira os caracteres que não forem números para aplicar o algoritmo
	while (i < strCEP.length) {
		if (strvalid.indexOf(strCEP.charAt(i)) < 0) {
			strCEP = strCEP.substring(0,i) + strCEP.substring(i+1,strCEP.length)
		} else i++;	
	}
	for(i=0; i<5; i++)
		strFormatado += strCEP.charAt(i);
	strFormatado += "-";
	for(i=5; i<strCEP.length; i++)
		strFormatado += strCEP.charAt(i);
	return strFormatado;		
}

function Trim(theString) {
	var aString = theString;
	var newString = "";
	var kBlank = " ";
	if (aString.indexOf(kBlank) >= 0) {
		for (var i = 0; i < aString.length; i++)
			if (aString.charAt(i) != kBlank)
				break;
		for (var j =  aString.length-1; j >= 0; j--)
			if (aString.charAt(j) != kBlank)
				break;
		if (i == aString.length && j == -1)
			newString = "";
		else
			if (i != 0 || j != aString.length -1)
				newString = Trim(aString.substring(i, j+1));
			else
				newString = aString.charAt(i) + Trim(aString.substring(i+1, j+1)) + aString.charAt(j+1);
	} else {
		newString = aString;
	}		
	return newString;
}

function trimOpcao(theString) {
	theString = Trim(theString)
	i = 0
	while (i < theString.length) {
		if (theString.charCodeAt(i) == 13 || theString.charCodeAt(i) == 10) {
			theString = theString.substring(0,i) + theString.substring(i+1,theString.length);
		} else {
			i++;
		}
	}
	return theString;
}

function verificaNumero(num, e, d){
	var aux, retorno;
		
	retorno = true;
	
	//aux = new Array();
	aux = num.split(",");
	
	if(aux[0].length > e)
		retorno = false;
			
	if(aux.length > 1){
		if(aux[1].length > d)
			retorno = false;
	}
	
	return retorno;
}
	
function buscaValida(strBusca)
	{
		var strvalid = "0123456789 ABCDEFGHIJKLMNOPQRSTUVXYZ().-,;", i = 0, strFormatado = "";
		strBusca = Trim(strBusca);
		strBusca = strBusca.toUpperCase();
				
		//retira os caracteres que não forem números para aplicar o algoritmo
		while (i < strBusca.length)
		{
			if (strvalid.indexOf(strBusca.charAt(i)) < 0)
				return false;
			else
				i++;
		}
		
		return true;
	}	
	
function tiraFoco(){
	document.body.focus();
}

function IsCPF(strCPF){
	if ((strCPF.length <11) || (strCPF.length >14)) {
		 return false;
	} else {  
		if ((strCPF != "11111111111") && (strCPF != "22222222222") && (strCPF != "33333333333") && (strCPF != "44444444444") && (strCPF != "55555555555") && (strCPF != "66666666666") && (strCPF != "77777777777") && (strCPF != "88888888888") && (strCPF != "99999999999") && (strCPF != "00000000000")) {
			strCor='';
			for (i=0;i<strCPF.length;i++){
				if ((strCPF.charAt(i)>='0')&&(strCPF.charAt(i)<='9')){
					strCor = strCor + strCPF.charAt(i);
				}
			}    
			if (strCor.length != 11)
				return false;
			else {
				cv = 0;
				for (i=0;i<9;i++){
					cv = cv + strCor.charAt(i)*(i+1);
				}
				cv = cv%11;
				if (cv==10) 
					cv = 0;
				if ( cv != strCor.charAt(9))
					return false;
				cv = 0;
				for (i=0;i<9;i++){
					cv = cv + strCor.charAt(i+1)*(i+1);
				}
				cv = cv%11;
				if (cv==10) 
					cv = 0;
				if ( cv != strCor.charAt(10))
					return false;
			}  
		} else return false;
	}
	return true;  
}

function IsStrValid(strToValidate, strValidChar) {
	var flag;
	var i;
	flag = true;
	
	if ((Trim(strToValidate) != "") && (Trim(strValidChar) != "")) {
		for (i=0;i<strToValidate.length;i++) {
			if (strValidChar.indexOf(strToValidate.charAt(i).toLowerCase()) == -1) {
				flag = false;
				return flag
			}
		}
	} else flag = false;
	
	return flag;
}

function isDate(strData){
	//verifica se a data foi digitada corretamente
	strData = retiraEspaco(strData);
	if (isEmpty(strData)) 
		return false;
	var strNum = "0123456789/";
	var Size = strData.length;
	//testa a validade dos caracteres que formam a data
	for (var i=0; i<Size; i++) {
		if (strNum.indexOf(strData.charAt(i)) < 0)
			return false;
	}
		
	var Pos1 = strData.indexOf("/");
	var Pos2 = strData.lastIndexOf("/");
	if (!(Pos1==2 && Pos2==5)) return false;
					
	a = strData.split("/");
	if (a.length == 3 && a[2].length==4 && a[2]>0) {
		if ((a[1]<1) || (a[1]>12)) 
			return false;
		else if ((a[0]<1) || (a[0]>numDias(a[1], a[2])))
				return false;
	} else return false;
		
	return true;
}

// ************ Validação de Data **********************
function isSmallDate(strData){
	strData = strData + "/2000";
	if (!isDate(strData))
		return false;
	return true;
}

function retiraEspaco(theString) {
	//retira todos os espaços de uma string
	if (theString.indexOf(" ") >= 0) {
		var i = 0;
		while (theString.indexOf(" ") >= 0) {
			if (theString.charAt(i) == " ") 
				theString = theString.substring(0,i) + theString.substring(i+1,theString.length);
			else i++
		}
		newString = theString;
	} 
	else newString = theString;
	return newString;
}

function numDias(intMes,intAno)	{
	//retorna o número de dias de um mês em um ano qualquer
	var Dias;
	intMes = parseInt(intMes, 10);
	intAno = parseInt(intAno, 10);
		
	switch(intMes) {
		case 1: 
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12: Dias = 31; break;
		case 4:
		case 6:
		case 9:
		case 11: Dias = 30;	break;
		case 2:
			Dias = 28;
			if (((intAno%400)==0) || ((intAno%100)!=0 && (intAno%4)==0)) 
				Dias++; 
				break;
		default:
			Dias = 0;
			alert("DATA DESCONHECIDA");
	}
	return Dias;
}
		
function isEmpty(str) {
	//verifica se alguma coisa foi digitada num determinado campo
	if (str == null || str == "")
		return true;
	return false;
}
		
//Função que testa um número
// t - Número a ser testado
// d - Usar decimais ou nao	
function isNumber(t,d) {
	var i, sepused;
	if (t == "")
		return false;
	sepused = false;
	
	for (i=0;i<t.length;i++) {
		if (Trim(t.substr(i,1)) == "" || (isNaN(t.substr(i,1)) && ((t.substr(i,1) != ",") || !d || sepused || i==0 || i==t.length-1)))
		   return false;
		if (t.substr(i,1) == ",")
		   sepused = true;	
	}
  return true;     
}

function formataHora(lStrHorario){
	
	//Coloca o 0 na frete do horario, caso nao tenha
	a = lStrHorario.split(":");
	if(a[0].length == 1)
		a[0] = "0" + a[0];
	
	lStrHorario = a[0] + ":" + a[1];
	
	return lStrHorario;
}

// Valida hora, minuto, segundo
// O parâmetro lStrHorario deve estar no formato hh:mm ou hh:mm:ss
function isHour(lStrHorario)
{
	var lHora, lMinuto, lSegundo, lPrimeiroSeparador, lSegundoSeparador
	
	if (lStrHorario.length < 5){
		return false
	}
	if (lStrHorario.length > 8){
		return false
	}
	
	lHora = lStrHorario.substr(0, 2)
	lPrimeiroSeparador = lStrHorario.substr(2, 1)
	if (lPrimeiroSeparador != ':'){
		return false
	}
	lMinuto = lStrHorario.substr(3, 2)
	if (lStrHorario.length > 5){
		lSegundoSeparador = lStrHorario.substr(5, 1)
		if (lSegundoSeparador != ':'){
			return false
		}
		lSegundo = lStrHorario.substr(6, 2)
		if (lSegundo.length < 2){
			return false
		}
	}
	
    //Valida Hora
    if (!(fJSIsNumber(lHora))){
		return false
	}
	if (!(fJSInRange(lHora, 0, 23))){
		return false
	}
		
	//Valida Minuto
	if (!(fJSIsNumber(lMinuto))){
		return false
	}
	if (!(fJSInRange(lMinuto, 0, 59))){
		return false
	}
		
	//Valida Segundo
	if (lStrHorario.length > 5){
		if (!(fJSIsNumber(lSegundo))){
			return false
		}
		if (!(fJSInRange(lSegundo, 0, 59))){
			return false
		}
	}
	return true
}

//Funcoes utilizadas para validação do horario
function fJSInRange( inputStr, ini, fim ){
  var num = parseInt(inputStr, 10)
  if ( num < ini || num > fim ) {
     return false
  }
  return true
}

function fJSIsNumber( num ){
    var numeros = '0123456789,';
    var valor = num.toString();
	var lCount = 0;
	alert ('aqui');
	for ( var i=0; i < valor.length; i++ ){
	      if ( numeros.indexOf( valor.substr(i,1) ) == -1 ) 
	      {
	          return false
	      }
	      
	      if ( valor.substr(i,1) == ',' ) {
	         lCount += 1
	         if ( lCount > 1 ) { return false }
	      }
    }
    return true
}

//Funcao que coloca os ':' no horario
function formataHora(index,evento,form) {
	var tecla = evento.keyCode;
	vr = form[index].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ":", "" );
	vr = vr.replace( ":", "" );
	tam = vr.length + 1;
	if (((tecla >= 48) && (tecla <= 57)) || ((tecla == 9) || (tecla == 8))){
		if ( tecla != 9 && tecla != 8 ){
			if ( tam == 3 )
				form[index].value = vr.substr( 0, tam - 1  ) + ':' + vr.substr( tam - 1, tam );
		}		
	}
	else{
		evento.returnValue = false;
	}
}

//Funcao que coloca as '/' na data
function formataData(index,evento,form) {
	var tecla = evento.keyCode;
	vr = form[index].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;
	if (((tecla >= 48) && (tecla <= 57)) || ((tecla == 9) || (tecla == 8))){
		if ( tecla != 9 && tecla != 8 ){
			if ( tam == 3 )
				form[index].value = vr.substr( 0, tam - 1  ) + '/' + vr.substr( tam - 1, tam );
			if ( tam > 3 && tam < 5 )
				form[index].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
			if ( tam >= 5 && tam <= 10 )
				form[index].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 );
		}		
	}
	else{
		evento.returnValue = false;
	}
}

function isEmail(str) {
//verifica se o e-mail digitado é válido 
	var strAlfa = "ABCDEFGHIJKLMNOPQRSTUWVXYZ";
	var strNum = "0123456789";
	var strSpecial = "_.-@";
	var strValid = strAlfa + strNum + strSpecial;
	var email = str.toUpperCase();
	//verifica se os caracteres do e-mail são válidos
	for (i=0; i<email.length; i++) {
		if (strValid.indexOf(email.charAt(i)) < 0) {
			return false;
		}
	}
		var strC = "@."; 
	//verifica se o e-mail contém @ e . (caracteres obrigatórios)
	for (i=0; i<strC.length; i++) {
		if (email.indexOf(strC.charAt(i)) < 0) 
			return false;
	}
	if (email.indexOf("@") != email.lastIndexOf("@"))
		return false;
	if (email.indexOf("@") > email.lastIndexOf("."))
	    return false;
	if (email.charAt(email.indexOf("@") + 1) == ".")
	    return false;
	if (!(email.indexOf("@") != 0 && email.lastIndexOf(".") != email.length-1))
		return false;
	if (str.substring(0,3) == "www")
		return false;
	if (str.substr(0,4) == "http")
		return false;
						
	return true;
}
		
function isMoney(strValue) {
	//verifica se uma determinada string é um valor em dinheiro

	//verificando se os caracteres da string são válidos
	var strDin = "0123456789.,";
	for (i=0; i<strValue.length; i++) {
		if (strDin.indexOf(strValue.charAt(i)) < 0)
			return false;
	}

	//verifica se a vírgula está no lugar certo caso ela exista	
	var arrDin = strValue.split(",");
	if(arrDin.length != 1 && arrDin.length !=2)
		return false;
	else
		if(arrDin.length == 2 && arrDin[1].length != 2)
			return false;
	
	//verifica se entre os pontos presentes na string
	//existe um número mútiplo de três de algarismos
	//Ex: "1.000", "1000.000", "1000000", "1.000.000.000" (corretos)
	//Ex: "1.00000", "100.0000", "1.000.0000.00" (incorretos)
	if(arrDin[0].indexOf(".") > 0){
		var arrInt = arrDin[0].split(".");
		var i;
		for(i=1; i<arrInt.length; i++)
			if( (arrInt[i].length % 3) != 0 )
				return false;
	}
	return true;
}
		
function inverteData(strData){
	var novadata, a;
	
	a = strData.split("/");
	novadata = a[2] + "/" +  a[1] + "/" + a[0] ;
	return novadata
}

function formatNumberTrunc(campo,decimais){
	var i,c,s,z,r,n;
	if (n==0) n = "0"
	r = "";
	c = 0;
	s = false;
	z = "0000000000";
	n = campo.value();
	d = decimais;
	if (!isNumeric(n.value)) campo.value = r;
	if (d>10) d = 10;
	if (d<0) d = 0;
   for (i=0;i<n.length;i++) {
       if (s) c++;
       if (c>d) return r;
       if (n.substr(i,1)=="." || n.substr(i,1)==","){
	       s = true;
	       if (d>0) r += ",";
	   }  else r += n.substr(i,1);
	}
	if (c<d) {
	   if (!s) r += ",";
	   r += z.substr(0,d-c);
	}   
	campo.value = r;
}	
//Verifica se o CGC é valido
function isCgc(strCGC) {
	//verifica se o CGC é válido
	var strvalid = "0123456789", i = 0;
	//retira os caracteres que não forem números para aplicar o algoritmo
	while (i < strCGC.length) {
		if (strvalid.indexOf(strCGC.charAt(i)) < 0) {
			strCGC = strCGC.substring(0,i) + strCGC.substring(i+1,strCGC.length)
		} else i++;	
	}
	if (strCGC.length != 14) return false;
	//teste do primeiro dígito
	strserie = "543298765432", c1=0;
	for (i=1; i < 13; i++) {
		c1 += strCGC.charAt(i-1) * strserie.charAt(i-1);
	}
	c1 %= 11;
	if (c1 < 2)
		c1 = 0
	else c1 = 11 - c1;
	if (c1 != strCGC.charAt(12))
		return false;
	//teste do segundo dígito
	strserie = "6543298765432", c1=0;
	for (i=1; i < 14; i++) {
		c1 += strCGC.charAt(i-1) * strserie.charAt(i-1);
	}
	c1 %= 11;
	if (c1 < 2)
		c1 = 0
	else c1 = 11 - c1;
	if (c1 != strCGC.charAt(13))
		return false;
	
	return true;		
} //29.010.519/0001-32

//Funcao que coloca os pontos, a barra e o traco no CGC
//Recebe como entrada um CGC valido, jah testado
function formataCGC(strCGC){
	var strvalid = "0123456789", i = 0, strFormatado = "";
	//retira os caracteres que não forem números para aplicar o algoritmo
	while (i < strCGC.length) {
		if (strvalid.indexOf(strCGC.charAt(i)) < 0) {
			strCGC = strCGC.substring(0,i) + strCGC.substring(i+1,strCGC.length)
		} else i++;	
	}
	
	for(i=0; i<2; i++)
		strFormatado += strCGC.charAt(i);
		
	strFormatado += ".";
		
	for(i=2; i<5; i++)
		strFormatado += strCGC.charAt(i);
	
	strFormatado += ".";
	
	for(i=5; i<8; i++)
		strFormatado += strCGC.charAt(i);
	
	strFormatado += "/";
	
	for(i=8; i<12; i++)
		strFormatado += strCGC.charAt(i);
	
	strFormatado += "-";
	
	for(i=12; i<14; i++)
		strFormatado += strCGC.charAt(i);
		
	return strFormatado;		
}

function isNumeric(strTexto){
	//verifica se uma string é um número inteiro
	//Obs.: utiliza a função isEmpty
	if (isEmpty(strTexto)) 
		return false;
	var strNum = "0123456789";
	
	for (var i=0; i < strTexto.length; i++) {
		if (strNum.indexOf(strTexto.charAt(i)) < 0)
			return false;			
	}
	return true;
}

function formataValor(campo){
    var i,s,c,z,d;
    var myvalor = ''; 
    myvalor = myvalor + campo.value; 
	s = false;
	z = "0000000000";
	d = 2;
	if (isMoney(myvalor)) {
       for (i=0;i<myvalor.length;i++) {
	      if (s) c++;
          if (c>d) break;
       	  if (myvalor.substr(i,1)=="." || myvalor.substr(i,1)==","){
	         s = true;
   	         if (d>0) r += ",";
 	      } else 
	   	  	 r += myvalor.substr(i,1);
		}
	    if (c<d) {
	    	if (!s) r += ",";
	    	r += z.substr(0,d-c);
		}   
		campo.value = r;
	} else
		myvalor = '';
}		

function mascaraCEP(t,e){
 var strCheck = '0123456789';
 var whichCode = (window.Event) ? e.which : e.keyCode; 
 key = String.fromCharCode(whichCode); // Valor para o código da Chave
 	if (strCheck.indexOf(key) == -1) return false; // Chave inválida
  		if(t.value.length==5) {
  			t.value+='-';
		}
		if(t.value.length==9) {
  			return false;
		}
}

function formataCPF(strCGC){
	var strvalid = "0123456789", i = 0, strFormatado = "";
	//retira os caracteres que não forem números para aplicar o algoritmo
	while (i < strCGC.length) {
		if (strvalid.indexOf(strCGC.charAt(i)) < 0) {
			strCGC = strCGC.substring(0,i) + strCGC.substring(i+1,strCGC.length)
		} else i++;	
	}
	
	for(i=0; i<3; i++)
		strFormatado += strCGC.charAt(i);
		
	strFormatado += ".";
		
	for(i=3; i<6; i++)
		strFormatado += strCGC.charAt(i);
	
	strFormatado += ".";
	
	for(i=6; i<9; i++)
		strFormatado += strCGC.charAt(i);
	
	strFormatado += "-";
	
	for(i=9; i<12; i++)
		strFormatado += strCGC.charAt(i);
	
	return strFormatado;		
}

function getNumeros(strFormatada) {
	var strvalid = "0123456789", i = 0;
	//retira os caracteres que não forem números para aplicar o algoritmo
	while (i < strFormatada.length) {
		if (strvalid.indexOf(strFormatada.charAt(i)) < 0) {
			strFormatada = strFormatada.substring(0,i) + strFormatada.substring(i+1,strFormatada.length)
		} else i++;	
	}
	return strFormatada;

}

function mascaraCNPJ(t,e){
 var strCheck = '0123456789';
 var whichCode = (window.Event) ? e.which : e.keyCode; 
 key = String.fromCharCode(whichCode); // Valor para o código da Chave
 	if (strCheck.indexOf(key) == -1) return false; // Chave inválida
  	if(t.value.length==2) {
  		t.value+='.';
	} else if(t.value.length==6) {
  		t.value+='.';
	} else if(t.value.length==10) {
  		t.value+='/';
	} else if(t.value.length==15) {
  		t.value+='-';
	}
	if(t.value.length==18) {
  		return false;
	}
}

function mascaraNUM(t,num,e){
	var strCheck = '0123456789';
	var whichCode = (window.Event) ? e.which : e.keyCode; 
	if (whichCode == 0 ) return true;   
	if (whichCode == 9 ) return true; //tecla tab   
	if (whichCode == 13) return true; //tecla enter   
	if (whichCode == 16) return true; //shift internet explorer   
	if (whichCode == 17) return true; //control no internet explorer   
	if (whichCode == 27 ) return true; //tecla esc   
	if (whichCode == 34 ) return true; //tecla end   
	if (whichCode == 35 ) return true;//tecla end
	key = String.fromCharCode(whichCode); // Valor para o código da Chave
 	if (strCheck.indexOf(key) == -1) return false; // Chave inválida
	if(t.value.length==num) {
		return false;
	}
}

function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    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;
  //  alert(whichCode);
    if (whichCode == 13) return true;
    
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}

function MaskMoeda(elem,e){

   var whichCode = (window.Event) ? e.which : e.keyCode;
 	if (whichCode==8) elem.value='';
}

function MascaraMoeda3d(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    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;
  //  alert(whichCode);
    if (whichCode == 13) return true;
    
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '00' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 3) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 3) {
        aux2 = '';
        for (j = 0, i = len - 4; i >= 0; i--) {
            if (j == 4) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 3, len);
    }
    return false;
}

function MascaraMoeda4d(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    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;
  //  alert(whichCode);

	if (whichCode == 0 ) return true;   
	if (whichCode == 9 ) return true; //tecla tab   
	if (whichCode == 13) return true; //tecla enter   
	if (whichCode == 16) return true; //shift internet explorer   
	if (whichCode == 17) return true; //control no internet explorer   
	if (whichCode == 27 ) return true; //tecla esc   
	if (whichCode == 34 ) return true; //tecla end   
	if (whichCode == 35 ) return true;//tecla end   
    
	/*  
	O trecho abaixo previne a ação padrão nos navegadores. Não estamos inserindo o caractere normalmente, mas via script  
	*/  
	  
	if (e.preventDefault){ //standart browsers   
	      e.preventDefault()   
	   }else{ // internet explorer   
	      e.returnValue = false  
	}   
    
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '000' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + '00' + aux;
    if (len == 3) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 4) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 4) {
        aux2 = '';
        for (j = 0, i = len - 5; i >= 0; i--) {
            if (j == 5) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 4, len);
    }
    return false;
}

function isDesconto4d(objTextBox, e){
    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;

	if (whichCode == 0 ) return true;   
	if (whichCode == 9 ) return true; //tecla tab   
	if (whichCode == 13) return true; //tecla enter   
	if (whichCode == 16) return true; //shift internet explorer   
	if (whichCode == 17) return true; //control no internet explorer   
	if (whichCode == 27 ) return true; //tecla esc   
	if (whichCode == 34 ) return true; //tecla end   
	if (whichCode == 35 ) return true;//tecla end
	/*  
	O trecho abaixo previne a ação padrão nos navegadores. Não estamos inserindo o caractere normalmente, mas via script  
	*/  
	  
	if (e.preventDefault){ //standart browsers   
	      e.preventDefault()   
	   }else{ // internet explorer   
	      e.returnValue = false  
	}   
    
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if (objTextBox.value.charAt(i) != '0') break;
    aux = '';
    var virgula = false;
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 2 && key != ',') aux += ',';
    objTextBox.value = '';
    objTextBox.value = aux;
    return false;
}

function FormataMoeda4d(objTextBox){
    var aux = '';
    var len = 0;
    aux = objTextBox.value;
    len = objTextBox.value.length;
	//verifica se a vírgula está no lugar certo caso ela exista
    if (len > 0) {
        if (len == 1) aux += ',';
   	    var arrDin = aux.split(",");
	    if(arrDin.length != 1 && arrDin.length !=2) {
            aux += ',0000';
	    } else {
	    	if(arrDin.length == 2 && arrDin[1].length < 4){
	    		if(arrDin[1].length == 0) aux += '0000';
	    		if(arrDin[1].length == 1) aux += '000';
	    		if(arrDin[1].length == 2) aux += '00';
	    		if(arrDin[1].length == 3) aux += '0';
	    	}
	    }
    }
    objTextBox.value = aux
    
}
