﻿// JScript File

//window.onLoad=clientSideInclude('weather', 'http://www.ip2phrase.com/ip2phrase.asp?template=<CITY>,<REGION>');

var newHTML;
var zipCode;
var id;

/***WEATHER (ZIPCODE) COOKIE CHECK***/
/***General Cookie functions in Common.js***/

function checkCookie(target)
{
	id = target
	zipCode=getCookie('zipCode');
	if (zipCode!=null && zipCode!="")
	{
		//Valid Zip found - Display weather widget
		getWeatherHTML();
	}
	else 
	{
		//No cookie found - display Zip Code Entry form.
		enterZip(target);
	}
}

/***END COOKIE FUNCTIONS***/
/*

*/
function enterZip(target)
{
	newHTML = '<p style="text-align: center;">Enter your ZIP code for weather information:</p>'+
			'<b>Zip: </b><input type="text" id="zip" maxlength="5" size="5" onkeypress="return enterPressed(event)" onkeydown="return enterPressed(event)"/>'+
			'<button id = "btnWeather" type="button" onclick="saveStartWeather()">Submit</button>';
	$(target).innerHTML=newHTML;
	$('zip').focus();

}

function saveStartWeather()
{
	zipCode = $("zip").value;
	if (zipCode.length = 5)
	{
		setCookie('zipCode',zipCode,365);
		getWeatherHTML();
	}
	else
	{
		alert("Sorry, that is not a valid 5 digit zip code.");
	}
}

function getWeatherHTML()
{
	Internal.ABCService.GetWeatherHTML(zipCode, getWeatherHTMLResponse);
}

function getWeatherHTMLResponse(response)
{
	response += '<a href="javascript:enterZip('+ "'weather')"+ '" >Change ZIP Code</a>';
	$(id).innerHTML=response;
}

