// JavaScript Document
function goTo(eq) {
	if(chicken != "happy") {
		$(".sheetss").hide()
		$(".sheetss:eq(" + eq + ")").fadeIn();
	}
}

//*Change form name in email validate function

/*Common Validation Fields*/

function validate_company_name(val) {
	var short = "#mes_company_name";
	$(short).html("");
	if(val.length < 5) {
		goTo(0);
		$(short).html("*Please enter your company's full name. Must be at least five characters");
		return false;
	} else if(val.indexOf("  ") > -1) {
		goTo(0);
		$(short).html("*Please do not enter consecutive spaces");
		return false;
	} else if(isRepeated(val) == true) {
		$(short).html("*Please do not enter repeated characters");
		return false;
	}
}

function validate_name(val) {
	var short = "#mes_name";
	$(short).html("");
	if(val.length < 8) {
		$(short).html("*Please enter your full name. Must be at least eight characters");
		return false;
	} else if(val.indexOf("  ") > -1) {
		$(short).html("*Please do not enter consecutive spaces");
		return false;
	} else if(isRepeated(val) == true) {
		$(short).html("*Please do not enter repeated characters");
		return false;
	}
}

function validate_phone(val) {
	var short = "#mes_phone";
	$(short).html("");	
	if(val.length != 10 && val.indexOf("-") < 0) {
		goTo(0);
		$(short).html("*Please enter your ten digit phone number");
		return false;
	} else if(val.indexOf(" ") > -1 || val.indexOf("-") > -1) {
		goTo(0);
		$(short).html("*Please do not enter any spaces or dashes for this field");
		return false;
	} else if(isRepeatedd(val) == true) {
		goTo(0);
		$(short).html("*Please do not enter repeated characters");
		return false;
	} else if(IsNumeric(val) == false) {
		goTo(0);
		$(short).html("*Please enter only numbers no dashes or other characters");
		return false;
	}
}

function validate_address(val) {
	var short = "#mes_address";
	$(short).html("");	
	if(val.length < 8) {
		goTo(0);
		$(short).html("*Please type in a valid address consisting of at least eight characters.");
		return false;
	} else if(isRepeated(val) == true) {
		goTo(0);
		$(short).html("*Please do not enter repeated characters");
		return false;
	} else if(val.indexOf("  ") > -1) {
		goTo(0);
		$(short).html("*Please do not enter consecutive spaces");
		return false;
	}
}

function validate_email(val) {
	var short = "#mes_email";
	$(short).html("");
	if(val.length < 6) {
		goTo(0);
		$(short).html("*Please enter a valid email address with at least six characters");
		return false;
	} else if(isRepeated(val) == true) {
		goTo(0);
		$(short).html("*Please do not enter repeated characters");
		return false;
	} else if(val.indexOf("  ") > -1) {
		goTo(0);
		$(short).html("*Please do not enter consecutive spaces");
		return false;
	} else if(isEmail(val) == false) {
		goTo(0);
		$(short).html("*Please enter a valid email");
		return false;
	}
}

function validate_password(val) {
	var short = "#mes_password";
	$(short).html("");	
	if(val.length < 8) {
		$(short).html("*Please enter an eight digit password.");
		return false;
	} else if(val.indexOf("  ") > -1) {
		$(short).html("*Please do not enter repeated spaces");
		return false;
	}
}

function validate_username(val) {
	var short = "#mes_username";
	$(short).html("");
	if(val.length < 8) {
		$(short).html("*Please enter an eight character username.");
		return false;
	} else if(isRepeated(val) == true) {
		$(short).html("*Please do not enter repeated characters.");
		return false;
	} else if(val.indexOf("  ") > -1) {
		$(short).html("*Please do not enter consecutive spaces");
		return false;
	}
}

function validate_first_name(val) {
	var short = "#mes_first_name";
	$(short).html("");
	if(val.length < 3) {
		goTo(0);
		$(short).html("*Please enter your first name");
		return false;
	} else if(isRepeated(val) == true) {
		goTo(0);
		$(short).html("*Please do not enter repeated characters");
		return false;
	} else if(val.indexOf("  ") > -1) {
		goTo(0);
		$(short).html("*Please do not enter consecutive spaces");
		return false;
	}
}

