// ---------------------------------------------------------
//	GLOBAL VARIABLES
//----------------------------------------------------------
var popWin;
var popWinType;
var ie;

ie = (document.all) ? true : false;

//Validaciones  languaje=JavaScript

//language="JavaScript"

//***********************************************************************************
//funcion que quita espacios al inicio o final de un string
//utilizada por las funciones de este mismo include

String.prototype.trim = function()
	{
		// Use a regular expression to replace leading and trailing 
		// spaces with the empty string
		return this.replace(/(^\s*)|(\s*$)/g, "");
	}
//***********************************************************************************
	
//***********************************************************************************	
//funcion para determinar si un campo es entrado vacio Campos Obligatorios
//Parametros de entrada: string a evaluar
//Parametros de Salida: La funcion retorna: -True: si es vacio
//											-False: no es vacio

function IsEmpty(strString)
{
	strString.trim()
	if (strString == "")
	{
		return true;
	}
	
	else
	{
		return false;
	}
}
//***********************************************************************************

//***********************************************************************************
//funcion que evalua si la informacion ingresada en un campo es vacia
//Parametros de entrada: string a evaluar (se convierte a numero y se 
//averigua si es numerico)
//Parametros de Salida: La funcion retorna: -True: si no es númerico
//											-False: si es númerico

function IsNotNumeric(strString)
{
	if (isNaN(parseInt(strString)))
	{
		return false;
	}
	else
	{
		return true;
	}
}

//***********************************************************************************

//***********************************************************************************
//funcion que valida el formato de una strDate ingresada
//por el momento valida formado "dd/mm/yyyy"
//Parametros de entrada: fecha a evaluar 
//Parametros de Salida: La funcion retorna: -True: si el formato "dd/mm/yyyy" es correcto
//											-False: si el formato "dd/mm/yyyy" no es  correcto

function ValidateDate(strDate)
{
var strDate;
var format=0;
var lngindex;
var strNumber;
var strmonth=0;
var strday=0;
var stryear=0;
var err;
var strCurrentDate;
var strCurrentYear;

	//toma la fecha actual
	strCurrentDate = new Date();
	//toma el año actual formato "yyyy"
	strCurrentYear = strCurrentDate.getFullYear();
	err=false;
	  
	//format dd/mm/yyyy  
	if(strDate.charAt(2) == "/" && strDate.charAt(5) == "/" && strDate.length == 10)
    {
    	format=1;
		// Verifica que al dia  sea numerico.
        for (lngindex = 0; lngindex < 2; lngindex++) 
		{
			strNumber = strDate.substring(lngindex, lngindex + 1);
			if(strNumber < "0" || "9" < strNumber) err=true; 
		}
		// Verifica que el mes sea numerico
		for (lngindex = 3; lngindex < 5; lngindex++) 
        {
			strNumber = strDate.substring(lngindex, lngindex + 1); 
			if(strNumber < "0" || "9" < strNumber) err=true; 
		}
		// Verifica que el año sea numerico.
		for (lngindex = 6; lngindex < 10; lngindex++) 
		{
			strNumber = strDate.substring(lngindex, lngindex + 1); 
			if(strNumber < "0" || "9" < strNumber) err=true;
		}
        
		// Obtiene el año,mes y dia
		if(err==false)
		{
			strday=eval(strDate.substring(0,2)); 
			strmonth=eval(strDate.substring(3,5)); 
			stryear=eval(strDate.substring(6,strDate.length)); 
		}
		//Formato incorrecto
		if(format !=1)
		var err=true;
	}

	// Verifica que el mes este entre 1 y 12.
	if(strmonth<=0 || strmonth>=13)
	err=true;
	      
	// Verifica el dia dependiendo del mes.
	if( strmonth==2 && ((stryear/4)==parseInt(stryear/4)) )
	{
		if(strday<=0 || strday>29) err=true;
	}
	//alert(err)
	if( strmonth==2 && ((stryear/4)!=parseInt(stryear/4)) )
	{
		if(strday<=0 || strday>28) err=true; 
	}
	//alert(err)
	if( strmonth==4 || strmonth==6 || strmonth==9 || strmonth==11 )
	{
		if(strday<=0 || strday>30) err=true;
	}
	//alert(err)
	if( strmonth==1 || strmonth==3 || strmonth==5 || strmonth==7 || strmonth==8 || strmonth==10 || strmonth==12 )
	{
		//alert (strday)
		if(strday<=0 || strday>31) err=true; 
		
	}
	
	// Verifica que el año este OK
	//el año debe ser mayor de cero y mayor o igual al año actual
	if(stryear<=0 || stryear<strCurrentYear) err=true;

	// Error strDate invalida.
	if(err==true)
	{
		return false; //fecha no valida
	}
	
	else
	{
		return true; //fecha valida
	}
	
}
//***********************************************************************************

