
	
$(document).ready(function() {

	function textareaLength(obj) {
	
		var text = $(obj).val();
		
		if ( text.length > 500 )
		{
			alert("Please limit your explanation to 500 or less characters.");
			
			$(obj).val( text.substring(0, text.length-1) );
		}
	}
	
	function checkInputs(obj, type, strTest) {
		
		var text = $.trim( $(obj).val() );
			
		if ( type == "regEx" ) 
		{
			if ( !strTest.test(text) )
			{
				$(obj).css("background-color","#F2EFEF");
				return false;
			}
			else { 
					$(obj).css("background-color","#FFFFFF");
					return true; 
			}
		}
		else if ( type == "string" )
		{
			if ( text == "" )
			{
				$(obj).css("background-color","#F2EFEF");
				return false;
			}	
			else { 
					$(obj).css("background-color","#FFFFFF");
					return true; 
			}
		}
		else if ( type == "select" )
		{
			if ( text == "Not Selected" )
			{
				$(obj).css("background-color","#F2EFEF");
				return false;
			}
			else { 
					$(obj).css("background-color","#FFFFFF");
					return true; 
			}
		}
		else
		{
			return false;
		}	
		
	} // function checkInputs
	


$("#quoteForm").submit(function() {

	var alertMsg = "";

	if ( checkInputs( $("select[name='aos']"), "select") == false ) { alertMsg = "Please select your Area of Service.\n"; }
	if ( checkInputs( $("select[name='code']"), "select") == false ) { alertMsg = alertMsg + "Please select your School Code.\n"; }
	if ( checkInputs( $("input[name='name']"), "string") == false ) { alertMsg = alertMsg + "Please enter your Name.\n"; }
	if ( checkInputs( $("input[name='orgname']"), "string") == false ) { alertMsg = alertMsg + "Please enter the name of your Organization.\n"; }
	if ( checkInputs( $("input[name='state']"), "regEx", /^[a-zA-Z]+$/) == false ) { alertMsg = alertMsg + "Please enter your State.\n"; }
	if ( checkInputs( $("input[name='email']"), "regEx",  /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/) == false ) { alertMsg = alertMsg + "Please enter a proper E-mail Address.\n"; }
	if ( checkInputs( $("input[name='phone']"), "regEx", /1?\W*([2-9][0-8][0-9])\W*([2-9][0-9]{2})\W*([0-9]{4})(\se?x?t?(\d*))?/) == false ) { alertMsg = alertMsg + "Please enter a valid Phone Number.\n"; }
	
	if ( alertMsg == "" )
	{
		return true;

	}
	else{
		alert(alertMsg);
		return false;
	}

});
	

$('textarea[name="comments"]').keyup(function(){
{
		textareaLength(this);
}
});

	
	

});

