
function agree() {
	document.getElementById('agreement').disabled = true;
	document.getElementById('alldone').disabled = false;
	}
	
function ismaxChrs(obj){
var  mChrs=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
	if (obj.getAttribute && obj.value.length > 0) {
		if (obj.value.length > mChrs) {
			obj.value = obj.value.substr(0, mChrs);
			}
		}
	}

function validate_form() {
	var errors='';
	if (document.getElementById('contname').value == "") {
		errors = errors + "Please enter your name\n\n";
	}
	
	if (document.getElementById('conttele').value == "" && document.getElementById('contemail').value == "") {
		errors = errors + "Please enter an email or telephone\nnumber so we can contact you.\n";
	}
	if (document.getElementById('strCAPTCHA').value == "") {
		errors = errors + "Please enter The verification code, this helps prevent false postings.\n";
	}

	if (errors) {
	alert( errors + "\n\nThankyou");
	document.NCH_returnValue = (errors == '');
	}
	else {
		alert("Thank you.");
	document.NCH_returnValue = (errors == '');
	}
} 

function checkBookingForm () {
	document.bookingForm.alldone.disabled='true';
	document.bookingForm.quit.disabled='true';
	var errors = "";
	
	if (alltrim(document.bookingForm.name.value) == "") {
		errors += "Please enter your name<br>";
	}
	
	if (alltrim(document.bookingForm.xx.value) == "" && alltrim(document.bookingForm.telephone.value) == "") {
		errors += "Please enter a contact number or email address<br>";
	}
	
	if (alltrim(document.bookingForm.xx.value) !== "") {
		if (!isValidEmail(alltrim(document.bookingForm.xx.value))) {
			errors += "Your email address is not correct";
		}
	}
	
	
	if (errors) {
		document.bookingForm.alldone.disabled=false;
		document.bookingForm.quit.disabled=false;

		if (document.getElementById('errorarea')) {
			document.getElementById('errorarea').innerHTML=errors;
		}
		return;
	}
	else {
		if (document.getElementById('errorarea')) {
			document.getElementById('errorarea').innerHTML="Thank you, we are sending your message";
		}
		document.bookingForm.submit();
	}
}

function clearErrorArea() {
		if (document.getElementById('errorarea')) {
			document.getElementById('errorarea').innerHTML='';
		}
}

//ajax request
function ajaxRequest(){
 var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"]
 if (window.ActiveXObject){ 
  for (var i=0; i<activexmodes.length; i++){
   try{
    return new ActiveXObject(activexmodes[i])
   }
   catch(e){
   }
  }
 }
 else if (window.XMLHttpRequest) 
  return new XMLHttpRequest()
 else
  return false
}
//Restrict to whole numbers on input	
function isWholeNumber(e){
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8 && unicode!=45){ 
		if (unicode<48||unicode>57) 
		return false 
	}
}

//Restrict to decimal numbers on input	
function isDeclNumber(e){
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8){ 
		if (unicode<46||unicode>57) 
		return false 
	}
}

//format to d decimal places
function toDecl(obj,a,d) {
		if (!isNaN(a)) {
		a = a / 1;
		a = a.toFixed(d); 
		document.getElementById(obj).value = a;
	}
}

function alltrim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = / +/g;
   temp = temp.replace(obj, " ");
   if (temp == " ") { temp = ""; }
   return temp;
}

toCamelCase.exp = / ([a-z])/;
function toCamelCase(s) {
	s = ' '+s.toLowerCase();
	for(var exp = toCamelCase.exp; 
		exp.test(s); 
		s = s.replace(exp, ' '+RegExp.$1.toUpperCase()) );
	return alltrim(s);
}

function passwordTrim(value) {
	var obj=/\W/g;
		value = value.replace(obj, "");
		return value;
}

function noSpecials(value) {
//	var obj=/[&/=:#?*\\'\\"<>%$]/g;
//	var obj = /&nbsp;|\*picture\*|\f|\n|\r|\t|[&/=:#?*<>%$\\"\\'\.\,\)\(]/g;
	var obj = /&nbsp;|\*picture\*|\f|\t|[&/=:#?*<>%$\\"\\'\.\,\)\(]/g;
		value = value.replace(obj, " ");
		return value;
}

function isValidEmail(emailAddress) {
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(2([0-4]\d|5[0-5])|1?\d{1,2})(\.(2([0-4]\d|5[0-5])|1?\d{1,2})){3} \])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    return re.test(emailAddress);
}
