var navigationController = {
   selectMain: function(menuItem) {
      this.navigationSelect('navigation', menuItem);
   },

   selectSub: function(menuItem) {
      this.navigationSelect('subnavigation', menuItem);
   },

   navigationSelect: function(navElement, menuItem) {
      // Manage main navigation

		if (navElement == 'navigation') {
			var theList = document.getElementById(navElement);
			var listElements = theList.getElementsByTagName('li');
			var i;
			
			// If the current element contains the 
			// id of the desired pre-selection,
			// change its class and also the <A>
			// node that it contains
			
			for (i=0; i< listElements.length; i++) {
				if (listElements[i].id == menuItem) {
					listElements[i].className = 'selected';
					
					var linkElements = listElements[i].getElementsByTagName('a');
					linkElements[0].className = 'selected';
				}
			}
		}
		
		// Manage subnavigation
		
		else {
			var listElement = document.getElementById(menuItem);
			var linkElements = listElement.getElementsByTagName('a');
			linkElements[0].className = 'selected';
		}
	}
}


/* strstr()
***********
Javascript equivalent.
*/
function strstr( haystack, needle, bool ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: strstr('Kevin van Zonneveld', 'van');
    // *     returns 1: 'van Zonneveld'
    // *     example 2: strstr('Kevin van Zonneveld', 'van', true);
    // *     returns 2: 'Kevin '
 
    var pos = 0;
 
    pos = haystack.indexOf( needle );
    if( pos == -1 ){
        return false;
    } 
	 else {
	    return true;
    }
}


/* getElementByClassname()
**************************
Get a stack of nodes based on a classname.
*/
function getElementByClassname(classname, node) {
	if (!node) node = document.getElementsByTagName("body")[0];
	
	var a = [];
	var re = new RegExp('\\b' + classname + '\\b');
	var els = node.getElementsByTagName("*");
	
	for(var i=0,j=els.length; i < j; i++)
		if(re.test(els[i].className)) a.push(els[i]);

	return a;
}


/* displayDiv()
***************
*/
function displayDiv(id) {
   var theDiv = document.getElementById(id);

   if (theDiv.style.display == 'none') {
      showDiv(id);
   }
   else {
      hideDiv(id);
   }
}


/* showDiv()
************
*/
function showDiv(id) {
   var theDiv = document.getElementById(id);

   theDiv.style.display = 'block';
}


/* hideDiv()
************
*/
function hideDiv(id) {
   var theDiv = document.getElementById(id);

   theDiv.style.display = 'none';
}


/* Array.prototype.getUniqueValues
**********************************
Gets unique values from an array, returns an array
of uniques.
*/
Array.prototype.getUniqueValues = function () { 
   var hash = new Object();
	
   for (j = 0; j < this.length; j++) {
	   hash[this[j]] = true;
	}
	
   var array = new Array();
	
   for (value in hash) {
	   array.push(value)
	}
	
   return array;
}


/* otherFieldSpecification()
****************************
Used in a combination of [x] Other, please specify [ ... ] 
situations. otherId is the id of the checkbox belonging to "Other";
specifyId is the id of the textbox belonging to the "Other";
errorMessage is returned if the textbox wasn't filled in when the
"Other" checkbox was ticked.

This can be cloned to suit radio buttons etc.
*/
function otherFieldSpecification(otherId, specifyId, errorMessage) {
	if (document.getElementById(otherId).checked == true) {
		if (document.getElementById(specifyId).value == '') {
			return errorMessage + "\n";
		}
	}
	
	return '';
}


/* copyInputValue()
*******************
Copies input from one textbox to another.
Additional parameter "type" will allow expansion
to include other input types.
*/
function copyInputValue(source, destination) {
   var sourceElement = document.getElementById(source);
	var destinationElement = document.getElementById(destination);
	
	destinationElement.value = sourceElement.value;
}


/* writeOrigin()
****************
Creates a cookie using the key/value pair "origin/value" in this format:
?.... origin=myvaluehere ...
*/
function writeOrigin() {
   var regex = new RegExp("(origin=)([a-zA-Z0-9_]+)");
	var matches = regex.exec(location.href);
	
	if (matches != null) {
      createCookie('enteractive_restaurant09Sydney_origin', matches[2], 30);
	}
}


/* redirect()
*************
Redirects to a specified web address.
*/
function redirect(newURL) {
   window.location = newURL;
}


/** Cookie Testing **/

