// JavaScript Document

function getXMLHttpRequest()
{
	var myXMLRequest;      // BT/BG REVISED for Safarai compliance. Aug 2009.
	
	if (window.ActiveXObject) {
		try 
		{ myXMLRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (except)
		{ try { myXMLRequest = new ActiveXObject("Microsoft.XMLHTTP"); }
		  catch(except) { alert("Your browser does not support XML-HTTP requests"); }
		}
	} else if (window.XMLHttpRequest) {
		myXMLRequest = new XMLHttpRequest();
	} else {
		alert("Your browser does not support XML-HTTP requests");
	}
	
	return myXMLRequest;		
}

   function showOver(which){
		if(document.all){
			document.all.refreshOver.style.left = "490px";
			document.all.refreshOver.style.top = "525px";
			document.all.refreshOver.style.display = "block";
			//alert(which);
		}
	}
	function hideOver(){
		if(document.all){
			document.all.refreshOver.style.display = "none";
			//alert(which);
		}
	}
	
	function showThis(id)
	{
		document.getElementById(id).style.display = "block";
	}
	
	function hideThis(id)
	{
		document.getElementById(id).style.display = "none";
	}
	
	function refreshPage(){
		window.location.reload( false );
	}
	
	function playNarration(file,bumper){
		//audio sources need to be changed for production!
		//var thisSlide = parseInt(frame);
		if (file!="#")
		{
			var test;
			if (navigator.userAgent.indexOf("MSIE")!=-1)
			{
				//test = document.plugins.namedItem("ShockwaveFlash")!=null ? true : false;
				try {
					var x = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
					if (typeof(x)!="undefined") {
						test = true;
						x = null;
					}
				}
				catch (e) {
					test = false;
				}
	
				//alert("value of MSIE test is: "+test);
			}
			else
			{
				test = navigator.mimeTypes["application/x-shockwave-flash"]!=null ? true : false;
			}
			if (test)
			{
				if (connection=="high")
				{
					//window.alert("Flash supported.");
					var flashvars = "audiopath=../audio/"+file;
					if (bumper!=null)
					{
						flashvars += "&audiobumper=../audio/"+bumper;
					}
					var swfobject = new FlashTag("../audio/audiostreamplayer.swf?timestamp="+new Date().getTime(),"1","1");
					swfobject.setVersion("7,0,0,0");
					swfobject.setId("audio_player");
					swfobject.setFlashvars(flashvars);
					document.getElementById("narration").style.display="inline";
					document.getElementById("narration").innerHTML = swfobject.toString();
					//window.alert(swfobject.toString());
				}
				else
				{
					//window.alert("Flash supported.");
					var flashvars = "audiopath=../audio_low/"+file;
					if (bumper!=null)
					{
						flashvars += "&audiobumper=../audio_low/"+bumper;
					}
					var swfobject = new FlashTag("../audio_low/audiostreamplayer.swf?timestamp="+new Date().getTime(),"1","1");
					swfobject.setVersion("7,0,0,0");
					swfobject.setId("audio_player");
					swfobject.setFlashvars(flashvars);
					document.getElementById("narration").style.display="inline";
					document.getElementById("narration").innerHTML = swfobject.toString();
					//window.alert(swfobject.toString());
				}
			}
			else
			{
				//window.alert("Flash not supported.");
				document.getElementById("narration").style.display="inline";
				document.getElementById("narration").innerHTML = "<embed src=\"../audio_low/"+file+"\" autostart=\"true\" loop=\"false\" hidden=\"true\" />";
			}
		}
		else
		{
			stopNarration();
		}
	}
	
	function stopNarration(){
		document.getElementById("narration").style.display="none";
		document.getElementById("narration").innerHTML = "";
		//window.alert("stopNarration called: "+document.getElementById("narration").innerHTML);
	}
	
	function sendContent(which)
	{
		var content = document.getElementById("copy"+which).innerHTML;
		return content;
	}
	
	function showLoader()
	{
		var loadDiv = document.createElement("DIV");
		loadDiv.setAttribute("id", "loading");
		loadDiv.setAttribute("class", "loading");
		var loadBoxDiv = document.createElement("DIV");
		loadBoxDiv.setAttribute("id","loadingBox");
		loadBoxDiv.setAttribute("class","loadingBox");
		loadBoxDiv.innerHTML = "<strong>Loading... Please Wait.</strong>";
		document.getElementById("wrapper").appendChild(loadDiv);
		document.getElementById("wrapper").insertBefore(loadBoxDiv,loadDiv);
	}
	
	function buildHelpPopup()
	{
		var docWrapper = document.getElementById("wrapper");
		var helpWrapperDiv = document.createElement("DIV");
		helpWrapperDiv.setAttribute("id","helpWrapper");
		docWrapper.appendChild(helpWrapperDiv);
		
		var helpScreenDiv = document.createElement("DIV");
		helpScreenDiv.setAttribute("id","helpScreen");
		
		docWrapper.insertBefore(helpScreenDiv,helpWrapperDiv);
		//helpWrapperDiv.appendChild(helpScreenDiv);
		
		try
		{		
			loadHelpContent(helpScreenDiv);
			helpWrapperDiv.style.display = "inline";
			helpScreenDiv.style.display = "inline";
		}
		catch (e)
		{
			document.getElementById("helpScreen").innerHTML = "Help content did not load";			
			helpWrapperDiv.style.display = "inline";
			helpScreenDiv.style.display = "inline";
		}
		
	}
	
	function loadHelpContent(targetDiv)
	{
		var content;
		var myXML = getXMLHttpRequest();
		myXML.open("GET","../help/popuphelp.html");
		
		myXML.onreadystatechange = function()
		{
			if(myXML.readyState == 4 && myXML.status == 200)
			{
				targetDiv.innerHTML = myXML.responseText;
			}
		}
		myXML.send(null);
	}
	
	function showHelpPopup()
	{
		var helpDiv = (document.getElementById("helpWrapper")!=null) ? document.getElementById("helpWrapper") : null;
		if (helpDiv==null)
		{
			buildHelpPopup();
		}
		else
		{
			document.getElementById("helpWrapper").style.display = "inline";
			document.getElementById("helpScreen").style.display = "inline";
		}
		
	}
	
	function hideHelpPopup()
	{
		document.getElementById("helpScreen").style.display = "none";
		document.getElementById("helpWrapper").style.display = "none";
	}
		
	function showLoaderAlt()
	{
		document.getElementById("loading").style.display = "inline";
		document.getElementById("loadingBox").style.display = "inline";
	}
	
	function hideLoaderAlt()
	{
		document.getElementById("loading").style.display = "none";
		document.getElementById("loadingBox").style.display = "none";
	}
	
	function showAllContent(pageName)
	{
		var myXML = getXMLHttpRequest();
		myXML.open("GET",pageName+".xml");
		//myXML.setRequestHeader("Accept","text/*");		
		//myXML.open("GET",pageName+"_inc.html");
		myXML.onreadystatechange = function()
		{
			if (myXML.readyState == 4 && myXML.status == 200)
			{
				var response = (myXML.responseXML!=null) ? myXML.responseXML : myXML.responseText;
				var slides = response.getElementsByTagName("slide");
				var content = "";
				var which
				for (i=0; i < slides.length; i++)
				{
					content += slides[i].firstChild.nodeValue;
				}
					document.getElementById("contentContainer").innerHTML = content;
					//document.getElementById("contentContainerTop").focus();					
			}
			//else clause is for debugging purposes only!
			else
			{
				document.getElementById("contentContainer").innerHTML = "error";
			}
		}
		myXML.send(null);		
	}
		
	function showContent(which){
		
		//buildLoader();
		//showLoaderAlt();
		var currentSlide = parseInt(which);
		createPageNav(currentSlide);
		
		var myXML = getXMLHttpRequest();	
		myXML.open("GET",pageName+".xml",true);
		//myXML.setRequestHeader("Accept","text/*");
		//myXML.setRequestHeader("Content-Type","text/html");
		myXML.onreadystatechange = function()
		{
			if (myXML.readyState == 4 && myXML.status == 200)
			{
				//showLoader();
				var response = (myXML.responseXML!=null) ? myXML.responseXML : myXML.responseText;
				var slides = response.getElementsByTagName("slide");
				for (i=0; i < slides.length; i++)
				{
					ID = slides[i].getAttributeNode("ID").nodeValue;
					if (ID == "copy"+which)
					{
						var content = slides[i].firstChild.nodeValue;
						var audio = "#";
						var audiofiles = slides[i].getElementsByTagName("audio");
						var bumper = null;
						if (audiofiles.length > 0)
						{
							audio = audiofiles[0].getAttributeNode("file").nodeValue;
							if (audiofiles.length > 1)
							{
								bumper = audiofiles[1].getAttributeNode("file").nodeValue;
							}
						}
					}
				}
					document.getElementById("contentContainer").innerHTML = content;
					//document.getElementById("contentContainer").scrollTop = 0;
					if (document.getElementById("jumpMenu"))
					{
						document.getElementById("jumpMenu").value = which;
					}
					playNarration(audio,bumper);
					//hideLoaderAlt();
					location.href="#start";
					
					if (currentSlide>1)
					{
						//location.href="#start";
					}
			}
		}
		myXML.send(null);
		//hideLoaderAlt();
	}
	
	function hideContent(){
		for (i=1; i<=pageCnt; i++){
			document.getElementById("copy"+i).style.display = "none";
		}
		stopNarration();
	}
	
	function createPageNav(currentSlide){
		
		var nextSlide = currentSlide + 1;
		var prevSlide = currentSlide - 1;
		if(prevSlide <= 0){
			prevSlide = pageCnt;
		}
		if(currentSlide == pageCnt){
			nextSlide = 1;
		}
		document.getElementById("nextBtn").href = "javascript:showContent("+nextSlide+");";
		document.getElementById("prevBtn").href = "javascript:showContent("+prevSlide+");";
		document.getElementById("pageLocation").innerHTML = "Slide " + currentSlide + " of " + pageCnt;
	}
	
	function popUpPrintView(url){
		var popup = window.open(url, "Print_View", "width=500,height=500,location=no,resizable=yes,scrollbars=yes")
		popup.focus();
	}
	
	function popUpSlideShow(url){
		var popup = window.open(url,"Slide_Show", "width=800,height=620,location=no,resizable=no,titlebar=no,menubar=no,scrollbars=no,status=no,top=80,left=180");
		popup.focus();
	}
	
	function popUpAnimation(url){
		var popup = window.open(url,"Animation","width=790,height=470,location=no,resizable=no,titlebar=no,menubar=no,scrollbars=no,status=no,top=80,left=180");
		popup.focus();
	}
	
	function hidePrintIcon(){
		document.getElementById("printicon").style.display = 'none';
	}
	
	function showPrintIcon(){
		document.getElementById("printicon").style.display = 'block';
	}
	
	function changeFontSize(id,fontSize)
	{
		document.getElementById(id).style.fontSize = fontSize;
	}