$(document).ready(function() {
	var container = jQuery(this);
	var panelCount = container.find("div.exhibitorInfoBox").size();	
	var orderPanel1Count = container.find("div.orderExpanderBox1").size();	
	var orderPanel2Count = container.find("div.orderExpanderBox2").size();	
	$("div.exhibitorInfoBox").hide();
				   
	$("a.exhibitorLink").click(function() {
	if(location.hash)
		{
		//GET THE BOX NUMBER FO THE NEWLY CLICKED LINK
		var boxNum = $(this).attr("href").slice(1);
		for(var i=1;i<(panelCount+1);i++)
			{
			//HIDE PREVIOUSLY DISPLAYED BOXES
			
			if(boxNum != i) { $("#infoBlock"+i).slideUp("normal"); }
			}
		$("#infoBlock"+boxNum).slideToggle("normal");
		}
	});
	
	$("a.orderViewExpander1").click(function() {
	if(location.hash)
		{
		//GET THE BOX NUMBER FO THE NEWLY CLICKED LINK
		var boxNum = $(this).attr("href").slice(1);
		boxNum = boxNum.replace('expand1_','');
		for(var i=1;i<(orderPanel1Count+1);i++)
			{
			//HIDE PREVIOUSLY DISPLAYED BOXES					
			if(boxNum != i) { $("#expand1_"+i).slideUp("normal"); }
			}
		$("#expand1_"+boxNum).slideToggle("normal");
		}
	});
	
	$("a.orderViewExpander2").click(function() {
	if(location.hash)
		{
		//GET THE BOX NUMBER FO THE NEWLY CLICKED LINK
		var boxNum = $(this).attr("href").slice(1);
		boxNum = boxNum.replace('expand2_','');
		for(var i=1;i<(orderPanel2Count+1);i++)
			{
			//HIDE PREVIOUSLY DISPLAYED BOXES		
			if(boxNum != i) { $("#expand2_"+i).slideUp("normal"); }
			}
		$("#expand2_"+boxNum).slideToggle("normal");
		}
	});
	
	$("a.searchBoxLink").click(function() {
		$("#searchBox").show();
	
	});	
});


function chkExhibitorInterestForm() {
	var errors = "";
	if(document.getElementById('name').value == "") { errors += "Please enter a contact name\n"; }
	if(document.getElementById('email').value == "") { errors += "Please enter a contact e-mail address\n"; }	
	if(errors) {
		alert("There were errors with your form submission:\n\n"+errors);
		} 
	else {
		document.exhibitorInterestForm.submit();
		}
	}

/*AJAX FUNCTIONS*/
var xmlHttp;
var contentDiv = "";

function addVisitor() {
	var errors = "";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
 		alert ("Browser does not support HTTP Request")
 		return;
 		}
	var name = document.getElementById('visitor_name').value;
	if(name == "") { errors += "Please enter the visitor name\n";  }
	var email = document.getElementById('visitor_email').value;	
	if(email == "") { errors += "Please enter the visitor e-mail\n";  }	
	var position = document.getElementById('visitor_position').value;	
	var mobile = document.getElementById('visitor_mobile').value;		
	if(mobile == "" || mobile.substr(0,2) != '07') { errors += "Please enter the visitor mobile number\n";  }	
	if(errors == "") {
		var url="ajaxInformationHelper.php?type=addVisitorName&name="+name+"&email="+email+"&mobile="+mobile+"&position="+position+"&random="+Math.random();
		xmlHttp.onreadystatechange=addVisitorStateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		} 
	else {
		alert("There are some error with your visitor registration:\n\n"+errors);
		}
	}

function addVisitorStateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if(xmlHttp.responseText) {
			var responseText = xmlHttp.responseText;
			//alert(responseText);
			responseArray = responseText.split("::");
			
			var process = true;
			var visitorName = responseArray[0];
			var visitorEmail = responseArray[1];
			var visitorId = responseArray[3];			
			var currVisitorList = document.getElementById('visitor_list');
			var currVisitorListLength = parseInt(currVisitorList.length);
			for(var i=0;i<currVisitorListLength;i++) {
				if(visitorName == currVisitorList[i].value) {
					process = false;
				}
			}
			if(process == true) {
				var anOption = document.createElement("OPTION") 
				currVisitorList.options.add(anOption) 
				anOption.text = visitorName;//+ " <"+visitorEmail+">";
				anOption.value = visitorId;//+"::"+visitorEmail; 
				document.getElementById('visitor_name').value;
				document.getElementById('visitor_email').value;	
			}
	 	} 
	}
}

