
/* shortcut to getElementById */
function getNode(node) {
	return document.getElementById(node);
}

function swapTextNode(parentObject, newText) {
    parentObject.replaceChild(document.createTextNode(newText), parentObject.firstChild);
}

/* Replace text in a node. Has more protection than the previous version and will fall back on non-DOM techniques if it can't pick out the childNodes */
function replaceInnerText(node, text) {
	//	replacement for node.innerHTML = text; which is apparently broken in Safari 1.2.4
	if (typeof node.childNodes != "undefined" && node.childNodes.length > 0) {
		var newnode = document.createTextNode(text);
		node.replaceChild(newnode, node.firstChild);
	} else {
		// fall back on the old school just in case
		node.innerHTML = text;
	}
}

/* Destroy a node with the Death Star */
function killNode(nodeID) {
	var node = getNode(nodeID);
	var nodeParent = node.parentElement;
	if (typeof nodeParent != "undefined") {
		nodeParent.removeChild(node);
	} else {
		node.style.display = "none";
	}
}

var req;

function xmlRequest() {
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.isDOM = true;
		return req;
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		return req;
	} else 
		return null;
}

function isXMLReady(xmlObject) {
	return (xmlObject.readyState == 4 && xmlObject.status == 200);
}


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() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            // ...processing statements go here...
			var xml = req.responseXML;
//	        var movieParent = xml.getElementsByTagName("MOVIE")[0];
//        	var elementId = "b" + movieParent.getAttribute("DS") + movieParent.getAttribute("ID") + COUNT_DELIM + movieParent.getAttribute("POS");        
	        try {
				haveXml(xml);	//custom code for each page, found out in inline <script> probly.
	        } catch (e) {}
        } else {
            //alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
    }
}

