
	function verificaNumero()
	{
		var varCaractere = String.fromCharCode(event.keyCode)
				
		if (!fctEhDigitoNumerico(varCaractere))
		{
			event.returnValue = false;
		}

	}

	
    function verificaNumeroBrowser(e) {
        var characterCode;
        var strCaratere;

        if (e && e.which) {
            e = e;
            characterCode = e.which;
        }
        else {
            e = event;
            characterCode = e.keyCode;
        }

        //backspace
        if (characterCode == 8) {
            return true;
        }
        else {
            strCaratere = String.fromCharCode(characterCode);
            if (!fctEhDigitoNumerico(strCaratere)) {
                return false;
            }
            return true;
        }
    }
	
	function verificaNumeroComVirgula()
	{
	    
	    //Permito a Vírgula
        if(event.keyCode == 44)
        {
            event.returnValue = true;
        }
        else
        {   
		    var varCaractere = String.fromCharCode(event.keyCode)
    				
		    if (!fctEhDigitoNumerico(varCaractere))
		    {
			    event.returnValue = false;
		    }
		}

	}
	

    function verificaNumeroBrowserComVirgula(e) {
        var characterCode;
        var strCaratere;

        if (e && e.which) {
            e = e;
            characterCode = e.which;
        }
        else {
            e = event;
            characterCode = e.keyCode;
        }

        //backspace
        if (characterCode == 8) {
            return true;
        }
        //Permito a Vírgula
        else if(characterCode == 44)
        {
            return true;
        }
        else {
            strCaratere = String.fromCharCode(characterCode);
            if (!fctEhDigitoNumerico(strCaratere)) {
                return false;
            }
            return true;
        }
    }

	function fctEhDigitoNumerico(istrDig)
	{
		if((istrDig == '0') || (istrDig == '1') || (istrDig == '2') || (istrDig == '3') || (istrDig == '4') || (istrDig =='5') || (istrDig == '6') || (istrDig == '7') || (istrDig == '8') || (istrDig == '9')) 
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	
	
	function ftcEhNumero(numero)
	{
		try
		{
			x = parsefloat(numero);
			return true;
		}
		catch(e)
		{
			return false	;
		}
	}
	
	 function Limpar(valor, validos) {
    // retira caracteres invalidos da string
    var result = "";
    var aux;
    for (var i=0; i < valor.length; i++) {
    aux = validos.indexOf(valor.substring(i, i+1));
        if (aux>=0) {
        result += aux;
        }
    }
    return result;
    }
    
    
    

   
	
	

    //Formata número tipo moeda usando o evento onKeyDown
    function Formata(campo,tammax,teclapres,decimal) {
    var tecla = teclapres.keyCode;
    vr = Limpar(campo.value,"0123456789");
    tam = vr.length;
    dec=decimal
    
    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 <= dec )
        { campo.value = vr ; }

        if ( (tam > dec) && (tam <= 5) ){
        campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
        if ( (tam >= 6) && (tam <= 8) ){
        campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
    }
    if ( (tam >= 9) && (tam <= 11) ){
    campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
    if ( (tam >= 12) && (tam <= 14) ){
    campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
    if ( (tam >= 15) && (tam <= 17) ){
    campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;}
        } 
    }
    
    //Busca o endereço de acordo com o CEP
    //Chamada: onclick="fncBuscaCEP('txtCEP1', 'txtCEP2', 'txtEndereco', 'txtBairro', 'txtCidade', 'cboEstado');"
    //Adicionar na página o iFrame: <iframe id="frmCEP" width="0" height="0"></iframe>
function fncBuscaCEP(strCEP1, strCEP2, strCampoEndereco, strCampoBairro, strCampoCidade, strCampoEstado)
{
    var cep = document.forms[0].elements[strCEP1].value + document.forms[0].elements[strCEP2].value;
    window.frmCEP.location.reload('BuscaCEP.aspx?cep=' + cep + '&form=Form1&CpLog=' + strCampoEndereco + '&CpBai=' + strCampoBairro + '&CpCid=' + strCampoCidade + '&CpEst=' + strCampoEstado);
}

function bloqueiaEnter()
{
 if (event.keyCode == 13)
 {
    event.keyCode = 0;
    return;
 }
}



// Formata RG para que receba apenas numeros e o caracter X
function FormataRG()
{
 if ((event.keyCode < 48 || event.keyCode > 57) && event.keyCode != 120 && event.keyCode != 88)
 {
    event.keyCode = 0;
    return;
 }

}

// Possibilitar apenas Numerico
function Numerico()
{
 if (event.keyCode < 48 || event.keyCode > 57)
 {
    event.keyCode = 0;
    return;
 }
}


//Formata o CPF ao digitar (Máscara)
//Chamada: onkeypress="FormataCPF(document.Form1,this.id,11,8,5,2,event);"
function FormataCPF(pForm,pCampo,pTamMax,pPos1,pPos2,pPosTraco,pTeclaPres)
{
 if (event.keyCode < 48 || event.keyCode > 57)
 {
    event.keyCode = 0;
    return;
 }
 
 
 var wTecla, wVr, wTam;
 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;
 
 }
}

//Valida o CPF
	function fctEhCPF(objCPF, args)
	{
		var CPF = args.Value.replace(/\D/gi,'');

		if (CPF.length < 11){
		    return args.IsValid = true;
		}
		
		if (CPF.length > 11){
		    return args.IsValid = false;
		}

		var POSICAO, I, SOMA, DV, DV_INFORMADO;
		var DIGITO = new Array(10);
		DV_INFORMADO = CPF.substr(9, 2);

		for (I=0; I<=8; I++) {
			DIGITO[I] = CPF.substr( I, 1);
		}

		// Calcula o valor do 10º dígito da verificação
		POSICAO = 10;
		SOMA = 0;
		for (I=0; I<=8; I++) {
			SOMA = SOMA + DIGITO[I] * POSICAO;
			POSICAO = POSICAO - 1;
		} 
		DIGITO[9] = SOMA % 11;
		if (DIGITO[9] < 2) {
				DIGITO[9] = 0;
		}
		else{
			DIGITO[9] = 11 - DIGITO[9];
		}

		// Calcula o valor do 11º dígito da verificação
		POSICAO = 11;
		SOMA = 0;
		for (I=0; I<=9; I++) {
			SOMA = SOMA + DIGITO[I] * POSICAO;
			POSICAO = POSICAO - 1;
		}
		DIGITO[10] = SOMA % 11;
		if (DIGITO[10] < 2) {
				DIGITO[10] = 0;
		}
		else {
				DIGITO[10] = 11 - DIGITO[10];
		}
		
		// Verifica se os valores dos dígitos verificadores conferem
		DV = DIGITO[9] * 10 + DIGITO[10];
		if (DV != DV_INFORMADO || CPF == '11111111111' || CPF == '22222222222' || CPF == '33333333333' || CPF == '44444444444' || CPF == '55555555555' || CPF == '66666666666' || CPF == '77777777777' || CPF == '88888888888' || CPF == '99999999999' || CPF == '00000000000') {
			return args.IsValid = false;
		}
		
		return args.IsValid = true;
	}


function fncValorFrete(strCEP1, strCEP2, strCampoEndereco, strCampoBairro, strCampoCidade, strCampoEstado)
{
    var cep = document.Form1.elements[strCEP1].value + document.Form1.elements[strCEP2].value;
    window.frmCEP.location.reload('ifraCalcularFrete.aspx?cep=' + cep + '&form=Form1&CpLog=' + strCampoEndereco + '&CpBai=' + strCampoBairro + '&CpCid=' + strCampoCidade + '&CpEst=' + strCampoEstado);
    document.Form1.txtNumero.focus();
}


function fctComparaDatas(diaData1,mesData1,anoData1,diaData2,mesData2,anoData2)
{
    data1 = new Date(anoData1, mesData1-1, diaData1); 
    data2 = new Date(anoData2, mesData2-1, diaData2);  
    
    if(data1 >= data2)   
        return false;    
    else
        return true;    
}

function ValidaEmail(sender, args){
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid

	if (!reg1.test(args.Value) && reg2.test(args.Value)) // if syntax is valid
		return args.IsValid = true;
	else
		return args.IsValid = false;
}

function ValidDate(objName) {
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var booFound = false;
	var intday;
	var intMonth;
	var intYear;
	var datefield = objName;
	
	//var strSeparatorArray = new Array("-"," ","/",".");
    var strSeparatorArray = new Array("/");
	
	var intElementNr;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "Jan";
	strMonthArray[1] = "Feb";
	strMonthArray[2] = "Mar";
	strMonthArray[3] = "Apr";
	strMonthArray[4] = "May";
	strMonthArray[5] = "Jun";
	strMonthArray[6] = "Jul";
	strMonthArray[7] = "Aug";
	strMonthArray[8] = "Sep";
	strMonthArray[9] = "Oct";
	strMonthArray[10] = "Nov";
	strMonthArray[11] = "Dec";
	strDate = objName;

	if (strDate.length < 5) {
		if (strDate.length < 1) {
			return true;
		} else {
			return false;
		}	
	}

	//Separator - Day - Month - Year
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) {
				err = 1;
				return false;
			} else {
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
		}
			
	}
	
	if (! booFound) { return false;	}

	if (strYear.length == 2) {
		strYear = '20' + strYear;
	}

	intday = parseInt(strDay, 10);
	if (isNaN(intday)) {
		err = 2;
		return false;
	}

	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) {
		for (i = 0;i<12;i++) {
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
			}
		}
		if (isNaN(intMonth)) {
			err = 3;
			return false;
	   }
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) {
		err = 4;
		return false;
	}
	if (intMonth>12 || intMonth<1) {
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
		err = 6;
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
		err = 7;
		return false;
	}
	if (intMonth == 2) {
		if (intday < 1) {
			err = 8;
			return false;
		}
		if (LeapYear(intYear) == true) {
			if (intday > 29) {
				err = 9;
				return false;
   			}
		} else {
			if (intday > 28) {
				err = 10;
				return false;
      		}
   		}
	}
	return true;
}

function LeapYear(intYear) {
	if (intYear % 100 == 0) {
		if (intYear % 400 == 0) { return true; }
	} else {
		if ((intYear % 4) == 0) { return true; }
	}
	return false;
}


function formataMoeda(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;
    if (whichCode == 13) return true;
    if (whichCode == 8) return true;
    if (whichCode == 9) 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;
}













var strCONTENTID;
var v_charCode = null;

function Mascara(o, f, e) {
    v_obj = o
    v_fun = f

    if (e && e.which) {
        e = e;
        v_charCode = e.which;
    }
    else {
        e = event;
        v_charCode = e.keyCode;
    }

    setTimeout("execmascara()", 1)
}

/*Função que Executa os objetos*/
function execmascara() {
    v_obj.value = v_fun(v_obj.value)
}

/*Função que padroniza DATA*/
function Mask_Data(v) {
    if (v_charCode != 8 && v_charCode != 46) {
        v = v.replace(/\D/g, "")
        v = v.replace(/(\d{2})(\d)/, "$1/$2")
        v = v.replace(/(\d{2})(\d)/, "$1/$2")
        if (v.length == 2 || v.length == 5) { v += '/'; }
    }
    return v
}


