function getXMLHTTPRequest()
{
var req = false;
try
  {
    req = new XMLHttpRequest(); /* p.e. Firefox */
  }
catch(err1)
  {
  try
    {
     req = new ActiveXObject("Msxml2.XMLHTTP");
  /* algunas versiones IE */
    }
  catch(err2)
    {
    try
      {
       req = new ActiveXObject("Microsoft.XMLHTTP");
  /* algunas versiones IE */
      }
      catch(err3)
        {
         req = false;
        }
    }
  }
return req;
}

var miPeticion = getXMLHTTPRequest();
//*********************************************************************************************************************************************
//Valida correo
function valida_correo(correo) {
		  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(correo)){
			
		   return (true)
		  } else {
		   
		   return (false);
		  }
		 }
//******************************************************************************************************************************************
//************************************************************************************************
function from(id,ide,url){
		//alert(id);
	
		var mi_aleatorio=parseInt(Math.random()*99999999);//para que no guarde la página en el caché...
		var vinculo=url+"?id="+id+"&rand="+mi_aleatorio;
		//alert(vinculo);
		miPeticion.open("GET",vinculo,true);//ponemos true para que la petición sea asincrónica
		miPeticion.onreadystatechange=miPeticion.onreadystatechange=function(){
               if (miPeticion.readyState==4)
               {
				   //alert(miPeticion.readyState);
                       if (miPeticion.status==200)
                       {
						   		//alert(miPeticion.status);
                               var http=miPeticion.responseText;
							   //alert(http);
							   // var txt=unescape(http);
							 //  var txt2=txt.replace(/\+/gi," ");
							 	//document.getElementById('resultados').style.display="block";
							   document.getElementById(ide).innerHTML= http;
							   
                       }
				   }else{
					   //document.getElementById('resultados').style.display="block";
				   	document.getElementById(ide).innerHTML="<img src='ima/ajax-loader.gif' title='cargando...'>";
               }
       }
       miPeticion.send(null);
		
}
//********************************************************************************************************************************************
//valida rut
    function EsRut(texto)
    {   
       var tmpstr = "";   
       for ( i=0; i < texto.length ; i++ )      
          if ( texto.charAt(i) != ' ' && texto.charAt(i) != '.' && texto.charAt(i) != '-' )
             tmpstr = tmpstr + texto.charAt(i);   
       texto = tmpstr;   
       largo = texto.length;   

       if ( largo < 2 )   
       {      
          return false;   
       }   

       for (i=0; i < largo ; i++ )   
       {         
          if ( texto.charAt(i) !="0" && texto.charAt(i) != "1" && texto.charAt(i) !="2" && texto.charAt(i) != "3" && texto.charAt(i) != "4" && texto.charAt(i) !="5" && texto.charAt(i) != "6" && texto.charAt(i) != "7" && texto.charAt(i) !="8" && texto.charAt(i) != "9" && texto.charAt(i) !="k" && texto.charAt(i) != "K" )
          {         
             return false;      
          }   
       }   

       var invertido = "";   
       for ( i=(largo-1),j=0; i>=0; i--,j++ )      
          invertido = invertido + texto.charAt(i);   
       var dtexto = "";   
       dtexto = dtexto + invertido.charAt(0);   
       dtexto = dtexto + '-';   
       cnt = 0;   

       for ( i=1,j=2; i<largo; i++,j++ )   
       {      
          if ( cnt == 3 )      
          {         
             dtexto = dtexto + '.';         
             j++;         
             dtexto = dtexto + invertido.charAt(i);         
             cnt = 1;      
          }      
          else      
          {            
             dtexto = dtexto + invertido.charAt(i);         
             cnt++;      
          }   
       }   

       invertido = "";   
       for ( i=(dtexto.length-1),j=0; i>=0; i--,j++ )      
          invertido = invertido + dtexto.charAt(i);   

       if ( revisarDigito(texto) )      
          return true;   

       return false;
    }

    function revisarDigito(componente)
    {   
       var crut =  componente
       largo = crut.length;   
       if ( largo < 2 )   
       {      
          return false;   
       }   
       if ( largo > 2 )      
          rut = crut.substring(0, largo - 1);   
       else      
       rut = crut.charAt(0);   
       dv = crut.charAt(largo-1);   
       
       if ( dv != '0' && dv != '1' && dv != '2' && dv != '3' && dv != '4' && dv != '5' && dv != '6' && dv != '7' && dv != '8' && dv != '9' && dv != 'k'  && dv != 'K')   
       {      
          return false;   
       }      

       if ( rut == null || dv == null )
          return 0   

       var dvr = '0'   
       suma = 0   
       mul  = 2   

       for (i= rut.length -1 ; i >= 0; i--)   
       {   
          suma = suma + rut.charAt(i) * mul      
          if (mul == 7)         
             mul = 2      
          else             
             mul++   
       }   
       res = suma % 11   
       if (res==1)      
          dvr = 'k'   
       else if (res==0)      
          dvr = '0'   
       else   
       {      
          dvi = 11-res      
          dvr = dvi + ""   
       }
       if ( dvr != dv)   
       {      
          return false   
       }

       return true
    }

