// JavaScript Document
function isEmailAddr (s){ 
	var rv = false
	if ((s == null) || (s.length == 0)){ 
       	rv = false;
 	}else{
		var reEmail =/([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		//reEmail = /.+\@.+\..+$/
		
		rv = reEmail.test(s)
    }
	if(rv){
		return rv
	}else{
		return false
	}
}

function validateRadio(theRadio){
	// set var radio_choice to false
	var radio_choice = false;

	// Loop from zero to the one minus the number of radio button selections
	for (counter = 0; counter < theRadio.length; counter++){
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (theRadio[counter].checked){
			radio_choice = true; 
			strRadioValue = theRadio[counter].value;
		}
	}
	if(!radio_choice){
		return (false);
	}
	    return (true);
}

function validateSelect(selectbox){
	var iSelect = selectbox.options[selectbox.selectedIndex].value ;
	if(iSelect == 0){
		return false;
	}else{
		return true;
	}
}

function validation(theForm){
	if (theForm.first_name.value == ""){
    	alert("Please enter your first name.");
    	theForm.first_name.focus();
    	return (false);
  	}
	if (theForm.last_name.value == ""){
    	alert("Please enter your last name.");
    	theForm.last_name.focus();
    	return (false);
  	}	
	if (theForm.mailing_address.value == ""){
    	alert("Please enter your mailing address.");
    	theForm.mailing_address.focus();
    	return (false);
  	}
	if (theForm.town.value == ""){
    	alert("Please enter your town.");
    	theForm.town.focus();
    	return (false);
  	}
	if (theForm.phone.value == ""){
    	alert("Please enter your phone number.");
    	theForm.phone.focus();
    	return (false);
  	}
  	if (!isEmailAddr(theForm.email.value)){
    	alert("Please enter a complete email address in the form: yourname@yourdomain.com");
    	theForm.email.focus();
    	return (false);
 	}
	if (!validateRadio(theForm.age_bracket)){
		alert("Please select a age bracket."); 
		theForm.age_bracket[0].focus();
		return false;
	}
	if (theForm.how_did_you_hear_about_fashions_on_the_field.value == ""){
    	alert("Please tell us how did you hear about fashions on the field.");
    	theForm.how_did_you_hear_about_fashions_on_the_field.focus();
    	return (false);
  	}
	if (!theForm.yes_i_agree_to_criteria.checked){
    	alert("Please make sure you read and understand these criteria and agree to abide by them, please check the box.");
    	theForm.yes_i_agree_to_criteria.focus();
    	return (false);
 	}
	
	return (true);
}

function validation_enquiry(theForm){
	if (theForm.name.value == ""){
    	alert("Please enter your name.");
    	theForm.name.focus();
    	return (false);
  	}
  	if (!isEmailAddr(theForm.email.value)){
    	alert("Please enter a complete email address in the form: yourname@yourdomain.com");
    	theForm.email.focus();
    	return (false);
 	}	
	if (theForm.your_query.value == ""){
    	alert("Please enter your query.");
    	theForm.your_query.focus();
    	return (false);
  	}
	
	return (true);
}