/**************************************************************************

	Javascript GENERAL functions library.
	
	Boréalis Développement Inc. 
	www.borealisdev.qc.ca
	© Copyright 1997-2007 Stéphane Lebeau
	
***************************************************************************/


/**************************************************************************/
/* Ajax 																  																*/
/**************************************************************************/
function objectXMLHTTP()
{
	var objetX;
	var navigateur = window.navigator.appName;
	
	if (navigateur == "Microsoft Internet Explorer")
	{
		objetX = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		objetX = new XMLHttpRequest();
	}
	
	return objetX;
}	


/**************************************************************************/
/* Clock and date												  																*/
/**************************************************************************/

//Date (header) ****************************************
function Datum(){
	var now = new Date();
	var jour = now.getDay();
	var day = now.getDate();
	var year = now.getFullYear();
	var month = now.getMonth();
	var temp;
	var lang = readCookie("AppLang");

	if (lang == "fr") {
		(month==0)?month="Janvier":(month==1)?month="Février":(month==2)?month="Mars":
		(month==3)?month="Avril":(month==4)?month="Mai":(month==5)?month="Juin":
		(month==6)?month="Juillet":(month==7)?month="Août":(month==8)?month="Septembre":
		(month==9)?month="Octobre":(month==10)?month="Novembre": month="Décembre";
	} else {
		(month==0)?month="January":(month==1)?month="February":(month==2)?month="March":
		(month==3)?month="April":(month==4)?month="May":(month==5)?month="June":
		(month==6)?month="July":(month==7)?month="August":(month==8)?month="September":
		(month==9)?month="October":(month==10)?month="November": month="December";	
	}
	
	if (lang == "fr") {
		(jour==0)?jour="Dim.":(jour==1)?jour="Lun.":(jour==2)?jour="Mar.":(jour==3)?jour="Mer.":
		(jour==4)?jour="Jeu.":(jour==5)?jour="Ven.": jour="Sam.";
	} else {	
		(jour==0)?jour="Sun.":(jour==1)?jour="Mon.":(jour==2)?jour="Tue.":(jour==3)?jour="Wed.":
		(jour==4)?jour="Thu.":(jour==5)?jour="Fri.": jour="Sat.";
	}
	
	if (lang == "fr") {
		if (day==1) {temp="er";} else {temp = "";}
	} else {
		(day==1)?temp="st":(day==2)?temp="nd":(day==3)?temp="rd":
		(day==21)?temp="st":(day==22)?temp="nd":(day==23)?temp="rd":
		(day==31)?temp="st":temp="th";
	}

	if (lang == "fr") {				
		var result = jour+" "+day+""+temp+" "+month+" "+year;
	} else {
		var result = jour+" "+month+" "+day+""+temp+" "+year;		
	}
	
	//document.write(result);
	window.document.getElementById("datum").innerHTML = result;
}

//Time clock (header) *********************************
function Clock() {	
	//if (!document.layers && !document.all) return;

	var runTime = new Date();
	var hours = runTime.getHours();
	var minutes = runTime.getMinutes();
	var seconds = runTime.getSeconds();
	var GMT = runTime.getTimezoneOffset();
	
	GMT = GMT / 60;
	if (GMT > 0) {GMT = "GMT -"+GMT;}
		else
			if (GMT < 0) {GMT = -GMT; GMT="GMT +"+GMT;}
				else
					{GMT = "";}

	if (hours <=9 ) {
		hours = "0" + hours;
	}

	if (minutes <= 9) {
		minutes = "0" + minutes;
	}

	if (seconds <= 9) {
		seconds = "0" + seconds;
	}

	//var movingtime = ""+ hours + ":" + minutes + ":" + seconds + " " + GMT;
	var movingtime = ""+ hours + ":" + minutes + ":" + seconds;	

	/*if (document.layers) {
		document.layers.clock.document.write(movingtime);
		document.layers.clock.document.close();
	}
	else if (document.all) {
		Clock.innerHTML = movingtime;
	}*/
	
	window.document.getElementById("clock").innerHTML = movingtime;
	
	//console.debug("Time: %s", movingtime);	

	setTimeout("Clock()", 1000)
}


/**************************************************************************/
/* Search engine												  																*/
/**************************************************************************/

//Change cell color ***********************************
function ChangeCellBG(el, myColor) {
     el.style.background =myColor;
}

//Table Highlight *************************************
var rowHighlight = true // turn on row highlights
var colHighlight = false // turn off row highlights

function getElement(el) {
	var tagList = new Object
	for (var i = 1; i < arguments.length; i++)
		tagList[arguments[i]] = true
	while ((el!=null) && (tagList[el.tagName]==null))
		el = el.parentElement
	return el
}

function checkHighlight(which) {
	var el = getElement(event.srcElement,"TH","TD")
	if (el==null) return

	if ((el.tagName=="TH") && (colHighlight)) {
		var idx = el.cellIndex
		var table = getElement(el, "TABLE")
		var column = table.all.tags("COL")[idx]

		if (which)
			column.className="ListHighlight"
		else
			column.className=""
	}

	if ((el.tagName=="TD") && (rowHighlight)) {
		var row = getElement(el, "TR")
		var table = getElement(row, "TABLE")

		if (which)
			row.className = "ListHighlight"
		else
			row.className = ""
		cache = row
	}
}


/**************************************************************************/
/* Query manipulation										  																*/
/**************************************************************************/
/*
 * This function parses comma-separated name=value 
 * argument pairs from the query string of the URL. 
 * It stores the name=value pairs in 
 * properties of an object and returns that object.
*/

function getArgs() {
    var args = new Object(  );
    var query = location.search.substring(1);     
    var pairs = query.split("&");
    for(var i = 0; i < pairs.length; i++) {
			var pos = pairs[i].indexOf('='); 						// Look for "name=value"
			if (pos == -1) continue; 										// If not found, skip
			var argname = pairs[i].substring(0,pos); 		// Extract the name
			var value = pairs[i].substring(pos+1);			// Extract the value
			args[argname] = unescape(value);						// Store as a property
    }
    return args;
}

function formatQuery(args) {
	var Result = "";
	var Temp = "";
	for (key in args) {
		if (Result != "") {Result += "&";}
		Temp = key + "=" + args[key];
		Result += Temp;
	}
	return Result;
}