function validate_last_name(val) {
	var short = "#mes_last_name";
	$(short).html("");
	if(val.length < 4) {
		goTo(0);
		$(short).html("*Please enter your last name");
		return false;
	} else if(isRepeated(val) == true) {
		goTo(0);
		$(short).html("*Please do not enter repeated characters");
		return false;
	} else if(val.indexOf("  ") > -1) {
		goTo(0);
		$(short).html("*Please do not enter consecutive spaces");
		return false;
	}
}

function validate_message(val) {
	var short = "#mes_message";
	$(short).html("");
	if(val.length < 10) {
		$(short).html("*Please enter a message at least ten characters long.");
		return false;
	} else if(isRepeated(val) == true) {
		$(short).html("*Please do not enter repeated characters");
		return false;
	} else if(val.indexOf("  ") > -1) {
		$(short).html("*Please do not enter consecutive spaces");
		return false;
	}
}

function validate_subject(val) {
	var short = "#mes_subject";
	$(short).html("");
	if(val.length < 4) {
		$(short).html("*Please enter a subject");
		return false;
	} else if(isRepeated(val) == true) {
		$(short).html("*Please do not enter repeated characters");
		return false;
	} else if(val.indexOf("  ") > -1) {
		$(short).html("*Please do not enter consecutive spaces");
		return false;
	}
}

function validate_zip(val) {
	var short = "#mes_zip";
	$(short).html("");
	if(val.length != 5) {
		goTo(0);
		$(short).html("*Please enter your 5 digit zip code.");
		return false;
	} else if(isRepeated(val) == true) {
		goTo(0);
		$(short).html("*Please do not enter repeated characters");
		return false;
	} else if(val.indexOf(" ") > -1) {
		goTo(0);
		$(short).html("*Please do not enter any spaces");
		return false;
	} else if(IsNumeric(val) == false) {
		goTo(0);
		$(short).html("*Please enter only numbers no dashes or other characters");
		return false;
	}
}

function validate_best_time_of_day(val) {
	var short = "#mes_best_time_of_day";
	$(short).html("");
	if(val.length < 2) {
		$(short).html("*Please select the best time to call.");
		return false;
	}
}

function validate_hear_about_us(val) {
	var short = "#mes_hear_about_us";
	$(short).html("");
	if(val.length < 2) {
		$(short).html("*Please select the method your heard about us.");
		return false;
	}
}

//*********************new validations*********************************************************
function validate_business_desc(val) {
	var short = "#mes_business_desc";
	$(short).html("");
	if(val.length < 10) {
		goTo(0);
		$(short).html("*Please enter a message at least ten characters long.");
		return false;
	} else if(isRepeated(val) == true) {
		goTo(0);
		$(short).html("*Please do not enter repeated characters");
		return false;
	} else if(val.indexOf("  ") > -1) {
		goTo(0);
		$(short).html("*Please do not enter consecutive spaces");
		return false;
	}
}

function validate_project_desc(val) {
	var short = "#mes_project_desc";
	var eq = 1;
	$(short).html("");
	if(val.length < 10) {
		goTo(eq);
		$(short).html("*Please enter a message at least ten characters long.");
		return false;
	} else if(isRepeated(val) == true) {
		goTo(eq);
		$(short).html("*Please do not enter repeated characters");
		return false;
	} else if(val.indexOf("  ") > -1) {
		goTo(eq);
		$(short).html("*Please do not enter consecutive spaces");
		return false;
	}
}

function validate_menu_items(val) {
	var short = "#mes_menu_items";
	var eq = 2;
	$(short).html("");
	if(val.length < 6) {
		goTo(eq);
		$(short).html("*Please enter valid menu items with at least six characters");
		return false;
	} else if(val.indexOf("---") > -1) {
		goTo(eq);
		$(short).html("*Please respond to the question");
		return false;
	} else if(isRepeated(val) == true) {
		goTo(eq);
		$(short).html("*Please do not enter repeated characters");
		return false;
	} else if(val.indexOf("  ") > -1) {
		goTo(eq);
		$(short).html("*Please do not enter consecutive spaces");
		return false;
	}  else if(val.indexOf(",") < 0) {
		goTo(eq);
		$(short).html("*Please enter more than one page, separated by a comma");
		return false;
	}
}

