Rollimage = new Array()
Rollimage[0] = new Image()
Rollimage[0].src = "http://www.foxnews.com/i/new/feat-shows-blue.gif"
Rollimage[1] = new Image()
Rollimage[1].src = "http://www.foxnews.com/i/new/feat-shows-white.gif"

function SwapOut() {
	document.rollover.src = Rollimage[1].src;
	return true;
}

function SwapBack() {
	document.rollover.src = Rollimage[0].src;
	return true;
}

function overlay(element) {
	el = document.getElementById(element);
	el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
}

function changeDisplay(id) {
	if (document.getElementById(id) != null) {
		document.getElementById(id).style.background = '#EBF1F6';
	}
	return false;
}

function cleanDisplay(id) {
	if (document.getElementById(id) != null) {
		document.getElementById(id).style.background = '#fff';
	}
}

function cleanDisplayEven(id) {
	if (document.getElementById(id) != null) {
		document.getElementById(id).style.background = '#E5E5E5';
	}
}

function Cookie(document, name, hours, path, domain, secure) {
	this.$document = document;
	this.$name = name;
	this.$expiration = hours ? new Date((new Date()).getTime() + hours * 3600000) : null;
	this.$path = path ? path : null;
	this.$domain = domain ? domain : null;
	this.$secure = secure ? true : false;
}

Cookie.prototype.store = function() {
	var cookieval = "";
	for ( var prop in this) {
		// Ignore properties with names that begin with '$' and also methods
		if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function')) {
			continue;
		}
		if (cookieval != "") {
			cookieval += '&';
		}
		cookieval += prop + ':' + escape(this[prop]);
	}
	var cookie = this.$name + '=' + cookieval;
	cookie += this.$expiration ? '; expires=' + this.$expiration.toGMTString()
			: '';
	cookie += this.$path ? '; path=' + this.$path : '';
	cookie += this.$domain ? '; domain=' + this.$domain : '';
	cookie += this.$secure ? '; secure' : '';

	this.$document.cookie = cookie;
}

Cookie.prototype.load = function() {
	var allcookies = this.$document.cookie;
	if (allcookies == "")
		return false;

	var start = allcookies.indexOf(this.$name + '=');
	if (start == -1)
		return false;
	start += this.$name.length + 1;
	var end = allcookies.indexOf(';', start);
	if (end == -1)
		end = allcookies.length;
	var cookieval = allcookies.substring(start, end);

	var a = cookieval.split('&');
	for ( var i = 0; i < a.length; i++) {
		a[i] = a[i].split(':');
	}

	for ( var i = 0; i < a.length; i++) {
		this[a[i][0]] = unescape(a[i][1]);
	}

	return true;
}

Cookie.prototype.remove = function() {
	var cookie;
	cookie = this.$name + '=';
	cookie += this.$path ? '; path=' + this.$path : '';
	cookie += this.$domain ? '; domain=' + this.$domain : '';
	cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';

	this.$document.cookie = cookie;
}

function getCookieValue(n) {
	if (!document.cookie) {
		return '';
	}
	c = document.cookie;
	var v = "";
	index = c.indexOf(n + "=");
	if (index < 0) {
		return '';
	}
	var countbegin = (c.indexOf("=", index) + 1);
	if (0 < countbegin) {
		var countend = c.indexOf(";", countbegin);
		if (countend < 0) {
			countend = c.length;
		}
		return c.substring(countbegin, countend);
	}
	return '';
}

function resetWeatherData() {

    p = '; domain=foxnews.com; path=/; expires=Fri, 02-Jan-1970 00:00:00 GMT';
    c = 'weatherloc='+p;
    document.cookie = c;

    c = 'weatherdata='+p;
    document.cookie = c;
    renderWeather();
}

function clearDefault(el,default_value) {
    if (el.value==default_value) {
        el.value = "";
    }
}

