var xmlHttp;
function subscribe(str) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	var quantity = document.getElementById("quantity");
	if (quantity == null) {
		quantity = 1;
	} else {
		quantity = document.getElementById("quantity").value;
	}
	if ((quantity * 2) - quantity > 0) {
	var url="/subscribe/ajaxsubscribe.php";
	url=url+"?act="+str;
	url=url+"&q="+quantity;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	} else {
		alert("Please choose a quantity");
	}
}
function stateChanged() 
{
	if (xmlHttp.readyState==4) {
		document.getElementById("actionbox").innerHTML=xmlHttp.responseText;
		loadorderlist();
	}
}
function loadorderlist(str) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="/subscribe/ajaxorderlist.php";
	url=url+"?sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged2;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function stateChanged2() 
{
	if (xmlHttp.readyState==4) {
		document.getElementById("orderlist").innerHTML=xmlHttp.responseText;
		var height = $('#main').height();
		height += document.getElementById('orderlist').clientHeight;
		$('#main').height(height-150);


		return true;
	}
}
function saveqompas() {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	if (document.getElementById('qompas').checked == true) {
	var url="/subscribe/ajaxqompas.php";
	url=url+"?sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged5;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}
}
function stateChanged5() 
{
	if (xmlHttp.readyState==4) {
		return true;
	}
}
function deletefromorder(str) {
	var answer = confirm('Are you sure you want to remove this from your order?');
	if (answer) {
		
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="/subscribe/ajaxdelete.php";
	url=url+"?key="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged3;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}
}
function stateChanged3() 
{
	if (xmlHttp.readyState==4) {
		history.go(0);
	}
}
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;
}
