/*

=================================================================================================
>> EASYMENU - XHTML/CSS/DHTML Semantically correct drop down menu 
=================================================================================================
Description:	This script takes a nested set of <ul>s and turns it into a fully functional
		DHTML menu. All that is required is the correct use of class names, and
		the application of some CSS. For the latest version of this script, go to
		http://www.easymenu.co.uk
		
Use:		Use of this code is free for all non-commercial applications. If you would like to 
		use the code on a commercial website, payment is required. 
                You are free to make alterations to the code as required.
		

Copyright:	This script is copyright 2004-2005 easymenu.co.uk. All rights reserved.


--------------------------------------------------------------------------------------------------
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
--------------------------------------------------------------------------------------------------
Credits: 	Inspiration/Code borrowed from Dave Lindquist (http://www.gazingus.org)
		Menu hide functionality was aided by some code I found on http://www.jessett.com/
		Konqueror functionality was aided by some code Scott Wehrenberg emailed over
--------------------------------------------------------------------------------------------------
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
--------------------------------------------------------------------------------------------------

==================================================================================================
>> REVISION HISTORY
==================================================================================================
Date		Version		Changes/Bug Fixes/New functionality added
--------------------------------------------------------------------------------------------------
10/01/2005	1.01		Fixed known issue where hovering over a sub-menu, then returning to 
				its parent menu not via the "starter" item on that menu, where the 
				new item moused over is a "starter" caused the two sub-menus 
				to overlay each other until a further movement of the mouse. 
				Fixed known issue where returning to parent menu via a non-"starter"
				menu item on the parent menu would not hide the child menu
08/01/2005	1.00		First full release of easymenu.
				Stylesheets now loaded in through JavaScript to improve accessibility.
01/12/2004	0.9		Base code inherited from client project
				Added suggestion from Scott Wehrenberg enabling Konqueror functionality
--------------------------------------------------------------------------------------------------



*/
	// Load up the stylesheet for the menus. This code is here rather than in the html
	// document to allow for non-javascript browsers to render a seperately styled non-
	// interactive list rather than the DHTML menu
	//document.write("<link rel='stylesheet' href='/skins/design2-slick/includes/cssmenu.css' type='text/css' />");

	var currentMenu = null;
	var lastMenuStarter = null;
	var mytimer = null;
	var timerOn = false;
	var opera = window.opera ? true : false;

	if (!document.getElementById)
		document.getElementById = function() { return null; }

	function initialiseDummy(dummy, root) {
		dummy.onmouseover = function() {
			containingMenu = this.parentNode.parentNode;
			for (var x=0;x<containingMenu.childNodes.length;x++) {
				if (containingMenu.childNodes[x].nodeName.toUpperCase()=="LI") {
					if (containingMenu.childNodes[x].getElementsByTagName("ul").length>0) {
						containingMenu.childNodes[x].getElementsByTagName("UL").item(0).style.visibility = 'hidden';
					}
				}
			}
		}
		dummy.onfocus = function() {
			dummy.onmouseover();
		}
	}
	
	function initialiseMenu(menu, starter, root) {
		var leftstarter = false;
	
		if (menu == null || starter == null) return;
			currentMenu = menu;
	
		starter.onmouseover = function() {
			if (currentMenu) {
				if (this.parentNode.parentNode!=currentMenu) {
					currentMenu.style.visibility = "hidden";
					hideAllMenus(currentMenu, root);

				}
				if (this.parentNode.parentNode==root) {
					while (currentMenu.parentNode.parentNode!=root) {
						currentMenu.parentNode.parentNode.style.visibility = "hidden";
						currentMenu = currentMenu.parentNode.parentNode;
					}
				}
				currentMenu = null;
				this.showMenu();
	        	}
		}
	
		menu.onmouseover = function() {
			if (currentMenu) {
				currentMenu = null;
				this.showMenu();
	        	}
		}	
	
		starter.showMenu = function() {
			if (!opera) {
				if (this.parentNode.parentNode==root) {
					menu.style.left = this.offsetLeft + "px";
					menu.style.top = this.offsetTop + this.offsetHeight + "px";
					if (menu.offsetWidth < this.offsetWidth) menu.style.width = this.offsetWidth;

				}
				else {
				 	menu.style.left = this.offsetLeft + this.offsetWidth + "px";
				 	menu.style.top = this.offsetTop + "px";
				}
			}
			else {
				var rootOffset = root.offsetLeft;
				if (this.parentNode.parentNode==root) {
					menu.style.left = this.offsetLeft - rootOffset + "px";
					menu.style.width = this.offsetWidth;
					menu.style.top = this.offsetHeight + "px";
				}
				else {
				 	menu.style.left = this.offsetWidth - rootOffset + "px";
				 	menu.style.top = this.offsetTop + "px"; //menu.style.top - menu.style.offsetHeight + "px";
				}

			}
			menu.style.visibility = "visible";
			currentMenu = menu;
		}

		starter.onfocus	 = function() {
			starter.onmouseover();
		}
	
		menu.onfocus	 = function() {
//			currentMenu.style.visibility="hidden";
		}

		menu.showMenu = function() {
			menu.style.visibility = "visible";
			currentMenu = menu;
			stopTime();
		}

		menu.hideMenu = function()  {
			if (!timerOn) {
				mytimer = setInterval("killMenu('" + this.id + "', '" + root.id + "');", 2000);
				timerOn = true;
				for (var x=0;x<menu.childNodes.length;x++) {
					if (menu.childNodes[x].nodeName=="LI") {
						if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
							menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
							menuItem.style.visibility = "hidden";
						}
					}
				}
			}
		}

		menu.onmouseout = function(event) {
			this.hideMenu();
		}
		menu.onblur = function() {
			this.hideMenu();
		}
		starter.onmouseout = function() {
			for (var x=0;x<menu.childNodes.length;x++) {
				if (menu.childNodes[x].nodeName=="LI") {
					if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
						menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
						menuItem.style.visibility = "hidden";
					}
				}
			}
			menu.style.visibility = "hidden";
		}
}
	function killMenu(menu, root) {
		var menu = document.getElementById(menu);
		var root = document.getElementById(root);
		menu.style.visibility = "hidden";
		for (var x=0;x<menu.childNodes.length;x++) {
			if (menu.childNodes[x].nodeName=="LI") {
				if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
					menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
					menuItem.style.visibility = "hidden";
				}
			}
		}
		while (menu.parentNode.parentNode!=root) {
			menu.parentNode.parentNode.style.visibility = "hidden";
			menu = menu.parentNode.parentNode;
		}
		stopTime();
	}
	function stopTime() {
		if (mytimer) {
		 	 clearInterval(mytimer);
			 mytimer = null;
			 timerOn = false;
		}
	} 

	window.onload = function() {
		var root = document.getElementById("menuList");
		var rootOffset = root.offsetLeft;
		//var rootOffset = 300;
		//alert(rootOffset);
		getMenus(root, root);
	}