//***********************************************************************************
//función para dar formato  a números
 function dar_formato(num){  
 var cadena = ""; var aux;  
 var cont = 1,m,k;  
 if(num<0) aux=1; else aux=0;  
num=num.toString();  
 for(m=num.length-1; m>=0; m--){  
  cadena = num.charAt(m) + cadena;  
  if(cont%3 == 0 && m >aux)  cadena = "." + cadena; else cadena = cadena;  
  if(cont== 3) cont = 1; else cont++;  
 }  
 cadena = cadena.replace(/.,/,",");   
 return cadena;  
 }
//**************************************************************************************************************
function agranda(id,num){
		document.getElementById(id).style.width=num;
		document.getElementById(id).style.height=num;
	}
function achica(id,num){
		document.getElementById(id).style.width=num;
		document.getElementById(id).style.height=num;
	}	
function td(id,color){
		document.getElementById(id).style.backgroundColor=color;
	}
function no_td(id,color){
		document.getElementById(id).style.backgroundColor=color;
	}
function ima(id,ima){
		document.getElementById(id).src=ima;
	}
function no_ima(id,ima){
		document.getElementById(id).src=ima;
	}
function valida_numero(num){
	if (!/^([0-9])*$/.test(num)){
                return false;
                    }else{
						return true;
						}
	}
//******************************************************************************
function ocultar(id){
		document.getElementById(id).style.display="none";
	}
function mostrar(id){
		ocultar('uno');
		ocultar('dos');
		ocultar('tres');
		ocultar('cuatro');
		//ocultar('cinco');
		//ocultar('seis');
		ocultar("siete");
		if (id=="dos"){
			document.getElementById(id).style.display="block";
			document.getElementById("tres").style.display="block";
			document.getElementById("siete").style.display="block";
			}else{
				document.getElementById(id).style.display="block";
				}
		
	}
//******************************************************************************
function detecta(){
var navegador = navigator.appName;
//alert(navegador);
switch (navegador){
case "Microsoft Internet Explorer":
//alert("Su navegador es Internet Explorer");
document.getElementById("capa").style.marginLeft="0px";
document.getElementById("capa").style.marginTop ="0px";
document.getElementById("capa2").style.marginLeft="0px";
document.getElementById("capa2").style.marginTop ="0px";

break;
case "Netscape":
//alert("Su navegador es Mozilla o Google Chrome");
document.getElementById("capa").style.marginLeft="165px";
document.getElementById("capa").style.marginTop ="-23px";
break;
}
}
//*****************************************************************
function show(id){
		document.getElementById(id).style.display="block";
	}
function hide(id){
		document.getElementById(id).style.display="none";
	}
	
function popUp(URL) 
{
	day = new Date();
	ida = day.getTime();
	eval("page" + ida + " = window.open(URL, '" + ida + "', 'toolbar=0,scrollbars=0,location=0,statusbar=200,menubar=0,resizable=200,left=400,top=400,width=550,height=415');");
}

