/************************************************************************/
/*															 			*/
/*	Accordent Event Menu v2.00											*/
/*	=========================								 			*/
/*																		*/
/*	Last Edited: 9/15/2008									  			*/
/*	Please send all comments & bug reports to: support@accordent.com	*/
/*																		*/
/************************************************************************/

var topicsVisibility   = false; // Don't Show Topics
var rsrcsVisibility    = false	// Don't Show Resources Tab
var downldVisibility   = false	// Don't show Downloads Section
var linksVisibility    = false	// Don't show Links Section
var emailVisibility    = false  // Don't show Email Tab
var captionsVisibility = false; // Don't show Closed Captions
var chaptersLoaded     = false;
var blank = /^[\s]*$/i;

var TheChapterTextArray = [];
var TheChapterTimeArray = [];



//*****************************************************************
function getChapters(sender, args)
{ 

var FoundChapterMatch = false;
var ChapterIDNumber = 1;
var ChapterId = "";
var arr = new Array(); arr = document.documentElement.getElementsByTagName("*"); 
   
var tagObj = document.documentElement.getElementsByTagName("*").item(i); 
for(var i=0; i < arr.length; i++) 
{ 

var tagName = document.documentElement.getElementsByTagName("*").item(i).nodeName; 


switch (tagName.toUpperCase()) 
{ 
case "DIV": 

var tagObj = document.documentElement.getElementsByTagName("*").item(i); 
var DivValue = tagObj.innerHTML;
 
if (DivValue.indexOf("-ATChapter-") == 0)
{	
	var ChapterArray = DivValue.split("-ATChapter-");

// Test for older versions of the Capture Station pre v4.2
if ((ChapterArray[(1)].replace("</DIV>","")).indexOf(":") == 2 )
	{
		TheChapterTimeArray[ChapterIDNumber] = (ChapterArray[(1)].replace("</DIV>",""));    
	}
  else

	{
	TheChapterTimeArray[ChapterIDNumber] = GetTimeFromLong( (ChapterArray[(1)].replace("</DIV>","")));    	
	
	}

	TheChapterTextArray[ChapterIDNumber] = ChapterArray[(2)].replace("<DIV>","");

	if (ChapterIDNumber < (chaptersDisplayed +1))
    {
		ChapterId  = "TextTopics" + ChapterIDNumber
	    sender.findName(ChapterId).Tag = ChapterIDNumber.toString();
	    sender.findName(ChapterId).Text = (TheChapterTextArray[ChapterIDNumber]).substr(0, chapterCharLength);
    }

	ChapterIDNumber++;

	break; 

}

default: 
 
}   // Switch

}   //For i loop

}  // Function

  
//*****************************************************************************************










// Checks to see if browser is Firefox and user has Port25 plugin installed.
function hasP25() {
	var P25 = false;
	var plugin = navigator.mimeTypes && navigator.mimeTypes["application/x-ms-wmp"];
	var FFcheck = navigator.userAgent.indexOf("Firefox");
	if (plugin && FFcheck != -1)
		P25 = true;
	return P25;
}

function isWin() {
	var win = false;
	var ua = navigator.userAgent.toLowerCase();
	if (ua.indexOf('win') > -1)
		win = true;
	//if(win){alert('is win');}else{alert('is NOT win');}
	return win;
}


function SetChapters() {


}


// check to see if user has enabled chaptering functionality
function topicsTabCheck() {
	try{
		var topicsTabTag = pres_chaptering;
		//var topicsTabTag = 'yes';
		var chkNoTopicsTabTag = topicsTabTag.indexOf("<@");
		if ((pres_ondemand=='visible') && (topicsTabTag != '') && (chkNoTopicsTabTag < 0)) {
			topicsVisibility = true;
		}		
	} catch(e) {}
	return topicsVisibility;
}
topicsTabCheck();