//***********************************************************************************
//funcion que evalua si el e-mail es valido
//Parametros de entrada: string a evaluar
//Parametros de Salida: La funcion retorna: -True: si es valido
//											-False: si es valido
function CheckEmail(Campo)
{
	var ok = true;

	with (Campo)
	{
		// Validar que los caracteres que contiene la cuenta de correo
		// esten dentro de los caracteres de la siguiente lista
		var car_validos = "0123456789abcdefghijlkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@.-_";
		var car_otros = "@.-_";

		for (var i=0; i < value.length; i++) {
			var ch = value.substring(i, i+1);
			if (car_validos.indexOf(ch) == -1) ok = false;
		};		
		apos = value.indexOf("@");
		lastpos = value.length-1;

		// Validar primer y ultimo caracter
		var car1 = value.substring(0, 1);
		var car2 = value.substring(lastpos, lastpos+1);
		if ((car_otros.indexOf(car1) != -1) || (car_otros.indexOf(car2) != -1)) ok = false;

		// Validar anterior y siguiente caracter despues de "@"
		car1 = value.substring(apos-1, apos);
		car2= value.substring(apos+1, apos+2);
		if ((car_otros.indexOf(car1) != -1) || (car_otros.indexOf(car2) != -1)) ok = false;

		// Buscar si existe otro simbolo "@" en el campo
		var subcadena = value.substring(apos + 1, 100);
		a2pos = subcadena.indexOf("@");
		spacepos = value.indexOf(" ");
		dotpos = value.lastIndexOf(".");

		//if (apos < 1 || a2pos != -1 || dotpos - apos < 2 || lastpos - dotpos > 3 || lastpos - dotpos < 2 || spacepos != -1) {
		if (apos < 1 || a2pos != -1 || lastpos - dotpos < 2 || spacepos != -1) ok = false;
	};
	if (!ok ) {
		Campo.focus();
		return false;
	};

	return true;

}
//***********************************************************************************

//***********************************************************************************
//funcion que evalua si la informacion ingresada en un campo es numerico
//Parametros de entrada: valor a evaluar
//Parametros de Salida: La funcion retorna: -True: si es númerico
//											-False: si no es númerico
function IsNumeric(Valor){ 
	
   var val = Valor;
   var error = false;
   for (var i = 0; i < val.length; i++) 
     { var ch = val.substring(i, i + 1); if(ch < "0" || "9" < ch) error=true; }
    if(error==true) 
    {
     return false;
    }
    else
    {
		return true;
    }
}
//***********************************************************************************

//***********************************************************************************
//funcion que evalua si el campo esta lleno
//Parametros de entrada: string a evaluar
//Parametros de Salida: La funcion retorna: -True: si esta lleno
//											-False: si no esta lleno

function CampoLleno(strString)
 {	
 var strStringOrig;
 	
	strStringOrig = strString.value;
	//strStringOrig = strStringOrig.trim;
		  
	if (strStringOrig=="")
	{	
		strString.focus();
		return false;
	}
	
	else
	{
		return true;
	}
}
//***********************************************************************************