function validate_three_sites(val, eqq) {
	var short = "#mes_three_sites";
	var eq = 2;
	$(short).html("");
	if(val.length < 12) {
		goTo(eq);
		$(short).html("*Please enter valid website urls with at least twelve characters");
		$(".three_sites").eq(eqq).focus();
		return false;
	} else if(val.indexOf("---") > -1) {
		goTo(eq);
		$(short).html("*Please respond to the question");
		$(".three_sites").eq(eqq).focus();
		return false;
	} else if(val.indexOf("  ") > -1) {
		goTo(eq);
		$(".three_sites").eq(eqq).focus();
		$(short).html("*Please do not enter consecutive spaces");
		return false;
	} else if(IsWeb(val) == false) {
		goTo(eq);
		$(".three_sites").eq(eqq).focus();
		$(short).html("*Please enter a valid web address like ");
		$(".three_sites").eq(eqq).val("---http://www.tehgol.com");
		return false;
	}
}

function validate_three_sites_why(val, eqq) {
	var short = "#mes_three_sites";
	var eq = 2;
	$(short).html("");
	if(val.length < 6) {
		goTo(eq);
		$(short).html("*Please enter valid reasons why you like the sites with at least six characters");
		$(".three_sites_why").eq(eqq).focus();
		return false;
	} else if(val.indexOf("---") > -1) {
		goTo(eq);
		$(short).html("*Please respond to the question");
		$(".three_sites_why").eq(eqq).focus();
		return false;
	} else if(val.indexOf("  ") > -1) {
		goTo(eq);
		$(".three_sites_why").eq(eqq).focus();
		$(short).html("*Please do not enter consecutive spaces");
		return false;
	} 
}

function validate_color_pref(val, eqq) {
	var short = "#mes_color_pref";
	var eq = 2;
	$(short).html("");
	if(val.indexOf("rgb") < 0) {
		goTo(eq);
		$(".color_pref").eq(eqq).focus();
		$(short).html("*Please use the color picker to select a color");
		return false;
	}
}

function validate_graphics_desc(val) {
	var short = "#mes_graphics_desc";
	var eq = 2;
	$(short).html("");
	if(val.length < 10) {
		goTo(eq);
		$(short).html("*Please enter a message at least ten characters long.");
		return false;
	} else if(isRepeated(val) == true) {
		goTo(eq);
		$(short).html("*Please do not enter repeated characters");
		return false;
	} else if(val.indexOf("  ") > -1) {
		goTo(eq);
		$(short).html("*Please do not enter consecutive spaces");
		return false;
	}
}
/*Common Validation Fields End Here*/

//function validate() {
//	if(validate_name($("#name").val()) == false) { return false };
//	if(validate_phone($("#phone").val()) == false) { return false };
//	if(validate_email($("#email").val()) == false) { return false };
//	if(validate_address($("#address").val()) == false) { return false };
//	if(validate_password($("#password").val()) == false) { return false };
//	if(validate_username($("#username").val()) == false) { return false };
//	if(validate_first_name($("#first_name").val()) == false) { return false };
//	if(validate_last_name($("#last_name").val()) == false) { return false };
//	if(validate_subject($("#subject").val()) == false) { return false };
//	if(validate_zip($("#zip").val()) == false) { return false };
//	if(validate_message($("#message").val()) == false) { return false };
//	if(validate_best_time_of_day($("#best_time_of_day").val()) == false) { return false };	
//	if(validate_hear_about_us($("#hear_about_us").val()) == false) { return false };	
//	return true;
//}

//extra functions
function isRepeated(val) {
	if (navigator.appName == "Microsoft Internet Explorer") {
		return false;	//give up on ie because it sucks . . . . leave it to php
	} else {
		for(var i = 0; i < val.length - 1; i++) {
			if(val[i] == val[i+1] && val[i] == val[i+2]) {
				return true;
			} 
		}		
	}
}

function isRepeatedd(val) {
	if(navigator.appName == "Microsoft Internet Explorer") {
		return false;	//give up on ie because it sucks . . . . leave it to php
	} else {
		for(var i = 0; i < val.length - 1; i++) {
			if(val[i] == val[i+1] && val[i] == val[i+2] && val[i] == val[i+3] && val[i] == val[i+4] && val[i] == val[i+5]) {
				return true;
			} 
		}	
	}
}


//
function IsNumeric(sText) {
   var ValidChars = "0123456789.";
   var IsNumber = true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) { 
 	  Char = sText.charAt(i); 
      if(ValidChars.indexOf(Char) == -1) {
         IsNumber = false;
       }
	}
   return IsNumber;
}

//

function isEmail(val) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(val) == false) {
      return false;
   }
}

function IsWeb(val) {
	var reg = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
   if(reg.test(val) == false) {
      return false;
   }
}
