var lowercaseLetters = "abcdefghijklmnopqrstuvwxyzáéíóúñü_-";
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZÁÉÍÓÚÑ_-";

function abrir_ventana(name, ancho, alto){
	var winleft = (screen.width - ancho) / 2;
	var winUp = (screen.height - alto) / 2;
	var winProp;
	winProp = 'width='+ancho+',height='+alto+',left='+winleft+',top='+winUp+',scrollbars=no,resizable=no'
	ventana = window.open(name, "DCI", winProp); 
	if (ventana.opener == null) ventana.opener = self;
}

function MM_findObj(n, d) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function estados()  {

	if (document.forma.pais.selectedIndex > 0) {
	
	var pais;
	pais = document.forma.pais.value;
	document.forma.action = 'registro.php?idp=' + pais;
	document.forma.submit();
	}
}

function estados2(a)  {
 
	if (document.forma.pais.selectedIndex > 0) {
	var pais;
	pais =document.forma.pais.value;
	document.forma.action = 'mi_cuenta.php?idu='+a+'&paisup='+pais;
	document.forma.submit();
	}
}

function blockcampos () {
if (document.forma.suscripcion.value == 3) {
document.forma.deposito.disabled = true;
document.forma.dia.disabled = true;
document.forma.mes.disabled = true;
document.forma.ano.disabled = true;
return true; } else {
document.forma.deposito.disabled = false;
document.forma.dia.disabled = false;
document.forma.mes.disabled = false;
document.forma.ano.disabled = false;
}
}
function borrarconf() {
document.forma.confirmacion.value ='';
}

function abrirenpadre(url) {
parent.opener.document.location.href = url;
window.close();
}

function numeros ()  { //verifica que solo ingresen al campo de texto numeros en el evento onKeypress

if ((event.keyCode < 48) ||(event.keyCode > 57)) event.returnValue = false;

}

function isDigit (c) //devuelve si un caracter es numero o no
{   return ((c >= "0") && (c <= "9"))
}

function isLetter (c) //busca en un arreglo de todas las letras si es una letra o no
{
    return( ( uppercaseLetters.indexOf( c ) != -1 ) ||
            ( lowercaseLetters.indexOf( c ) != -1 ) )
}

function isEmpty(s) //verifica si un string es nulo o vacio
{   return ((s == null) || (s.length == 0) || (s == ""))
}

function isAlphanumeric (s) //verifica que un string sea alfanumerico estricto y sin espacios en blanco
{   var i;

    if (isEmpty(s)) return false;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (! (isLetter(c) || isDigit(c) ) )
        return false;
    }

    return true;
}