function deleteVisitor() {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
 		alert ("Browser does not support HTTP Request")
 		return;
 		}
	var currVisitorList = document.getElementById('visitor_list');
	var thisElement = currVisitorList.selectedIndex;
	var thisValue = currVisitorList.value;
	var url="ajaxInformationHelper.php?type=removeVisitorName&visitorId="+thisValue+"&random="+Math.random();
	xmlHttp.onreadystatechange=deleteVisitorStateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}
	
	
function deleteVisitorStateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if(xmlHttp.responseText) {
			var responseText = xmlHttp.responseText;
			var responseArray = responseText.split("::");
			var currVisitorList = document.getElementById('visitor_list');
			var thisElement = currVisitorList.selectedIndex;
			if(responseArray[1] == "remove") {
				currVisitorList.removeChild(currVisitorList.childNodes[(thisElement+1)]);
			}
	 	} 
	}
}

function getMemberVisitors() {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
 		alert ("Browser does not support HTTP Request")
 		return;
 		}
	var membershipnum = document.getElementById('membershipId').value;
	var url="ajaxInformationHelper.php?type=buildMemberVisitorPage&membershipnum="+membershipnum+"&random="+Math.random();
	xmlHttp.onreadystatechange=getMemberVisitorsStateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}

function getMemberVisitorsStateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if(xmlHttp.responseText) {
			var responseText = xmlHttp.responseText;
			document.getElementById('memberVisitorBreakdownBox').innerHTML = responseText;
			document.getElementById('AssocVisitorBreakdownBox').innerHTML = '';
			document.getElementById('PressVisitorBreakdownBox').innerHTML = '';
	 	} 
	}
}

function getAssocVisitors() {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
 		alert ("Browser does not support HTTP Request")
 		return;
 		}
	var assocVisitorId = document.getElementById('assocVisitorId').value;
	var url="ajaxInformationHelper.php?type=buildAssocVisitorPage&assocVisitorId="+assocVisitorId+"&random="+Math.random();
	xmlHttp.onreadystatechange=getAssocVisitorsStateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}

function getAssocVisitorsStateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if(xmlHttp.responseText) {
			var responseText = xmlHttp.responseText;
			document.getElementById('AssocVisitorBreakdownBox').innerHTML = responseText;
			document.getElementById('PressVisitorBreakdownBox').innerHTML = '';
			document.getElementById('memberVisitorBreakdownBox').innerHTML = '';
		} 
	}
}

function getPressVisitors() {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
 		alert ("Browser does not support HTTP Request")
 		return;
 		}
	var assocVisitorId = document.getElementById('pressVisitorId').value;
	var url="ajaxInformationHelper.php?type=buildAssocVisitorPage&assocVisitorId="+assocVisitorId+"&random="+Math.random();
	xmlHttp.onreadystatechange=getPressVisitorsStateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}

function getPressVisitorsStateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if(xmlHttp.responseText) {
			var responseText = xmlHttp.responseText;
			document.getElementById('AssocVisitorBreakdownBox').innerHTML = '';
			document.getElementById('PressVisitorBreakdownBox').innerHTML = responseText;
			document.getElementById('memberVisitorBreakdownBox').innerHTML = '';
	 	} 
	}
}

function getItemDetails(itemId) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
 		alert ("Browser does not support HTTP Request")
 		return;
 		}
	var url="ajaxInformationHelper.php?type=buildItemEditForm&itemId="+itemId+"&random="+Math.random();
	xmlHttp.onreadystatechange=getItemDetailsStateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}

function getItemDetailsStateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if(xmlHttp.responseText) {
			var responseText = xmlHttp.responseText;
			document.getElementById('itemDetailsContainer').innerHTML = responseText;
	 	} 
	}
}

function addItemOption() {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
 		alert ("Browser does not support HTTP Request")
 		return;
 		}
	var optionValue = document.getElementById('newOption').value;
	var itemId = document.getElementById('itemid').value;
	var url="ajaxInformationHelper.php?type=addItemOption&itemId="+itemId+"&optionValue="+optionValue+"&random="+Math.random();
	xmlHttp.onreadystatechange=addItemOptionStateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}

function addItemOptionStateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if(xmlHttp.responseText) {
			var responseText = xmlHttp.responseText;
			document.getElementById('optionsContainer').innerHTML = responseText;
	 	} 
	}
}

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;
	}
	
	
function clearItemForm() {
	document.getElementById('itemid').value = '';
	document.getElementById('formid').value = '';
	document.getElementById('item_code').value = '';
	document.getElementById('item_code_late').value = '';
	document.getElementById('item_price').value = '';
	document.getElementById('item_unit').value = '';	
	document.getElementById('item_description').value = '';
	document.getElementById('optionsOuterContainer').innerHTML = "";
}
	
function calculatePrice(itemId) {
	if(document.getElementById('qty'+itemId).value > 0) {
		var newTotal = (document.getElementById('unitprice'+itemId).value*document.getElementById('qty'+itemId).value);
		document.getElementById('totalbox'+itemId).innerHTML = "&pound;"+newTotal.toFixed(2);
		}
	else
		{
		var newTotal = 0;
		document.getElementById('totalbox'+itemId).innerHTML = "&pound;"+newTotal.toFixed(2);
		}	
	}

function changeDinnerTicketNameBoxes(stdPrice,grpPrice) {
	//BUILD IN FUNCTIONALITY TO RETAIN NAMES ALREADY ENTERED INTO FORM WHEN CHANGING NUMBER OF DINERS
	var newInnerHtml = "";
	if(document.getElementById('ticketQty').value != "" && document.getElementById('ticketQty').value > 0) {
		
		if(document.getElementById('ticketQty').value < 12) {
			document.getElementById('ticketPrice').innerHTML = ' @ &pound;'+stdPrice+'.00';
			document.getElementById('ticketPriceField').value = stdPrice;
		} else {
			document.getElementById('ticketPrice').innerHTML = ' @ &pound;'+grpPrice+'.00';
			document.getElementById('ticketPriceField').value = grpPrice;
		}
		var dinnerTicketQty = parseInt(document.getElementById('ticketQty').value)+1;
		for(var i=1;i<dinnerTicketQty;i++) {
			newInnerHtml+= '<div style="width:15px;float:left;">'+i+'.</div><div style="display:inline;width:270px;"><input type="text" name="dinnerName_'+i+'" style="width:260px;" /></div><div style="display:inline;width:100px;"><input type="text" name="dinnerDietry_'+i+'" style="width:260px;display:inline" /></div><div style="clear:both;line-height:1px;">&nbsp;</div>';
		}
		document.getElementById('dinnerNameContainer').innerHTML = newInnerHtml;
	} else {
		document.getElementById('ticketPrice').innerHTML = ' @ &pound;'+stdPrice+'.00';
		document.getElementById('ticketPriceField').value = stdPrice;
		document.getElementById('dinnerNameContainer').innerHTML = 'Please select the quantity of tickets you require.';
	}
}

function showHideFormDivs(showDiv,firstDiv,lastDiv) {
	lastDiv = lastDiv+=1;
	for(var i=firstDiv;i<lastDiv;i++) {
		if(document.getElementById('formDetails_'+i)) {
			document.getElementById('formDetails_'+i).style.display = 'none';
		}
	}
	document.getElementById(showDiv).style.display = 'block';
}

function chkDinnerOrder() {
	var errors = "";
	if(document.getElementById('ticketQty').value > 0) {
		if(document.getElementById('name').value == "" || document.getElementById('name').value == null) { errors+="Please enter your name\n"; }
		if(document.getElementById('address1').value == "" || document.getElementById('address1').value == null) { errors+="Please enter your address\n"; }	
		//if(document.getElementById('town').value == "" || document.getElementById('town').value == null) { errors+="Please enter your town\n"; }
		if(document.getElementById('postcode').value == "" || document.getElementById('postcode').value == null) { errors+="Please enter your postcode\n"; }
		if(document.getElementById('country').value == "" || document.getElementById('country').value == null) { errors+="Please enter your country\n"; }	
		if(document.getElementById('email').value == "" || document.getElementById('email').value == null) { errors+="Please enter your e-mail address\n"; }
		
		for(var i=1;i<document.getElementById('ticketQty').value;i++) {
			if(document.getElementById('dinnerName_'+i).value == '') { errors+="Please enter the name for diner #"+i+"\n"; }
		}
		if(errors != "") { alert("There were some errors with your form submission:\n\n"+errors); return false; }
		else { //document.forms['dinnerForm'].submit(); } 
		//document.getElementById('dinnerForm').submit(); }
		}
	} else {
		return false;
	}
}

