/* NAVIGATION */

function secMenuAssortment()
{
	document.getElementById('navS').innerHTML =
		'<label style="cursor: pointer;" onclick="parent.location=\'index.php?path=SpecialRequest\'" onmouseover="this.className=\'navSon\'" onmouseout="this.className=\'\'"><a href="index.php?path=SpecialRequest">Special request</a></label>'+
		'<label style="cursor: pointer;" onclick="parent.location=\'index.php?path=DirectOrder&categorie=Food\'" onmouseover="this.className=\'navSon\'" onmouseout="this.className=\'\'"><a href="index.php?path=DirectOrder&categorie=Food">Food</a></label>'+
		'<label style="cursor: pointer;" onclick="parent.location=\'index.php?path=DirectOrder&categorie=Drink\'" onmouseover="this.className=\'navSon\'" onmouseout="this.className=\'\'"><a href="index.php?path=DirectOrder&categorie=Drink">Drink</a></label>';
		//'<label style="cursor: pointer;" onclick="parent.location=\'index.php?path=DirectOrder\'" onmouseover="this.className=\'navSon\'" onmouseout="this.className=\'\'"><a>Direct order</a></label>';
		//'<label style="cursor: pointer;" onclick="parent.location=\'index.php?path=Promotions\'" onmouseover="this.className=\'navSon\'" onmouseout="this.className=\'\'"><a href="index.php?path=promotions">Promotions</a></label>';
}

function secMenuServices()
{
	document.getElementById('navS').innerHTML =
		'<label style="cursor: pointer;" onclick="parent.location=\'index.php?path=Services\'" onmouseover="this.className=\'navSon\'" onmouseout="this.className=\'\'"><a href="index.php?path=Services">Services</a></label>'+
		'<label style="cursor: pointer;" onclick="parent.location=\'index.php?path=Funmiles\'" onmouseover="this.className=\'navSon\'" onmouseout="this.className=\'\'"><a href="index.php?path=Funmiles">Funmiles</a></label>'+
		'<label style="cursor: pointer;" onclick="parent.location=\'index.php?path=Policy\'" onmouseover="this.className=\'navSon\'" onmouseout="this.className=\'\'"><a href="index.php?path=Policy">Policy</a></label>';
}

function secMenuInformation()
{
	document.getElementById('navS').innerHTML =
		'<label style="cursor: pointer;" onclick="parent.location=\'index.php?path=Location\'" onmouseover="this.className=\'navSon\'" onmouseout="this.className=\'\'"><a href="index.php?path=Location">Location</a></label>'+
		'<label style="cursor: pointer;" onclick="parent.location=\'index.php?path=History\'" onmouseover="this.className=\'navSon\'" onmouseout="this.className=\'\'"><a href="index.php?path=History">History</a></label>'+
		'<label style="cursor: pointer;" onclick="parent.location=\'index.php?path=Aboutus\'" onmouseover="this.className=\'navSon\'" onmouseout="this.className=\'\'"><a href="index.php?path=Aboutus">About us</a></label>';
}

function secMenuEmpty()
{
	document.getElementById('navS').innerHTML = '';
}

function selectCategorie(targ,selObj)
{
	eval("parent.location='index.php?path=DirectOrder&categorie="+selObj.options[selObj.selectedIndex].value+"'");
}

function selectLocation(targ,selObj)
{
	eval("parent.location='index.php?path=Location&id="+selObj.options[selObj.selectedIndex].value+"'");
}

/* XML */

function addOrder(productId, quantity, size)
{
	xmlhttp=null
	//code for Mozilla, etc.
	if (window.XMLHttpRequest)
	{
  		xmlhttp=new XMLHttpRequest()
  	}
	// code for IE
	else if (window.ActiveXObject)
  	{
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  	}
	if (xmlhttp!=null)
  	{
		xmlhttp.onreadystatechange=onResponseOrder;
		xmlhttp.open("GET","index.php?path=AddOrder&id="+productId+"&quantity="+quantity+"&size="+size,true);
		//alert("index.php?path=AddOrder&id="+productId+"&quantity="+quantity+"&size="+size);
		xmlhttp.send(null);
  	}
	else
	{
		alert("Your browser does not support XMLHTTP.")
	}
	hideToolTip('tooltipOrder');
	document.getElementById('quantity').value = '';
	document.getElementById("size").selectedIndex = 0;
}

function onResponseOrder()
{
	checkReadyState(xmlhttp);
}

function loadXMLDoc(url, what) 
{
	xmlhttp=null
	//code for Mozilla, etc.
	if (window.XMLHttpRequest)
	{
  		xmlhttp=new XMLHttpRequest()
  	}
	// code for IE
	else if (window.ActiveXObject)
  	{
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  	}
	if (xmlhttp!=null)
  	{
		if(what==1)
			xmlhttp.onreadystatechange=onResponsePromotion;
		else
			xmlhttp.onreadystatechange=onResponseOrder;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
  	}
	else
	{
		alert("Your browser does not support XMLHTTP.")
	}
}