// load correct xsl file depending on browser type and plugin
function loadChapters(divLyr){

	if(!topicsVisibility){ return true; }
	if(document.implementation && document.implementation.createDocument){
		// Mozilla
		var xsltProcessor = new XSLTProcessor();
		// load the xslt file
		var myXMLHTTPRequest = new XMLHttpRequest();
		//	IF is WINDOWS MEDIA
//		if (isWin()){
//			myXMLHTTPRequest.open("GET", "chapters.xsl", false);
			// otherwise load list of time/topic without link
//		} else {
			myXMLHTTPRequest.open("GET", "schapters.xsl", false);
//		}
		myXMLHTTPRequest.send(null);
		// get the XML document
		xslStylesheet = myXMLHTTPRequest.responseXML;
		xsltProcessor.importStylesheet(xslStylesheet);
		// load the xml file
		myXMLHTTPRequest = null;
		myXMLHTTPRequest = new XMLHttpRequest();
		myXMLHTTPRequest.open("GET", "presentation.xml", false);
		myXMLHTTPRequest.send(null);
		var xmlSource = myXMLHTTPRequest.responseXML;
		//transform
		var resultDocument = xsltProcessor.transformToFragment(xmlSource, document);
		document.getElementById(divLyr).appendChild(resultDocument);
//alert(resultDocument.ToString());
		// cleanup variables
		delete xsltProcessor;
		delete myXMLHTTPRequest;
		delete xslStylesheet;
		delete xmlSource;
		delete resultDocument;
	}else if(window.ActiveXObject){
		// IE
		// Load XML
		xml = new ActiveXObject("MSXML2.DOMDocument");
		xml.async = false
		xml.load("presentation.xml")
		// Load XSL - with linked chapters
		xsl = new ActiveXObject("MSXML2.DOMDocument");
		xsl.async = false
		xsl.load("schapters.xsl")
		// Transform
		document.getElementById(divLyr).innerHTML=xml.transformNode(xsl);
		// cleanup variables
		delete xml;
		delete xsl;
	}else{
		// Browser unknown
		alert("Browser unknown");
	}
	chaptersLoaded = true;
	return chaptersLoaded;
}

// check to see if one or more downloadable files has been defined.
downldVisibility = function dwnldDocCheck() {
	var dlArray = new Array();
	var hasdlFile = false;
	// add downloadable file custom tags below. only one by default.
	dlArray[0] = '';
		
	try {
		// loop thru array to see if there are any downloadable files in any position
		for (var i=0;i<=0;i++) {
			if(dlArray[i] != '' && dlArray[i].indexOf("@>") < 0) {
				hasdlFile = true;
				break;
			}
		}
		// alert(hasdlFile);
		if (!hasdlFile) {
			downldVisibility = false; // no downloadable file has been defined in this array
		} else {
			downldVisibility = true; // at least one downloadable file has been defined in this array
			for (var i=0;i<=0;i++) {
				var dlli = 'dl' + i;
				if (dlArray[i] == '' || dlArray[i].indexOf("@>") > -1) {
					document.getElementById(dlli).style.display = 'none';
				}
			}	
		}
	} catch(e) {}
	return downldVisibility;
}();

// check to see if one or more URL links has been defined.
linksVisibility = function linksCheck() {
	var linkArray = new Array();
	var hasLink = false;
	// add URL link custom tags below. only one by default.
	linkArray[0] = 'http://www.accordent.com/';
	
	try {
		// loop thru array to see if there are any URL links in any position
		for (var i=0;i<=0;i++) {
			if(linkArray[i] != '' && linkArray[i].indexOf("@>") < 0) {
				hasLink = true;
				break;
			}
		}
		// alert(hasLink);
		if (!hasLink) {
			linksVisibility = false; // no link has been defined in this array
		} else {
			linksVisibility = true; // at least one link has been defined in this array
			for (var i=0;i<=2;i++) {
				var linkli = 'links' + i;
				if (linkArray[i] == '' || linkArray[i].indexOf("@>") > -1) {
					document.getElementById(linkli).style.display = 'none';
				}
			}	
		}
	} catch(e) {}
	return linksVisibility;
}();

// if neither downloadable files nor URL links exist, hide Resources tab
if (!downldVisibility && !linksVisibility) {rsrcsVisibility = false;} else {rsrcsVisibility = true;}

// check to see if Captions are used
function ClosedCaptionsCheck() {
	try{
		var CCtag = pres_cc_file;
		var CCtab = pres_cc_option;
		//var CCtag = 'somefile';
		var chkNoCCTag = CCtag.indexOf("<@");
		var chkNoCCTab = CCtab.indexOf("<@");
		if ( (CCtab != '') && (chkNoCCTab < 0)  && (CCtag != '') && (chkNoCCTag < 0)  && (isBrowserIeWin() || hasP25()) ) {
			captionsVisibility = true;
		}		
	} catch(e) {}
	return captionsVisibility;
}
captionsVisibility = ClosedCaptionsCheck();

// check to see if email address has been defined
emailVisibility = function emailCheck() {
	try {
		var emailTo = pres_email;
		var chkNoTag = emailTo.indexOf("<@");
		if (emailTo == '' || chkNoTag > -1) {
			linksVisibility = false;
		}
	} catch(e) {}
	return linksVisibility;
}();


function pageInit(){
	chaptersLoaded = loadChapters('chaptersBox');
   
}

