
/* ===================================================================== */

// JavaScript Document

var pong;
function makeArray(n){
  this.length = n;
  for (i=1;i<=n;i++){
    this[i]=0;
  }
  return this;
}

// standard date display function with y2k compatibility
function displayDate() {
  var this_month = new makeArray(12);
  this_month[0]  = "Enero";
  this_month[1]  = "Febrero";
  this_month[2]  = "Marzo";
  this_month[3]  = "Abril";
  this_month[4]  = "Mayo";
  this_month[5]  = "Junio";
  this_month[6]  = "Julio";
  this_month[7]  = "Agosto";
  this_month[8]  = "Septiembre";
  this_month[9]  = "Octubre";
  this_month[10] = "Noviembre";
  this_month[11] = "Deciembre";

  var this_day_e = new makeArray(7);
  this_day_e[0]  = "Domingo";
  this_day_e[1]  = "Lunes";
  this_day_e[2]  = "Martes";
  this_day_e[3]  = "Miércoles";
  this_day_e[4]  = "Jueves";
  this_day_e[5]  = "Viernes";
  this_day_e[6]  = "Sábado";

  var today = new Date();
  var day   = today.getDate();
  var month = today.getMonth();
  var year  = today.getYear();
  var dia = today.getDay();
    if (year < 1000) {
       year += 1900; }
  return( " " + this_day_e[dia] + ", " + day + " de " + this_month[month] + " " + year);
}


var lowercaseLetters = "abcdefghijklmnopqrstuvwxyzáéíóúñü_-";
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZÁÉÍÓÚÑ_-";

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 isemail( v ) 
{
	var reg  = /(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;
	return reg.test( v );
}

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 isblank(val)
{
	if(val==null) return true;
	for(var i=0;i<val.length;i++)
	{
		if
		(	
				(val.charAt(i) != ' ') 
			&& 	(val.charAt(i) != "\t") 
			&& 	(val.charAt(i) != "\n") 
			&& 	(val.charAt(i) != "\r")
		) return false;
	}
	return true;
}

/* ===================================================================== */

function iswrote( field )
{
	var v = field.value;
	if( isblank(v) )
	{
		try
		{
			field.value = "";
		}catch(e){}
		field.focus();
		return false;
	}

	return true;
}

/* ===================================================================== */

function isselected( field )
{
	if( field.selectedIndex == 0 )
	{
		field.focus();
		return false;
	}

	return true;
}

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 chequeaRequeridos(frm, CamposRequeridos, Descripcion) {
	var alertMsg = "_______________________________________________________________\n\n";
 		 alertMsg += "El formulario no ha sido enviado debido a que se presentaron problemas.\n";
	 	 alertMsg += "Por favor corrija los problemas y vueva a enviar el formulario.\n";
		 alertMsg += "_______________________________________________________________\n\n";
		 alertMsg += "Los siguientes campos deben rellenarse: \n\n";

	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < CamposRequeridos.length; i++){
		var obj = frm.elements[CamposRequeridos[i]];
		if (obj) {
			switch(obj.type) {
			case "select-one":
				if (obj.selectedIndex == 0 || obj.options[obj.selectedIndex].text == "" || obj.value == ""){
					alertMsg += " - " + Descripcion[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + Descripcion[i] + "\n";
				}
				break;
						
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + Descripcion[i] + "\n";
				}
				break;
				
			case "text":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + Descripcion[i] + "\n";				
					
				}
				break;
				
			case "password":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + Descripcion[i] + "\n";				
					
				}						
				break;
				
			default:
			}
			
			if (obj.type == undefined) {
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++)
					if (obj[j].checked) blnchecked = true;
				
				if (!blnchecked)
					alertMsg += " - " + Descripcion[i] + "\n";
			}
		}
	}

	if (alertMsg.length == l_Msg) {
		return true;
	} else {
		alert(alertMsg);
		return false;
	}
}