function getMenus(elementItem, root) {
	var selectedItem;
	var menuStarter;
	var menuItem;
	for (var x=0;x<elementItem.childNodes.length;x++) {
		if (elementItem.childNodes[x].nodeName.toUpperCase()=="LI") {
			if (elementItem.childNodes[x].getElementsByTagName("ul").length>0) {
				menuStarter = elementItem.childNodes[x].getElementsByTagName("A").item(0);
				menuItem = elementItem.childNodes[x].getElementsByTagName("UL").item(0);
				getMenus(menuItem, root);
				initialiseMenu(menuItem, menuStarter, root);
			}
			else {
				initialiseDummy(elementItem.childNodes[x].getElementsByTagName("A").item(0), root);
			}
		}
	}
}
function hideAllMenus(elementItem, root) {
	for (var x=0;x<elementItem.childNodes.length;x++) {
		if (elementItem.childNodes[x].nodeName.toUpperCase()=="LI") {
			if (elementItem.childNodes[x].getElementsByTagName("ul").length>0) {
				elementItem.childNodes[x].getElementsByTagName("UL").item(0).style.visibility = 'hidden';
				hideAllMenus(elementItem.childNodes[x].getElementsByTagName("UL").item(0), root);
			}
		}
	}
}

//Select list functions.
function selectListDeleteAllOptions(elSel) {
	for (i = elSel.length - 1; i>=0; i--) {
		elSel.remove(i);
	}
}

function selectListDeleteOption(elSel, val) {
	for (i = elSel.length - 1; i>=0; i--) {
		if (elSel.options[i].value==val) {
			elSel.remove(i);
		}
	}
}

function selectListAppendOptionToStart(elSel, num, oText, oVal)
{
  if (elSel.selectedIndex >= 0) {
    var elOptNew = document.createElement('option');
    elOptNew.text = oText;
    elOptNew.value = oVal;
    var elOptOld = elSel.options[elSel.selectedIndex];  
    try {
      elSel.add(elOptNew, elOptOld); // standards compliant; doesn't work in IE
    }
    catch(ex) {
      elSel.add(elOptNew, elSel.selectedIndex); // IE only
    }
  }
}

