function ValidateEnAU(source, arguments){
	/*
	var controls = arguments.Value.split("|");
	var txt1 = eval("document.forms[0]." + controls[0] + ".value");
	var txt2 = eval("document.forms[0]." + controls[1] + ".value");
	if(txt1.length == 0 && txt1.length == 0){
		arguments.IsValid = false;
	}else{
		arguments.IsValid = true;
	}
	*/
}


function KeyDownHandler(btn)
{ 
	// process only the Enter key 
	if (event.keyCode == 13) 
	{ 
	// cancel the default submit 
	event.returnValue=false; 
	event.cancel = true; 
	// submit the form by programmatically clicking the specified button 
	btn.click(); 
	} 
} 

function LoadPassword(sPassword)
{
	with(document.FrmPage)
	{
		TxtFldPassword.value = sPassword;
		TxtFldPasswordConfirmation.value = sPassword;
	}
}

function HideHint(){
	with(document.all("HintLayer")){
		style.visibility='hidden';
	}
}

function ShowHint(){
	with(document.all("HintLayer")){
		style.left = event.x + 10;
		style.top = event.y + 15;

		var pixelRight  = style.pixelLeft + style.pixelWidth;
		var pixelBottom = style.pixelTop + style.pixelHeight;
			
		if(pixelRight > document.body.clientWidth){
			style.left = document.body.clientWidth - (pixelRight - style.pixelLeft + 10);
		}

		if(pixelBottom > document.body.clientHeight){
			style.top = document.body.clientHeight - (pixelBottom - style.pixelTop + 10);
		}

		style.visibility='visible';
		
		setTimeout("HideHint();", 10000);
	}
}

function ValidateAccessCode(source, arguments)
{
	var AccessCode = arguments.Value;
	
	if(AccessCode.length == 7)
	{
		arguments.IsValid == false;
	}
	else if(AccessCode.length < 6)
	{
		arguments.IsValid == false;
	}
	else
	{
		if(AccessCode.length == 8){
			num1 = AccessCode.substring(0,1);
			num2 = AccessCode.substring(1,2);
			num3 = AccessCode.substring(2,3);
			num4 = AccessCode.substring(3,4);
			num5 = AccessCode.substring(4,5);
			num6 = AccessCode.substring(5,6);
			num7 = AccessCode.substring(6,7);
			iTemp = AccessCode.substring(7,8);
			
			var sum = (1*num1) + (2*num2) + (3*num3) + (4*num4) + (5*num5) + (6*num6) + (7*num7);
			
			check = sum%10;
		}
		if(AccessCode.length == 6){
			num1 = AccessCode.substring(0,1);
			num2 = AccessCode.substring(1,2);
			num3 = AccessCode.substring(2,3);
			num4 = AccessCode.substring(3,4);
			num5 = AccessCode.substring(4,5);
			iTemp = AccessCode.substring(5,6);

			sum = (1*num1) + (2*num2) + (3*num3) + (4*num4) + (5*num5);
			
			check = sum%10;
		}
		
		if(iTemp==check)
		{
			arguments.IsValid = true;
		}
		else
		{
			arguments.IsValid = false;
		}
	}
}

function LoginAction(iIndex){
	with(document.FrmPage){
		RdBtnLstLogin[iIndex].checked = true;
		return;
	}
}
function CheckSearUserMandatoryFields(source, arguments){
	with(document.FrmPage){
		if((TxtFldDocumentValue.value == "") && (TxtFldEmail.value == "")){
			arguments.IsValid = false;
		}
		else
		{
			arguments.IsValid = true;
		}
	}
}

function ValidateCpfFunction (source, arguments){
	with(document.FrmPage){
		var CPF = arguments.Value;
		if(isInt(CPF)){
			if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
				CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
				CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
				CPF == "88888888888" || CPF == "99999999999")
			{
				arguments.IsValid = false;
			}
			else
			{
				soma = 0;
				for (i=0; i < 9; i ++)
					soma += parseInt(CPF.charAt(i)) * (10 - i);
				resto = 11 - (soma % 11);
				if (resto == 10 || resto == 11)
					resto = 0;
				if (resto != parseInt(CPF.charAt(9)))
				
					arguments.IsValid = false;
					
				soma = 0;
				for (i = 0; i < 10; i ++)
					soma += parseInt(CPF.charAt(i)) * (11 - i);
				resto = 11 - (soma % 11);
				if (resto == 10 || resto == 11)
					resto = 0;
				if (resto != parseInt(CPF.charAt(10)))
				{			
					arguments.IsValid = false;
				}
				else
				{			
					arguments.IsValid = true;
				}
			}
		}
		else
		{
			arguments.IsValid = false;
		}
	}
}

