
//sets the value of the hidden field which is checked against to display
//the correct form fields
function setEnqType(newVal){
	var hideVal;
	hideVal = newVal.options[newVal.selectedIndex].value;
	document.contactUs.hidden1.value = hideVal;
}

//initial validation and submission of the trade or retail selection
function sendForm(){
		if(document.contactUs.hidden1.value == "business" || document.contactUs.hidden1.value == "personal"){
			document.contactUs.action = "contactUs.asp";
			document.contactUs.submit();
		}
		else if (document.contactUs.hidden1.value == 0){
			alert("Please choose the type of enquiry you wish to make!");//submitForm();
		}
		else{
			//goes to other submit function because one of 
			// the forms must have been filled out
			submitForm();
		}
}

//validates the (completed) forms
function submitForm(){
	var theForm = document.contactUs;
	var blnSubmit = false;
	
	if(theForm.name.value == ""){
		alert("Please enter your name!");
		blnSubmit = false;
		return false;
	}
	else{
		blnSubmit = true;
	}
	
	if(theForm.email.value == "" && theForm.telephone.value == ""){
		alert("Please enter either your telephone number or email address so we can contact you!");
		blnSubmit = false;
		return false;
	}
	else{
		blnSubmit = true;
	}
	
	//email validation
	if(theForm.telephone.value === ""){
	if (theForm.email.value != ""){
		var field = theForm.email; // email field
  		var str = field.value; // email string
  		var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
  		var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
  		if (!reg1.test(str) && reg2.test(str)){ // if syntax is valid
   			blnSubmit = true;
  		}
		else{
  			alert("Can you please insert a valid email address!"); // this is also optional
  			field.focus();
  			field.select();
			blnSubmit = false;
  			return false;
			}
	}
	else{
		alert("Please insert your email address!");
		theForm.email.focus();
		blnSubmit = false;
		return false;
	}
	}
	
	if(theForm.comments.value == ""){
		alert("Please enter your enquiry/comments in the box provided!");
		theForm.comments.focus();
		blnSubmit = false;
		return false;
	}
	else{
		blnSubmit = true;
	}
	
	if(blnSubmit){
		theForm.action = "thanks.asp";
		theForm.submit();
	}	
}

