// JavaScript Document

	var	nDefaultPFontSize = 75;
	var	nDefaultH1FontSize = 120;
	var	nDefaultH2FontSize = 90;

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();






var activeMenu;
activeMenu = "";


function menuOn ( item )
{
	item.style.backgroundColor = '#BE0606';
	item.style.cursor = 'hand';
}

function menuOff ( item )
{
	item.style.backgroundColor = '';
	item.style.cursor = 'hand';
}

function DoSendMail(mailbox,domain)
{
	var sEmailString = 'mailto:' + mailbox + '@' + domain;
	window.open(sEmailString, '_blank');
}

function showItem ( idToShow )
{
	document.getElementById(idToShow).style.display = '';
}

function hideItem ( idToHide )
{
	document.getElementById(idToHide).style.display = 'none';
}

/****************************************
 If string is spaces or line breaks only
 function returns true.
****************************************/
function isBlank(string)
{
  for(var i=0; i<string.length; i++) {
    var c = string.charAt(i);
    if((c!=' ') && (c!='\n') && (c!='\t'))
      return false;
  }
  return true;
}

/****************************************
 If form element is blank
 function returns true.
****************************************/
function isFieldEmpty( field_name )
{
 if(field_name.value == null || field_name.value == "" || isBlank(field_name.value))
    return true;
 else
    return false;
}

/****************************************
 Turn on highlight for given image
****************************************/
function	switchIMG( item, image )	
{
	if ( IsLevelDown )
	{
		eval('document.' + item + '.src = "../' + image + '"');
		//item.src = '../' + image;
	} else {
		eval('document.' + item + '.src = "' + image + '"');
		//item.src = image;
	}
}

function doMain ( item )
{

	if ( item != activeMenu )
	{
		msrc = eval('document.' + item + '.src.indexOf("_on")');
		//alert(msrc);
	
		if ( msrc == "-1" )
		{
			switchIMG( item, 'images/menu/'+ item + '_on.gif' );
		} else {
			switchIMG( item, 'images/menu/'+ item + '_off.gif' );
		}
	}

}

function doSub ( item )
{

	src = eval('document.' + item + '.src.indexOf("_on")');

	if ( src == "-1" )
	{
		switchIMG( item, 'images/sub_menu/'+ item + '_on.gif' );
	} else {
		switchIMG( item, 'images/sub_menu/'+ item + '_off.gif' );
	}
}

function toggleSubMenu ( item )
{

	if ( BrowserDetect.browser == "Firefox" )
	{

		for ( i=0; i<document.getElementsByTagName("div").length; i++ )
		{
			if ( document.getElementsByTagName("div")[i].id.indexOf("_sub") != -1  )
			{
				document.getElementsByTagName("div")[i].style.display = "none"
			}
		}

		document.getElementById(item + '_sub').style.display = "";

	} else {
		var bMainMenuItemIsActive;
		bMainMenuItemIsActive = false;
	
		if ( activeMenu != '' && activeMenu != item )
		{
			switchIMG( activeMenu, 'images/menu/'+ activeMenu + '_off.gif' );
		}
	
		for ( i=0; i<document.getElementsByTagName("div").length; i++ )
		{
			if ( document.getElementsByTagName("div")[i].id.indexOf("_sub") != -1  )
			{
				if ( document.getElementsByTagName("div")[i].id == item + '_sub' && document.getElementsByTagName("div")[i].style.display == "none" )
				{
					document.getElementsByTagName("div")[i].style.display = ""
					activeMenu = item;
					bMainMenuItemIsActive = true;
				} else  {
					document.getElementsByTagName("div")[i].style.display = "none"
				}
			}
		}
	
		if  ( !bMainMenuItemIsActive )
		{
			activeMenu = '';
		}
	}

}




