var lastModifiedProductID = '';
var lastAction = '';

function addToCart(productID)
{
	var inputCountID ='orderInputID_'+productID;
	var inputCount = document.getElementById(inputCountID).value;
	var rand = Math.random(9999);//kulonben lehet, hogy cache-el
	var url = 'UpdateCart.php'+'?action=add&productID='+productID+'&inputCount='+inputCount+'&rand='+rand;//+'&sid='+sid;
	lastModifiedProductID = productID;
	lastAction = 'add';
//	makeRequest(updateContent,'test.xml');
	makeRequest(updateContent,url);
}

function modifyProductCount(productID,updateFromCartPage)
{
	var inputCountID = 'orderInputID_'+productID;
	var inputCount = document.getElementById(inputCountID).value;
	var rand = Math.random(9999);//kulonben lehet, hogy cache-el
	var url = 'UpdateCart.php'+'?action=modify&productID='+productID+'&inputCount='+inputCount+'&updateFromCartPage='+updateFromCartPage+'&rand='+rand;//+'&sid='+sid;
	lastModifiedProductID = productID;
	lastAction = 'add';
//	makeRequest(updateContent,'test.xml');
	makeRequest(updateContent,url);
}

function removeFromCart(productID,updateFromCartPage)
{
	var rand = Math.random(9999);//kulonben lehet, hogy cache-el
	var url = 'UpdateCart.php'+'?action=remove&productID='+productID+'&updateFromCartPage='+updateFromCartPage+'&rand='+rand;//+'&sid='+sid;
	lastModifiedProductID = productID;
	lastAction = 'delete';
	makeRequest(updateContent,url);
}

function updateContent()
{
	//alert(http_request.responseText);
//	var xmldoc = http_request.responseXML;
//	var root = xmldoc.getElementsByTagName('root').item(0);//alert(xmldoc);alert(root);

/*	var xmldoc = http_request.responseXML;alert(xmldoc);
	var root_node = xmldoc.getElementsByTagName('response').item(0);
	alert(root_node);

	var response = http_request.responseXML.documentElement;alert(response);
	var isOk = response.getElementsByTagName("isOk")[0].firstChild.data;
	var currentOrderCount = response.getElementsByTagName("currentOrderCount")[0].firstChild.data;*/
	var returnArray = http_request.responseText.split(';;');
	var currentOrderCount = returnArray[0];
	var numOfItemsInCart = returnArray[1];
	var priceOfItemsInCart = returnArray[2];
	var currentOrderCountID ='currentOrderCountID_'+lastModifiedProductID;//alert(currentOrderCount);
	
	elem = document.getElementById(currentOrderCountID);
	if ( elem )
		elem.innerHTML = currentOrderCount;

	document.getElementById('ListOfItemsInCartID').innerHTML = returnArray[3];

	elem = document.getElementById('cartContentID');
	if ( elem ) {
		if ( numOfItemsInCart > 0 )
			elem.innerHTML = returnArray[4];
		else
			elem.innerHTML = '';	
	}

	if ( lastAction == 'add' )
		var myFx1 = new Fx.Tween('addToCartImg_'+lastModifiedProductID, {property: 'opacity',duration: 200} );
	else//'delete'
		var myFx1 = new Fx.Tween('deleteFromCartImg_'+lastModifiedProductID, {property: 'opacity',duration: 200} );
	var myFx2 = new Fx.Tween(currentOrderCountID, {property: 'opacity',duration: 200} );
	var myFx3 = new Fx.Tween('ListOfItemsInCartID', {property: 'opacity',duration: 200} );

	myFx1.start(1,0).chain(
	    function(){ this.start(0,1); },
	    function(){ this.start(1,0); },
	    function(){ this.start(0,1); },
	    function(){ this.start(1,0); },
	    function(){ this.start(0,1); }
	);
	myFx2.start(1,0).chain(
	    function(){ this.start(0,1); },
	    function(){ this.start(1,0); },
	    function(){ this.start(0,1); },
	    function(){ this.start(1,0); },
	    function(){ this.start(0,1); }
	);
	myFx3.start(1,0).chain(
	    function(){ this.start(0,1); },
	    function(){ this.start(1,0); },
	    function(){ this.start(0,1); },
	    function(){ this.start(1,0); },
	    function(){ this.start(0,1); }
	);
}

