// Are we being framed?
if(top.frames.length > 0) { top.location.href = self.location; }

// Simple Cookie Setter
function set_cookie(name, value, expires, path, domain, secure) {
        var cookieString = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toUTCString() : "") +
        ( (path) ? ";path=" + escape(path) : "") +
        ( (domain) ? ";domain=" + escape(domain) : "") +
        ( (secure) ? ";secure" : "");
        document.cookie = cookieString;
}

// Expands and collapses divs in left nav
function ln_toggle_list(item) {
	var a = document.getElementById(item);
	var b = document.getElementById(item + 'i');
	if(a.style.display=='block') { a.style.display='none'; b.src = 'images/arrow-left.gif'; }
	else { a.style.display='block'; b.src = 'images/arrow-down.gif'; }
}

// Location search form helper
function CheckSearch(field_name) {
    if (field_name.value=='Location Search' || field_name.value=='') {
        alert("Please enter a location name.");
        field_name.focus();
        return false;
    }
    return true;
}

// Location search form helper
function Check() {
    if (document.zipSearchForm.cityOrZip.value=='Enter city or US zip' ||
        document.zipSearchForm.cityOrZip.value=='') {
        alert("Please enter a location name or US zip code.");
        document.zipSearchForm.cityOrZip.focus();
        return false;
    }
    return true;
}

// Business Directory launcher
function PopUpDirectory(regionID, dirID) {
	var dirURL = 'businessDirectory.iws?';
	dirURL = dirURL + 'regionID=' + regionID + '&businessCatID=' + dirID;
	window.open(dirURL,"Business_Directory","width=425,height=363,menubar=no,scrollbars=yes")
}

// Opens trailer links in new window
function trailer_link(name,url,width) {
	opt = "width=" + width + ",menubar=no,scrollbars=yes";
	window.open(url,name,opt);
}

// Left nav zoom in box handler
var zoom_timer_id = 0;
function kill_zoom_timer() { if(zoom_timer_id != 0) {clearTimeout(zoom_timer_id); zoom_timer_id=0;} }
function show_region_zoom() { kill_zoom_timer(); var a = document.getElementById('ln-zoombox'); a.style.display='inline'; }
function hide_region_zoom() { kill_zoom_timer(); zoom_timer_id = setTimeout(kill_region_zoom, 600); }
function kill_region_zoom() { var a = document.getElementById('ln-zoombox'); a.style.display='none'; }

// Forecast Feedback Tool
function feedback_show() { document.getElementById('feedback_form').style.display = 'block'; }
function feedback_hide() { document.getElementById('feedback_form').style.display = 'none';      }
function feedback_submit(token, key, type) {
	var feedback_box = document.getElementById('feedback_form');
	var url = 'json/forecast_feedback.iws';
	var params = 'token=' + token + '&type=' + type + '&key=' + key + '&feedback=' + escape(document.getElementById('feedback_comments').value);
	document.getElementById('feedback_button').disabled = true;
	new Ajax.Updater( feedback_box, url, {method:'post', postBody:params});
	return;
}


//Start Basic Ajax Routine- Author: Dynamic Drive (http://www.dynamicdrive.com)
//Last updated: Jan 15th, 06'

function createAjaxObj(){
var httprequest=false
if (window.XMLHttpRequest){ // if Mozilla, Safari etc
httprequest=new XMLHttpRequest()
if (httprequest.overrideMimeType)
httprequest.overrideMimeType('text/xml')
}
else if (window.ActiveXObject){ // if IE
try {
httprequest=new ActiveXObject("Msxml2.XMLHTTP");
} 
catch (e){
try{
httprequest=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){}
}
}
return httprequest
}

var ajaxpack=new Object()
ajaxpack.basedomain="http://"+window.location.hostname
ajaxpack.ajaxobj=createAjaxObj()
ajaxpack.filetype="txt"
ajaxpack.addrandomnumber=0 //Set to 1 or 0. See documentation.

ajaxpack.getAjaxRequest=function(url, parameters, callbackfunc, filetype){
ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
if (ajaxpack.addrandomnumber==1) //Further defeat caching problem in IE?
var parameters=parameters+"&ajaxcachebust="+new Date().getTime()
if (this.ajaxobj){
this.filetype=filetype
this.ajaxobj.onreadystatechange=callbackfunc
this.ajaxobj.open('GET', url+"?"+parameters, true)
this.ajaxobj.send(null)
}
}

ajaxpack.postAjaxRequest=function(url, parameters, callbackfunc, filetype){
ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
if (this.ajaxobj){
this.filetype=filetype
this.ajaxobj.onreadystatechange = callbackfunc;
this.ajaxobj.open('POST', url, true);
this.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
this.ajaxobj.setRequestHeader("Content-length", parameters.length);
this.ajaxobj.setRequestHeader("Connection", "close");
this.ajaxobj.send(parameters);
}
}

//End Basic Ajax Routine- Author: Dynamic Drive (http://www.dynamicdrive.com)

