 // Include this line in the cfm page: 
// <cfoutput><SCRIPT LANGUAGE="JAVASCRIPT" SRC="#Variables.JS#/validation.js"> </SCRIPT></cfoutput>


//***
// back_msg: Ask user confirmation before load the previous page
// ARGUMENTS:
//  1- cancel_msg: Message
//
// RETURN VALUES: None
//

//***
function back_msg(back_msg)
{
	if (back_msg == null)
	{
		history.back()	
	}
	else if (confirm(back_msg))
	{
		history.back()
	}
}


//***
// validate_passwd - Compare values of passwd1 and passwd2.  
// ARGUMENTS:
//  1- passwd1: password field
//  2- passwd2: password confimration field
//  3- msg1(optional): message displayed when passwd1 or passwd2 is empty
//  4- msg2(optional): message displayed when passwd1 and passwd2 don't match
//
// RETURN VALUES:
//  true: password confirmation ok
//  false: password confirmation not ok
//

//***
function validate_passwd(passwd1, passwd2, msg1, msg2)
{
	!msg1 ? msg1 = "Please enter your password." : msg1
	!msg2 ? msg2 = "Please reenter your password.\nConfirmation has failed." : msg2

	if (!passwd1.value || !passwd2.value)
	{
	   if (!passwd1.value){
	    alert(msg1);
		passwd1.focus();
		}
	   else { 
	    alert(msg2);
		passwd2.focus();
	   }
	   return false;
	}
	else if (passwd1.value != passwd2.value)
	{
		alert(msg2);
		passwd2.select();
		return false;
	}
	else return true
}

//***
// validate_mandatory: Check if a value has been entered in a form field
// ARGUMENTS:
//  1- fieldname: Field to check
//  2- msg(optional): Message to display. If null, no message is displayed.
//  3- null_val(optional): Specify a customized value for "null".
//
// RETURN VALUES:
//  1- true: value entered, validation ok.
//  2- false: value not entered, validation error.
//

//***
function validate_mandatory(fieldname, msg, null_val)
{
	if (fieldname.value == null_val || fieldname.value == "")
	{
		return_val = false
		
		if (msg)
		{
			alert(msg)
		}
		
		fieldname.focus()
	}
	else 
	{
		return_val = true
	}

	return(return_val)
}



//***
// validate_email: Validate an email field value (user@server.ext)
// ARGUMENTS:
//  1- fieldname: name of the email field in the form.
//  2- msg(optional): Message to be displayed if the format is wrong.
//  3- strPattern(optional): Customized email format
//
// RETURN VALUES:
//  1- true: Format ok.
//  2- false: format not ok.
//
//***

function validate_email(fieldname, msg, strPattern) 
{
	//var addressPattern = /^[\w+\.]+\@[\w+\.]+\.[A-Za-z0-9]+$/;
	var addressPattern = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;


	!strPattern ? strPattern = addressPattern : strPattern
	
	if (!addressPattern.test(fieldname.value))
	{
		return_val = false
		
		if (msg)
		{
			alert(msg)
		}
		
		fieldname.select()
	}
	else
	{
		return_val = true
	}

	return(return_val)
}




