Date.prototype.Months = ["January", "February", "March", 
                         "April", "May", "June", "July", 
                         "August", "September", "October", 
                         "November", "December"];
Date.prototype.Days = ["Sunday", "Monday", "Tuesday", 
                       "Wednesday", "Thursday", 
                       "Friday", "Saturday"];
Date.prototype.format = dateFormat;

function dateFormat(format) {
   var dateString = format;

  //yyyy  is a 4-digit year - i.e., 2002  
   dateString = dateString.replace( new RegExp("yyyy", "g"), this.getYear() );
   
  //yy    is a 2-digit year - i.e., 02
   var yy = new String( this.getYear() ).substring(2,4);
   if (yy.length == 1) yy = "0" + yy;//pad if single digit
   dateString = dateString.replace( new RegExp("yy", "g"), yy );
   
  //MMMM is the full month - i.e., September
   dateString = dateString.replace( new RegExp("MMMM", "g"), this.Months[this.getMonth()] );
   
  //MMM   is the first three letters of the month - i.e., Sep
   dateString = dateString.replace( new RegExp("MMM", "g"), new String( this.Months[this.getMonth()] ).substring(0,3) );
   
  //MM   is the number of the month - i.e., 9
   var MM = new String(this.getMonth()+1);
   if (MM.length == 1) MM = "0" + MM;//pad if single digit
   dateString = dateString.replace( new RegExp("MM", "g"), MM ); 
     
  //HH    is hours - i.e., 3
   var HH = new String( this.getHours() );
   if (HH.length == 1) HH = "0" + HH;//pad if single digit
   dateString = dateString.replace( new RegExp("HH", "g"), HH );
   
  //mm    is minutes (always 2-digit) - i.e., 05
   var mm = new String( this.getMinutes() );
   if (mm.length == 1) mm = "0" + mm;//pad if single digit
   dateString = dateString.replace( new RegExp("mm", "g"), mm );
   
  //ss    is seconds (always 2-digit) - i.e., 08
   var ss = new String( this.getSeconds() );
   if (ss.length == 1) ss = "0" + ss;//pad if single digit
   dateString = dateString.replace( new RegExp("ss", "g"), ss );
   
  //EEE   is the first three letters of the day - i.e., Wed
   dateString = dateString.replace( new RegExp("EEE", "g"), new String( this.Days[this.getDay()] ).substring(0,3) );
   
  //dd    is the numerical day of the month - i.e, 25
   var dd = new String( this.getDate() );
   if (dd.length == 1) dd = "0" + dd;//pad if single digit
   dateString = dateString.replace( new RegExp("dd", "g"), dd );
   
  //EEEE   is the full day of the week - i.e., Wednesday
   dateString = dateString.replace( new RegExp("EEEE", "g"), this.Days[this.getDay()] );

  //timezone is the the timezone in hours from GMT - i.e., GMT+5
   tz = this.getTimezoneOffset();
   timezone = "";
   if (tz < 0)
      timezone = "GMT-" +  tz / 60;
   else if (tz == 0)
      timezone = "GMT";
   else
      timezone = "GMT+" + tz / 60;
   dateString = dateString.replace( new RegExp("timezone", "g"), timezone );
   
  //time24   is the time based on a 24 hour clock - i.e., 18:24   
   var minutes = new String( this.getMinutes() );
   if (minutes.length == 1) minutes = "0" + minutes;//pad if single digit
   var time24 = new String( this.getHours() + ":" + minutes );
   dateString = dateString.replace( new RegExp("time24", "g"), time24 );
   
  //time     is the time based on am/pm - i.e., 6:24PM
   var time;
   var ampm;
   var hour = this.getHours();
   if ( hour < 12) {
      if (hour == 0) hour = 12;
         ampm = "AM"
   } else {
      if (hour !=12)
         hour = hour - 12;
      ampm = "PM";   
   }
   time = new String(hour + ":" + minutes + ampm);     
   dateString = dateString.replace( new RegExp("time", "g"), time );

   return dateString;   
}

