var modeFound = 0;
var debug=false;

setMenuValue();

//============================================================
function setMenuValue() {
	var sMenuItemString;
	var srchData = getSearchAsArray();

	if (debug) {alert(modeFound);}

	if (modeFound) { // update cookie value
		if (debug) {alert(1);}
		if (srchData["m"]=="1"){
			setCookie("ENEN_EDITVIEW_MODE", "View mode", "10", "/");
			sMenuItemString="View mode";
		}
		else {
			setCookie("ENEN_EDITVIEW_MODE", "Edit mode", "10", "/");
			sMenuItemString="Edit mode";
		}
	} else {
		if (debug) {alert(1);}
		var sCookieValue = getCookie("ENEN_EDITVIEW_MODE");
		if (debug) {alert(sCookieValue);}
		if (sCookieValue==null){		// first time -> set cookie value
			setCookie("ENEN_EDITVIEW_MODE", "Edit mode", "10", "/");
			sMenuItemString="Edit mode";
		} else { // get current mode to display in menu
			sMenuItemString=sCookieValue;
		}
	}

	document.write(sMenuItemString);
}
//============================================================
function getSearchAsArray() {
	// Browser-sniffing variables.
	var minNav3 = (navigator.appName == "Netscape" && 
		parseInt(navigator.appVersion) >= 3)
	var minIE4 = (navigator.appName.indexOf("Microsoft") >= 0 && 
		parseInt(navigator.appVersion) >= 4)
	var minDOM = minNav3 || minIE4   // Baseline DOM required       for this function
	// Initialize array to be returned.
	var results = new Array()

		//alert (minDOM) 

	if (minDOM) {
		// Unescape and strip away leading question mark.
		var input = unescape(location.search.substring(1))
		if (input) {
			// Divide long string into array of name/value pairs.
			var srchArray = input.split("&")
			var tempArray = new Array()

			for (i = 0; i < srchArray.length; i++) {
				// Divide each name/value pair temporarily into a two-entry array.
				tempArray = srchArray[i].split("=")
				// Use temp array values as index identifier and value.
				results[tempArray[0]] = tempArray[1]
				if (tempArray[0]=="m"){modeFound=1}
			}
		}
	}
	return results
}
//============================================================
function setCookie(cookie_name, cookie_value, cookie_life, cookie_path) {
	var today = new Date()
	var expiry = new Date(today.getTime() + cookie_life * 24*60*60*1000)
	if (cookie_value != null && cookie_value != ""){
		var cookie_string =cookie_name + "=" + escape(cookie_value)
		if(cookie_life){ cookie_string += "; expires=" + expiry.toGMTString()}
		if(cookie_path){ cookie_string += "; path=" + cookie_path}
 		document.cookie = cookie_string
	}
} 
	
function getCookie(name) {
	var index = document.cookie.indexOf(name + "=")
	if (index == -1) { return null}
	index = document.cookie.indexOf("=", index) + 1
	var end_string = document.cookie.indexOf(";", index)
	if (end_string == -1) { end_string = document.cookie.length }
	return unescape(document.cookie.substring(index, end_string))
}

function del_cookie(name) {
	document.cookie = name + '=' + '; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/';
}
//============================================================

