var f
var bSubmitting = false
var s_prefix = "sub"

function showSecureMessage() {

	alert("All credit card and check(ACH) transactions are processed in the background on NOVA, a secured third-party merchant processing server.\n\nThis means sensitive data is never stored, exposed or transmitted in an unsecure fashion over the internet.")

}
function showPaymentMethod(o) {

	if (o.value == "C") {
		document.getElementById("TABLE_BILLINGACH").style.display = "none"
		document.getElementById("TABLE_BILLINGCREDIT").style.display = ""
	} else if (o.value == "A") {
		document.getElementById("TABLE_BILLINGCREDIT").style.display = "none"
		document.getElementById("TABLE_BILLINGACH").style.display = ""
	}
	
}
function validateSUBSCRIBE() {

	// Subscriber
	if (blank("FName","a First Name for the Subscriber")) return false
	if (blank("LName","a Last Name for the Subscriber")) return false
	if (f.subEMail.value == "" && f.subBillingEMail.value == "") {
		alert("Missing Required Information\nYour E-Mail address must be entered if not entering a Billing E-Mail address.")
		f.subEMail.focus()
		return false
	}
	if (!isValidEMail(f.subEMail,"Subscriber's E-Mail")) return false
	if (blank("Phone","a Phone Number for the Subscriber")) return false
	if (!isValidPhone(f.subPhone,"Subscriber's Phone Number")) return false
	if (!isValidPhone(f.subFax,"Subscriber's Fax Number")) return false
		
	if (blank("Address1","an Address Line 1 for the Subscriber")) return false
	if (blank("City","a City for the Subscriber")) return false
	if (blank("State","a State for the Subscriber")) return false
	if (blank("Zip","a U.S. Postal or Canadian Zip Code for the Subscriber")) return false
	if (!isValidZip(f.subZip,"Subscriber's Zip Code")) return false

	if (f.IsBillingDifferent.checked) {
		// Billing Address
		if (blank("BillingFName","a First Name for Billing Information")) return false
		if (blank("BillingLName","a Last Name for Billing Information")) return false
		if (!isValidEMail(f.subBillingEMail,"Billing E-Mail")) return false
			
		if (blank("BillingPhone","a Phone Number for Billing Information")) return false
		if (!isValidPhone(f.subBillingPhone,"Billing Phone Number")) return false
		if (!isValidPhone(f.subBillingFax,"Billing Fax Numbner")) return false
			
		if (blank("BillingAddress1","an Address Line 1 for Billing Information")) return false
		if (blank("BillingCity","a City for Billing Information")) return false
		if (blank("BillingState","a State for Billing Information")) return false
		if (blank("BillingZip","a U.S. Postal or Canadian Zip Code for Billing Information")) return false
		if (!isValidZip(f.subBillingZip,"Billing Zip Code")) return false
	}
	
	// Payment
	if (f.PaymentType[0].checked){
		// Credit Card
		if (blank("BillingCCType","the type of credit card")) return false
		if (blank("BillingCCNum","the credit card number")) return false
		f.subBillingCCNum.value = strip(f.subBillingCCNum.value)
		if (!isValidCreditCardNumber(f.subBillingCCNum,f.subBillingCCType.value,"Credit Card Number",true)) return false
		if (blank("BillingCCExpMonth","a credit card expiration date in the format of (MM YYYY)")) return false
		if (!isValidMonth(f.subBillingCCExpMonth)) return false
		if (blank("BillingCCExpYear","a credit card expiration date in the format of (MM YYYY)")) return false
		if (!isValidMonthYear(f.subBillingCCExpMonth,f.subBillingCCExpYear)) return false
		if (blank("BillingCCCCV","the credit card CCV number found on the back of your card")) return false
	} else {
		// ACH
		if (blank("BillingACHBank","the bank or institution this check is drawn on")) return false
		if (blank("BillingACHRouting","the routing number\nThis is the first series of numbers on the lower-left corner of any check.")) return false
		if (!isValidABA(f.subBillingACHRouting)) return false
		if (blank("BillingACHNum","the account number for this checking or savings account")) return false
		
	}
	if (!f.chkAccept.checked) {
		alert("You must check that you agree to this site and its privacy policy.")
		f.chkAccept.focus()
		return false
	}
	if (!isValidPassword(f.userPassword,f.userPasswordRetyped)) return false
	if (blank("Signature","your signature, i.e., first, middle and last name, to agree you adhere to such said terms")) return false
	return true
}
function validateMAILINGLIST() {

	if (f.mailEMail.value == "") {
		alert("Missing Required Information\nAn E-Mail address must be entered.")
		f.mailEMail.focus()
		return false
	}
	if (!isValidEMail(f.mailEMail,"E-Mail")) return false
	if (blank("FName","a First Name")) return false
	if (blank("LName","a Last Name")) return false
	if (blank("Phone","a Phone Number")) return false
	if (!isValidPhone(f.mailPhone,"Phone Number")) return false
	if (!isValidPhone(f.mailFax,"Fax Number")) return false
	if (blank("Address1","an Address Line 1")) return false
	if (blank("City","a City")) return false
	if (blank("State","a State")) return false
	if (blank("Zip","a U.S. Postal or Canadian Zip Code")) return false
	if (!isValidZip(f.mailZip,"Zip Code")) return false
	
	return true
}
function validateBLOGMEMBER() {

	if (f.userEMail.value == "") {
		alert("Missing Required Information\nAn E-Mail address must be entered.")
		f.userEMail.focus()
		return false
	}
	if (!isValidEMail(f.userEMail,"E-Mail")) return false
	if (!f.chkAccept.checked) {
		alert("You must check that you agree to this site's blog terms and its privacy policy.")
		f.chkAccept.focus()
		return false
	}
	if (blank("Handle","a Display Name")) return false
	if (!isValidPassword(f.userPassword,f.userPasswordRetyped)) return false
	
	return true
}
function validateBLOGTOPIC() {

	if (blank("Title","Blog Topic Subject")) return false
	if (foundOffensive(f.topicTitle)) return false
	if (foundScript(f.topicTitle)) return false
	if (blank("Contents","Blog Topic Contents")) return false
	if (foundOffensive(f.topicContents)) return false
	if (foundScript(f.topicContents)) return false
	if (blank("Author","Blog Topic Author")) return false
	if (foundOffensive(f.topicAuthor)) return false
	if (foundScript(f.topicAuthor)) return false
	return true
}
function validateBLOGPOST() {

	if (blank("Contents","Blog Post Contents")) return false
	if (foundOffensive(f.postContents)) return false
	if (foundScript(f.postContents)) return false
	if (blank("Author","Blog Post Author")) return false
	if (foundOffensive(f.postAuthor)) return false
	if (foundScript(f.postAuthor)) return false
	return true
}
function validateLOGIN() {

	if (blank("EMail","E-Mail Address")) return false
	if (blank("Password","Password")) return false
	return true
}
function submitMe() {

	if (!bSubmitting) {
		bSubmitting = true
		f = document.forms[0]
		var s_name = f.name
		var b_valid = false
	
		switch (s_name) {
	
			case "SUBSCRIBE":
				s_prefix = "sub"
				updateBillingAddress()
				updateBillingMethod()
				b_valid = validateSUBSCRIBE()
				break
			
			case "MAILINGLIST":
				s_prefix = "mail"
				b_valid = validateMAILINGLIST()
				break
			
			case "BLOGMEMBER":
				s_prefix = "user"
				b_valid = validateBLOGMEMBER()
				break
				
			case "BLOGTOPIC":
				s_prefix = "topic"
				b_valid = validateBLOGTOPIC()
				break
				
			case "BLOGPOST":
				s_prefix = "post"
				b_valid = validateBLOGPOST()
				break
			
			case "LOGIN":
				s_prefix = "login"
				b_valid = validateLOGIN()
				break
	
		}
	
		if (b_valid) {
			f.submit()
		} else {
			bSubmitting = false
		}
	}	
	
}
function updateWhoDesc(what) {

	if (what == "") {
		document.getElementById("TABLE_WHOREFERREDDESC").style.display = "none"
	} else {
		document.getElementById("lblWhoReferred1Desc").innerHTML = "Enter the " + what
		document.getElementById("TABLE_WHOREFERREDDESC").style.display = ""
	}

}
function updateBillingMethod() {
	if (f.PaymentType[0].checked) {
		if (f.subBillingCCType.value == "VISA") {
			f.subBillingMethod.value = "VISA"
		} else if (f.subBillingCCType.value == "MASTERCARD") {
			f.subBillingMethod.value = "MCARD"
		}
	} else {
		f.subBillingMethod .value= "ACH"
	}
	f.subBillingCCExp.value = f.subBillingCCExpMonth.value + f.subBillingCCExpYear.value
								
}
function setAnonymous() {

	f = document.forms[0]
	if (f.IsAnonymous.checked) {
		f.subFName.value = "Current"
		f.subLName.value = "Resident"
		f.IsBillingDifferent.checked = true
		showID(f.IsBillingDifferent,'TABLE_BILLINGADD')
		document.getElementById("TD_BILLINGDIFFERENT").style.display = "none"
	} else {
		f.subFName.value = ""
		f.subLName.value = ""
		document.getElementById("TD_BILLINGDIFFERENT").style.display = ""
	}
	
}
function set1stFocus() {

	if (document.forms[0] != null) {
		var f_which = document.forms[0]
		var s_name = f_which.name
		var s_field
		switch (s_name) {
	
			case "SUBSCRIBE":
				s_field = "subFName"
				break
			
			case "MAILINGLIST":
				s_field = "mailEMail"
				break
			
			case "BLOGMEMBER":
				s_field = "userEMail"
				break
				
			case "BLOGTOPIC":
				s_field = "topicTitle"
				break
				
			case "BLOGPOST":
				s_field = "postContents"
				break
			
			case "LOGIN":
				s_field = "loginEMail"
				break
	
		}
		f_which[s_field].focus()
	}

}
