	
    // validar si el valor es numero
	function EsNumero(n)
    {
       if (!(n=='0' || n=='1' || n=='2' || n=='3' || n=='4' || n=='5' || n=='6'|| n=='7' || n=='8' || n=='9'))
            {   return false;}
       return true;
    }

	function ValidaRut()
	{
	    browserName = navigator.appName;
	    browserVer = parseInt(navigator.appVersion);
		var msj="";
	    if (!RutCorrecto(window.document.frm.rut.value))
	    {
	        msj = "EL RUT ingresado no es correcto. \n"
	        alert( msj + "Por favor, verifíquelo e ingréselo nuevamente.");
	        if ((browserName == "Microsoft Internet Explorer" || browserName == "Netscape")&& (browserVer >= 4))
            {
				window.document.frm.rut.focus();
				window.document.frm.rut.select();
	            return true;
		    }
		    return true;
	    }
        return true;
    }
        
	function RutCorrecto(rutx)
    {
        var rutaux="";
        var dv='';
        var dvc='';
         
        for (i=0; i<rutx.length; i++)
 		{
 			if (rutx.charAt(i)!=' ' && rutx.charAt(i)!='.' && rutx.charAt(i)!='-')
				rutaux = rutx.charAt(i) + rutaux;
        }           
          
        // validar el caracter correspondiente al digito verificador
        dv = rutaux.charAt(0);
        if (!(EsNumero(dv) || dv=='k' || dv == 'K'))
           return false;

       // validar los caracteres correspondientes al rut                      
	   for (i=1; i<rutaux.length; i++)
       {
			if (!(EsNumero(rutaux.charAt(i))))
                return false;
       }

       // validar digito verificador
	   if (rutaux.length>=2)
	   {
		   suma = 0;
           mult = 2;
		   for (i=1; i<rutaux.length; i++)
           {
               suma = suma + rutaux.charAt(i) * mult;
               mult++;
               if (mult==8)
                   mult = 2;
           }
           resto = suma % 11;
           if (resto == 1)
              dvc='k';
           else if (resto == 0)
                dvc = '0';
           else
           {
                dvr = 11 - resto;
                dvc = dvr + "";
           }            
	       if (dvc == rutaux.charAt(0).toLowerCase())
           {
               rutx = '-' + rutaux.charAt(0).toUpperCase();
               j = 0;
              for (i = 1; i < rutaux.length; i++)
               {
                   rutx = rutaux.charAt(i) + rutx;
                   j++;
                   if (j==3)
		           {
                       rutx =  rutx;
                        // rutx = '.' + rutx;
                       j=0;   
 		           }
               }
               window.document.frm.rut.value = rutx;
               return true;
           }
           
        }
        document.frm.rut.focus();
        return false;
     }
        
     
	  
	
	  
	