function selectListAppendOptionToEnd(elSel, oText, oVal)
{
  var elOptNew = document.createElement('option');
  elOptNew.text = oText;
  elOptNew.value = oVal;

  try {
    elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
  }
  catch(ex) {
    elSel.add(elOptNew); // IE only
  }
}
function selectListSetSelectedOption(elSel, val) {
	for (i = elSel.length - 1; i>=0; i--) {
		if (elSel.options[i].value==val) {
			elSel.selectedIndex=i;
		}
	}
}



function setInnerHTML(tagToSet, theText) {

var the_inputs=document.getElementsByTagName(tagToSet);

	for(var n=0;n<the_inputs.length;n++) {
		the_inputs[n].innerHTML=theText;
	}
}

/*********************** End of menu code **********************************/



function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}




	function delArticle(id, title, node)
	{
		if (node < pages.length-1) {
			nextPagesLevel = pages[node+1][2];
		} else {
			nextPagesLevel = pages[node][2];
		}
		if (nextPagesLevel > pages[node][2]) {
			alert('You cannot delete a page which has subpages. Please delete or move the subpages first.');
		} else {
			if (confirm("Are you sure you want to delete '" + title + "'"))	{
				window.location.href = 'index.php?del=' + id;
			}
		}
	}


	function delConfirm(id, title, page)
	{
		if (confirm("Are you sure you want to delete " + title))	{
			window.location.href = page+'?del=' + id;
		}
	}
	function delConfirm2(title, page)
	{
		if (confirm("Are you sure you want to delete '" + title + "'"))	{
			window.location.href = page;
		}
	}


	function delCatConfirm(id, title, page)
	{
		if (confirm("Note that any products or subcategories within '"+title+"' will also be deleted.\nAre you sure you still want to delete the category '" + title + "'?\n"))	{
			window.location.href = page+'?del=' + id;
		}
	}



	function doEditorSubmit()
	{
		/*
		This fixes a bug with the Editor when submitting from a script.
		To solve this problem, simply call the form onsubmit() just before calling the form submit() method.
		See the Editor FAQ for more info.
		*/
		document.forms[0].onsubmit();
		document.forms[0].submit();
	}


	function selectLayout(id, code) {
		for (i=1; i<9; i++) document.getElementById('layout'+i).className='sampledesignarea';
		e = document.getElementById(id);
		e.className='sampledesignarea highlight';
		document.getElementById('layout_code').value = code;
	}



	function showElement(id) {
		e = document.getElementById(id);
		e.style.visibility='visible';
		e.style.display='';
	}

	function hideElement(id) {
		e = document.getElementById(id);
		e.style.visibility='hidden';
		e.style.display='none';
	}

	function toggleElement(id) {
		e = document.getElementById(id);
		if (e.style.display=='block') {
			e.style.visibility='hidden';
			e.style.display='none';
		} else {
			e.style.visibility='visible';
			e.style.display='block';
		}
	}


	function showComponentPopup(id, componentNumber, componentType) {
		if (componentType=='empty') {
			document.getElementById('updatecomponentarea').style.display='none';
		} else {
			document.getElementById('updatecomponentarea').style.display='block';
			for (i=1; i<5; i++) document.getElementById('component'+i).style.visibility='hidden';
			document.getElementById('component'+componentNumber).style.visibility='visible';
		}

		e = document.getElementById(id);
		e.style.visibility='visible';
	}

	function hideComponentPopup(id) {
		for (i=1; i<5; i++) document.getElementById('component'+i).style.visibility='hidden';
		e = document.getElementById(id);
		e.style.visibility='hidden';
	}
	

	

	/***************************************
	Required Functions for launching AssetManager from my code
	***************************************/
	function modalDialogShow_IE(url,width,height) //IE
		{
		return window.showModalDialog(url,window,
			"dialogWidth:"+width+"px;dialogHeight:"+height+"px;edge:Raised;center:Yes;help:No;Resizable:Yes;Maximize:Yes");
		}
	function modalDialogShow_Moz(url,width,height) //Moz
		{
		var left = screen.availWidth/2 - width/2;
		var top = screen.availHeight/2 - height/2;
		activeModalWin = window.open(url, "", "width="+width+"px,height="+height+",left="+left+",top="+top);
		window.onfocus = function(){if (activeModalWin.closed == false){activeModalWin.focus();};};
		}
	var sActiveAssetInput;
	function setAssetValue(v) //required by the asset manager
		{
		document.getElementById(sActiveAssetInput).value = v;
		}
	function openAsset(s, siteURL, siteServerDir)
		{
		sActiveAssetInput = s
		if(navigator.appName.indexOf('Microsoft')!=-1)
			/* document.getElementById(sActiveAssetInput).value=modalDialogShow_IE("/cms/Editor/assetmanager/assetmanager.php?site_url="+siteURL+"&site_server_dir="+siteServerDir,640,465); //IE	*/
			document.getElementById(sActiveAssetInput).value=modalDialogShow_IE(siteURL+"/cms/assetmanager/assetmanager.php?site_url="+siteURL+"&site_server_dir="+siteServerDir,640,465); //IE
		else
			modalDialogShow_Moz(siteURL+"/cms/assetmanager/assetmanager.php?site_url="+siteURL+"&site_server_dir="+siteServerDir,640,465); //Moz	
		}

	function openAssetStandAlone(siteURL, siteServerDir)
		{
		if(navigator.appName.indexOf('Microsoft')!=-1)
			modalDialogShow_IE(siteURL+"/cms/assetmanager/assetmanager.php?site_url="+siteURL+"&site_server_dir="+siteServerDir,640,465); //IE
		else
			modalDialogShow_Moz(siteURL+"/cms/assetmanager/assetmanager.php?site_url="+siteURL+"&site_server_dir="+siteServerDir,640,465); //Moz	
		}


