<!--
function borrapc(id)
{
	if (confirm("Confirma que desea elmiminar este producto del Carro?"))
	{
		eval(parent.location='carrocompras.php?id='+id+'&borracc=1');
	}
}

function revregc()
{
	if (
	valida_rut(document.frc.rut) && 
	checkField(document.frc.nombre,isNotWhitespace,false,"Debe Ingresar su Nombre.") &&
	checkField(document.frc.clave,isNotWhitespace,false,"Debe Ingresar una Contraseña.") &&
	checkField(document.frc.clave2,isNotWhitespace,false,"Debe Confirmar su Contraseña.") &&
	checkField(document.frc.direccion,isNotWhitespace,false,"Debe ingresar su Dirección.") &&
	checkField(document.frc.email,isEmail,false,"Debe ingresar una Dirección de E-Mail válida.") &&
	checkField(document.frc.fono,isNotWhitespace,false,"Debe ingresar un Teléfono de Contacto.") &&
	checkField(document.frc.especialidad,isNotWhitespace,false,"Debe ingresar una Descripción o Especialidad.")
	)
	{
		if (document.frc.clave.value.length<6 || document.frc.clave.value.length>12)
		{
			alert("El Largo de la Contraseña debe estar entre 6 y 12 caracteres.");
			document.frc.clave.focus();
		}
		else
		{
			if (document.frc.clave.value==document.frc.clave2.value)
			{
				if (document.frc.tipo.value=="farmacia")
				{
					if (document.frc.nombrecontacto.value=="")
					{
						alert("Debe ingresar el Nombre del Contacto.");
						document.frc.nombrecontacto.focus();
					}
					else
					{
						document.frc.regis.value=1;	
						document.frc.submit();
					}
				}
				else
				{
					document.frc.regis.value=1;	
					document.frc.submit();
				}
			}
			else
			{	
				alert("Las Contraseñas ingresadas no Coinciden. Vuelva a escribirlas.");
				document.frc.clave2.value="";
				document.frc.clave.focus();
			}
		}
	}
}

function revlog()
{
	if (
	valida_rut(document.flog.rut) &&
	checkField(document.flog.clave,isNotWhitespace,false,"Debe ingresar su Clave")
	)
	{
		document.flog.loguea.value=1;
		document.flog.submit();
	}
}

function revlog2()
{
	if (
	valida_rut(document.flog.rut) &&
	checkField(document.flog.clave,isNotWhitespace,false,"Debe ingresar su Clave")
	)
	{
		var x=0;
		for (var i=0;i<eval(document.flog.tipo.length);i++)
		{
			if (eval('document.flog.tipo['+i+'].checked'))
			{
				x=1;
			}
		}
		if (x==0)
		{
			alert("Debe seleccionar un Tipo de Cliente!");
			document.flog.tipo[0].focus();
		}
		else
		{
			document.flog.loguea.value=1;
			document.flog.submit();
		}
	}
}

function ingrecli()
{
	var x=0;
	for (var i=0;i<eval(document.fclien.tipo.length);i++)
	{
		if (eval('document.fclien.tipo['+i+'].checked'))
		{
			x=1;
		}
	}
	if (x==0)
	{
		alert("Debe seleccionar un Tipo de Cliente!");
		document.fclien.tipo[0].focus();
	}
	else
	{
		document.fclien.submit();
	}
}

function buscador()
{
	if (document.fbusca.criterio.value=="")
	{
		alert("Debe ingresar un Criterio de Búsqueda!");
		document.fbusca.criterio.focus();
	}
	else
	{
		document.fbusca.buscar.value=1;
		document.fbusca.submit();
	}
}

function revcon()
{
	if (
	checkField(document.fcon.nombre,isNotWhitespace,false,"Debe ingresar su Nombre") &&
	checkField(document.fcon.email,isEmail,false,"Debe ingresar un E-Mail válido") &&
	checkField(document.fcon.telefono,isNotWhitespace,false,"Debe ingresar un Teléfono de Contacto") &&
	checkField(document.fcon.mensaje,isNotWhitespace,false,"Debe ingresar un Mensaje")
	)
	{
		document.fcon.guardacon.value=1;
		document.fcon.submit();
	}
}