function updateCart() {
	var form = document.paymentpage;
	for(var i=0;i<form.length;i++) {
		var thisField = form.getElementsByTagName('input')[i].name;
		nameArray = thisField.split("_");
		if(nameArray[0] == 'item') {
			updateCartQty(nameArray[1],document.getElementById(thisField).value);
		}
	}
}

function updateCartQty(cartId,qty) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
 		alert ("Browser does not support HTTP Request")
 		return;
 		}
	var url="ajaxInformationHelper.php?type=updateCartQty&cartId="+cartId+"&qty="+qty+"&random="+Math.random();
	xmlHttp.onreadystatechange=updateCartQtyStateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}

function updateCartQtyStateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if(xmlHttp.responseText) {
			var responseText = xmlHttp.responseText;
			responseArray = responseText.split("::");
			$("#confirmationBox").fadeIn("fast");
			setTimeout("$(\"#confirmationBox\").fadeOut(\"slow\")",1500);
			setTimeout("location.replace('placeorder.php?acctId="+document.getElementById('acctid').value+"')",1500);
	 	} 
	}
}

function chkOrderForm() {
	var form = document.itemorders;
	var errors = "";
	for(var i=0;i<(form.length-1);i++) {
		if(form.getElementsByTagName('input')[i]) {
			var thisField = form.getElementsByTagName('input')[i].name;
			
			thisFieldId = thisField.substr(3);
			
			if(thisField.substr(0,3) == 'qty') {
				if(document.getElementById('option'+thisFieldId)) {
					if(document.getElementById('option'+thisFieldId).value == "" && (document.getElementById('qty'+thisFieldId).value != "" || document.getElementById('qty'+thisFieldId).value > 0)) {
					codeStr = document.getElementById('code'+thisFieldId).innerHTML.replace("<STRONG>","");
					codeStr = codeStr.replace("</STRONG>","");			
					errors+= "Please select an option for "+codeStr+"\n";
					}
				}
			}
		}
		
	}
	if(errors) {
		alert("There are some errors with your form submission:\n\n"+errors);
	} else {
		form.submit();
	}
}

function markRefundPaid(orderref,acctId) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
 		alert ("Browser does not support HTTP Request")
 		return;
 		}
	var url="ajaxInformationHelper.php?type=markRefundPaid&orderref="+orderref+"&acctId="+acctId+"&random="+Math.random();
	xmlHttp.onreadystatechange=markRefundPaidStateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function markRefundPaidStateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if(xmlHttp.responseText) {
			var responseText = xmlHttp.responseText;
			var responseArray = responseText.split("::");
			$("#refundRow"+responseArray[1]).fadeOut("slow");
	 	} 
	}
}
function updateExhibInterestStatus() {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
 		alert ("Browser does not support HTTP Request")
 		return;
 		}
	var memberId = document.getElementById('memberId').value;
	var updatedStatus = document.getElementById('enquiryStatus').value;
	var url="ajaxInformationHelper.php?type=updateNewExhibitorInterestStatus&memberId="+memberId+"&status="+updatedStatus+"&random="+Math.random();
	xmlHttp.onreadystatechange=updateExhibInterestStatusStateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function updateExhibInterestStatusStateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if(xmlHttp.responseText) {
			var responseText = xmlHttp.responseText;
			$("#updateBox").fadeIn("fast");
			setTimeout("$(\"#updateBox\").fadeOut(\"slow\")",1500);
		} 
	}
}

