function FormataCPFCNPJ(campo){
	if(ValidaCGC(campo)){
		FormataCNPJ(campo);
	}
	else if(ValidaCPF(campo)){
		FormataCPF2(campo);
		}
}
function FormataCPF2(Campo){
	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("-", "");
	
	tam = vr.length;
//		tam = vr.length + 1;
		if (tam >= 10 && tam < 14)
			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);
}

function FormataCNPJ( el ) 
{ 
         vr = el.value; 
         tam = vr.length; 


      if ( vr.indexOf(".") == -1 ) 
      { 
      if ( tam <= 2 ) 
              el.value = vr; 
      if ( (tam > 2) && (tam <= 6) ) 
              el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, tam ); 
      if ( (tam >= 7) && (tam <= 10) ) 
              el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' 
+ vr.substr( 5, 3 ) + '/'; 
      if ( (tam >= 11) && (tam <= 18) ) 
             el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + 
vr.substr( 5, 3 ) + '/' + vr.substr( 8, 4 ) + '-' + vr.substr( 12, 2 ) ; 
      } 
      return true; 
} 

function isCPFCNPJ(campo){
	if(ValidaCGC(campo) || ValidaCPF(campo)){
		return true;
	}
	return false;
}

function ValidaCGC(obj){
 s = TiraTudo(obj.value);
 if (isNaN(s)) {
  return false;
 }
 var i;
 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 ValidaCPF(obj){
 s = TiraTudo(obj.value);
/* expressao=/^([0-9]{3})[.]([0-9]{3})[.]([0-9]{3})[-]([0-9]{2})$/;
  if (!expressao.test(s)) {
	alert('Regex');
	obj.focus();
	return false;
}*/

 if (isNaN(s)) {
  return false;
 }
 var i;
 var c = s.substr(0,9);
 var dv = s.substr(9,2);
 var d1 = 0;
 for (i = 0; i < 9; i++) {
  d1 += c.charAt(i)*(10-i);
 }
 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 < 9; i++) {
  d1 += c.charAt(i)*(11-i);
 }
 d1 = 11 - (d1 % 11);
 if (d1 > 9) d1 = 0;
 if (dv.charAt(1) != d1) {
     return false;
    }
    return true;
}

function RemoveLinha(NomeTabela,NumeroLinha){
	var Tabela;
	Tabela = document.getElementById(NomeTabela); 
	if (NumeroLinha==null) return;
	Tabela.deleteRow(NumeroLinha);
}

function LinhaSelecionada(NomeTabela,NumeroLinha){
	var Tabela;
	var Linha;
	
	if (NumeroLinha==null){
		Linha=this;
	}else{
		Tabela = document.getElementById(NomeTabela); 
		Linha = Tabela.rows(NumeroLinha);
	}
	if (Linha==null) return false;

	if (Linha.cells(0).style.backgroundColor=="#cdcdcd"){
		return true;
	}
	return false;
}

function SelecionaLinha(NomeTabela,NumeroLinha){
	var Tabela;
	var Linha;
	
	if (NumeroLinha==null){
		Linha=this;
	}else{
		Tabela = document.getElementById(NomeTabela); 
		Linha = Tabela.rows(NumeroLinha);
	}
		
	for (i=0; i < Linha.cells.length; i++){
		Linha.cells(i).style.backgroundColor="#CDCDCD";
	}
}

function TiraSelecaoLinha(NomeTabela,NumeroLinha){
	var Tabela;
	var Linha;
	
	if (NumeroLinha==null){
		Linha=this;
	}else{
		Tabela = document.getElementById(NomeTabela); 
		Linha = Tabela.rows(NumeroLinha);
	}
	
	TiraSelecaoLinha2(Linha);
	
}
function TiraSelecaoLinha2(Linha){
	for (var i=0; i < Linha.cells.length; i++){
		Linha.cells(i).style.backgroundColor="";
	}
}
function TiraSelecaoLinhas(NomeTabela){
	var Tabela = document.getElementById(NomeTabela); 
	if (Tabela==null) return; 
	for (var x=1; x < Tabela.rows.length; x++){
		TiraSelecaoLinha2(Tabela.rows(x));
	}	
}

