//<script>
//alert('Lib.js included succesfully');
/**************************************
Function : Open New Window function   *
Author   : Martin Bélanger            *
***************************************
parameters :
	-Page to Open
	-Height of the new window
	-Width of the new window
	-Name of the new window (optional)

syntax : 

	WinOpen('fichier',H,W[,WinName])
*/


function WinOpen(fichier,H,W,WinName)
{
	if (WinName == '')
	{
		WinName = 'popwin'
	}
	var avwidth = screen.availWidth;
	var avheight = screen.availHeight;
	avwidth = (avwidth - W)/2;
	avheight = (avheight - H)/2;
	var win = window.open(fichier,WinName,"scrollBars=yes,height="+H+",width="+W+",top="+avheight+",left="+avwidth+" resizable=yes")
	win.focus();
}

function WinOpenFull(fichier,WinName)
{
	if (WinName == '')
	{
		WinName = 'popwin'
	}
	var avwidth = screen.availWidth;
	var avheight = screen.availHeight;
	avwidth = avwidth - 50;
	avheight = avheight - 50;
	var win = window.open(fichier,WinName,"scrollBars=yes,height="+avheight+",width="+avwidth+",top=10,left=10 resizable=yes")
	win.focus();
}

//---------------------------------------------------------------------------------------------------------------
//Regular expr to enforce certain characters >> Author: Ramzi Abu-Abed

function isAlphaNumeric(strValid)
{
	strValid.search(/^[A-Z0-9a-z]+$/)!=-1?state = true:state = false;
	return state;
}
//---------------------------------------------------------------------------------------------------------------
//Enfore string length >> Author: Ramzi Abu-Abed
//Parameters: strValid: String to validate -- strMinLen: Min allowed characters -- strMaxLen: Max allowed characters
function isLengthOk(strValid,strMinLen,strMaxLen)
{
	!(strValid)?state = false:strValid.length > strMaxLen || strValid.length < strMinLen?state = false:state=true;
	return state;
}

//---------------------------------------------------------------------------------------------------------------
//Regular expr to enforce a number >> Author: Talal Chaihaytli
function IsThereNumber(strValue)
	{	
	  (strValue.replace(/[0-9]{1}/,'')==strValue)?state =false :state = true;
	  return state;	
	}

//---------------------------------------------------------------------------------------------------------------
//Regular expr to enforce a characters >> Author: Talal Chaihaytli
function IsThereChar(strValue)
{	
  (strValue.replace(/[a-zA-Z]{1}/,'')==strValue)?state =false :state = true;
  return state;	
}

//---------------------------------------------------------------------------------------------------------------
//Swap Images (ie only, faster than MM_swapImgRestore)

function  AlterImage(objImg,newImg)
{	
	var img = new Image()
	img.src = newImg
	objImg.src = img.src
}
//---------------------------------------------------------------------------------------------------------------

/*Swap Images functions*/
function MM_swapImgRestore() { //v2.0
  if (document.MM_swapImgData != null)
    for (var i=0; i<(document.MM_swapImgData.length-1); i+=2)
      document.MM_swapImgData[i].src = document.MM_swapImgData[i+1];
}

function MM_preloadImages() { //v2.0
  if (document.images) {
    var imgFiles = MM_preloadImages.arguments;
    if (document.preloadArray==null) document.preloadArray = new Array();
    var i = document.preloadArray.length;
    with (document) for (var j=0; j < imgFiles.length; j++) if (imgFiles[j].charAt(0)!="#"){
      preloadArray[i] = new Image;
      preloadArray[i++].src = imgFiles[j];
  } }
}

function MM_swapImage() { //v2.0
  var i,j=0,objStr,obj,swapArray=new Array,oldArray=document.MM_swapImgData;
  for (i=0; i < (MM_swapImage.arguments.length-2); i+=3) {
    objStr = MM_swapImage.arguments[(navigator.appName == 'Netscape')?i:i+1];
    if ((objStr.indexOf('document.layers[')==0 && document.layers==null) ||
        (objStr.indexOf('document.all[')   ==0 && document.all   ==null))
      objStr = 'document'+objStr.substring(objStr.lastIndexOf('.'),objStr.length);
    obj = eval(objStr);
    if (obj != null) {
      swapArray[j++] = obj;
      swapArray[j++] = (oldArray==null || oldArray[j-1]!=obj)?obj.src:oldArray[j];
      obj.src = MM_swapImage.arguments[i+2];
  } }
  document.MM_swapImgData = swapArray; //used for restore
}
//---------------------------------------------------------------------------------------------------------------
/**************************************
Function : trim function like VB      *
Author   : Martin Bélanger            *
***************************************
removes leading and trailing spaces
*/
function trim(str)
	{
		str = this != window? this : str;
		return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
	}
