
var defaultEmptyOK = false
var bolBrochureSubmitted = false;
function ValidateBrochure(objForm) {
	var strBaseMessage = new String('Please rectify the following items before submitting the form:\r\n\r\n');
	var strMessage = new String();
	
	if (!bolBrochureSubmitted) {
		if(objForm.strTitle.value.length == 0) {
			strMessage += 'a title is required\r\n';
		}
		
		if(objForm.FirstName.value.length == 0) {
			strMessage += 'a first name is required\r\n';
		}
		
		if(objForm.LastName.value.length == 0) {
			strMessage += 'a last name is required\r\n';
		}
		
		if(objForm.Address1.value.length == 0) {
			strMessage += 'an address is required\r\n';
		}
		
		if(objForm.CitySuburb.value.length == 0) {
			strMessage += 'a city is required\r\n';
		}
		
		if(objForm.StateProvince.value.length == 0) {
			strMessage += 'a state is required\r\n';
		}	
		
		if(objForm.Country.value.length == 0) {
			strMessage += 'a country is required\r\n';
		}
		
		if(objForm.PostcodeZip.value.length == 0) {
			strMessage += 'a postcode is required\r\n';
		}
		
		if(objForm.Telephone.value.length == 0) {
			strMessage += 'a phone number is required\r\n';
		}
	
		if(objForm.Email.value.length == 0) {
			strMessage += 'an email address is required\r\n';
		} else if (!isEmail(objForm.Email.value)) {
			strMessage += 'a valid email address is required\r\n';
		}

	if(objForm.HowDidYou0.value == 0)
	{
		strMessage += 'other questions - how did you hear about us?\r\n';
	} 
	try {
		if(objForm.HowDidYou1.value == 0)
		{
			strMessage += 'other questions - how did you hear about us?\r\n';
		}
	} catch(e) {
		/*
		Do nothing the second HowDidYou hear about us drop down does not
		exist so we don't need to validate it
		*/
	}
		
		/* pgh P1_BF_632 13.07.2007 */
		objForm.brochureList.value = "";
		objForm.brochureCodeList.value = "";
		if(objForm.chkBrochures.length != undefined) {
			for (var i=0; i < objForm.chkBrochures.length; i++) {
	   		if (objForm.chkBrochures[i].checked) {
	      	objForm.brochureList.value += objForm.chkBrochures[i].value + " (" + objForm.strBrochureCode[i].value + ")\r\n";
	      	objForm.brochureCodeList.value += objForm.strBrochureCode[i].value + "\r\n";
	      }
	   	}
	  } else {
	  	if (objForm.chkBrochures.checked) {
	  		objForm.brochureList.value = objForm.chkBrochures.value + " (" + objForm.strBrochureCode.value + ")\r\n";
	  		objForm.brochureCodeList.value = objForm.strBrochureCode.value + "\r\n";
	  	}
	  }
	} 
	else 
	{
		strMessage += 'please submit this form only once\r\n';
		bolBrochureSubmitted = true;
	}

	
	if (objForm.brochureList.value.length == 0)
		strMessage += 'at least one brochure must be selected\r\n';

	if(strMessage.length == 0) {
		//objForm.SubmitButton.value = 'Please wait';
		//objForm.SubmitButton.disabled = true;
		bolBrochureSubmitted = true;
		//objForm.submit();
		return true;
	} else {
		bolBrochureSubmitted = false;
		alert(strBaseMessage + strMessage);
		return false;
	}

}

// isEmail (STRING s [, BOOLEAN emptyOK])
//
// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.


// Check whether string s is empty.

function isEmpty(s) {   
	return ((s == null) || (s.length == 0))
}


function isEmail (s)
{   
	if (isEmpty(s)) {
		if (isEmail.arguments.length == 1) {
			return defaultEmptyOK;
		} else {	
			return (isEmail.arguments[1] == true);
		}
	}

	// is s whitespace?
	if (isWhitespace(s)) return false;

	// there must be >= 1 character before @, so we
	// start looking at character position 1
	// (i.e. second character)
	var i = 1;
	var sLength = s.length;

	// look for @
	while ((i < sLength) && (s.charAt(i) != "@"))
	{ i++
	}

	if ((i >= sLength) || (s.charAt(i) != "@")) return false;
	else i += 2;

	// look for .
	while ((i < sLength) && (s.charAt(i) != "."))
	{ i++
	}

	// there must be at least one character after the .
	if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
	else return true;
}