function GetCookie() {
	var strName = "enteractive_cookieTest";
	
	if (document.cookie.indexOf(strName) == -1) {
		return false;
	}
	else {
		cookieStart = document.cookie.indexOf(strName);
		cookieValStart = (document.cookie.indexOf("=", cookieStart) + 1);
		cookieValEnd = document.cookie.indexOf(";", cookieStart);

		if (cookieValEnd == -1) {
			cookieValEnd = document.cookie.length;
		}
		cookieValue = document.cookie.substring(cookieValStart, cookieValEnd);
	}
	
	if (cookieValue = "True") {
		return ("True");
	}
}

function SetCookie(name,value,expires,path,domain,secure) {
	var strDNS = GetDNS();
		document.cookie = name + "=" +escape(value) +
		  ( (expires) ? ";expires=" + expires.toGMTString() + 1000*60*20 : "") +
		( (path) ? ";path=" + path : "") +
		  //( (domain) ? ";domain=" + domain : "") +
		( (domain) ? ";domain=" + strDNS : "") +
		  ( (secure) ? ";secure" : "");
		 return true
}

function GetDNS() {
	cookieDomain = document.location.hostname;
}

function CheckCookiesEnabled(autoSubmit) {
   var errorMessage = "<p><strong>You have disabled Cookies.</strong><br />This page requires Cookies to be enabled. Please check your security settings and enable Cookies before continuing.</p>";

	SetCookie('enteractive_cookieTest','True','','/','','');

   var theDiv = document.getElementById('contentDiv');
	
	if (GetCookie() == "True") {
		if (autoSubmit == true) {
			return true;
		}
		else {
         showDiv('contentDiv');
		}
	} 
	else {
	   document.getElementById('contentDiv').innerHTML = errorMessage;
      showDiv('contentDiv');
	
		if (autoSubmit == true) {
			return false;
		}
 	}
}


function detectBrowser() {
	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: "Chrome",
				identity: "Chrome"
			},
			{ 	string: navigator.userAgent,
				subString: "OmniWeb",
				versionSearch: "OmniWeb/",
				identity: "OmniWeb"
			},
			{
				string: navigator.vendor,
				subString: "Apple",
				identity: "Safari",
				versionSearch: "Version"
			},
			{
				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.userAgent,
					subString: "iPhone",
					identity: "iPhone/iPod"
			 },
			{
				string: navigator.platform,
				subString: "Linux",
				identity: "Linux"
			}
		]
	
	};
	BrowserDetect.init();
	
	if ((BrowserDetect.browser == 'Safari') && (BrowserDetect.OS == 'Windows')) {
		document.getElementById('safariLogin').style.display = "block";
	}
}var navigationController = {
   selectMain: function(menuItem) {
      this.navigationSelect('navigation', menuItem);
   },

   selectSub: function(menuItem) {
      this.navigationSelect('subnavigation', menuItem);
   },

   navigationSelect: function(navElement, menuItem) {
      // Manage main navigation

		if (navElement == 'navigation') {
			var theList = document.getElementById(navElement);
			var listElements = theList.getElementsByTagName('li');
			var i;
			
			// If the current element contains the 
			// id of the desired pre-selection,
			// change its class and also the <A>
			// node that it contains
			
			for (i=0; i< listElements.length; i++) {
				if (listElements[i].id == menuItem) {
					listElements[i].className = 'selected';
					
					var linkElements = listElements[i].getElementsByTagName('a');
					linkElements[0].className = 'selected';
				}
			}
		}
		
		// Manage subnavigation
		
		else {
			var listElement = document.getElementById(menuItem);
			var linkElements = listElement.getElementsByTagName('a');
			linkElements[0].className = 'selected';
		}
	}
}


/* strstr()
***********
Javascript equivalent.
*/
function strstr( haystack, needle, bool ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: strstr('Kevin van Zonneveld', 'van');
    // *     returns 1: 'van Zonneveld'
    // *     example 2: strstr('Kevin van Zonneveld', 'van', true);
    // *     returns 2: 'Kevin '
 
    var pos = 0;
 
    pos = haystack.indexOf( needle );
    if( pos == -1 ){
        return false;
    } 
	 else {
	    return true;
    }
}


/* getElementByClassname()
**************************
Get a stack of nodes based on a classname.
*/
function getElementByClassname(classname, node) {
	if (!node) node = document.getElementsByTagName("body")[0];
	
	var a = [];
	var re = new RegExp('\\b' + classname + '\\b');
	var els = node.getElementsByTagName("*");
	
	for(var i=0,j=els.length; i < j; i++)
		if(re.test(els[i].className)) a.push(els[i]);

	return a;
}


/* displayDiv()
***************
*/
function displayDiv(id) {
   var theDiv = document.getElementById(id);

   if (theDiv.style.display == 'none') {
      showDiv(id);
   }
   else {
      hideDiv(id);
   }
}


/* showDiv()
************
*/
function showDiv(id) {
   var theDiv = document.getElementById(id);

   theDiv.style.display = 'block';
}


