
//------------------------------------------------------------------------------------------------//
// MAIN FUNCTIONS SECTION                                                                         //
//------------------------------------------------------------------------------------------------//
var  submitButtonName;
var blnDOM = false, blnIE4 = false, blnNN4 = false; 

if (document.layers) blnNN4 = true;
else if (document.all) blnIE4 = true;
else if (document.getElementById) blnDOM = true;
function doPostBack(strSubmitButtonName)
{
	submitButtonName = strSubmitButtonName;
	
}

function getKeycode(e)
{ 
	if (blnNN4)
	{
		var NN4key = e.which
		
		if (NN4key ==13)
		{
			window.document.all.item(submitButtonName).click();
		}
	}
	if (blnDOM)
	{
		var blnkey = e.which
		
		if (blnkey ==13)
		{
			window.document.all.item(submitButtonName).click();
		}
	}
	if (blnIE4)
	{
		var IE4key = event.keyCode
		
	if (IE4key ==13)
		{
			window.document.all.item(submitButtonName).click();
		}
	}
}

function GetMainFormName(){
	var i;
	for (i=0;i<document.forms.length;i++){
		if (document.forms[i].name.indexOf("__aspnetForm") != -1)
		return document.forms[i].name;
	}
	return null;
}

function GetElementName(name,mf){
	var n = name.toLowerCase()
	if (n==null || n=="") return null;
	var i, s, j;
	for (i=0;i<document.forms[mf].elements.length;i++){
		if (document.forms[mf].elements[i].name.toLowerCase().indexOf(n) != -1){
			var strform = document.forms[mf].elements[i].name.toLowerCase();
			var strformname = strform.substr(strform.indexOf(n),n.length);
			if (strformname == n)
				return document.forms[mf].elements[i].name;
		}	
	}
	return null;
}

function gotoUrlNav() {
	togo = document.forms[0].Select1.options[document.forms[0].Select1.selectedIndex].value;
	if (togo!="") document.location.href= togo;
}


/*function GetMainFormName()
{
	var i;
	for (i=0;i<document.forms.length;i++)
	{
		// Framework v1.0.3705
		if (document.forms[i].name.indexOf("_ServerForm") != -1)
			return document.forms[i].name;
		// Framework v1.1.4322
		if (document.forms[i].name.indexOf("__aspnetForm") != -1)
			return document.forms[i].name;
	}
	return null;
}

function GetElementName(n,mf)
{
	if (n==null || n=="") return null;
	var i, s, j;
	for (i=0;i<document.forms[mf].elements.length;i++)
	{
		if (document.forms[mf].elements[i].name.toLowerCase().indexOf(n.toLowerCase()) != -1)
		{
			var strform = document.forms[mf].elements[i].name.toLowerCase();
			var strformname = strform.substr(strform.indexOf(n.toLowerCase()),n.length);
			if (strformname == n)
				return document.forms[mf].elements[i].name;
		}	
	}
	return null;
}

*/


function SaveElement(ElementObject,ElementValue)
{
	var mf = GetMainFormName();					
	if (mf==null) return;
	var element  = GetElement(ElementObject,mf);
	if (element!=null) 
		element.value = ElementValue;
}



function GetElement(ElementName, formName)
{
	return document.forms[formName].elements[GetElementName(ElementName,formName)];
}

//------------------------------------------------------------------------------------------------//
// CONTACT US FUNCTIONS SECTION                                                                   //
//------------------------------------------------------------------------------------------------//
var subjectlist;

//-----------------------------------------------//
// This function add a subject to subjects list. //
//-----------------------------------------------//
function AddSubject(subject, subsubject)
{
	var index;
	var subjectfound = false;
	var currentsubject;
	
	if (!subjectlist)
	{
		// Initialize subject Array;
		 subjectlist = new Array();
	}

	// Search the subject in subjects Array
	for (index = 0; (index < subjectlist.length) && !subjectfound; index++)
	{
		currentsubject = subjectlist[index];
		
		// Test if subject and current subject are defined
		if (subject && currentsubject)
		{
			if (subject.code == currentsubject.code)
			{
				subjectfound = true;
			}
		}
	}

	if (!subjectfound)
	{
		// Add the subject to subjects Array
		subjectlist.push(subject);
		currentsubject = subject;
	}

	// Add the subsubject to the subject
	AddSubSubject(currentsubject, subsubject);
}

//---------------------------------------------//
// This function add a subsubject to a subject //
//---------------------------------------------//
function AddSubSubject(subject, subsubject)
{
	// Test if subject and subsubject are defined
	if (subject && subsubject)
	{
		if (!subject.subsubjects)
		{
			subject.subsubjects = new Array();
		}
		
		// Add subsubject
		subject.subsubjects.push(subsubject);
	}
}