//---------------------------------------------------------------------------------------------------------------
/**************************************
Function : round function like VB     *
Author   : Martin Bélanger            *
**************************************/
function round(number,X) 
{
	// rounds number to X decimal places, defaults to 2
	X = (!X ? 2 : X);
	return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}
//---------------------------------------------------------------------------------------------------------------
/*********************************************
Function : FormatNumber function like VB     *
Author   : Martin Bélanger					 *
*********************************************/
function FormatNumber(lnumber,lnbDec)
{
	if (!lnbDec)
		lnbDec = 2
		
	lnumber = round(lnumber,lnbDec)
	lnumber = lnumber.toString()
	lnumber = lnumber.replace(',','.')
	
	if(lnumber.indexOf('.') == -1)
		lnumber = lnumber + '.'
		
	for(i=0;i<lnbDec;i++)
	{
		if(lnumber.charAt((lnumber.indexOf('.')+1)+i) == '')
			lnumber = lnumber + '0'
	}
	return lnumber
}
//---------------------------------------------------------------------------------------------------------------
/***********************************************************
Function : Verify if at least One check box is checked     *
Author   : Martin Bélanger								   *
***********************************************************/

function AtLeastOneChecked(objFrame, objCheckAll)
{
	var nb=0;
	for (i=1; i<objFrame.length && nb == 0; i++)
	{
		
		if (objFrame(i).checked && objFrame(i).name != objCheckAll.name)
		{
			nb++;
			break;
		}
	}
	if (nb==0)
		return false;
	else
		return true;
}

function show(id) 
{
	ns4 = (document.layers)? true:false
	ie4 = (document.all)? true:false
	ns5 = (navigator.appName == "Netscape" || navigator.appVersion>=5)? true:false	
	if(ns4) document.layers[id].visibility = "show"
	else 
		if(ie4 && document.all[id]) document.all[id].style.visibility = "visible"
		else if(ns5) document.getElementById(id).style.visibility = "visible"
}

function showInner(id_outer,id_inner)//Author: Ramzi purpose: Created to access div within a div for Netscrap 4.75
{
	if(document.layers)
	 document.layers[id_outer].document.layers[id_inner].visibility = "show";
}

function hide(id) 
{	
	ns4 = (document.layers)? true:false
	ie4 = (document.all)? true:false
	ns5 = (navigator.appName == "Netscape" || navigator.appVersion>=5)? true:false
	if(ns4) document.layers[id].visibility = "hide"
	else 
		if(ie4 && document.all[id]) document.all[id].style.visibility = "hidden"
		else if(ns5) document.getElementById(id).style.visibility = "hidden"
}

function hideInner(id_outer,id_inner)//Author: Ramzi purpose: Created to access div within a div for Netscrap 4.75
{	
	if(document.layers)
	  document.layers[id_outer].document.layers[id_inner].visibility = "hidden";

}

function IsNumeric(number)
{
	var IsNumeric = true
	
	if(isNaN(Math.round(number)))
		IsNumeric = false
	
	if(number.length==0)	
		IsNumeric = false
	
	return(IsNumeric)
}

function IsEmail(strEmail) 
{	
	strEmail = trim(strEmail)
	if (strEmail.indexOf("@") < 1 || strEmail.indexOf(".") == -1 || (strEmail.lastIndexOf(".")-strEmail.indexOf("@") <= 1) || parseInt(strEmail.indexOf(".") + 1) == strEmail.length || strEmail.indexOf(" ") > -1)
	{
		return(false)
	}
	else
	{
		return(true)
	}
}


function layerWrite(id,nestref,text) 
{
	ns4 = (document.layers)? true:false
	ie4 = (document.all)? true:false
	ns5 = (navigator.appName == "Netscape" || navigator.appVersion>=5)? true:false
	if (ns4) {	
		var lyr = (nestref)? eval('document.'+nestref+'.document.'+id+'.document') : document.layers[id].document
		lyr.open()
		lyr.write(text)		
		lyr.close()
	}
	else if (ie4) document.all[id].innerHTML = text
	else if (ns5) document.getElementById(id).innerHTML = text
}




/*-----------------------------------------------------------------------------
' Prototype Name		: IsIn
' Constructor affected	: String, Number
' Exemple				: http://rcastaging.rideau.com/sample/in.asp
'
' MODIFICATIONS
' DATE			AUTHOR			ACTION
' 2002.04.08	Frédéric Vachon	Creation of prototye
'
'
'----------------------------------------------------------------------------*/
String.prototype.isIn =	function(strIsIn)
						{
							var arrIn = strIsIn.split(",")
							for(var i = 0; i < arrIn.length; i++)
								if(this == arrIn[i])
									return(true)
							return(false)		
						}
						
						
