// this function validates and checks to see if the user has logged in correctly
function _memberLogin()
{
	// check to make sure everything is good
	var oForm = document.forms[0];					
	var sBody = getRequestBody(oForm);									// get the form
	var oXmlHttp = zXmlHttp.createRequest();
	var invalidFields = 0;
	
	if (document.form1.txt_Customer.value==""||!IsNumeric(document.form1.txt_Customer.value))
		invalidFields++;
	
	if (document.forms[0].pwd_Password.value=="")
		invalidFields++;
		
	if (invalidFields==0) 
	{
  		// Open a connection to the server
  		oXmlHttp.open("POST", "/members/scripts/_login.asp", true);
		oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  		// Setup a function for the server to run when it's done
  		oXmlHttp.onreadystatechange = function ()
		{
			if (oXmlHttp.readyState == 1)
				document.getElementById("spn_Status").innerHTML = "Searching.";
			else if (oXmlHttp.readyState == 2)
				document.getElementById("spn_Status").innerHTML = "Searching..";
			else if (oXmlHttp.readyState == 3)
				document.getElementById("spn_Status").innerHTML = "Searching...";
			else if (oXmlHttp.readyState == 4) 
			{
				if (oXmlHttp.status == 200)
				{
			    	response = oXmlHttp.responseText;
					if (response=="-1")
				    	document.getElementById("spn_Status").innerHTML = "The Customer ID and Password you provided do not match our records.";
					else
						window.location="/members/interface.asp";
					window.status = "Done";
					response = "";
				}
				else
					alert("Sorry, server error (" + oXmlHttp.status + ") has occurred logging in the club member. If problems persist please contact your site administrator or hosting company. Thank you!");
			}
		};
  		// Send the request
  		oXmlHttp.send(sBody);
	}
	else
		document.getElementById("spn_Status").innerHTML = "Please provide a Customer ID or Password.";
}

// this function validates the dining reservations form
function validateDining()
{
	if (document.form1.Full_Name.value=="")
	{
		alert("Please provide your full name.");
		document.form1.Full_Name.focus();
	}
	else if (document.form1.UserEmail.value==""||document.form1.UserEmail.value.indexOf("@")<2||document.form1.UserEmail.value.indexOf(".")<2)
	{
		alert("Please provide a valid email address.");
		document.form1.UserEmail.focus();
	}
	else if (document.form1.CustomerID.value=="")
	{
		alert("Please provide your Delaware Country Club Member ID.");
		document.form1.Event_Type.focus();
	}
	else if (document.form1.Date_Requested.value==""||!isDate(document.form1.Date_Requested.value))
	{
		alert("Please provide the date you wish to make these reservations.");
		document.form1.Date_Requested.focus();
	}
	else if (document.form1.Time_Requested.value=="")
	{
		alert("Please provide an approximate time you wish to make these reservations.");
		document.form1.Time_Requested.focus();
	}
	else
	{
		document.getElementById("btn_Submit").disabled = true;
		document.form1.action = "/members/scripts/FormMailer.asp?refer=/members/diningreservations.asp&InfoType=Dining Reservations Requested at delawarecc.com";
		document.form1.submit();
	}
}

// this function validates the change password form
function validatePassword()
{
	if (document.form1.hid_Member.value==""||!IsNumeric(document.form1.hid_Member.value))
	{
		alert("You are not currently logged in. Please login to view this page.");
		window.location = "/members";
	}
	else if (document.form1.pwd_Original.value=="")
	{
		alert("Please provide your current password.");
		document.form1.pwd_Original.focus();
	}
	else if (document.form1.pwd_New.value=="")
	{
		alert("Please provide your new password.");
		document.form1.pwd_New.focus();
	}
	else if (document.form1.pwd_Confirm.value=="")
	{
		alert("Please confirm your new password.");
		document.form1.pwd_Confirm.focus();
	}
	else if (document.form1.pwd_New.value!=document.form1.pwd_Confirm.value)
	{
		alert("The confirmation password does not match your new password. Please correct and try again.");
		document.form1.pwd_New.focus();
	}
	else if (document.form1.pwd_Original.value==document.form1.pwd_New.value)
	{
		alert("The new password cannot be the same as the current password. Please correct and try again.");
		document.form1.pwd_New.focus();
	}
	else
	{
		document.form1.action = "/members/scripts/srv_changepassword.asp";
		document.getElementById("btn_Submit").disabled = true;
		document.form1.submit();
	}
}