function longitud_login_password(frm) {
	
	var errorMsg = "";
	var errorMsgLong = "";

	var pass;
	pass = frm.password.value; 
	
	var confirmacion;
	confirmacion = frm.confirmacion.value;
	
	var login;
	login = frm.login.value;

	if (login.length < 6) {
		
		errorMsg += "\n Login \t\t- El Login debe tener al menos 6 caracteres";
		frm.login.value =  "";
	
	} else {
		
		if (isAlphanumeric(login) == false){
			
			errorMsg += "\n Login \t\t- El Login solo puede tener numeros y letras";
			frm.login.value =  "";
		}
	}
	
	if (pass.length < 6 ){
			
		errorMsg += "\n Contraseña \t- La Contraseña debe tener al menos 6 caracteres";
 
 		} else {
			
			if (isAlphanumeric(pass) == false){
			
			errorMsg += "\n Contraseña \t\t- La Contraseña solo puede tener numeros y letras";
			
			} else {
			
				if (confirmacion != pass) {
	
				errorMsg += "\n Confirmación \t- No coinciden la Contraseña y la Confirmación";
				frm.password.value = "";
				frm.confirmacion.value =  "";
				
				}
			}
			
		
	 }	
		
	if ((errorMsg != "") || (errorMsgLong != "")){
		msg = "_______________________________________________________________\n\n";
		msg += "El formulario no ha sido enviado 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 longitud_password(frm) {
	
	var errorMsg = "";
	var errorMsgLong = "";

	var pass;
	pass = frm.password.value; 
	
	var confirmacion;
	confirmacion = frm.confirmacion.value;
	
	if (pass.length < 6 ){
			
		errorMsg += "\n Password \t- El Password debe tener al menos 6 caracteres";
 
 	} else {
			
			if (isAlphanumeric(pass) == false){
			
			errorMsg += "\n Contraseña \t\t- El Password solo puede tener numeros y letras";
			
			} else {
			
				if (confirmacion != pass) {
	
				errorMsg += "\n Confirmación \t- No coinciden la Contraseña y la Confirmación";
				frm.password.value = "";
				frm.confirmacion.value =  "";
				
				}
			}
			
		
	 }	
		
	if ((errorMsg != "") || (errorMsgLong != "")){
		msg = "_______________________________________________________________\n\n";
		msg += "El formulario no ha sido enviado 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 validaEmail(frm) {
	
	var errorMsg = "";
	var errorMsgLong = "";
	
	
	//Verifica el email
			
	if (frm.email.value != '') {
	var checkEmail = "@.";
	var checkStr = frm.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\t- Debe ingresar un email válido";
	}
	}
	
	if ((errorMsg != "") || (errorMsgLong != "")){
		msg = "_______________________________________________________________\n\n";
		msg += "El formulario no ha sido enviado 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 validaEmailDESTINATARIO(frm) {
	
	var errorMsg = "";
	var errorMsgLong = "";
	
	
	//Verifica el email
			
	if (frm.DESTINATARIO.value != '') {
	var checkEmail = "@.";
	var checkStr = frm.DESTINATARIO.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-mail de tu amigo \t- Debe ingresar un email válido";
	}
	}
	
	if ((errorMsg != "") || (errorMsgLong != "")){
		msg = "_______________________________________________________________\n\n";
		msg += "El formulario no ha sido enviado 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 validaEmailEMAIL_REMITENTE(frm) {
	
	var errorMsg = "";
	var errorMsgLong = "";
	
	
	//Verifica el email
			
	if (frm.EMAIL_REMITENTE.value != '') {
	var checkEmail = "@.";
	var checkStr = frm.EMAIL_REMITENTE.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 Tu E-mail \t- Debe ingresar un email válido";
	}
	}
	
	if ((errorMsg != "") || (errorMsgLong != "")){
		msg = "_______________________________________________________________\n\n";
		msg += "El formulario no ha sido enviado 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 ValidarEmailDos (frm, fecha, deshabilitar) 
{
	
  if (chequeaRequeridos(frm, cmpReq, desc) && validaEmailDESTINATARIO(frm) && validaEmailEMAIL_REMITENTE(frm))
  {
    if (deshabilitar == null) frm.Submit.disabled = true;
    return true;
  }
  else
    return false;
}

function Validar (frm, fecha, deshabilitar) 
{
 
 if (chequeaRequeridos(frm, cmpReq, desc))
  {
    if (deshabilitar == null) frm.Submit.disabled = true;
    return true;
  }
  else
    return false;
}   

function ValidarEmail (frm, fecha, deshabilitar) 
{
	
  if (chequeaRequeridos(frm, cmpReq, desc) && validaEmail(frm))
  {
    if (deshabilitar == null) frm.Submit.disabled = true;
    return true;
  }
  else
    return false;
}   

function ValidarEmail_Login_Password (frm, fecha, deshabilitar) 
{
  if (chequeaRequeridos(frm, cmpReq, desc) && validaEmail(frm) && longitud_login_password(frm))
  {
    if (deshabilitar == null) frm.Submit.disabled = true;
    return true;
  }
  else
    return false;
} 

function ValidarEmail_Password (frm, fecha, deshabilitar) 
{
  if (chequeaRequeridos(frm, cmpReq, desc) && validaEmail(frm) && longitud_password(frm))
  {
    if (deshabilitar == null) frm.Submit.disabled = true;
    return true;
  }
  else
    return false;
}

function abrir_forgot(name){
	var winleft = (screen.width - 300) / 2;
	var winUp = (screen.height - 130) / 2;
	var winProp;
	winProp = 'width=300'+',height=130'+',left='+winleft+',top='+winUp+',scrollbars=no,resizable=no'
	ventana = window.open(name, "forgot", winProp); 
	if (ventana.opener == null) ventana.opener = self;
}

function abrir(name){
	var winleft = (screen.width - 500) / 2;
	var winUp = (screen.height - 300) / 2;
	var winProp;
	winProp = 'width=500'+',height=300'+',left='+winleft+',top='+winUp+',scrollbars=no,resizable=no'
	ventana = window.open(name, "prod", winProp); 
	if (ventana.opener == null) ventana.opener = self;
}

function ExpandSection(idVariable){

	if (idVariable.style.display=="none") {

			idVariable.style.display="" ;

	} else {

		idVariable.style.display="none" ;
		
	}

}


function ContractSection(idVariable){

	if (idVariable.style.display=="") {

		idVariable.style.display="none"

	}

}

function PopupFoto(url) {
	ventana = window.open(url, "ventana", "width=5,height=5,dependent=yes,screenX=0,screenY=0,titlebar=no,directories=no,menubars=no,status=no,scrollbars=no,resizable=no"); 
	if (ventana.opener == null) ventana.opener = self;
}

function abrir_foto(name){
	var winleft = (screen.width - 590) / 2;
	var winUp = (screen.height - 480) / 2;
	var winProp;
	winProp = 'width=590'+',height=480'+',left='+winleft+',top='+winUp+',scrollbars=no,resizable=no'
	ventana = window.open(name, "foto", winProp); 
	if (ventana.opener == null) ventana.opener = self;
}