function codeCheck(){
	// get code from input box
//	var promo_code = trim(document.getElementById("promo_code").value).toUpperCase();

	var promo_code = document.getElementById("promo_code").value.toUpperCase().replace(/^\s+|\s+$/g, '');

	if (promo_code != ''){
		// display 'Checking...' text and hide button
		document.getElementById("check_button").style.display = 'none';
		document.getElementById("checking_text").style.display = 'inline';
		
		// ajax request
		var url = "scripts/codecheck_peb.aspx";
		request.open("POST", url, true);
		request.onreadystatechange = function(){updateFee(promo_code);};
		request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		
		var sendString = "code=" + promo_code;
		request.send(sendString);
	}
}

var xmldoc;
var element;

function updateFee(promo_code){
	if (request.readyState == 4){
		if (request.status == 200) {
			xmldoc = request.responseXML;
			element = xmldoc.documentElement;
			fee = element.firstChild;		
		
			var figure = fee.firstChild.nodeValue;
		
			// hide any remaining info messages
			document.getElementById("fee_paragraph").style.display = 'none';
			document.getElementById("error_paragraph").style.display = 'none';
			
			if (figure >= 0){
				// display registration fee info
				var fee_holder = document.getElementById("fee_holder");
				while(fee_holder.hasChildNodes()){
					fee_holder.removeChild(fee_holder.lastChild);
				}
				if (figure == 0){
					var fee_text = document.createTextNode("FREE");					
				}else{
					var fee_text = document.createTextNode("\u00A3" + figure);					
				}			
				fee_holder.appendChild(fee_text);
				document.getElementById("fee_paragraph").style.display = 'block';
				
				// now fill hidden 'amount' field
				document.getElementById("amount").value = figure;
				
				// now fill hidden 'registration_code' field
				document.getElementById("registration_code").value = promo_code;
				
				// show form
				document.getElementById("form_holder").style.display = 'block';
			}else{				
				document.getElementById("error_paragraph").style.display = 'block';
				// hide form
				document.getElementById("form_holder").style.display = 'none';
			}
			
			// hide 'Checking...' text and show button
			document.getElementById("check_button").style.display = 'inline';
			document.getElementById("checking_text").style.display = 'none';			
		}
	}
}

function showHideSubmit(action){
	var submit_row = document.getElementById("submit_row");
	if (action == "hide") {  // hide
		submit_row.style.display = 'none';
	}else{  // show
		submit_row.style.display = '';
	}
}