function abrirventana(url,ancho,alto,valorOpciones){	
	if (ancho==null) var ancho=550;
	if (alto==null) var alto=550;
	var left=(screen.width - ancho)/2;
	var top=(screen.height - alto)/2;	
	if(!valorOpciones) {
		valorOpciones='width='+ancho+',height='+alto+',left='+left+',top='+top+',location=no,toolbar=no,status=no,menubar=no,directories=no,resizable=no,scrollbars=yes,copyhistory=no';
	}	
	window.open(url,'',valorOpciones);
}
function formatNumber(num, culture) {
    num = num.toString().replace(/\$|\,/g,'');
    
    if(isNaN(num))
        num = "0";
        
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    
    if(cents<10)
        cents = "0" + cents;
        
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++){
        if (culture == 'es'){
            num = num.substring(0,num.length-(4*i+3)) + '.' + num.substring(num.length-(4*i+3));
        }else if (culture == 'es-es'){
            num = num.substring(0,num.length-(4*i+3)) + '.' + num.substring(num.length-(4*i+3));
        }else{
            num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
        }
    }
    
    return (((sign)?'':'-') + num);
}

function showHelp(pstr_idhelp, pstr_idbor, pstr_iderror, pstr_iderror2, pstr_iderror3, pstr_iderror4, pstr_iderror5, pstr_iderror6)
    { 
    
    //Retrasamos el mostrar la ayuda unas décimas de segundo 
    //para que salten los validadores antes que el showHelp al pulsar en el botón submit.    
    if (pstr_iderror == null) pstr_iderror = "";
    if (pstr_iderror2 == null) pstr_iderror2 = "";
    if (pstr_iderror3 == null) pstr_iderror3 = "";
    if (pstr_iderror4 == null) pstr_iderror4 = "";
    if (pstr_iderror5 == null) pstr_iderror5 = "";
    if (pstr_iderror6 == null) pstr_iderror6 = "";
    
    setTimeout("showHelpText('" + pstr_idhelp + "', '" + pstr_idbor + "', '" + pstr_iderror + "', '" + pstr_iderror2 + "', '" + pstr_iderror3 + "', '" + pstr_iderror4 + "', '" + pstr_iderror5 + "', '" + pstr_iderror6 + "');", 50);
    }

function showHelpText(pstr_idhelp, pstr_idbor, pstr_iderror, pstr_iderror2, pstr_iderror3, pstr_iderror4, pstr_iderror5, pstr_iderror6)
    { 
    //Mostramos el mensaje de ayuda si el mensaje/s de error asociado no está activo
    
    var  pstr_iderror_obj = document.getElementById(pstr_iderror);
    var  pstr_iderror2_obj = document.getElementById(pstr_iderror2);
    var  pstr_iderror3_obj = document.getElementById(pstr_iderror3);
    var  pstr_iderror4_obj = document.getElementById(pstr_iderror4);
    var  pstr_iderror5_obj = document.getElementById(pstr_iderror5);
    var  pstr_iderror6_obj = document.getElementById(pstr_iderror6);
    var xbol_ok = true;     
    if((pstr_iderror != null)  && (pstr_iderror != '')  && (pstr_iderror_obj != null)  && (pstr_iderror_obj.style.display != 'none')  && (pstr_iderror_obj.style.visibility != "hidden"))  xbol_ok = false;
    if((pstr_iderror2 != null) && (pstr_iderror2 != '') && (pstr_iderror2_obj != null) && (pstr_iderror2_obj.style.display != 'none') && (pstr_iderror2_obj.style.visibility != "hidden")) xbol_ok = false;
    if((pstr_iderror3 != null) && (pstr_iderror3 != '') && (pstr_iderror3_obj != null) && (pstr_iderror3_obj.style.display != 'none') && (pstr_iderror3_obj.style.visibility != "hidden")) xbol_ok = false;
    if((pstr_iderror4 != null) && (pstr_iderror4 != '') && (pstr_iderror4_obj != null) && (pstr_iderror4_obj.style.display != 'none') && (pstr_iderror4_obj.style.visibility != "hidden")) xbol_ok = false;
    if((pstr_iderror5 != null) && (pstr_iderror5 != '') && (pstr_iderror5_obj != null) && (pstr_iderror5_obj.style.display != 'none') && (pstr_iderror5_obj.style.visibility != "hidden")) xbol_ok = false;
    if((pstr_iderror6 != null) && (pstr_iderror6 != '') && (pstr_iderror6_obj != null) && (pstr_iderror6_obj.style.display != 'none') && (pstr_iderror6_obj.style.visibility != "hidden")) xbol_ok = false;
    
        
    if(xbol_ok) 
        {
        if(document.getElementById(pstr_idhelp) != null) document.getElementById(pstr_idhelp).style.display = '';
        if(document.getElementById(pstr_idbor) != null) document.getElementById(pstr_idbor).className = "f_helpbor";
        }
        
    }