/*****************************************/	



/************************ TREE NODE Functions *********************************/
	/* Array description
		pages[x][0] = page id
		pages[x][1] = nav order
		pages[x][2] = nav level
		pages[x][3] = shown ("block") or hidden ("none");
	*/

	//Hide all sub pages - This executes only once after page loads.
	function collapseAll(id) {
		topLevel = 0;

		for (x in pages) {
			if (pages[x][2]>topLevel) {
				e = document.getElementById('page'+pages[x][0]);
				e.style.display='none';
				e.style.visibility='hidden';
			}
	
			//If the next node is a child of this node, then show the plus icon.
			if (x<pages.length-1) {
				if (pages[parseInt(x)+1][2]>pages[x][2]) {
					e = document.getElementById('icon'+pages[x][0]);
					e.style.display='block';
					e = document.getElementById('iconspacer'+pages[x][0]);
					e.style.display='none';
					e.style.visibility='hidden';
				}
			}
		}
	}

	//Open up a node - This is called each time a node is expanded.
	function openUpNode(node) {

		e = document.getElementById('icon'+pages[node][0]);
		if (e.className=='iconplus') e.className = 'iconminus'; else e.className = 'iconplus';


		for (x in pages) {
			if (x>node) {
				if ((pages[x][2])>pages[node][2]) {
					e = document.getElementById('page'+pages[x][0]);
					f = document.getElementById('icon'+pages[x][0]);
					if (e.style.display=='block') {
						//alert('hiding tree');
						e.style.display='none';
						e.style.visibility='hidden';
						f.className = 'iconplus';
					} else {
						//e.style.visibility='visible';
						//alert('opening tree');
						if ((pages[x][2]-1)==pages[node][2]) { //Only open one level up.
							e.style.visibility='visible';
							e.style.display='block'; 
						}
						f.className = 'iconplus';
					}
				} else break;
			}
		}
	}
	
	function showNodeWithId(id) {
		var openNodes = new Array();
		for (x in pages) {
			if (pages[x][0] == id) {
				levelToOpen = pages[x][2]-1;
				i=0;
				for (y=x; y>-1; y--) {
					if (pages[y][2]==levelToOpen) {
						openNodes[i]=y;
						i++;
						levelToOpen=levelToOpen-1;
					}
				}
			}
		}
		for (z=(openNodes.length-1); z>-1; z--) {
			openUpNode(openNodes[z]);
		}
	}




	function hideProgressBar () {
		e = document.getElementById('progressbar');
		e.style.display='none';
		e.style.visibility='hidden';		
	}

	function showProgressBar () {
		e = document.getElementById('progressbar');
		e.style.display='block';
		e.style.visibility='visible';		
	}



var newwindow;
function openHelpFAQ(topicid)
{
	newwindow=window.open('helpfaq.php#'+topicid,'name','height=540,width=516,toolbar=no,menubar=no,left=10,top=10,resizable=true,scrollbars=yes,location=no,status=no,directories=no,');
	if (window.focus) {newwindow.focus()}
}
/*********************************************************/


