﻿// JavaScript Document
/*
This file loads the list of videos and data for the Qumu demo
required to add the 'openHttpRequest.js' to your page

When the xml finishes loading it calls an xmlIsDone() function.
Define that function on your page to capture the load & parse the XML data.
*/

// intial variable that we'll access later
var XMLHttp = null;
//var xml = null;

function loadXML(myPath) {
	
    //Open the Http Request
    XMLHttp = getXMLHttp();
    
    //Get the XML
    XMLHttp.open("GET", myPath);
    XMLHttp.onreadystatechange = handlerFunction; //call handlerFunction when ready-ness of xml changes
    XMLHttp.send(null);
}

function handlerFunction() {
	//alert("ReadyState = " + XMLHttp.readyState);
    
	if (XMLHttp.readyState == 4) {
		xml = XMLHttp.responseXML;
		var myXmlId = null;
	
		for (i=0; i <= xml.childNodes.length; i++) {
	
			if (xml.childNodes[i].nodeName == "root") {
				myXmlId = xml.childNodes[i].getAttribute("xmlId");
				break;
			} else {
				//do nothing	
			}
		}
	
		switch (myXmlId) {
			
			case "topNavXML":
				topNavXML = XMLHttp.responseXML;
				//alert("topNavXML is ready");
				break;
				
			case "featuredXML":
				featuredXML = XMLHttp.responseXML;
				//alert("featuredXML is ready");
				break;
				
			case "bandsXML":
				bandsXML = XMLHttp.responseXML;
				//alert("bandsXML is ready");
				break;
				
			case "tourDatesXML":
				tourDatesXML = XMLHttp.responseXML;
				//alert("tourDatesXML is ready");
				break;
				
			case "mediaXML":
				mediaXML = XMLHttp.responseXML;
				//alert("mediaXML is ready");
				break;
				
			case "newsXML":
				newsXML = XMLHttp.responseXML;
				//alert("newsXML is ready");
				break;
				
			case "adsXML":
				adsXML = XMLHttp.responseXML;
				//alert("adsXML is ready");
				break;
				
			case "linksXML":
				linksXML = XMLHttp.responseXML;
				//alert("linksXML is ready");
				break;
				
			case "streetXML":
				streetXML = XMLHttp.responseXML;
				//alert("streetXML is ready");
				break;
				
			case "contactXML":
				contactXML = XMLHttp.responseXML;
				//alert("contactXML is ready");
				break;
				
			case "pressXML":
				pressXML = XMLHttp.responseXML;
				//alert("pressXML is ready");
				break;
				
			case "footerXML":
				footerXML = XMLHttp.responseXML;
				//alert("footerXML is ready");
				break;
				
			default:
				//error
				break;
				
		}
        //alert(XMLHttp.responseText);
        xmlIsDone();
    }
}

//when xml is loaded update the data loaded variable
function xmlIsDone() {
	XmlLoaded ++;
	DataLoaded ++;
	loadPageData();
	//checkLoadStatus(3);
}

//this function loads the xml data 
function loadPageData() {
	//alert("load page data called: loading " + XmlToLoad[XmlLoaded]);
	
	if (XmlLoaded < XmlTotal) {
		loadXML(XmlToLoad[XmlLoaded]);
	}
	
	else if (XmlLoaded == XmlTotal) {
		checkLoadStatus(DataTotal);
	}

}
