var BtnArray = new Array()
var RowArray = new Array()
var T_TIMER
var T_URL
var B_KILLCLICK = false

BtnArray[0] = new Image(74,15)
BtnArray[1] = new Image(74,15)
BtnArray[2] = new Image(85,15)
BtnArray[3] = new Image(85,15)
BtnArray[4] = new Image(52,15)
BtnArray[5] = new Image(52,15)
BtnArray[6] = new Image(114,15)
BtnArray[7] = new Image(114,15)
BtnArray[8] = new Image(108,15)
BtnArray[9] = new Image(108,15)
BtnArray[10] = new Image(92,15)
BtnArray[11] = new Image(92,15)
BtnArray[12] = new Image(58,15)
BtnArray[13] = new Image(58,15)
BtnArray[14] = new Image(58,15)
BtnArray[15] = new Image(58,15)
BtnArray[16] = new Image(63,15)
BtnArray[17] = new Image(63,15)
BtnArray[18] = new Image(38,15)
BtnArray[19] = new Image(38,15)

BtnArray[0].src = "images/BTN_SUBSCRIBE_0.gif"
BtnArray[1].src = "images/BTN_SUBSCRIBE_1.gif"
BtnArray[2].src = "images/BTN_GIFT_0.gif"
BtnArray[3].src = "images/BTN_GIFT_1.gif"
BtnArray[4].src = "images/BTN_RENEW_0.gif"
BtnArray[5].src = "images/BTN_RENEW_1.gif"
BtnArray[6].src = "images/BTN_SUBSCRIBERS_0.gif"
BtnArray[7].src = "images/BTN_SUBSCRIBERS_1.gif"
BtnArray[8].src = "images/BTN_MAILING_0.gif"
BtnArray[9].src = "images/BTN_MAILING_1.gif"
BtnArray[10].src = "images/BTN_MEMBERS_0.gif"
BtnArray[11].src = "images/BTN_MEMBERS_1.gif"
BtnArray[12].src = "images/BTN_LOGIN_0.gif"
BtnArray[13].src = "images/BTN_LOGIN_1.gif"
BtnArray[14].src = "images/BTN_LOGOUT_0.gif"
BtnArray[15].src = "images/BTN_LOGOUT_1.gif"
BtnArray[16].src = "images/BTN_SETTINGS_0.gif"
BtnArray[17].src = "images/BTN_SETTINGS_1.gif"
BtnArray[18].src = "images/BTN_MAIN_0.gif"
BtnArray[19].src = "images/BTN_MAIN_1.gif"