function checkReadyState(obj)
{
	if(obj.readyState == 4)
	{
		if(obj.status == 200)
			return true;
		else
			alert("Problem retrieving XML data");
	}
}

function onResponsePromotion()
{
	if(checkReadyState(xmlhttp))
	{
		var response = xmlhttp.responseXML.documentElement;
		x=response.getElementsByTagName("promotion");
		document.getElementById('tooltipTitle2').innerHTML = x[0].getElementsByTagName("title")[0].firstChild.data;
		document.getElementById('tooltipPrice').innerHTML="$ "+x[0].getElementsByTagName("price_dollar")[0].firstChild.data+"<br />"+x[0].getElementsByTagName("price_naf")[0].firstChild.data+" Naf";
		document.getElementById('tooltipPicture').style.background = "url(../pictures/promotions/g"+x[0].getElementsByTagName("promotionId")[0].firstChild.data+"."+x[0].getElementsByTagName("picture")[0].firstChild.data+")";
		document.getElementById('tooltipNavLeft').innerHTML = "&nbsp;<a href=\"#\" id=\"tooltipPrevious\" onclick=\"showPromotion(event,"+x[0].getElementsByTagName("previous")[0].firstChild.data+",130,176)\">Previous</a> - <a href=\"#\" id=\"tooltipNext\" onclick=\"showPromotion(event,"+x[0].getElementsByTagName("next")[0].firstChild.data+",130,176)\">Next</a>";
	}
}

function onResponseOrder2()
{
	if(checkReadyState(xmlhttp))
	{
		var response = xmlhttp.responseXML.documentElement;
		x=response.getElementsByTagName("product");
	}
}

function onResponseOrder3() 
{
	var txt;
	if(checkReadyState(xmlhttp))
	{
		var response = xmlhttp.responseXML.documentElement;
		txt='<table width="94%">';
		x=response.getElementsByTagName("product");
		for (i=0;i<x.length;i++)
	  	{
	  		txt=txt + "<tr valign=\"top\">";
	  		xx=x[i].getElementsByTagName("itemcode");
	    	{
		    	try
		      	{
		      		txt=txt + "<td>" + xx[0].firstChild.data + "</td>";
		      	}
		    	catch (er)
		      	{
		      		txt=txt + "<td> </td>";
		      	}
	    	}
	  		xx=x[i].getElementsByTagName("product");
	    	{
			    try
			    {
			    	txt=txt + "<td>" + xx[0].firstChild.data + "</td>";
			    }
			    catch (er)
			    {
			      	txt=txt + "<td> </td>";
			    }
	    	}
	  		txt=txt + "</tr>"
	 	}
		txt=txt + "</table>";
		document.getElementById('orderList').innerHTML=txt;
	}
}

/* AJAX TOOLTIP */

function showTooltip(e, div, hWidth, hHeight)
{
	var winW = 630, winH = 460;

	if (parseInt(navigator.appVersion)>3) 
	{
 		if (navigator.appName=="Netscape" || navigator.appName=="Opera") 
 		{
  			winW = window.innerWidth;
  			winH = window.innerHeight;
 		}
 		if (navigator.appName.indexOf("Microsoft")!=-1) 
 		{
  			winW = document.body.offsetWidth;
  			winH = document.body.offsetHeight;
 		}
	}

	if(document.all)
		e = event;
	
	var obj = document.getElementById(div);
	obj.style.display = 'block';
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)
		st=0; 
	var leftPos = e.clientX - -50;
	if(leftPos<0)
		leftPos = 0;
	obj.style.left = (winW / 2)-hWidth + 'px';
	obj.style.top = (winH / 2)-hHeight + 'px';
}

function showPromotion(e,id, hWidth, hHeight)
{
	showTooltip(e, 'tooltip', hWidth, hHeight);
	
	//load the xml into page
	loadXMLDoc("index.php?path=Promotionxml&id="+id, 1);
}

function showOrder(id,e, hWidth, hHeight)
{
	showTooltip(e, 'tooltipOrder', hWidth, hHeight);
	document.getElementById('productId').value = id;
}

function hideToolTip(div)
{
	document.getElementById(div).style.display = 'none';
}

/* */

function screenAddOrder(id)
{
	var w = 353;
	var h = 245;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	var pos = "left="+winl+",top="+wint;
	newWindow = window.open("index.php?path=AddOrder&id="+id,"_blank","dependent=yes,scrollbars=no,width="+w+",height="+h+","+pos);
}

function updateOrder(group)
{
	loadXMLDoc("index.php?path=OrderXml&group="+group, 2);
}