function CheckForm () { //valida todos los campos del formulario de registro de usuarios

	var errorMsg = "";
	var errorMsgLong = "";

	//Verifica el nombre
	if (document.forma.nombre.value == ""){
		errorMsg += "\n Nombre \t- Debe ingresar su nombre";
	}
	
	//Verifica el apellido
	if (document.forma.apellido.value == ""){
		errorMsg += "\n Apellido \t- Debe ingresar su apellido";
	}
	//Verifica el mail
	if (document.forma.email.value == ""){
		errorMsg += "\n Email \t- Debe ingresar su dirección de correo electrónico";
	} else {
	
	if (document.forma.email.value != '') {
	var checkEmail = "@.";
	var checkStr = document.forma.email.value;
	var EmailValid = false;
	var EmailAt = false;
	var EmailPeriod = false;
	for (i = 0;  i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkEmail.length;  j++)
	{
		if (ch == checkEmail.charAt(j) && ch == "@")
		EmailAt = true;
		if (ch == checkEmail.charAt(j) && ch == ".")
		EmailPeriod = true;
		if (EmailAt && EmailPeriod)
		break;
		if (j == checkEmail.length)
		break;
	}
	// if both the @ and . were in the string
		if (EmailAt && EmailPeriod)
		{
			EmailValid = true
			break;
		}
	}
	if (!EmailValid) {
	  errorMsg += "\n Email \t- Debe ingresar una dirección válida de correo electrónico";
	}
	}
	}
	//Verifica el pais
	if (document.forma.pais.selectedIndex == 0){
		errorMsg += "\n Pais \t- Debe seleccionar País/Región";
	}
	
	//Verifica el estado
	if (document.forma.auxiliar.value == 2) {
		if (document.forma.estado.selectedIndex == 0){
			errorMsg += "\n Estado \t- Debe seleccionar Estado/Provincia/Territorio";
		}
	}
		
	if (document.forma.ciudad.value == ""){
	errorMsg += "\n Ciudad \t- Debe ingresar la ciudad";
	}
	
	if (document.forma.municipio.value == ""){
	errorMsg += "\n Municipio - Debe ingresar el municipio o localidad";
	}
	
	if (document.forma.urbanizacion.value == ""){
	errorMsg += "\n Urbanización - Debe ingresar el sector o la urbanización";
	}
	
	if (document.forma.avenida.value == ""){
	errorMsg += "\n Avenida \t- Debe ingresar la avenida o la calle";
	}
	
	if (document.forma.edificio.value == ""){
	errorMsg += "\n Edificio \t- Debe ingresar el nombre del edificio, quinta o casa";
	}
	
	if (document.forma.piso.value == ""){
	errorMsg += "\n Piso \t- Debe ingresar el piso y el apartamento o número de la casa";
	}
	
	var login;
	login = document.forma.login.value;
	if (login.length < 5) { 
	errorMsg += "\n Login \t- Debe tener al menos 5 caracteres de longitud";
	} else {
	if (isAlphanumeric(login) == false) {
	errorMsg += "\n Login \t- No puede tener caracteres especiales o espacios en blanco";
	}
	}
	
	var pass;
	pass = document.forma.password.value; 
	if (pass.length < 8) {
	errorMsg += "\n Clave \t- Debe tener al menos 8 caracteres de longitud";
	} else { 
	if (isAlphanumeric(pass) == false) {
	errorMsg += "\n Clave \t- No puede tener caracteres especiales o espacios en blanco";
	}
	}
	
	var confirmacion;
	confirmacion = document.forma.confirmacion.value
	if (confirmacion != pass) {
	errorMsg += "\n Confirmación \t- No coinciden la clave y la confirmación";
	}
	
	var dia;
	var mes;
	var ano;
	dia = document.forma.dia.selectedIndex;
	mes = document.forma.mes.selectedIndex;
	ano = document.forma.ano.value;
	if (document.forma.suscripcion.value != 3){
	  if (document.forma.deposito.value == ''){
	  	errorMsg += "\n Depósito - Debe ingresar el número del depósito o transferencia";
	  } else { 
	  	if ((dia==0) || (mes == 0) || (ano == '')){
	  		errorMsg += "\n Fecha \t- Debe ingresar la fecha del depósito o transferencia";
	  	}
	  }
	}
	
	if ((dia > 0) && (mes > 0) && (ano != '')){
		
		var fechadep = new Date(ano,mes,dia);
		var today = new Date();
		var diahoy = today.getDate();
 		var meshoy = today.getMonth() + 1;
		var anohoy = today.getYear();
		var fechahoy = new Date(anohoy,meshoy,diahoy);
		if (fechadep > fechahoy) {
			errorMsg += "\n Fecha \t- La fecha del depósito no puede ser mayor a la fecha de hoy";
		}
	}	
	
	//If there is aproblem with the form then display an error
	if ((errorMsg != "") || (errorMsgLong != "")){
		msg = "_______________________________________________________________\n\n";
		msg += "El fromulario no ha sido enviada debido a que se presentaron problemas.\n";
		msg += "Por favor corrija los problemas y vueva a enviar el formulario.\n";
		msg += "_______________________________________________________________\n\n";
		msg += "Los siguientes campos necesitan ser corregidos: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
		return false;
	}
	
	return true;
}