//***********************************************************************************
//valida si la ingresada como primer parametro es mayor a la ingresada
//como segundo parametro.
//Parametros:	-strDate1 : Fecha Mayor
//				-strDate2 : Fecha Menor				
function ComparationDate(strDate1,strDate2) 
{
	var strCurrentDay;
	var strCurrentMonth;
	var strCurrentYear;
	var strday;
	var strmonth; 
	var stryear;
	var blnValidate;
	
	strMayorDate = strDate1;
	strMinorDate = strDate2;
			
	//dia, mes y año Fecha 1
	strMinorDay=eval(strMinorDate.substring(0,2)); 
	strMinorMonth=eval(strMinorDate.substring(3,5)); 
	strMinorYear=eval(strMinorDate.substring(6,strMinorDate.length)); 
				
	//dia, mes y año Fecha 2
	strMayorDay=eval(strMayorDate.substring(0,2)); 
	strMayorMonth=eval(strMayorDate.substring(3,5)); 
	strMayorYear=eval(strMayorDate.substring(6,strMayorDate.length)); 
					
	//Compara Años
	//Si el año de la fecha mayor es menor que el de la fecha menor retorna false
	if ((parseInt(strMayorYear))<(parseInt(strMinorYear)))
	{
		blnValidate = false;
	}
	
	else
	{
		blnValidate = true;
	}
	
	//Si los años son iguales se deben comparar los meses	
	if ((parseInt(strMayorYear))==(parseInt(strMinorYear)))
	{
		//Si el mes de la fecha mayor es menor que el de la fecha menor retorna false
		if ((parseInt(strMayorMonth))<(parseInt(strMinorMonth)))
		{
			blnValidate = false;
		}
			
		else
		{
			blnValidate = true;
		}	
	}
	
	//Si los meses son iguales se deben comprar los dias
	if ((parseInt(strMayorMonth))==(parseInt(strMinorMonth)))
	{
		//Si el dia de la fecha mayor es menor que el de la fecha menor retorna false
		if ((parseInt(strMayorDay))<=(parseInt(strMinorDay)))
		{
			blnValidate = false;
		}
			
		else
		{
			blnValidate = true;
		}		
	}
	//retorna false si no paso la validacion y true si la paso
	if (blnValidate == false)
	{
		return false;
	}
	
	else
	{
		return true;
	}
}

function validarforma(frmForm) {
   var strError = "";
	   var lngDias;
   for (var intLoop = 0; intLoop<frmForm.elements.length; intLoop++){
      if (null!=frmForm.elements[intLoop].getAttribute("Necesario")){
         if (frmForm.elements[intLoop].value == "" && frmForm.elements[intLoop].disabled == false) {
            strError += "  " + frmForm.elements[intLoop].name + "\n";
            frmForm.elements[intLoop].style.background = "yellow";
           }
       }
    }
	  if ("" != strError) {
	     alert("Esta dejando campos vacios necesarios para ingresar el formulario (Campos en amarillo)");
	     return false;
	  }
    return true;
}

/* -----------------------------------------------
FUNCTION: popLanguage
DESC: Create a module level pop up window
ARGS:
	formName - url to be opened
	sel - name of the select element from which to
		  get the value.
-------------------------------------------------*/
function popLanguage(formName,sel) {
	//Set Variables
	var name, width, height, fieldValue, localeValue, hrefTarget,objTest,bolTestResult;
	name = "LanguageSelection";
	width ="400";
	height ="470";
	objTest = /_none/;
	fieldValue = sel.options[sel.selectedIndex].value;
	//localeValue = fieldValue.substring(3,5) + "_" + fieldValue.substring(0,2);
	localeValue = fieldValue;
	bolTestResult = objTest.test(fieldValue);
	if (localeValue == "90") {
		//location.href = "/content/us/en/index.jsx";
		location.href = "/default44.asp";
		return false;
		}
	if (bolTestResult) {
		formName.submit();
	} else if(fieldValue == ""){
		alert('Por favor Seleccione un País');
	}else {
		hrefTarget = "/popuppais.asp?country=" + fieldValue;
		// Pop up the window
		popWindow(hrefTarget,name,width,height, "yes");
	}
	return false;
}

