

// renamed to functions2.js because of severe caching problems


var message="Copyright  - to request images please visit our images request form and well be more than happy to supply you with the needed images free of charge\n\nThe image request form can be found at the bottom of the page or within the site map under the Contact heading.";
//redirectpage = "http://www.aqualux.co.uk/aqualux/imagerequest.asp";
///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
window.location = redirectpage;
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
window.location = redirectpage;
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

//document.oncontextmenu=new Function("alert(message);return false")


function CreateBookmarkLink() { 
	if (window.sidebar) { 
	// Mozilla Firefox Bookmark		
		window.sidebar.addPanel(document.title, location.href,"");	
	} else if( window.external ) { 
	// IE Favorite		
		window.external.AddFavorite(location.href, document.title)
	} else if(window.opera && window.print) { 
	// Opera Hotlist		
		return true;
	 }
}


function verifyContactForm() {
	oForm = document.contactForm;
	if (oForm.firstname.value == "") {
		alert("Please enter your first name");
		oForm.firstname.focus();
		return false;
	}
	if (oForm.surname.value == "") {
		alert("Please enter your surname");
		oForm.surname.focus();
		return false;
	}
	if ((oForm.phone.value == "") && (oForm.email.value == "")) {
		alert("Please enter either your Telephone Number or Email Address");
		oForm.email.focus();
		return false;
	}

	//Update the hidden how heard field
	var howHeard = oForm.h_how_heard.value
	oForm.howHeard.value = howHeard

	if (howHeard == "") {
			alert("Please select how you heard about us")
			oForm.h_how_heard.focus();
			return false;
	} else if (howHeard == "Search Engine") {
		if (oForm.h_how_heard_se.value == "") {
			alert("Please select which search engine you used");
			oForm.h_how_heard_se.focus();
			return false;
		} else {
			oForm.howHeard.value += ' ' + oForm.h_how_heard_se.value
		}
	} else if ((howHeard == "Newspaper Article") || (howHeard == "Magazine Article") || (howHeard == "Link from a Website") || (howHeard == "Other")) {
		if (oForm.h_how_heard_other.value == "") {
			alert("Please enter more detail on how you heard about us");
			oForm.h_how_heard_other.focus();
			return false;
		} else {
			oForm.howHeard.value += ' ' + oForm.h_how_heard_other.value
		}
	}

	if (oForm.comment.value == "") {
		alert("Please enter some comments");
		oForm.comment.focus();
		return false;
	}
	
	// check the code entered into the captcha box is correct
	if(oForm.captchaCode.value.toLowerCase() == captchaCodes[(captchaNumber)]) {
		oForm.formValidated.value = 'true';
		// success
		return true;
	} else {
		alert('Please enter the verification code.');
		oForm.captchaCode.focus();
		return false;
	}
	return false;
}

function verifyBusinessEnquiryForm()	{
	oForm = document.businessEnquiryForm;
	if (oForm.firstname.value == "") {
		alert("Please enter your first name")
		oForm.firstname.focus();
		return false;
	}
	if (oForm.surname.value == "") {
		alert("Please enter your surname")
		oForm.surname.focus();
		return false;
	}
	if (oForm.Address.value == "") {
		alert("Please enter your address")
		oForm.Address.focus();
		return false;
	}
	if (oForm.Country.value == "") {
		alert("Please enter your country")
		oForm.Country.focus();
		return false;
	}
	if (oForm.Postcode.value == "") {
		alert("Please enter your postcode")
		oForm.Postcode.focus();
		return false;
	}
	if (oForm.Email.value == "") {
		alert("Please enter your Email")
		oForm.Email.focus();
		return false;
	}
	if (oForm.Nature.value == "") {
		alert("Please select the nature of your enquiry")
		oForm.Nature.focus();
		return false;
	} 
	if (oForm.Howheard.value == "") {
		alert("Please select how you heard about Aqualux")
		oForm.Howheard.focus();
		return false;
	} 
	if ((oForm.Howheard.value == "Other") && (oForm.Other.value == "")) {
		alert("Please enter how you heard about Aqualux")
		oForm.Other.focus();
		return false;
	}
	// check the code entered into the captcha box is correct
	if(oForm.captchaCode.value.toLowerCase() == captchaCodes[(captchaNumber)]) {
		// success
		oForm.formValidated.value = 'true';
		return true;
	} else {
		alert('Please enter the verification code.');
		oForm.captchaCode.focus();
		return false;
	}
	return false;
}

function verifyRequestImagesForm() {
	oForm = document.requesImagesForm;
	if (oForm.firstname.value == "") {
		alert("Please enter your first name");
		oForm.firstname.focus();
		return false;
	}
	if (oForm.surname.value == "") {
		alert("Please enter your surname");
		oForm.surname.focus();
		return false;
	}
	if ((oForm.phone.value == "") && (oForm.email.value == "")) {
		alert("Please enter either your Telephone Number or Email Address");
		oForm.phone.focus();
		return false;
	}
	if (oForm.comment.value == "") {
		alert("Please enter some comments");
		oForm.comment.focus();
		return false;
	}
	// check the code entered into the captcha box is correct
	if(oForm.captchaCode.value.toLowerCase() == captchaCodes[(captchaNumber)]) {
		oForm.formValidated.value = 'true';
		// success
		return true;
	} else {
		alert('Please enter the verification code.');
		oForm.captchaCode.focus();
		return false;
	}
	return false;
}


