<!--
// All JavaScripts contained herein are
// Copyright 2001-2003 MejorAmor.com
// All rights reserved.
// Commercial distribution or modification prohibited without
// express written permission.


/*
Autor: Oscar Salazar Romero
Fecha: 08/23/2004
Nombre Funcion: CheckBox_LimitSelectedOptions
Descripcion:
Esta  función nos ayuda para limitar el número de opciones que es posible seleccionar de una lista de
elementos CheckBox, para lograr esto, esta funcion necesita saber cual es el indice del primer elemento del
CheckBox y cual el ultimo para trabajar en esa parte de la forma.

Nota importante:
	Siempre deberemos saber los indices exactos para este tipo de campos cuando deseamos limitarlos.
*/
function fnFormValid_CheckBox_LimitSelectedOptions(intMaxSelected, intIndexMin, intIndexMax, intIndexForm, objCheckBox, strMensaje)
{
	var i = 0;
	var objElemento = "";
	var intCount = 0;
	
	//Solamente cuando estamos marcando la opción, no cuando estamos desmarcando la opción.
	if (objCheckBox.checked)
	{
		for (i = intIndexMin; i <= intIndexMax; i++)
		{
			objElemento = document.forms[intIndexForm].elements[i];
			//Prevenimos que quiza haya otros campos intermedios.
			if (objElemento.type == "checkbox")	
				if (objElemento.checked)
					intCount = intCount + 1;
		}
		
		if (intCount > intMaxSelected)
		{		
			if (!(strMensaje == ""))
			{
				strMensaje = strMensaje.replace('Tag.MaxSelected', "" + intMaxSelected + "");
				alert(strMensaje);
			}
			event.returnValue = false;
		}
	}
}

function str_fnFormValid_CampoRequeridoTexto(objCampo, strNombre, strError)
{
	var strCampoRequeridoTexto_RETURN = strError;
	
	if (objCampo.value == "")
	{
		strCampoRequeridoTexto_RETURN = strCampoRequeridoTexto_RETURN  + "\n   * " + strNombre
	}

	return strCampoRequeridoTexto_RETURN;
}

function str_fnFormValid_CampoRequeridoCheckBox(objCampo, intIndexForm, intIndexMin, intIndexMax, intMinSelected, strNombre, strError)
{
	var strCampoRequeridoCheckBox_RETURN = strError;
	var intCountSelected = 0;
	var blnFlag = false;
	
	for (i = intIndexMin; i <= intIndexMax; i++)
	{
		objElemento = document.forms[intIndexForm].elements[i];
		//Prevenimos que quiza haya otros campos intermedios.
		if (objElemento.type == "checkbox")	
		{
			if (objElemento.checked)
			{
				intCountSelected = intCountSelected + 1;
				if (intCountSelected >= intMinSelected)	
				{
					blnFlag = true;
					break;
				}	
			}
		}
	}
	
	if (!(blnFlag))
	{		
		strCampoRequeridoCheckBox_RETURN = strCampoRequeridoCheckBox_RETURN  + "\n   * " + strNombre
	}
	
	return strCampoRequeridoCheckBox_RETURN;
}

function str_fnFormValid_CampoRequeridoRadioButton(objCampo, intOptionsNum, strNombre, strError)
{
	var strCampoRequeridoRadioButton_RETURN = strError;
	var blnFlag = false;
	
	for (i = 0; i < intOptionsNum; i++)
	{
		if (objCampo[i].checked)
		{
			blnFlag = true;
			break;
		}
	}
	
	if (!(blnFlag))
	{		
		strCampoRequeridoRadioButton_RETURN = strCampoRequeridoRadioButton_RETURN  + "\n   * " + strNombre
	}
	
	return strCampoRequeridoRadioButton_RETURN;
}

function str_fnFormValid_CampoRequeridoSelect(objCampo, strNombre, strError)
{
	var strCampoRequeridoSelect_RETURN = strError;
	
	//NOTA: Para saber si un select esta seleccionado basta con que el index sea mayor de 0, sin embargo si blnIndiceCero, 
	//por lo tanto si el select tiene la opcion 0 como opcion real, entonces no necesita usar esta validacion y sera incorrecta.
	if (objCampo.selectedIndex <= 0)
	{
		strCampoRequeridoSelect_RETURN = strCampoRequeridoSelect_RETURN  + "\n   * " + strNombre
	}
	
	return strCampoRequeridoSelect_RETURN;
}

