// <script> for memberreg.asp

window.onload = initWindow; // Note: This will override any onload event defined in the html BODY object

var theForm

function initWindow() {	// Define Event Handlers (so we don't have to uglify the HTML code!)
	theForm =  document.getElementById("formCounselor");
}

function validateForm() {
	/*
	if (!checkField("Company", "the Loan Officer's Company", 1, false))
		return false;
	if (!checkField("LO_Name", "the Loan Officer's Name", 1, false))
		return false;
	if (!checkField("LO_Phone", "the Loan Officer's Phone", 10, false))
		return false;
	if (!isEmailAddress(theForm.LO_Email.value)) {
		theForm.LO_Email.focus();
		alert("Please enter a valid Loan Officer E-Mail Address.");
		return false;
	}
	*/
	if (!checkField("B_Name", "the Borrower's Name", 1, false))
		return false;
	if (!checkField("B_Phone", "the Borrower's Phone", 10, false))
		return false;
	if (!checkField("Language", "the Borrower's Preferred Language", 1, false))
		return false;
	if (!checkField("City", "a City", 1, false))
		return false;
	if (!checkField("Reason", "a Reason", 1, false))
		return false;

	// Validate CC Fields
	if (theForm.payby) {
		var paybyindex = getRadioChecked(theForm.payby);
		if (paybyindex == -1) {
			alert("Please choose a payment method - Check or Credit Card.");
			return false;
		}
		if (paybyindex == 1) {
			if (!checkField("CC_Number", "your Credit Card Number", 15, true))
				return false;
			if (!checkField("CC_VerifyCode", "your Credit Card Verification Code", 3, true))
				return false;
			if (!checkField("CC_ExpDate", "your Credit Card Expiration Date", 4, false))
				return false;
			if (!checkField("CC_Name", "your Name as it appears on your Card", 1, false))
				return false;
			if (!checkField("CC_BillingAddress", "your Billing Address", 1, false))
				return false;
			if (!checkField("CC_BillingCity", "your Billing Address City", 1, false))
				return false;
			if (!checkField("CC_BillingState", "your Billing Address State", 2, false))
				return false;
			if (!checkField("CC_BillingZip", "your Billing Address Zip Code", 5, true))
				return false;
		}
	}

	var toAddr = theForm.elements("~toAddress");
	var bodyPrefix = theForm.elements("~bodyPrefix");
	if (isMortPro) {
		toAddr.value = theForm.LO_Email.value;
		bodyPrefix.value = "Thank you.  Your request for counseling and payment has been received.  Please note that if you are requesting this counseling to be completed as a RUSH situation (five days before CLOSING or less) the full amount of $300 will be charged for the counseling session.  Please allow 72 hours for a counselor to contact your borrower to set up an appointment for counseling.  If they have not heard anything within 72 hours, please contact Sarah Bryar at 630-916-7720 or email sarahb@iamp.biz.  IF YOU SHOULD NEED TO CANCEL THIS COUNSELING REQUEST AND PAYMENT, YOU MUST DO SO WITHIN 24 HOURS OF SUBMITTING THIS REQUEST.  AFTER 24 HOURS, NO REFUNDS WILL BE ISSUED.";
	} else {
		toAddr.value = theForm.B_Email.value;
		bodyPrefix.value = "Your request for counseling has been received.  Please allow 72 hours for a counselor to contact you to set up an appointment.  If you have not heard anything within 72 hours, please call Sarah Bryar at 630-916-7720 or email sarahb@iamp.biz.  Thank you.";
	}
	document.getElementById("btnSubmit").disabled = true;
	return true;
}

function checkField(fieldName, fullName, minLen, numericOnly) {
	fld = eval(theForm.id + "." + fieldName);
	if (!fld || fld.style.display=="none") // If the field doesn't exist or is hidden, don't worry about it!
		return true;
	if (fld.value.length < minLen) {
		msg = "Please enter " + fullName + ".";
		if (minLen > 1)
			msg += "\n(At least " + minLen + " characters.)";
		fld.focus();
		alert(msg);
		return false;
	}
	if (numericOnly && isNaN(parseFloat(fld.value))) {
		fld.focus();
		fld.select();
		alert("Please use only numbers when entering " + fullName + ".");
		return false;
	}
	return true;
}

function getRadioChecked(radioObject) {
	nChecked = -1
	for (i=0; i < radioObject.length; i++) {
		if (radioObject[i].checked)
			nChecked = i;
	}
	return nChecked;
}

function isVowel(sChar) {
	lChar = sChar.slice(0, 1).toLowerCase();
	if (lChar == "a" || 
		lChar == "e" ||
		lChar == "i" ||
		lChar == "o" ||
		lChar == "u") {
		return true;
	} else {
		return false;
	}
}

function showCC(bShow) {
	var o = document.getElementById('ccFields');
	if (!bShow)
		o.style.display = 'none';
	else
		o.style.display = '';
}