/********************************************
 *** Villa Louise website and booking system ***
 ** Written by Ian Collier, Autumn/Winter 2008 **
 ******** This work copyright Ian Collier ********
 *** Please do not copy or modified this work ***
 ** without seeking the express permission of **
 ** the author beforehand.  Thank you *********
 ********************************************/
function changeweather (clickedtab,isnight,updatedtext,humiditytext,pressuretext,windchilltext,windtext,description,humidity,pressure,windchill,windspeed,winddirection,high1,high2,high3,high4,high5,symbol1,symbol2,symbol3,symbol4,symbol5,low1,low2,low3,low4,low5,day1,day2,day3,day4,day5,lastupdated) {
	// changes the weather widget according to the clicked tab
	// detect browser
	var isie=(navigator.appName=="Microsoft Internet Explorer");
	// set nighttime variable according to whether is is night (isnight=0) or day (isnight=1)
	var nighttime=(isnight==0); 
	//set variables for the document elements
	var fivedaytab=document.getElementById("fivedaytab");
	var fivedaytabtext=document.getElementById("fivedaytext");
	var currenttab=document.getElementById("currenttab");
	var currenttabtext=document.getElementById("currenttext");
	var winfo=document.getElementById("weatherinfo");
	// don't change if the current selected tab is active
	if((clickedtab==0 && fivedaytab.className!="activetab" && fivedaytab.className!="activetabnight") || (clickedtab==1 && currenttab.className!="activetab" && currenttab.className!="activetabnight")) {
		if((fivedaytab.className=="activetab") || (fivedaytab.className=="activetabnight")) {		
			if(clickedtab==0) {
				// tab 0 contains the five day weather forecast
				if(nighttime) {
					// change the tabs - use night colours
					fivedaytab.className="nonactivetabnight";
					fivedaytabtext.className="nonactivetabtext";
					currenttab.className="activetabnight";	
					currenttabtext.className="activetabtext";
				}
				else {
					// change the tabs - use night colours
					fivedaytab.className="nonactivetab";
					fivedaytabtext.className="nonactivetabtext";
					currenttab.className="activetab";	
					currenttabtext.className="activetabtext";
				}
			}
			else {
				// tab 1 contains the current conditions
				if(nighttime) {
					// change the tabs - use night colors
					currenttab.className="activetabnight";
					currenttabtext.className="activetabtext";
					fivedaytab.className="nonactivetabnight";
					fivedaytabtext.className="nonactivetabtext";
				}
				else {
					// change the tabs - use night colors
					currenttab.className="activetab";
					currenttabtext.className="activetabtext";
					fivedaytab.className="nonactivetab";
					fivedaytabtext.className="nonactivetabtext";
				}
			}
		}
		else {
			if(clickedtab==0) {
				// tab 0 contains the five day weather forecast
				if(nighttime) {
					// change the tabs - use night colours
					fivedaytab.className="activetabnight";
					fivedaytabtext.className="activetabtext";
					currenttab.className="nonactivetabnight";	
					currenttabtext.className="nonactivetabtext";
				}
				else {
					// change the tabs - use night colours
					fivedaytab.className="activetab";
					fivedaytabtext.className="activetabtext";
					currenttab.className="nonactivetab";	
					currenttabtext.className="nonactivetabtext";
				}
			}
			else {
				// tab 1 contains the current conditions
				if(nighttime) {
					// change the tabs - use night colors
					currenttab.className="nonactivetabnight";
					currenttabtext.className="nonactivetabtext";
					fivedaytab.className="activetabnight";
					fivedaytabtext.className="activetabtext";
				}
				else {
					// change the tabs - use night colors
					currenttab.className="nonactivetab";
					currenttabtext.className="nonactivetabtext";
					fivedaytab.className="activetab";
					fivedaytabtext.className="activetabtext";
				}
			}	
		}
		// display the appropriate weather information
		// remove existing cells
		while (winfo.hasChildNodes()) {
			winfo.removeChild(winfo.lastChild);
		}
		// substitute NA in day 1
		if(high1=="N/A") {
			var high1temp="N/A";
		}
		else {
			var high1temp=high1+"&deg;C";
		}
		// initialize variables
		var para=null;
		var newcell=null;
		// if tab 0 is the active tab then display the five day forecast
		// display the current conditions otherwise
		if(clickedtab==0) {
			// check browser
			if(isie) {
				// day 1
				// create a paragraph element
				if(nighttime) {
					para=document.createElement('<p class="weather" id="day1" style="color : #FFFFFF">');
				}
				else {
					para=document.createElement('<p class="weather" id="day1">');
				}
				// create a cell element and add it the table
				// create a new cell
				newcell=document.createElement('<td style="width : 20%;">');
				// add paragraph
				newcell.appendChild(para);
				// add the cell
				winfo.appendChild(newcell);
				// set text
				document.getElementById("day1").innerHTML=day1+'<br /><br />'+high1temp+'<br /><img class="weathericon" src="http://villalouisepalmisland.com/commonfiles/weather/symbols/normal/'+symbol1+'" title="" /><br />'+low1+'&deg;C';
				// day 2
				// create a paragraph element
				if(nighttime) {
					para=document.createElement('<p class="weather" id="day2" style="color : #FFFFFF">');
				}
				else {
					para=document.createElement('<p class="weather" id="day2">');
				}
				// create a cell element and add it the table
				// create a new cell
				newcell=document.createElement('<td style="width : 20%;">');
				// add paragraph
				newcell.appendChild(para);
				// add the cell
				winfo.appendChild(newcell);
				// set text
				document.getElementById("day2").innerHTML=day2+'<br /><br />'+high2+'&deg;C<br /><img class="weathericon" src="http://villalouisepalmisland.com/commonfiles/weather/symbols/normal/'+symbol2+'" title="" /><br />'+low2+'&deg;C';		
				// day 3
				// create a paragraph element
				if(nighttime) {
					para=document.createElement('<p class="weather" id="day3" style="color : #FFFFFF">');
				}
				else {
					para=document.createElement('<p class="weather" id="day3">');
				}
				// create a cell element and add it the table
				// create a new cell
				newcell=document.createElement('<td style="width : 20%;">');
				// add paragraph
				newcell.appendChild(para);
				// add the cell
				winfo.appendChild(newcell);
				// set text
				document.getElementById("day3").innerHTML=day3+'<br /><br />'+high3+'&deg;C<br /><img class="weathericon" src="http://villalouisepalmisland.com/commonfiles/weather/symbols/normal/'+symbol3+'" title="" /><br />'+low3+'&deg;C';
				// day 4
				// create a paragraph element
				if(nighttime) {
					para=document.createElement('<p class="weather" id="day4" style="color : #FFFFFF">');
				}
				else {
					para=document.createElement('<p class="weather" id="day4">');
				}
				// create a cell element and add it the table
				// create a new cell
				newcell=document.createElement('<td style="width : 20%;">');
				// add paragraph
				newcell.appendChild(para);
				// add the cell
				winfo.appendChild(newcell);
				// set text
				document.getElementById("day4").innerHTML=day4+'<br /><br />'+high4+'&deg;C<br /><img class="weathericon" src="http://villalouisepalmisland.com/commonfiles/weather/symbols/normal/'+symbol4+'" title="" /><br />'+low4+'&deg;C';
				// day 5
				// create a paragraph element
				if(nighttime) {
					para=document.createElement('<p class="weather" id="day5" style="color : #FFFFFF">');
				}
				else {
					para=document.createElement('<p class="weather" id="day5">');
				}
				// create a cell element and add it the table
				// create a new cell
				newcell=document.createElement('<td style="width : 20%;">');
				// add paragraph
				newcell.appendChild(para);
				// add the cell
				winfo.appendChild(newcell);
				// set text
				document.getElementById("day5").innerHTML=day5+'<br /><br />'+high5+'&deg;C<br /><img class="weathericon" src="http://villalouisepalmisland.com/commonfiles/weather/symbols/normal/'+symbol5+'" title="" /><br />'+low5+'&deg;C';
			}
			else {
				if(nighttime) {
					winfo.innerHTML='<td style="width : 20%;"><p class="weather" id="day1" style="color : #FFFFFF;">'+day1+'<br /><br />'+high1temp+'<br /><img class="weathericon" src="http://villalouisepalmisland.com/commonfiles/weather/symbols/normal/'+symbol1+'" title="" /><br />'+low1+'&deg;C</p></td><td style="width : 20%;"><p class="weather" id="day2" style="color : #FFFFFF;">'+day2+'<br /><br />'+high2+'&deg;C<br /><img class="weathericon" src="http://villalouisepalmisland.com/commonfiles/weather/symbols/normal/'+symbol2+'" title="" /><br />'+low2+'&deg;C</p></td><td style="width : 20%;"><p class="weather" id="day3" style="color : #FFFFFF;">'+day3+'<br /><br />'+high3+'&deg;C<br /><img class="weathericon" src="http://villalouisepalmisland.com/commonfiles/weather/symbols/normal/'+symbol3+'" title="" /><br />'+low3+'&deg;C</p></td><td style="width : 20%;"><p class="weather" id="day4" style="color : #FFFFFF;">'+day4+'<br /><br />'+high4+'&deg;C<br /><img class="weathericon" src="http://villalouisepalmisland.com/commonfiles/weather/symbols/normal/'+symbol4+'" title="" /><br />'+low4+'&deg;C</p></td><td style="width : 20%;"><p class="weather" id="day5" style="color : #FFFFFF;">'+day5+'<br /><br />'+high5+'&deg;C<br /><img class="weathericon" src="http://villalouisepalmisland.com/commonfiles/weather/symbols/normal/'+symbol5+'" title="" /><br />'+low5+'&deg;C</p></td>';
				}
				else {				
					winfo.innerHTML='<td style="width : 20%;"><p class="weather" id="day1">'+day1+'<br /><br />'+high1temp+'<br /><img class="weathericon" src="http://villalouisepalmisland.com/commonfiles/weather/symbols/normal/'+symbol1+'" title="" /><br />'+low1+'&deg;C</p></td><td style="width : 20%;"><p class="weather" id="day2">'+day2+'<br /><br />'+high2+'&deg;C<br /><img class="weathericon" src="http://villalouisepalmisland.com/commonfiles/weather/symbols/normal/'+symbol2+'" title="" /><br />'+low2+'&deg;C</p></td><td style="width : 20%;"><p class="weather" id="day3">'+day3+'<br /><br />'+high3+'&deg;C<br /><img class="weathericon" src="http://villalouisepalmisland.com/commonfiles/weather/symbols/normal/'+symbol3+'" title="" /><br />'+low3+'&deg;C</p></td><td style="width : 20%;"><p class="weather" id="day4">'+day4+'<br /><br />'+high4+'&deg;C<br /><img class="weathericon" src="http://villalouisepalmisland.com/commonfiles/weather/symbols/normal/'+symbol4+'" title="" /><br />'+low4+'&deg;C</p></td><td style="width : 20%;"><p class="weather" id="day5">'+day5+'<br /><br />'+high5+'&deg;C<br /><img class="weathericon" src="http://villalouisepalmisland.com/commonfiles/weather/symbols/normal/'+symbol5+'" title="" /><br />'+low5+'&deg;C</p></td>';
				}
			}
		}
		else {
			// check browser
			if(isie) {
				// left column
				// create a paragraph element
				if(nighttime) {
					para=document.createElement('<p class="weather" id="currentleft" style="color : #FFFFFF;text-align : left;">');
				}
				else {
					para=document.createElement('<p class="weather" id="currentleft" style="text-align : left;">');
				}
				// create a cell element and add it the table
				// create a new cell
				newcell=document.createElement('<td colspan=2 style="width : 40%;">');
				// add paragraph
				newcell.appendChild(para);
				// add the cell
				winfo.appendChild(newcell);
				// set text
				document.getElementById("currentleft").innerHTML="<br />"+humiditytext+": "+humidity+"%<br /><br />"+pressuretext+": "+pressure+"mb";
				// right column
				// create a paragraph element
				if(nighttime) {
					para=document.createElement('<p class="weather" id="currentright" style="color : #FFFFFF;text-align : left;">');
				}
				else {
					para=document.createElement('<p class="weather" id="currentright" style="text-align : left;">');
				}
				// create a cell element and add it the table
				// create a new cell
				newcell=document.createElement('<td colspan=3 style="width : 60%";>');
				// add paragraph
				newcell.appendChild(para);
				// add the cell
				winfo.appendChild(newcell);
				// set text
				document.getElementById("currentright").innerHTML="<br />"+windtext+": "+windspeed+"km/h "+winddirection+"<br /><br >"+windchilltext+": "+windchill+"&deg;C"
			}
			else {
				if(nighttime) {
					winfo.innerHTML='<td colspan=2 style="width : 40%;"><p class="weather" style="color : #FFFFFF;text-align : left;"><br />'+humiditytext+': '+humidity+'%<br /><br />'+pressuretext+': '+pressure+'mb</p></td><td colspan=3  style="width : 60%;"><p class="weather" style="color : #FFFFFF;text-align : left;"><br />'+windtext+': '+windspeed+'km/h '+winddirection+'<br /><br />'+windchilltext+': '+windchill+'&deg;C</p></td>';			
				}
				else {
					winfo.innerHTML='<td colspan=2 style="width : 40%;"><p class="weather" style=";text-align : left;"><br />'+humiditytext+': '+humidity+'%<br /><br />'+pressuretext+': '+pressure+'mb</p></td><td colspan=3 style="width : 60%;"><p class="weather" style="text-align : left;"><br />'+windtext+': '+windspeed+'km/h '+winddirection+'<br /><br />'+windchilltext+': '+windchill+'&deg;C</p></td>';			
				}
			}		
		}
	}
}