
var ERRORCOLOR="lightpink"; 
var SENTCOLOR="lightblue";

		$(document).ready(function()
		{
			
			 $("input").click(function () { 
      $(this).css("background-color","white");
	  });
	  
	  			 $("select").click(function () { 
      $(this).css("background-color","white");
	  });
	 			 $("textarea").click(function () { 
      $(this).css("background-color","white");
    });
	
		 

});
	
	
		function messageSent(sss){
		 $("#sentError").empty();
		 $("#sentError").css("background-color","white");
		 $("#sentError").append(sss).show();
		 $("#sentError").animate( {backgroundColor:SENTCOLOR}, 600);
		}

		
		function errInForm(sss){
		 $("#sentError").empty();
		 $("#sentError").css("background-color","white");
		 $("#sentError").append(sss).show();
		 $("#sentError").animate( {backgroundColor:ERRORCOLOR}, 600);
		}
		
		function validateForm(){
		    
			hideErrors();
			
			var fname = $("#fname").val();
			var lname = $("#lname").val();
			var address1 =$("#address1").val();
			var city = $("#city").val();
			var state=$("#state").val();
			var zip=$("#zip").val();
			var emailcheck = $("#email").val();
			var phonecheck = $("#phone").val();
			
		
			if (fname == null || fname == '') {
				errInForm("Your first name is required");
				$("#fname").animate( {backgroundColor:ERRORCOLOR}, 1000);
				return false;
			}
			
			if (lname == null || lname == '') {
				errInForm("Your last name is required");
				$("#lname").animate( {backgroundColor:ERRORCOLOR}, 1000);
				return false;
			}

/*			
			if (address1 == null || address1 == '') {
                errInForm("Your address is required");
                $("#address1").animate( {backgroundColor:ERRORCOLOR}, 1000);
                return false;
            }
			

            if (city == null || city == '') {
                errInForm("Your city is required");
                $("#city").animate( {backgroundColor:ERRORCOLOR}, 1000);
                return false;
            }

            if (state=="XX") {
                errInForm("Your state is required");
                $("#state").animate( {backgroundColor:ERRORCOLOR}, 1000);
                return false;
            }

            if (zip == null || zip == '') {
                errInForm("Your zip is required");
                $("#zip").animate( {backgroundColor:ERRORCOLOR}, 1000);
                return false;
            }
*/			
			
			if (emailcheck == null || emailcheck == '') {
                errInForm("Your email is required");
                $("#email").animate( {backgroundColor:ERRORCOLOR}, 1000);
                return false;				
			}
			
			if(!isValidEmail(emailcheck))
			{
			    errInForm("Your email is not valid.");
                $("#email").animate( {backgroundColor:ERRORCOLOR}, 1000);
                return false;		
			}
/*		
			if (phonecheck == null || phonecheck == '') {
                errInForm("Your daytime phone number is required");
                $("#phone").animate( {backgroundColor:ERRORCOLOR}, 1000);
                return false;				
			}
*/		
			
            //message can be sent!
	        //messageSent("Thank you! We will be in touch with you shortly.")		
			return true;	   
		}		
		
		function hideErrors()  
		{
		 //hide error containers
		 $("#sentError").empty().hide();

         //return background colors
         $("#fname").css("background-color","white");
         $("#lname").css("background-color","white");
         $("#address1").css("background-color","white");
         $("#city").css("background-color","white");
         $("#state").css("background-color","white");
         $("#zip").css("background-color","white");	
		 $("#email").css("background-color","white");
         $("#phone").css("background-color","white");	
		}
		

		function isValidEmail(strEmail){
           validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
           strEmail = document.forms[0].email.value;
           if (strEmail.search(validRegExp) == -1) 
           {return false;} 
           return true; 
       }




		
		function validateForm2(){
		    
			hideErrors2();
			
			var age = $("#age").val();
			var gender = $("#gender").val();
			var state=$("#state").val();
			var grapevine=$("#grapevine").val();
			var lookback=$("#lookback").val();

	    if (age == null || age == '') {
                errInForm("Your age is required");
                $("#age").animate( {backgroundColor:ERRORCOLOR}, 1000);
                return false;
            }


            if (gender=="XX") {
                errInForm("Your gender is required");
                $("#gender").animate( {backgroundColor:ERRORCOLOR}, 1000);
                return false;
            }	
		



            if (state=="XX") {
                errInForm("Your state of residence is required");
                $("#state").animate( {backgroundColor:ERRORCOLOR}, 1000);
                return false;
            }

		
	            if (grapevine=="XX") {
                errInForm("Please let us know how you heard about this survey.");
                $("#grapevine").animate( {backgroundColor:ERRORCOLOR}, 1000);
                return false;
            }		

	    if (lookback == null || lookback == '') {
                errInForm("Please fill in a message for us.");
                $("#lookback").animate( {backgroundColor:ERRORCOLOR}, 1000);
                return false;
            }
		
			
            //message can be sent!
	
			return true;	   
		}		
		
		function hideErrors2()  
		{
		 //hide error containers
		 $("#sentError").empty().hide();

         //return background colors
         $("#age").css("background-color","white");
         $("#gender").css("background-color","white");
         $("#state").css("background-color","white");
         $("#grapevine").css("background-color","white");
         $("#lookback").css("background-color","white");		
		}

		
		