function revpreg()
{
	if (
	checkField(document.fpre.nombre,isNotWhitespace,false,"Debe ingresar su Nombre") &&
	checkField(document.fpre.email,isEmail,false,"Debe ingresar un E-Mail válido") &&
	checkField(document.fpre.telefono,isNotWhitespace,false,"Debe ingresar un Teléfono de Contacto") &&
	checkField(document.fpre.pregunta,isNotWhitespace,false,"Debe ingresar una Consulta")
	)
	{
		document.fpre.guardapre.value=1;
		document.fpre.submit();
	}
}

function esDigito (c)
{   return ((c >= "0") && (c <= "9")) }

function esDigitoVerificadorValido(c)
{
        var test= "" + c;
        if (test == "0" || test == "1" || test == "2" || test == "3" || test == "4" || test == "5" || test == "6" || test == "7" || test == "8" || test == "9" || test == "k" || test == "K")
        {
                return true;
        }
        alert ("RUT invalido");
        return false;
}

function esRutValido(s)
{
        var test = "" + s;
        for (var k=0;k < test.length; k++)
        {
                var c=test.substring(k,k+1);
                if (esDigito(c)==false)
                {
                        alert ("RUT invalido");
                        return false;
                }
        }
        return true;
}

function calculaDigitoVerificador(rut)
{
        var test = "" + rut;
        var total=0;
        var i=2;
        for (var k=test.length;k > 0; k--)
        {
                var c=test.substring(k-1,k);
                //alert (c);
                if (i==8)
                {
                        i=2;
                }
                total+=parseInt(c)*i
                i++;
        }
        if ((11-(total-(Math.floor(total/11)*11)))==11){
                return 0;
        }
        else{
                return (11-(total-(Math.floor(total/11)*11)));
        }
}

//function revisaRut(rut_org)
function revisaRut(rut_org,rut_solo,dv_solo)
{
  var dv;
  var rut ="";

  if ( rut_org.length < 8 )
  {
        alert ("RUT invalido");
 	return false;
  }
  for ( i=0; i < rut_org.length-1  && rut_org.charAt(i) != '-'; i++ )
    if ( rut_org.charAt(i) != ' ' && rut_org.charAt(i) != '.' && rut_org.charAt(i) != '-' )
      rut = rut + rut_org.charAt(i);

//  dv = rut_org.charAt(rut_org.length-1);
  for ( i=rut_org.length-1; i > 0 && rut_org.charAt(i) != '-' ; i-- )
    if ( rut_org.charAt(i) != ' ' && rut_org.charAt(i) != '.' && rut_org.charAt(i) != '-' )
      dv = rut_org.charAt(i);

 // alert("digito verificador ='"+dv+"'");


        if (esDigitoVerificadorValido(dv)==false)
        {
                return false;
        }
        if (calculaDigitoVerificador(rut)==10)
        {
                var test=""+dv;
                if ((test != "K")&&(test != "k"))
                {
                        alert ("RUT invalido");
                        return false;

                }
        }
        else if (calculaDigitoVerificador(rut)!=dv)
        {
  // alert(calculaDigitoVerificador(rut));
  // alert("rut='"+rut+"'");
  // alert("digito verificador ='"+dv+"'");
                alert ("RUT invalido");
                return false;
        }
        if (revisaRut.arguments.length==3)
        {
          rut_solo.value=rut;
          if (dv=="k")
          {
            dv_solo.value="K";
          }
          else
          {
            dv_solo.value=dv;
          }
        }
	return true;
}

function valida_rut(rut)
{
 var i=0;
 var x=0;
 var z=rut.value;
 while (i<z.length)
 {
	if (z.charAt(i)=='-')
	{
		x=1;
	}
	i++;
 }
 if (x==1)
 {
 var retorna=revisaRut(rut.value);
  if (!retorna)
  {
    rut.focus();
  }
  return(retorna);
 }
 else
 {
 	alert("Rut Inválido");
	rut.focus();
 }
}
//-->