// Set Location
// Created 17/04/08 by GH

function DisplayForcastTop(vthetown) {
		if(vthetown) {
			var objCity = vthetown;
		}
		else {
        var objCity = document.getElementById('header1_CityDropdown3').value;
		}
        if (objCity)
        {
			if (objCity == '')
			{
				alert("Please select a valid town");
				
			}
			else {
			document.getElementById('LocationList').style.display='none';
			document.getElementById('TopWeatherForcast').style.display= 'block';
			document.getElementById('changeLocation').style.display = 'block';
			try {
			    document.getElementById('WeatherTowns').style.display = 'none';
			}
			catch (err) {
			}
			GetWeatherInfoTop(objCity);
			
			//create a cookie
			var exdt = new Date();
			exdt.setFullYear(exdt.getFullYear() + 1);
			SetCookie('weather', objCity, exdt, '/', '', '')
			//createCookie("weather", objCity, 365);
			}
	    }
	}

	function DisplayForcastTopHeader(vthetown) {
	    if (vthetown) {
	        var objCity = vthetown;
	    }
	    else {
	        var objCity = document.getElementById('header1_CityDropdown3').value;
	    }
	    if (objCity) {
	        if (objCity == '') {
	            alert("Please select a valid town");

	        }
	        else {
	            //document.getElementById('WeatherTowns').style.display = 'none';
	            document.getElementById('LocationList').style.display = 'none';
	            document.getElementById('TopWeatherForcast').style.display = 'block';
	            document.getElementById('changeLocation').style.display = 'block';
	            GetWeatherInfoTop(objCity);

	            //create a cookie
	            var exdt = new Date();
	            exdt.setFullYear(exdt.getFullYear() + 1);
	            SetCookie('weather', objCity, exdt, '/', '', '')
	            //createCookie("weather", objCity, 365);
	        }
	    }
	}


    function GetWeatherInfoTop(cityId)
    {

        //var file = '/includes/html/weather/' + cityId + '_top.htm';
        var file = '/FileChecker.aspx?FileName=' + cityId;
        var weather_ajax_control = new sack();
        weather_ajax_control.method = "GET";
        weather_ajax_control.encodeURIString = false;
        weather_ajax_control.element = 'TopWeatherForcast';
        weather_ajax_control.requestFile = file;
        weather_ajax_control.onError = function() { document.getElementById('TopWeatherForcast').innerHTML = '<p>Forecast Unavailable</p>'; }
        weather_ajax_control.runAJAX();	
    }
    
    function ShowHideWeather(vhide)
    {
        if(document.getElementById('LocationList').style.display=='block')
        {
            document.getElementById('LocationList').style.display='none';
            document.getElementById('TopWeatherForcast').style.display='block';
            document.getElementById('changeLocation').style.display = 'block';
            try
            {
                document.getElementById('WeatherTowns').style.display = 'none';
            }
            catch (err)
            {
            }
        }
        else
        {
			document.getElementById('LocationList').style.display='block';
			document.getElementById('changeLocation').style.display='none';
			document.getElementById('TopWeatherForcast').style.display = 'none';
			try
            {
			    document.getElementById('WeatherTowns').style.display = 'block';
			}
			catch (err)
			{
			}
        }            
    }
	
function DisplayForcast(vthetown) {
		
		if(vthetown) {
			var objCity = vthetown;
		}
		else {
    
        var objCity = document.getElementById('weather1_CityDropdownMod').value;
		}
		
        if (objCity)
        {
			if (objCity == '')
			{
				document.getElementById('ErrorMsg').style.display = 'block';
				document.getElementById('ErrorMsg').innerHTML = '<div class="default-box-blue"><div class="padding-box"><div style="margin: 0 0 0 10px;" class="redtxt">Please select a valid city/town.</div></div></div>';
			}
			else
			{
				document.getElementById('ErrorMsg').style.display = 'none';
			document.getElementById('WeatherTowns').style.display='none';
			document.getElementById('LocationList').style.display='none';
			document.getElementById('TopWeatherForcast').style.display= 'block';
			document.getElementById('changeLocation').style.display='block';
				GetWeatherInfo(objCity);
				
				//create a cookie
				var exdt = new Date();
				exdt.setFullYear(exdt.getFullYear() + 1);
				SetCookie('weather', objCity, exdt, '/', '', '')
				//createCookie("weather", objCity, 365);
			}
	    }
    
}