function addNewExhibitorInterestNote() {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
 		alert ("Browser does not support HTTP Request")
 		return;
 		}
	var memberId = document.getElementById('memberId').value;
	var noteTaker = document.getElementById('noteTaker').value;
	var noteDetail = escape(document.getElementById('noteDetail').value);
	var url="ajaxInformationHelper.php?type=addNewExhibitorInterestNote&memberId="+memberId+"&noteTaker="+noteTaker+"&noteDetail="+noteDetail+"&random="+Math.random();
	xmlHttp.onreadystatechange=addNewExhibitorInterestNoteStateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function addNewExhibitorInterestNoteStateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if(xmlHttp.responseText) {
			var responseText = xmlHttp.responseText;
			var newInnerHTML = document.getElementById('notePane').innerHTML;
			
			newInnerHTML+= "<div class=\"tableRow"+responseText+"\" style=\"padding-bottom:5px;\">";
			newInnerHTML+= "<div style=\"float:left;width:100px;\"><strong>Note taker:</strong></div>";
			newInnerHTML+= "<div style=\"float:left;width:500px;\">"+document.getElementById('noteTaker').value+"</div>";
			newInnerHTML+= "<div style=\"clear:both;line-height:1px;border-top:1px solid #7399aa;\">&nbsp;</div>";
			newInnerHTML+= "<div><strong>Note Details:</strong><br />"+document.getElementById('noteDetail').value+"</div>";
			newInnerHTML+= "</div>";
	 		document.getElementById('notePane').innerHTML = newInnerHTML;
		} 
	}
}

function removePressReleaseImage(nid) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
 		alert ("Browser does not support HTTP Request")
 		return;
 		}
	var url="ajaxInformationHelper.php?type=removePressReleaseImage&nid="+nid+"&random="+Math.random();
	xmlHttp.onreadystatechange=removePressReleaseImageStateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function removePressReleaseImageStateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if(xmlHttp.responseText) {
			var responseText = xmlHttp.responseText;
			document.getElementById('prevImageName').value = '';
			document.getElementById('existingImageBox').innerHTML = "<strong>Existing image:</strong> N/A";
		} 
	}
}

function chkItemCode(codeType) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
 		alert ("Browser does not support HTTP Request")
 		return;
 		}
	var code = "";
	if(codeType == "code") {
		var code = document.getElementById('item_code').value;
	} else {
		var code = document.getElementById('item_code_late').value;	
	}
	var url="ajaxInformationHelper.php?type=chkItemCode&itemCode="+code+"&codeType="+codeType+"&random="+Math.random();
	if(code != "") {
		xmlHttp.onreadystatechange=chkItemCodeStateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function chkItemCodeStateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if(xmlHttp.responseText) {
			var responseText = xmlHttp.responseText;
			alert("The code or late code you have enetered is already in use. Please correct it before continuing.");
		} 
	}
}


function chkExhibitorAdd() {
	var errors = "";
	if(document.getElementById('memberId').value == "") { errors+= "Please select a member to make an exhibitor\n"; }
	if(document.getElementById('standnum_1').value == "") { errors+= "Please enter a stand number\n"; }
	if(document.getElementById('width_1').value == "") { errors+= "Please enter a stand width\n"; }
	if(document.getElementById('depth_1').value == "") { errors+= "Please enter a stand depth\n"; }
	if(document.getElementById('sqm_1').value == "") { errors+= "Please enter the cost per sqm\n"; }
	if(errors) { alert("There were some errors with your form submission:\n\n"+errors);return false; } else { document.newExhibitorForm.submit(); }
	
}

function chknewprodform() {
	var errors = "";
	if(document.getElementById('prodName').value == "") { errors+= "Please enter the product name\n"; }
	if(document.getElementById('prodDesc').value == "") { errors+= "Please enter the product description\n"; }
	if(document.getElementById('userLogo').value == "") { errors+= "Please select the product image\n"; }
	if(errors) { alert("There were some errors with your form submission:\n\n"+errors);return false; } else { document.newprodForm.submit(); }
}

function chknewprodform2() {
	var errors = "";
	if(document.getElementById('prodName2').value == "") { errors+= "Please enter the product name\n"; }
	if(document.getElementById('prodDesc2').value == "") { errors+= "Please enter the product description\n"; }
	if(document.getElementById('userLogo2').value == "" && document.getElementById('prevImageBox').innerHTML == "") { errors+= "Please select the product image\n"; }
	if(errors) { alert("There were some errors with your form submission:\n\n"+errors);return false; } else { document.newprodForm2.submit(); }
}

function deleteProduct(productId) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
 		alert ("Browser does not support HTTP Request")
 		return;
 		}
	var url="../ajaxInformationHelper.php?type=deleteNewProduct&productId="+productId+"&random="+Math.random();
	xmlHttp.onreadystatechange=deleteProductStateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function deleteProductStateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if(xmlHttp.responseText) {
			var responseText = xmlHttp.responseText;
			var responseArray = responseText.split("::");
			document.getElementById('productCount').innerHTML = responseArray[1];
			document.getElementById('prodBox'+responseArray[0]).style.display = 'none';
		} 
	}
}