/* -----------------------------------------------
FUNCTION: popWindow 
DESC: Opens a window and positions it on the screen

ARGS:
	hrefTarget - url to be opened
	name - name of popup window (becomes popupType)
	width - width of the pop up window
	height - height of the pop up window
-------------------------------------------------*/
function popWindow(hrefTarget,name,width,height,simple) {
// Create offset
	if (document.all) {
		xMax = screen.width, yMax = screen.height;
	} else {
		if (document.layers) {
			xMax = window.outerWidth, yMax = window.outerHeight;
		} else {
			xMax = 640, yMax=480;
		}
	}
	var xOffset = (xMax - 586)/2, yOffset = (yMax - 700)/2;
//Check if pop up exists	
	if (!popWin||popWin.closed) {
		// no pop up exists set the popWinType to the current type
		popWinType = name;
		// open pop up window		if(simple=="yes")
			popWin = window.open(hrefTarget,name,'width='+width+',height='+height+',screenX='+xOffset+',screenY='+yOffset+', top='+yOffset+',left='+xOffset+',scrollbars=no,menubar=no,resizable=no');		else			popWin = window.open(hrefTarget,name,'width='+width+',height='+height+',screenX='+xOffset+',screenY='+yOffset+', top='+yOffset+',left='+xOffset+',scrollbars=yes,menubar=yes,resizable=yes');
	} else {
		// Check if the pop up is the same type
		if (popWinType != name) {
		// it is not the same type so close the current pop up
		popWin.close();
		// set the popWinType to the current type
		popWinType = name;
		// open pop up window				if(simple=="yes")			popWin = window.open(hrefTarget,name,'width='+width+',height='+height+',screenX='+xOffset+',screenY='+yOffset+', top='+yOffset+',left='+xOffset+',scrollbars=no,menubar=no,resizable=no');		else			popWin = window.open(hrefTarget,name,'width='+width+',height='+height+',screenX='+xOffset+',screenY='+yOffset+', top='+yOffset+',left='+xOffset+',scrollbars=yes,menubar=yes,resizable=yes');				
		return;
		}
		// Bring pop up to the foreground
		popWin.focus();
		// Change the location of the pop up to the location being requested
		popWin.location = hrefTarget;
	}		
}/* -----------------------------------------------
FUNCTION: setPreferences
DESC: calls the url to change the language / homepage
		preferences...then closes the window.
ARGS:
	strRedirectorKey - url
	strPermanentFlag - flag that says whether or not
					   the use wants to save these settings.
					   ("yes"/"no")
-------------------------------------------------*/
function setPreferences(strRedirectorKey,strPermanentFlag) {
	if (opener)
	{		switch(strRedirectorKey){			case "44": // Colombia
				opener.location.href = "/default44.asp?country="+strRedirectorKey+"&setCookie="+strPermanentFlag;
				window.close();
				break;			/*case "56": // Ecuador				//opener.location.href = "/default56.asp?country="+strRedirectorKey+"&setCookie="+strPermanentFlag;
				opener.location.href = "/default.asp";
				window.close();
				break;
			case "65": // Estados Unidos				//opener.location.href = "/default65.asp?country="+strRedirectorKey+"&setCookie="+strPermanentFlag;
				opener.location.href = "/default.asp";
				window.close();
				break;
			case "176": // Panama				//opener.location.href = "/default176.asp?country="+strRedirectorKey+"&setCookie="+strPermanentFlag;
				opener.location.href = "/default.asp";
				window.close();
				break;
			case "179": // Peru				//opener.location.href = "/default179.asp?country="+strRedirectorKey+"&setCookie="+strPermanentFlag;
				opener.location.href = "/default.asp";
				window.close();
				break;
			case "235": // Venezuela				//opener.location.href = "/default235.asp?country="+strRedirectorKey+"&setCookie="+strPermanentFlag;
				opener.location.href = "/default.asp";
				window.close();
				break;*/
		}		
	}
}
//***********************************************************************************
