// Include this line in the cfm page: 
// <cfoutput><SCRIPT LANGUAGE="JAVASCRIPT" SRC="#Variables.JSDIR#/Common.js"> </SCRIPT></cfoutput>

//***
// openP: open a popup window with default attributes
// ARGUMENTS:
//  1- link: WEB page to be displayed in the popup window
//  2- opt_list(optional): Window attributes.
// 
// RETURN VALUES: none
//
//  By Yannick Haineault
// November 30, 2001
//***
function openP(link, opt_list) 
{
	!opt_list ? opt_list =  'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+screen.availWidth * .75+',height='+screen.availHeight * .75+',left=0,top=0': opt_list

//	win_pop = window.open(link,'_popup', opt_list)
//	win_pop.focus()

	winID = window.open(link,'_blank', opt_list)
	winID.focus()
	//return(winID)
}

//***
// back_or_close: Go back in history, or close window if in a popup
// ARGUMENTS:
//  1- back_num: Number of pages to go back in history
// 
// RETURN VALUES: none
//
//  By Yannick Haineault
// November 30, 2001
//***
function back_or_close(back_num)
{
	!back_num ? back_num = -1 : back_num
	back_num > 0 ? back_num * -1 : back_num
	
//	hist_len = history.length
		
	if (self.opener)// && ((hist_len == 0) || (hist_len == 2)))
	{
		window.close()
	}
	else 
	{
		history.go(back_num)
	}
}

//***
// cancel_input: Ask user confirmation before cancelling a form input
// ARGUMENTS:
//  1- cancel_msg: Confirmation message
//
// RETURN VALUES: None
//
//  By Yannick Haineault
//  November 30, 2001
//***
function cancel_input(cancel_msg, destination)
{
	if (destination == null)
	{
		if (cancel_msg == null)
		{
			back_or_close()	
		}
		else if (confirm(cancel_msg))
		{
			back_or_close()
		}
	}
	else
	{
		if (cancel_msg == null)
		{
			location.href=destination	
		}
		else if (confirm(cancel_msg))
		{
			location.href=destination
		}
	
	}
}

//***
// back_msg: Ask user confirmation before load the previous page
// ARGUMENTS:
//  1- cancel_msg: Message
//
// RETURN VALUES: None
//
//  By Yannick Haineault
//  February 14, 2002
//***
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
//
//  By Yannick Haineault
//  December 10, 2001
//***
function validate_passwd(passwd1, passwd2, msg1, msg2)
{
	!msg1 ? msg1 = "Please confirm your password." : msg1
	!msg2 ? msg2 = "Please reenter your password.\nConfirmation has failed." : msg2

	if (!passwd1.value || !passwd2.value)
	{
		alert(msg1);
		passwd1.focus()
		return false;
	}
	else if (passwd1.value != passwd2.value)
	{
		alert(msg2);
		passwd1.focus();
		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.
//
//  By Yannick Haineault
//  December 11, 2001
//***
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)
}

//***
// aevalidate_mandatory: Check if a value has been entered in an active edit 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.
//
//  By Yannick Haineault
//  February 11, 2002
//***
function aevalidate_mandatory(fieldname, msg, null_val)
{
	if (aeObjects[fieldname].DOM.body.innerText == null_val || aeObjects[fieldname].DOM.body.innerText == "")
	{
		return_val = false
		
		if (msg)
		{
			alert(msg)
		}
		
		aeObjects[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.
//
//  By Yannick Haineault
//  December 11, 2001
//***
function validate_email(fieldname, msg, strPattern) 
{
	var addressPattern = /^[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)
}
