// GENERIC WINDOW OPENER
function openWin(url,name,options)  {
win = window.open(url,name,options);
self.name = "main";
win.focus();
}
// GENERIC COOKIE SCRIPT (Next 3 functions)
function getCookieVal(offset) {
 var endstr=document.cookie.indexOf(";",offset);
 if (endstr==-1)
 endstr=document.cookie.length;
 return unescape(document.cookie.substring(offset,endstr));
}
function GetCookie(cname) {
 var arg=cname+"="; var alen=arg.length;
 var clen=document.cookie.length; var i=0;
 while (i<clen) {
	var j=i+alen;
	if (document.cookie.substring(i,j)==arg) return getCookieVal (j);		i=document.cookie.indexOf(" ",i)+ 1;
	if (i==0) break;
 } return null;
}
function SaveCookie(cname,cvalue,cdays,cpath,cdomain) {
 ex=new Date; ex.setTime(ex.getTime()+(cdays*86400000));
 if (cpath == null) { cpath = "" } else { cpath= "; path="+cpath }      
 if (cdomain == null) { cdomain = "" } else { cdomain= "; domain="+cdomain }      
 document.cookie=cname+'='+cvalue+'; expires='+ex.toGMTString()+cpath+cdomain;
}

//REDIRECT
   function go(form) { 
           baseLocation = form.gotoURL.options[form.gotoURL.selectedIndex].value
           if (baseLocation == ".") { return }
           if (baseLocation.substring(0,5) != "http:") { 
                   baseLocation = "" + baseLocation 
           }
           window.location = baseLocation
   }

//FONTSIZE
function ChangeFontSize(id, size) {
    document.getElementById(id).style.fontSize = size + "px";
    var lineheight = size*1.2;
    document.getElementById(id).style.lineHeight = lineheight + "px";
    SaveCookie("fontsize_bg",size,365);
}

function CheckFontSize() {
	if (GetCookie('fontsize_bg')) { //see if cookie already exists
		var fontsize = GetCookie('fontsize_bg');
		if (fontsize != 13) {
		ChangeFontSize('body_text',fontsize);
		}
	}
}

// WEATHER SCRIPTS/FUNCTIONS
var myweatherpage = "/weather/";
function setwzone() {	// Does popup window for user to set preferred zone(s)
	getzone = 
"http://newslink.nandomedia.com/cgi-bin/weather/findcode.cgi?camefrom=http://"+escape(location.hostname)+escape(location.pathname);
	setme = window.open(getzone,"setwzone","status=yes,width=350,height=350,scrollbars=yes,resizable=no");
}
//Turns response from zone lookup (query to your page) into cookie
if (document.location.search.substr(1,5)=="wzone") {
	if (GetCookie('mywzone_ip')) { //see if cookie already exists
		var oldzones = GetCookie('mywzone_ip');
		var newzones = oldzones + "|" + document.location.search.substr(7);
		SaveCookie("mywzone_ip",newzones,365);
	} else {
		SaveCookie("mywzone_ip",document.location.search.substr(7),365);
	}
	window.location="http://"+location.hostname+location.pathname;
}
if (document.location.search.substr(1,10)=="clearwzone") { //Zeroes out our cookie into cookie
	SaveCookie("mywzone_ip","",365);
}

// COOKIE CHECK
function qpSumbmit()
{
 /* check for a cookie */
  if (document.cookie == "") 
  {
    /* if a cookie is not found - alert user change cookieexists field value to false */
    alert("COOKIES need to be enabled!");

    /* If the user has Cookies disabled an alert will let him know that cookies need to be enabled to log on.*/ 

    document.Form1.cookieexists.value ="false";
  } else {
   /* this sets the value to true and nothing else will happen, the user will be able to log on*/
    document.Form1.cookieexists.value ="true";
    document.submit();
  }
}

/* Set a cookie to be sure that one exists. Note that this is outside the function*/
document.cookie = 'killme' + escape('nothing');


