﻿
function clearQuotes(theForm) {
	for (i=0;i<theForm.elements.length;i++) {
		if (theForm.elements[i].value) {
			theForm.elements[i].value = theForm.elements[i].value.replace(/'/gi,"`");
		}
	}
}

function checkEmail(theEmail) {
	if (theEmail.indexOf('.')==-1) return false;
	if (theEmail.indexOf('@')==-1) return false;
	if (theEmail.length<6) return false;
	return true;
}

function checkCompetition() {
	theForm=document.CompetitionForm;
	clearQuotes(theForm);
	
	if (theForm.fname.value.length<1) {alert("Please enter your first name.");return false;}
//	if (theForm.lname.value.length<1) {alert("Please enter your last name.");return false;}
	if (theForm.email.value.length<1) {alert("Please enter your email address.");return false;}
	if (checkEmail(theForm.email.value)==false) {alert("The email address you have entered does not seem to be valid.");return false;}

	return true;
}

function checkSubscription() {
	theForm=document.Form;
	clearQuotes(theForm);
	
	if (theForm.fname.value.length<1) {alert("Please enter your first name.");return false;}
	if (theForm.postcode.value.length<1) {alert("Please enter your post or zip code.");return false;}
//	if (theForm.lname.value.length<1) {alert("Please enter your last name.");return false;}
	if (theForm.email.value.length<1) {alert("Please enter your email address.");return false;}
	if (checkEmail(theForm.email.value)==false) {alert("The email address you have entered does not seem to be valid.");return false;}

	return true;
}

function checkSampleRequest() {
	//theForm=document.Form;
	//clearQuotes(theForm);
    var obj;

    obj = document.getElementById("company");
	if (obj.value.length < 1) {
	    alert("Please enter your company.");
	    obj.focus();
	    return false; 
	}
	obj = document.getElementById("fname");
	if (obj.value.length < 1) {
	    alert("Please enter your first name.");
	    obj.focus();
	    return false; 
	}
	obj = document.getElementById("lname");
	if (obj.value.length < 1) {
	    alert("Please enter your last name.");
	    obj.focus();
	    return false;
	}
	//if (theForm.address1.value.length<1) {alert("Please enter your address.");return false;}
	//if (theForm.city.value.length<1) {alert("Please enter your city.");return false;}
	//if (theForm.state.value.length<1) {alert("Please enter your state.");return false;}
	//if (theForm.postcode.value.length<1) {alert("Please enter your post or zip code.");return false;}
//	if (theForm.lname.value.length<1) {alert("Please enter your last name.");return false;}
	obj = document.getElementById("email");
	if (obj.value.length < 1) {
	    alert("Please enter your email address.");
	    obj.focus();
	    return false;
	}
	if (checkEmail(obj.value) == false) {
	    alert("Please enter valid email address.");
	    obj.focus();
	    return false;
	}

	obj = document.getElementById("telephone");
	if (obj.value.length < 1) {
	    alert("Please enter your phone number.");
	    obj.focus();
	    return false;
	}

	return true;
}

function checkEnquiry() {
	theForm=document.Form;//.EnquiryForm;
	clearQuotes(theForm);
	
	if (theForm.fname.value.length<1) {alert("Please enter your first name.");return false;}
//	if (theForm.lname.value.length<1) {alert("Please enter your last name.");return false;}
//	if (theForm.org.value.length<1) {alert("Please enter your Company name.");return false;}
//	if (theForm.street.value.length<1) {alert("Please enter your street address.");return false;}
//	if (theForm.suburb.value.length<1) {alert("Please enter your town or suburb.");return false;}
	if (theForm.postcode.value.length<1) {alert("Please enter your post or zip code.");return false;}
//	if (theForm.state.value.length<1) {alert("Please enter your state or region.");return false;}
//	if (theForm.country.value.length<1) {alert("Please enter your Country.");return false;}
	if (theForm.email.value.length<1) {alert("Please enter your email address.");return false;}
	if (checkEmail(theForm.email.value)==false) {alert("The email address you have entered does not seem to be valid.");return false;}
//	if (theForm.phone1.value.length<1) {alert("Please enter your phone number.");return false;}
	if (theForm.notes.value.length<1) {alert("Please enter comments.");return false;}

	return true;
}

function checkMember() {
	theForm=document.MemberForm;
	clearQuotes(theForm);
	
	if (theForm.fname.value.length<1) {alert("Please enter your first name.");return false;}
//	if (theForm.lname.value.length<1) {alert("Please enter your last name.");return false;}
	if (theForm.email.value.length<1) {alert("Please enter your email address.");return false;}
	if (checkEmail(theForm.email.value)==false) {alert("The email address you have entered does not seem to be valid.");return false;}

	if (theForm.password.value.length<1) {alert("Please enter a password.");return false;}
	if (theForm.password2.value.length<1) {alert("Please enter your password again.");return false;}
	if (theForm.password.value != theForm.password2.value) {alert("Your passwords do not match. Please retype them.");return false;}

	return true;
}

function checkJoinNow(f)
{
	with(f)
	{
		if (checkEmail(email.value) == false)
		{
			alert("The email address you have entered does not seem to be valid.");
			return false;
		}
	}
	
}


