// Javascript by Alexander Nietzen M... alex@webeditors.com
// Open Source

// validate the form area to make sure that they fill out all fields.
function VALIDATE_FORM_FIELDS() {
// Check for Required Fields




//make sure first name is more then just a space
if (document.validate.first_name.value.replace(/ /g,"") == "") {
        alert("REQUIRED Information is Missing \n Please enter your First Name");
        document.validate.first_name.focus();
        return false;
}

//make sure the last name is more then just a space
else if (document.validate.last_name.value.replace(/ /g,"") == "") {
        alert("REQUIRED Information is Missing \n Please enter your Last Name");
        document.validate.last_name.focus();
        return false;
}

//make sure the last name is more then just a space
else if (document.validate.agency.value.replace(/ /g,"") == "") {
        alert("REQUIRED Information is Missing \n Please enter your Agency's Name");
        document.validate.agency.focus();
        return false;
}

//make sure the last name is more then just a space
else if (document.validate.title.value.replace(/ /g,"") == "") {
        alert("REQUIRED Information is Missing \n Please enter your Title");
        document.validate.title.focus();
        return false;
}







//make sure address is more then just a space
else if (document.validate.street.value.replace(/ /g,"") == "") {
        alert("REQUIRED Information is Missing \n Please enter your Address");
        document.validate.street.focus();
        return false;
}

//make sure city is more then just a space
else if (document.validate.city.value.replace(/ /g,"") == "") {
        alert("REQUIRED Information is Missing \n Please enter your City");
        document.validate.city.focus();
        return false;
}

//make sure that the person checked what state there from
else if (document.validate.state.value.replace(/ /g,"") == "") {
        alert("REQUIRED Information is Missing \n   Please select your State");
        document.validate.state.focus();
        return false;
}

//make sure zip code is more then just a space
else if (document.validate.zip.value.replace(/ /g,"") == "") {
        alert("REQUIRED Information is Missing \n Please enter your Zip Code");
        document.validate.zip.focus();
        return false;
}

//make sure day phone is more then just a space
else if (document.validate.day_phone.value.replace(/ /g,"") == "") {
        alert("REQUIRED Information is Missing \n Please enter your Day Phone Number");
        document.validate.day_phone.focus();
        return false;
}

//make sure fax is more then just a space
else if (document.validate.fax.value.replace(/ /g,"") == "") {
        alert("REQUIRED Information is Missing \n Please enter your Fax Number");
        document.validate.fax.focus();
        return false;
}

//lets make sure the required email address field is even filled out first
else if (document.validate.email.value.replace(/ /g,"") == "") {
        alert("REQUIRED Information is Missing \n Please enter Email Address");
        document.validate.email.focus();
        return false;
}

//ensure they've put in orders are filled out
else if (document.validate.order_size.value.replace(/ /g,"") == "" && document.validate.renewal_size.value.replace(/ /g,"") == "") {
        alert("REQUIRED Information is Missing \n Please enter how many units you'd like to order.");
        document.validate.order_size.focus();
        return false;
}


// 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 < document.validate.admin_1.length; counter++)
{
// If a radio button has been selected it will return true
// (If not it will return false)
if (document.validate.admin_1[counter].checked)
radio_choice = true; 
if (document.validate.admin_1[counter].checked)
user_input = document.validate.admin_1[counter].value;
}

if (!radio_choice)
{
// If there were no selections made display an alert box 
alert("Please choose a Campus Administrator.");
document.validate.admin_1[0].focus();
return false;
}

else if(user_input == "No") {
	if (document.validate.admin_first_name.value.replace(/ /g,"") == "") {
        alert("REQUIRED Information is Missing \n Please enter your Campus Administrator's First Name");
        document.validate.admin_first_name.focus();
        return false;
	}
	else if (document.validate.admin_last_name.value.replace(/ /g,"") == "") {
        alert("REQUIRED Information is Missing \n Please enter your Campus Administrator's Last Name");
        document.validate.admin_last_name.focus();
        return false;
	}
	else if (document.validate.admin_email.value.replace(/ /g,"") == "") {
        alert("REQUIRED Information is Missing \n Please enter your Campus Administrator's E-mail");
        document.validate.admin_email.focus();
        return false;
	}
}

//check to make sure they selected a radio
//else if (document.validate.payment[0].checked == false && document.validate.payment[1].checked == false && document.validate.payment[2].checked == false && document.validate.payment[3].checked == false) {
//    alert(" Error: \n You didn't select a Payment Type\n Please select one");
//    document.validate.payment[0].focus();
//	if (window.scrollBy) window.scrollBy(0,-30);
//    return false;
//}

// lets define the valid e-mail address
    var email_pattern = /^[\w\-_\.]+@[\w\-\.]+\.[a-z]{2,7}$/i;
// checks for a word charachter or '-' one or more times followed by an '@' followed by [a-z] [A-Z] or [0-9] or '-' one or more times followed by a "." followed by a word character or "." one for more times.
    var email_result;
    email_result = email_pattern.exec(document.validate.email.value);

if (email_result) {
         // good to go!
         }
         else  {
         alert("Bad E-mail address! \n   Please try again.");
            document.validate.email.focus();
            return false;
      }
	  
if (user_input == "No") {
    var admin_email_result;
	admin_email_result = email_pattern.exec(document.validate.admin_email.value);
	if (admin_email_result) {
		// Do nothing
		}
		else {
		alert("Bad E-mail address. \n Please try again.");
			document.validate.admin_email.focus();
			return false;
		}
	}
	
	//Convert for passage

//for (var i = 0; i<document.validate.elements.length; i++) {
//	var replace_brs = document.validate.elements[i].value.replace(/(\n|\r)/g,'?br /?');
//	document.validate.elements[i].value = replace_brs;
//}

	return true;

}//close function
// WWW: http://www.mattkruse.com/
// Function to auto-tab phone field
// -------------------------------------------------------------------
//alert(document.validate.);

//-->


