// JavaScript Document

function validateForm(){
	formValid = 'true';
	msgs = '';
	
	fName = $("#firstName").val();
	lName = $("#lastName").val();
	address = $("#add1").val();
	city = $("#city").val();
	state = $("#state").val();
	zip = $("#zip").val();
	phone = $("#phone").val();
	email = $("#email").val();
	
	if(fName.trim() == ''){
		formValid = 'false';	
		msgs += "*First name cannot be empty.<br/>";
	}
	if(lName.trim() == ''){
		formValid = 'false';	
		msgs += "*Last name cannot be empty.<br/>";
	}
	if(address.trim() == ''){
		formValid = 'false';
		msgs += "*Address field cannot be empty.<br/>";
	}
	if(city.trim() == ''){
		formValid = 'false';
		msgs += "*City field cannot be empty.<br/>";
	}
	if(state.trim() == ''){
		formValid = 'false';
		msgs += "*State/Province field cannot be empty.<br/>";
	}
	if(zip.trim() == ''){
		formValid = 'false';
		msgs += "*Zip Code field cannot be empty.<br/>";
	}
	if(phone.trim() == ''){
		formValid = 'false';
		msgs += "*Phone field cannot be empty.<br/>";
	}
	if(email.trim() == ''){
		formValid = 'false';
		msgs += "*E-Mail address field cannot be empty.<br/>";
	}
	
	if(formValid == 'true'){
		return true;
	}
	else{
		$("#formErrors").html("<span style='font-weight:bold;text-decoration:underline;'>Form not submitted, following errors occurred:</span><br />"+msgs);
		return false;	
	}
}

String.prototype.trim = function () {
  return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};
