<!--
var req;
var processedSigns = new Array(12);
var signIndex;
function loadXMLDoc(url) {
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}
function processReqChange() {
var content;
    // only if req shows "complete"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            // ...processing statements go here...
            response = req.responseXML.documentElement;

            title = response.getElementsByTagName('title')[0].firstChild.data;

            signs = response.getElementsByTagName('sign');

//alert(req.responseText);
//alert(signs.length);
for (i = 0; i < signs.length; i++) {
	var signName = signs[i].attributes.getNamedItem('name').nodeValue;
	var predictionList = signs[i].getElementsByTagName('prediction')[0].childNodes;
	var linkList = signs[i].getElementsByTagName('link')[0].childNodes;
	var prediction = "";
	var link = "";
	for (n = 0; n < predictionList.length; n++) {
		tmpNodeValue = predictionList[n].nodeValue;
		if (tmpNodeValue) prediction += tmpNodeValue;
	}
	for (x = 0; x< linkList.length; x++) {
		link = linkList[x].nodeValue;
	}
//alert("Welcome " + signName + ", \n" + prediction + "\nLink: " + link);
content = "<b>" + signName + "</b><br/>" + prediction + "<br/><a href=\"" + link + "\">Link...</a>";
processedSigns[i] = content;
//alert(processedSigns[i]);
//alert(prediction);
}
        } else {
            alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
    }

   if (signIndex) content = processedSigns[signIndex];

   div = document.getElementById("myHoroscope");
   div.innerHTML = "";
   div.innerHTML = content;
}

function displayHoroscope() {
   loadXMLDoc('/publish/content/1.0/horoscopes.xml')
   var myHoro = getCookie('SaneHoroscope');
   signIndex = myHoro;
   var content = processedSigns[myHoro];
   /*div = document.getElementById("myHoroscope");
   div.innerHTML = "";
   div.innerHTML = content;*/
}

function chooseSign(event) {
    event = (event) ? event : ((window.event) ? window.event : null);
    var item, content, div;
    if (event) {
        var select = (event.target) ? event.target : ((event.srcElement) ? event.srcElement : null);
        if (select && select.options.length > 1) {
	    if (select.value) {
            	content = processedSigns[select.value];
		setCookie('SaneHoroscope', select.value, null, '/', null, null);
	    } else {
		content = "Now, listen. We'd <i>assumed</i> you knew what we meant when we said \"Choose a sign.\" Obviously, we were wrong. So what we <i>meant</i> was for you to select, from the little popup there, the sign the corresponds to the one in which you were born. If you do not know the sign in which you were born, one will either be assigned to you, or you can pick it out of <a href=\"http://www.sanemagazine.com/horoscopes.html\">the lineup here</a>. Thanks for playing.";
	    }
            	div = document.getElementById("myHoroscope");
            	div.innerHTML = "";
            	div.innerHTML = content;
        }
    }

}

function getCookie(name) {
  var arg = name + "=";
  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 setCookie (name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

//-->

