
/* JavaScript User Interface functions for WX Clent Website */

function ForecastPopup(){

	popup = window.open('','name', 'height=230 width=340');
	var tmp = popup.document;
	tmp.write('<html><head><title>Forecast for Clent ... </title></head>');
	tmp.write('<body bgcolor="white"><img alt="Weather" border="0" src="http://www.netweather.tv/4web2/netweather4webi.pl?lat=52.5;lon=-2;title=Clent;template=1" /></body></html>');
	if (window.focus){
		popup.focus
	}


}


function RainPopup(){

	popup = window.open('','name', 'height=590,width=715');
	var tmp = popup.document;
	tmp.write('<html><head><title>Rain Details ... </title></head>');
	tmp.write('<body bgcolor="black"><img src="raindetail.gif"/></body></html>');
	
	if (window.focus){
		popup.focus
	}
   
}

function AstroPopup(){

	popup = window.open('','name', 'height=470,width=540');
	var tmp = popup.document;
	tmp.write('<html><head><title>Astronomical Details ... </title></head>');
	tmp.write('<body bgcolor="black"><img src="moondetail1.gif"/><img src="moondetail2.gif"/></body></html>');
	
	if (window.focus){
		popup.focus
	}
   
}

function SelectGraph(graphtext) {
   
   switch(graphtext){
    	case "Last 24 Hours":
    	imgGraph.src="curr24hourgraph.gif"
   	break;    
    	case "Last 48 Hours":
    	imgGraph.src="curr48hourgraph.gif"
    	break;
    	case "Last 72 Hours":
    	imgGraph.src="curr72hourgraph.gif"
    	break;
	case "Last 7 Days":
    	imgGraph.src="weekgra.gif"
    	break;
    	case "Last 30 Days":
    	imgGraph.src="monthtodate.gif"
    	break;
    	default:
   }		
  
  var TitleElement = document.getElementById('lblGraph');
  TitleElement.firstChild.nodeValue=graphtext;

}

function HideElement (elementId) {
    var element;
    if (document.all){
	element = document.all[elementId];
    }else if (document.getElementById){
	element = document.getElementById(elementId);
    }
    if (element && element.style){
	element.style.display = 'none';
   }
}

function ShowElement (elementId) {
    var element;
    if (document.all){
	element = document.all[elementId];
    }else if (document.getElementById) {
  	element = document.getElementById(elementId);
    }
    if (element && element.style){
	element.style.display = '';
    }
}

function TickerMessage(string) {
  var element = document.getElementById('main-ticker');
  element.innerHTML=string;

}


function PageInit(currenttemp, lasthoursrain, rainratemin, timenow, tempdaymax, tempdaymin, tempnitemax, tempnitemin){


// Dynamic Temperature Content ...
   // Convert Current Temperature to number
   var currentTemp = Number(currenttemp);

   // Show Windchill if below 10 C
   if (currentTemp < 10) {
    	ShowElement('WindChill');  
   }else{
    	HideElement('WindChill');
   }

   // Show Heat Index if above 20 C
   if (currentTemp > 20) {
	ShowElement('HeatIndex');
   }else{
	HideElement('HeatIndex');
   }

// Dynamic Rain Content ...
   // Convert Last Hours Rain-String to number
   var i = lasthoursrain.indexOf('mm');
   var rainHours = Number( lasthoursrain.substring(0, i));

   // Convert Hour Rain-Rate to number
   var rainRateMin = Number(rainratemin);
      
   if (rainHours > 0) {    
   	ShowElement('LastHoursRain');
	
      // Show Minute Rain Rate - if not zero - else show Hour Rate
	if (rainRateMin != 0) {
		ShowElement('RainRateMin');		
	}else{
		ShowElement('RainRateHour');
	}	

   }else{
	HideElement('LastHoursRain');
	HideElement('RainRateMin');
	HideElement('RainRateHour');	
   }

// Ticker Content ... Temperature observations

   var strMsg;
      
   strMsg = 'Clent Weather News Update: ...... ';

   if (timenow < '18:00'){
	if (timenow < '06:00'){
		// Between 0000 - 0600
		strMsg = strMsg + 'Yesterday\'s High was ~ ' + tempdaymax + ' C ... Overnight Low so far ~ ' + tempnitemin + ' C ';		
      }else{
		// Between 0600 - 1800
		strMsg = strMsg + 'Today\'s High so far ~ ' + tempdaymax + ' C ... Lastnight\'s Low was ~ ' + tempnitemin + ' C ';
	}
   }else{
	// Between 1800 - 0000  
	strMsg = strMsg + 'Today\'s High reached ~ ' + tempdaymax + ' C ... Tonight\'s Low so far ~ ' + tempnitemin + ' C '; 	
   }
   
   strMsg = strMsg + '......';
      
   TickerMessage(strMsg); 	

}


