﻿var xmlHttp
function checkNumber(MemberId) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
  		alert ("Your browser does not support AJAX - MemberId not verifiable! " + MemberId);
 		 return;
  	} 
	var url="getmemberid.php";
	url=url+"?q="+MemberId;	
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateModified;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function stateModified() { 
	if (xmlHttp.readyState==4){ 
		if(xmlHttp.responseText == "") {
			alert ("Membership not verified - discount at general public rates will apply! " );
			return false;
		} else {
			return true;
		}
	}
}

function getgroup(MerchantId,GroupId,MemberNo,Currency) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
  		alert ("Your browser does not support AJAX - GroupId not accessible! " + GroupId);
 		 return;
  	} 
	var url="getgroup.php";
	url=url+"?m="+MerchantId+"&g="+GroupId;	
	url=url+"&n="+MemberNo+"&c="+Currency;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function stateChanged() { 
	if (xmlHttp.readyState==4){ 
		if(xmlHttp.responseText == "") {
			document.getElementById("targetMenu").innerHTML="<P CLASS=\"clsNormal visualIEFloatFix\"><strong>No Menu Available</strong></p>";
		} else {
			document.getElementById("targetMenu").innerHTML=xmlHttp.responseText;
		}
	}
}

function getproduct(MerchantId,GroupId,ProductId,MemberNo,Currency) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
  		alert ("Your browser does not support AJAX - ProductId not accessible! " + ProductId);
 		 return;
  	} 
	var url="getproduct.php";
	url=url+"?m="+MerchantId+"&g="+GroupId+"&p="+ProductId;
	url=url+"&n="+MemberNo+"&c="+Currency;	
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateAltered;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function stateAltered() { 
	if (xmlHttp.readyState==4){ 
		if(xmlHttp.responseText == "") {
			document.getElementById("targetProduct").innerHTML="<P CLASS=\"clsNormal visualIEFloatFix\"><strong>No Product Details Available</strong></p>";
		} else {
			var outstring = xmlHttp.responseText.replace(/Pound/g,"£");
			outstring = outstring.replace(/%A3/g,"£");
			document.getElementById("targetProduct").innerHTML=outstring;
		}
	}
}

function deleteproduct(MerchantId,MemberNo,TempNo,Sequence,Currency,Banner) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
  		alert ("Your browser does not support AJAX - ProductId not accessible! " + ProductId);
 		 return;
  	} 
	var url="deleteproduct.php";
	url=url+"?m="+MerchantId+"&n="+MemberNo+"&t="+TempNo;
	url=url+"&s="+Sequence+"&c="+Currency+"&b="+Banner;	
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateDifferent;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function stateDifferent() { 
	if (xmlHttp.readyState==4){ 
		if(xmlHttp.responseText == "") {
			document.getElementById("adverts").innerHTML="<P CLASS=\"clsNormal visualIEFloatFix\"><strong>No Product Details Available</strong></p>";
		} else {
			var outstring = xmlHttp.responseText.replace(/Pound/g,"£");
			outstring = outstring.replace(/%A3/g,"£");
			document.getElementById("adverts").innerHTML=outstring;
		}
	}
}

function checkout(MerchantId,MemberNo,TempNo,Currency) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
  		alert ("Your browser does not support AJAX - ProductId not accessible! " + ProductId);
 		 return;
  	} 
	var url="checkout.php";
	url=url+"?m="+MerchantId+"&n="+MemberNo+"&t="+TempNo;
	url=url+"&c="+Currency;
	if(MemberNo == TempNo) {
		var clientname = document.getElementById("ClientName").value;
		var clientaddress = document.getElementById("ClientAddress").value;
		var clientphone = document.getElementById("ClientPhone").value;
		var clientemail = document.getElementById("ClientEmail").value;
		url=url+"&cn="+clientname+"&ca="+clientaddress+"&cp="+clientphone+"&ce="+clientemail;
	}	
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateComplete;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function stateComplete() { 
	if (xmlHttp.readyState==4){ 
		if(xmlHttp.responseText == "") {
			document.getElementById("targetProduct").innerHTML="<P CLASS=\"clsNormal visualIEFloatFix\"><strong>No Order Details Available</strong></p>";
		} else {
			var outstring = xmlHttp.responseText.replace(/Pound/g,"£");
			outstring = outstring.replace(/%A3/g,"£");
			document.getElementById("targetProduct").innerHTML=outstring;
		}
	}
}

function nonmember(MerchantId,MemberNo,TempNo,Currency) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
  		alert ("Your browser does not support AJAX - ProductId not accessible! " + ProductId);
 		 return;
  	} 
	var url="nonmember.php";
	url=url+"?m="+MerchantId+"&n="+MemberNo+"&t="+TempNo;
	url=url+"&c="+Currency;	
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateCompleted;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function stateCompleted() { 
	if (xmlHttp.readyState==4){ 
		if(xmlHttp.responseText == "") {
			document.getElementById("targetProduct").innerHTML="<P CLASS=\"clsNormal visualIEFloatFix\"><strong>No Order Details Available</strong></p>";
		} else {
			var outstring = xmlHttp.responseText.replace(/Pound/g,"£");
			outstring = outstring.replace(/%A3/g,"£");
			document.getElementById("targetProduct").innerHTML=outstring;
		}
	}
}


function mailorder(MerchantId,MemberNo,TempNo,Currency,ClientName,ClientAddress,ClientPhone,ClientEmail) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
  		alert ("Your browser does not support AJAX - ProductId not accessible! " + ProductId);
 		 return;
  	} 
	var url="mailorder.php";
	url=url+"?m="+MerchantId+"&n="+MemberNo+"&t="+TempNo;
	url=url+"&c="+Currency;	
	url=url+"&cn="+ClientName+"&ca="+ClientAddress+"&cp="+ClientPhone+"&ce="+ClientEmail;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateEnd;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function stateEnd() { 
	if (xmlHttp.readyState==4){ 
		if(xmlHttp.responseText == "") {
			document.getElementById("targetProduct").innerHTML="<P CLASS=\"clsNormal visualIEFloatFix\"><strong>No Order Details Available</strong></p>";
		} else {
			var outstring = xmlHttp.responseText.replace(/Pound/g,"£");
			outstring = outstring.replace(/%A3/g,"£");
			document.getElementById("targetProduct").innerHTML=outstring;
		}
	}
}

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;
} 