function verifyBrochureForm(){
	oForm = document.brochureForm;
	
	if (oForm.firstname.value == "") {
		alert("Please enter your first name")
		oForm.firstname.focus();
		return false;
	}

	if (oForm.surname.value == "") {
		alert("Please enter your surname")
		oForm.surname.focus();
		return false;
	}
	
	if (oForm.email.value == "") {
		alert("Please enter your email address")
		oForm.email.focus();
		return false;
	}  
	

	if (oForm.h_formValidated.value != "true") {
		alert("To prevent SPAM, we require you to manually enter your name");
		oForm.name.focus();
		return false;
	} else {
		return true;
	}

	return false;
	
}

function verifyDownloadBrochureForm(){
	oForm = document.downloadBrochureForm;
	
	if (oForm.firstname.value == "") {
		alert("Please enter your first name")
		oForm.firstname.focus();
		return false;
	} 

	if (oForm.surname.value == "") {
		alert("Please enter your surname")
		oForm.surname.focus();
		return false;
	} 

	if (oForm.email.value == "") {
		alert("Please enter your email address")
		oForm.email.focus();
		return false;
	}  
	if (oForm.h_formValidated.value != "true") {
		alert("To prevent SPAM, we require you to manually enter your name");
		oForm.name.focus();
		return false;
	} else {
		return true;
	}

	return false;
	
}

function verifyTradeRegistrationForm() {
	oForm = document.tradeRegistrationForm;
	if (oForm.firstname.value == '') {
		alert('Please enter your first name.');
		oForm.firstname.focus();
		return false;
	}
	if (oForm.surname.value == '') {
		alert('Please enter your surname.');
		oForm.surname.focus();
		return false;
	} 
	if (oForm.company.value == '') {
		alert('Please enter your company name');
		oForm.company.focus();
		return false;
	} 
	if (oForm.email.value == '') {
		alert('Please enter your email address.');
		oForm.email.focus();
		return false;
	}
	if (oForm.password.value == '') {
		alert('Please enter a password.');
		oForm.password.focus();
		return false;
	} 
	if (oForm.password.value != oForm.password2.value) {
		alert('Your passwords do not match please re-type them.');
		oForm.password.focus();
		return false;
	} 
	// check the code entered into the captcha box is correct
	if(oForm.captchaCode.value.toLowerCase() == captchaCodes[(captchaNumber)]) {
		oForm.formValidated.value = 'true';
		// success
		return true;
	} else {
		alert('Please enter the verification code.');
		oForm.captchaCode.focus();
		return false;
	}
	return false;
}


function verifyReferralForm() {

	if (document.referral_form.friends_email.value == '') {
		alert('Please enter a valid friends email address');
		document.referral_form.friends_email.focus();
		return false;
	} else if (document.referral_form.h_formValidated.value == 'false') {
		alert('To prevent SPAM we require you to manually enter your friends email address');
		document.referral_form.friends_email.focus();
	} else if (document.referral_form.your_name.value == '') {
		alert('Please enter your name');
		document.referral_form.your_name.focus();
		return false;
	} else if (document.referral_form.your_email.value == '') {
		alert('Please enter a valid email address');
		document.referral_form.your_email.focus();
		return false;
	} else if (document.referral_form.message.value == '') {
		alert('Please enter a message to your friend.');
		document.referral_form.message.focus();
		return false;
	} 
	return true;	
}

function verifyRegisterForm() {
	oForm = document.registerForm;
	if (oForm.firstname.value == "") {
		alert("Please enter your first name");
		oForm.firstname.focus();
		return false;
	}
	if (oForm.surname.value == "") {
		alert("Please enter your surname");
		oForm.surname.focus();
		return false;
	}
	if (oForm.email.value == "") {
		alert("Please enter either your Email Address");
		oForm.email.focus();
		return false;
	}

	// check the code entered into the captcha box is correct
	if(oForm.captchaCode.value.toLowerCase() == captchaCodes[(captchaNumber)]) {
		oForm.formValidated.value = 'true';
		// success
		return true;
	} else {
		alert('Please enter the verification code.');
		oForm.captchaCode.focus();
		return false;
	}
	return false;
}


function verifyHuman(formName) {
	document[formName].h_formValidated.value = 'true'
}


function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function defaultFocus(oEle, sValue){
	if(oEle.value == sValue){
		oEle.value = '';
	}
}

function defaultBlur(oEle, sValue){
	if(oEle.value == ''){
		oEle.value = sValue;
	}
}

function printPage() {
  if (window.print)
    window.print()
  else
    alert("Sorry, your browser doesn't support this feature.");
}

