/* Global Variables {{{*/
var today; //Global variable for today's date
var language;//Global variable for the pages language
var issuedDate;//GLobal varibale to hold the current Issued Date
var daysBack = 31;//Number of days you are allowed to go into the past
var listStart = 0;//Default start of list
var listEnd = 143;//Default end of list
var sortedAbreviationArray;//Global to hold the sorted Abrev array
var sortedAbreviationArrayCAN = new Array();
var sortedAbreviationArrayMEX = new Array();
var sortedAbreviationArrayUSA = new Array();
var defaultStationIndex;
var defaultStationAbrevIndex;
var issDate, selectedHour, hourBox, endUrl, endUrlArray, baseUrl, tgrapheVal;
var tgrapheBox, theImage, currStation, statCodeBox, disableDate, incButtonBot;
var incButton, decButtonBot, decButton, provBox, optElm;
var index = 0; 
/*}}}*/

/*******************************************************************************************
	Function:	initialize()
	Date:			13 FEB 08
	Author:		Shayne Brioux
	Purpose:		The purpose of this function is to setup all the default values when the page
					is first loaded.
********************************************************************************************/
function initialize(){/*{{{*/
	disableViewButton();

	today = zeroTheHours(new Date());//todays date
	issuedDate = zeroTheHours(new Date());//Default issued date is today
	language = (document.getElementsByTagName('body'))[0].getAttribute('lang');//Get and store the pages language
	//document.getElementById('view').style.display = "none";//Hide the view button
	document.getElementById('Heure').selectedIndex = 0;//Default to 00 hours
	document.getElementById('province').selectedIndex = 0;//Default to the first province
	document.getElementById('station').selectedIndex = 85;//Default to the first station
	document.getElementById('tgraphe').selectedIndex = 0;//default to the first chart type
	document.getElementById('code_station').style.visibility = 'visible';//Unhide all station codes
	document.getElementById('code_station_label').style.visibility = 'visible';//Unhide all station code label
	//BOTTOM CONTROLS
	//document.getElementById('viewBot').style.display = "none";//Hide the view button
	document.getElementById('HeureBot').selectedIndex = 0;//Default to 00 hours
	document.getElementById('provinceBot').selectedIndex = 0;//Default to the first province
	document.getElementById('stationBot').selectedIndex = 85;//Default to the first station
	document.getElementById('tgrapheBot').selectedIndex = 0;//default to the first chart type
	document.getElementById('code_stationBot').style.visibility = 'visible';//Unhide all station codes
	document.getElementById('code_stationBot_label').style.visibility = 'visible';//Unhide all station code label
	sortedAbreviationArray= new Array(tababrev.length);//Create a temporary array to store the abrev list sorted

	//Itterate through the list of abreviations and store them in the new array. Done this was to prevent
	//the list from referencing the origional list.
   // sort code list by country 
	for(var count = listStart; count < listEnd; count++){
      sortedAbreviationArrayCAN[count] = tababrev[count];
   }
   sortedAbreviationArrayCAN.sort();
	
	for(var count = 143; count < 217; count++){
      sortedAbreviationArrayMEX[index] = tababrev[count];
      index = index + 1;
   }
   sortedAbreviationArrayMEX.sort();

   index = 0;
	for(var count = 217; count < 354; count++){
	    sortedAbreviationArrayUSA[index] = tababrev[count];
	    index = index + 1;
	}
	sortedAbreviationArrayUSA.sort();

	for(var count = 0; count < tababrev.length; count++){
		sortedAbreviationArray[count] = tababrev[count];
	}
	//sortedAbreviationArray.sort();//Sort the sortedAbreviationArray alphabetically

   for(var count = 0; count < sortedAbreviationArrayCAN.length; count++){
		 sortedAbreviationArray[count] = sortedAbreviationArrayCAN[count];
   }
   index = 143;
   for(var count = 0; count < sortedAbreviationArrayMEX.length; count++){
      sortedAbreviationArray[index] = sortedAbreviationArrayMEX[count];
      index = index + 1;
   }
   index = 217;
	for(var count = 0; count < sortedAbreviationArrayUSA.length; count++){
   	 sortedAbreviationArray[index] = sortedAbreviationArrayUSA[count]; 
		 index = index + 1;
	}

	populateStationList();//Populates the station options box
	populateStationAbrevList();//Populates the Abreviated station options box
	checkButtons();//Check the status of the buttons and disable as necessary
	registerFormEvents();//Attaches all the events to the buttons on the page
	updateImage();//Updates the image on the page
	setFormValues();//Sets default parameters for all the form elements on the page

}/*}}}*/
/**************************************************************************************
	Function:	setFormValues
	Date:			13 MAR 09
	Author:		Shayne Brioux
	Purpose:		The purpose of this function is to set the default values for the elements
					of the form
***************************************************************************************/
function setFormValues(){
	document.getElementById('station').selectedIndex = defaultStationIndex;
	document.getElementById('stationBot').selectedIndex = defaultStationIndex;
	document.getElementById('code_station').selectedIndex = defaultStationAbrevIndex;
	document.getElementById('code_stationBot').selectedIndex = defaultStationAbrevIndex;

}
/**************************************************************************************
	Function:	registerFormEvents
	Date:			13 MAR 09
	Author:		Shayne Brioux
	Purpose:		The purpose of this function is to attach event handlers to the form
					elements on the page using the traditional model.
***************************************************************************************/
function registerFormEvents(){/*{{{*/
	document.getElementById('Heure').onchange = hourChangeEvent;
	document.getElementById('HeureBot').onchange = hourChangeEvent;

	document.getElementById('province').onchange = countryChangeEvent;
	document.getElementById('provinceBot').onchange = countryChangeEvent;

	document.getElementById('station').onchange = stationChangeEvent;
	document.getElementById('stationBot').onchange = stationChangeEvent;

	document.getElementById('code_station').onchange = codeChangeEvent;
	document.getElementById('code_stationBot').onchange = codeChangeEvent;

	document.getElementById('tgraphe').onchange = graphTypeChangeEvent;
	document.getElementById('tgrapheBot').onchange = graphTypeChangeEvent;
}/*}}}*/
/**************************************************************************************
Function: 	hourChangeEvent
Date:			13 MAR 09
Author:		Shayne Brioux
Purpose:		The purpose of this function is to act as an intimediary between the two
				sets of controls now on the page.  WHen one control is changed then set the
				opposite control to the same value.
****************************************************************************************/
function hourChangeEvent(){
	var topHourBox = document.getElementById('Heure');
	var botHourBox = document.getElementById('HeureBot');

	if(this.id == 'Heure'){
		botHourBox.selectedIndex = topHourBox.selectedIndex;
	} else {
		topHourBox.selectedIndex = botHourBox.selectedIndex;
	}
	updateImage();
}
/**************************************************************************************
Function: 	countryChangeEvent
Date:			13 MAR 09
Author:		Shayne Brioux
Purpose:		The purpose of this function is to act as an intimediary between the two
				sets of controls now on the page.  WHen one control is changed then set the
				opposite control to the same value.
****************************************************************************************/
function countryChangeEvent(){
	var topProvBox = document.getElementById('province');
	var botProvBox = document.getElementById('provinceBot');
	if(this.id == 'province'){
		botProvBox.selectedIndex = topProvBox.selectedIndex;
	} else {
		topProvBox.selectedIndex = botProvBox.selectedIndex;
	}
	countryChange();
}
/**************************************************************************************
Function: 	stationChangeEvent
Date:			13 MAR 09
Author:		Shayne Brioux
Purpose:		The purpose of this function is to act as an intimediary between the two
				sets of controls now on the page.  WHen one control is changed then set the
				opposite control to the same value.
****************************************************************************************/
function stationChangeEvent(){
	var topStationBox = document.getElementById('station');
	var botStationBox = document.getElementById('stationBot');

	if(this.id == 'station'){
		botStationBox.selectedIndex = topStationBox.selectedIndex;
	} else {
		topStationBox.selectedIndex = botStationBox.selectedIndex;
	}
	stationChange();
}
/**************************************************************************************
Function: 	codeChangeEvent
Date:			13 MAR 09
Author:		Shayne Brioux
Purpose:		The purpose of this function is to act as an intimediary between the two
				sets of controls now on the page.  WHen one control is changed then set the
				opposite control to the same value.
****************************************************************************************/
function codeChangeEvent(){
	var topCodeBox = document.getElementById('code_station');
	var botCodeBox = document.getElementById('code_stationBot');

	if(this.id == 'code_station'){
		botCodeBox.selectedIndex = topCodeBox.selectedIndex;
	} else {
		topCodeBox.selectedIndex = botCodeBox.selectedIndex;
	}
	codeChange();
}
/**************************************************************************************
Function: 	graphTypeChangeEvent
Date:			13 MAR 09
Author:		Shayne Brioux
Purpose:		The purpose of this function is to act as an intimediary between the two
				sets of controls now on the page.  WHen one control is changed then set the
				opposite control to the same value.
****************************************************************************************/
function graphTypeChangeEvent(){
	var topTypeBox = document.getElementById('tgraphe');
	var botTypeBox = document.getElementById('tgrapheBot');

	if(this.id == 'tgraphe'){
		botTypeBox.selectedIndex = topTypeBox.selectedIndex;
	} else {
		topTypeBox.selectedIndex = botTypeBox.selectedIndex;
	}
	updateImage();
}
/*******************************************************************************************
Function:	issuedInc
Date:			13 FEB 08
Author:		Shayne Brioux
Purpose:		The purpose of this function is to increment the issued date
********************************************************************************************/
function issuedInc(){/*{{{*/
	issuedDate.setDate(issuedDate.getDate()+1);//Increment the current issued date	
	updateIssuedDateTag();//update the date tag on the page
	checkButtons();//Re-check status of all buttons
	updateImage();//Update the image on the page
	return false;
}/*}}}*/
/*******************************************************************************************
Function:	issuedDec
Date:			13 FEB 08
Author:		Shayne Brioux
Purpose:		The purpose of this function is to decrement the issued date by one day
********************************************************************************************/
function issuedDec(){/*{{{*/
	issuedDate.setDate(issuedDate.getDate()-1);//Decrement the current issued date one day
	updateIssuedDateTag();//Update the date tag on the page
	checkButtons();//Re-check status of all buttons
	updateImage();//Update the image on the page
	return false;
}/*}}}*/
/*******************************************************************************************
Function:	updateIssuedDateTag
Date:			13 FEB 08
Author:		Shayne Brioux
Purpose:		The purpose of this function is to update the issued date on the page
********************************************************************************************/
function updateIssuedDateTag(){/*{{{*/
	dateTag = document.getElementById('datecour');//Get a handle to the issued date
	dateTag.value = formatDate(issuedDate);//Update the date tag with formated issued date
	dateTagBot = document.getElementById('datecourBot');//Get a handle to the issued date
	dateTagBot.value = formatDate(issuedDate);//Update the date tag with formated issued date
}/*}}}*/
/*******************************************************************************************
Function:	checkButtons
Date:			13 FEB 08
Author:		Shayne Brioux
Purpose:		The purpose of this function is to disabled or enable the increment and decrement
				buttons on the page based on the issued date. 
********************************************************************************************/
function checkButtons(){/*{{{*/
	decButton = document.getElementById('back1Day');//Get a handle to the decrement button
	decButtonBot = document.getElementById('back1DayBot');//Get a handle to the decrement button
	incButton = document.getElementById('forward1Day');//Get a handle to the increment button
	incButtonBot = document.getElementById('forward1DayBot');//Get a handle to the increment button
	disableDate = zeroTheHours(new Date());//set up a disabled date with hours zero'd
	disableDate.setDate(disableDate.getDate()-daysBack);//Set the disabled date to 31 days in past
	//If the date today is the same as the issued date then disable the increment button
	if(Date.parse(today) == Date.parse(issuedDate)){
		incButton.disabled= "disabled";
		incButtonBot.disabled = "disabled";
	} else { 
		incButton.disabled = '';//Other wise enable it just incase it was prev disabled
		incButtonBot.disabled = '';
	}
	//If the issued date is less then disable the decrement button
	if(Date.parse(issuedDate) <= Date.parse(disableDate)){
		decButton.disabled = "disabled";
		decButtonBot.disabled = "disabled";
	} else {
		decButton.disabled = '';//Other wise enable it incase it was previously disabled
		decButtonBot.disabled = '';
	}
}/*}}}*/
/*******************************************************************************************
Function:	countryChange	
Date:			13 FEB 08
Author:		Shayne Brioux
Purpose:		The purpose of this function is to find out what the current selected province
				(country) is and then setup the start of the list and end of the list.
********************************************************************************************/
function countryChange(){/*{{{*/
	provBox = document.getElementById('province');//Get a handle to the province box
	provBoxBot = document.getElementById('provinceBot');//Get a handle to the province box
	provBoxVal = provBox[provBox.selectedIndex].value;//Get the selected province
	codeStatBox = document.getElementById('code_station');
	codeStatBoxBot = document.getElementById('code_stationBot');
	stationBoxTop = document.getElementById('station');
	stationBoxBot = document.getElementById('stationBot');
	if(provBoxVal == "CAN"){//If the selected province is Canada
		listStart = 0;//Set the start of the list to where canada starts in the array
		listEnd = 143;//Set the end of the list to where canada ends in the array
		defaultStationIndex = 85;
	}else if(provBoxVal == "MEX"){//If the selected province is Mexico
		listStart = 143;//Set the start of the list to where Mexico starts in the array
		listEnd = 217;//Set the end of the list to where Mexico ends in the array
		defaultStationIndex = 0;
	}else{//If the selected province is USA
		listStart = 217;//Set the start of the list to where USA starts in the array
		listEnd = 354;//Set the end of the list to where USA ends in the array
		defaultStationIndex = 0;
	}
	updateStationList();

	stationBoxTop.selectedIndex = defaultStationIndex;
	stationBoxBot.selectedIndex = defaultStationIndex;

	var index = 0;
	for(index = 0; index < codeStatBox.length; index++){
		if(stationBoxTop.value == codeStatBox.options[index].value){
			codeStatBox.selectedIndex = index;
			codeStatBoxBot.selectedIndex = index;
			index = codeStatBox.length;
		}
	}

	
	updateImage();//Update the image on the page
}/*}}}*/
/******************************************************************************************
Function:	populateStationList
Date:			13 MAR 09
Author:		Shayne Brioux
Purpose:		This function is used to put all initial values into the options box for stations
******************************************************************************************/
function populateStationList(){/*{{{*/
	var stationList = document.getElementById('station');
	while(stationList.hasChildNodes()){
		stationList.removeChild(stationList.childNodes[0]);
	}
	var stationListBot = document.getElementById('stationBot');
	while(stationListBot.hasChildNodes()){
		stationListBot.removeChild(stationListBot.childNodes[0]);
	}
	for(var i = listStart; i < listEnd; i++){
		optElm = document.createElement("option");
		optElm.value = tababrev[i];
		optElm.innerHTML = tabstat[i];
		stationList.appendChild(optElm);
	}
	for(var i = listStart; i < listEnd; i++){
		optElm = document.createElement("option");
		optElm.value = tababrev[i];
		optElm.innerHTML = tabstat[i];
		stationListBot.appendChild(optElm);
	}
	provBox = document.getElementById('province');
	var defStation = 0;
	if(provBox.value == "CAN"){
		defaultStationIndex = 85;//85 for Ottawa
	}
	stationList.selectedIndex = defaultStationIndex;
	stationListBot.selectedIndex = defaultStationIndex;
}/*}}}*/
/*******************************************************************************************
Function:	stationChange
Date:			13 FEB 08
Author:		Shayne Brioux
Purpose:		The purpose of this function is to setup which station is the currently selected
				station.
********************************************************************************************/
function stationChange(){/*{{{*/
	stationList = document.getElementById('station');//get a handle to the station box
	selectedStation = stationList[stationList.selectedIndex].value;
	codeList = document.getElementById('code_station');
	codeListBot = document.getElementById('code_stationBot');
	index = 0;
	for(i = 0; i < sortedAbreviationArray.length; i++){
		if(sortedAbreviationArray[i] == selectedStation){
			index = i;
			codeList.selectedIndex = index;
			codeListBot.selectedIndex = index;
			i = sortedAbreviationArray.length;
		}
	}
	updateImage();//Update the image on the page
}/*}}}*/
/*******************************************************************************************
Function:	codeChange
Date:			13 FEB 08
Author:		Shayne Brioux
Purpose:		The purpose of this function is to change the country and station boxes based
				on the users newly selected station code.
********************************************************************************************/
function codeChange(){/*{{{*/
	countryList = document.getElementById('province');
	countryListBot = document.getElementById('provinceBot');
	selectedCountry = countryList[countryList.selectedIndex].value;
	codeList = document.getElementById('code_station');
	selectedCode = codeList[codeList.selectedIndex].value;
	var selectedCodesCountry;
	for(i = 0; i < tababrev.length;i++){
		if(tababrev[i] == (selectedCode)){
			selectedCodesCountry = tabprov[i];
		}
	}
	if(selectedCountry != selectedCodesCountry){
		if(selectedCodesCountry == "CAN "){
			listStart = 0;
			listEnd = 143;
			countryList.selectedIndex = 0;
			countryListBot.selectedIndex = 0;
		} else if(selectedCodesCountry == "MEX "){
			listStart = 143;
			listEnd = 217;
			countryList.selectedIndex = 1;
			countryListBot.selectedIndex = 1;
		} else if (selectedCodesCountry == "USA "){
			listStart = 217;
			listEnd = 354;
			countryList.selectedIndex = 2;
			countryListBot.selectedIndex = 2;
		}
		updateStationList();
	}

	stationList = document.getElementById('station');
	stationListBot = document.getElementById('stationBot');
	var temp = 0;
	for(i = 0; i < stationList.length; i++){
		if(stationList.options[i].value == selectedCode){
			temp = i;
		}
	}
	stationList.selectedIndex = temp;
	stationListBot.selectedIndex = temp;
	updateImage();
}/*}}}*/
/*******************************************************************************************
Function:	updateStationList
Date:			13 FEB 08
Author:		Shayne Brioux
Purpose:		The purpose of this function is to update the current station list based upon
				the selected province (country).
********************************************************************************************/
function updateStationList(){/*{{{*/
	var selIndex = 0;
	var statList = document.getElementById('station');//Get a handle to the station box
	while(statList.hasChildNodes()){//While the list has options
		statList.removeChild(statList.childNodes[0]);//remove them so no duplicates are created
	}
	var statListBot = document.getElementById('stationBot');//Get a handle to the bottom station box
	while(statListBot.hasChildNodes()){//While the list has options
		statListBot.removeChild(statListBot.childNodes[0]);//Remove them so no duplicates are created
	}
	codeStatList = document.getElementById('code_station');//Get a handle to the station code box
	selectStat = codeStatList[codeStatList.selectedIndex].value;//get the currently selected station code
	//Itterate through the array of station codes
	for(var i = listStart; i < listEnd; i++){
		var optElm = document.createElement("option");//Create a new option element
		var optElm2 = document.createElement("option");//Create a new option element
		optElm.value = tababrev[i];//Set the value of the new option to the station code
		optElm2.value = tababrev[i];//Set the value of the new option to the station code
		//If the current abreviation is the same as the selected station code then set that to selected
		if(tababrev[i] == selectStat) selIndex= i-listStart;
		optElm.innerHTML = tabstat[i];//fill the text into the option box
		optElm2.innerHTML = tabstat[i];//fill the text into the option box
		statList.appendChild(optElm);//add the newly created option to the select box
		statListBot.appendChild(optElm2);//add the newly created option to the select box
	}
}/*}}}*/
/*******************************************************************************************
Function:	populateStationAbrevList
Date:			13 FEB 08
Author:		Shayne Brioux
Purpose:		The purpose of this function is to update the current station code list based upon
				the currently selected station
********************************************************************************************/
function populateStationAbrevList(){/*{{{*/
	var selIndicy;
	var codeStationList = document.getElementById('code_station');//Get a handle to the station code box
	var codeStationListBot = document.getElementById('code_stationBot');//Get a handle to the station code box
	var statList = document.getElementById('station');//Get a handle to the station box
	var selectedStation = statList[statList.selectedIndex].value;//Get the currently selected station

	while(codeStationList.hasChildNodes()){//While the station codes list has options
		codeStationList.removeChild(codeStationList.childNodes[0]);//Remove them so no duplicates are created
	}
	while(codeStationListBot.hasChildNodes()){
		codeStationListBot.removeChild(codeStationListBot.childNodes[0]);
	}
	//Itterate through the sortedAbreviationArray 
	for(var i = 0; i < tababrev.length; i++){
      if (i == 0) {
			var optG = document.createElement("optgroup");
		   optG.label = "Canada";
		   codeStationList.appendChild(optG);
		} else if (i == 143) {
		   var optG = document.createElement("optgroup");     
			if (language == "en") {
		       optG.label = "Mexico";
		   } else {
		       optG.label = "Mexique";
		   }
		   codeStationList.appendChild(optG);
	   } else if (i == 217) {
	      var optG = document.createElement("optgroup");    
			if (language == "en") {
			    optG.label = "USA";  
			} else {
			    optG.label = "États-Unis";
			}
		   codeStationList.appendChild(optG);   
		}
		
		optElm = document.createElement("option");//Create a new option element
		optElm.value = sortedAbreviationArray[i];//Set the value of the new element to the station code
		optElm.innerHTML = sortedAbreviationArray[i];//fill in the text into the option box
		optG.appendChild(optElm);//Add the newly created option to the select box
		//If the current value is the same as the selected station then we set that to selected
		if(optElm.value == selectedStation){
			selIndicy = i;
			optElm.selected = "selected";
		}
	}
	//Itterate through the sortedAbreviationArray
	for(var i = 0; i < tababrev.length; i++){
		if (i == 0) {
		    var optG = document.createElement("optgroup");
		    optG.label = "Canada";
		    codeStationListBot.appendChild(optG);
		} else if (i == 143) {
		    var optG = document.createElement("optgroup");
		    if (language == "en") {
		       optG.label = "Mexico";     
			 } else {
			    optG.label = "Mexique";          
			 }
	       codeStationListBot.appendChild(optG);  
		} else if (i == 217) {
			 var optG = document.createElement("optgroup");
			 if (language == "en") {
			    optG.label = "USA";
			 } else {
		       optG.label = "États-Unis";    
			 }
		    codeStationListBot.appendChild(optG);  
		}

		optElm = document.createElement("option");//Create a new option element
		optElm.value = sortedAbreviationArray[i];//Set the value of the new element to the station code
		optElm.innerHTML = sortedAbreviationArray[i];//fill in the text into the option box
		optG.appendChild(optElm);
		if(optElm.value == selectedStation){
			selIndicy = i;
			optElm.selected = "selected";
		}
	}
	defaultStationAbrevIndex = selIndicy;
}/*}}}*/
/*******************************************************************************************
Function:	updateImage
Date:			13 FEB 08
Author:		Shayne Brioux
Purpose:		The purpose of this function is to update the image on the page based on the 
				currently selected parameters
********************************************************************************************/
function updateImage(){/*{{{*/
	statCodeBox = document.getElementById('station');//Get handle to the station box
	currStation = statCodeBox[statCodeBox.selectedIndex].value;//Get the currently selected station
	theImage = document.getElementById('graphiques');//Get a handle to the main image
	tgrapheBox = document.getElementById('tgraphe');//Get a handle to the graph type box
	tgrapheVal = tgrapheBox[tgrapheBox.selectedIndex].value;//get the selected graph type
	if(tgrapheVal == 0) tgrapheVal = '';//If it is the first graph type we set the val to blank
	else tgrapheVal++;//Other wise we increment the val one
	//store the common part of the url
	baseUrl = 'http://collaboration.cmc.ec.gc.ca/cmc/ensemble/data2/combine/images' + tgrapheVal + '/';
	endUrlArray = new Array(3);//Setup an array to store the three possible url endings
	endUrlArray[0] = '_I_NAEFS@EPSGRAMS_tt@surf@nt@pr@ws@surf_360.png';
	endUrlArray[1] = '_I_NAEFS@EPSGRAMS_ht@gz@500@ws@200@pn_360.png';
	endUrlArray[2] = '_I_NAEFS@EPSGRAMS_dz1000@500_360.png';
	//get the proper url ending based on the selected chart type
	endUrl = endUrlArray[tgrapheBox[tgrapheBox.selectedIndex].value];
	hourBox = document.getElementById('Heure');//Get a handle to the hour box
	selectedHour = hourBox[hourBox.selectedIndex].value;//Get the selected hour
	issDate = (document.getElementById('datecour').value).replace(/-/g,"");//Get the date and remove the dashes
	theImage.style.display = "block";//Display the image if previously hidden
	document.getElementById('errMessHolder').style.display = 'none';//Hide the error message
	//Build the correct url based on prev variables and then update the img tag
	theImage.src = baseUrl + issDate + selectedHour + "_054@007_E1_" + (currStation.replace(/ /g,"")).toLowerCase() + endUrl;
	theImage.onerror = noImage;//Setup the error handler if there is no image

}/*}}}*/
/*******************************************************************************************
Function:	noImage
Date:			13 FEB 08
Author:		Shayne Brioux
Purpose:		The purpose of this function is to hide the image and output the appropriate
				error message based on language should the image fail to load.  This function
				is called by the onerror of the img tag.
********************************************************************************************/
function noImage(){/*{{{*/
	this.style.display = 'none';//Hide the image
	errMessTag = document.getElementById('errMessHolder');//Get a handle to the error message tag
	errMessTag.style.display = "block";//Display the error message tag
	if(language == "en"){//If the current language is english
		errMessTag.innerHTML = "No Image Available";//Display the english message
	} else {
		errMessTag.innerHTML = "Image non disponible";//Display the french error message.
	}
}/*}}}*/
/*******************************************************************************************
Function:	formatDate
Date:			13 FEB 08
Author:		Shayne Brioux
Variables:	date - the date you want to format to XXXX-XX-XX format
Purpose:		The purpose of this function is to take the date variable and return a date
				formatted to the XXXX-XX-XX format.
********************************************************************************************/
function formatDate(date){/*{{{*/
	inday = date.getDate();//Extract the passed day
	inmonth = date.getMonth()+1;//Extract the passed month
	inyear = date.getFullYear();//Extract the passed year
	if(inday < 10) inday = "0" + inday;//If the day is less then 10 add a leading zero
	if(inmonth < 10) inmonth = "0" + inmonth;//If the month is less then 10 add a leading zero
	return inyear + "-" + inmonth + "-" + inday;//Return the formatted date
}/*}}}*/
/*******************************************************************************************
Function:	zeroTheHours
Date:			13 FEB 08
Author:		Shayne Brioux
Variables:	date - the date object that requires the hours and such to be defaulted to 0
Purpose:		The purpose of this function is to take the passed date object and clear the hour
				seconds, milliseconds and minutes. The purpose of this is for easier comparison
				of dates in other parts of the project.
********************************************************************************************/
function zeroTheHours(date){/*{{{*/
	date.setHours(0);//Set the dates hours to 0
	date.setMinutes(0);//Set the dates minutes to 0
	date.setSeconds(0);//Set the dates seconds to 0
	date.setMilliseconds(0);//set the dates milliseconds to 0
	return date;//Return the new date
}/*}}}*/