function ValidateEsCo(source, arguments)
{
	var mask = /^\d{1,10}$/g;
	arguments.IsValid = mask.test(arguments.Value);
	if(!arguments.IsValid)
	{
		alert("Por favor, ingrese correctamente su número de documento, solamente con números y tamaño máximo 10.");
	}
}

function ValidateEsEc(source, arguments)
{
	var mask = /^\d{1,10}$/g;
	arguments.IsValid = mask.test(arguments.Value);
	if(!arguments.IsValid)
	{
		alert("Por favor, ingrese correctamente su número de documento, solamente con números y tamaño máximo 10.");
	}
}

function ValidateEsVe(source, arguments)
{
	var mask = /^\d{1,8}$/g;
	arguments.IsValid = mask.test(arguments.Value);
	if(!arguments.IsValid)
	{
		alert("Por favor, ingrese correctamente su número de documento, solamente con números y tamaño máximo 8.");
	}
}

function ValidateEsPe(source, arguments)
{
	var mask = /^\d{1,8}$/g;
	arguments.IsValid = mask.test(arguments.Value);
	if(!arguments.IsValid)
	{
		alert("Por favor, ingrese correctamente su número de documento, solamente con números y tamaño máximo 8.");
	}
}

function ValidateEsPy(source, arguments)
{
	var mask = /^\d{1,7}$/g;
	arguments.IsValid = mask.test(arguments.Value);
	if(!arguments.IsValid)
	{
		alert("Por favor, ingrese correctamente su número de documento, solamente con números y tamaño máximo 7.");
	}
}

function ValidateEsEs(source, arguments)
{
	var mask; 
	var Obj = window.document.getElementById("PersonalRegisterID");
	var documentType = Obj.options[Obj.selectedIndex].text;
	var msg;
	
	switch(documentType)
	{
		case "DNI":
			mask = /^\d{8}[a-zA-Z]$/g
			msg = "Por favor, introduzca correctamente su DNI (8 numeros + 1 letra).";
		break;
		case "NIE":
			mask = /^[a-zA-Z]\d{7}[a-zA-Z]$/g
			msg = "Por favor, ingrese correctamente su NIE (1 letra + 7 números + 1 letra).";
		break;
		case "NIF":
			mask = /^[a-zA-Z]\d{7}[a-zA-Z]$/g
			msg = "Por favor, ingrese correctamente su NIF (1 letra + 7 números + 1 letra).";
		break;
	}	
	
	arguments.IsValid = mask.test(arguments.Value);
	
	if(!arguments.IsValid)
	{
		alert(msg);
	}
}

/*********************************************************************************
*	FUNCTION:		isInt
*	PARAMETER:		theStr	AS String 
*	RETURNS:		TRUE if the passed parameter is an integer, otherwise FALSE
*	CALLS:			isDigit
**********************************************************************************/
function isInt(theStr) {
	var flag = true;

	if (isEmpty(theStr)) { flag=false; }
	else
	{	for (var i=0; i<theStr.length; i++) {
			if (isDigit(theStr.substring(i,i+1)) == false) {
				flag = false;
				
				break;
			}
		}
	}
	return(flag);
}

/*********************************************************************************
*	FUNCTION	isEmpty checks if the parameter is empty or null
*	PARAMETER	str		AS String
**********************************************************************************/
function isEmpty (str) {
	if ((str==null)||(str.length==0)) return true;
	else return(false);
}

/*********************************************************************************
*	FUNCTION:		isDigit
*	PARAMETER:		Any Chracter
*	CALLS			isEmpty to check the NULL
*	RETURNS:		TRUE if the passed chracter is a digit, otherwise FALSE
**********************************************************************************/
function isDigit(theNum) {
	var theMask = '0123456789';
	
	if (isEmpty(theNum)) return(false);
	else if (theMask.indexOf(theNum) == -1) return(false);
	
	return(true);
}

function ValidateEmail(Source, args)
{
	args.IsValid = false;
	
	var str = args.Value;
		
	if(str == "noemail") args.IsValid = true;
	else
	{
		var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (reg.test(str))
			args.IsValid = true;
		else
			args.IsValid = false;
	}
}