var referralType = "";
function writeReferralLink(referralURL){
	document.write('<a href="' + referralURL + '?');
	document.write('title=' + escape(document.title));
	document.write('&location=' + escape(document.location));
	if(referralType == "product"){
		document.write('&type=product');
	}
	document.write('"><img src="http://www.aqualux.co.uk/pics/send_to_friend.gif" width="100" height="40" alt="Send this page to a friend" title="Send this page to a friend" hspace="3" vspace="3" /></a>');
}

function toggleDiv(elementId, imageId, imageSrcOff,imageSrcOn) {
	// if there are No menus open
	if(document.getElementById(elementId).style.display == 'none'){
		// open one
		document.getElementById(elementId).style.display = 'block';
		// swap the open/closed image
		document.getElementById(imageId).src = "../pics/" + imageSrcOn;

	} else {
	
		document.getElementById(elementId).style.display = 'none';
		document.getElementById(imageId).src = "../pics/" + imageSrcOff;

	}
}
function verifyCompetitionForm() {

  	elmLoop();
  	
  	if (document.competitionForm.name.value == '') {
		alert('Please enter your name');
		document.competitionForm.name.focus();
		return false;
	} else if (document.competitionForm.h_formValidated.value == 'false') {
		alert('To prevent SPAM we require you to manually enter your name');
		document.competitionForm.friends_email.focus();
	} else if (!validateEmail(document.competitionForm.email.value)) {
		alert('Please enter a valid email address');
		document.competitionForm.email.focus();
		return false;
	} else if (document.competitionForm.address.value == '') {
		alert('Please enter your address');
		document.competitionForm.address.focus();
		return false;
	} else if (document.competitionForm.town.value == '') {
		alert('Please enter your town');
		document.competitionForm.town.focus();
		return false;
	} else if (document.competitionForm.county.value == '') {
		alert('Please enter your county');
		document.competitionForm.county.focus();
		return false;
	} else if (document.competitionForm.postcode.value == '') {
		alert('Please enter your postcode');
		document.competitionForm.postcode.focus();
		return false;
	} else if (document.competitionForm.telephone.value == '') {
		alert('Please enter your telephone number');
		document.competitionForm.telephone.focus();
		return false;
	}
	return true;
}


function verifyQuestionForm() {
	oForm = document.questionForm;
	if (oForm.firstname.value == "") {
		alert("Please enter your first name");
		oForm.firstname.focus();
		return false;
	}
	if (oForm.surname.value == "") {
		alert("Please enter your surname");
		oForm.surname.focus();
		return false;
	}
	if (oForm.email.value == "") {
		alert("Please enter your Email Address");
		oForm.email.focus();
		return false;
	}
	if (oForm.question.value == "") {
		alert("Please enter your question");
		oForm.question.focus();
		return false;
	}
	
	
	if (oForm.h_formValidated.value != "true") {
		alert("To prevent SPAM, we require you to manually enter your name");
		oForm.name.focus();
		return false;
	} else {
		return true;
	}

	return false;
}























function validateEmail(email_address) {
	if (/\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email_address)){
		return true;
	}
	return false;
}

function elmLoop(){

	var theForm = document.forms[0];
	var alertText = "";

	var validated = new Array();
	var selected = new Array();

  for(i=0; i<theForm.elements.length; i++){

    // skip the fieldsets
    if(typeof(theForm.elements[i].type) == "undefined") {
      continue;
    }

    // skip anything that not a question
    eleName = theForm.elements[i].name;
    if(eleName.substr(0, 2) != "q_") {
      continue;
    }

    alertText += "Type: " + theForm.elements[i].type;

    if(theForm.elements[i].type == "text" || theForm.elements[i].type == "textarea") {
      alertText += " Value: " + theForm.elements[i].value;
        alertText += " Name: " + theForm.elements[i].name;
      if(theForm.elements[i].value == "") {
        alertText += " INVALID";
        validated[theForm.elements[i].name] = false;
      } else {
        validated[theForm.elements[i].name] = true;
      }
    }
    else if(theForm.elements[i].type == "radio") {
      alertText += " Checked? " + theForm.elements[i].checked;
      alertText += " Value: " + theForm.elements[i].value;
      alertText += " Name: " + theForm.elements[i].name;
      if(theForm.elements[i].checked) {
        validated[theForm.elements[i].name] = true;
        selected[theForm.elements[i].name] = true;
      }
     if (selected[theForm.elements[i].name] != true) {
        validated[theForm.elements[i].name] = false;
      }
    }
    alertText += "\n";
  }
  //alert(alertText);

  // now check for invalid fields
  // loop through the validated array
  for(var j in validated){
    if(validated[j] == false) {
      alert('Please enter/select an answer to all the questions');
      return false;
    }
  }
  return true;

}

function toggleDiv(elementId) {
	// if there are No menus open
	if (elementId == 'brochure') {
		document.getElementById('download').style.display = 'none';
		document.getElementById('brochure').style.display = 'block';
	} else {
		document.getElementById('download').style.display = 'block';
		document.getElementById('brochure').style.display = 'none';
	}
	
}


