//Email Validation Script
			function validateEmail(strng) {
				var email_error=false;
  				var emailFilter=/^.+@.+\..{2,3}$/;
  				if (!(emailFilter.test(strng))) { 
					email_error = true;
 				} 
				else {
    			//test email for illegal characters
   					var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
   					if (strng.match(illegalChars)) {	  
					 	email_error = true;
    				}
  				}
 				return email_error;    
			}
//Phone Validation Script
			function validatePhone (strng, fieldname) {
  				var phone_error = false;
 				var stripped = strng.replace(/[\(\)\.\+\/\-\ ]/g, ''); //strip out acceptable non-numeric characters
  				if (isNaN(parseInt(stripped))) {
					phone_error = true;
  				}
  				if (!(stripped.length >= 10)) {
					phone_error = true;
  				} 
				if(phone_error == true){
					alert('Please enter a 10 digit phone number');	
				}
  				return phone_error;
			}
//jQuery code to validate the form
$(window).bind("load", function() { 	
	//Set up the information for the form you would like validated
	var form_id_top = $('#gform_wrapper_2 form').attr("id");
	var form_id_top2 = $('#gform_wrapper_3 form').attr("id");
	var form_text_color = '#585858';
	//Set all default values for the form you are validating
	var myDefaultValues = new Array("Name: ","Email: ", "Website name: ", "Website URL: ", "Site description: ", "Email Address");
	$('form#'+form_id_top).submit(function(){ 
		var form_error = validateForm(form_id_top);
		if(form_error == false){
			return false;	
		}
		else{
			return true;	
		}
	});
	$('form#'+form_id_top2).submit(function(){ 
		var form_error = validateForm(form_id_top2);
		if(form_error == false){
			return false;	
		}
		else{
			return true;	
		}
	});
function validateForm(formID){
//check every input in the form to make sure all fields have been filled in and there are no empty fields.
		var error = '';
		var form_id = formID;
		$('form#'+form_id+' .gform_body ul li').each(function(){
			var defaultValue = '';
			var i = 0;
			var li_id = $(this).attr("id");
			var li_class = $(this).attr("class");
			if(li_id != 'field_2_6' && li_id != 'field_2_5' && li_id != ''){
				var input_id = $('#'+li_id+' input').attr("id");
				var input_value = $('#'+li_id+' input#'+input_id).val();
			}
			//Add the class 'email' to an email field on the form
			if(li_class == 'gfield    email'){
				var email_error = validateEmail(input_value);
				if(email_error == true){
					$('input#'+input_id).css({'color': 'red'});
					$('li#'+li_id+' label').css({'color': 'red'});
					error += 'email error';	
				}
				else{
					$('input#'+input_id).css({'color': form_text_color});
					$('li#'+li_id+' label').css({'color': form_text_color});	
				}
			}
			//add the class 'phone' to a phone field on the form
			else if(li_class == 'gfield    phone'){
				var phone_error = validatePhone(input_value);
				if(phone_error == true){
					$('input#'+input_id).css({'color': 'red'});
					$('li#'+li_id+' label').css({'color': 'red'});
					error += 'phone error';	
				}
				else{
					$('input#'+input_id).css({'color': form_text_color});
					$('li#'+li_id+' label').css({'color': form_text_color});	
				}	
			}
			//add the class 'required-input' to any required fields
			else if(li_class == 'gfield    required-input'){
			//input values against the known list of default values
			for(i=0;i<myDefaultValues.length;i++){
				defaultValue = myDefaultValues[i];
//if there is a match or an empty field is found change the text of the default value or the label red.
				if(input_value == defaultValue || input_value == ''){
					$('input#'+input_id).css({'color': 'red'});
					$('li#'+li_id+' label').css({'color': 'red'});
					error += 'error#'+i;
					break;
				}
				else{
					$('input#'+input_id).css({'color': form_text_color});
					$('li#'+li_id+' label').css({'color': form_text_color});
				}
//if the field has passed the test turn the text of the value and the label black.
			}
			}
			else{}
		});
			//in case there was any errors do not submit the form
			if(error != ''){
				return false;	
			}
			else{
				return true;	
			}
  		
	}
});