function Checa_Email(objEmail){

      var emailStr = objEmail.value


        //remove espaços antes da verificação
        var emailStr = trim(emailStr)
        /* Critica de e-mail */
        var emailPat=/^(.+)@(.+)$/
        var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
        var validChars="\[^\\s" + specialChars + "\]"
        var quotedUser="(\"[^\"]*\")"
        var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
        var atom=validChars + '+'
        var word="(" + atom + "|" + quotedUser + ")"
        var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
        var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


        var matchArray=emailStr.match(emailPat)
        if (matchArray==null) {
                alert("O endere\u00E7o de e-mail est\u00E1 incorreto (verifique @ e .'s)");
            objEmail.select();
            objEmail.focus();
                return false;
        }
        var user=matchArray[1]
        var domain=matchArray[2]

        if (user.match(userPat)==null) {
            alert("O endere\u00E7o de e-mail est\u00E1 inv\u00E1lido.");
         objEmail.select();
         objEmail.focus();
            return false;
        }

        var IPArray=domain.match(ipDomainPat)
        if (IPArray!=null) {
                  for (var i=1;i<=4;i++) {
                    if (IPArray[i]>255) {
                        alert("O endere\u00E7o de e-mail est\u00E1 inv\u00E1lido.");
                  objEmail.select();
                  objEmail.focus();
                        return false;
                    }
            }
            return true
        }

        var domainArray=domain.match(domainPat)
        if (domainArray==null) {
            alert("O endere\u00E7o de e-mail est\u00E1 inv\u00E1lido.");
         objEmail.select();
         objEmail.focus();
            return false;
        }

        var atomPat=new RegExp(atom,"g")
        var domArr=domain.match(atomPat)
        var len=domArr.length
        if (domArr[domArr.length-1].length<2 ||
            domArr[domArr.length-1].length>3) {
            alert("O endere\u00E7o de e-mail est\u00E1 inv\u00E1lido.");
         objEmail.select();
         objEmail.focus();
            return false;
        }

        if (len<2) {
           var errStr="O endere\u00E7o de e-mail est\u00E1 inv\u00E1lido.";
           alert(errStr);
          objEmail.select();
         objEmail.focus();
           return false;
        }

        return true;
}


function AceitaNumero(e)
{
	
	if (document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;
	
	if (tecla==8 || tecla==9 || tecla==16 || tecla==46) {
		return;
	}else if (tecla>=35 && tecla<=40){
		return;
	}
		if(tecla==44){
			return true;
		}
		if (tecla > 47 && tecla < 58) // numeros de 0 a 9
		return true;
	else{
		if (tecla != 8) // backspace
			event.keyCode = 0;
		else
			return true;
		}
}

function FormataIM(Campo, teclapres){
	var tecla = teclapres.keyCode;
	
	if (tecla==8 || tecla==9 || tecla==16 || tecla==46) {
		return;
	}else if (tecla>=35 && tecla<=40){
		return;
	}
	
	var vr = new String(Campo.value);
	vr = vr.replace("-", "");

	tam = vr.length + 1;
	
	if (tecla != 9 && tecla != 8){
		if (tam > 8 && tam < 11)
			Campo.value = vr.substr(0, 8) + '-' + vr.substr(8, tam);
	}
}

function FormataPeriodo(Campo, teclapres){
	var tecla = teclapres.keyCode;
	
	if (tecla==8 || tecla==9 || tecla==16 || tecla==46) {
		return;
	}else if (tecla>=35 && tecla<=40){
		return;
	}
	
	var vr = new String(Campo.value);
	vr = vr.replace("/", "");

	tam = vr.length + 1;
	
	if (tecla != 9 && tecla != 8){
		if (tam > 2 && tam < 7)
			Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, tam);
	}
}

function FormataData(Campo, teclapres){
	var tecla = teclapres.keyCode;
	var vr = new String(Campo.value);
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	tam = vr.length + 1;
	
	if (tecla==8 || tecla==9 || tecla==16 || tecla==46) {
		return;
	}else if (tecla>=35 && tecla<=40){
		return;
	}
	
	if (tecla != 9 && tecla != 8){
		if (tam > 2 && tam < 5)
			Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, tam);
		if (tam >= 5 && tam <=10)
			Campo.value = vr.substr(0,2) + '/' + vr.substr(2,2) + '/' + vr.substr(4,4);
	}
}

