function setValorDdl(strDdl, strHdn)
{
    objDdl = new getObj(strDdl);
    odjHdn = new getObj(strHdn);
    for(i=0;i<objDdl.obj.length;i++)
	{
	    if (objDdl.obj.options[i].selected==true)
		{
			odjHdn.obj.value = objDdl.obj.options[i].text;			
		} 
	}	
}
function isNull(val)
{
	return(val==null);
}
function inStr(param, sb)
{
	if(param.indexOf(sb) > -1)
	{
		return true;
	}
	else
	{
		return false;
	}
}
function isVisible(nObj)
{
    var objI = new getObj(nObj);
    if(objI.style.display == 'none' || objI.style.visibility == 'hidden')
    {
        return false;
    }
    return true;
}
function isDate(data)
{
    var reDat = /^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/ ;
    if (! reDat.test(data)) 
    {
        return false;
	}
	return true;
}
function isEmail(email)
{
    var reEml = /^([a-zA-Z0-9_\-])+(\.([a-zA-Z0-9_\-])+)*@((\[(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5]))\]))|((([a-zA-Z0-9])+(([\-])+([a-zA-Z0-9])+)*\.)+([a-zA-Z])+(([\-])+([a-zA-Z0-9])+)*))$/;
    if (! reEml.test(email)) 
    {
        return false;
	}
	return true;
}

function isCPF(cpf)
{
    if (cpf.length < 11)
    {
        return false;
    }
    for (i = 0; i <= 10; i++) 
	{
	    c = cpf.charAt(i);
		if(! (c >= "0") && (c <= "9")) 
		{
			return false;
		}
		varjsSoma = 0;
		for ( j = 0; j < 9; j++ ) 
		{
			varjsSoma += (10 - j) * ( eval(cpf.charAt(j)) );
		}
		vdigito = 11 - (varjsSoma % 11);
		if ( (varjsSoma % 11) < 2 ) vdigito = 0;
		if ( eval( cpf.charAt(9) ) != vdigito ) 
		{
			return false;
		}
		varjsSoma = 0;
		for ( k = 0; k < 9; k++ ) 
		{
			varjsSoma += (11 - k) * ( eval(cpf.charAt(k)) );
		}
		varjsSoma += 2 * ( eval(cpf.charAt(9)) );
		vdigito = 11 - (varjsSoma % 11);
		if ((varjsSoma % 11) < 2 ) vdigito = 0;
		if (eval(cpf.charAt(10)) != vdigito) 
		{
			return false;
		}
	}
	return true;
}
function isCNPJ(CNPJ) 
{
    var erro = "";
    if(CNPJ.length < 14)
    {
        erro += "CNPJ deve conter 14 dígitos\n";
    }
    var nonNumbers = /\D/;
    if (nonNumbers.test(CNPJ)) 
    {
        erro += "A verificação de CNPJ suporta apenas números\n"; 
    }
    var a = [];
    var b = new Number;             
    var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
    for (i=0; i<12; i++)
    {
        a[i] = CNPJ.charAt(i);
        b += a[i] * c[i+1];
    }
    if ((x = b % 11) < 2) 
    { 
        a[12] = 0;
    } 
    else 
    { 
        a[12] = 11-x;
    }
    b = 0;
    for (y=0; y<13; y++) 
    {
        b += (a[y] * c[y]); 
    }
    if ((x = b % 11) < 2) 
    { 
        a[13] = 0; 
    } 
    else 
    { 
        a[13] = 11-x; 
    }
    if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13]))
    {
        erro +="Dígito verificador com problema\n";
    }
    if (erro.length > 0)
    {
        return false;
    }     
    return true;
}
function isCC(ag,cc,dvCC)
{
    var jsSoma=0, parte1, cont, dv=0 ,j=0, i=0;
    if(ag.length<4)
    {
        for(i=1; i<4-ag.length; i++)
        {    
            ag = '0' + ag;
        }
    }
    if(cc.length<6)
    {
        for(i=1; i<6-cc.length; i++)
        {    
            cc = '0' + cc;
        }
    }
    var agcc = ag + '' +  cc + '' + dvCC;
	var cont = new Array(10);
	cont[0] = 1;
	cont[1] = 2;
	cont[2] = 1;
	cont[3] = 2;
	cont[4] = 1;
	cont[5] = 2;
	cont[6] = 1;
	cont[7] = 2;
	cont[8] = 1;
	cont[9] = 2;	
	var ascI = new Array(10);
	ascI[0] = 48;
	ascI[1] = 49;
	ascI[2] = 50;
	ascI[3] = 51;
	ascI[4] = 52;
	ascI[5] = 53;
	ascI[6] = 54;
	ascI[7] = 55;
	ascI[8] = 56;
	ascI[9] = 57;	
	for(i=0;i<=9;i++)
	{
		parcial = (ascI[parseInt(agcc.substr(i,1))]-48) * cont[i];
		parte1 = String(parcial/10);
		if (parte1.substr(0,1)==".")
	    {
		    parte1 = 0;
		}
		parte1 = parseInt(parte1);
		jsSoma = jsSoma + (parcial - (parte1 * 10)) + (parte1);		
	}
	jsSoma = jsSoma * 9;
	parte1 = String(jsSoma/10);
	if (parte1.substr(0,1)==".")
	{
	    parte1 = 0;
	}
	parte1 = parseInt(parte1);
	dv = (jsSoma - (parte1 * 10)) + 48;
	if (dv != ascI[agcc.substr(10,1)])
	{
    	return false; 
	}	
	
	return true;
}
function formata(src, mask)
{
    var i = src.value.length; 
    var saida = mask.substring(0,1);
    var texto = mask.substring(i)
    if (texto.substring(0,1) != saida)
    {
        src.value += texto.substring(0,1);
    }
}

