 // Include this line in the cfm page: 
// <cfoutput><SCRIPT LANGUAGE="JAVASCRIPT" SRC="#Variables.JSDIR#/Common.js"> </SCRIPT></cfoutput>

//***
// window_open: open a popup or reuse an existing one if already openned.
// ARGUMENTS:
//  1- URL: WEB page to be displayed in the popup window
//  2- NOT USED (Make the replace easier on Fireworks-generated HTML
// 
// RETURN VALUES: none
//
//  By Yannick Haineault
//  August 12, 2002
//***

function window_open(url,not_used)
{
	var winWidth = screen.availWidth*.75;
	var winHeight = screen.availHeight*.75;
	var win_options = 'toolbar=1,scrollbars=1,resizable=1,width='+winWidth+',height='+winHeight+'top=0,left=0';
	var URL_win;
	
	URL_win = window.open(url,'external_link',win_options);
	URL_win.focus();
}

//***
// 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=1,location=0,directories=0,status=yes,menubar=yes,scrollbars=1,resizable=1,width=750,height=550,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)
}

//***
// openP_screen: open a popup window with default attributes.  The window's size will be proportionnal to the screen size
// ARGUMENTS:
//  1- link: WEB page to be displayed in the popup window
//  2- opt_list(optional): Window attributes.
//  3- size_ratio: size of the window.  Default: .85 which is 85% of the current screen size.
//	4- width_ratio: Width of the window.  This value overwritte the size_ratio for the width.  Use 'null' if you don't want to use it.
//	5- height_ratio: Height of the window.  This value overwritte the size_ratio for the height.  Use 'null' if you don't want to use it.
//  6- location ratio: Location of the window.  Default .075 which is 7.5% of the current screen size.
//	7- x_ratio: Horizontal position of the window.  This value overwritte the location_ratio for the 'x' coordinate.
//	8- y_ratio: Vertical position of the window.  This value overwritte the location_ratio for the 'y' coordinate.
// 
// RETURN VALUES: none
//
//  By Yannick Haineault
// May 21, 2002
//***

function openP_screen(link, opt_list, size_ratio, width_ratio, height_ratio, location_ratio, x_ratio, y_ratio)
{
	size_ratio = !size_ratio ? .85 : size_ratio;
	size_ratio = size_ratio > 1 ? 1 : size_ratio;
		
	location_ratio = !location_ratio ? (1 - size_ratio)/2 : location_ratio;
	location_ratio = location_ratio > size_ratio ? 0 : location_ratio;

	x_ratio = !x_ratio ? location_ratio : x_ratio;
	y_ratio = !y_ratio ? location_ratio : y_ratio;

	width_ratio = !width_ratio ? size_ratio : width_ratio;
	height_ratio = !height_ratio ? size_ratio : height_ratio;

	var win_width=screen.availWidth * width_ratio;
	var win_height=screen.availHeight * height_ratio;
	var win_x=screen.availWidth * x_ratio;
	var win_y=screen.availHeight * y_ratio;
	
	var winsize=width='width='+(win_width)+',height=1,left='+(win_x)+',top='+(win_y);

	!opt_list ? opt_list = 'toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1' + winsize : opt_list + winsize;

	var winID = window.open(link,'_blank', opt_list);

	winID.moveTo((win_x), (win_y));

/*alert(screen.availWidth);
alert(screen.availHeight);
alert(win_height);
alert(width_ratio);
alert(height_ratio);*/

	for (var a = 1; a <= (win_height); a += 15 )
	{
		winID.resizeTo((win_width), a);
	}

	winID.resizeTo((win_width),(win_height));
	
}



//***
// 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)))
	{
		var winH = -15;
		for (i = 1; i < 40; i++)
		{
			window.resizeBy(0, winH);
		}
		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
		}
	
	}
}

function cancel_input_NE(cancel_msg, destination)
{
	if (destination == null)
	{
		if (cancel_msg == null)
		{
			back_or_close_NE()	
		}
		else if (confirm(cancel_msg))
		{
			back_or_close_NE()
		}
	}
	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 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
}

/*
// This script works like our Password Verifier, however, it also checks for a minimum length and invalid characters.
// ARGUMENTS:
//  1- pwd1: password field
//  2- pwd2: password confimration field
//
// RETURN VALUES:
//  true: password confirmation
//  false: password confirmation not ok
//
//  By François Brouillet
//  December 2007
*/

/* Messages anglais */
function validatePwd_1(pwd1,pwd2) 
{
	var invalid = " "; // Invalid character is a space
	var minLength = 6; // Minimum length
	var pw1 = pwd1.value;
	var pw2 = pwd2.value;
	// check for a value in both fields.
	if (pw1 == '' || pw2 == '') {
	alert('Please enter your password twice.');
	return false;
	}
	// check for minimum length
	if (pwd1.value.length < minLength) {
	alert('Your password must be at least ' + minLength + ' characters long. Try again.');
	return false;
	}
	// check for spaces
	if (pwd1.value.indexOf(invalid) > -1) {
	alert("Sorry, spaces are not allowed.");
	return false;
	}
	else {
	if (pw1 != pw2) {
	alert ("You did not enter the same new password twice. Please re-enter your password.");
	return false;
	}
	else {
	/*alert('Nice job.');*/
	return true;
	      }
	   }
}

/* Messages français */
function validatePwd_2(pwd1,pwd2) 
{
	var invalid = " "; // Invalid character is a space
	var minLength = 6; // Minimum length
	var pw1 = pwd1.value;
	var pw2 = pwd2.value;
	// check for a value in both fields.
	if (pw1 == '' || pw2 == '') {
	alert('Veuillez entrer votre mot de passe et le confirmer.');
	return false;
	}
	// check for minimum length
	if (pwd1.value.length < minLength) {
	alert('Votre mot de passe doit compter au moins ' + minLength + ' caractères. Veuillez recommencer.');
	return false;
	}
	// check for spaces
	if (pwd1.value.indexOf(invalid) > -1) {
	alert("Désolé, les espaces ne sont pas permis.");
	return false;
	}
	else {
	if (pw1 != pw2) {
	alert ("Les mots de passe diffèrent. Veuillez recommencer.");
	return false;
	}
	else {
	/*alert('Nice job.');*/
	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 == "" || fieldname.value == " " || 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.
//
//***
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 = /^[\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)
}


function validate_pc(fieldname, msg, strPattern) 
{
	//var addressPattern = /^[\w+\.]+\@[\w+\.]+\.[A-Za-z0-9]+$/;
	var addressPattern = /^\s*[a-ceghj-npr-tvxy]\d[a-z](\s)?\d[a-z]\d\s*$/i;


	!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)
}

function validate_tel(fieldname, msg, strPattern) 
{
	
	var addressPattern = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;


	!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)
}





// ---------------------------------------------------------------- 

// Embedded Popups
var xPos;
var yPos;
function setPos(e) {
	// Gets the position of the mouse click
	if (document.all) {
		xPos = window.event.x + 25;
		yPos = window.event.y + document.body.scrollTop + 5;
	}
	return true;
}
function showpopbox(sName,absX,absY) {
	if (!isNaN(absX) && !isNaN(absY)) {
		// allow for absolutely positioned elements
		xPos = absX;
		yPos = absY;
	}
	// opens the embedded popups
	document.getElementById(sName).style.display = 'block';
	document.getElementById(sName).style.left = xPos + "px";
	document.getElementById(sName).style.top = yPos + "px";
}
function hidepopbox(sName) {
	// Closes the embedded popups
	document.getElementById(sName).style.display = 'none';
}
