// This is used to read XML files
function importXML(fileName, actionFunction)
{
	/*
		Import XML and load it contents
		@param fileName: name of XML file
	*/
	if (document.implementation && document.implementation.createDocument) // Mozilla
	{
		xmlDoc = document.implementation.createDocument("", "", null);
		if(actionFunction == 'quote'){
			xmlDoc.onload = travelQuotes;
		}
		else if(actionFunction == 'facts'){
			xmlDoc.onload = countryFacts;
		}
	}
	else if (window.ActiveXObject) // IE
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.onreadystatechange = function () 
		{
			if (xmlDoc.readyState == 4)
			{
				if(actionFunction == 'quote'){
					travelQuotes();
				}
				else if(actionFunction == 'facts'){
					countryFacts();
				}
			}
		};
 	}
	else // Other Browser
	{
		window.alert('Your browser can\'t handle this script');
		return;
	}
	xmlDoc.load(fileName);
}

function travelQuotes()
{
	/*
		Display random travel quote from travel_quote.xml file
	*/
	var contents = xmlDoc.getElementsByTagName('qContent');
	var authors = xmlDoc.getElementsByTagName('qAuthor');
	
	var displayNum = Math.floor(Math.random()*contents.length);	
	document.getElementById('quoteContent').innerHTML = contents[displayNum].childNodes[0].nodeValue;
	document.getElementById('quoteAuthor').innerHTML = authors[displayNum].childNodes[0].nodeValue;
	
}

function countryFacts()
{
	/* 
		Display facts of countries in XML file
	*/
		
	var cName = xmlDoc.getElementsByTagName('name');
	var cImg = xmlDoc.getElementsByTagName('displayImg');
	var cArea = xmlDoc.getElementsByTagName('area');
	var cPopulation = xmlDoc.getElementsByTagName('population');
	var cCapital = xmlDoc.getElementsByTagName('capital');
	var cPeople = xmlDoc.getElementsByTagName('people');
	var cLanguage = xmlDoc.getElementsByTagName('language');
	var cReligion = xmlDoc.getElementsByTagName('religion');
	var cIndustries = xmlDoc.getElementsByTagName('majorIndust');
	var cLinks = xmlDoc.getElementsByTagName('links');
	
	for(i=0; i < cName.length; i++)
	{
		
		document.getElementById('factContainer').innerHTML += 
			"<p><font class=\"hightlightText\" style=\"font-size:13px; text-decoration:underline;\">" 
				+ cName[i].childNodes[0].nodeValue +  "</font> <br> "
				+ "<b>Area:</b> "+ cArea[i].childNodes[0].nodeValue +" <br> <b>Population:</b> "
				+ cPopulation[i].childNodes[0].nodeValue +"<br>"				
				+ "<b>Capital:</b> "+ cCapital[i].childNodes[0].nodeValue + "<br>"
				+ "<b>People:</b> "+ cPeople[i].childNodes[0].nodeValue +" <br>"
				+ "<b>Language:</b> "+ cLanguage[i].childNodes[0].nodeValue +" <br>"
				+ "<b>Religion:</b> "+ cReligion[i].childNodes[0].nodeValue +" <br>"
				+ "<b>Major Industries:</b> "+ cIndustries[i].childNodes[0].nodeValue + "<br>"				
				+ "</p>"
				+ "<img src=\"images/country_facts/"+ cImg[i].childNodes[0].nodeValue +"\" />";
				
				//+ "<a href=\""+ cLinks[i].childNodes[0].nodeValue +"\" > More Information </a>"
	} //end of display information
	
	if(cName.length == 0) // if there is no country listed
	{
		document.getElementById('factContainer').innerHTML += "<p class=\"confirm\"><br><br>Coming Soon</p>";
	}
}