onerror=handleErr;

function handleErr(msg,url,l)
{

return true;
}


function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  return false;
}
var noCookie = getQueryVariable("noCookie");
weather_station = 'KLGU';       // default to Logan
function update_weather()
{
	if (!noCookie ) {
   var weathercookie = getCookie("StationCookie");
   var coopStationCookie = getCookie("coopSC");
   var stID = getCookie("stIDeikooc");//if the station id has been submitted on rightnavbar with enter station id
	}
	else{
    deleteCookie("StationCookie");
    deleteCookie("coopSC");
    deleteCookie("stIDeikooc");
	var weathercookie = getQueryVariable("stn");
	var stID = getQueryVariable("stIDeikooc");
	var coopStationCookie = weathercookie;
	}
	
   if(weathercookie && weathercookie.length > 0 ) {
      // update web element every 10 minutes
      setTimeout("update_weather()",600000);
		
      if (noCookie == 1){
       url = '/includes/element.php?noCookie=1';
   		}
   	 else{       
   	 url = '/includes/element.php';}
     

      if(stID && stID.length > 0) {//if the stid has been entered
         if (coopStationCookie && coopStationCookie.length > 0) {//if coop cookie set need to save incase back trace
            var pars = 'stn=' + weathercookie + '&coopSC=' + coopStationCookie + '&stIDeikooc=' + stID;
         } else {//just stid and save weather cookie
            var pars = 'stn=' + weathercookie + '&stIDeikooc=' + stID;
         }
      } else if (coopStationCookie && coopStationCookie.length > 0) {//no st id just coop and weather cookie
         var pars = 'stn=' + weathercookie + '&coopSC=' + coopStationCookie;
      } else {//just weather cookie nothing else
         var pars = 'stn=' + weathercookie;
      }

      /*
      if(coopStationCookie && coopStationCookie.length > 0) {
         var pars = 'stn=' + weathercookie + '&coopSC=' + coopStationCookie;
      } else {
         var pars = 'stn=' + weathercookie;
      }
      */
      new Ajax.Updater(
            'weather',
            url,
            {
               method: 'post',
               parameters: pars
            });
   } else {
      deleteCookie("StationCookie");
      deleteCookie("coopSC");
      deleteCookie("stIDeikooc");
      setCookie("StationCookie", weather_station, 30);
      update_weather();
   }
}
update_weather();

function changeLocation(wform)
{
   $('lochoose').style.display = 'none';
   var station = wform.wtext.value;
   var temp_weather_station = station.toUpperCase();
   deleteCookie("stIDeikooc");
   setCookie("stIDeikooc", temp_weather_station, 30);
   update_weather();
}

function closeid() {
  $('lochoose').style.display = 'none';
  $('change_location').style.display = 'inline';
}

function openChanger()
{
  $('selection').style.display = 'none';
  $('lochoose').style.display = 'inline'; 
}

function openSelection()
{
   $('change_location').style.display = 'none';
   $('selection').style.display = 'inline';
}

/***********************************************
* Disable "Enter" key in Form script- By Nurul
* Fadilah(nurul@volmedia.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
* This script has also been modified by Aaron Gelter
***********************************************/
function handleEnter (field, event) 
{
   //if(document.wchoose.wtext.value.length != 4) return true;
   if(document.getElementById('wchoose').wtext.value.length != 4) return true;
   var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
   if (keyCode == 13) {
      var i;
      for (i = 0; i < field.form.elements.length; i++)
         if (field == field.form.elements[i])
            break;
      i = (i + 1) % field.form.elements.length;
      field.form.elements[i].focus();
      return false;
   } 
   else
      return true;
}

//This functions opens the google map window
function open_map_win()
{
   window.open("/includes/weathermap.php","","width=600, height=650,scrollbars=no,toolbar=no,location=no,menubar=no");
}

//This function opens an optional google window
function google_support() {
   window.open("/includes/footer.inc.php","","width=670, height=900, scrollbar=no, toolbar=no, location=no, menubar=no");
}

