var v = true;
var sp = "slow";
function validateForm() {
	v = true;
	$(".required").trigger("validate");
	if (v && document.getElementById("tos")) {
		if (document.getElementById("tos").checked) {
			ShowExitPopup = false;
			return true;
		} else {
			alert("Please click checkbox to agree to the SpyBubble Terms and Conditions of use.");
			return false;
		}
	}
	if (v) {
		ShowExitPopup = false;
	} else {
		document.getElementById("txtUserName").focus();
	}
	return v;
}
$(document)
		.ready(
				function() {
					if ($("#txtUserName").val().length <= 0)
						$("#txtUserName").focus();
					$(".RQR").addClass("required");
					$(".RQR").focus(
							function() {
								var x = $(this).addClass("focus").removeClass(
										"missing").next();
								x.find(".missing").hide().text("");
								x.find(".tip").fadeIn(sp);
							});
					$(".RQR").blur(function() {
						$(this).removeClass("focus").trigger("validate");
					});
					$("select.dropdownmenu").focus(function() {
						$(this).addClass("focus");
					}).blur(function() {
						$(this).removeClass("focus");
					});
					$("#txtContEmail")
							.bind(
									"validate",
									function() {
										var _v = true;
										var m = "";
										this.value = this.value.replace(/\s/g,
												"");
										if (this.value.length <= 0) {
											m = this.title;
											_v = false;
										} else if (this.value.length > this.maxlength) {
											m = "Please use less than "
													+ this.maxlength
													+ " characters.";
											_v = false;
										} else if (!this.value
												.match(/^[a-zA-Z0-9'\-_]+(?:[\.][a-zA-Z0-9'\-_]+)*@([a-zA-Z0-9]([-]?[a-zA-Z0-9_])*\.)*[a-zA-Z0-9]([-]?[a-zA-Z0-9]){0,61}[a-zA-Z0-9]{0,1}\.[a-zA-Z]{2,6}(\.[a-zA-Z]{2})?$/)) {
											m = " Invalid email address";
											_v = false;
										}
										$(this).removeClass("missing")
												.removeClass("RQR").next()
												.find(".missing").text("");
										if (!_v) {
											var x = $(this).addClass("missing")
													.next();
											x.find(".tip").hide();
											x.find(".missing").text(m).fadeIn(
													sp);
											v = _v;
										}
									});
					$(
							"#txtUserName,#password,#txtPass,#lastName,#manuf,#phone,#txtCaptcha,#oldpass")
							.bind(
									"validate",
									function() {
										var _v = true;
										var m = "";
										if (this.value.length <= 0) {
											m = this.title;
											_v = false;
										} else if (this.value.length > this.maxlength) {
											m = "Please use less than "
													+ this.maxlength
													+ " characters.";
											_v = false;
										}
										$(this).removeClass("missing")
												.removeClass("RQR").next()
												.find(".missing").text("");
										if (!_v) {
											var x = $(this).addClass("missing")
													.next();
											x.find(".tip").hide();
											x.find(".missing").text(m).fadeIn(
													sp);
											v = _v;
										} else if (this.id == "txtUserName") {
											$(this).trigger("check");
										}
										if (this.id == "txtPass"
												&& $("#txtPassConfirm")[0].value.length > 0)
											$("#txtPassConfirm").trigger(
													"validate");
									});
					$("#txtPassConfirm")
							.bind(
									"validate",
									function() {
										var _v = true;
										var m = "";
										if (this.value.length <= 0) {
											m = this.title;
											_v = false;
										} else if (this.value.length > this.maxlength) {
											m = "Please use less than "
													+ this.maxlength
													+ " characters.";
											_v = false;
										} else if (this.value.length > 0
												&& this.value != $("#txtPass")[0].value) {
											m = " Passwords do not match";
											_v = false;
										}
										$(this).removeClass("missing")
												.removeClass("RQR").next()
												.find(".missing").text("");
										if (!_v) {
											var x = $(this).addClass("missing")
													.next();
											x.find(".tip").hide();
											x.find(".missing").text(m).fadeIn(
													sp);
											v = _v;
										}
									});
					$("#txtComment")
							.bind(
									"validate",
									function() {
										var _v = true;
										var m = "";
										if (this.value.length <= 0) {
											m = this.title;
											_v = false;
										} else if (this.value.length > this.maxlength) {
											m = "Please use less than "
													+ this.maxlength
													+ " characters.";
											_v = false;
										} else if (this.value.length > 0
												&& this.value != $("#txtPass")[0].value) {
											m = " Passwords do not match";
											_v = false;
										}
										$(this).removeClass("missing")
												.removeClass("RQR").next()
												.find(".missing").text("");
										if (!_v) {
											var x = $(this).addClass("missing")
													.next();
											x.find(".tip").hide();
											x.find(".missing").text(m).fadeIn(
													sp);
											v = _v;
										}
									});
					$("#txtUserName").change(function() {
						if (this.value.length > 0) {
							$(this).attr("test", 1);
						}
					});
				});
