
String.prototype.RTrim = function() {return this.replace(/\s+$/, "");}
String.prototype.LTrim = function() {return this.replace(/^\s+/, "");}
String.prototype.Trim  = function() {return this.RTrim().LTrim();}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function popUpWindow(str_URL, str_winName, int_width, int_height) {
	// <a href="javascript:popUpWindow('http://www.google.com','window_name_no_spaces','600','400')">
	newwindow = window.open(str_URL, str_winName, 'width='+int_width+',height='+int_height+',menubar=off,directories=off,toolbar=off');
	if (window.focus) {newwindow.focus()};
}

//<a href="javascript:openImage('../pics/p_map.gif', 'Clarke Rubicon - Coalville, Leicestershire', 999, 334, 'no', 'no','yes')">Click to View</a>
function openImage(str_URL, str_title, int_width, int_height, str_resize, str_scroll, str_autoSize) {
	if (int_width == 0) {
		int_width = 600
	} if (int_height == 0) {
		int_height = 400
	} if (str_resize != 'yes') {
		str_resize = 'no'
	} if (str_scroll != 'yes') {
		str_scroll = 'no'
	}
	
	newWindow = window.open('', '_blank', 'width='+int_width+',height='+int_height+',menubar=off,directories=off,status=no,toolbar=off,resizable='+str_resize+',scrollbars='+str_scroll);
	newWindow.document.write("<html>")
	newWindow.document.write("<title>" + str_title + "</title>")
	newWindow.document.write("<link rel=\"stylesheet\" href=\"../include/styles.css\" type=\"text/css\">")
	
	if (str_autoSize = 'yes') {
		newWindow.document.write("<body onload=\"window.resizeTo(document.getElementById('myImage').width+20, document.getElementById('myImage').height+80)\" style=\"margin: 5px;\">")
	} else {
		newWindow.document.write("<body>")
	}

	newWindow.document.write("<center>")
	newWindow.document.write("<img src=\"" + str_URL + "\" alt=\"" + str_title + "\" id=\"myImage\" />")
	newWindow.document.write("<a href=\"javascript:self.close();\">Close Window</a>")
	newWindow.document.write("</center>")
	newWindow.document.write("</body>")
	newWindow.document.write("</html>")
	newWindow.document.close()
	if (window.focus) {newWindow.focus()};
}


function defaultFocus(oEle, sValue){
	if(oEle.value == sValue){
		oEle.value = '';
	}
}

function defaultBlur(oEle, sValue){
	if(oEle.value == ''){
		oEle.value = sValue;
	}
}

function validateEmail(email_address) {
	if (/\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email_address)){
		return true;
	}
	return false;
}



function verifyContactForm() {

	var onErrorAlert		= true;
	var onErrorMessage	= false;
	var errorMessages		= new Array();
	var focused					= false;
	var formObj					= document.contactForm;

	if (formObj.name.value == '') {
		errorMessages.push('Please enter your name');
		if(!focused){
			formObj.name.focus();
			focused = true;
		}
	}

	if (!validateEmail(formObj.email.value)) {
		errorMessages.push('Please enter a valid email address');
		if(!focused){
			formObj.email.focus();
			focused = true;
		}
	}
	
	if (formObj.address.value == '') {
		errorMessages.push('Please enter your address');
		if(!focused){
			formObj.address.focus();
			focused = true;
		}
	}
	
	if (formObj.postcode.value == '') {
		errorMessages.push('Please enter your postcode');
		if(!focused){
			formObj.postcode.focus();
			focused = true;
		}
	} 
	
	if (formObj.telephone.value == '') {
		errorMessages.push('Please enter your telephone number');
		if(!focused){
			formObj.telephone.focus();
			focused = true;
		}
	}

	if (formObj.comments.value == '') {
		errorMessages.push('Please enter your comments');
		if(!focused){
			formObj.comments.focus();
			focused = true;
		}
	}

	
	if (formObj.h_formValidated.value != 'true') {
		errorMessages.push('To prevent SPAM we require you to manually enter your name');
		if(!focused){
			formObj.name.focus();
			focused = true;
		}
	}

	if(errorMessages.length != 0){
		if(onErrorAlert){
				alert(errorMessages[0]);
		}
		if(onErrorMessage){
				oErrorDiv = document.getElementById("error_messages");
				oErrorDiv.innerHTML = "There was a problem with the information you supplied:<br />";
				for(var i=0; i<errorMessages.length; i++){
					oErrorDiv.innerHTML += "<li>" + errorMessages[i] + "</li>";
				}
				oErrorDiv.style.display = "block";
		}
		return false;

	} else {
		var groupId = 20;
		var updateURL = 'contactSave.asp?name=' + formObj.name.value
	       + '&email=' + formObj.email.value + '&groupId=' + groupId;
	  var responseText = ajaxGet(updateURL);
	  if (returnSuccess(responseText,"There has been a problem sending your enquiry, please wait a moment and try again.")) {
			return true;
	  } else {
			return false;
		}
	}

}


