   function submitting() {
    $('submitBtn').value="Submitting...";
    $('submitBtn').disable=true;
	return true;
    }
           
   function checkCode(str) {
		
   }
   
   function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		 
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   
		    return false
		 }

 		 return true					
	}

   
   
   function submitReg() {
   
   var errorsArray = new Array();
   var hasErrors = new Boolean(false);

   
   /* perform pre-clean up */
   
   allNodes = $("bookingForm").getElementsByClassName("error");
	for(i = 0; i < allNodes.length; i++) {
		Element.removeClassName($(allNodes[i]), "error");

	}
	$('error-status').removeClassName('errors');
	$('error-status').addClassName('hide');
	
	$('errorList').innerHTML = "";
	
	/* Check for errors  - Could be shortened*/
	if ($("title").present() == false) {
		errorsArray.push("title");
		hasErrors = true;
		$('errorList').innerHTML = "<li>Title cannot be empty</li>";
	}
	if ($("surname").present() == false) {
		errorsArray.push("surname");
		hasErrors = true;
		$('errorList').innerHTML += "<li>Surname cannot be empty</li>";
	}
	if ($("fname").present() == false) {
		errorsArray.push("fname");
		hasErrors = true;
		$('errorList').innerHTML += "<li>Forename cannot be empty</li>";
	}
	if ($("email").present() == false) {
		errorsArray.push("email");
		hasErrors = true;
		$('errorList').innerHTML += "<li>Email cannot be empty</li>";
	}
	if ($("email").present() == true) {
		if(echeck($F("email")) == false) {
			errorsArray.push("email");
			hasErrors = true;
			$('errorList').innerHTML += "<li>Email addresss is not valid</li>";
			}
	}
	if ($("address1").present() == false) {
		errorsArray.push("address1");
		hasErrors = true;
		$('errorList').innerHTML += "<li>Address line 1 cannot be empty</li>";
	}
	if ($("address2").present() == false) {
		errorsArray.push("address2");
		hasErrors = true;
		$('errorList').innerHTML += "<li>Address line 2 cannot be empty</li>";
	}
	if ($("country").present() == false) {
		errorsArray.push("country");
		hasErrors = true;
		$('errorList').innerHTML += "<li>Country cannot be empty</li>";
	}
	if ($("telephone").present() == false) {
		errorsArray.push("telephone");
		hasErrors = true;
		$('errorList').innerHTML += "<li>Telephone cannot be empty</li>";
	}
	
	/* Display errors */
	if (hasErrors == true) {
		$('error-status').removeClassName('hide');
		$('error-status').addClassName('errors');
		errrorLength = errorsArray.length;
		for(i = 0; i < errrorLength; i++) {
			Element.addClassName($(errorsArray.shift()), "error");
		}
		document.images.cryptogram.src='capt/cryptographp.php?cfg=0&&'+Math.round(Math.random(0)*1000)+1;
		$('submitBtn').disable=false;
		$('submitBtn').value="Send";
		return false;
	}	
	
	/* Ajax Requests */
	
	
	var data = $('bookingForm').serialize();
	var url = '/mailer.php';
	var myAjax = new Ajax.Request( 
			url, 
			{ 
					method: 'post', 
					postBody: data,
					onLoading: function() {
						$('submitBtn').disable=true;
						$('submitBtn').value="Submitting...";
						},
					onComplete: function check(response) {
						if (response.responseText == "code error") {
							$('error-status').removeClassName('hide');
							$('error-status').addClassName('errors');
							Element.addClassName($('security'), "error");
							$('errorList').innerHTML += "<li>Security Code is incorrect</li>";
							document.images.cryptogram.src='capt/cryptographp.php?cfg=0&&'+Math.round(Math.random(0)*1000)+1;
							return false;
						}
						else {
							$('submitBtn').disabled=true;
							$('submitBtn').value="Success";
							document.images.cryptogram.src='capt/cryptographp.php?cfg=0&&'+Math.round(Math.random(0)*1000)+1;
						}
					}
			});
}
