// JavaScript Document

$(document).ready(function(){	
	/*$("#MemberManagementMenu").click(function() {
		$("#MemberManagementSubmenu").toggleClass("nodisplay");
	});
	$("#ReportMenu").click(function() {
		$("#ReportSubmenu").toggleClass("nodisplay");
	});
	$("#ViewMemberDeflist dt").addClass("alt");
	$("#ReportSubmenu h3").click(function() {
		alert("What reports would you like on this topic? Contact your system administrator.");
	});
	
	if ($("div#AccountNumberSubmenu:visible").length > 0 || $("div#EmailSubmenu:visible").length > 0 || $("div#PhoneSubmenu:visible").length > 0 || $("div#FullNameSubmenu:visible").length > 0) {
		$("#CheckInFormSubmit").removeAttr("disabled");
	}*//* else {
		$("#CheckInFormSubmit").disabled = true;	
	}*/
	
	//if clicking on checkin button, reset/hide fields/message divs
	/*$("#AccountNumberButton").click(function() {
		$("div.checkindiv input:text").val("");
		$("div.checkindiv:visible").toggleClass("nodisplay");
		$("#AccountNumberSubmenu").toggleClass("nodisplay");
		$("#CheckInStatus").remove();
		$("label.error").remove();
		$("#hidCheckInType").val("AccountNumber");
		$("#CheckInFormSubmit").removeAttr("disabled");
	});
	$("#EmailButton").click(function() {
		$("div.checkindiv input:text").val("");
		$("div.checkindiv:visible").toggleClass("nodisplay");
		$("#EmailSubmenu").toggleClass("nodisplay");
		$("#CheckInStatus").remove();
		$("label.error").remove();
		$("#hidCheckInType").val("Email");
		$("#CheckInFormSubmit").removeAttr("disabled");
	});
	$("#PhoneButton").click(function() {
		$("div.checkindiv input:text").val("");
		$("div.checkindiv:visible").toggleClass("nodisplay");
		$("#PhoneSubmenu").toggleClass("nodisplay");
		$("#CheckInStatus").remove();
		$("label.error").remove();
		$("#hidCheckInType").val("Phone");
		$("#CheckInFormSubmit").removeAttr("disabled");
	});
	$("#FullNameButton").click(function() {
		$("div.checkindiv input:text").val("");
		$("div.checkindiv:visible").toggleClass("nodisplay");
		$("#FullNameSubmenu").toggleClass("nodisplay");
		$("#CheckInStatus").remove();
		$("label.error").remove();
		$("#hidCheckInType").val("Name");
		$("#CheckInFormSubmit").removeAttr("disabled");
	});
	$("table#CheckInForm_ChooseMember input:radio[name='SelectedMember']").click(function() {
		$("#hidSearchResult").val("SingleMember");
		$("#CheckInFormSubmit").removeAttr("disabled");
	});
	//if multiple members found, hide inputs
	if ($("div#CheckInForm_MultipleMembers").length > 0) {
		$("div#CheckInForm_Main").addClass("nodisplay");
	}
	$("#CheckInFormReset").click(function(){
		$("div#CheckInForm_Main").removeClass("nodisplay");
		$("div#CheckInForm_MultipleMembers").remove();
		$("div#CheckInStatus").remove();
		$("#VisitType option:selected").removeAttr("selected");
		$("div.checkindiv:visible").toggleClass("nodisplay");
		//$("#hidSeachResult").val("");
		$("label.error").remove();
		$("#CheckInForm").clearForm();
		$("#hidResetForm").val("reset");
	});*/

/*	$("#CheckInFormReset").click(function(){
		window.location.href="http://localhost/nbadminroot/nbpos/pos.php";
	});*/
	
	/*$("#CheckInForm").validate({
		 errorPlacement: function(error, element) {
			 if (element.attr("name") == "PrimaryPhoneAreaCode")
			 		error.insertAfter("#PhoneSubmenu");
			 else if (element.attr("name") == "PrimaryPhonePrefix")
			 		error.insertAfter("#PhoneSubmenu");
			 else if (element.attr("name") == "PrimaryPhoneNumber")
			 		error.insertAfter("#PhoneSubmenu");*/
/*			 else if (element.attr("name") == "FirstName")
			 		error.insertAfter("#FullNameSubmenu");
			 else if (element.attr("name") == "LastName")
			 		error.insertAfter("#FullNameSubmenu");*/
			 /*else
			   error.insertAfter(element);
		  },

		 rules: {
			 FirstName: {required: "div#FullNameSubmenu:visible"},
			 LastName: {required: "div#FullNameSubmenu:visible"},
			 AccountNumber: {required: "div#AccountNumberSubmenu:visible",
			 	digits: true,
				minlength: 5,
				maxlength: 5
		 		},
			 PrimaryPhoneAreaCode: {required: "div#PhoneSubmenu:visible",
			 	digits: true,
				minlength: 3,
				maxlength: 3
				},
			 PrimaryPhonePrefix: {required: "div#PhoneSubmenu:visible",
			 	digits: true,
				minlength: 3,
				maxlength: 3
				},
			 PrimaryPhoneNumber: {required: "div#PhoneSubmenu:visible",
			 	digits: true,
				minlength: 4,
				maxlength: 4
				},
			 Email: {required: "div#EmailSubmenu:visible"},
			 VisitType: {required: function() {
				 $("#hidResetForm").val() != "reset";
			 	}
			 }
		 },
		 messages: {
			 AccountNumber: "Please enter a five-digit account number, or swipe member's club card.",
			 FirstName: "Please enter your first name.",
			 LastName: "Please enter your last name.",
			 Email: "Please enter a valid email address.",
			 PrimaryPhoneAreaCode: "Please enter your primary phone area code.",
			 PrimaryPhonePrefix: "Please enter your primary phone prefix.",
			 PrimaryPhoneNumber: "Please enter your primary phone number.",
			 VisitType: "Please select the type of visit.<br />If Other, please explain in the textbox below."
		 }
	});
	$("#FormErrorDialog").dialog({
				modal: true,
				buttons: {
					Ok: function() {
					$(this).dialog('close');
					}},
				autoOpen: false,
				title: 'Noteable Blends'
	});
	$("#CheckInFormSubmit").click(function() {
			if (!$("#CheckInForm").valid()){
				//$(document).scrollTop(250);
				$("#FormErrorDialog").dialog("open");
			} else {
				$("#js_validated").value = true;	
			}
	});*/
	$("form#LogLinkForm span#LogOutLink").click(function() {
		$("form#LogLinkForm").submit();
	});
	$.validator.addMethod("matchNewPassword2", function (value, element) {
		return this.optional(element) || (value == $("input#NewPassword2").val());
	}, "New passwords must match.");
	$.validator.addMethod("matchNewPassword1", function (value, element) {
		return this.optional(element) || (value == $("input#NewPassword1").val());
	}, "New passwords must match.");
	function clearLoginForm() {
		//make sure same radio button remains checked
		var loginTypes = new Array();
		var loginType = $("div#LoginTypeGroup input:radio:checked").val();
		$("form#LoginForm").clearForm();
		$("form#LoginForm label.error").remove();
		loginTypes[0] = loginType;
		$("div#LoginTypeGroup input:radio").val(loginTypes);
	}
	/*$("input#LoginFormClear").click( function() {
		//make sure same radio button remains checked
		var loginTypes = new Array();
		var loginType = $("div#LoginTypeGroup input:radio:checked").val();
		$("form#LoginForm").clearForm();
		$("form#LoginForm label.error").hide();
		loginTypes[0] = loginType;
		$("div#LoginTypeGroup input:radio").val(loginTypes);
	});*/
	//show or hide fields based on radio button selection
	
	$("input#LoginFormClear").click( function() {
		var isLoggedIn = $("input#IsLoggedIn").val();
		clearLoginForm();
		$("input#IsLoggedIn").val(isLoggedIn);
	});
	$("input#LoginType_Login").click( function() {
		$("form#LoginForm label.error").remove();
		$("h2.errorServerSide").remove();
		$("div#UsernamePasswordGroup").removeClass("nodisplay");
		$("div#NewUsername").addClass("nodisplay");
		$("div#NewPasswordGroup").addClass("nodisplay");
		$("div#ForgotUsernamePassword").addClass("nodisplay");
		//comment out next line to force re-login--uncomment top of php script
		var isLoggedIn = $("input#IsLoggedIn").val();
		clearLoginForm();
		//comment out next line to force re-login--uncomment top of php script
		$("input#IsLoggedIn").val(isLoggedIn);
	});
	$("input#LoginType_ChangeUsername").click( function() {
		$("form#LoginForm label.error").remove();
		$("h2.errorServerSide").remove();
		if ($("input#IsLoggedIn").val() == true){
			$("div#UsernamePasswordGroup").addClass("nodisplay");
		} else {
			$("div#UsernamePasswordGroup").removeClass("nodisplay");
		}
		$("div#NewUsername").removeClass("nodisplay");
		$("div#NewPasswordGroup").addClass("nodisplay");
		$("div#ForgotUsernamePassword").addClass("nodisplay");
		//comment out next line to force re-login--uncomment top of php script
		var isLoggedIn = $("input#IsLoggedIn").val();
		clearLoginForm();
		//comment out next line to force re-login--uncomment top of php script
		$("input#IsLoggedIn").val(isLoggedIn);
	});
	$("input#LoginType_ChangePassword").click( function() {
		$("form#LoginForm label.error").remove();
		$("h2.errorServerSide").remove();
		if ($("input#IsLoggedIn").val() == true){
			$("div#UsernamePasswordGroup").addClass("nodisplay");
		} else {
			$("div#UsernamePasswordGroup").removeClass("nodisplay");
		}
		$("div#NewUsername").addClass("nodisplay");
		$("div#NewPasswordGroup").removeClass("nodisplay");
		$("div#ForgotUsernamePassword").addClass("nodisplay");
		//comment out next line to force re-login--uncomment top of php script
		var isLoggedIn = $("input#IsLoggedIn").val();
		clearLoginForm();
		//comment out next line to force re-login--uncomment top of php script
		$("input#IsLoggedIn").val(isLoggedIn);
	});
	$("input#LoginType_Forgot").click( function() {
		$("form#LoginForm label.error").remove();
		$("h2.errorServerSide").remove();
		$("div#UsernamePasswordGroup").addClass("nodisplay");
		$("div#NewUsername").addClass("nodisplay");
		$("div#NewPasswordGroup").addClass("nodisplay");
		$("div#ForgotUsernamePassword").removeClass("nodisplay");
		//comment out next line to force re-login--uncomment top of php script
		var isLoggedIn = $("input#IsLoggedIn").val();
		clearLoginForm();
		//comment out next line to force re-login--uncomment top of php script
		$("input#IsLoggedIn").val(isLoggedIn);
	});
	$("#LoginForm").validate({
		 rules: {
			 Username: {required: "div#UsernamePasswordGroup:visible"},
			 Password: {required: "div#UsernamePasswordGroup:visible"},
			 NewUsername: {required: "div#NewUsername:visible"},
			 NewPassword1: {required: "div#NewPasswordGroup:visible",
			 					matchNewPassword2: true},
			 NewPassword2: {required: "div#NewPasswordGroup:visible",
			 					matchNewPassword1: true},
			 Email: {email: true,
			 		required: "div#ForgotUsernamePassword:visible"
				}
		 },
		 messages: {
			 Username: "Please enter your username.",
			 Password: "Please enter your password.",
			 NewUsername: "Please enter your new username",
			 NewPassword1: {required: "Please enter your new password."},
			 NewPassword2: {required: "Please enter your new password again."},
			 Email: "Please enter your email address."
		 }
	});
	$("#FormErrorDialog").dialog({
				modal: true,
				buttons: {
					Ok: function() {
					$(this).dialog('close');
					}},
				autoOpen: false,
				title: 'Noteable Blends'
	});
	$("#LoginFormSubmit").click(function() {
			if (!$("#LoginForm").valid()){
				$("#FormErrorDialog").dialog("open");
			} else {
				$("#js_validated").value = true;	
			}
	});
});


