// JavaScript Document
/**
 * @author alexanderia_lover
 * @copyright 2008
 */
// creating ajax object

	if (window.ActiveXObject) {
	
	 xmlHttp12 = new ActiveXObject("Msxml2.XMLHTTP");
	}
	else  {
	
	 xmlHttp12 = new XMLHttpRequest();
	}

function getOrderItems()
	{
	xmlHttp12.open("GET","order_itemsList.php", true);	
	xmlHttp12.onreadystatechange = getOrderItems_Handler;
	xmlHttp12.send(null);
	}	
	
function getOrderItems_Handler()
{
	if (xmlHttp12.readyState == 1)
		{
		document.getElementById("orderCheckDiv").innerHTML="<img src='images/ajax-loader2.gif' alt='loading..' />"
		}

	if (xmlHttp12.readyState == 4) 
		{ 
		document.getElementById("orderCheckDiv").innerHTML = xmlHttp12.responseText ;
		}	 
}	

function removeOrderItem(productID)
	{
	xmlHttp12.open("GET","order_removeItem.php?productID="+productID, true);
	xmlHttp12.onreadystatechange = removeOrderItem_Handler;
	xmlHttp12.send(null);			
	}
	
function removeOrderItem_Handler()
	{
		if (xmlHttp12.readyState == 1)
			{
				//this code for the small ajax box which is under the main menu
			if(document.getElementById("orderCheckDiv"))
				{
			document.getElementById("orderCheckDiv").innerHTML="<img src='images/ajax-loader2.gif' alt='loading..' />";
				}
			//this code for the my_cart.php page
			//if the user was deleteing while he is in the mycart.php this will refresh the cart items
			if(document.getElementById("myCartdiv"))
				{
	            document.getElementById("myCartdiv").innerHTML="<img src='images/ajax-loader2.gif' alt='loading..' />"
				}
			}
	
		if (xmlHttp12.readyState == 4) 
			{ 
			//this code for the small ajax box which is under the main menu
			 if(document.getElementById("orderCheckDiv"))
				{
					getOrderItems();
				}
			//this code for the my_cart.php page
			 //if the user was deleteing while he is in the mycart.php this will refresh the cart items
			 if(document.getElementById("myCartdiv"))
				{
					//note that if there was no items at all -i mean the xmlHttp.responseText is null- so we haven't to replace the content of the myCartdiv with null .. we will refresh the page to give the empty cart message.
					if(xmlHttp12.responseText){
					document.getElementById("myCartdiv").innerHTML = xmlHttp12.responseText ;
					}
					else
					{
						document.location.href =('my_cart.php');
					}
				}
			
			}	 
	}
		
