// is there an existing cookie for the menu option?

function siteRootDir()
{
	return "http://www.evergreen-nebulizers.co.uk/";
}

function getCookieValue(aName) {
	var value = "";
	var myCookie = document.cookie;
	var searchText = aName + "=";
	var pos = myCookie.indexOf(searchText);
	if (pos != -1) {
			// got match
			var start = pos + searchText.length;
			var end = myCookie.indexOf(";", start);
			if (end == -1) end = myCookie.length;
			value = myCookie.substring(start, end);
			value = unescape(value);
	}
	return value;
}

function showMenuCategories()
{
	return getCookieValue("menuShowCats");
}

function setCookieValue(aName, aValue) {
	// aName isn't going to change but...
	var expDate = new Date();
	expDate.setMonth(expDate.getMonth() + 6);
	document.cookie = aName + "=" + aValue + "; path=/;expires= " + expDate.toGMTString();
}


function useCatMenu(aBool) {
		setCookieValue("menuShowCats", aBool);
}

function createDefaultCookie() {
	var expDate = new Date();
	expDate.setMonth(expDate.getMonth() + 6);
	document.cookie = "menuShowCats=false; path=/; expires=" + expDate.toGMTString();
	return "false";
}

function showCookieValues() {
	if (document.cookie != "") {
		document.write(document.cookie);
	} else {
		document.write("no cookie values");
	}
}

function loadCookie() {
	var res = "";
	if (document.cookie != "")
	{
		// read the value set
		res = getCookieValue("menuShowCats");
		
	} else {
		res = createDefaultCookie();
	}
	return res;
}

function setSelectedIdx() {
	if (showMenuCategories() == "true") {
		document.selector.usrChoice.selectedIndex = 1;	
	} else {
		document.selector.usrChoice.selectedIndex = 0;
	}
}

function getManMenu()
{
	// build text for manufacturer menu
	var menuTxt = '<p><a href="' + siteRootDir() + 'respironics/respironics.html">Philips Respironics</a> </p>'
    + '<p><a href="' + siteRootDir() + 'omron/omron.html">Omron</a></p>'
    + '<p><a href="' + siteRootDir() + 'pari/pari.html">Pari Medical</a> </p>'
    + '<p><a href="' + siteRootDir() + 'hscc/medix.html">The Medix range from Clement Clark</a> </p>'
    + '<p><a href="' + siteRootDir() + 'oximeters/pulse_oximeters.html">Pulse Oximeters</a> </p>'
    + '<p><a href="' + siteRootDir() + 'hscc/flutter.html">Flutter mucus clearance device</a></p>';
  return menuTxt;
}

function getCatMenu()
{
	// build text for category menu
	var menuTxt = '<p><a href="' + siteRootDir() + 'categories/budget.html">Budget Mains Only</a></p>'
		+ '<p><a href="' + siteRootDir() + 'categories/midrange.html">Mid Range Mains Only</a></p>'
		+ '<p><a href="' + siteRootDir() + 'categories/professional.html">Professional Mains Only</a></p>'
		+ '<p><a href="' + siteRootDir() + 'categories/portable.html">Portable Nebulisers</a></p>'
		+ '<p><a href="' + siteRootDir() + 'oximeters/pulse_oximeters.html">Pulse Oximeters</a> </p>'
		+ '<p><a href="' + siteRootDir() + 'hscc/flutter.html">Flutter mucus clearance device</a></p>';
	return menuTxt;
}

function chgMenuOption(value) 
{
 		//document.write(value);
 		useCatMenu(value);
 		if (value == "true") {
 			window.location = siteRootDir() + 'categories/selectcat.html';
 		} else {
			window.location = siteRootDir() + "order.html";
		}
}