function reverso(str)
{
	var lStr = str.length;
	var saida = '';
	for(i=lStr;i>=0;i--)
	{
		saida += str.substring(i-1,i);
	}
	return saida;
}

function completa(txt, tam, car)
{
    if(txt.length > 0)
    {
        while(txt.length < tam)
        {
            txt = car + txt;
        }
    }
    return txt;
}

function FormataValor(campo,tammax,teclapres) 
{
    //uso:
    //<input type="Text" name="fat_vr_bruto" maxlength="17" onKeyDown="FormataValor(this,17,event)">
    var tecla = teclapres.keyCode;//getKey(teclapres);
    vr = campo.value;
    vr = vr.replace( "/", "" );
    vr = vr.replace( "/", "" );
    vr = vr.replace( ",", "" );
    vr = vr.replace( ".", "" );
    vr = vr.replace( ".", "" );
    vr = vr.replace( ".", "" );
    vr = vr.replace( ".", "" );
    tam = vr.length;
    
    if (tam < tammax && tecla != 8){ tam = vr.length + 1; }

    if (tecla == 8 ){    tam = tam - 1; }

    if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
        if ( tam <= 2 ){ 
             campo.value = vr; }
         if ( (tam > 2) && (tam <= 5) ){
             campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); }
         if ( (tam >= 6) && (tam <= 8) ){
             campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, 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 - 2, 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 - 2, 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 );}
    }            
}


