


function FormataValor(campo, teclapres) 
{
    try
    {
	    var tecla = (teclapres.keyCode)?teclapres.keyCode: teclapres.which;
	    vr = getValue(campo)
	    vr = objElement.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;

	    tam = vr.length + 1 ; 

	    if (tecla == 8 ){	tam = tam - 1 ; }
    		
	    if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
	    {
		    if ( tam <= 2 )
		    {	setValue(campo, vr); }
	 	    if ( (tam > 2) && (tam <= 5) )
	 	    {	setValue(campo, vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam )) ; }
	 	    if ( (tam >= 6) && (tam <= 8) )
	 	    {	setValue(campo, vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam )) ; }
	 	    if ( (tam >= 9) && (tam <= 11) )
	 	    {	setValue(campo, 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) )
	 	    {	setValue(campo, 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) )
	 	    {	setValue(campo, 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 )) ;}
	    }	
    }
    catch(objErr)
    {
        gravarErro(ex + ' ; FormataDado.FormataValor; tecla: ' + tecla + ' campo: ' + campo);
        return null;
    } 
    
}


//Completa 
function completaURL(path)
{

	var strSite = new String('http://');
	
	try
	{
	    strSite += document.location.hostname;	
	    if(document.location.port != '')
	         strSite += ':' + document.location.port;
	    strSite += document.location.pathname.substring(0, document.location.pathname.indexOf('/', 1)) + '/';
	    strSite += path;
	}
    catch(objErr)
    {
        gravarErro(ex + ' ; FormataDado.completaURL; tecla: ' + tecla + ' campo: ' + campo);
        return null;
    } 
    
	return strSite;
	
}