Number.prototype.isIn =	function(strIsIn)
						{
							var arrIn = strIsIn.split(",")
							for(var i = 0; i < arrIn.length; i++)
								if(this == arrIn[i])
									return(true)
							return(false)		
						}

/*-----------------------------------------------------------------------------
' Prototype Name		: toCharCode
' Constructor affected	: String
' Description			: Opposite to fromCharCode()
' Exemple				: http://rcastaging.rideau.com/sample/toCharCode.asp
'
' MODIFICATIONS
' DATE			AUTHOR			ACTION
' 2002.04.08	Frédéric Vachon	Creation of prototye
'
'
'----------------------------------------------------------------------------*/
String.prototype.toCharCode =	function (){return(this.charCodeAt(0).toString(10));}

//---------------------------------------------------------------------------------------------------------------
/********************************************************************
Function : enable/disable clicks of links and buttons on a page	    *
		initClickPrevention()				    *
		stopClickPrevention ()				    *
Author   : 							    *
*********************************************************************/
function clickHandler (evt) 
	{
	  if (document.layers)
	    return false;
	  else if (evt.stopPropagation) 
	  {
	    evt.stopPropagation();
	    evt.preventDefault();
	  }
	  else if (window.event)
	    return false;
	}
	
function initClickPrevention () 
	{
	  var	MAC = navigator.userAgent.indexOf("Mac") > -1 ? 1 : 0;

	  if (document.layers) 
	  {
	    window.captureEvents(Event.CLICK);
	    window.onclick = clickHandler;
	  }
	  else if (document.all && !document.getElementById)
	    document.onclick = clickHandler;
	  else if (document.all && !MAC)
	    document.attachEvent('onclick', clickHandler);
	  else if (document.addEventListener)
	    document.addEventListener('click', clickHandler, true);
	}
	
function stopClickPrevention () 
	{
		var	MAC = navigator.userAgent.indexOf("Mac") > -1 ? 1 : 0;
	 if (document.layers) 
	  {
	    window.releaseEvents(Event.CLICK);
	    window.onclick = null;
	  }
	  else if (document.all && !document.getElementById)
	    document.onclick = null;
	  else if (document.all && !MAC)
	    document.detachEvent('onclick', clickHandler);
	  else if (document.addEventListener)
	    document.removeEventListener('click', clickHandler, true);
	}
	

function RedirectURL(strURL){
	with (document.frmMain){
		if(document.frmMain.hidPosition)
			document.frmMain.hidPosition.value='';
		if(document.frmMain.hidCurrentPageOrder)
			document.frmMain.hidCurrentPageOrder.value='';
		action = strURL;submit();
	}		
}
function ChangeLang(CurrentLang){		
	document.frmMain.hidLang.value = (CurrentLang == 'EN')?'FR':'EN';RedirectURL('#');
}
function ChangeLangEnter(CurrentLang){
	document.frmMain.hidLang.value = CurrentLang;
}
function ShowCart(){
	with(document.frmMain){action = "ShowCart.asp";submit();}
}
function AddToMyFavorites(){
	var objSelectedForm = eval("document.frmHidProductInformation" + ArrAddToCartNum[0]) ; 	
	with(document.frmMain){hidProductCode.value = objSelectedForm.hidProductCode.value;action = "AddToMyFavorites.asp";method = "post";submit();}
}	
function OnlineCatalog(){
	with(document.frmMain){
		hidPosition.value = "";action = "Catalog.asp";method = "post";submit();
	}				
}
function showEuro(which){
	show("divEuroPrice"+which);
}
function popUp(url) {
	newWin=window.open(url,"win",'toolbar=1,location=1,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=700,height=500');
}



/////////////////  Ajax Related funtions




function getServerName()
{
    var str = window.location.protocol + '//' + window.location.hostname;
    return str;
}

//
// summary:
// Provides a mechanism for attaching a handler to an event
//
// parameters:
// element - Element to attach event handler to 
// eventType - Event 
// handler - Handler called when event is raised 
// useCapture - Use capture
//
// returns:
// True if attached successfully
//
function AddEvent(element, eventType, handler, useCapture)
{
	var attached = false;

	if(element != null)
	{
		if(element.addEventListener)
		{
			element.addEventListener(eventType, handler, useCapture);
			attached=true;
		}
		else if(element.attachEvent)
		{
			element.attachEvent("on" + eventType, handler);
			attached=true;
		}
		else
		{
			attached = false;
		}
	}

	return attached;
}

//
// summary:
// Provides cross browser access to the event data element that raised the
// event
//
// parameters:
// e - Event data
//
function GetElementFromEventData(e)
{
	return e.target || e.srcElement;
}

//
// Generic helper methods for XmlHttp objects
//

//var xmlHttp; 