function str_fnFormValid_Email(strEmail, strEmailConfirm, blnConfirmField)
{
	var strError = "";
	var strErrorLocal = "";
	var blnEmailValid = "";
	
	var intAtLoc = 0;
	var intDotLoc = 0;
	var intLenEmail = 0;
	var intAts = 0;
	
	// Revisar el e-mail
	if (strEmail != "")
	{
		intAtLoc = strEmail.indexOf('@');
		intDotLoc = strEmail.indexOf('.');
		intLenEmail = strEmail.length;
		intAts = strEmail.lastIndexOf('@');
		
		strErrorLocal = "Email '" + strEmail + "' is not a valid email";
		
		if (intAtLoc != intAts)
			intAts = 2;
		else
			intAts = 1;
		
		if ((intAtLoc <= 0) || (intAtLoc >= intLenEmail) || (intDotLoc <= 0) || (intDotLoc >= intLenEmail) || (intAtLoc == (intDotLoc+1)) || (intDotLoc == (intAtLoc+1)) || (intAts > 1))
			strError = strErrorLocal + ". An example of a valid email is: jose@hotmail.com";
		
		else if ((strEmail.toLowerCase() == "account@domain.subdomain"))
			strError = strErrorLocal + ". Please write your personal email.";
			
		else if (strEmail.indexOf(' ') >= 0)
			strError = strErrorLocal + " because it has blank spaces.";
			
		else if (strEmail.indexOf(',') >= 0)
			strError = strErrorLocal + " because it has commas.";
			
		else if (strEmail.match("www."))
			strError = strErrorLocal + " because it has the string 'www.'";
		
		else if (strEmail.match("@mejoramor.com"))
			strError = strErrorLocal + ". Please write your personal email.";
			
		else if (strEmail.match("@hotmail.com.mx"))
			strError = strErrorLocal + ". The domain hotmail.com.mx is not valid.";
			
		else if (strEmail.match("@hotmeil.com"))
			strError = strErrorLocal + ". The domain hotmeil.com is not valid.";
			
		else if (strEmail.match("@homail.com"))
			strError = strErrorLocal + ". The domain homail.com is not valid.";
			
		else if (strEmail.match("@hotamil.com"))
			strError = strErrorLocal + ". The domain hotamil.com is not valid.";
			
		else if (strEmail.match("@hotamil.com"))
			strError = strErrorLocal + ". The domain hotamil.com is not valid.";
			
		else if (strEmail.match("@hotmal.com"))
			strError = strErrorLocal + ". The domain hotmal.com is not valid.";
			
		else if (strEmail.match("@holmail.com"))
			strError = strErrorLocal + ". The domain holmail.com is not valid.";
			
		else if (strEmail.match("@hotmil.com"))
			strError = strErrorLocal + ". The domain hotmil.com is not valid.";
			
		else if (strEmail.match("@htomail.com"))
			strError = strErrorLocal + ". The domain htomail.com is not valid.";
			
		else if (strEmail.match("@hotml.com"))
			strError = strErrorLocal + ". The domain hotml.com is not valid.";
			
		else if (strEmail.match("@hotamail.com"))
			strError = strErrorLocal + ". The domain hotamail.com is not valid.";
			
		else if (strEmail.match("@yaho.com"))
			strError = strErrorLocal + ". The domain yaho.com is not valid.";
			
		else if (strEmail.match("@jahoo.com"))
			strError = strErrorLocal + ". The domain jahoo.com is not valid.";
			
		else if (strEmail.match("@yajoo.com"))
			strError = strErrorLocal + ". The domain yajoo.com is not valid.";
			
		else if (strEmail.match("@yahho.com"))
			strError = strErrorLocal + ". The domain yahho.com is not valid.";
			
		else if (strEmail.match("@yiahu.com"))
			strError = strErrorLocal + ". The domain yiahu.com is not valid.";
		
		else if (strEmail.match("@hayoo.com"))
			strError = strErrorLocal + ". The domain hayoo.com is not valid.";
			
		else if (strEmail.match("@hayoo.com"))
			strError = strErrorLocal + ". The domain hayoo.com is not valid.";
	}
	else
	{
		if (blnConfirmField == true)
		{
			strError = "Email and Confirm Email cannot be blank."
		}
		else
		{
			strError = "Email cannot be blank."
		}
	}
	
	if (strError == "")
	{
		// Revisar el campo de confirmar e-mail
		if (blnConfirmField == false)
		{
			strEmail = strEmailConfirm;
		}
		
		if (strEmail != strEmailConfirm)
		{
			strError = "Email and Confirm Email are different.";
		}
	}
	
	return strError;
}