function parseDate(dateAsString,timeAsString,dateFormat,timeFormat) {
	var newYear = dateAsString.substring(dateFormat.indexOf("yyyy"),dateFormat.indexOf("yyyy")+4);
	var newMonth = dateAsString.substring(dateFormat.indexOf("MM"),dateFormat.indexOf("MM")+2)-1;
	var newDay = dateAsString.substring(dateFormat.indexOf("dd"),dateFormat.indexOf("dd")+2);
	var newHour = timeAsString.substring(timeFormat.indexOf("HH"),timeFormat.indexOf("HH")+2);
	var newMinutes = timeAsString.substring(timeFormat.indexOf("mm"),timeFormat.indexOf("mm")+2);
	return (new Date(newYear,newMonth,newDay,newHour, newMinutes,0,0));
}

function kmToMiles(km)
{
	miles = km/1.6093;
	miles = miles*1000;
	miles = Math.round(miles);
	miles = miles/1000;
	return miles;
}
	
function milesToKm(miles)
{
	km = miles*1.6093;
	km = km*1000;
	km = Math.round(km);
	km = km/1000;
	return km;
}	

function doNothing()
{
}

if (typeof((new Array()).push) == "undefined") {
 function push() {
     for (var i = 0 ; i < arguments.length ; i++) {
         this[this.length] = arguments[i];
        }
    } Array.prototype.push = push;
}
function confirmDelete(url,message)
{
	if(!message) message='Please confirm!';

	if(confirm(message))
	{
		document.location.href=url;
	}
}
function openWindow(url,windowName,width,height)
{
	if(typeof(windowName)=='undefined')
	{
		windowName='popup';
	}
	if(typeof(height)=='undefined')
	{
		height=400;
	}
	if(typeof(width)=='undefined')
	{
		width=600;
	}
	window.open(url,windowName,'height=' + height + ',width=' + width + ', menubar=no, scrollbars=yes, status=no, toolbar=no, resizable=yes, location=no');
}

function getObj(id)
{
	if (parseInt(navigator.appVersion)>3) {
	 	if (navigator.appName=="Netscape") {
	  		return document.getElementById(id);
	 	}
	 	if (navigator.appName.indexOf("Microsoft")!=-1) {
	  		return eval('document.all.'+id);
	 	}
	}
}

// Forms list sort functions

function upperCaseWithoutAccents(value) {
	var lowValue = value.toLowerCase();
	
	var minus = "aàâäbcçdeéèêëfghiîïjklmnoôöpqrstuùûvwxyz";
	var majus = "AAAABCCDEEEEEFGHIIIJKLMNOOOPQRSTUUUVWXYZ";
	var sortie = "";
	for (var i = 0 ; i < value.length ; i++) {
		var car = lowValue.substr(i, 1);
		sortie += (minus.indexOf(car) != -1) ? majus.substr(minus.indexOf(car), 1) : car;
	}
	return sortie;
} 

function compareText(opt1, opt2) {
	var majOpt1 = upperCaseWithoutAccents(opt1.text);
	var majOpt2 = upperCaseWithoutAccents(opt2.text);
	return majOpt1 < majOpt2 ? -1 : majOpt1 > majOpt2 ? 1 : 0;
}

function sortListBox(pListBox) {
	var options = new Array (pListBox.options.length);
	for (var i = 0; i < options.length; i++) {
		options[i] = new Option (pListBox.options[i].text, pListBox.options[i].value, pListBox.options[i].defaultSelected, pListBox.options[i].selected);
	}
	
	options.sort(compareText);
	pListBox.options.length = 0;

	for (var i = 0; i < options.length; i++) {
		pListBox.options[i] = options[i];
	}
}

function sortListBoxesByName(pListBoxName) {
	var listBoxes = document.getElementsByName(pListBoxName);
	for(i = 0; i < listBoxes.length; i++) {
		sortListBox(listBoxes[i]);
	}
}

function sortListBoxesStartingWith(pListBoxNamePrefix) {
	var lists = document.getElementsByTagName('select');
	for(i=0 ; i < lists.length ; i++){
		var list = lists[i];
		if(list.name.startsWith(pListBoxNamePrefix)) {
			sortListBox(list);
		}
	}
}

function sortFormListBoxes(formName) {
	var lists = document.getElementsByTagName('select');
	for(i=0 ; i < lists.length ; i++){
		var list = lists[i];
		if(list.form.name == formName) {
			sortListBox(list);
		}
	}
}

function isFF()
{
	return (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent));
}

function isIE()
{
	return (/MSIE (\d+\.\d+);/.test(navigator.userAgent));
}