function habilita(valor,texto){
if (valor==9999){
	controles.innerHTML='<input type="text" id="otra" name="otra" maxlength="25" size=25 onkeypress="return soloNombres(this,event);" value='+texto+'>'
	document.principal.otra.focus()
}
else
	controles.innerHTML='<input type="text" id="otra" name="otra" maxlength="25" size=25 disabled value='+texto+ '>'
}

var xsepara='                                                       ';

var Lista_Region_1=new Array();Lista_Region_1[0]="-1*"+xsepara;
var Lista_Region_2=new Array();Lista_Region_2[0]="-1*"+xsepara;
var Lista_Region_3=new Array();Lista_Region_3[0]="-1*"+xsepara;
var Lista_Region_4=new Array();Lista_Region_4[0]="-1*"+xsepara;
var Lista_Region_5=new Array();Lista_Region_5[0]="-1*"+xsepara;
var Lista_Region_6=new Array();Lista_Region_6[0]="-1*"+xsepara;
var Lista_Region_7=new Array();Lista_Region_7[0]="-1*"+xsepara;
var Lista_Region_8=new Array();Lista_Region_8[0]="-1*"+xsepara;
var Lista_Region_9=new Array();Lista_Region_9[0]="-1*"+xsepara;
var Lista_Region_10=new Array();Lista_Region_10[0]="-1*"+xsepara;
var Lista_Region_11=new Array();Lista_Region_11[0]="-1*"+xsepara;
var Lista_Region_12=new Array();Lista_Region_12[0]="-1*"+xsepara;
var Lista_Region_13=new Array();Lista_Region_13[0]="-1*"+xsepara;
var bro="";

if (navigator.appName=="Netscape")
	bro="_netscape";

function borra(opt)
{
	var temp = opt.options.length;
	for (var x=0;x < temp ;x++){
			opt.options[temp-x]=null;
	}
}

function addNew(opt,text, value,i)
{
	var el = new Option(text,value);
   	opt.options[i] = el;
}

function cambiaciudad(i,opt)
{
	var arreglo=new Array();
	var codigos=new Array();
	var str="Lista_Region_"+i;
	borra(opt);
	arreglo=eval(str);
	for (var x=0 ; x< arreglo.length ; x++){
		codigos=arreglo[x].split("*")
		addNew(opt,codigos[1],codigos[0],x);
		
	}
	opt[0].selected=true;
	document.principal.otra.value="";
	R=0;
}
var msg="";

function charTest(nStr){
	nStr=blancos(nStr);
	nStr=Rtrim(" ",nStr);
	var i=0;
	var charnoValidos = new Array();
	charnoValidos=["¤","á","é","í","ó","ú","ä","ë","ï","ö","ü","à","è","ì","ò","ù","(",")","<",">","/","|","?","¿","¢" ,"'" ,"¡" ,"!" ,"ñ" ,"," ,";" ,":",'"'," "];
	for(i=0;i<=33;i++){
		if (nStr.indexOf(charnoValidos[i])!=-1)
		{
			return false;
		}
	}
	var len = nStr.length;
	var  i,j;       
	if (nStr.indexOf("@")==-1)
                {
                        return (false);
                }
	j = nStr.indexOf("@");
	nStr=nStr.substring(j+1,len);
	if (nStr.indexOf(".")==-1 )
                {
                        return (false);
                }
	/*Tiene 2 @*/
	if (nStr.indexOf("@")!=-1 )
                {
                        return (false);
                }
      
	if (nStr.lastIndexOf(".")==nStr.length-1)
                {
                        return (false);
                }
        return (true);
}

function ValidaCorrectos(){
	
document.principal.email.value=stripInitialWhitespace(document.principal.email.value);
s=document.principal.email.value;
if(isEmpty(s)){
  /* nada */
}else{
	if(!charTest(document.principal.email.value)){
		alert("El formato del e-mail ingresado no es válido.");
		document.principal.email.focus();
	    return false;
	}
}
	
	if(document.principal.clave.value!=document.principal.clave2.value){
		alert("La contraseña ingresada no corresponde.");
		document.principal.clave.focus();
		return false;
	}
	if(document.principal.fono1.value>0 && document.principal.fono1.value<100000){
		alert("El teléfono ingresado no corresponde.");
		document.principal.telefono.focus();
		return false;
	}
	if(document.principal.celular.value>0 && document.principal.celular.value<1000000){
		alert("El teléfono móvil ingresado no corresponde.");
		document.principal.celular.focus();
		return false;
	}
	return true;
}

function valida(){
var paso;
var salida=false;

	paso=ValidaBlancos();
	if(paso==0){
		salida=ValidaCorrectos();
	}
	return salida;
}

function asigna(){
document.principal.CiudadNom.value=document.principal.Ciudad.options[document.principal.Ciudad.selectedIndex].text;
document.principal.CiudadCod.value=document.principal.Ciudad.value;
document.principal.RegionNom.value=document.principal.Region.options[document.principal.Region.selectedIndex].text;
document.principal.RegionCod.value=document.principal.Region.value;
}