function updateWeatherData() {
	var z = getCookieValue('weatherloc');
	var d = getCookieValue('weatherdata');
	if (z && !d) {
		var wif = document.createElement('script');
		wif.setAttribute("type", "text/javascript");
		wif.setAttribute('src', "http://www2.foxnews.com/weather/set_weather_js.asp?loc_id=" + getWeatherLocation(z).loc_id);
		return wif;
	} else if (!z || !d) {
		var wfo, wfs, win, win2, wsb, wlp, wlk, wul;
		wfo = document.createElement('form');
		wfo.setAttribute('action', 'http://www2.foxnews.com/weather/get_weather.asp?ref=root');
		wfo.setAttribute('method', 'post');
		wfs = document.createElement('fieldset');
		win = document.createElement('input');
		win.setAttribute('name', 'zip');
		win.setAttribute('value', 'Enter your zip code');
		win.onclick = function() {
			clearDefault(this, 'Enter your zip code');
		}
		win.style.width = '10em';
		win2 = document.createElement('input');
		win2.setAttribute('type', 'hidden');
		win2.setAttribute('name', 'source');
		win2.setAttribute('value', 'root');
		win2 = document.createElement('input');
		win2.setAttribute('type', 'hidden');
		win2.setAttribute('name', 'referer');
		win2.setAttribute('value', escape(document.location));
		if (z) {
			win.setAttribute('value', getWeatherLocation(z).zip);
		}
		wsb = document.createElement('a');
		wsb.className = 'button no_spon';
		wsb.setAttribute('href', '#');
		wsb.onclick = function() {
			if (win.value == '') {
				alert('Please enter your zip code');
				return false;
			} else {
				getParent(getParent(wsb)).submit();
			}
		};
		// wsb.appendChild(document.createTextNode('Get Weather'));
		// wfo.appendChild(document.createTextNode('Enter your zip code:'));
		wfs.appendChild(win);
		wfs.appendChild(win2);
		wfs.appendChild(wsb);
		wfo.appendChild(wfs);

		/*
		 * wlp = document.createElement("p"); wlp.className = 'note'; wlk =
		 * document.createElement("a");
		 * wlk.setAttribute("href","http://www2.foxnews.com/weather/weather_personal.asp");
		 * 
		 * wul = document.createElement("span");
		 * wul.style.textDecoration="underline";
		 * wul.appendChild(document.createTextNode("Click Here"));
		 * wlk.appendChild(document.createTextNode("Don't know your zip code?
		 * ")); wlk.appendChild(wul); wlp.appendChild(wlk);
		 * wfo.appendChild(wlp);
		 */
		return wfo;
	}

	var wul, wli, wh2, wdf, wdi, wdv, whi, wlo, wpa, i, day, d, h, l, w;
	wul = document.createElement('ul');

	var wd = eval('(' + unescape(d) + ')');
	days = wd.days;

	for (i = 0; i < 1; i++) {
		day = days[i]
		d = i == 0 ? "TODAY" : "TOMORROW";
		wli = document.createElement('li');

		var wWeatherLink = document.createElement('a');
		wWeatherLink
				.setAttribute(
						'href',
						'http://www2.foxnews.com/weather/weather_city.asp?zip=' + getWeatherLocation(z).zip);

		wdi = document.createElement('img');
		wdi.setAttribute('src',
				'http://www.foxnews.com/i/weather/' + day.image + '.gif');
		wdi.className = 'forecast';

		wWeatherLink.appendChild(wdi);

		wh2 = document.createElement('h2');
		wh2.appendChild(document.createTextNode(d));

		wpa = document.createElement('p');
		wpa.className = 'hi';
		// wpa.appendChild(document.createTextNode(day.forecast.replace(/\+/g, "
		// ")));
		wpa.appendChild(document.createTextNode(day.hi));
		wpa.appendChild(document.createTextNode(String.fromCharCode(176)));

		wlo = document.createElement('span');
		wlo.className = 'lo';
		wlo.appendChild(document.createTextNode(day.low));
		wlo.appendChild(document.createTextNode(String.fromCharCode(176)));

		wpa.appendChild(wlo);

		wdesc = document.createElement('p');
		wdesc.className = "description";
		wdesc.appendChild(document.createTextNode(day.forecast.replace(/\+/g,
				" ")));

		wli.appendChild(wWeatherLink);
		wli.appendChild(wh2);
		wli.appendChild(wpa);
		wli.appendChild(wdesc);
		wul.appendChild(wli);
	}
	return wul;
}

function getWeatherLocation(z) {
	var lo = eval('(' + unescape(z).replace(/\+/g, " ") + ')');
	return lo.location[0];
}

function renderWeather() {
	var weather_links = addWeatherLinks();
	if (weather_links) {
		document.getElementById('weather_header').className = 'fore';
	} else {
		document.getElementById('weather_header').className = '';
	}
	document.getElementById('weather_header').innerHTML = weather_links;
	document.getElementById('weather_header').appendChild(updateWeatherData());
}

function addWeatherLinks() {
	var z = getCookieValue('weatherloc');
	var d = getCookieValue('weatherdata');

	if (d && z) {
		var lo = getWeatherLocation(z);
		var st = '<p style="width:240px; text-align:right;"><a class="action" href="http://www2.foxnews.com/weather/weather_city.asp?zip='
				+ lo.zip + '">' + lo.city + '</a>';
		if (window.location != 'http://www2.foxnews.com/weather/weather_personal.asp') {
			st += '&nbsp;<a style="color:#0000FF" class="action" href="#" onclick="resetWeatherData();return false;">(change)</a>';
		}
		st += '</p>';
		return st;
	}
	return '';
}

var thirty_days = (30 * 24);
var thirty_mins = (30 / 60);
var one_minute = (1 / 60);

var weather_zipcode_cookie = new Cookie(document, "weatherloc", thirty_days,
		'', 'foxnews.com');
var weather_data_cookie = new Cookie(document, "weatherdata", 1, '',
		'foxnews.com');

function siteStreamFlashPlayer(n, site) {
	var s = typeof(n) == 'undefined' ? 1 : n;
	var d = typeof(site) == 'undefined' ? 'foxnews' : site;
	var w = 850;
	var h = 506;
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var settings ='height='+h+',';
	settings +='width='+w+',';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	settings +='toolbar=no,';
	settings +='location=no,';
	settings +='scrollbars=no,';
	settings +='status=no,';
	settings +='resizable=no,';
	settings +='fullscreen=no';
	var win = window.open('http://interactive.' + d + '.com/livestream/live.html?chanId='+s+'&openAIR=true','livePlayer',settings);
	win.focus();
	}

	var rs = {
	button : function(t){
	getParent(getParent(t)).submit();
	return false;
	}
	};

	function getParent(e) {
	return e.parentNode?e.parentNode:(e.parentElement?e.parentElement:null);
	} 