function checkValueEntered(id, message) {
	e = document.getElementById(id);
	if (!e.checked) {
		alert(message);
	} else {
		document.forms[0].submit();
	}
}

function toggleOpenClosed(id, textid, opentext, closedtext) {

	e = document.getElementById(id);
	t = document.getElementById(textid);
	//if (e.style.display=='none'||e.style.display=='') {
	if (e.style.display=='none') {
		e.style.display=''; //Dont set this to block because it stuffs up Firefox. Set it to ''. For more info see: http://snook.ca/archives/html_and_css/dynamically_sho/
		e.style.visibility='visible';
		t.innerHTML=closedtext;
		t.className = 'eventdate';
} else {
		e.style.display='none';
		e.style.visibility='hidden';
		t.innerHTML=opentext;
		t.className = 'eventdate closed';
	}


}

function selectListSetSelectedOption(elSel, val) {
	for (i = elSel.length - 1; i>=0; i--) {
		if (elSel.options[i].value==val) {
			elSel.selectedIndex=i;
		}
	}
}



function clearFields() {
	document.getElementById('venue_name').value = '';
	document.getElementById('artist_name').value = '';
	document.getElementById('start_datetime').value = '';
	document.getElementById('end_datetime').value = '';
	document.getElementById('type_id').value = '';
	document.getElementById('genre_id').value = '';
}
function checkIfRestrictedVenue(el) {
	
	var optionText = el.options[el.options.selectedIndex].text;
	var loc = optionText.indexOf(' (restricted)');

	if (loc > -1) {
		el.value='';
		var nameWithOutRestricted = optionText.substring(0, loc).replace("'", "\'");
		alert('The venue '+nameWithOutRestricted+' has been restricted by the owner.\nPlease contact this venue and ask them to add your event.');
	}
}


function submitAndShowWhirly(action, object_name) {
	clicker(action, object_name);
	document.forms["form1"].submit();
}

function clicker(action, object_name) {
	var thediv=document.getElementById('loading');
	if (thediv.style.display == "none") {
		thediv.style.visible = "visible";
		thediv.style.display = "block";
		if (action=="edit" || action=="update") thediv.innerHTML = '<table width="100%" height="100%"><tr><td align="center" valign="middle" width="100%" height="100%"><div id="loadingCentre"><img id="ajaxloader" style="margin-right:10px" src="/images/ajax-loader.gif" alt="Updating your '+object_name+'. Please wait..." align="left" /><h1 style="padding-top:5px;">Updating your '+object_name+'</h1><p>Please wait while we update your '+object_name+'. If you have specified a new photo that is large, then it may take some time to upload the photo.</p><p>If you believe this page has encountered difficulties, please <a href="/report-bug-enhancement.php" title="Report an issue.">click here</a> to report the issue to our support team.</p></div></td></tr></table>';
		if (action=="add" || action=="create") thediv.innerHTML = '<table width="100%" height="100%"><tr><td align="center" valign="middle" width="100%" height="100%"><div id="loadingCentre"><img id="ajaxloader" style="margin-right:10px" src="/images/ajax-loader.gif" alt="Creating your '+object_name+'. Please wait..." align="left" /><h1 style="padding-top:5px;">Creating your '+object_name+'</h1><p>Please wait while we create your '+object_name+'. If you have specified a new photo that is large, then it may take some time to upload the photo.</p><p>If you believe this page has encountered difficulties, please <a href="/report-bug-enhancement.php" title="Report an issue.">click here</a> to report the issue to our support team.</p></div></td></tr></table>';
	} else {
		thediv.style.visible = "hidden";
		thediv.style.display = "none";
		thediv.innerHTML = '';
	}
	setTimeout('document.getElementById("loading").innerHTML = document.getElementById("loading").innerHTML', 5); 
	return true;
}


function getPhone(id, tablename) {

	document.getElementById('thephone').innerHTML = 'Retrieving phone number.<br />Please wait...';

	var url="get-phone.php?id="+id+"&object="+tablename;
					 
	http.open("GET", url, true);
	http.onreadystatechange = doTheAction;
	http.send(null);
}

function doTheAction(){
	if(http.readyState == 4) {
		document.getElementById('thephone').innerHTML = http.responseText;
	}
}


//Preload the animated loading gif.
pic1= new Image(100,25); 
pic1.src="http://www.entertainmentcairns.com/images/ajax-loader.gif"; 



function pop_up_window(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=380,height=500,left = 350,top = 150');");
}

