 	function MM_findObj(n, d) { //v4.01
		var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
			d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
		if(!x && d.getElementById) x=d.getElementById(n); return x;
	}
	function MM_swapImage() { //v3.0
		var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
		 if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}
	function MM_swapImgRestore() { //v3.0
		var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}
	
	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 IsNumeric(sText) {
    var ValidChars = "0123456789.";
    var IsNumber=true;
    var Char;
   
    for (i = 0; i < sText.length && IsNumber == true; i++) { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) {
         IsNumber = false;
      }
    }
    return IsNumber;
   
  }
  
  function IsPhoneNum(sText) {
    var ValidChars = "0123456789.()+ ";
    var IsPhoneNum=true;
    var Char;
   
    for (i = 0; i < sText.length && IsPhoneNum == true; i++) { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) {
         IsPhoneNum = false;
      }
    }
    return IsPhoneNum;
   
  }
  
  function StripSpacesFromEnds(s) {
	// developed by willmaster.com
	while((s.indexOf(' ',0) == 0) && (s.length > 1)) {
		s = s.substring(1,s.length);
	}
	while((s.lastIndexOf(' ') == (s.length - 1) && (s.length > 1))) {
		s = s.substring(0,(s.length - 1));
	}
	if((s.indexOf(' ',0) == 0) && (s.length == 1)) s = '';
	return s;
  }
  
  function isEmail (sEmail) {
    var regEmail = /^([\w-]+\.?)*\w+@([\da-zA-z-]+\.)+[a-zA-z]{2,3}$/;
    if (sEmail==null || sEmail == "") { 
      return false;
    } else {
      return regEmail.test(sEmail);
    }
  }
  
  function LimitChars(element, maxChars){

	if ( document.all(element).type == "textarea" ) {
		if (document.all(element).innerText.length > maxChars ) {
			document.all(element).innerText = document.all(element).innerText.substring(0,maxChars);
		}
	} else if ( document.all(element).type = "text") {
		if (document.all(element).value.length > maxChars ) {
			document.all(element).value = document.all(element).value.substring(0,maxChars);
		}
	}

  }
  
  function LimitEditChars(element, maxChars){

	if ( document.updateDealForm(element).type == "textarea" ) {
		if (document.updateDealForm(element).innerText.length > maxChars ) {
			document.updateDealForm(element).innerText = document.updateDealForm(element).innerText.substring(0,maxChars);
		}
	} else if ( document.updateDealForm(element).type = "text") {
		if (document.updateDealForm(element).value.length > maxChars ) {
			document.updateDealForm(element).value = document.updateDealForm(element).value.substring(0,maxChars);
		}
	}

  }

  
  function isPresent(s) {
	s = StripSpacesFromEnds(s);
	return s.length;
  }
  
  function validateQueryForm() {
	name = document.queryForm.name.value;
	dayTel = document.queryForm.daytel.value;
	evenTel = document.queryForm.eventel.value;
	emailAddress = document.queryForm.email.value;

	if (name == "") {
		alert("You must enter a name!");
		document.queryForm.name.focus();
		return false;
	}
	
	if ((dayTel != "") && (!IsPhoneNum(dayTel))) {
	    alert("Telephone numbers may only consist of numbers, spaces, '(', ')' and '+'");
		document.queryForm.daytel.focus();
		return false;		   
	}
	
	if ((evenTel != "") && (!IsPhoneNum(evenTel))) {
	    alert("Telephone numbers may only consist of numbers, spaces, '(', ')' and '+'");
		document.queryForm.eventel.focus();
		return false;		   
	}
	
	if ((dayTel == "") && (evenTel == "") && (emailAddress == "")) {
		alert("You must supply a contact number or email address");
		document.queryForm.daytel.focus();
		return false;
	}
	
	// E-mail Validation by Henrik Petersen / NetKontoret
	// Explained at www.echoecho.com/jsforms.htm
	// Please do not remove this line and the two lines above.
	if (emailAddress != "") {
    	apos=emailAddress.indexOf("@"); 
    	dotpos=emailAddress.lastIndexOf(".");
    	lastpos=emailAddress.length-1;
    	if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) {
    		alert("You must enter a valid email address.");
    		document.queryForm.email.focus();
    		return false;
    	}
	}

  }
  
  function validateContactForm() {
	name = document.contact_form.full_name.value;
	phone = document.contact_form.phone.value;
	emailAddress = document.contact_form.email.value;

	if (name == "") {
		alert("You must enter a name!");
		document.contact_form.full_name.focus();
		return false;
	}
	
	if ((phone != "") && (!IsPhoneNum(phone))) {
	    alert("Telephone numbers may only consist of numbers, spaces, '(', ')' and '+'");
		document.contact_form.phone.focus();
		return false;		   
	}
	
	if ((phone == "") && (emailAddress == "")) {
		alert("You must supply a contact number or email address");
		document.contact_form.phone.focus();
		return false;
	}
	
	// E-mail Validation by Henrik Petersen / NetKontoret
	// Explained at www.echoecho.com/jsforms.htm
	// Please do not remove this line and the two lines above.
	if (emailAddress != "") {
    	apos=emailAddress.indexOf("@"); 
    	dotpos=emailAddress.lastIndexOf(".");
    	lastpos=emailAddress.length-1;
    	if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) {
    		alert("You must enter a valid email address.");
    		document.contact_form.email.focus();
    		return false;
    	}
	}

  }
  
  function validateBranchForm() {
	address1 = document.branch_form.address1.value;
	town = document.branch_form.town.value;
	phone = document.branch_form.phone.value;
	email = document.branch_form.email.value;

	if (address1 == "") {
		alert("You must enter the address!");
		document.branch_form.address1.focus();
		return false;
	 }
	if (town == "") {
		alert("You must enter the town!");
		document.branch_form.town.focus();
		return false;
	}
	if (phone == "") { 
        alert("You must enter a phone number!");
        document.branch_form.phone.focus(); 
        return false; 
    }
	if (email == "") { 
        alert("You must enter an email address!");
        document.branch_form.email.focus(); 
        return false; 
    }
  }
  
  function cancelBranch() {
	document.branch_form.action = "branches.php";
	document.branch_form.submit();
  }
  
  function validateEmail() {
	email_address = document.subscribe_form.email_address.value;
	if (!isEmail(email_address)) { 
          alert('Invalid email address!');
          document.subscribe_form.email_address.focus(); 
          return false;
	}
  }
  
  function subscribe() {
	document.subscribe_form.submit();
  }
  
  function unsubscribe() {
	document.subscribe_form.action = "unsubscribe.php";
	document.subscribe_form.submit();
  }
  
  function cancelUpdateTitle() {
	document.updateTitleForm.action = "admin.php";
	document.updateTitleForm.submit();
  }
  
  function cancelAdd() {
	document.addContentForm.action = "admin.php";
	document.addContentForm.submit();
  }

  function cancelUpdatePre() {
	document.updatePreTextForm.action = "admin.php";
	document.updatePreTextForm.submit();
  }
  
  function cancelUpdate() {
	document.updateContentForm.action = "admin.php";
	document.updateContentForm.submit();
  }
  
  function cancelUpdatePost() {
	document.updatePostTextForm.action = "admin.php";
	document.updatePostTextForm.submit();
  }
  
  function cancelUpdateNews() {
	document.updateNewsForm.action = "newsAdmin.php";
	document.updateNewsForm.submit();
  }
  
  function cancelAddNews() {
	document.addNewsForm.action = "newsAdmin.php";
	document.addNewsForm.submit();
  }
  
  function cancelUpdateRate() {
	document.updateRateForm.action = "admin.php";
	document.updateRateForm.submit();
  }
  
  function genEmailPreview() {
	document.emailForm.action = "emailPreview.php";
	document.emailForm.target = "_blank";
	document.emailForm.submit();
  }
  
  function sendEmail() {
	document.emailForm.action = "sendNewsletter.php";
	document.emailForm.target = "_self";
	document.emailForm.submit();
  }
  
  function nextEmailPage() {
	pageNum = parseInt(document.emailAddressForm.page_num.value);
	pageNum = pageNum + 1;
	document.emailAddressForm.page_num.value = pageNum;
	document.emailAddressForm.action = "emailList.php";
	document.emailAddressForm.submit();
  }
  
  function previousEmailPage() {
	pageNum = parseInt(document.emailAddressForm.page_num.value);
	pageNum = pageNum - 1;
	document.emailAddressForm.page_num.value = pageNum;
	document.emailAddressForm.action = "emailList.php";
	document.emailAddressForm.submit();
  }
  
  function firstEmailPage() {
	pageNum = 1;
	document.emailAddressForm.page_num.value = pageNum;
	document.emailAddressForm.action = "emailList.php";
	document.emailAddressForm.submit();
  }
  
  function lastEmailPage() {
	maxPage = parseInt(document.emailAddressForm.max_page.value);
	pageNum = maxPage;
	document.emailAddressForm.page_num.value = pageNum;
	document.emailAddressForm.action = "emailList.php";
	document.emailAddressForm.submit();
  }

	function addUserAccount() {
		document.user_form.action = "add_user_form.php";
		document.user_form.submit();
	}
  
  	function editUserAccount() {
		document.user_form.action = "edit_user.php";
		document.user_form.submit();
	}
	
	function deleteUserAccount() {
		var userConfirm =
	      confirm("Delete this user?");
	    if (userConfirm) {
		  document.user_form.action = "delete_user.php";
		  document.user_form.submit();
	    } else {
          return false;
	    }
	}
	
	function changePassword() {
		document.user_form.action = "changePassword.php";
		document.user_form.submit();
	}

	
	function confirmDelete() {
		var confirmDelete =
	        confirm("Delete this item?");
	    if (confirmDelete) {
			return true;
	    } else {
            return false;
	    }
	}
	
	function validateUserForm() {
		username = document.add_user_form.user_name.value;
		password = document.add_user_form.password.value;
		verifyPassword = document.add_user_form.vpassword.value;
		
		if (username == "") {
		  alert('You must enter a username!');
          document.add_user_form.user_name.focus(); 
          return false; 
	    }
		
		if (password == "") {
		  alert('You must enter a password!');
          document.add_user_form.password.focus(); 
          return false; 
	    }
		
		if (password.length < 6) {
		  alert('Passwords must be at least 6 characters in length!');
          document.add_user_form.password.focus(); 
          return false; 
	    }
		
		if (verifyPassword == "") {
		  alert('You must verify your password!');
          document.add_user_form.vpassword.focus(); 
          return false; 
	    }
		
		if (password != verifyPassword) {
		  alert('Password and verification do not match!');
          document.add_user_form.password.focus(); 
          return false; 
	    }
		
		document.add_user_form.action = "add_user.php";
		document.add_user_form.submit();
	}
	
	function validatePasswordForm() {
		newPassword = document.password_form.password.value;
		verifyPassword = document.password_form.vpassword.value;
		
		if (newPassword == "") {
		  alert('You must enter a new password!');
          document.password_form.password.focus(); 
          return false; 
	    }
		
		if (newPassword.length < 6) {
		  alert('Passwords must be at least 6 characters in length!');
          document.password_form.password.focus(); 
          return false; 
	    }
		
		if (verifyPassword == "") {
		  alert('You must verify your new password!');
          document.password_form.vpassword.focus(); 
          return false; 
	    }
		
		if (newPassword != verifyPassword) {
		  alert('New password and verification do not match!');
          document.password_form.password.focus(); 
          return false; 
	    }
		
		document.password_form.action = "updatePassword.php";
		document.password_form.submit();
	}
	
	function dataBackup() {
		document.admin_form.action = "dataBackup.php";
		document.admin_form.submit();
	}
							   