// JavaScript Document
/**
 * Evaluate and validate the supplied form.
 * Anything required in the contact form that 
 * was left empty by the user will be added to 
 * an array and then echoed back in an alert box,
 * alerting the user that they must fill out
 * said boxes
 *
 * Otherwise the form is submitted.
 */
 
function validate(formID){
	var target = document.getElementById(formID);
	var a = new Array();

	//Finance form validation
	if(formID == 'financeForm'){
		if ( target.firstName.value == "" )
			a.push('First Name');
		if ( target.lastName.value == "" )
			a.push('Last Name');
		if ( target.address.value == "" )
			a.push('Street Address');
		if ( target.city.value == "" )
			a.push('City');
		if ( target.state.value == "" )
			a.push('State');
		if ( target.dob1.value == "" || target.dob2.value == "" || target.dob3.value == "" )
			a.push('Date Of Birth');
		if ( target.cel1.value == "" || target.cel2.value == "" || target.cel3.value == "" )
			a.push('Home or Cell Phone Number');
		if ( target.ssn1.value == "" || target.ssn2.value == "" || target.ssn3.value == "" )
			a.push('Social Security Number');
		if ( target.income.value == "" )
			a.push('Monthly Income');
		if ( target.email.value == "" )
			a.push('E-mail Address');
	}
	
	else if(formID == 'contactForm'){
		if ( target.firstName.value == "" )
			a.push('First Name');
		if ( target.lastName.value == "" )
			a.push('Last Name');
		if ( target.email.value == "" )
			a.push('Email Address');
		if ( target.phone.value == "" )
			a.push('Day Phone');
	}
	
	else if(formID == 'footerContactForm'){
		if ( target.firstLastName.value == "" )
			a.push('First And Last Name');
		if ( target.phone.value == "" )
			a.push('A Contact Phone Number');
		if ( target.comments.value == "" )
			a.push('You Forgot To Ask Something!');
	}
	
	else if(formID == 'inventoryContact'){
		if ( target.firstLastName.value == "" )
			a.push('First Name');
		if ( target.email.value == "" )
			a.push('E-mail Address');
		if ( target.phone.value == "" )
			a.push('Daytime Phone Number');
	}
	
	else{
		if ( target.firstName.value == "" )
			a.push('First Name');
		if ( target.lastName.value == "" )
			a.push('Last Name');
		if ( target.email.value == "" )
			a.push('E-mail Address');
		if ( target.phone.value == "" )
			a.push('Phone Number');
	}
	
	if(a.length){
		var str = 'We are sorry, but you have failed to enter information into the following required fields:\n\n';
		
		for(i = 0; i < a.length; i++){
			str += '-' + a[i] + '\n';
		}
		str += '\nPlease fill in the above fields and try submitting your information again.';
		alert(str);
	}
	else
		target.submit();
	
} // end function validateFinanceForm()