function addStoryToList(element) {
	var startList = document.getElementById('startList[]');
	var finalList = document.getElementById('finalList[]');	
	if(element.checked == true) { //ADD STORY
		var anOption = document.createElement("OPTION") 
		startList.options.add(anOption);
		anOption.text = document.getElementById('text_'+element.value).label;
		anOption.value = element.value;
	} else { //REMOVE STORY
		for(var i=0;i<startList.length;i++) {
			if(startList[i].value == element.value) {
				startList.options[i] = null;
				break;
			}
		}
		
		/*for(var i=0;i<finalList.length;i++) {
			if(finalList[i].value == element.value) {
				finalList.options[i] = null;
				break;
			}
		}*/
	}
}

function showguideGetExhibDetails() {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
 		alert ("Browser does not support HTTP Request")
 		return;
 		}
	document.getElementById('exhibInfoBox').style.display = 'none';
	document.getElementById('ajaxloader').style.display = 'block';
	var exhibId = document.getElementById('exhibitorId').value;
	var url="ajaxInformationHelper.php?type=showShowguideEntry&exhibId="+exhibId+"&random="+Math.random();
	xmlHttp.onreadystatechange=showguideGetExhibDetailsStateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function showguideGetExhibDetailsStateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if(xmlHttp.responseText) {
			var responseText = xmlHttp.responseText;
			document.getElementById('exhibInfoBox').innerHTML = responseText;
			document.getElementById('ajaxloader').style.display = 'none';
			document.getElementById('exhibInfoBox').style.display = 'block';
			
		} 
	}
}

function loadProducts(letter) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
 		alert ("Browser does not support HTTP Request")
 		return;
 		}
	document.getElementById('exhibInfoBox').style.display = 'none';
	document.getElementById('ajaxloader').style.display = 'block';
	var url="ajaxInformationHelper.php?type=getShowGuideProducts&letter="+letter+"&random="+Math.random();
	xmlHttp.onreadystatechange=loadProductsStateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function loadProductsStateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if(xmlHttp.responseText) {
			var responseText = xmlHttp.responseText;
			document.getElementById('exhibInfoBox').innerHTML = responseText;
			document.getElementById('ajaxloader').style.display = 'none';
			document.getElementById('exhibInfoBox').style.display = 'block';
			
		} 
	}
}

function getNewProducts(prodId,acctId,orderformId) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
 		alert ("Browser does not support HTTP Request")
 		return;
 		}
	document.getElementById('newprodBox').style.display = 'none';
	document.getElementById('editProdBox').innerHTML = '<img src="../../images/ajax-loader.gif" width="16" height="16" alt="" title="" />';
	document.getElementById('editProdBox').style.display = 'block';
	var url="../ajaxInformationHelper.php?type=getNewProd&prodId="+prodId+"&acctId="+acctId+"&orderformId="+orderformId+"&random="+Math.random();
	xmlHttp.onreadystatechange=getNewProductsStateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function getNewProductsStateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if(xmlHttp.responseText) {
			var responseText = xmlHttp.responseText;
			document.getElementById('editProdBox').innerHTML = responseText;
		} 
	}
}

function getDinnerOrders() {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
 		alert ("Browser does not support HTTP Request")
 		return;
 		}
	document.getElementById('exhibInfoBox').style.display = 'none';
	document.getElementById('ajaxloader').style.display = 'block';
	var memberId = document.getElementById('chequeOrderMemberId').value;
	var url="ajaxInformationHelper.php?type=getShowGuideProducts&memberId="+memberId+"&random="+Math.random();
	xmlHttp.onreadystatechange=getDinnerOrdersStateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function getDinnerOrdersStateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if(xmlHttp.responseText) {
			var responseText = xmlHttp.responseText;
			document.getElementById('exhibInfoBox').innerHTML = responseText;
			document.getElementById('ajaxloader').style.display = 'none';
			document.getElementById('exhibInfoBox').style.display = 'block';
			
		} 
	}
}