var R=0;
function habilita_netscape(i)
{ //funcion para nestcape
if (i==9999){
	R=1;
	document.forms[0].otra.focus();
	}
else {
	R=0;
	document.forms[0].otra.value="";
	}
}

function noKeyValid(fld,e)
{
	var i = j = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode); 
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	len = fld.value.length;
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);

}

function soloNumeros(fld,e)
{	var i = j = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode); 
	if (strCheck.indexOf(key) == -1) return false;
	len = fld.value.length;
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
}

function soloDV(fld,e)
{	var i = j = 0;
	var strCheck = '0123456789Kk';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode); 
	if (strCheck.indexOf(key) == -1) return false;
	len = fld.value.length;
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
}

function soloNombres(fld,e)
{	var i = j = 0;
var strCheck = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&ÀÁ";
strCheck = strCheck +"ÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèé";
strCheck = strCheck +"ÂÃÄÅÆÇÈÉÊËÌÍÎêëìíîïðñòóôõöøùúûüýþ' ";
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode); 
	if (strCheck.indexOf(key) == -1) return false;
	len = fld.value.length;
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
}

function solovalidos(fld,e)
{	var i = j = 0;
var strCheck = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&ÀÁ";
strCheck = strCheck +"ÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèé";
strCheck = strCheck +"ÂÃÄÅÆÇÈÉÊËÌÍÎêëìíîïðñòóôõöøùúûüýþ1234567890.;-' ";
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode); 
	if (strCheck.indexOf(key) == -1) return false;
	len = fld.value.length;
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
}


function noSelected(fld,e)
{
	var i = j = 0;
	var strCheck;
	var aux = aux2 = '';
	if (R==1)
		strCheck = 'ABCDEFGHIJKLMNÑOPQRSTUVWXYZabcdefghijklmnñopqrstuw xyz0123456789';
	else
		strCheck = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode); 
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	len = fld.value.length;
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);

}

function isEmpty(s){
   return ((s == null) || (s.length == 0))
}

function valTelefono(pre,phone){
phone=blancos(phone)
if (pre==2)
	if (phone.length!=7)
		return false
	else
		return true

else
	if (phone.length!=6)	
		return false
	else
		return true
}

function stripInitialWhitespace(s){
   var i = 0;
   var xx = 0;
    while ((i < s.length) && (s.charAt(i) == " "))
       i++;
    return s.substring (i, s.length);
}