/////////////////////////////////////////////////////////////////
function FormataMesData(Campo, teclapres){
	var tecla = teclapres.keyCode;
	var vr = new String(Campo.value);
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	tam = vr.length + 1;
	
	if (tecla==8 || tecla==9 || tecla==16 || tecla==46) {
		return;
	}else if (tecla>=35 && tecla<=40){
		return;
	}
	
	if (tecla != 9 && tecla != 8){
		if (tam > 2 && tam < 5)
			Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, tam);
}
}
/////////////////////////////////////////////////////////////////
function FormataHora(Campo, teclapres){
	var tecla = teclapres.keyCode;
	
	if (tecla==8 || tecla==9 || tecla==16 || tecla==46) {
		return;
	}else if (tecla>=35 && tecla<=40){
		return;
	}
	
	var vr = new String(Campo.value);
	vr = vr.replace(":", "");
	vr = vr.replace(":", "");

	tam = vr.length + 1;
	
	if (tecla != 9 && tecla != 8){
		if (tam > 2 && tam < 5)
			Campo.value = vr.substr(0, 2) + ':' + vr.substr(2, tam);
		if (tam >= 5 && tam < 9)
			Campo.value = vr.substr(0,2) + ':' + vr.substr(2,2) + ':' + vr.substr(4,2);
		}
	}
/////////////////////////////////////////////////////////////////
function FormataCPF(Campo, teclapres){
	var tecla = 0;
	if (teclapres != null)
		tecla = teclapres.keyCode;
	
	if (tecla==8 || tecla==9 || tecla==16 || tecla==46) {
		return;
	}else if (tecla>=35 && tecla<=40){
		return;
	}
	
	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("-", "");
	
	tam = vr.length;
	if (teclapres!=null)
		tam = vr.length + 1;
		
	if (tecla != 9 && tecla != 8){
		if (tam > 3 && tam < 7)
			Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
		if (tam >= 7 && tam <10)
			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);
		if (tam >= 10 && tam < 14)
			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);
	}
}
/////////////////////////////////////////////////////////////////
function FormataControle(Campo, teclapres){
	var tecla = teclapres.keyCode;
	
	if (tecla==8 || tecla==9 || tecla==16 || tecla==46) {
		return;
	}else if (tecla>=35 && tecla<=40){
		return;
	}
	
	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	tam = vr.length + 1;
	
 if (tecla != 9 && tecla != 8)
		if (tam > 7){
			if (tam > 4 && tam < 9)
				Campo.value = vr.substr(0, 4) + '.' + vr.substr(4, tam);
			if (tam >= 9 && tam <13)
				Campo.value = vr.substr(0,4) + '.' + vr.substr(4,4) + '.' + vr.substr(8,tam-8);
			if (tam >= 13 && tam < 17)
				Campo.value = vr.substr(0,4) + '.' + vr.substr(4,4) + '.' + vr.substr(8,4) + '.' + vr.substr(12,tam-12);
			}
		else{
			if (tam > 1 && tam < 5)
				Campo.value = vr.substr(0, 1) + '.' + vr.substr(1, tam);
			if (tam >= 5 && tam < 8)
				Campo.value = vr.substr(0,1) + '.' + vr.substr(1,3) + '.' + vr.substr(4,tam-4);
			}
}