function hotkey(e){
	if (document.layers)
	{
		if ( e.which == 65 )
		{
			doMain('aboutus')
			toggleSubMenu('aboutus')
		} else if ( e.which == 73 ) {
			doMain('information')
			toggleSubMenu('information')
		} else if ( e.which == 77 ) {
			doMain('medialibrary')
			toggleSubMenu('medialibrary')
		}

	}  else if (document.all) {
		if ( event.keyCode == 65 )
		{
			doMain('aboutus')
			toggleSubMenu('aboutus')
		} else if ( event.keyCode == 73 ) {
			doMain('information')
			toggleSubMenu('information')
		} else if ( event.keyCode == 77 ) {
			doMain('medialibrary')
			toggleSubMenu('medialibrary')
		}
	}
}

// -----------------------------------
// Increases the text size of all text
// located inside any <p> tags by a factor
// of 10% (max is 100)
function increaseTextSize ()
{

	var nPFontSize = readCookie('pfontsize');
	var nH1FontSize = readCookie('h1fontsize');
	var nH2FontSize = readCookie('h2fontsize');

	if ( nPFontSize == null )
	{
		nPFontSize = nDefaultPFontSize;
		nH1FontSize = nDefaultH1FontSize;
		nH2FontSize = nDefaultH2FontSize;
	} else {
		nPFontSize = parseInt(nPFontSize);
		nH1FontSize = parseInt(nH1FontSize);
		nH2FontSize = parseInt(nH2FontSize);
	}
	
	if ( nPFontSize < 100 )
	{
		nPFontSize += 5;
		nH1FontSize += 5;
		nH2FontSize += 5;
	}
		
	setFontSize ('P', nPFontSize + '%')
	setFontSize ('LI', nPFontSize + '%')
	setFontSize ('H1', nH1FontSize + '%')
	setFontSize ('H2', nH2FontSize + '%')
	
	createCookie('pfontsize', nPFontSize, 365)
	createCookie('h1fontsize', nH1FontSize, 365)
	createCookie('h2fontsize', nH2FontSize, 365)
}
// -----------------------------------

// -----------------------------------
// Decreases the text size of all text
// located inside any <p> tags by a factor
// of 10% (min is 50)
function decreaseTextSize ()
{

	var nPFontSize = readCookie('pfontsize');
	var nH1FontSize = readCookie('h1fontsize');
	var nH2FontSize = readCookie('h2fontsize');

	if ( nPFontSize == null )
	{
		nPFontSize = nDefaultPFontSize;
		nH1FontSize = nDefaultH1FontSize;
		nH2FontSize = nDefaultH2FontSize;
	} else {
		nPFontSize = parseInt(nPFontSize);
		nH1FontSize = parseInt(nH1FontSize);
		nH2FontSize = parseInt(nH2FontSize);
	}
	
	if ( nPFontSize > 55 )
	{
		nPFontSize -= 5;
		nH1FontSize -= 5;
		nH2FontSize -= 5;
	}
		
	setFontSize ('P', nPFontSize + '%')
	setFontSize ('LI', nPFontSize + '%')
	setFontSize ('H1', nH1FontSize + '%')
	setFontSize ('H2', nH2FontSize + '%')
	
	createCookie('pfontsize', nPFontSize, 365)
	createCookie('h1fontsize', nH1FontSize, 365)
	createCookie('h2fontsize', nH2FontSize, 365)
}
// -----------------------------------

function setFontSize ( element, newsize )
{
	//alert("new size = " + newsize)
	if (document.getElementsByTagName) 
	{

		var getElement = document.getElementsByTagName(element);
		var eachElement;

		for (i=0; i<getElement.length; i++) 
		{
				eachElement = getElement[i];
				eachElement.style.fontSize = newsize;
		}
	}
}