function CheckForm2 () { //valida todos los campos del formulario de micuenta

	var errorMsg = "";
	var errorMsgLong = "";

	//Verifica el nombre
	if (document.forma.nombre.value == ""){
		errorMsg += "\n Nombre \t- Debe ingresar su nombre";
	}
	
	//Verifica el apellido
	if (document.forma.apellido.value == ""){
		errorMsg += "\n Apellido \t- Debe ingresar su apellido";
	}
	//Verifica el mail
	if (document.forma.email.value == ""){
		errorMsg += "\n Email \t- Debe ingresar su dirección de correo electrónico";
	} else {
	
	if (document.forma.email.value != '') {
	var checkEmail = "@.";
	var checkStr = document.forma.email.value;
	var EmailValid = false;
	var EmailAt = false;
	var EmailPeriod = false;
	for (i = 0;  i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkEmail.length;  j++)
	{
		if (ch == checkEmail.charAt(j) && ch == "@")
		EmailAt = true;
		if (ch == checkEmail.charAt(j) && ch == ".")
		EmailPeriod = true;
		if (EmailAt && EmailPeriod)
		break;
		if (j == checkEmail.length)
		break;
	}
	// if both the @ and . were in the string
		if (EmailAt && EmailPeriod)
		{
			EmailValid = true
			break;
		}
	}
	if (!EmailValid) {
	  errorMsg += "\n Email \t- Debe ingresar una dirección válida de correo electrónico";
	}
	}
	}
	//Verifica el pais
	if (document.forma.pais.selectedIndex == 0){
		errorMsg += "\n Pais \t- Debe seleccionar País/Región";
	}
	
	//Verifica el estado
	if (document.forma.auxiliar.value == 2) {
		if (document.forma.estado.selectedIndex == 0){
			errorMsg += "\n Estado \t- Debe seleccionar Estado/Provincia/Territorio";
		}
	}
	
	if (document.forma.ciudad.value == ""){
	errorMsg += "\n Ciudad \t- Debe ingresar la ciudad";
	}
	
	if (document.forma.municipio.value == ""){
	errorMsg += "\n Municipio - Debe ingresar el municipio o la localidad";
	}
	
	if (document.forma.urbanizacion.value == ""){
	errorMsg += "\n Urbanización - Debe ingresar el sector o la urbanización";
	}
	
	if (document.forma.avenida.value == ""){
	errorMsg += "\n Avenida \t- Debe ingresar la avenida o la calle";
	}
	
	if (document.forma.edificio.value == ""){
	errorMsg += "\n Edificio \t- Debe ingresar el nombre del edificio, quinta o casa";
	}
	
	if (document.forma.piso.value == ""){
	errorMsg += "\n Piso \t- Debe ingresar el piso y el apartamento o número de la casa";
	}
	
	var pass;
	pass = document.forma.clave.value; 
	if (pass.length < 8) {
	errorMsg += "\n Clave \t- Debe tener al menos 8 caracteres de longitud";
	} else { 
	if (isAlphanumeric(pass) == false) {
	errorMsg += "\n Clave \t- No puede tener caracteres especiales o espacios en blanco";
	}
	}
	
	var confirmacion;
	confirmacion = document.forma.confirmacion.value
	if (confirmacion != pass) {
	errorMsg += "\n Confirmación \t- No coinciden la clave y la confirmación";
	}
	
	//If there is aproblem with the form then display an error
	if ((errorMsg != "") || (errorMsgLong != "")){
		msg = "_______________________________________________________________\n\n";
		msg += "El fromulario no ha sido enviada debido a que se presentaron problemas.\n";
		msg += "Por favor corrija los problemas y vueva a enviar el formulario.\n";
		msg += "_______________________________________________________________\n\n";
		msg += "Los siguientes campos necesitan ser corregidos: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
		return false;
	}
	
	return true;
}

function ChkPlan () {

	var errorMsg = "";
	var errorMsgLong = "";

	var dia;
	var mes;
	var ano;
	dia = document.forma.dia.selectedIndex;
	mes = document.forma.mes.selectedIndex;
	ano = document.forma.ano.value;
	if (document.forma.suscripcion.value != 3){
	  if (document.forma.deposito.value == ''){
	  	errorMsg += "\n Depósito - Debe ingresar el número del depósito o transferencia";
	  } else { 
	  	if ((dia==0) || (mes == 0) || (ano == '')){
	  		errorMsg += "\n Fecha \t- Debe ingresar la fecha del depósito o transferencia";
	  	}
	  }
	}
	
	if ((dia > 0) && (mes > 0) && (ano != '')){
		
		var fechadep = new Date(ano,mes,dia);
		var today = new Date();
		var diahoy = today.getDate();
 		var meshoy = today.getMonth() + 1;
		var anohoy = today.getYear();
		var fechahoy = new Date(anohoy,meshoy,diahoy);
		if (fechadep > fechahoy) {
			errorMsg += "\n Fecha \t- La fecha del depósito no puede ser mayor a la fecha de hoy";
		}
	}	
	
	//If there is aproblem with the form then display an error
	if ((errorMsg != "") || (errorMsgLong != "")){
		msg = "_______________________________________________________________\n\n";
		msg += "El fromulario no ha sido enviada debido a que se presentaron problemas.\n";
		msg += "Por favor corrija los problemas y vueva a enviar el formulario.\n";
		msg += "_______________________________________________________________\n\n";
		msg += "Los siguientes campos necesitan ser corregidos: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
		return false;
	}
	
	return true;
}