function mascara(txtMascara, txtValor, txtChar, sentido)
{
    var saida='';
    var iAux=0;
    switch (sentido)
    {
        case 'LR':
        {    
            for(i=0; i< txtMascara.length; i++)
            {
                if(iAux<txtValor.length)
                {
                    if(txtMascara.substring(i,i+1)==txtChar)
                    {
                        saida += txtValor.substring(iAux,iAux+1);
                        iAux++;
                    }
                    else
                    {
                        saida += txtMascara.substring(i,i+1);
                    }
                }
            }
            break;
        }
        case 'RL':
        {
            iAux=txtValor.length-1;
            for(i=txtMascara.length-1; i>=0; i--)
            {
                if(iAux >=0)
                {
                    if(txtMascara.substring(i,i+1)==txtChar)
                    {
                        saida = txtValor.substring(iAux,iAux+1) + saida;
                        iAux--;
                    }
                    else
                    {
                        saida = txtMascara.substring(i,i+1) + saida;
                    }
                }
            }
            break;
        }        
    }//switch    
    return saida;
}
function soNum(e) 
{
	var tecla = getKey(e);
	var strTecla = String.fromCharCode(tecla);
	var reNum = /^(\d)+$/;	
    if (! reNum.test(strTecla) && tecla != 0) 
    {
        return false;
	}
	return true;	
}
function soLetra(e)
{
	var tecla = getKey(e);
	var strTecla = String.fromCharCode(tecla);
	var reLetra = /^[^<>`~!/@\#}$%:;)(_^{&*=|'+-0123456789"¨?]+$/;
    if (! reLetra.test(strTecla) && tecla != 0) 
    {
        return false;
	}
	return true;	
}
function soLetraSemAcento(e)
{
	var tecla = getKey(e);
	var strTecla = String.fromCharCode(tecla);
	var reLetraSA = /^([a-zA-Z ])+$/;
    if (! reLetraSA.test(strTecla) && tecla != 0) 
    {
        return false;
	}
	return true;	
}
function soLetraEmail(e)
{
	var tecla = getKey(e);
	var strTecla = String.fromCharCode(tecla);
	var reLetraEmail = /^([a-zA-Z0-9_\-\.@])+$/;	
    if (! reLetraEmail.test(strTecla) && tecla != 0) 
    {
        return false;
	}
	return true;	
}
function soLetraENumero(e)
{
	var tecla = getKey(e);
	var strTecla = String.fromCharCode(tecla);
	var reLetraENumero = /^([a-zA-Z0-9 ])+$/;	
    if (! reLetraENumero.test(strTecla) && tecla != 0) 
    {
        return false;
	}
	return true;	
}

function right(str, len)
{
	return str.substr(str.length-len);
}

function left(str, len)
{
	return str.substr(0, len);
}

function nextObj(aObj, lim, nObj)
{    
    if(aObj.value.length >= lim)
    {
        var objI = new getObj(nObj);
        objI.obj.focus();        
    }
}
function showL(nObj)
{
    var objI = new getObj(nObj);
    objI.style.display = '';
}
function hideL(nObj)
{
    var objI = new getObj(nObj);
    objI.style.display = 'none';
}
function getObj(name)
{
    if (document.getElementById)
    {  	  
  	    this.obj = document.getElementById(name);
	    this.style = document.getElementById(name).style;	    
    }
    else if (document.all)
    {	    
	    this.obj = document.all[name];
	    this.style = document.all[name].style;	    
    }
    else if (document.layers)
    {	    
	    this.obj = getObjNN4(document,name);
	    this.style = this.obj;	    
    }
}
function getObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}
function isObject(a) 
{
    return (typeof a == 'object' && !!a) || isFunction(a);
} 
function isFunction(a) 
{
    return typeof a == 'function';
}
function getKey(evt) 
{
    //return evt?(evt.keyCode?evt.keyCode:(evt.which?evt.which:evt.charCode)):null;
    var e = evt? evt : window.event; 
	if(!e) return; 
	var key = 0; 
	key = e.charCode; 
	if (typeof(key) == 'undefined') 
	{ 
		key = e.keyCode; 
		if (typeof(key) == 'undefined') 
		{ 
			key = e.which; 
		} 
	} 
	return key;
}
function url_encode(str) {  
	var hex_chars = "0123456789ABCDEF";  
    var noEncode = /^([a-zA-Z0-9\_\-\.])$/;  
    var n, strCode, hex1, hex2, strEncode = "";  

    for(n = 0; n < str.length; n++) {  
    	if (noEncode.test(str.charAt(n))) {  
        	strEncode += str.charAt(n);  
        } else {  
        	strCode = str.charCodeAt(n);  
            hex1 = hex_chars.charAt(Math.floor(strCode / 16));  
            hex2 = hex_chars.charAt(strCode % 16);  
            strEncode += "%" + (hex1 + hex2);  
        }  
     }  
     return strEncode;  
}  	
function url_decode(str) {  
	var n, strCode, strDecode = "";  

    for (n = 0; n < str.length; n++) {  
    	if (str.charAt(n) == "%") {  
        	strCode = str.charAt(n + 1) + str.charAt(n + 2);  
            strDecode += String.fromCharCode(parseInt(strCode, 16));  
            n += 2;  
        } else {  
        	strDecode += str.charAt(n);  
        }  
    }  
    return strDecode;  
}  

function AbrePop(url) {
	var largura = '600';
	var altura = '400';
	var rolagem = 'yes';
	var params = '';
	if (arguments.length > 1) {
		if (arguments[1]!='') largura = arguments[1];
		if (arguments.length > 2) {
			if (arguments[2]!='') altura = arguments[2];
			if (arguments.length > 3) {
				if (arguments[3]!='') rolagem = arguments[3];
				if (arguments.length > 4) {
					if (arguments[4]!='') params = ',' + arguments[4];
				}
			}
		}
	}
	window.open(url, '_blank', 'top=0,left=0,scrollbars=' + rolagem + ',width=' + largura + ',height=' + altura + params)
}

function soAlfaNumerico(e)
{
	var tecla = getKey(e);

	if(
		!(
			(
				((tecla > 47) && (tecla < 58))  ||
				((tecla > 64) && (tecla < 91))  ||
				((tecla > 96) && (tecla < 123)) ||
				((tecla > 224) && (tecla < 228)) ||
				((tecla > 242) && (tecla < 246)) ||
				(tecla==252) ||
				(tecla==250) ||
				(tecla==241) ||
				(tecla==237) ||
				(tecla==234) ||
				(tecla==233) ||
				(tecla==92) ||
				(tecla==47) ||
				(tecla==46) ||
				(tecla==45) ||
				(tecla==39) ||
				(tecla==37) ||
				(tecla==36) ||
				(tecla==35) ||
				(tecla==32) ||
				(tecla==9) ||
				(tecla==8)
				) && 
				(tecla!=168)
			)
		)
	{
		return true;//false;
	}
		return true;
}