function validarCaracteresSenha(oSrc, args){
    args.IsValid = (args.Value.length >= 4);
}

function FormataValor(controle,digitos,decimais,teclapres)
{
    vr = controle.value;
    vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );

    
    if(vr.length > digitos)
    {
        vr = vr.substr(0,digitos) + "," + vr.substr(digitos, decimais);
    }
    
    controle.value = vr;
}

function Popups(url,popName,wdt,hgt,scrolls)
{
    midWidth = (screen.AvailWidth - wdt) / 2;
    midHeight= (screen.AvailHeight - hgt) / 2;
    prop = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+scrolls+",resizable=no,copyhistory=no,width="+wdt+",height="+hgt+",left="+midWidth+",top="+midHeight+"";
    window.open(url,popName,prop);
}

function inTd(obj)
{
    obj.style.backgroundColor = "#DFFBD2";
}

function outTd(obj)
{
    obj.style.backgroundColor = "";
    //obj.style.cursor = "";
}

function inTdFont(obj)
{
    obj.style.backgroundColor = "#DFFBD2";
    obj.style.fontSize = "12 px";
    // obj.style.font-size += 5;
}

function outTdFont(obj)
{
    obj.style.backgroundColor = "";
    obj.style.fontSize = "10 px";
    // obj.style.font-size -= 5;
    //obj.style.cursor = "";
}


function vdata(wobj, wparam)
{
     var wdata = wobj.value;
     var wdatanew = "";
     var wletra = "";
     var wtoday = new Date();
     var wanoatu = wtoday.getFullYear();
     var wmesatu = wtoday.getMonth() + 1;
     var wdiaatu = wtoday.getDate();
     wdiaatu = "00" + wdiaatu
     wdiaatu = wdiaatu.substring(wdiaatu.length - 2,wdiaatu.length)
     wmesatu = "00" + wmesatu
     wmesatu = wmesatu.substring(wmesatu.length - 2,wmesatu.length)

     if (wdata.toUpperCase() == "H")
     {
          wdata = wdiaatu + wmesatu + wanoatu
     }
     
     for (x = 0; x < wdata.length; x++)
     {
          wletra = wdata.substring(x,x + 1);
          if (!isNaN(parseFloat(wletra)))
          {
               wdatanew = wdatanew + wletra;
          }
     }

     wdata = wdatanew;
     wdatanew = "";
    
     if (wdata.length == 2)
     {
          wdata = wdata + wmesatu
     }
     if (wdata.length == 4)
     {
          wdata = wdata + wanoatu
     }
     if (wdata.length = 6 || wdata.length == 8)
     {
          var wdia = wdata.substring(0,2);
          var wmes = wdata.substring(2,4);
          if (wdata.length == 6)
          {
               var wano = wdata.substring(4,6);
               wanoatu = wanoatu + ""
               wano = wanoatu.substring(0,2) + wano;
          }
          else
          {
               var wano = wdata.substring(4,8);
          }
          var wdiamax = "312831303130313130313031";
          var wanomax = "3000";
          var wmesmax = "12";
          if (eval(wano) >= 1900 && eval(wano) <= eval(wanomax))
          {
               if (eval(wmes) >= 1 && eval(wmes) <= eval(wmesmax))
               {
                    var wini = eval(wmes) * 2 - 2;
                    var wfin = eval(wmes) * 2;
                    if (eval(wdia) >= 1 && eval(wdia) <= eval(wdiamax.substring(wini,wfin)))
                    {
                         wdatanew = "1";
                    } 
                    else
                    {
                         if (parseInt(eval(wano)/4) - eval(wano)/4 == 0 && wdia == "29" && wmes == "02")
                         {
                              wdatanew = "1";
                         }
                    }
               }
          }
     }
     if (wdatanew == "1")
     {
          wdia = "0" + wdia;
          wdia = wdia.substring(wdia.length, wdia.length - 2);
          wmes = "0" + wmes;
          wmes = wmes.substring(wmes.length, wmes.length - 2);
          wdatanew = wdia + "/" + wmes + "/" + wano;
     }
     else
     {
          wdatanew = "";
     }
     wobj.value = wdatanew;
}

function completar(caixa){
	try{
		var novoValor = soNumeros(caixa);
		var max = 7;
		for(var qtd = novoValor.length; qtd < max; qtd++)
			novoValor = '0' + novoValor;
		
		caixa.value = novoValor;
	}
	catch(e){
	}
}

function pular(obj, qtd, idProxObj)
{
	try
	{
		obj.value = soNumeros(obj);
		
		if(obj.value.length == qtd)
		{
    		var next = getObj(idProxObj);
			if(next!=null)
			{
			    next.focus();
			}
		}
	}
	catch(e){
	alert(e.message);
	}
}

function soNumeros(obj){
	var novoValor = "";
	try{
		var valor = obj.value;
		for(var i = 0; i < valor.length; i++){
			var letra = valor.substring(i, i+1);
			if(!isNaN(letra))
				novoValor += letra;
		}
	}
	catch(e){
	}
	return novoValor;
}

try{
	document.onkeydown = HotKeys;
	ffocus();
}
catch(e){
}

function getObj(idObjeto){
	var obj = null;
	try{
		if(document.getElementById)
			obj = document.getElementById(idObjeto);
		else if(document.all)
			obj = document.all(idObjeto);
		else if(document.layers)
			obj = document.layers(idObjeto);
	}
	catch(e){
	}
	
	return obj;
}

function MostrarOcultarPainel(obj)
{
    if (document.getElementById(obj).style.display == "none")
        document.getElementById(obj).style.display = "block";
    else
        document.getElementById(obj).style.display = "none";
}

function Recorrencia(obj, strTxt)
{
    /*alert(obj.checked);
    
    alert(document.getElementById(strTxt).disabled);
    alert(document.getElementById(strTxt).value);*/

    if(obj.checked)
    {
        document.getElementById(strTxt).disabled = true;
        document.getElementById(strTxt).value = "0";
    }
    else
    {
        document.getElementById(strTxt).disabled = false;
    }
}