function CheckFormCliente () { //valida todos los campos del formulario de nuevo_cliente

	var errorMsg = "";
	var errorMsgLong = "";

	//Verifica el nombre
	if (document.forma.nombre.value == ""){
		errorMsg += "\n Nombre \t- Debe ingresar el nombre del cliente";
	}
	
	//Verifica el tipo
	if (document.forma.tipo.selectedIndex == 0) {
		errorMsg += "\n Tipo \t- Debe seleccionar el tipo de cliente";
	}
	
	//Verifica datos
	if (document.forma.datos.value == "") {
		errorMsg += "\n Datos \t- Debe los datos del cliente";
	}
	
	//Verifica el mail
			
	if (document.forma.email.value != '') {
	var checkEmail = "@.";
	var checkStr = document.forma.email.value;
	var EmailValid = false;
	var EmailAt = false;
	var EmailPeriod = false;
	for (i = 0;  i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkEmail.length;  j++)
	{
		if (ch == checkEmail.charAt(j) && ch == "@")
		EmailAt = true;
		if (ch == checkEmail.charAt(j) && ch == ".")
		EmailPeriod = true;
		if (EmailAt && EmailPeriod)
		break;
		if (j == checkEmail.length)
		break;
	}
	// if both the @ and . were in the string
		if (EmailAt && EmailPeriod)
		{
			EmailValid = true
			break;
		}
	}
	if (!EmailValid) {
	  errorMsg += "\n Email \t- Debe ingresar una dirección válida de correo electrónico";
	}
	}
	
	//Verifica el mail2
			
	if (document.forma.email2.value != '') {
	var checkEmail = "@.";
	var checkStr = document.forma.email2.value;
	var EmailValid = false;
	var EmailAt = false;
	var EmailPeriod = false;
	for (i = 0;  i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkEmail.length;  j++)
	{
		if (ch == checkEmail.charAt(j) && ch == "@")
		EmailAt = true;
		if (ch == checkEmail.charAt(j) && ch == ".")
		EmailPeriod = true;
		if (EmailAt && EmailPeriod)
		break;
		if (j == checkEmail.length)
		break;
	}
	// if both the @ and . were in the string
		if (EmailAt && EmailPeriod)
		{
			EmailValid = true
			break;
		}
	}
	if (!EmailValid) {
	  errorMsg += "\n E. adic. \t- Debe ingresar una dirección válida de correo electrónico";
	}
	}
	
	//Verifica el pais
	if (document.forma.pais.selectedIndex == 0){
		errorMsg += "\n Pais \t- Debe seleccionar País/Región";
	}
	
	
	//If there is aproblem with the form then display an error
	if ((errorMsg != "") || (errorMsgLong != "")){
		msg = "_______________________________________________________________\n\n";
		msg += "El fromulario no ha sido enviada debido a que se presentaron problemas.\n";
		msg += "Por favor corrija los problemas y vueva a enviar el formulario.\n";
		msg += "_______________________________________________________________\n\n";
		msg += "Los siguientes campos necesitan ser corregidos: \n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
		return false;
	}
	
	return true;

}	