function trim(cadena) {
    for (z = 0; z < cadena.length; ) {
        if (cadena.charAt(z) == " ")
            cadena = cadena.substring(z + 1, cadena.length);
        else
            break;
    }

    for (z = cadena.length - 1; z >= 0; z = cadena.length - 1) {
        if (cadena.charAt(z) == " ")
            cadena = cadena.substring(0, z);
        else
            break;
    }

    return cadena;
}   
    
function hideHelp(pstr_idhelp, pstr_idbor)
    {    
    if(document.getElementById(pstr_idhelp) != null) document.getElementById(pstr_idhelp).style.display='none';
    if(document.getElementById(pstr_idbor) != null) document.getElementById(pstr_idbor).className = "";
    }  
    
       //separador de miles         
        function soloNumeros(event) 
        {
           
           var evento_key;
           var keynum = 0;
           var numcheck;
           var keychar;
                
          
           if (window.event)//IE
           {
                evento_key = window.event.keyCode;
                 if (evento_key >= 48 && evento_key <= 57) 
                    {
                        window.event.keyCode = evento_key;  
                        //alert("valorfinal");           
                        return true;                
                    } 
            
                 else
                    {
                        window.event.keyCode = 0;
                        return false;
                    }
           }
           else 
           {
                if(event.which)//Mozilla Firefox
                {
                    
                    evento_key = event.which;
                    if (evento_key >= 48 && evento_key <= 57)
                    {
                        return true;                
                    } 
                    if (evento_key==8)
                    {
                        return true;    
                    }
                    else
                    {
                        event.preventDefault(); 
                        return false;
                    }
                }
           }                
        };

 
        function separadorMilesM(objeto,event)
        {
        
            if (event.which != null)             
            {                                               
                var evento_key = event.which;                                                     
                if (evento_key==8)                
                {
                    //8 para retroceso
                    evento_key=50;
                }  
                if (evento_key==46)                
                {
                    //tecla suprimir
                    evento_key=50;
                }           
                if ((evento_key >= 96 && evento_key <= 105) || (evento_key >= 48 && evento_key <= 57))                 
                {
                    var strCheck ='0123456789';
                    var milSep=".";
                    var filamilSep=0;
                    var valorIndividual='';
                    var numeroinverso='';
                    
                    //alert(evento_key);

                    for (j=objeto.value.length-1; j>=0 ;j--) 
                    {
                        valorIndividual=objeto.value.charAt(j);
                        if (strCheck.indexOf(valorIndividual)>=0) 
                        {
                            if (filamilSep==3) 
                            {
                                numeroinverso=numeroinverso+milSep;
                                filamilSep=0;
                            }

                            // Quito cero a izquierda
                            if (!(j==0 && valorIndividual=='0')) 
                            {
                                numeroinverso=numeroinverso+valorIndividual;
                                filamilSep=filamilSep+1;
                            }

                        }
                    }

                    var valorfinal='';
                    for (j = numeroinverso.length-1 ; j>=0 ; j--) 
                    {
                        valorIndividual=numeroinverso.charAt(j);
                        valorfinal=valorfinal+valorIndividual;
                    }
                    objeto.value = valorfinal;
                    return true;
                 } 
                 else 
                 {
                        return false;
                 }
            }
            if (objeto.value != null)
            {                
                var evento_keyM =window.event.keyCode;                 
                if (evento_keyM==8)                
                {
                    //8 para retroceso
                    evento_keyM=50;
                }                  
                if (evento_keyM==46)                
                {
                    //tecla suprimir
                    evento_keyM=50;
                }           
                if ((evento_keyM >= 96 && evento_keyM <= 105) || (evento_keyM >= 48 && evento_keyM <= 57))                 
                {
                    var strCheckM ='0123456789';
                    var milSepM=".";
                    var filamilSepM=0;
                    var valorIndividualM='';
                    var numeroinversoM='';
                    for (j=objeto.value.length-1; j>=0 ;j--) 
                    {
                        valorIndividualM=objeto.value.charAt(j);
                        if (strCheckM.indexOf(valorIndividualM)>=0) 
                        {
                            if (filamilSepM==3) 
                            {
                                numeroinversoM=numeroinversoM+milSepM;
                                filamilSepM=0;
                            }
                            // Quito cero a izquierda
                            if (!(j==0 && valorIndividualM=='0')) 
                            {
                                numeroinversoM=numeroinversoM+valorIndividualM;
                                filamilSepM=filamilSepM+1;
                            }
                        }
                    }
                    var valorfinalM='';
                    for (j = numeroinversoM.length-1 ; j>=0 ; j--) 
                    {
                        valorIndividualM=numeroinversoM.charAt(j);
                        valorfinalM=valorfinalM+valorIndividualM;
                    }
                    objeto.value = valorfinalM;
                    return true;
                 } 
                 else 
                 {
                        return false;
                 }
            }
    };
        