function GetWeatherInfo(cityId)
{

    //var file = '/includes/html/weather/' + cityId + '.htm';
    var file = '/FileChecker.aspx?FileName=' + cityId + "&section=bottom";
	var weather_ajax_control = new sack();
	weather_ajax_control.method = "GET";
	weather_ajax_control.encodeURIString = false;
	weather_ajax_control.element = 'WeatherForcast';
	weather_ajax_control.requestFile = file;
	weather_ajax_control.onCompletion = function() {document.getElementById('WeatherIntro').style.display='none';}
	weather_ajax_control.onError = function() {document.getElementById('WeatherForcast').innerHTML = '<p class="content">The weather forecast is currently unavailable.</p>';}
	weather_ajax_control.runAJAX();	
}

function GetStateNewsInfo(vstate)
{
	document.getElementById('statenews').innerHTML = vstate + " News";

	var newsfile = '/includes/html/news/News-' + vstate + '.html';
	var news_ajax_control = new sack();
	news_ajax_control.method = "GET";
	news_ajax_control.encodeURIString = false;
	news_ajax_control.element = 'LocalNews';
	news_ajax_control.requestFile = newsfile;
	news_ajax_control.onError = function() {document.getElementById('LocalNews').innerHTML = '<p class="content">The news is currently unavailable.</p>';}
	news_ajax_control.runAJAX();	
	
}


    

/**-------------------------------------------------------------*/
/**------------------------- Set Town and State ----------------*/
/**-------------------------------------------------------------*/

function hsetLocation(vdropdownid) {

	var vselectedState = null
	var vstatefuel = null

	try {
	    if (vdropdownid == "header1_CityDropdown3") {
	        document.getElementById('weather1_CityDropdownMod').selectedIndex = document.getElementById('header1_CityDropdown3').selectedIndex;
	    }
	    else {
	        document.getElementById('header1_CityDropdown3').selectedIndex = document.getElementById('weather1_CityDropdownMod').selectedIndex;
	    }
	}
	catch (err) {
	}
	
	vtownDropDown = document.getElementById('header1_CityDropdown3');
	
	// Find the value of the town they selected
	vweather = vtownDropDown.value;
	
	// Find the selected Index of the town selected
	vweatherIndex = vtownDropDown.selectedIndex;
	
	// Set the States into an array
	var vstate = new Array();
	vstate[0] = "WA";
	vstate[1] = "SA";
	vstate[2] = "NT";
	vstate[3] = "QLD";
	vstate[4] = "NSW";
	vstate[5] = "VIC";
	vstate[6] = "TAS";
	vstate[7] = "AUS";
	
	var vcity = new Array();
	vcity[0] = "Perth";
	vcity[1] = "Adelaide";
	vcity[2] = "OzBest";
	vcity[3] = "Brisbane";
	vcity[4] = "Sydney";
	vcity[5] = "Melbourne";
	vcity[6] = "OzBest";
	vcity[7] = "OzBest";
	
	
	var vtopWeatherCities = new Array();
	vtopWeatherCities[0] = "9528";
	vtopWeatherCities[1] = "9401";
	vtopWeatherCities[2] = "9110";
	vtopWeatherCities[3] = "9250";
	vtopWeatherCities[4] = "9770";
	vtopWeatherCities[5] = "9477";
	vtopWeatherCities[6] = "9329";
	vtopWeatherCities[7] = "9028";
	
	
	// This array will be used to store the indexes of all the states in the dropdown
	var vstateIndex = new Array();
	

	for (mm=0; mm<8; mm++) {
		if(vweather == vtopWeatherCities[mm]){
			vselectedState = vstate[mm]
		}
	}
		
	if (vselectedState == null){
		// Go through each state
		for (jj=0; jj<7; jj++) {
		
			// Go through the length of the dropdown
			for (ii=0; ii<vtownDropDown.length; ii++) {
				
				// Does the vaule of the dropdown equal the value of the state above?
				if (vtownDropDown.options[ii].value == vstate[jj]){
				
					// Set the index of the state in the blank array for refference later on
					vstateIndex[jj] = ii;
				}
			}
		}
		
		
		
		// Compare the Index of the selected town to the index of the States
		for (kk=0; kk<7; kk++) {
			if (vweatherIndex < vstateIndex[kk]){
					vselectedState = vstate[kk - 1];
					break;
			}
			
		}
		
		
		// If at the end of the loop you still haven't found the right state then it is TAS the last item in the list
		if (vselectedState == null) {
			vselectedState = vstate[6];
		}
		
		}
		
	// If the news isn't set then set it to the correct state
	vstatenews = vselectedState;
	
	
	
	// If the fuel isn't set then set it to the correct state 
	// but first check to see if the state is TAS or NT as they are not avalable
	if (vstatefuel == null){
		for (op=0; op<7; op++) {
			
			if (vstate[op] == vselectedState){
				vstatefuel = vcity[op];
				
			}
		}
	}

	
	// Set the date a year from now
	var exdt = new Date();
	exdt.setFullYear(exdt.getFullYear() + 1);
	SetCookie('vstatenews',vstatenews,exdt,'','','')
	
	// Set the date a year from now
	var exdt = new Date();
	exdt.setFullYear(exdt.getFullYear() + 1);
	SetCookie('fuelwatch',vstatefuel,exdt,'','','')


	try {
	    GetStateNewsInfo(vstatenews)
	}
	catch (err) {
	}	
		
	try {
	    displayFuelInfo(vstatefuel);
    }
    catch (err) {
    }	
	
	DisplayForcastTop(vweather);
	
	try {
	    DisplayForcast(vweather);
    }
    catch (err) {
    }	
}