function reorderStoryList(direction) {
	var startList = document.getElementById('startList[]');
	var selectedID = startList.selectedIndex;
	if(selectedID >= 0) {
		if(direction == "up" && (startList.selectedIndex > 0)) {
			var replaceValue = startList[(selectedID-1)].value;
			var replaceText = startList[(selectedID-1)].text;
			var selectedValue = startList[selectedID].value;
			var selectedText = startList[selectedID].text;
			
			startList[(selectedID-1)].value = selectedValue;
			startList[(selectedID-1)].text = selectedText;
			startList[selectedID].value = replaceValue;
			startList[selectedID].text = replaceText;
			startList.selectedIndex = (selectedID-1);
			
		} else if(direction == "down" && (startList.selectedIndex < (startList.length-1))) {
			var replaceValue = startList[(selectedID+1)].value;
			var replaceText = startList[(selectedID+1)].text;
			var selectedValue = startList[selectedID].value;
			var selectedText = startList[selectedID].text;
			
			startList[(selectedID+1)].value = selectedValue;
			startList[(selectedID+1)].text = selectedText;
			startList[selectedID].value = replaceValue;
			startList[selectedID].text = replaceText;
			startList.selectedIndex = (selectedID+1);
		}
	}
}

function submitStoryEmailForm() {
	for(var i=0;i<document.getElementById('startList[]').length;i++) {
		document.getElementById('startList[]')[i].selected = true;
	}
	document.prForm.submit();
}

function chkDistributorNomination() {
	var errors = false;
	var regionArray = new Array("Central","Scotland and Ireland","North","South East","South West and Wales","London and Eastern Region");
	for(var i=0;i<regionArray.length;i++) {
		if(document.getElementById('region_'+regionArray[i]).value == "") { errors = true; }
	}
	if(document.getElementById('distributorNominationname').value == "") { errors = true; }
	if(document.getElementById('distributorNominationemail').value == "") { errors = true; }	
	if(errors == true) {
		alert("Please ensure all regions have a distributor nominated and you've entered your personal details before continuing");
		return false;
	}
}

function chkSupplierNomination() {
	var errors = false;
	if(document.getElementById('supplierId').value == "") { errors = true; }
	if(document.getElementById('supplierNominationname').value == "") { errors = true; }
	if(document.getElementById('supplierNominationemail').value == "") { errors = true; }	
	if(errors == true) {
		alert("Please ensure you have nominated a supplier and you've entered your personal details before continuing");
		return false;
	}
}

function chkSupplierVote() {
	var errors = false;
	for(var rankNum=1;rankNum<4;rankNum++) {
		for(var i=0;i<document.forms['supplierVoteForm']['rank'+rankNum].length;i++) { 
			if(document.forms['supplierVoteForm']['rank'+rankNum][i].checked == true)  {
				errors = false;
				break;
			} else {
				errors = true;
			}
		}
	}
	if(errors == true) { alert("Please complete your vote before continuing");return false; } 
}

function chkShowguideEntry() {
	var wordCount = 0;
	var entrySplit = document.getElementById('editorial').value.split(" ");
	var wordCount = (entrySplit.length-1);
	if(wordCount != 1) { var plural = "s"; }
	if(wordCount > 50) {
		document.getElementById('wordCount').innerHTML = "(<span style=\"color:red;\">"+wordCount+" word"+plural+"</span>)";	
		alert("Your entry must be a maximum of 50 words. Please correct your entry to continue");
		return false;
	} else {
		document.getElementById('wordCount').innerHTML = "("+wordCount+" word"+plural+")";	
	}
}

function chkGameForm() {
	var errors = "";
	var errmsg = "";
	if(document.getElementById('company_name').value == "") { errors = true;errmsg = errmsg+"Company name\n"; }
	if(document.getElementById('contact_name').value == "") { errors = true;errmsg = errmsg+"Contact name\n"; }
	if(document.getElementById('position').value == "") { errors = true;errmsg = errmsg+"Position\n"; }
	if(document.getElementById('tel').value == "") { errors = true;errmsg = errmsg+"Telephone\n"; }
	if(document.getElementById('email').value == "") { errors = true;errmsg = errmsg+"E-mail\n"; }
	if(document.getElementById('disclaimer').checked != true) { errors = true;errmsg = errmsg+"Disclaimer\n"; }
	
	if(errors) {
		alert("Please complete the following fields to continue:\n\n"+errmsg);
		return false;
	} else {
		document.getElementById('competitionForm').submit();
	}
	
}