function btn_mo(which) {

	document.images["BTN" + which].src = BtnArray[(which * 2)].src

}
function btn_mi(which) {

	document.images["BTN" + which].src = BtnArray[(which * 2) + 1].src

}
function rowOver(which) {

	if (!RowArray[which]) document.getElementById("TR" + which).style.backgroundColor = "#B3CBE6"

}
function rowOut(which) {

	if (!RowArray[which]) document.getElementById("TR" + which).style.backgroundColor = "white"

}
function killClick() {
	B_KILLCLICK = true
}
function rowClick(which) {

	if (!B_KILLCLICK) location.href = "manage_subscribers_edit.asp?EDIT=Y&ID=" + which
	B_KILLCLICK = false
		
	/*
	var f = document.forms[0]
	RowArray[which] = !RowArray[which]
	if (RowArray[which]) {
		document.getElementById("TR" + which).style.backgroundColor = "#B5CBE3"
	} else {
		document.getElementById("TR" + which).style.backgroundColor = "white"
	}
	f.elements["chk" + which].checked = RowArray[which]*/
}
function deleteRows() {
	var f = document.forms[0]
	f.DELETE.value = "Y"
	f.submit()
}
function updateTotal() {
	var f = document.forms[0]
	var n_unit = f.subUnitPrice.value
	var n_qty = f.subQty.value
	var n_editions = f.subEditions.value
	var n_total = n_unit * (n_qty * n_editions)
	n_total = n_total.toFixed(2)
	f.subTotalPrice.value = n_total
}
function determineCountry(F_STATE,F_COUNTRY) {

	var B_USA = false
	switch(F_STATE.value) {
	
		case "AB":
		case "BC":
		case "MB":
		case "NB":
		case "NL":
		case "NT":
		case "NS":
		case "ON":
		case "PE":
		case "PQ":
		case "QC":
		case "SK":
		case "YK":
		case "YT":
		case "NU":
			F_COUNTRY.value = "CA"
			break
		default:
			F_COUNTRY.value = "US"
			B_USA = true
			break
	}
	if (B_USA) {
		document.forms[0].subUnitPrice.value = "5.60"
	} else {
		document.forms[0].subUnitPrice.value = "6.60"
	}
	updateTotal()
	return true
}
function lblmi(what) {

	document.getElementById(what.id).style.textDecoration = "underline"
}
function lblmo(what) {

	document.getElementById(what.id).style.textDecoration = "none"
}
function copyBilling(what) {

	f["subBilling" + what].value = f["sub" + what].value

}
function updateBillingAddress() {

	if (!f.IsBillingDifferent.checked) {
	
		copyBilling("FName")
		copyBilling("MName")
		copyBilling("LName")
		copyBilling("BName")
		copyBilling("EMail")
		copyBilling("Phone")
		copyBilling("Fax")
		copyBilling("Address1")
		copyBilling("Address2")
		copyBilling("City")
		copyBilling("State")
		copyBilling("Zip")
		copyBilling("Country")
		
	}
		
}
function blank(what,whatsname) {

	if (f[s_prefix + what].value == "") {
		alert("Missing Required Information\nPlease enter " + whatsname)
		f[s_prefix + what].focus()
		return true
	}
	return false

}
function showID(f_check,s_id) {

	if (f_check.checked) {
		document.getElementById(s_id).style.display = ""
	} else {
		document.getElementById(s_id).style.display = "none"
	}

}
function foundScript(o_what) {

	// ALLOWED HTML TAGS
	// <A>, <B>, <I>, <UL>, <OL>, <LI>
	var A_WORDS = new Array("<OBJECT","<C","<D","<E","<F","<G","<H","<J","<K","<M","<N","<P","<Q","<R","<S","<T","<V","<W","<X","<Y","<Z","ONCLICK","ONLOAD","ONRESZIE","ONFOCUS","ONBLUR","ONMOUSEOUT","ONMOUSEOVER","ONMOUSEUP","ONMOUSEWHEEL","ONKEYDOWN","ONKEYUP","ONDBLCLICK","ONACTIVATE","ONDEACTIVATE","ONDRAGSTART","ONKEYPRESS","PARENT.","DOCUMENT.","WINDOW.")
	var what = o_what.value + " "
	var S_ORIGINAL = what
	var S_TEXT = what.toUpperCase()
	var S_MARKUP
	var N_FOUND = -1
	
	for (var n=0; n<A_WORDS.length; n++) {
		N_FOUND = S_TEXT.indexOf(A_WORDS[n])
		if (N_FOUND >= 0) {
			S_MARKUP = what.substring(0,N_FOUND) + "]-->" + what.substring(N_FOUND,what.length)
			alert("Script, e.g., javascript, jscript, vbscript, or restricted HTML has been detected.\n\n" + S_MARKUP)
			o_what.focus()
			return true
		}
	}
	return false

}
function checkLength(o_field,s_label,i_max) {
	
	f = document.forms[0]
	var s_field = o_field.value
	if (s_field.length > i_max) {
		alert(s_label + " cannot exceed " + i_max + " characters.")
		var s_new = s_field.substr(0,i_max)
		o_field.value = s_new
	}		

}
function foundOffensive(o_what) {
	
	var A_WORDS = new Array("COCK","CUNT","DICK","PUSSY","SHIT","TWAT","DYKE","FAG","LESBO","WHORE","BITCH","BASTARD","FUCK","SLUT","WANKER","NIGGER","SPIC","WOP","GOOK","KIKE","WETBACK","DAMN","ASSHOLE","ASS HOLE","ASS-HOLE","NIGGAZ","LMAO","SOB","!%#@","ASS ")
	var A_REPWORDS = new Array("----","----","----","-----","----","----","----","---","-----","-----","-----","-------","----","----","------","------","----","---","----","----","-------","----","-------","--------","--------","------","----","---","----","--- ")
	var what = o_what.value + " "
	var S_ORIGINAL = what
	var S_TEXT = what.toUpperCase()
	var S_MARKUP
	var N_FOUND = -1
	var N_WORDLEN
	var B_FOUND = false
	var N_START
	var S_REMAIN
	for (var n=0; n<A_WORDS.length; n++) {
		N_FOUND = S_TEXT.indexOf(A_WORDS[n])
		while (N_FOUND >= 0) {
			// FOUND
			B_FOUND = true
			N_WORDLEN = A_WORDS[n].length
			S_MARKUP = what.substring(0,N_FOUND) + "[" + A_WORDS[n] + "]" + what.substring(N_FOUND + N_WORDLEN,what.length)
			what = S_MARKUP
			S_TEXT = what.toUpperCase()
			N_START = N_FOUND + N_WORDLEN + 3
			if (N_START <= S_TEXT.length) {
				S_REMAIN = S_TEXT.substring(N_START,S_TEXT.length)
				N_FOUND = S_REMAIN.indexOf(A_WORDS[n])
				if (N_FOUND >= 0) N_FOUND = N_FOUND + N_START
			} else {
				N_FOUND = -1
			}
		}
	}
	if (B_FOUND) {
		var B_DECISION = confirm("Offensive Language Detected. Would you like to mask these words?\n\n" + S_MARKUP)
		if (B_DECISION) {
			S_TEXT = S_ORIGINAL.toUpperCase()
			for (n=0; n<A_WORDS.length; n++) {
				N_FOUND = S_TEXT.indexOf(A_WORDS[n])
				while (N_FOUND >= 0) {
					// FOUND
					N_WORDLEN = A_WORDS[n].length
					S_ORIGINAL = S_ORIGINAL.substring(0,N_FOUND) + A_REPWORDS[n] + S_ORIGINAL.substr(N_FOUND + N_WORDLEN,S_ORIGINAL.length-1)
					N_START = N_FOUND + N_WORDLEN
					if (N_START <= S_TEXT.length) {
						S_REMAIN = S_TEXT.substring(N_START,S_TEXT.length)
						N_FOUND = S_REMAIN.indexOf(A_WORDS[n])
						if (N_FOUND >= 0) N_FOUND = N_FOUND + N_START
					} else {
						N_FOUND = -1
					}
				}
			}
			o_what.value = S_ORIGINAL
			B_FOUND = false
		}
	}
	if (B_FOUND) o_what.focus()
	return B_FOUND
}
function allDigits(str)
{
	return inValidCharSet(str,"0123456789");
}
function isValidPassword(O_PASS1,O_PASS2)
{

	if (O_PASS1.value == "") {
		alert("Missing Required Information\nPlease enter your password for this account.")
		O_PASS1.focus
		return false
	}
	if (O_PASS2.value == "") {
		alert("Missing Required Information\nPlease retype your password.")
		O_PASS2.focus
		return false
	}
	if (O_PASS1.value != O_PASS2.value) {
		alert("Invalid Information Entered\nThe retyped password does not match. Please retype the password again.")
		O_PASS1.focus
		return false
	}
	return true

}
function isValidMonthYear(S_MONTH,S_YEAR)
{
	var D_DATE = new Date()
	var D_MONTH = D_DATE.getMonth()
	var D_YEAR = D_DATE.getYear()
	D_MONTH++
	if (D_YEAR == S_YEAR.value) {
		if (S_MONTH.value < D_MONTH) {
			alert("Invalid information entered\nPlease enter a valid credit card expiration. The date entered has already expired.")
			S_YEAR.focus()
			return false
		}
	}
	return true
}
function inValidCharSet(str,charset)
{
	var result = true;
	
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	
	return result;
}
function isValidContent(field,content) {
	var valid = content
	var ok = "yes"
	var temp
	
	for (var i=0; i<field.length; i++) {
		temp = "" + field.substring(i,i+1)
		if (valid.indexOf(temp) == "-1") ok = "no"
	}
	if (ok == "no") {
		return false
	}
	return true
}
function isValidEMail(what,label) {

	var nAMP=-1,nDOT=-1,nERR=0,whatText
	whatText = what.value
	if (whatText == "") return true
	
	if (isValidContent(whatText,"!#$%&'*+-./0123456789=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz{|}~")) {
		for (var i=0; i<whatText.length; i++) {
			if (whatText.charAt(i) == "@") {
				if (nAMP == -1) {
					nAMP = i
				} else {
					nERR = 1
					break
				}
			} else if (whatText.charAt(i) == ".") {
				nDOT++
			}
		}
		if (nAMP == -1) {
			nERR = 2
		} else if (nDOT  == -1) {
			nERR = 3
		}
	} else {
		nERR = 4
	}
	
	if (nERR == 1) {
	// 1 - Too many ampersands
	alert("Invalid information entered\nA valid " + label + " must be entered.")
	} else if (nERR == 2) {
	// 2 - No ampersand
	alert("Invalid information entered\nA valid " + label + " must be entered.")
	} else if (nERR == 3) {
	// 3 - no dots
	alert("Invalid information entered\nA valid " + label + " must be entered.")
	} else if (nERR == 4) {
	// 4 - Invalid charachters
	alert("Invalid information entered\nA valid " + label + " must be entered.")
	} else {
		return true
	}
	
	what.focus()
	return false
}
function isValidZip(what,label) {

	var s1, s2, whatText = what.value
	if (isValidContent(whatText,"-0123456789")) {
		
		switch(whatText.length) {
			case 5:
				if (allDigits(whatText)) return true
				break;
				
			case 9:
				if (allDigits(whatText)) {
					whatText = whatText.substring(0,4) + "-" + whatText.substring(5,8)
					what.value = whatText
					return true
				}
				break;
				
			case 10:
				if (whatText.charAt(5) == "-") {
					s1 = whatText.substring(0,4)
					s2 = whatText.substring(6,9)
					if (s1.length == 5 && s2.length == 4) {
						if (allDigits(s1) && allDigits(s2)) return true
					}
				}
				break;
		}
	
	} else if (isValidContent(whatText,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ ")) {
		switch(whatText.length) {
			case 6:
				if (isValidContent(whatText,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")) {
					whatText = whatText.substring(0,2) + " " + whatText.substring(3,5)
					what.value = whatText
					return true
				}
				break;
			case 7:
				if (whatText.charAt(3) == " ") {
					s1 = whatText.substring(0,2)
					s2 = whatText.substring(4,6)
					if (s1.length == 3 && s2.length == 3) {
						if (isValidContent(s1,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") && isValidContent(s2,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")) return true
					}
				}
				break;
		}
	}
	alert("Invalid information entered\nA " + label + " must be entered in the standard U.S. Postal format.\n\nExamples: U.S.: (90210, 30144-3948) Canada: (AE7 B38, AE7B38).")
	what.focus()
	return false

}
function isValidMonth(what) {

	var bResult = true
	if (what.value != "") {
		var strOld = what.value
		for (var i=0; i<strOld.length; i++) {
			if (strOld.charCodeAt(i) < 48 || strOld.charCodeAt(i) > 57) {
				bResult = false
				break
			}
		}
		if (bResult) {
			if (what.value > 12 || what.value <= 0) bResult = false
		}
	} else {
		bResult = false
	}
	if (!bResult) {
		alert("Invalid information entered\nPlease enter a valid credit card expiration month.")
		what.focus()
	}
	return bResult

}
function strip(what) {

	if (what != "") {
		var strNew = ""
		var strOld = what
		for (var i=0; i<strOld.length; i++) {
			if (strOld.charCodeAt(i) >= 48 && strOld.charCodeAt(i) <= 57) strNew = strNew + strOld.charAt(i)
		}
		return strNew
	}
	return ""
	
}
function isValidPhone(what,label) {
	var cA
	var cB
	var strValue = what.value
	var strExt = ""
	
	if (strValue == "") return true
	
	// Remove any extension or special post formatting
	cA = strValue.indexOf(" ")
	if (cA != -1) {
		strExt = strValue.substring(cA + 1,(strValue.length-1))
		strValue = strValue.substring(0,cA - 1)
	}
	// Remove non-numeric charachters
	strValue = strip(strValue)
	if (strExt != "") {
		if (strExt.charAt(0) != "x") strExt = "x" + strExt
		strExt = " " + strExt
	}
	
	switch (strValue.length) {
		
		case 7:
			what.value = strValue.substring(0,3) + "-" + strValue.substring(3,7) + strExt
			return true
			break;
		
		case 10:
			what.value = strValue.substring(0,3) + "-" + strValue.substring(3,6) + "-" + strValue.substring(6,10) + strExt
			return true
			break
			
		case 11:
			if (strValue.charAt(0) == "1") {
				what.value = strValue.substring(1,4) + "-" + strValue.substring(4,7) + "-" + strValue.substring(7,11) + strExt
				return true
			}
			break
	}
	alert("Invalid information entered\nA " + label + " must be entered in one of the following accepted formats\n\nExamples: 404-555-1212, (404)555-1212, 4045551212, 555-1212, etc.")
	what.focus()
	return false
}
function isValidExpDate(formField,fieldLabel,required)
{
	var result = true;
	var formValue = formField.value;
	if (formValue.length == 5) {
		formField.value = formValue.substr(0,3) + "20" + formValue.substr(3,2)
		formValue = formField.value
	}
 	if (result && (formField.value.length>0))
 	{
 		var elems = formValue.split("/");
 		
 		result = (elems.length == 2); // should be two components
 		var expired = false;
 		
 		if (result)
 		{
 			var month = parseInt(elems[0],10);
 			var year = parseInt(elems[1],10);
 			
 			if (elems[1].length == 2)
 				year += 2000;
 			
 			var now = new Date();
 			
 			var nowMonth = now.getMonth() + 1;
 			var nowYear = now.getFullYear();
 			
 			expired = (nowYear > year) || ((nowYear == year ) && (nowMonth > month));
 			
			result = allDigits(elems[0]) && (month > 0) && (month < 13) &&
					 allDigits(elems[1]) && ((elems[1].length == 2) || (elems[1].length == 4));
 		}
 		
  		if (!result)
 		{
 			alert('Invalid Information\nPlease enter a date in the format MM/YYYY for the ' + fieldLabel +' field.');
			formField.focus();
		}
		else if (expired)
		{
 			result = false;
 			alert('Invalid Information\nThe date for ' + fieldLabel +' has expired.');
			formField.focus();
		}
	} 
	
	return result;
}

function isValidCreditCardNumber(formField,ccType,fieldLabel,required)
{
	var result = true;
 	var ccNum = formField.value;
 
  	if (result && (formField.value.length>0))
 	{ 
 		if (!allDigits(ccNum))
 		{
 			alert('Invalid Information\nPlease enter only numbers (no dashes or spaces) for the ' + fieldLabel +' field.');
			formField.focus();
			result = false;
		}	

		if (result)
 		{ 
 			
 			if (!LuhnCheck(ccNum) || !validateCCNum(ccType,ccNum))
 			{
 				alert('Invalid Information\nPlease enter a valid card number for the ' + fieldLabel +' field.');
				formField.focus();
				result = false;
			}	
		} 

	} 
	
	return result;
}
function LuhnCheck(str) 
{
  var result = true;

  var sum = 0; 
  var mul = 1; 
  var strLen = str.length;
  
  for (i = 0; i < strLen; i++) 
  {
    var digit = str.substring(strLen-i-1,strLen-i);
    var tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }
  if ((sum % 10) != 0)
    result = false;
 
  return result;
}
function validateCCNum(cardType,cardNum)
{
	var result = false;
	cardType = cardType.toUpperCase();
	
	var cardLen = cardNum.length;
	var firstdig = cardNum.substring(0,1);
	var seconddig = cardNum.substring(1,2);
	var first4digs = cardNum.substring(0,4);
	

	switch (cardType)
	{
		case "VISA":
			result = ((cardLen == 16) || (cardLen == 13)) && (firstdig == "4");
			break;
		case "AMEX":
			var validNums = "47";
			result = (cardLen == 15) && (firstdig == "3") && (validNums.indexOf(seconddig)>=0);
			break;
		case "MASTERCARD":
			var validNums = "12345";
			result = (cardLen == 16) && (firstdig == "5") && (validNums.indexOf(seconddig)>=0);
			break;
		case "DISCOVER":
			result = (cardLen == 16) && (first4digs == "6011");
			break;
		case "DINERS":
			var validNums = "068";
			result = (cardLen == 14) && (firstdig == "3") && (validNums.indexOf(seconddig)>=0);
			break;
	}
	
	
	return result;
}
function isValidABA(s) {

  if (s.value == '800884439') return true
  var i, n, t
  t = s.value
  // Now run through each digit and calculate the total.

  n = 0;
  for (i = 0; i < t.length; i += 3) {
    n += parseInt(t.charAt(i),     10) * 3
      +  parseInt(t.charAt(i + 1), 10) * 7
      +  parseInt(t.charAt(i + 2), 10);
  }

  if (n != 0 && n % 10 == 0) {
    return true
  } else {
	alert("Invalid Information\nPlease enter a valid routing number.")
	s.focus()
    return false
   }
}
function delayLoad(URL_LOAD) {
	T_URL = URL_LOAD
	T_TIMER = setTimeout("loadURL()",1000)
}
function loadURL() {
	clearTimeout(T_TIMER)
	location.href = T_URL
}
function checkAll(O_WHAT) {
	var f = document.forms[0]
	var B_VAL = O_WHAT.checked
	for (var n=0; n<f.length; n++) {
		if (f[n].type == "checkbox") f[n].checked = B_VAL
	}
}