function FormataCNPJ(Campo, teclapres){

	var tecla = 0;
	if (teclapres != null)
		tecla = teclapres.keyCode;
	
	if (tecla==8 || tecla==9 || tecla==16 || tecla==46) {
		return;
	}else if (tecla>=35 && tecla<=40){
		return;
	}
	
	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");

	tam = vr.length;
	if (teclapres != null)
		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 AbreConsulta(url, nome_janela){
	var largura = 800, altura = 600;
	if (nome_janela==null) nome_janela="";
	var janela = window.open(url,nome_janela,"width=" + largura + ",height=" + altura);
	janela.moveBy(0,0);
}

function AbreRelatorio(url, nome_janela){
	var largura = 790, altura = 470;
	if (nome_janela==null) nome_janela="";
	window.open(url,nome_janela,"top=0,left=0,toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,directories=no,width=" + largura + ",height=" + altura);
}

function AbrePopUp(url, largura, altura, nome_janela){
	if (nome_janela==null) nome_janela="";
	 return window.open(url,nome_janela,"toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,width=" + largura + ",height=" + altura);
}

function Arredonda( valor , casas ){
   var novo = Math.round( valor * Math.pow( 10 , casas ) ) / Math.pow( 10 , casas );
   return( novo );
}

function AjustaCasasDecimais(strNumero){
	var LocVirgula = strNumero.indexOf(',');
	var myNum = strNumero;
	var myDec = "";

	if (LocVirgula > -1){
		myNum = strNumero.substring(0,LocVirgula);
		myDec = strNumero.substring(LocVirgula);
		//alert (myNum + " - " + myDec + " - " + myDec.length);
		if (myDec.length==1)
			myDec += "00";
		else if (myDec.length==2)
			myDec += "0";
		//alert (myNum + " - " + myDec + " - " + myDec.length);
	}else{
		myNum = strNumero;
		myDec = ",00";
	}
	return myNum + myDec;
}

function FormataNumero(num){
	var retorno = "";
	num = Arredonda(num,2);
	var n = Math.floor(num);
	var myNum = num + "";
	var myDec = ""
	if (myNum.indexOf('.',0) > -1){
		myDec = myNum.substring(myNum.indexOf('.'));
		myDec = TrocaPic(myDec, ".", ",");
	}
	var arr=new Array('0'), i=0; 
	while (n>0){
		arr[i]=''+n%1000; 
		n=Math.floor(n/1000); 
		i++;
	}
 	arr=arr.reverse();
 	for (var i in arr){ 
		if (i>0){ //padding zeros
  	 		while (arr[i].length<3){ 
				arr[i]='0'+arr[i];
			}
		}
	}
	//alert (arr.join('.'));
	retorno = AjustaCasasDecimais(arr.join('.') + myDec);
 	return retorno;
}
function FormataNumero2(num){
	var retorno = "";
//	num = Arredonda(num,2);
//	var n = Math.floor(num);
	n=num;
	var myNum = num + "";
	var myDec = ""
 	
	if (myNum.indexOf('.',0) > -1){
		myDec = myNum.substring(myNum.indexOf('.'));
		myDec = TrocaPic(myDec, ".", ",");
	}
	var arr=new Array('0'), i=0; 
	while (n>=1){
		arr[i]=''+n%1000; 
		n=Math.floor(n/1000); 
		i++;
	}
 	arr=arr.reverse();
 	for (var i in arr){ 
		if (i>0){ //padding zeros
  	 		while (arr[i].length<3){ 
				arr[i]='0'+arr[i];
			}
		}
	}
	//alert (arr.join('.'));
	retorno = AjustaCasasDecimais(arr.join('.') + myDec);
 	return retorno;
}

function DefineValorCelula(NomeTabela, NumeroLinha, NumeroCelula, strValor){
	var Tabela = document.getElementById(NomeTabela);
	var Linha = Tabela.getElementsByTagName("tr").item(NumeroLinha);
	var Celula = Linha.getElementsByTagName("td").item(NumeroCelula);
	if (Celula != null){
		var CelulaValor = Celula.childNodes.item(0);
		if (CelulaValor == null){
			// creates a Text Node
			currenttext=document.createTextNode(strValor);
			// appends the Text Node we created into the cell TD
			Celula.appendChild(currenttext);
		}else{
			CelulaValor.data = strValor;
		}
	}
}

function TabelaValorCelula(NomeTabela, NumeroLinha, NumeroCelula){
	var retorno = "";
	var Tabela = document.getElementById(NomeTabela);
	var Linha = Tabela.getElementsByTagName("tr").item(NumeroLinha);
	var Celula = Linha.getElementsByTagName("td").item(NumeroCelula);
	if (Celula != null){
		var CelulaValor = Celula.childNodes.item(0);
		if (CelulaValor != null)	
			retorno = CelulaValor.data;
	}
	if (retorno==null) retorno="";
	return retorno;
}

function TiraTudo(Valor){
	var vr = new String(Valor);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");
	vr = vr.replace(",", "");
	return vr;
}

function TiraPic(Valor, ValorTirar){
	return Valor.replace(ValorTirar,"");
}

function TrocaPic(Valor, ValorTrocar, ValorPor){
	return Valor.replace(ValorTrocar, ValorPor);
}
function toFloat(num){
	while(num.indexOf(".",0)>0)
			num=num.replace(".","");
		return parseFloat(num);
}
function CNumero(Valor){
	var retorno=Trim(Valor);
	while(retorno.indexOf(".")>0)
		retorno = TiraPic(retorno,".");
	retorno = TrocaPic(retorno, ",", ".");
	if (isNaN(retorno))
		retorno="0";
	return retorno;
}
function CNumero2(Valor){
	var retorno=Trim(Valor);
	while(retorno.indexOf(".")>0)
		retorno = TiraPic(retorno,".");
	retorno = TrocaPic(retorno, ",", "");

	if (isNaN(retorno))
		retorno="0";
	return parseInt(retorno);
}

function TabelaNumeroLinhas(NomeTabela){
	var Tabela = document.getElementById(NomeTabela);
	if (Tabela==null) return 0;
	var NumLinhas = Tabela.rows.length;
	return NumLinhas;
}

function TabelaCalculaColuna(NomeTabela, NumeroColuna){
	var Valor="", Total=0.0;
	var Tabela = document.getElementById(NomeTabela);
	var NumLinhas = TabelaNumeroLinhas(NomeTabela);
	for (i=0; i < NumLinhas; i++){
		Valor = TabelaValorCelula(NomeTabela,i,NumeroColuna);
		Total = Total + parseFloat(CNumero(Valor));
	}
	return String(Total);
}

function Trim(str) {
	return LTrim(RTrim(str));
}
function LTrim(str) {
	return str.replace(/^\s*/, "");
}
function RTrim (str) {
	return str.replace(/\s*$/, "");
}
 
String.prototype.formataData = function(){
	var key = window.event.keyCode;
	
	
	if (key==8 || key==9 || key==16 || key==46) {
		return this;
	}else if (key>=35 && key<=40){
		return this;
	}else{
		var s = this.replace(/\D/g,'');
		var f = '';
		if (s.length >= 2) {
			f = s.substr(0,2) + '/';
			if (s.length >= 4) {
				f += s.substr(2,2) + '/' + s.substr(4);
			} else f += s.substr(2);
		} else f = s;
		return f;
	}
}

function TeclaSoData(e){
	if (key==8 || key==9 || key==16 || key==46) {
		return true;
	}else if (key>=35 && key<=40){
		return true;
	}else{
		if (key==47) {
			var s = this.replace(/\D/g,'');
			var f = '';
			if (s.length >= 2) {
				f = s.substr(0,2) + '/';
				if (s.length >= 4) {
					f += s.substr(2,2) + '/' + s.substr(4);
				} else f += s.substr(2);
			} else f = s;
			return true;
		}
		return TeclaSoNumero(e);
	}
}

function FormataData2(Controle){
	var texto=Controle.value;
	if (Controle.value.trim()=="") return "";
	return texto;
}

function TeclaSoNumero(e){
	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 EEmail(str){
	if (str.indexOf('@', 0) == -1) 
		return false;
	return true;
}

// Verifica se a Data digitada é válida
function EDataValida(vfield, vfieldName){
	var diaStr, mesStr, anoStr
	var diaInt, mesInt, anoInt
	var tam, sep1, sep2, verAno
	
	tam = vfield.value.length;

	sep1 = parseInt(vfield.value.indexOf("/", 0));

	if (sep1<0)	{
		alert("A Data digitada deve ter o seguinte formato: DD/MM/AAAA !");
		return false;
	}

	sep2 = parseInt(vfield.value.indexOf("/", sep1+1));

	if (sep2<5){
		alert("A Data digitada deve ter o seguinte formato: DD/MM/AAAA !");
		return false;
	}

	verAno = tam-sep2;

	if(verAno < 5 )	{
		alert("As datas devem ser preenchidas utilizando 4 dígitos para informar o Ano (ex.: DD/MM/AAAA)!");
		return false;
	}

	diaStr = vfield.value.substring(0, sep1);

	if(diaStr.substring(0, 1) == "0")
	diaStr = diaStr.substring(1, 2);

	if (isValidNumberValue(diaStr, vfieldName))	{
		mesStr = vfield.value.substring(sep1+1, sep2); 

		if(mesStr.substring(0, 1) == "0")
		mesStr = mesStr.substring(1, 2);

		if (isValidNumberValue(mesStr, vfieldName))	{
			anoStr = vfield.value.substring(sep2+1, tam);
		
			if (isValidNumberValue(anoStr, vfieldName)){
				diaInt = parseInt(diaStr);
				mesInt = parseInt(mesStr);
				anoInt = parseInt(anoStr);
	
				if ((diaInt <= 0) || (diaInt > 31))	{
					alert("O dia informado não é válido!");
					return false;
				}
	
				if ((mesInt <= 0) || (mesInt > 12)){
					alert("O mês informado não é válido!");
					return false;
				}

				if ((mesInt == 4) || (mesInt == 6) || (mesInt == 9) || (mesInt == 11)){
					if( diaInt > 30){
						alert("O mês informado não possui mais de 30 dias!");
						return false;
					}
				}

				if (mesInt == 2){
					if ((anoInt % 4 == 0) && ( (anoInt % 100 != 0) || (anoInt % 400 == 0))){
						if (diaInt > 29){
							alert("O mês informado não possui mais de 29 dias!");
							return false;
						}
					}else{
						if(diaInt > 28){
							alert("O mês informado não possui mais de 28 dias!");
							return false;
						}
					}
					return true;
				} 
				return true;
			}else return false;
		}else return false;
	}else return false;
}

// Verifica se somente números foram digitados no campo;
function isValidNumberValue (objTextControl, strFieldName) 
{
var strValidNumber = "1234567890";

for (nCount=0; nCount < objTextControl.length; nCount++) 
{
strTempChar=objTextControl.substring(nCount,nCount+1);
if ( strValidNumber.indexOf(strTempChar,0)==-1) 
{
alert("O campo " + strFieldName + " deve conter somente números!");
return false; 
}
} 

return true;
}
 

function Avisa(mens){
	alert(mens);
}

function ENumero(s){
	var i=0;
    var dotAppeared = false;
    dotAppeared = false;
    if (EVazio(s)){ 
       if (ENumero.arguments.length == 1) {
		   return (false);
	   }else{
		   return (ENumero.arguments[1] == true);
	   }
	}
    
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( i != 0 ) {
            if ( c == "." ) {
                if( !dotAppeared )
                    dotAppeared = true;
                else
                    return (false);
            } else     
                if (!EDigito(c)) return (false);
        } else { 
            if ( c == "." ) {
                if( !dotAppeared )
                    dotAppeared = (true);
                else
                    return (false);
            } else     
                if (!EDigito(c) && (c != "-") || (c == "+")) return (false);
        }
    }
    return (true);
}

function EInteiro(Valor)
{   var i=0;
    if (EVazio(Valor)) 
       if (EInteiro.arguments.length == 1) return (false);
       else return (EInteiro.arguments[1] == true);
    
    for (i = 0; i < Valor.length; i++)
    {   
        var c = Valor.charAt(i);
        if( i != 0 ) {
            if (!EDigito(c)) return (false);
        } else { 
            if (!EDigito(c) && (c != "-") || (c == "+")) return (false);
        }
    }
    return (true);
}
function EDigito(c){
	return ((c >= "0") && (c <= "9"));
}

function EVazio(Valor) {
	if (Valor=="" || Valor==null){
		return (true);
	}
	return (false);
}

function ValidaCampo(Campo, NomeCampo) {
	var mens = "";
	if (EVazio(Campo.value)){
		if (NomeCampo!=null){ 
			mens="Informe o Campo '" + NomeCampo + "'";
		}else{
			mens="Campos obrigatórios estão faltando";
		}
		
		alert(mens);
		Campo.focus();
		return (false);
	}
	return (true);
}
function EData(campo)
{
	reDate=/^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/;
  if (reDate.test(campo.value)) {
					return true;
  } else if (campo.value != null && campo.value != "") {
    alert(campo.value + " NÃO é uma data válida.");
				campo.focus();
				return false;
  }
		return true;
} 
function EPeriodo(campo)
{
	reDate=/^(0?[1-9]|1[0-2])\/(19|20)?\d{2}$/;

  if (reDate.test(campo.value)) {
					return true;
  } else if (campo.value != null && campo.value != "") {
    alert("\""+campo.value + "\" NÃO é um período válido.");
				campo.focus();
				return false;
  }
		return true;
} 
function EAno(campo){
	reDate=/^(19|20)?\d{2}$/;

  if (reDate.test(campo.value)) {
					return true;
  } else if (campo.value != null && campo.value != "") {
    alert("\""+campo.value + "\" NÃO é um período válido.");
				campo.focus();
				return false;
  }
		return true;
}

function retornaPalavra(string, delimitador, indice)
{
	var array = string.split(delimitador);
	return array[indice];
}