/**-------------------------------------------------------------*/
/**------ Expand and Contract fuctions for the panels ----------*/
/**-------------------------------------------------------------*/

function hpanelexpand(vpanel) {
	
	// Get the cookie if there is one
	var cpanels = GetCookie('cpanelsec');
	
	// set this varible as you are going to need to put the cookie information in there later
	vcookieval = "";
	
	// Heres the list of all the panels
	var vpanelarray = new Array();
	vpanelarray[0] = "weather"
	vpanelarray[1] = "careers"
	vpanelarray[2] = "real_estate"
	vpanelarray[3] = "fuel_watch"
	vpanelarray[4] = "threefl_news"
	vpanelarray[5] = "finance"
	vpanelarray[6] = "photo"
	vpanelarray[7] = "quiz"
	vpanelarray[8] = "quote"
	vpanelarray[9] = "cars"
	vpanelarray[10] = "world_time"
	vpanelarray[11] = "movies"
	vpanelarray[12] = "dating"
	vpanelarray[13] = "horoscopes"
	vpanelarray[14] = "on_this_day"
	vpanelarray[15] = "member_news"
	vpanelarray[16] = "dictionary"
	vpanelarray[17] = "network_status"
	vpanelarray[18] = "tv_guide"
	
	// New Array to put the cookie information in so you can break it up
	var vcookieresult = new Array();
	
	// Is the cookie empty?
	if (cpanels != null) {
		
		// If it is not then break up the value one character at a time and input into the array
		for (i=0; i<19; i++) {
			vcookieresult[i] = cpanels.charAt(i);
		}
		
		for (jk=0; jk<19; jk++) {
			
			// If the panel they clicked on equals one of the varibles in the array then set that panel to "e" for expaned
			if (vpanel == vpanelarray[jk]){
					vcookieresult[jk] = "e";
			}
		}
		
	}
	else {
		
		// If there is no cookie then set them all to "e" for expaned
		for (km=0; km<19; km++) {
			vcookieresult[km] = "e";
		}
	}
	
	// Put all the cookie values from the array into one string again for cookie
	for (mn=0; mn<19; mn++) {
		vcookieval = vcookieval + vcookieresult[mn];
	}
	
	// Show the panel
	document.getElementById("panel" + vpanel).style.display = "block";
	document.getElementById(vpanel + "panelShow").style.display = "none";
	document.getElementById(vpanel + "panelHide").style.display = "block";
	
	// Set the date a year from now
	var exdt = new Date();
	exdt.setFullYear(exdt.getFullYear() + 1);
	
	// Set the cookie for future refference
	SetCookie("cpanelsec",vcookieval,exdt,'','','')
	
}


