/*
* This file reads the news_sched.xml file and displays its contents.
* author:V.Sendling-Ortiz, vivortiz@yahoo.com
*/
var isFireFox = (!document.layers) && (navigator.userAgent.indexOf('Firefox')!=-1)?true:false;
var xmlFile = "xml/news_sched.xml";
var xmlDoc;
var isFullSchedule = false;
var schedCount;

//Is IE or Firefox?
if (isFireFox){
	//Create an instance of the XML parser in Mozilla browsers
	//namespace, root, file
	xmlDoc=document.implementation.createDocument("","",null);
	xmlDoc.load(xmlFile);
}else{
	xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
}


//Print full shedule?
function setFullSchedule(inShort){
	isFullSchedule = inShort;
}
//Loads XML file
function loadXML(xmlFile, inRetText)
{  
  if (isFireFox){
	xmlDoc.async="false";
	xmlDoc.onreadystatechange=verify;	
	xmlObj=xmlDoc.documentElement; //root element 
  }else{
	xmlDoc.async="false";
	xmlDoc.onreadystatechange=verify;
	xmlDoc.load(xmlFile);
	xmlObj=xmlDoc.documentElement; //root element 
  }
  try{	
	if (inRetText){			
	}else{
		displayXML();
	}
  }
  catch(e){
	document.write("<a href='schedule.htm' style='color:white'><u>Click here</u></a> to see full schedule.");
    //document.write ("<BR><font color=red>Problem displaying XML file (check font non-friendly symbols): " + e.message + "</font><BR><HR>")
  }
}

//Verifies
function verify()
{
  // 0 Object is not initialized
  // 1 Loading object is loading data
  // 2 Loaded object has loaded data
  // 3 Data from object can be worked with
  // 4 Object completely initialized
  if (xmlDoc.readyState != 4)
  {
		return false;
  }else{
		//alert(xmlDoc.readyState);
  }
}

//Displays XML file contents
function displayXML(){	
    var schedCount = xmlObj.childNodes.length;
	var displayCount;	
	var isShowFullText = false;
		
	if (isFullSchedule){
		if (schedCount == 0){
			document.write("There are currenly no events scheduled. Please check back again.");
			return;
		}
		displayCount = schedCount;
		isShowFullText = true;
	}else{
		if (schedCount < 2){
			displayCount = 1
		}else{
			displayCount = 2;
		}
	}
	
	//will loop thru from top top bottom XML file.
	for (i=0;i<displayCount;i++)
	{			
		//get scheduled dates
		var x=xmlDoc.getElementsByTagName('schdate');
		var strNodeValue = x[i].childNodes[0].nodeValue;		
		document.write("<h3>" + strNodeValue + "</h3>");		
		
		
		//get scheduled times
		var x=xmlDoc.getElementsByTagName('schtime');
		document.write("<p>");
		document.write("<li>");
		var strNodeValue = x[i].childNodes[0].nodeValue;
		document.write(strNodeValue);
		
		document.write(" - ");
		
		//get scheduled information
		var x=xmlDoc.getElementsByTagName('schtextloc');
		var strNodeValue = x[i].childNodes[0].nodeValue;		
		document.write(strNodeValue);
		
		//show full schedule description text?\
		if (isShowFullText){
			var x=xmlDoc.getElementsByTagName('schtext');
			var strNodeValue = x[i].childNodes[0].nodeValue;		
			document.write(": " + strNodeValue);
		}
		document.write("</li>");
		document.write("</p>");	
		
		if (isShowFullText){		
			document.write("<hr>");
		}
	}	
}

//
function setFileNodeCount(inSchedCount){
	schedCount = inSchedCount;
}
function getFileNodeCount(){
	return schedCount;
}

//Only return text without formating
function returnText(){ 
    var schedCount = xmlObj.childNodes.length;
	var displayCount = schedCount;
	var isShowFullText = false;
	var outString = "";
	
	setFileNodeCount(schedCount);	
	
	//will loop thru from top top bottom XML file.
	for (i=0;i<displayCount;i++)
	{			
		//get scheduled dates
		var x=xmlDoc.getElementsByTagName('schdate');
		var strNodeValue = x[i].childNodes[0].nodeValue;
		if (outString == ""){
			outString = strNodeValue;
		}else{
			outString = outString + strNodeValue;
		}		
				
		//get scheduled times
		var x=xmlDoc.getElementsByTagName('schtime');		
		var strNodeValue = x[i].childNodes[0].nodeValue;
		outString = outString + "| " + strNodeValue;
		
		//get scheduled information
		var x=xmlDoc.getElementsByTagName('schtextloc');
		var strNodeValue = x[i].childNodes[0].nodeValue;		
		outString = outString + "| " + strNodeValue;
				
		//get scheduled text
		var x=xmlDoc.getElementsByTagName('schtext');
		var strNodeValue = x[i].childNodes[0].nodeValue;
		outString = outString + "| " + strNodeValue + ";";		
	}
	
	outString = outString.split(";");
	
	return outString;
}