//Validate browser
if (document.layers) 
{
	//NN4
	document.location = "Unsupported.aspx";
}
if (!document.all && !document.getElementById)
{
	//Older browsers
	document.location = "Unsupported.aspx";
}

function changeLang(act_lang_id)
{
	var rx = /lang_id=\w/i;
	var lang_id = (act_lang_id=="F") ? "E" : "F";
	var new_loc = ""+document.location.href;
	new_loc = new_loc.replace(rx,"lang_id="+lang_id);
	//for case where no param was found
	if ( new_loc.indexOf('?') < 0 )
	{
		new_loc += '?lang_id=' + lang_id;
	}
	document.location = new_loc;
}

// ***********************************************************
// rollover functions
var img_over = null;
function f_over(href)
{
	var rx = /_off\./i;
	var id = get_id(href);
	if(id!=0)
	{
		var img_arrow = document.images["img_arrow_"+id];
		if(img_arrow && rx.test(img_arrow.src))
		{
			img_over = img_arrow;
			img_arrow.src = img_arrow.src.replace(rx, "_on.");
		}
	}
}
function f_out()
{
	var rx = /_on\./i;
	if(img_over!=null)
	{
		if(rx.test(img_over.src))
		{
			img_over.src = img_over.src.replace(rx, "_off.");
			img_over = null;
		}
	}
}
function f_img_over(img_href)
{
	var rx = /_off\./i;
	var id = get_id(img_href);
	if(id!=0)
	{
		var img_arrow = document.images["img_arrow_"+id];
		if(img_arrow && rx.test(img_arrow.src))
		{
			img_over = img_arrow;
			img_arrow.src = img_arrow.src.replace(rx, "_on.");
		}
	}
}
function get_id(el)
{
	var rx = /[^\d]+/;
	var id = el.id.replace(rx,"");
	return((id=="") ? 0 : id);
}
// end rollover functions
// ***********************************************************


/************************************************************

************************************************************/
function changeImageSelector(intN)
{
	if ( ! document.getElementById ) return null;
	var ul = document.getElementById('imageSelector');
	var arrLi = ul.getElementsByTagName("li");
	for (i=0; i<arrLi.length; i++)
	{
		if (intN == i)
		{
			if (arrLi[i].className)
			{
				arrLi[i].className = "True";
			}
			else
			{
				arrLi[i].setAttribute("class", "True");
			}
		}
		else 
		{
			if(arrLi[i].className)
			{
				arrLi[i].className = "False";
			}
			else
			{
				arrLi[i].setAttribute("class", "False");
			}
		}
	}
}



/************************************************************
Swap images in client Page
************************************************************/
function presentImage(strMediaName, idImageToChange)
{
	if (document.layers) return null;
	temp = new Image();
	temp.src = 'media/' + strMediaName;
	document.getElementById(idImageToChange).removeAttribute("style", true);
	document.getElementById(idImageToChange).removeAttribute("height", true);
	document.getElementById(idImageToChange).removeAttribute("width", true);
	document.getElementById(idImageToChange).src = temp.src;	
}


/****************************************************************************
Called on Page Unload Event
****************************************************************************/
function unload()
{
	/*
	if (typeof(getActiveStyleSheet) == "function" && typeof(createCookie) == "function")
	{
		var title = getActiveStyleSheet();
		createCookie("style", title, 365);
	}
	*/
}

function disableButton(btn)
{
	btn.disabled='true';
}


/****************************************************************************
Called on Page Load Event
****************************************************************************/
function main()
{
	if (typeof(readCookie) == "function" && typeof(getPreferredStyleSheet) == "function" && typeof(readCookie) == "setActiveStyleSheet")
	{
		var cookie = readCookie("style");
		var title = cookie ? cookie : getPreferredStyleSheet();
		setActiveStyleSheet(title);
	}
  
	if (typeof(setAutoFocus) == "function")
	{
		setAutoFocus();
	}
		
	if (typeof(createButtonsEvents) == "function" && document.images)
	{
		createButtonsEvents();
	}
	
	//process onload stack
	for (i=0; i<arrOnLoad.length; i++)
	{
		//debug
		//alert(arrOnLoad[i]);
		eval(arrOnLoad[i]);
	}
  
}

/****************************************************************************
Handle window object Events
****************************************************************************/
window.onload = main;
window.onunload = unload;
var arrOnLoad = new Array();

// Search functions
function TrimString(str) 
{
  str = str.replace( /^\s+/g, "" );// strip leading
  return str.replace( /\s+$/g, "" );// strip trailing
}

function RunSearch(terms, nav_id, lang_id)
{		
	terms = TrimString(terms);
	terms = terms.replace(/\s\s/gi," ");

	if (terms.length > 0)
	{
		terms = terms.replace(/>/gi, '');
		terms = terms.replace(/</gi, '');
		terms = terms.replace(/&/gi, '');
		terms = terms.replace(/#/gi, '');
		terms = terms.replace(/=/gi, '');
		terms = terms.replace(/\\/gi, '');
		terms = terms.replace(/\//gi, '');
		terms = terms.replace(/\`/gi, '');
		terms = terms.replace(/[ ][ ]+/gi, ' ');
		document.location = 'Default.aspx?nav_id=' + nav_id + "&lang_id=" + lang_id + "&terms=" + terms;
	}
	else
	{
		if (lang_id == 'F')
			alert('Veuillez entrer un mot cl\xE9 ? ')
		else
			alert('Please, enter a keyword?')
	}
}

function show(layer)
{
	document.getElementById(layer).style.visibility = "visible";
}

function hide(layer)
{
	document.getElementById(layer).style.visibility = "hidden";
}

function rl(img_name)
{
	var rx = /_off\./i;
	document.images[img_name].src = document.images[img_name].src.replace(rx,"_on.");
}
function rv(img_name)
{
	var rx = /_on\./i;
	document.images[img_name].src = document.images[img_name].src.replace(rx,"_off.");
}
