

var xmlHttp

// Create Shopping cart sessions
var nwebpath='';
var nprodname = '';
function createSession(webpath,id,name,category,quantity,europrice,sterlingprice,variant_for_unique,prodname)

{ 
	nwebpath=webpath;
	nprodname = prodname;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
	if(quantity=='')
		quantity=1;


	var variant_for_unique_str = "";

	if (variant_for_unique != -1){

		variant_for_unique_str = "-"+variant_for_unique;

	}

	

	var_val = document.getElementById('variant'+id+variant_for_unique_str);

	if(var_val == '[object]'){

		variant_id = document.getElementById('variant'+id+variant_for_unique_str).value;

	}

	else

		variant_id = 0;

		

//	alert(quantity);

//	alert('id'+id+'var'+variant_id+'old'+quantity+'unq:'+variant_for_unique);

	

	var url = webpath+"/js/setsession.php";
	
	if(prodname != undefined){
	url=url+"?id="+id+"&name="+name+"&category="+category+"&quantity="+quantity+"&europrice="+europrice+"&sterlingprice="+sterlingprice+"&variant="+variant_id+"&variant_old="+variant_for_unique+"&productname="+ prodname;
	}else{
		url=url+"?id="+id+"&name="+name+"&category="+category+"&quantity="+quantity+"&europrice="+europrice+"&sterlingprice="+sterlingprice+"&variant="+variant_id+"&variant_old="+variant_for_unique;
		}

	url=url+"&sid="+Math.random();

	xmlHttp.onreadystatechange=stateChangedAddtobasket; 

	xmlHttp.open("POST",url,true);

	xmlHttp.send(null);
	

			

}


function stateChangedAddtobasket() 

{ 

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 {
		
		if (xmlHttp.status == 200) {
			if(nprodname != undefined  ){
				window.location.reload();
				
			}else {
				window.location= nwebpath+'/orders/shopping-cart';
			}
			
		}
		else{
			//alert("There was a problem while using XMLHTTP:\n" + req1.statusText);
			return false;
		}
	 }
 } 



// Erase Shopping cart sessions

function eraseSession(webpath,id)

{ 

	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null)

	{

	alert ("Browser does not support HTTP Request");

	return;

	} 

	var url = webpath+"/js/erasesession.php";

	url=url+"?id="+id;

	url=url+"&sid="+Math.random();

	xmlHttp.onreadystatechange=stateChanged1; 

	xmlHttp.open("GET",url,true);

	xmlHttp.send(null);

	

}



function stateChanged1() 

{ 



	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

	{ 

		

	} 

} 



//XMLHTTPOBJECT

function GetXmlHttpObject()

{ 

	var objXMLHttp=null;

	if (window.XMLHttpRequest)

	{

	objXMLHttp=new XMLHttpRequest();

	}

	else if (window.ActiveXObject)

	{

	objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");

	}

	return objXMLHttp;

}
