<!--
// Script Desarrollado por José Oyarzo
// joyarzo@vtr.cl

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_validateForm() { //v3.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (val!=''+num) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } // //if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function RevisaRUT(RUT) {
	var ceros = "0000000000000";
	var checkOK = "0123456789--Kk";
	var checkStr = RUT.value;
	var allValid = true;
	var txtlargo = 0;
	var txtprincip = "1234567890123";
	var txtdigitover = "x";
	var txtrut = "1234567890123-5";

	txtlargo = RUT.length;
	/******** Verifica largos límites ********/
	if (txtlargo<3) return(false);
	if (txtlargo>15) return(false);


	txtprincip = RUT.substr(0,txtlargo-2);
	txtdigitover = RUT.substr(txtlargo-1,1);
	txtdigitover.toUpperCase();

	/******** Verifica caracteres ********/
	for (i = 0;  i < RUT.length;  i++) {
		ch = RUT.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j)) break;

		if (j == checkOK.length) { allValid = false;  break;  }
	}
	if (!allValid) return (false);


	/******** Se eliminan espacios, y se rellena con ceros hasta llegar a 15 ********/

	txtrut = ceros.substr(0,txtrut.length-txtlargo) + RUT;


	/****** Se verifica el dígito ver ********/
	var  Suma = 0
	var  Aux = "8765432765432"
	var digitos = "123456789K0"
	for ( i=0 ; i<13 ; i++)	{
		Suma = Suma + Number(txtrut.substr(i,1)) * Number(Aux.substr(i,1));
	}

	Dig = digitos.substr(11 - (Suma % 11) - 1, 1)
	if (Dig != txtdigitover.toUpperCase()) return (false);

    return (true);
  }
  
// esta función revibe un objeto y valida que contenga contenido.
// o: objeto a validar
// m: mensaje a desplegar

// ejemplo de llamada:
// if (!valida_textbox(f.tx_usuario,'Ingrese Nombre de Usuario')) return;

function valida_objeto_NoVacio(o,m)
{
	if (o.value == '')
	{
		if (m == '') m='Ingrese Información Solicitada';
		alert (m);
		o.focus();
		return false;
	}
	return true;

}

function valida_objeto_hidden_NoVacio(o,m)

{

	if (o.value == '')

	{

		if (m == '') m='Ingrese Información Solicitada';

		alert (m);

		return false;

	}

	return true;



}

function valida_objeto_Numerico(o,m)
{
	if (isNaN(o.value))
	{
		if (m == '') m='Sólo se permiten números para este campo';
		alert (m);
		o.focus();
		return false;
	}
	return true;
	

}

function valida_rut(o,m)
{
	if (m == '') m='El RUT ingresado no es válido';
	
	if( !RevisaRUT(o.value) ) 
	{
		alert(m);
		o.focus();
		return false;
	}
	return true;
}

function valida_email(o,m,n)
{
	if (m == '') m='Error en Dirección de Correo Electrónico';
	
	MM_validateForm(n,'','NisEmail'); 
	
	if (!(document.MM_returnValue)) 
	{
		alert(m);
		o.focus();
		return false;
	}
	return true;
}

function valida_eq_password(p1,p2,m)
{
	if (m == '') m='La password ingresada es distinta a la password de confirmación';
	if (p1.value != p2.value) 
	{
		p1.value='';
		p2.value='';
		alert(m);
		p1.focus();
		return false;
	}
	return true;
}
//->