//---------------------------------------------//
// This function fills a select with subjects. //
//---------------------------------------------//
function FillSubject()
{	var currentBrowser = ReturnBrowser();
	var index;
	var optionitem;
	var subjectselect = GetElement("mail_subject_list", 0);
	var subjecthidden = GetElement("mail_subject", 0);
	
	if (subjectselect && subjectlist)
	{
		// Reset subjects
		ResetSelect(subjectselect);
		
		for (index = 0; index < subjectlist.length; index++)
		{
			// Add option item
			optionitem = document.createElement("OPTION");
			optionitem.text = subjectlist[index].text;
			optionitem.value = subjectlist[index].code;
			if(currentBrowser =="MSIE")
			{
				subjectselect.add(optionitem);
				
			}
			else
			{
				subjectselect.appendChild(optionitem);
			}
			if (subjecthidden)
			{
				// Select the current value
				optionitem.selected = (optionitem.value == subjecthidden.value);
			}
		}
	}
}
// DETECT BROWSER
function ReturnBrowser() {
   var Browser;
   Browser=((navigator.appName == "Microsoft Internet Explorer")?"MSIE":Browser);
   Browser=((navigator.appName == "Netscape")?"Netscape":Browser);
   Browser=((navigator.userAgent.indexOf("Firefox") > -1)?"Firefox":Browser);
   Browser=((navigator.userAgent.indexOf("Safari") > -1)?"Safari":Browser);
   Browser=((navigator.userAgent.indexOf("Camino") > -1)?"Camino":Browser);
   Browser=((navigator.userAgent.indexOf("Opera") > -1)?"Opera":Browser);
   return Browser=((Browser)?Browser:"Other");
   }


//------------------------------------------------//
// This function fills a select with subsubjects. //
//------------------------------------------------//
function FillSubSubject()
{	var currentBrowser = ReturnBrowser();
	var optionitem;
	var index;
	var subjectselect = GetElement("mail_subject_list", 0);
	var subsubjectselect = GetElement("mail_subsubject_list", 0);
	var subsubjecthidden = GetElement("mail_subsubject", 0);
	
	if (subjectselect && subsubjectselect)
	{
		// Reset subsubjects					
		ResetSelect(subsubjectselect);
		
		currentsubject = subjectlist[subjectselect.options.selectedIndex - 1];
		
		if (currentsubject && currentsubject.subsubjects)
		{		
			for (index = 0; index < currentsubject.subsubjects.length; index++)
			{
				// Add option item
				optionitem = document.createElement("OPTION");
				optionitem.text = currentsubject.subsubjects[index].text;
				optionitem.value = currentsubject.subsubjects[index].code;
				if(currentBrowser =="MSIE")
				{ 
					subsubjectselect.add(optionitem);
					
				}
				else
				{
					subsubjectselect.appendChild(optionitem);
				}
				if (subsubjecthidden)
				{
					// Select the current value
					optionitem.selected = (optionitem.value == subsubjecthidden.value);
				}
			}
		}
	}
}

//------------------------------------------------//
// This function resets a select.                 //
//------------------------------------------------//
function ResetSelect(selectlist)
{
	// Remove options
	while (selectlist.options.length != 1)
	{
		selectlist.options[1] = null;
	}
}

//------------------------------------------------//
// This function gets a value from a list using   //
// its index and return the default value if      //
// index is out of range or list is null.         //
//------------------------------------------------//
function GetListValue(list, index, defaultvalue)
{
	if (list && list[index])
	{
		return list[index];
	}
	else
	{
		return defaultvalue;
	}
}	

//------------------------------------------------//
// This function sets mailto and subject values   //
// to hidden fields. It also rebuild subsubjects  //
// list.                                          //
//------------------------------------------------//
function OnSubjectListChange()
{
	var subjectselect = GetElement("mail_subject_list", 0);
	var subject = GetListValue(subjectlist, subjectselect.selectedIndex - 1, null);
	
	if (subject)
	{
		SaveElement('mail_subject', subject.text);
		SaveElement('mail_subject_code', subject.code);
		SaveElement('mail_to', subject.emailto);
	}
	else
	{
		SaveElement('mail_subject', '');
		SaveElement('mail_subject_code', '');
		SaveElement('mail_to', '');
	}
	
	if(GetElement("mail_subsubject_list", 0))
	{
		FillSubSubject();
	}
}

//------------------------------------------------//
// This function sets mailto and subject values   //
// to hidden fields. It also rebuild subsubjects  //
// list.                                          //
//------------------------------------------------//
function OnSubSubjectListChange()
{
	var subjectselect;
	var subsubjectselect;
	var subject;
	var subsubject;
	
	subjectselect = GetElement("mail_subject_list", 0);
	subsubjectselect = GetElement("mail_subsubject_list", 0);
	subject = GetListValue(subjectlist, subjectselect.selectedIndex - 1, null);
	
	if (subject)
	{
		subsubject = GetListValue(subject.subsubjects, subsubjectselect.selectedIndex - 1, null);
		
		if (subsubject)
		{
			SaveElement('mail_subsubject', subsubject.text);
			SaveElement('mail_subsubject_code', subsubject.code);
		}
		else
		{
			SaveElement('mail_subsubject', '');
			SaveElement('mail_subsubject_code', '');
		}
	}
}