function CheckFormCliente2 () { //valida todos los campos del formulario de modificacion_cliente

	var errorMsg = "";
	var errorMsgLong = "";

	//Verifica el nombre
	if (document.forma.nombre.value == ""){
		errorMsg += "\n Nombre \t- Debe ingresar el nombre del cliente";
	}
	
	//Verifica el tipo
	//if (document.forma.tipo.selectedIndex == 0) {
	//	errorMsg += "\n Tipo \t- Debe seleccionar el tipo de cliente";
	//}
	
	//Verifica datos
	if (document.forma.datos.value == "") {
		errorMsg += "\n Datos \t- Debe los datos del cliente";
	}
	
	//Verifica el mail
			
	if (document.forma.email.value != '') {
	var checkEmail = "@.";
	var checkStr = document.forma.email.value;
	var EmailValid = false;
	var EmailAt = false;
	var EmailPeriod = false;
	for (i = 0;  i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkEmail.length;  j++)
	{
		if (ch == checkEmail.charAt(j) && ch == "@")
		EmailAt = true;
		if (ch == checkEmail.charAt(j) && ch == ".")
		EmailPeriod = true;
		if (EmailAt && EmailPeriod)
		break;
		if (j == checkEmail.length)
		break;
	}
	// if both the @ and . were in the string
		if (EmailAt && EmailPeriod)
		{
			EmailValid = true
			break;
		}
	}
	if (!EmailValid) {
	  errorMsg += "\n Email \t- Debe ingresar una dirección válida de correo electrónico";
	}
	}
	
	//Verifica el mail2
			
	if (document.forma.email2.value != '') {
	var checkEmail = "@.";
	var checkStr = document.forma.email2.value;
	var EmailValid = false;
	var EmailAt = false;
	var EmailPeriod = false;
	for (i = 0;  i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkEmail.length;  j++)
	{
		if (ch == checkEmail.charAt(j) && ch == "@")
		EmailAt = true;
		if (ch == checkEmail.charAt(j) && ch == ".")
		EmailPeriod = true;
		if (EmailAt && EmailPeriod)
		break;
		if (j == checkEmail.length)
		break;
	}
	// if both the @ and . were in the string
		if (EmailAt && EmailPeriod)
		{
			EmailValid = true
			break;
		}
	}
	if (!EmailValid) {
	  errorMsg += "\n E. adic. \t- Debe ingresar una dirección válida de correo electrónico";
	}
	}
	
	//Verifica el pais
	if (document.forma.pais.selectedIndex == 0){
		errorMsg += "\n Pais \t- Debe seleccionar País/Región";
	}
	
	
	//If there is aproblem with the form then display an error
	if ((errorMsg != "") || (errorMsgLong != "")){
		msg = "_______________________________________________________________\n\n";
		msg += "El fromulario no ha sido enviada debido a que se presentaron problemas.\n";
		msg += "Por favor corrija los problemas y vueva a enviar el formulario.\n";
		msg += "_______________________________________________________________\n\n";
		msg += "Los siguientes campos necesitan ser corregidos: \n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
		return false;
	}
	
	return true;

}	

function checklogin (){

	var errorMsg = "";

	//Verifica el login
	if (document.frm_validar.txt_login.value == ""){
		errorMsg += "\n Login \t \t- Debe ingresar su Login";
	}

	//Verifica el password
	if (document.frm_validar.txt_pass.value == "") {
		errorMsg += "\n Password \t- Debe ingresar su Password";
	}
		
	//If there is aproblem with the form then display an error
	if (errorMsg != ""){
		msg = "_______________________________________________________________\n\n";
		msg += "El fromulario no ha sido enviada debido a que se presentaron problemas.\n";
		msg += "Por favor corrija los problemas y vueva a enviar el formulario.\n";
		msg += "_______________________________________________________________\n\n";
		msg += "Los siguientes campos necesitan ser corregidos: \n";
		
		errorMsg += alert(msg + errorMsg);
		return false;
	}
	
	return true;

}

function abrircliente(theURL, Name, popW, popH, scroll) { // V 1.0
var winleft = (screen.width - popW) / 2;
var winUp = (screen.height - popH) / 2;
winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+',scrollbars='+scroll+',resizable'
Win = window.open(theURL, Name, winProp)
if (parseInt(navigator.appVersion) >= 4) { Win.window.focus(); }

}

function trcolorin(valor)
{
	valor.style.backgroundColor= "#006666";
	valor.style.cursor="hand";
}

function trcolorout(valor)
{
	valor.style.backgroundColor= "#002247";
}

function tdcolorin(valor)
{
	valor.style.backgroundColor= "#006666";
	valor.style.cursor="hand";
}

function tdcolorout(valor)
{
	valor.style.backgroundColor= "";
}


function MM_setTextOfLayer(objName,x,newText) { //v4.01
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (document.layers) {document.write(unescape(newText)); document.close();}
    else innerHTML = unescape(newText);
}

function ver(valor)
{
	MM_findObj("frame1").style.display="";
	MM_findObj("frame1").src="detalle.php?idc="+valor
}