function verifyRegisterForm() {

	var onErrorAlert		= true;
	var onErrorMessage	= false;
	var errorMessages		= new Array();
	var focused					= false;
	var formObj					= document.registerForm;

	if (formObj.name.value == '') {
		errorMessages.push('Please enter your name');
		if(!focused){
			formObj.name.focus();
			focused = true;
		}
	}

	if (!validateEmail(formObj.email.value)) {
		errorMessages.push('Please enter a valid email address');
		if(!focused){
			formObj.email.focus();
			focused = true;
		}
	}

	
	if (formObj.h_formValidated.value != 'true') {
		errorMessages.push('To prevent SPAM we require you to manually enter your email address');
		if(!focused){
			formObj.name.focus();
			focused = true;
		}
	}
	
	if(errorMessages.length != 0){
		if(onErrorAlert){
				alert(errorMessages[0]);
		}
		if(onErrorMessage){
				oErrorDiv = document.getElementById("error_messages");
				oErrorDiv.innerHTML = "There was a problem with the information you supplied:<br />";
				for(var i=0; i<errorMessages.length; i++){
					oErrorDiv.innerHTML += "<li>" + errorMessages[i] + "</li>";
				}
				oErrorDiv.style.display = "block";
		}
		return false;

	} else {
		var groupId = 19;
		var updateURL = 'contactSave.asp?name=' + formObj.name.value
	       + '&email=' + formObj.email.value + '&groupId=' + groupId;
	  var responseText = ajaxGet(updateURL);
	  if (returnSuccess(responseText,"There has been a problem sending your enquiry, please wait a moment and try again.")) {
			return true;
	  } else {
			return false;
		}
	}

}




function selectASize(id, size) {
	var hiddenInput = document.getElementById('hidden_size');
	hiddenInput.value = id + '~' + size;
	hideDropDown();

	var messageDiv = document.getElementById('your_size');
	messageDiv.innerHTML = 'Your size: <b>'+size+'</b>';

}

function showDropDown () {
	var sDropDown = document.getElementById('size_list');
	sDropDown.style.display = 'block';
}
function hideDropDown () {
	var sDropDown = document.getElementById('size_list');
	sDropDown.style.display = 'none';
}

var hideTimer = false;

function startHideTimer() {
	if(hideTimer == false) {
		hideTimer = setTimeout('hideDropDown()', 1500);
	}
}
function cancelHideTimer() {
	if(hideTimer) {
		clearTimeout(hideTimer);
		hideTimer = false;
	}
}

function printPage() {
  if (window.print)
    window.print()
  else
    alert("Sorry, your browser doesn't support this feature.");
}


function ajaxGet(urlToGet) {
	//Gets a URL and returns the response
	var xmlhttp = GetXmlHttpObject();
	if (xmlhttp == null) {
		// Check if browser is compatable
		alert("Sorry, your browser does not support HTTP Request...");
		return;
	}

	xmlhttp.open("GET",urlToGet,false);
	xmlhttp.send(null);
	return xmlhttp.responseText;
}

function GetXmlHttpObject() {
	//Returns the XML HHTP object (browser dependant)
	var objXMLHttp=null;
	if (window.XMLHttpRequest) {
		//FF / Safari / Opera / Chrome Check
		objXMLHttp=new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		//IE Check
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}


function returnSuccess(responseMessage,errorMessage) {
	//Checks for 'Success' at end of string and returns error message if not present
	responseMessage = responseMessage.Trim();
	if (Right(responseMessage,7) == "Success") {
		return true;
	} else {
		alert(errorMessage);
		return false;
	}
}

function Left (str, n) {
   return str.substring(0, n);
}

function Right (str, n) {
   len = str.length;
   return str.substring(len -n, len);
}

function verifyHuman(formName) {
	document[formName].h_formValidated.value = 'true'
}