function showUpdating(whichLayer){ var elem; var vis; if( document.getElementById ) // this is the way the standards work elem = document.getElementById( whichLayer ); else if( document.all ) // this is the way old msie versions work elem = document.all[whichLayer]; else if( document.layers ) // this is the way nn4 works elem = document.layers[whichLayer]; vis = elem.style; vis.display = 'block'; } function hideUpdating(whichLayer){ var elem; var vis; if( document.getElementById ) // this is the way the standards work elem = document.getElementById( whichLayer ); else if( document.all ) // this is the way old msie versions work elem = document.all[whichLayer]; else if( document.layers ) // this is the way nn4 works elem = document.layers[whichLayer]; vis = elem.style; vis.display = 'none'; if(wxAjax.getPopLock()) wxAjax.setPopLock(false); } function clearQueryField() { if (document.getElementById('goodzip').value == "Zip Code or City") { document.getElementById('goodzip').value = ""; } } function fillQueryField() { if (document.getElementById('goodzip').value == "") { document.getElementById('goodzip').value = "Zip Code or City"; } } function resetQueryField() { document.getElementById('goodzip').value = "Zip Code or City"; document.getElementById('wthrChangeCityButton').focus(); } function swapNodes(node1, node2) { var itemtmp = node1.cloneNode(1); var parent = node1.parentNode; node2 = parent.replaceChild(itemtmp, node2); parent.replaceChild(node2, node1); parent.replaceChild(node1,itemtmp); itemtmp = null; } function moveUp(_userId, moduleId, modDiv) { if(wxAjax.getButtonLock()){ showUpdating('weatherUpdating'); return; } var elem = document.getElementById(modDiv); var elemParent = elem.parentNode; var parentDiv = elemParent.parentNode; var modulePosition = parseInt(elemParent.id.substring('weatherModule'.length)); if (modulePosition > 1) { wxAjax.setButtonLock(true); var swapIndex = modulePosition - 1; var swapDivId = 'weatherModule' + swapIndex.toString(); var toSwap = document.getElementById(swapDivId); toSwap.setAttribute('id', elemParent.id); elemParent.setAttribute('id', swapDivId); swapNodes(elemParent, toSwap); WeatherAjax.moveUp(_userId, moduleId, dwrCallback); } } function moveDown(_userId, moduleId, modDiv){ if(wxAjax.getButtonLock()){ showUpdating('weatherUpdating'); return; } var elem = document.getElementById(modDiv); var elemParent = elem.parentNode; var parentId = elemParent.id; var modulePosition = parentId.substring('weatherModule'.length); if (modulePosition < wxAjax.getModuleCount()){ wxAjax.setButtonLock(true); var swapIndex = ++modulePosition; var divName2 = 'weatherModule' + swapIndex.toString(); var toSwap = document.getElementById(divName2); elemParent.setAttribute('id', divName2); toSwap.setAttribute('id', parentId); swapNodes(toSwap, elemParent); WeatherAjax.moveDown(_userId, moduleId, dwrCallback); } } function dwrCallback(){ if(wxAjax.getButtonLock()){ wxAjax.setButtonLock(false); hideUpdating('weatherUpdating'); } } function removeMod(_userId, moduleId, modDiv){ if(wxAjax.getButtonLock()){ showUpdating('weatherUpdating'); return; } wxAjax.setButtonLock(true); WeatherAjax.removeModule(_userId, moduleId, handleRemoveModules); newCount = wxAjax.getModuleCount() - 1; wxAjax.setModuleCount(newCount); } function handleRemoveModules(str) { WeatherAjax.refreshModules(wxAjax.userId, wxAjax.getCurrentZip(), wxAjax.siteName, wxAjax.siteURL, handleRefreshModules); } function addModules(_userId) { var myForm = document.getElementById('addmodules'); var inputs = myForm.getElementsByTagName('input'); var moduleArr = new Array(); for (var i = 0; i < inputs.length; i++){ if (inputs[i].checked){ var inId = inputs[i].name; var index = inId.indexOf("_"); index++; inId = inId.substring(index); moduleArr.push(inId); } if(inputs[i].name == 'newZip'){ var newZip = inputs[i].value; if(newZip.length > 0) { if(!validateZipFromOverlay()){ alert('Please enter a 5 digit zip code only'); return false; } wxAjax.setCurrentZip(newZip); updatePrimaryZip(_userId, newZip); } } } wxAjax.setPopLock(true); WeatherAjax.addModules(_userId, moduleArr, wxAjax.getCurrentZip(), wxAjax.siteName, wxAjax.siteURL, handleAddModules); hideUpdating('newWeatherOverlay'); } function updatePrimaryZip(_userId, zipCode){ wxAjax.setPopLock(true); WeatherAjax.updatePrimaryZipCode(_userId, zipCode); WeatherAjax.getWeather(zipCode, wxAjax.siteName, wxAjax.siteURL, handleGetWeather); } function handleAddModules(str) { WeatherAjax.refreshModules(wxAjax.userId, wxAjax.getCurrentZip(), wxAjax.siteName, wxAjax.siteURL, handleRefreshModules); } function validateZip() { var value = document.getElementById('goodzip').value; if (value.length == 5 && value.match(/^\d+$/)) { return true; } else if (value.match(/[a-z,A-Z]+, *[a-z,A-Z]/)) { return true; } return false; } function getWeather(siteName, siteURL) { if (!validateZip()){ alert("Please enter a 5 digit zip code or a city name followed by a comma and state abbreviation."); return; } wxAjax.setPopLock(true); var cityZip = document.getElementById('goodzip').value; WeatherAjax.getWeather(cityZip, wxAjax.siteName, wxAjax.siteURL, handleGetWeather); resetQueryField(); } function handleRefreshModules(str) { var jsonObj = str.evalJSON(); var moduleLength = jsonObj.length; wxAjax.setModuleCount(moduleLength); for(i = 1; i <= wxAjax.totalDivCount; i++) { divName = 'weatherModule' + i.toString(); curMod = document.getElementById(divName); Element.extend(curMod); if (i <= moduleLength) { var module = jsonObj[i - 1]; curMod.update(module); } else { curMod.update(''); } } wxAjax.setPopLock(false); dwrCallback(); } function handleGetWeather(str) { var jsonObj = str.evalJSON(); var weatherErr = jsonObj.error; var weatherAlert = jsonObj.alert; var weatherTable = jsonObj.tabledata; var weatherZip = jsonObj.zip_code; var weatherCity = jsonObj.city; var radarURL = jsonObj.radar; wxAjax.setCurrentZip(weatherZip); var city = document.getElementById('_cityname'); Element.extend(city); var tbl = document.getElementById('tableData'); Element.extend(tbl); var alerts = document.getElementById('wthrBreakingAlert'); Element.extend(alerts); if(weatherErr.length > 0){ city.update(weatherErr); tbl.update(''); alerts.update(''); alerts.hide(); } else { city.update('

' + weatherCity + '

'); var radar = document.getElementById('wthrMapImage'); Element.extend(radar); alerts.update(weatherAlert); if(weatherAlert.length > 0){ alerts.show(); } else { alerts.hide(); } tbl.update(weatherTable); dynamicCity = weatherCity; dynamicDisp = radarURL; doRadarTab(); radar.update(''); } WeatherAjax.refreshModules(wxAjax.userId, wxAjax.getCurrentZip(), wxAjax.siteName, wxAjax.siteURL, handleRefreshModules); } function getOverlayHTML(_userId) { if (wxAjax.getPopLock()) { return; } WeatherAjax.getOverlayHTML(_userId, handleGetOverlay); } function handleGetOverlay(str) { var overlay = document.getElementById('newWeatherOverlay'); Element.extend(overlay); var checkBoxes = document.getElementById('moduleCheckboxes'); Element.extend(checkBoxes); checkBoxes.update(str); Element.show(overlay); wxAjax.setPopLock(true); } function checkEnter(e){ //e is event object passed from function invocation var characterCode; //literal character code will be stored in this variable if(e && e.which) { //if which property of event object is supported (NN4) characterCode = e.which; //character code is contained in NN4's which property } else { characterCode = e.keyCode; //character code is contained in IE's keyCode property } if(characterCode == 13 || characterCode == 3){ //if generated character code is equal to ascii 13 (if enter key) getWeather(wxAjax.sitename, wxAjax.siteURL); resetQueryField(); return false; } else { return true; } } function checkOverLayEnter(e){ //e is event object passed from function invocation var characterCode; //literal character code will be stored in this variable if(e && e.which) { //if which property of event object is supported (NN4) characterCode = e.which; //character code is contained in NN4's which property } else { characterCode = e.keyCode; //character code is contained in IE's keyCode property } if(characterCode == 13 || characterCode == 3){ //if generated character code is equal to ascii 13 (if enter key) addModules(wxAjax.userId); hideUpdating('newWeatherOverlay'); return false; } else { return true; } } function validateZipFromOverlay() { var value = document.getElementById('newZip').value; if (value.length == 5 && value.match(/^\d+$/)) { return true; } else { return false; } } function getURLogin(){ var login = wxAjax.getDestURL() + URLEncode(window.location.pathname); document.location.href=login; } function URLEncode(toEncode ){ var SAFECHARS = "0123456789" + // Numeric "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic "abcdefghijklmnopqrstuvwxyz" + "-_.!~*'()"; // RFC2396 Mark characters var HEX = "0123456789ABCDEF"; var plaintext = toEncode; var encoded = ""; for (var i = 0; i < plaintext.length; i++ ) { var ch = plaintext.charAt(i); if (ch == " ") { encoded += "+"; } else if (SAFECHARS.indexOf(ch) != -1) { encoded += ch; } else { var charCode = ch.charCodeAt(0); if (charCode > 255) { alert( "Unicode Character '" + ch + "' cannot be encoded using standard URL encoding.\n" + "(URL encoding only supports 8-bit characters.)\n" + "A space (+) will be substituted." ); encoded += "+"; } else { encoded += "%"; encoded += HEX.charAt((charCode >> 4) & 0xF); encoded += HEX.charAt(charCode & 0xF); } } } // for return encoded; } function fixTimes(){ var spanTag; if(document.getElementById('wthrDaylightBody')){ var daylight = document.getElementById('wthrDaylightBody'); var divArray = daylight.getElementsByTagName('span'); for (var i = 0; i < divArray.length; i++){ if(i == 1 || i == 3){ spanTag = divArray[i]; Element.extend(spanTag); var wrongTime = spanTag.innerHTML.toString(); var rightTime = wrongTime.replace(/AM/, "PM"); spanTag.update(rightTime); } } } }