function str_fnFormValid_Email_es(strEmail, strEmailConfirm, blnConfirmField)
{
	var strError = "";
	var strErrorLocal = "";
	var blnEmailValid = "";
	
	var intAtLoc = 0;
	var intDotLoc = 0;
	var intLenEmail = 0;
	var intAts = 0;
	
	if (strEmail != "")
	{
		intAtLoc = strEmail.indexOf('@');
		intDotLoc = strEmail.indexOf('.');
		intLenEmail = strEmail.length;
		intAts = strEmail.lastIndexOf('@');
		
		strErrorLocal = "Email '" + strEmail + "' es inválido";
		
		if (intAtLoc != intAts)
			intAts = 2;
		else
			intAts = 1;
		
		if ((intAtLoc <= 0) || (intAtLoc >= intLenEmail) || (intDotLoc <= 0) || (intDotLoc >= intLenEmail) || (intAtLoc == (intDotLoc+1)) || (intDotLoc == (intAtLoc+1)) || (intAts > 1))
			strError = strErrorLocal + ". Un ejemplo de email válido es: jose@hotmail.com";
		
		else if ((strEmail.toLowerCase() == "account@domain.subdomain"))
			strError = strErrorLocal + ". Por favor escribe tu propio email.";
			
		else if (strEmail.indexOf(' ') >= 0)
			strError = strErrorLocal + " por que contiene espacios en blanco.";
			
		else if (strEmail.indexOf(',') >= 0)
			strError = strErrorLocal + " por que contiene comas.";
			
		else if (strEmail.match("www."))
			strError = strErrorLocal + " por que contiene la cadena 'www.'";
		
		else if (strEmail.match("@mejoramor.com"))
			strError = strErrorLocal + " por favor escribe tu propio email.";
			
		else if (strEmail.match("@hotmail.com.mx"))
			strError = strErrorLocal + ". El dominio hotmail.com.mx is not valid.";
			
		else if (strEmail.match("@hotmeil.com"))
			strError = strErrorLocal + ". El dominio hotmeil.com es inválido.";
			
		else if (strEmail.match("@homail.com"))
			strError = strErrorLocal + ". El dominio homail.com es inválido.";
			
		else if (strEmail.match("@hotamil.com"))
			strError = strErrorLocal + ". El dominio hotamil.com es inválido.";
			
		else if (strEmail.match("@hotamil.com"))
			strError = strErrorLocal + ". El dominio hotamil.com es inválido.";
			
		else if (strEmail.match("@hotmal.com"))
			strError = strErrorLocal + ". El dominio hotmal.com es inválido.";
			
		else if (strEmail.match("@holmail.com"))
			strError = strErrorLocal + ". El dominio holmail.com es inválido.";
			
		else if (strEmail.match("@hotmil.com"))
			strError = strErrorLocal + ". El dominio hotmil.com es inválido.";
			
		else if (strEmail.match("@htomail.com"))
			strError = strErrorLocal + ". El dominio htomail.com es inválido.";
			
		else if (strEmail.match("@hotml.com"))
			strError = strErrorLocal + ". El dominio hotml.com es inválido.";
			
		else if (strEmail.match("@hotamail.com"))
			strError = strErrorLocal + ". El dominio hotamail.com es inválido.";
			
		else if (strEmail.match("@yaho.com"))
			strError = strErrorLocal + ". El dominio yaho.com es inválido.";
			
		else if (strEmail.match("@jahoo.com"))
			strError = strErrorLocal + ". El dominio jahoo.com es inválido.";
			
		else if (strEmail.match("@yajoo.com"))
			strError = strErrorLocal + ". El dominio yajoo.com es inválido.";
			
		else if (strEmail.match("@yahho.com"))
			strError = strErrorLocal + ". El dominio yahho.com es inválido.";
			
		else if (strEmail.match("@yiahu.com"))
			strError = strErrorLocal + ". The domain yiahu.com es inválido.";
		
		else if (strEmail.match("@hayoo.com"))
			strError = strErrorLocal + ". El dominio hayoo.com es inválido.";
			
		else if (strEmail.match("@hayoo.com"))
			strError = strErrorLocal + ". El dominio hayoo.com es inválido.";
	}
	else
	{
		if (blnConfirmField == true)
		{
			strError = "Email y Confirmar Email no pueden estar en blanco."
		}
		else
		{
			strError = "Email no puede estar en blanco."
		}
	}
	
	if (strError == "")
	{		
		// Revisar el campo de confirmar e-mail
		if (blnConfirmField == false)
		{
			strEmail = strEmailConfirm;
		}
		
		if (strEmail != strEmailConfirm)
		{
			strError = "Email y Confirmar Email son diferentes.";
		}
	}
	
	return strError;
}
//-->
