﻿var xmlHttp;
var ReturnValue;
function RemoveItem(id1)
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }
	var url="/add_cart.php?action=remove&id="+id1+ "&t=" + new Date().getTime();
	xmlHttp.onreadystatechange=AddToCart_Changed;
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	function AddToCart_Changed() 
	{ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		 { 
			if (xmlHttp.responseText=="Remove Done")
			{
				window.location.reload();
			}
		}
	}
}

function AddToCart(obj1)
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }
	var url="/add_cart.php?action=add&id="+obj1.id.replace('productID_','') + "&t=" + new Date().getTime();
	xmlHttp.onreadystatechange=AddToCart_Changed;
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	function AddToCart_Changed() 
	{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 { 
		if (xmlHttp.responseText=="Fail")
		{
			alert("Error! Please Try Again");
		}
		else
		{
			if (document.getElementById("no_item_display")!=null)
			{
				document.getElementById("no_item_display").innerHTML='<a href="/your_cart.php" style="color:#FFFF00; font-size:18px; text-decoration:underline;">Edit / Process Order</a>';
			}
			if(xmlHttp.responseText.substr(0,3)=="Yes")
			{
				var FinalData=xmlHttp.responseText.split('|');
				if (document.getElementById("div_qty_"+obj1.id.replace('productID_',''))==null)
				{
					var FinalData=xmlHttp.responseText.split('|');
					FinalData[0]=FinalData[0].replace('Yes','');
					var BigTable=document.getElementById("cart_table").getElementsByTagName("TBODY")[0];
					var row1=BigTable.insertRow(-1);
					row1.id="tr_small_cart_"+obj1.id.replace('productID_','');
					row1.setAttribute('class','item_color');
					var cell2=row1.insertCell(-1);
					cell2.innerHTML=FinalData[0];
					var cell3=row1.insertCell(-1);
					cell3.vAlign="top";
					cell3.innerHTML='<div id="div_qty_'+ obj1.id.replace('productID_','') +'" style="position:absolute;">'+FinalData[1]+'</div>';
					var cell4=row1.insertCell(-1);
					cell4.innerHTML='<div style="text-align:right;" id="div_price_'+ obj1.id.replace('productID_','') +'">RM'+FinalData[2]+'</div>';
				}
				else
				{
					document.getElementById("div_qty_"+obj1.id.replace('productID_','')).innerHTML='<div id="div_qty_'+ obj1.id.replace('productID_','') +'" style="position:absolute;">'+FinalData[1]+'</div>';
					document.getElementById("div_price_"+obj1.id.replace('productID_','')).innerHTML='<div id="div_price_'+ obj1.id.replace('productID_','') +'" style="text-align:right;">RM'+FinalData[2]+'</div>';
				}
			}
			else
			{
				var FinalData=xmlHttp.responseText.split('|');
				var BigTable=document.getElementById("cart_table").getElementsByTagName("TBODY")[0];
				var row1=BigTable.insertRow(-1);
				row1.id='tr_small_cart_'+obj1.id.replace('productID_','');
				row1.setAttribute('class','item_color');
				var cell2=row1.insertCell(-1);
				cell2.innerHTML=FinalData[0];
				var cell3=row1.insertCell(-1);
				cell3.vAlign="top";
				cell3.innerHTML='<div id="div_qty_'+ obj1.id.replace('productID_','') +'" style="position:absolute;">'+FinalData[1]+'</div>';
				var cell4=row1.insertCell(-1);
				cell4.innerHTML='<div style="text-align:right;" id="div_price_'+ obj1.id.replace('productID_','') +'">RM'+FinalData[2]+'</div>';
			}
		}
	ChangeFontSize(obj1.id.replace('productID_',''));		
	 } 
	}

}
var AFont=14;
var aaa=document.all;
function ChangeFontSize(id1)
{
	AFont++;
	document.getElementById("div_qty_"+id1).style.fontSize=AFont+"px";
	if ((AFont==80 && aaa!=null) || (AFont==150 && aaa==null) )
	{
		ChangeFontSize2(id1);
	}
	else
	{
		setTimeout("ChangeFontSize('"+id1+"')",1);
	}
}
function ChangeFontSize2(id1)
{
	AFont--;
	document.getElementById("div_qty_"+id1).style.fontSize=AFont+"px";
	if (AFont==14)
	{
		
	}
	else
	{
		setTimeout("ChangeFontSize2('"+id1+"')",1);
	}
}
//--------------------------------------Below No Need Change------------------------

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}












