/* Validates an Email Address*/
function validateEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   return reg.test(email);
}


// Original JavaScript code by Chirp Internet: www.chirp.com.au 
function checkArray(form, arrayName) { 
	var retval = new Array(); 
	for(var i=0; i < form.elements.length; i++) { 
		var el = form.elements[i]; if(el.type == "checkbox" && el.name == arrayName && el.checked) { 
			retval.push(el.value); 
		} 
	} 
	return retval; 
} 


/* Validate Getting Started Form */
function validateForm(form) { 
	
	if (form.name.value == "") {
		alert("Name is a required field.");
		form.name.focus();
		return false;
	}		
	if (form.email.value == "") {
		alert("E-mail address is a required field.");
		form.email.focus();
		return false;
	} else if (validateEmail(form.email.value) == false) {
		alert("The E-mail you entered is invalid.");
		form.email.focus();
		return false;
	}
	if (form.ages.value == "") {
		alert("What are the approx ages of those travelling? is a required field.");
		form.ages.focus();
		return false;
	}
	if (form.how_long.value == "") {
		alert("How much time do you have? is a required field.");
		form.how_long.focus();
		return false;
	}

	/* Check countries checkbox */	
	var itemsChecked = checkArray(form, "countries[]"); 
	if (itemsChecked.length < 1) { 
		alert("Which countries are you interested in visiting? is a required field.");
		return false; 
	} 
	
	return true;
	
}