function enfoques1(){
var s,err=0,msg, pos=0;
alert("ASDASD");
	s=document.form1.N_Rut.value;
	if (isEmpty(s)){
		err++;
		msg="Debe ingresar su R.U.T completo."; 
		if (pos == 0)
			pos = 1;
	}
	
	s=document.form1.V_Rut.value;
	if (isEmpty(s)){
		err++;
		msg="Debe ingresar su R.U.T completo."; 
		if (pos == 0)
			pos = 2;
	}
document.form1.nombres.value=stripInitialWhitespace(document.form1.nombres.value);
	s=document.form1.nombres.value;
	if (isEmpty(s)){
		err++;
		msg="Debe ingresar su nombre.";
		pos = 3;
	}
	document.form1.apellidopat.value=stripInitialWhitespace(document.form1.apellidopat.value);
	s=document.form1.apellidopat.value;
	if (isEmpty(s)){
		err++;
		msg="Debe ingresar su apellido paterno.";
		if (pos == 0)
			pos = 5;
	}
	
	document.form1.apellidomat.value=stripInitialWhitespace(document.form1.apellidomat.value);
	s=document.form1.apellidomat.value;
	if (isEmpty(s)){
		err++;
		msg="Debe ingresar su apellido.";
		if (pos == 0)
			pos = 5;
	}
	
	document.form1.value=stripInitialWhitespace(document.form1.pass.value);
	s=document.form1.pass.value;
	if (isEmpty(s)){
		err++;
		msg="Debe ingresar su contraseña."; 
		if (pos == 0)
			pos = 6;
	}
	else {
		var LEN=s.length
		if (LEN<5){
			err++;
			msg="Su contraseña debe tener mínimo 5 caracteres.";
			if (pos == 0)
			pos = 6;
		
		}
	
	}

document.form1.pass2.value=stripInitialWhitespace(document.form1.pass2.value);
	s=document.form1.clave2.value;
	if (isEmpty(s)){
		err++;
		msg="Debe ingresar nuevamente su contraseña."; 
		if (pos == 0)
			pos = 7;
	}
	
if (document.form1.pass2.value!=document.form1.pass.value)
{		err++;
		msg="La verificación de contraseña no coincide."; 
		if (pos == 0)
			pos = 7;
	}
	
s=document.form1.fechanacimientomes.value;
	if (s==0)
	{
		err++;
		msg="Debe seleccionar un mes en su fecha de nacimiento.";
		if (pos == 0)
			pos = 8;
	}

document.form1.fechanacimientoano.value=stripInitialWhitespace(document.form1.fechanacimientoano.value);
	s=document.form1.fechanacimientoano.value;
	if (isEmpty(s)){
		err++;
		msg="Debe el año de su fecha de nacimiento.";
		if (pos == 0)
			pos = 9;
	}
	
s=document.form1.idgenero.value;
	if (s==0)
	{
		err++;
		msg="Debe seleccionar sexo.";
		if (pos == 0)
			pos = 10;
	}
	


s=document.form1.idestado.value;
	if (s==0)
	{
		err++;
		msg="Debe seleccionar Estado Civil.";
		if (pos == 0)
			pos = 11;
	}
	document.form1.direccion.value=stripInitialWhitespace(document.form1.direccion.value);
	s=document.form1.direccion.value;
	if (isEmpty(s)){
		err++;
		msg="Debe ingresar su dirección.";
		pos = 12;
	}

	s=document.principal.cod_region.value;
	if (s==0)
	{
		err++;
		msg="Debe seleccionar una región.";
		if (pos == 0)
			pos = 13;
	}
	
		s=document.principal.cod_ciudad.value;
	if (s==0)
	{
		err++;
		msg="Debe seleccionar una ciudad.";
		if (pos == 0)
			pos = 14;
	}
	
	
	
	
/*	s=document.principal.prefono1.value;
	if (isEmpty(s)){
	//	err++;
		msg="Debe ingresar su número de area local."; 
		if (pos == 0)
			pos = 11;
	}
	
	
	s=document.principal.fono1.value;
	if (isEmpty(s)){
		err++;
		msg="Debe ingresar su telefono."; 
		if (pos == 0)
			pos = 12;
	}*/
	
	//if ((document.principal.fono1.value=="" && document.principal.prefono1.value=="")&&(document.principal.celular.value==""))
	//{
//	if (isEmpty(s)){
//		err++;
	//	msg="Debe ingresar al menos un teléfono."; 
	//	if (pos == 0)
		//	pos = 12;
			
			//}
	//}
	
	/*
	if (document.principal.fono1.value!="" && document.principal.prefono1.value!="")
		if (! valTelefono(document.principal.prefono1.value,document.principal.fono1.value)){
			err++;
			msg="El teléfono ingresado no corresponde.";
			if (pos == 0)
				pos = 12
			}	
		
		if (document.principal.fono1.value!="" && document.principal.prefono1.value=="")
		{
			err++;
			msg="Debe ingresar el codigo de area del telefono";
			if (pos == 0)
				pos = 12
			}	
		
	if (document.principal.fono1.value=="" && document.principal.prefono1.value!="")
		{
			err++;
			msg="Debe ingresar ademas del codigo de area, el teléfono";
			if (pos == 0)
				pos = 12
			}	
	
			
	
	
/*	
document.principal.email.value=stripInitialWhitespace(document.principal.email.value);
	s=document.principal.email.value;
	if (isEmpty(s)){
		err++;
		msg="Debe ingresar su e-mail."; 
		if (pos == 0)
			pos = 13;
	}*/
	
var nStr=document.form1.email.value;
if (!isEmpty(nStr)){
  var len = nStr.length;
      var  i,j;       
      if (nStr.indexOf("@")==-1)
                {       msg ="El formato del e-mail ingresado no es válido1.";
                        if (pos == 0)
	             		pos = 15;

                }
      j = nStr.indexOf("@");
      nStr=nStr.substring(j+1,len);
        
      if (nStr.indexOf(".")==-1 )
         {       msg ="El formato del e-mail ingresado no es válido2.";
						if (pos == 0)
	             		pos = 15;

                }
	/*Tiene 2 @*/
	if (nStr.indexOf("@")!=-1 )
                {       msg ="El formato del e-mail ingresado no es válido3.";
						if (pos == 0)
	             		pos = 15;

                }
      
      if (nStr.lastIndexOf(".")==nStr.length-1)
             {       msg ="El formato del e-mail ingresado no es válido4.";
					if (pos == 0)
	             		pos = 15;
	
                }
	 }
	
	if (document.form1.N_Rut.value=="1"){
		msg="R.U.T incorrecto.";
		err++;
		if (pos == 0)
			pos = 1;
	}
		
  
		
	if (err == 1)
		alert(msg);
	if (err > 1)
		alert("Debe ingresar todos sus datos.");
	if (pos != 0){
		if (pos == 1)
			document.form1.N_Rut.focus();
		if (pos == 2)
			document.form1.V_Rut.focus();
		if (pos == 3)
			document.form1.nombres.focus();
		if (pos == 4)
			document.form1.apellidopat.focus();
		if (pos == 5)
			document.form1.apellidomat.focus();
		if (pos == 6)
			document.form1.pass.focus();
		if (pos == 7)
			document.form1.pass2.focus();
		if (pos == 8)
			document.form1.fechanacimientomes.focus();
		if (pos == 9)
			document.form1.fechanacimientoano.focus();
		if (pos == 10)
			document.form1.idgenero.focus();
		if (pos == 11)
			document.form1.idestado.focus();
		if (pos == 12)
			document.form1.direccion.focus();
		if (pos == 13)
			document.form1.cod_region.focus();
		if (pos == 14)
			document.form1.cod_ciudad.focus();
		if (pos == 13)
			document.form1.mail.focus();

		
	}
	return err;
}
