// JavaScript Document

/**************************************************************************
	BLOG DATA FEEDER 1
**************************************************************************/

// global flag
var isIE = false;
// global request and XML document objects
var req;
// retrieve XML document (reusable generic function);
// parameter is URL string (relative or complete) to
// an .xml file whose Content-Type is a valid XML
// type, such as text/xml; XML source must be from
// same domain as HTML file
function loadXMLDoc(url) {
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", 'http://www.callansolem.com/modx/blog/rss.xml', true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", 'http://www.callansolem.com/modx/blog/rss.xml', true);
            req.send();
        }
    }
}
// handle onreadystatechange event of req object
function processReqChange() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            getmessage();
         } else {
            alert("There was a problem retrieving the XML data: Try refreshing the page.\n" +
                req.statusText);
         }
    }
}

// display info
function getmessage() {
	
//document.getElementById("blogName").innerHTML=req.responseXML.getElementsByTagName("title")[0].firstChild.nodeValue;
//document.getElementById("blogName").innerHTML=req.responseXML.getElementsByTagName("title")[0].childNodes[0].nodeValue;
//truncate description
var len = 180;
var shortDescrip = req.responseXML.getElementsByTagName("description")[1].childNodes[0].nodeValue.replace(/(<([^>]+)>)/ig,"");
if (shortDescrip.length > len) {
	shortDescrip = shortDescrip.substring(0, len);
	shortDescrip = shortDescrip.replace(/\w+$/, '');
}
document.getElementById("blogDescription").innerHTML=shortDescrip;
}