	function ShowImage(sID,iID) {
		/* 
		Shows an animated spinny wheel thingy ala osx
		Version 1.0 | by peter graves
		*/
		pwimage = document.getElementById(iID);
		frmbutton = document.getElementById(sID);
		frmbutton.style.visibility = 'hidden';
		pwimage.style.visibility = "visible"; 
		pwimage.style.display= "inline";
		setTimeout('pwimage.src = "/images/ajax-loader.gif"', 200); 
		}
		
		

// wait for the DOM to be loaded 
//$(document).ready(function() { 
//	// bind 'myForm' and provide a simple callback function 
//   $('#frmRegister').ajaxForm(function() { 
//    alert("Thank you for your comment!"); 
//    }); 
//}); 

// prepare the form when the DOM is ready 
$(document).ready(function() { 
    var options = { 
        target:        '#response_message',   // target element(s) to be updated with server response 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse  // post-submit callback 
 
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  'xml'        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 
 
    // bind form using 'ajaxForm' 
    $('#frmRegister').ajaxForm(options); 
}); 
 
// pre-submit callback 
function showRequest(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 
    //alert('About to submit: \n\n' + queryString); 
 
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    return true; 
} 
 
// post-submit callback 
function showResponse(responseText, statusText)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
 
  //  alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
  //      '\n\nThe output div should have already been updated with the responseText.'); 
} 

/*
Validation of booking form 
*/
function validateFormOnSubmit(theForm) {
	var reason = "";
	var par = theForm.fBookParticipants.value;
	
	reason += validateEmpty(theForm.fFirstName,"Please enter your first name");
    reason += validateEmpty(theForm.fLastName,"Please enter your last name");
    reason += validateEmpty(theForm.fPrefName,"Please enter your prefered name");
    reason += validateEmpty(theForm.fAddress,"Please enter your address");	
    reason += validatePostcode(theForm.fPostCode,"Please enter your postcode");
	reason += validateEmpty(theForm.fDayTel,"Please enter your day time telephone number");
    reason += validateEmail(theForm.fEmailAddress);
	
	if (par!=1) {
		for (i=2;i<=par;i++) {
			//firstname = 'fFirstName_'+i;
			var firstnamefld = theForm.elements['fFirstName_' + i];
			var lastnamefld  = theForm.elements['fLastName_' + i];	
			var prefnamefld  = theForm.elements['fPrefName_' + i];				
			var addressfld   = theForm.elements['fAddress_' + i];
			var postcodefld  = theForm.elements['fPostCode_' + i];
			var daytelfld    = theForm.elements['fDayTel_' + i];
			var emailfld     = theForm.elements['fEmailAddress_' + i];			
			
			reason += validateEmpty(firstnamefld,"Please enter participants " + i + " first name");
			reason += validateEmpty(lastnamefld,"Please enter participants " + i + " last name");
			reason += validateEmpty(prefnamefld,"Please enter participants " + i + " prefered name");
			reason += validateEmpty(addressfld,"Please enter participants " + i + " address");	
			reason += validatePostcode(postcodefld,"Please participants " + i + " postcode");
			reason += validateEmpty(daytelfld,"Please enter participants " + i + " day time telephone number");
			reason += validateEmailParticipant(i,emailfld);
		}
	}
	
	//if (!theForm.fInvoiceDetails.checked) {
	//    reason += validateEmpty(theForm.fDeliveryAddress1,"Please enter your delivery address");
	//    reason += validatePostcode(theForm.fDeliveryPostCode,"Please enter your delivery postcode");		
	//}
      
	//alert(reason);  
	
    if (reason != "") {
      alert(reason);
      return false;
    }
    return true; 
  }

function validateEmpty(fld,str) {
    var error = "";
  
    if (fld.value.length == 0) {
        fld.style.background = '#eb80e0'; 
        error = str+"\n"
    } else {
        fld.style.background = '#FFFFFF';
    }
    return error;   
}

function trim(s){ return s.replace(/^\s+|\s+$/, '');} 

function validateEmailParticipant(i,fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    
    if (fld.value == "") {
        fld.style.background = '#eb80e0';
        error = "You didn't enter a valid email address for participant " + i +"\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#eb80e0';
        error = "Please enter a valid email address for participant " + i +"\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#eb80e0';
        error = "The email address contains illegal characters for participant " + i +"\n";
    } else {
        fld.style.background = '#FFFFFF';
    }
    return error;	
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    
    if (fld.value == "") {
        fld.style.background = '#eb80e0';
        error = "You didn't enter a valid email address\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#eb80e0';
        error = "Please enter a valid email address\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#eb80e0';
        error = "The email address contains illegal characters\n";
    } else {
        fld.style.background = '#FFFFFF';
    }
    return error;
}

function validatePostcode(fld,str) {
    var error = "";
  
    if (!isValidPostcode(fld.value)) {
        fld.style.background = '#eb80e0'; 
        error = str+"\n"
    } else {
        fld.style.background = '#FFFFFF';
		fld.value = formatPostcode(fld.value);
    }
    return error;   
}

/* tests to see if string is in correct UK style postcode: AL1 1AB, BM1 5YZ etc. */
function isValidPostcode(p) {
	//var postcodeRegEx = /[A-Z]{1,2}[0-9]{1,2} ?[0-9][A-Z]{2}/i;
	var postcodeRegEx = /[A-Z]{1,2}[0-9]{1,2}[A-Z]{0,1} ?[0-9][A-Z]{2}/i;
	return postcodeRegEx.test(p);
}
/*	formats a VALID postcode nicely: AB120XY -> AB1 0XY */
function formatPostcode(p) {
	if (isValidPostcode(p)) {
		var postcodeRegEx = /(^[A-Z]{1,2}[0-9]{1,2})([0-9][A-Z]{2}$)/i;
		//var postcodeRegEx = /[A-Z]{1,2}[0-9]{1,2}[A-Z]{0,1} ?[0-9][A-Z]{2}/i;
		return p.replace(postcodeRegEx,"$1 $2").toUpperCase();
	} else {
		return p;
	}
}

/*
jQuery Drop Down Menu
From http://javascript-array.com/scripts/jquery_simple_drop_down_menu/
Modified by Peter Graves March 2009
*/

var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;
var ddmenuitemclass = 0;
var ddmenucurrentclass = 0;

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   // ddmenucurrentclass = $(this).Class;
   ddmenucurrentclass = $(this).attr("class");
   ddmenuitemclass = $(this).addClass('current');
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function jsddm_close() { 

	if(ddmenuitemclass) {
		if(ddmenucurrentclass=='current'){
			// don't remove the class as this is the current category already.
			// yeah.  coding on a lazy sunday afternoon.  messy, but it works.w
		}else{
			ddmenuitemclass.removeClass('current');
		}
	}

	if(ddmenuitem)	ddmenuitem.css('visibility', 'hidden');
}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

$(document).ready(function()
{  $('#jsddm > li').bind('mouseover', jsddm_open)
   $('#jsddm > li').bind('mouseout',  jsddm_timer)});

document.onclick = jsddm_close;