
	var req=null;
	var mutex_lock=false;
	var added=0;
	
	Function.prototype.defaults = function()
	{
		var _f = this;
		var _a = Array(_f.length-arguments.length).concat(Array.prototype.slice.apply(arguments));
		
		return function()
		{
			return _f.apply(_f, Array.prototype.slice.apply(arguments).concat(_a.slice(arguments.length, _a.length)));
		}
	}
	
	var popup = function (bodyHTML, X, Y )
	{
		
			bodyHTML=bodyHTML.replace(/&lt;/gi,"<");
			bodyHTML=bodyHTML.replace(/&gt;/gi,">");
			bodyHTML=bodyHTML.replace(/&#37;/gi,"%");
			bodyHTML=bodyHTML.replace(/&amp;/gi,"&");
			document.getElementById('alertBox').innerHTML=bodyHTML;
			
		document.getElementById('screen').style.display='inline';
		document.getElementById('screen').style.width=document.documentElement.clientWidth;
		document.getElementById('screen').style.height=document.documentElement.clientHeight;
		document.getElementById('alertBox').style.display='inline';
		/*
		if(X==-1)
			document.getElementById('alertBox').style.left=document.documentElement.clientWidth/2-document.getElementById('alertBox').scrollWidth/2;
		else
			document.getElementById('alertBox').style.left=X;
		
		if(Y==-1)
			document.getElementById('alertBox').style.top=document.documentElement.clientHeight/2-document.getElementById('alertBox').scrollHeight/2;
		else
			document.getElementById('alertBox').style.top=Y;
		*/
		
	}.defaults("default", -1, -1);

	
	function submit_form(id)
	{
		document.getElementById(id).submit();
	}	
	
	function initializeXML()
	{
		try
		{
			// Firefox, Opera 8.0+, Safari
			req=new XMLHttpRequest();
		}
		catch (e)
		{
			// Internet Explorer
			try
			{
				req=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				req=new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		if (req==null)
		{
			//alert ("Browser does not support HTTP Request");
		}
	}
	
	initializeXML();
	
	function XMLcompleted() 
	{ 
		if (req.readyState==4 || req.readyState=="complete")
		{ 
		
			xmlDoc=req.responseXML;
			
			document.getElementById('notes').value=xmlDoc.getElementsByTagName('notes')[0].childNodes[0].nodeValue;
			
			if(document.getElementById('notes').value=="-")
				document.getElementById('notes').value="";
			
			/*
			dateString=document.getElementById('due').value;
			var now = new Date();
			var date = new Date(dateString.substring(0,4),
				dateString.substring(5,7)-1,
				dateString.substring(8,10));
			if (
					((now.getYear()>date.getYear()) || 
					(now.getYear()==date.getYear() && now.getMonth()>date.getMonth()) || 
					(now.getYear()==date.getYear() && now.getMonth()==date.getMonth() && now.getDate()>date.getDate()))
					&&
					(pay_method_value>2 && pay_method_value<6))
			*/
			
			mutex_lock=false;
		} 
	}
	
	function XMLviewcart() 
	{ 
			//alert(32);
		if (req.readyState==4 || req.readyState=="complete")
		{ 
		
			xmlDoc=req.responseXML;
			
			if(xmlDoc==null)
			{
				//alert(2);
				return;
			}
			
			theArray=xmlDoc.getElementsByTagName("body");
			theLen=theArray.length;
			result="";
			for(i=0; i<theLen; i++)
				result+=theArray[i].childNodes[0].nodeValue;
			popup(result);
			mutex_lock=false;
		} 
	}
	
	var getXML = function (URL,query,mode)
	{
		if(mutex_lock || URL=="")
			return;
		else
			mutex_lock=true;
			
		if(mode=="viewCart")
		{
			req.onreadystatechange=XMLviewcart;
		}
		else
			req.onreadystatechange=XMLcompleted;
			
		req.open("POST", URL, true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		var encoded = "";
		encoded = query;
		req.send(encoded);
	}.defaults('','','');
	
	function validateXML()
	{
		if (req.readyState==4 || req.readyState=="complete")
		{
			xmlDoc=req.responseXML;
			//alert('validateXML');
			if(xmlDoc!=null)
			{
			theArray=xmlDoc.getElementsByTagName("body");
			theLen=theArray.length;
			for(i=0; i<theLen; i++)
				popup(theArray[i].childNodes[0].nodeValue);
			}
			mutex_lock=false;
			viewCart();
		}
	}
	
	function addItem(id)
	{		
		
		if(added!=0)
		{
			viewCart();
			return;
		}
		else
			added=id;
			
		if(mutex_lock)
			return;
		else
			mutex_lock=true;
		req.onreadystatechange=validateXML;
		req.open("POST", "modifyCart.php", true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		var multiPart=document.getElementById("multiPart");
		if(multiPart!=null)
		{
			multiPart="&mP="+multiPart.value;
		}
		else
			multiPart="";
		var encoded = "";
		encoded = "cart_mode=add&add_item=" + id + multiPart;
		req.send(encoded);
		temp=parseInt(document.getElementById("cart_total").innerHTML.replace("<a xmlns=\"http://www.w3.org/1999/xhtml\">","").replace("</a>",""),10);
		document.getElementById("cart_total").innerHTML=(temp+1);
	}
	
	function updateItem()
	{		
		if(mutex_lock)
			return;
		else
			mutex_lock=true;
			
		cartItems=document.getElementsByName("keys");

		len=cartItems.length;
		getValues="cart_mode=update";
		for(i=0; i<len; i++)
		{
			id=cartItems[i].value;
			ITEM=document.getElementById(id+"_count").value;
			getValues+="&key:"+id+"="+ITEM;
			//alert(id + " has value " + item);
		}
		
		req.onreadystatechange=validateXML;
		req.open("POST", "modifyCart.php", true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		var encoded = "";
		encoded = getValues;
		req.send(encoded);
	}
	
	function removeItem(id)
	{		
		if(mutex_lock)
			return;
		else
			mutex_lock=true;
		if(added==id)
			added=0;
		
		req.onreadystatechange=validateXML;
		req.open("POST", "modifyCart.php", true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		var encoded = "";
		encoded = "remove_item=" + id + "&cart_mode=remove";
		req.send(encoded);
		temp=parseInt(document.getElementById("cart_total").innerHTML.replace("<a xmlns=\"http://www.w3.org/1999/xhtml\">","").replace("</a>",""),10);
		document.getElementById("cart_total").innerHTML=(temp-1);
	}
	
	function emailFriend()
	{		
		req.onreadystatechange=validateXML;
		req.open("POST", "email.php", true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		var encoded = "";
		encoded = "first=" + document.getElementById('first').value +
			"&last=" + document.getElementById('last').value;
		req.send(encoded);
	}
	
	
	function clearPopup()
	{
		document.getElementById('screen').style.display='none';
		document.getElementById('alertBox').style.display='none';
	}
	function viewCart()
	{
		getXML("returnCart.php","vari=irav","viewCart");
	}
	
	function adjust()
	{
		document.getElementById('screen').style.width=document.documentElement.clientWidth;
		document.getElementById('screen').style.height=document.documentElement.clientHeight;
		
		//document.getElementById('alertBox').style.left=document.documentElement.clientWidth/2-document.getElementById('alertBox').scrollWidth/2;
		//document.getElementById('alertBox').style.top=document.documentElement.clientHeight/2-document.getElementById('alertBox').scrollHeight/2;
	}
	
	function navto(url)
	{
		window.location.href=url;
	}
	
	function enlarge(title,img)
	{
	
		sz=title.length;
		if(sz<16)
			sz = 5;
		else if(sz>=16 && sz<22)
			sz = 4;
		else if(sz>=22 && sz<27)
			sz = 3;
		else if(sz>=27 && sz<32)
			sz = 2;
		else
			sz = 1;
		html="";
		html += '<img style="position: absolute; left: 0px; top: -78px;" width="760" src="pop_up_images/header_label_inv.png" /> ';
		html += '<div  style="position: absolute;  width: 200px; top: -53px; left: 15px; z-index: 10; font-family: Palatino,Georgia,\'Times New Roman\',Times,serif;">';
		html += "<font size=\""+sz+"\"><b>"+title+"</b></font><br>";
		html += '</div>';
		html += '<img onmouseover="document.body.style.cursor=\'pointer\';" onmouseout="document.body.style.cursor=\'default\';" onclick="clearPopup()" style="position: absolute; left: 700px; top: -66px;" src="pop_up_images/closebutton.png" /> ';
		html += '<table bgcolor="#FFFFFF"  width="754"> ';
		html += '<tr> ';
		html += '<td width="754" height="352">';
		html += '<center><img src="uploaded_images/l_'+img+'" width="754"></center>';
		html += '</td>';
		html += '</tr>';
		html += '</table><br><br>';
		html += '</span>';
		popup(html);
	}