// For comments for this function please see the function function hpanelexpand()
function hpanelcontract(vpanel) {
	
	var cpanels = GetCookie('cpanelsec');
	
	
	vcookieval = "";
	
	var vpanelarray = new Array();
	vpanelarray[0] = "weather"
	vpanelarray[1] = "careers"
	vpanelarray[2] = "real_estate"
	vpanelarray[3] = "fuel_watch"
	vpanelarray[4] = "threefl_news"
	vpanelarray[5] = "finance"
	vpanelarray[6] = "photo"
	vpanelarray[7] = "quiz"
	vpanelarray[8] = "quote"
	vpanelarray[9] = "cars"
	vpanelarray[10] = "world_time"
	vpanelarray[11] = "movies"
	vpanelarray[12] = "dating"
	vpanelarray[13] = "horoscopes"
	vpanelarray[14] = "on_this_day"
	vpanelarray[15] = "member_news"
	vpanelarray[16] = "dictionary"
	vpanelarray[17] = "network_status"
	vpanelarray[18] = "tv_guide"
	
	var vcookieresult = new Array();
	
	if (cpanels != null) {

		for (i=0; i<19; i++) {
			vcookieresult[i] = cpanels.charAt(i);

		}

		
		for (jk=0; jk<19; jk++) {
			if (vpanel == vpanelarray[jk]) {
					vcookieresult[jk] = "c";
			}
		}
		
	}
	else {
		for (km=0; km<19; km++) {
			vcookieresult[km] = "e";
		}
	}
	
	for (mn=0; mn<19; mn++) {
		vcookieval = vcookieval + vcookieresult[mn];
	}
	
	document.getElementById("panel" + vpanel).style.display = "none";
	document.getElementById(vpanel + "panelHide").style.display = "none";
	document.getElementById(vpanel + "panelShow").style.display = "block";
	var exdt = new Date();
	exdt.setFullYear(exdt.getFullYear() + 1);
	SetCookie("cpanelsec",vcookieval,exdt,'','','')
}


// For comments for this function please see the function function hpanelexpand()
function hhidpanels() {
	
	var cpanels = GetCookie('cpanelsec');
	
	var vpanelarray = new Array();
	vpanelarray[0] = "weather"
	vpanelarray[1] = "careers"
	vpanelarray[2] = "real_estate"
	vpanelarray[3] = "fuel_watch"
	vpanelarray[4] = "threefl_news"
	vpanelarray[5] = "finance"
	vpanelarray[6] = "photo"
	vpanelarray[7] = "quiz"
	vpanelarray[8] = "quote"
	vpanelarray[9] = "cars"
	vpanelarray[10] = "world_time"
	vpanelarray[11] = "movies"
	vpanelarray[12] = "dating"
	vpanelarray[13] = "horoscopes"
	vpanelarray[14] = "on_this_day"
	vpanelarray[15] = "member_news"
	vpanelarray[16] = "dictionary"
	vpanelarray[17] = "network_status"
	vpanelarray[18] = "tv_guide"
	
	var vcookieresult = new Array();
	
	if (cpanels != null) {
		for (i=0; i<19; i++) {
			if (cpanels.charAt(i) == "c"){
				document.getElementById("panel" + vpanelarray[i]).style.display = "none";
				document.getElementById(vpanelarray[i] + "panelHide").style.display = "none";
				document.getElementById(vpanelarray[i] + "panelShow").style.display = "block";
			}
		}
	}
}

/**-------------------------------------------------------------*/
/**---------------------------- Weather ------------------------*/
/**-------------------------------------------------------------*/

function hloadWeather() {
	
	ShowHideWeather()
	
	// Top
	
	var file = '/includes/html/weather-dropdown-top.html';
	var weather_ajax_control = new sack();
	weather_ajax_control.method = "GET";
	weather_ajax_control.encodeURIString = false;
	weather_ajax_control.element = 'LocationList';
	weather_ajax_control.requestFile = file;
	weather_ajax_control.onError = function() {document.getElementById('LocationList').innerHTML = 'Error!';}
	weather_ajax_control.runAJAX();
	
	// Middle
	
	var file = '/includes/html/weather-dropdown.html';
	var weather_ajax_control = new sack();
	weather_ajax_control.method = "GET";
	weather_ajax_control.encodeURIString = false;
	weather_ajax_control.element = 'WeatherTowns';
	weather_ajax_control.requestFile = file;
	weather_ajax_control.onError = function() {document.getElementById('WeatherTowns').innerHTML = 'Error!';}
	weather_ajax_control.runAJAX();
					
}

function hloadWorldTime() {
	var file = '/includes/html/worldtime-dropdown.html';
	document.getElementById('worldTimeChangeLocLink').style.display= 'none';
	document.getElementById('worldTimeChangeLocDrop').style.display= 'block';
	var weather_ajax_control = new sack();
	weather_ajax_control.method = "GET";
	weather_ajax_control.encodeURIString = false;
	weather_ajax_control.element = 'world_ChangeLocation';
	weather_ajax_control.requestFile = file;
	weather_ajax_control.onError = function() {document.getElementById('world_ChangeLocation').innerHTML = 'Error!';}
	weather_ajax_control.runAJAX();
	

					
}