var analyticsID = "UA-6110864-6";
//// Track this gadget using Google Analytics.
_IG_Analytics(analyticsID, "/seasonal_load");
_IG_RegisterOnloadHandler(loadData);
var myLocId;
var myPerId;
var locList;
var perList;
var myLocState = "New York";
//
var IGx;
var prefs = new gadgets.Prefs();;
var myLocState = prefs.getString('myState');
var siteBase = "http://gadgets.fourthfloorequipment.com/";
var targetURL = siteBase + "cgi-bin/seasonaldata.cgi";
// initializing function.
// called when the gadget is loaded.
function loadData(){
var url = targetURL + "?act=load_all&state=" + myLocState.replace(/ /g, "+");
_IG_FetchXmlContent(url, loadAllResponse);
_IG_Analytics(analyticsID, "/" + myLocState.replace(/ /g, "+"));
_gel("RegionText").innerHTML = myLocState;
}
//
// callback function from loadData
function loadAllResponse(obj){
var xmlDoc = obj;
myLocId = try_el(xmlDoc, "current_loc", 0)
myPerId = try_el(xmlDoc, "current_per", 0)
locList = xmlDoc.getElementsByTagName("locationlist")[0];
perList = xmlDoc.getElementsByTagName("periodlist")[0];
if (locList == null){
alert("location list is null");
}
if (myLocId == null){
alert("location id is null");
}
processLocations(locList, myLocId);
LoadSeasonSelector(perList, myPerId);
ShowData(perList, myPerId);
}
// loadRegionalResponse
function loadRegionalResponse(obj){
// var xmlDoc = obj.data;
var xmlDoc = obj;
myLocId = xmlDoc.getElementsByTagName("current_loc")[0].firstChild.data;
perList = xmlDoc.getElementsByTagName("periodlist")[0];
myPerId = _gel("period").value;
ShowData(perList, myPerId);
}
// ShiftSeason
function shiftSeason(){
_IG_Analytics(analyticsID, "/season_change");
myPerId = _gel("period").value;
ShowData(perList, myPerId);
_gel('content').scrollTop = 0;
hidePeriodSelector();
_gel("PeriodText").innerHTML = _gel("period").options[_gel("period").selectedIndex].text;
}
// ShiftRegion
function shiftRegion(){
myLocState = _gel("region").value;
var url = targetURL + "?act=load_all&state=" + myLocState.replace(/ /g, "+");
_IG_FetchXmlContent(url, loadRegionalResponse);
_IG_Analytics(analyticsID, "/" + myLocState.replace(/ /g, "+"));
_gel("RegionText").innerHTML = myLocState;
hideRegionSelector();
}
// ShowData
// Shows the items listed for the current period
//
function ShowData(PeriodNode, myPerId){
var nodeChild = PeriodNode.firstChild;
var thisPeriod;
while (nodeChild){
if (nodeChild.nodeType != 1 || nodeChild.getElementsByTagName("periodid")[0].firstChild.data != myPerId){
nodeChild=nodeChild.nextSibling;
continue;
}
itemList = nodeChild.getElementsByTagName("itemlist")[0];
OutputContent(itemList);
break;
}
}
function OutputContent(itemList){
var output = "";
var counter = 0;
var thisItem = itemList.firstChild;
while (thisItem){
if (thisItem.nodeType != 1 ){
thisItem=thisItem.nextSibling;
continue;
}
var myImg = "";
var myName = thisItem.getElementsByTagName("name")[0].firstChild.data;
var myItemId = thisItem.getElementsByTagName("item_id")[0].firstChild.data;
if (thisItem.getElementsByTagName("image")[0].firstChild == null ||
thisItem.getElementsByTagName("image")[0].firstChild.data == " "){
myImg = '';
} else {
myImg = '';
}
output += '';
counter++;
thisItem=thisItem.nextSibling;
}
if (counter == 0){
ads = new Array(
'',
'',
''
)
output = 'Nothing is in season at this time. But get ready with this great book
' + ads[Math.floor(Math.random()*ads.length)];
}
_gel("content").innerHTML = output;
// gadgets.window.adjustHeight();
}
// LoadSeasonSelector
// takes the period trunk and loads the select box
//
function LoadSeasonSelector(PeriodNode, thisPeriod){
var nodeChild = PeriodNode.firstChild;
while (nodeChild){
if (nodeChild.nodeType != 1){
nodeChild=nodeChild.nextSibling;
continue;
}
var y=document.createElement('option');
y.text=nodeChild.getElementsByTagName("name")[0].firstChild.data;
y.value=nodeChild.getElementsByTagName("periodid")[0].firstChild.data;
if (y.value == thisPeriod){
_gel("PeriodText").innerHTML = y.text;
y.selected = true;
}
var x=_gel("period");
try {
x.add(y,null); // standards compliant
} catch(ex) {
x.add(y); // IE only
}
nodeChild=nodeChild.nextSibling;
}
}
//
// processLocations
// takes the location list portion of the response tree and
// loads it into the document
function processLocations(LocListNode, myLocId){
var LocListChild = LocListNode.firstChild;
var i =0;
while (LocListChild){
if (LocListChild.nodeType != 1){
LocListChild=LocListChild.nextSibling;
continue;
}
var x=_gel("region");
var y=document.createElement('option');
y.text=LocListChild.getElementsByTagName("loc_long")[0].firstChild.data;
y.value=LocListChild.getElementsByTagName("loc_long")[0].firstChild.data;
try {
x.add(y,null); // standards compliant
} catch(ex) {
x.add(y); // IE only
}
if (LocListChild.getElementsByTagName("loc_id")[0].firstChild.data == myLocId){
x.selectedIndex = i;
}
LocListChild=LocListChild.nextSibling;
i++;
}
}
// showRegionSelector
//
function showRegionSelector(){
_gel("RegionSelector").style.display = "inline";
_gel("RegionText").style.display = "none";
}
// hideRegionSelector
//
function hideRegionSelector(){
_gel("RegionSelector").style.display = "none";
_gel("RegionText").style.display = "inline";
}
// showPeriodSelector
//
function showPeriodSelector(){
_gel("PeriodSelector").style.display = "inline";
_gel("PeriodText").style.display = "none";
}
// hidePeriodSelector
//
function hidePeriodSelector(){
_gel("PeriodSelector").style.display = "none";
_gel("PeriodText").style.display = "inline";
}
function hiliteItem(divObj){
divObj.style.border = "1px dotted #FF99FF";
}
function unhiliteItem(divObj){
divObj.style.border = "1px dotted #FFFFFF";
}
function try_el(xmlDoc, nodeName, i){
result = "";
try{
result = xmlDoc.getElementsByTagName(nodeName)[i].firstChild.data;
} catch(e){
}
return result;
}
// log_clicker
//
function log_clicker(item){
_IG_Analytics(analyticsID, "/click/" + item);
// alert(item);
}
]]>