function setGlobalTextSize ()
{

	var nPFontSize = readCookie('pfontsize');
	var nH1FontSize = readCookie('h1fontsize');
	var nH2FontSize = readCookie('h2fontsize');

	if ( nPFontSize == null )
	{
		nPFontSize = nDefaultPFontSize;
		nH1FontSize = nDefaultH1FontSize;
		nH2FontSize = nDefaultH2FontSize;
	} else {
		nPFontSize = parseInt(nPFontSize);
		nH1FontSize = parseInt(nH1FontSize);
		nH2FontSize = parseInt(nH2FontSize);
	}
	
	setFontSize ('P', nPFontSize + '%')
	setFontSize ('LI', nPFontSize + '%')
	setFontSize ('H1', nH1FontSize + '%')
	setFontSize ('H2', nH2FontSize + '%')
}
		

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}



function displayDiary ( quickRef )
{
	var xmlDoc = null;
	var nWritten = 0;
	var nRow = 1;
	var sQuickRefName = '';
	var sDirectoryPrefix = '';
	
	if ( window.ActiveXObject )
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	} else if ( document.implementation.createDocument ) {
		xmlDoc = document.implementation.createDocument("","",null);
	}
	
	if ( xmlDoc != null )
	{
		xmlDoc.async = false;
		if ( IsLevelDown )
		{
			sDirectoryPrefix = "../";
		}
		
		xmlDoc.load(sDirectoryPrefix + "SessionDiary.xml");
	
		document.write("<table width='450' border='0' cellspacing='1' cellpadding='2'>");
		document.write("<tr>");
		document.write("<td width='35%' class='HeaderRow'><p><strong>Class</strong></p></td>");
		document.write("<td width='15%' class='HeaderRow'><p><strong>Day</strong></p></td>");
		document.write("<td width='25%' class='HeaderRow'><p><strong>Time</strong></p></td>");
		document.write("<td width='25%' class='HeaderRow'><p><strong>Venue</strong></p></td>");
		document.write("</tr>");
	
		var x = xmlDoc.getElementsByTagName("Session");
		for ( i = 0; i < x.length; i++ )
		{ 
			if ( x[i].getElementsByTagName("QuickRef")[0].childNodes[0].nodeValue.toLowerCase() == quickRef.toLowerCase() || quickRef.toLowerCase() == 'all'  )
			{
				
				if ( quickRef.toLowerCase() == 'all' && sQuickRefName != x[i].getElementsByTagName("QuickRefName")[0].childNodes[0].nodeValue ) 
				{
				  document.write("<tr>")
					document.write("<td colspan='4' align='center'><p><strong>" + x[i].getElementsByTagName("QuickRefName")[0].childNodes[0].nodeValue + "</strong></p></td>")
					document.write("</tr>")
					sQuickRefName = x[i].getElementsByTagName("QuickRefName")[0].childNodes[0].nodeValue;
				}
				
				document.write("<tr>");
				document.write("<td valign='top' class='Row" + nRow + "'><p>" + x[i].getElementsByTagName("Name")[0].childNodes[0].nodeValue + "</p></td>");
				document.write("<td valign='top' class='Row" + nRow + "'><p>" + x[i].getElementsByTagName("Day")[0].childNodes[0].nodeValue + "</p></td>");
				document.write("<td valign='top' class='Row" + nRow + "'><p>" + x[i].getElementsByTagName("StartTime")[0].childNodes[0].nodeValue + " - " + x[i].getElementsByTagName("EndTime")[0].childNodes[0].nodeValue + "</p></td>");
				document.write("<td valign='top' class='Row" + nRow + "'><p>")
				document.write("<a href='" + sDirectoryPrefix + "locations.html#" + x[i].getElementsByTagName("Day")[0].childNodes[0].nodeValue.toLowerCase() + "s'>" + x[i].getElementsByTagName("Venue")[0].childNodes[0].nodeValue + "</a></p></td>");
				document.write("</tr>");
				nWritten++;
				if ( nRow == 1 )
				{
					nRow = 2;
				} else {
					nRow = 1;
				}
			}
		}
	
		document.write("</table>");
	
	}	
}


