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('