//------------------------------------------------------------------------------------------------//
// SPECIFIC FUNCTIONS SECTION                                                                         //
//------------------------------------------------------------------------------------------------//


function sesame(url,winObj,longueur,hauteur,scroll){
	window.open(url,winObj,"status=0,toolbar=no,scrollbars=0,width="+longueur+",height="+hauteur+",scrollbars="+scroll+"")
}
function sesame2(url,winObj,longueur,hauteur,scroll){
	window.open(url,winObj,"status=1,toolbar=no,scrollbars=0,width="+longueur+",height="+hauteur+",scrollbars="+scroll+"")
}


document.PageLoaded=0;

function sesameProd(url,winObj,longueur,hauteur,scroll){
	if(document.PageLoaded)	window.open(url,winObj,"status=0,toolbar=no,scrollbars=0,width="+longueur+",height="+hauteur+",scrollbars="+scroll+"");
}

function roll(ImgNme){
	ClicName=(document.clicImgFafa)? document.clicImgFafa.name:"";
	if(ClicName!=ImgNme){	
		obj=document.images[ImgNme];
		obj.src=(obj.src.lastIndexOf('-on')!=-1)? obj.src.replace(/-on/gi,"-off"):obj.src.replace(/-off/gi,"-on");
	}
}

function Clic(ImgNme){
        obj=(document.images)? document.images[ImgNme]:0; ClicNme=(document.clicImgFafa)? document.clicImgFafa.name:""; 
        if (!obj && document.layers) {
                for (i=0; i<document.layers.length; i++) { ObjLyr=document.layers[i].document;
                        if (ObjLyr.images && ObjLyr.images[ImgNme]) obj=ObjLyr.images[ImgNme];}}        
      	if (document.clicImgFafa){
				 document.clicImgFafa.src=document.clicImgFafa.src.replace(/-on/gi,"-off");        
		}
		obj.src=obj.src.replace(/-off/gi,"-on");
       document.clicImgFafa=obj;		
}

function rollOver(ImgNme){ 
	imgsrc=dlib_po(ImgNme,"image").src;
	isOn=(imgsrc.indexOf("_on")!=-1)?1:0;
	dlib_po(ImgNme,"image").src=(isOn)? imgsrc.replace(/_on/gi,"_off"):imgsrc.replace(/_off/gi,"_on"); 
}

function getRelativRootURL(RootIndex){
	ShortURL=self.location.href.substring(self.location.href.indexOf(RootIndex)+RootIndex.length);
	ShortURL=ShortURL.split("/");
	RelativPath="";
	for(i=0; i<ShortURL.length-1; i++) RelativPath+="../";
	 return RelativPath;
}

function SetSuccessurl(url)
{
	url = url + '?RetourUrl=' + document.location;
	window.open(url, '_self');
}

function GoSearchHint (oSelect)
{
	if (oSelect.options[oSelect.selectedIndex].value != '')
	{
		document.location = "@@WebBoxRelativePath@@/../search/results_hint.aspx?HintCode=" + oSelect.options[oSelect.selectedIndex].value;
	}
}

// String TRIM Functions

// LEFT TRIM
function leftTrim(sString) 
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	return sString;
}

// RIGHT TRIM
function rightTrim(sString) 
{
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

// FULL TRIM
function trimAll(sString) 
{
	sString = leftTrim(sString);
	sString = rightTrim(sString);
	return sString;
}



// FLASH ACTIVATION
function CreateControl(DivID, CLSID, ObjectID, WIDTH, HEIGHT, URL, FLASHVARS, AUTOSTART)
{
  var d = document.getElementById(DivID);
  var objectTag = '<object classid=' + CLSID + ' id=' + ObjectID + ' width=' + WIDTH + ' height=' + HEIGHT +' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">';
  objectTag = objectTag + '<param name="allowScriptAccess" value="sameDomain">';
  objectTag = objectTag + '<param name="movie" value=' + URL + '>'
  objectTag = objectTag + '<param name="FlashVars" value=' + FLASHVARS + '>';
  objectTag = objectTag + '<param name="quality" value="high">'  
  objectTag = objectTag + '<param name="bgcolor" value="#000000">'  
  objectTag = objectTag + '<param name="autoStart" value=' + AUTOSTART + '/>';
  objectTag = objectTag + '<embed src="' + URL + '" flashVars="' + FLASHVARS + '" quality="high" bgcolor="#000000" width="' + WIDTH + '" height="' + HEIGHT +'" name="main" align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">';
  objectTag = objectTag + "</object>";
  d.innerHTML = objectTag;
}

/*
 * Registration functions
 */
function Sethiddenloginvalue(val)
{
	var _f = document.forms[0];
	for (i=0;i<_f.elements.length;i++)
	{
		if (_f.elements[i].id.indexOf('hidden_login') != -1)
			_f.elements[i].value=val;

	}
}