//
// summary:
// Performs the XMLHttp send GET request 
//
// parameters:
// xmlHttp - Xml Http object 
// url - Url to send
//
function PerformXmlHttpGet(xmlHttp, url) 
{ 
	xmlHttp.open('GET', url, true); 
	xmlHttp.send(null); 
} 

function PostXMLHTTRequest(url, wait)
{
	var httpXml = Sarissa.getXmlHttpRequest();
	httpXml.open('POST', url, wait);
	if (wait == true)
	{
		httpXml.onreadystatechange = function()
		{
	      	if (httpXml.readyState == 4)
		  	{
    		}
    	};
	}
	httpXml.send(null);
	
	return httpXml.responseText;
}

function GetXMLHTTRequest(url, wait)
{
	var httpXml = Sarissa.getXmlHttpRequest();
	httpXml.open('GET', url, wait);
	if (wait == true)
	{
		httpXml.onreadystatechange = function()
		{
	      	if (httpXml.readyState == 4)
		  	{
    		}
    	};
	}
	httpXml.send(null);
	
	return httpXml.responseText;
}
//
// summary:
// Gets the Xml document object based upon the users browser
//
// returns:
// Xml DOM object
//
function GetXmlObject() 
{ 
	var msie = (window.ActiveXObject) ? true : false;
	var moz = (document.implementation && document.implementation.createDocument) ? true : false;
	if (moz)
	{
		//return document.implementation.createDocument("", "", null);
		return new Sarissa.getDomDocument();
	} 
	else if (msie)
	{
		return new ActiveXObject('Microsoft.XMLDOM');
	}
	// return Server.CreateObject("MSXML2.ServerXMLHTTP")
	//return Server.CreateObject("Microsoft.XMLDOM")
}

//
// summary:
// Gets the XmlHttp object based upon the users browser
//
// parameters:
// handler - Callback handler
//
// returns:
// XmlHttp object
//
function GetXmlHttpObject(handler) 
{ 
	var isIE = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0; 
	var isIE5 = (navigator.appVersion.indexOf("MSIE 5.5")!=-1) ? 1 : 0; 
	var isOpera = ((navigator.userAgent.indexOf("Opera6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1)) ? 1 : 0; 
	//netscape, safari, mozilla behave the same??? 
	var isNetscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0; 
	var localXmlHttp = null;

	// Depending on the browser, try to create the xmlHttp object 
	if (isIE)
	{ 
		//alert('isIE');
		// The object to create depends on version of IE 
		// If it isn't ie5, then default to the Msxml2.XMLHTTP object 
		var strObjName = (isIE5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP'; 
		 
		//Attempt to create the object 
		try
		{ 
			localXmlHttp = new ActiveXObject(strObjName); 

			if (handler != null)
			{
				localXmlHttp.onreadystatechange = handler; 
			}
		} 
		catch(e)
		{ 
			// Object creation error 
			alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled'); 
			return; 
		} 
	} 
	else if (isOpera)
	{ 
		//alert('isOpera');
		// Opera has some issues with xmlHttp object functionality 
		//alert('Opera detected. The page may not behave as expected.'); 
		//return; 
		return Sarissa.getXmlHttpRequest();
	} 
	else
	{ 
		//alert('isSafari');
		// Mozilla | Netscape | Safari 
		localXmlHttp = new XMLHttpRequest(); 

		if (handler != null)
		{
			localXmlHttp.onload = handler; 
			localXmlHttp.onerror = handler; 
		}
	} 
	 
	// Return the instantiated object 
	return localXmlHttp; 
}

//
// summary:
// Tests whether the callback was successful
//
// parameters:
// xmlHttp - Xml Http object
//
// returns:
// True is successfull
//
function IsCallbackSuccessful(xmlHttp)
{
	return (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete');
}

//
// summary:
// Generates a random number to be used on urls sent back to the server.
//
// remarks:
// This is used to get around the IE problem of caching requests
//
// returns:
// A random integer
//
function NextUrlIndex()
{
	var floatNum = Math.random()*50000;
	var intNum = Math.floor(floatNum); 
	return intNum;
}

//
// summary:
// Checks the event data for an enter key press.
//
// remarks:
// Used by text key press handlers to verify if an enter key press was
// raised.
//
// parameters:
// e - Event data
//
function CheckEnter(e)
{ 
	var characterCode = null;

	// If which property of event object is supported (NN4)
	if(e && e.which)
	{ 
		// Character code is contained in NN4's which property
		characterCode = e.which;
	}
	else
	{
		// Character code is contained in IE's keyCode property
		characterCode = e.keyCode;
	}

	// If generated character code is equal to ascii 13 (if enter key)
	if(characterCode == 13)
	{ 
		return true;
	}
	else
	{
		return false; 
	}
}

