function getMenuCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function setMenuCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value);
//((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function checkMenuCookie()
{
activemenu=getMenuCookie('activemenu');
if (activemenu!=null && activemenu!="")
  {
  return activemenu;
  }
  else 
  {
  activemenu="typemenu";
  setMenuCookie('activemenu',activemenu,3);
  return activemenu;
  }
}

function setMenu()
{
  activemenu=checkMenuCookie();
//  document.getElementById(activemenu).style.display="block";
  if (document.getElementById('tabmenu'))
    {
	  switch(activemenu)
	  {
		case "typemenu":
		  document.getElementById("swapbutton1").style.display="none";
		  document.getElementById("swapbutton2").style.display="inline";
		  document.getElementById("swapbutton3").style.display="inline";
		  break;
	
		case "nationmenu":
		  document.getElementById("swapbutton1").style.display="inline";
		  document.getElementById("swapbutton2").style.display="none";
		  document.getElementById("swapbutton3").style.display="inline";
		  break;
	
		case "brandmenu":
		  document.getElementById("swapbutton1").style.display="inline";
		  document.getElementById("swapbutton2").style.display="inline";
		  document.getElementById("swapbutton3").style.display="none";
		  break;
	   }
	}
  loadXMLDoc(activemenu);
}

var xmlhttp;

function loadXMLDoc(menufile)
	{
	mpath="/";
	xmlfile = mpath + menufile + ".xml";
	
	xmlhttp=null;
	if (window.XMLHttpRequest)
	  {// code for IE7, Firefox, Mozilla, etc.
	  xmlhttp=new XMLHttpRequest();
	  }
	else if (window.ActiveXObject)
	  {// code for IE5, IE6
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	if (xmlhttp!=null)
	  {
	  xmlhttp.onreadystatechange=onResponse;
	  xmlhttp.open("GET",xmlfile,true);
	  xmlhttp.send(null);
	  }
	else
	  {
	  alert("Your browser does not support XMLHTTP.");
	  }
	}

function onResponse()
	{
	if(xmlhttp.readyState!=4) return;
	if(xmlhttp.status!=200) return;

	topmenu=xmlhttp.responseXML.getElementsByTagName("menu")[0].childNodes;

	txt="<ul>";
	mno=0;

	for  (tiptr=0; tiptr < topmenu.length; tiptr++)
		{
		tmitem=topmenu[tiptr];
		if (tmitem.nodeType==1)
			{
			midmenu=tmitem.getElementsByTagName("menu");
			if (midmenu.length > 0)
				{
				mno++;
				txt=txt + "<li onmouseover=show('mno" + mno + "'); onmouseout=hide('mno" + mno + "');>" + makelink(tmitem,true);
				txt=txt + "<ul id='mno" + mno + "'>";
				miditemlist=midmenu[0].childNodes;
				for (mptr=0; mptr < miditemlist.length; mptr++)
					{
					mmitem=miditemlist[mptr];
					if (mmitem.nodeType==1)
						{
						submenu=mmitem.getElementsByTagName("menu");
						if (submenu.length > 0)
							{
							mno++;
							txt=txt + "<li onmouseover=show('mno" + mno + "'); onmouseout=hide('mno" + mno + "');>" + makelink(mmitem,true);
							txt=txt + "<ul id='mno" + mno + "'>";
							subitemlist=submenu[0].childNodes;
							for (sptr=0; sptr < subitemlist.length; sptr++)
								{
								smitem=subitemlist[sptr];
								if (smitem.nodeType==1)
									{
									txt=txt + "<li>" + makelink(smitem) + "</li>";
									}
								}
							txt=txt + "</ul>";
							} else {
								txt=txt + "<li>" + makelink(mmitem);
							}
						txt=txt + "</li>";
						}
					}
					txt=txt + "</ul>";
				} else {
					txt=txt+"<li>"+makelink(tmitem);
				}
				txt=txt + "</li>";
			}
		}		
	txt=txt + "</ul>";
	document.getElementById("menuholder").innerHTML=txt;
	}

function makelink(mitem,withchild)
	{
	text=mitem.getAttribute("text");
	cat=mitem.getAttribute("cat");
	mtext="<a href='" + cat + "'>"// change here, delete the zoom tool. 
	if (withchild) { mtext=mtext+"<b>&#187;</b>"; }
	mtext=mtext + text + "</a>";
	return mtext;
	}
	
	function show(id) 
	{
	var d = document.getElementById(id);
	if (d) {d.style.visibility='visible';}
	}

function hide(id) 
	{
	var d = document.getElementById(id);
	if (d) {d.style.visibility='hidden';}
	}
	
function menuswap(newid)
{
  switch(newid)
  {
    case "typemenu":
      document.getElementById("swapbutton1").style.display="none";
      document.getElementById("swapbutton2").style.display="inline";
      document.getElementById("swapbutton3").style.display="inline";
      break;

    case "nationmenu":
      document.getElementById("swapbutton1").style.display="inline";
      document.getElementById("swapbutton2").style.display="none";
      document.getElementById("swapbutton3").style.display="inline";
      break;
	  
    case "brandmenu":
      document.getElementById("swapbutton1").style.display="inline";
      document.getElementById("swapbutton2").style.display="inline";
      document.getElementById("swapbutton3").style.display="none";
      break;
   }
   setMenuCookie('activemenu',newid,"0");
   loadXMLDoc(newid);
}
var mxmlhttp;

function mloadXMLDoc()
	{
	mpath="/";
	mxmlfile = mpath + "nationmenu.xml";
	mxmlhttp=null;
	if (window.XMLHttpRequest)
	  {// code for IE7, Firefox, Mozilla, etc.
	  mxmlhttp=new XMLHttpRequest();
	  }
	else if (window.ActiveXObject)
	  {// code for IE5, IE6
	  mxmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	if (mxmlhttp!=null)
	  {
	  mxmlhttp.onreadystatechange=monResponse;
	  mxmlhttp.open("GET",mxmlfile,true);
	  mxmlhttp.send(null);
	  }
	else
	  {
	  alert("Your browser does not support XMLHTTP.");
	  }
	}

function monResponse()
	{
	if(mxmlhttp.readyState!=4) return;
	if(mxmlhttp.status!=200) return;

	topmenu=mxmlhttp.responseXML.getElementsByTagName("menu")[0].childNodes;

	for (mi=0; mi<topmenu.length; mi++)
	  {
	  mitem=topmenu[mi];
	  if (mitem.nodeType==1)
	  	{
	  mtext=mitem.getAttribute('text')
	  mcat=mitem.getAttribute('cat');
	  marray.push(mtext);
	  carray.push(mcat);
	  	}
	  }
	htmltext=""  
	for (fip=0; fip<flagarray.length; fip++)
	  {
	  scountry=flagarray[fip][0];
	  picturl=flagarray[fip][1];
	  cat=findcat(scountry);
	  htmltext+='<a href="' + cat + '">'; // change here, delete the zoom tool 
	  
	  htmltext+='<img src="/graphics/' + picturl + '"></a>';
	  }
	document.getElementById('flagmenuholder').innerHTML=htmltext;
	}
	
function findcat(country)
	{
	cat='';
	for (fi=0; fi<marray.length; fi++)
		{
		if (marray[fi]==country)
			{
			cat=carray[fi];
			break;
			}
		}
	return cat;
	}