/* hideDiv()
************
*/
function hideDiv(id) {
   var theDiv = document.getElementById(id);

   theDiv.style.display = 'none';
}


/* Array.prototype.getUniqueValues
**********************************
Gets unique values from an array, returns an array
of uniques.
*/
Array.prototype.getUniqueValues = function () { 
   var hash = new Object();
	
   for (j = 0; j < this.length; j++) {
	   hash[this[j]] = true;
	}
	
   var array = new Array();
	
   for (value in hash) {
	   array.push(value)
	}
	
   return array;
}


/* otherFieldSpecification()
****************************
Used in a combination of [x] Other, please specify [ ... ] 
situations. otherId is the id of the checkbox belonging to "Other";
specifyId is the id of the textbox belonging to the "Other";
errorMessage is returned if the textbox wasn't filled in when the
"Other" checkbox was ticked.

This can be cloned to suit radio buttons etc.
*/
function otherFieldSpecification(otherId, specifyId, errorMessage) {
	if (document.getElementById(otherId).checked == true) {
		if (document.getElementById(specifyId).value == '') {
			return errorMessage + "\n";
		}
	}
	
	return '';
}


/* copyInputValue()
*******************
Copies input from one textbox to another.
Additional parameter "type" will allow expansion
to include other input types.
*/
function copyInputValue(source, destination) {
   var sourceElement = document.getElementById(source);
	var destinationElement = document.getElementById(destination);
	
	destinationElement.value = sourceElement.value;
}


/* writeOrigin()
****************
Creates a cookie using the key/value pair "origin/value" in this format:
?.... origin=myvaluehere ...
*/
function writeOrigin() {
   var regex = new RegExp("(origin=)([a-zA-Z0-9_]+)");
	var matches = regex.exec(location.href);
	
	if (matches != null) {
      createCookie('enteractive_restaurant09Sydney_origin', matches[2], 30);
	}
}


/* redirect()
*************
Redirects to a specified web address.
*/
function redirect(newURL) {
   window.location = newURL;
}


/** Cookie Testing **/

function GetCookie() {
	var strName = "enteractive_cookieTest";
	
	if (document.cookie.indexOf(strName) == -1) {
		return false;
	}
	else {
		cookieStart = document.cookie.indexOf(strName);
		cookieValStart = (document.cookie.indexOf("=", cookieStart) + 1);
		cookieValEnd = document.cookie.indexOf(";", cookieStart);

		if (cookieValEnd == -1) {
			cookieValEnd = document.cookie.length;
		}
		cookieValue = document.cookie.substring(cookieValStart, cookieValEnd);
	}
	
	if (cookieValue = "True") {
		return ("True");
	}
}

function SetCookie(name,value,expires,path,domain,secure) {
	var strDNS = GetDNS();
		document.cookie = name + "=" +escape(value) +
		  ( (expires) ? ";expires=" + expires.toGMTString() + 1000*60*20 : "") +
		( (path) ? ";path=" + path : "") +
		  //( (domain) ? ";domain=" + domain : "") +
		( (domain) ? ";domain=" + strDNS : "") +
		  ( (secure) ? ";secure" : "");
		 return true
}

function GetDNS() {
	cookieDomain = document.location.hostname;
}

function CheckCookiesEnabled(autoSubmit) {
   var errorMessage = "<p><strong>You have disabled Cookies.</strong><br />This page requires Cookies to be enabled. Please check your security settings and enable Cookies before continuing.</p>";

	SetCookie('enteractive_cookieTest','True','','/','','');

   var theDiv = document.getElementById('contentDiv');
	
	if (GetCookie() == "True") {
		if (autoSubmit == true) {
			return true;
		}
		else {
         showDiv('contentDiv');
		}
	} 
	else {
	   document.getElementById('contentDiv').innerHTML = errorMessage;
      showDiv('contentDiv');
	
		if (autoSubmit == true) {
			return false;
		}
 	}
}


function detectBrowser() {
	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: "Chrome",
				identity: "Chrome"
			},
			{ 	string: navigator.userAgent,
				subString: "OmniWeb",
				versionSearch: "OmniWeb/",
				identity: "OmniWeb"
			},
			{
				string: navigator.vendor,
				subString: "Apple",
				identity: "Safari",
				versionSearch: "Version"
			},
			{
				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.userAgent,
					subString: "iPhone",
					identity: "iPhone/iPod"
			 },
			{
				string: navigator.platform,
				subString: "Linux",
				identity: "Linux"
			}
		]
	
	};
	BrowserDetect.init();
	
	if ((BrowserDetect.browser == 'Safari') && (BrowserDetect.OS == 'Windows')) {
		document.getElementById('safariLogin').style.display = "block";
	}
}
