// JavaScript Document
// Message center functionaltiy including dynamic changing lists
// and assignment of variables for entry in the database.
////////////////////////////////////////////////////////////////////
//global variables
var IsThisAMember = 0;
var MessageType = 0;
var thirdTier;
var endValue;

function IsMember(val){
	IsThisAMember = val;
	if (val=="1"){
		document.getElementById("memberNum").style.display = "";
	} else {
		document.getElementById("memberNum").style.display = "none";
	}
}

//function SetMsgType(mtval) {
//	MessageType = mtval;
//}

function placeFocus() {
	document.myform.firstname.focus();	
	document.myform.firstname.select();
}

function setClass(el, bg) {  
  el.className = bg;
}

function IsFieldEmpty(content) {
	var retval;
	if (trimall(content) == "") 
		retval=1;
	else
		retval=0;
	return retval;
}

function allEve(e){
	var ev= (window.event)? window.event: e;
	if(!ev || !ev.type) return false;
	var ME= ev;
	if(ME.type.indexOf('key')!= -1){
		if(('ie') || ME.type.indexOf('keypress')!= -1){
			ME.key= (ev.keyCode)? ev.keyCode: ((ev.charCode)? ev.charCode: ev.which);
		}
		else ME.key= ev.charCode;
		if(ME.key) ME.letter= String.fromCharCode(ME.key);
	}
	return ME;
}

function isnumberkey(e) {
	var retval = true;
	var c = allEve(e).key;
	  if ( (c < 48) || (c > 57)  ) retval = false;
	  this.onkeyup = document.myform.membernumber.focus();	  
	return retval;
}
function isphonekey() {
	var retval = false;
	if ( isnumberkey() || (event.keyCode == 40) ||  (event.keyCode == 41) || (event.keyCode == 45) )
	  retval = true;
	return retval;
}
function trimall(sString) {
    if (sString.length > 0) {
		while (sString.substring(0,1) == ' ')
			sString = sString.substring(1, sString.length);
		while (sString.substring(sString.length-1, sString.length) == ' ')
			sString = sString.substring(0,sString.length-1);
    }
	return sString;
}
//////////////////////////////////////////////////////////////////////////////////////////////
// Character count for message text area /////////////
////////////////////////////////////////////////////
function counterUpdate(opt_countedTextBox, opt_countBody, opt_maxSize) {
        var countedTextBox = opt_countedTextBox ? opt_countedTextBox : "message";
        var countBody = opt_countBody ? opt_countBody : "ccount";
        var maxSize = opt_maxSize ? opt_maxSize : 1500;

        var field = document.getElementById(countedTextBox);

        if (field && field.value.length >= maxSize) {
                field.value = field.value.substring(0, maxSize);
        }
        var txtField = document.getElementById(countBody);
                if (txtField) { 
                txtField.innerHTML = maxSize - field.value.length;
        }
}
/////////////////////////////////////////////////////////////////////////////////////////////////
function testMe() {
	var fieldval;
	var retval;
	
	// check firstname----------------------------------------------------------------
	fieldval = trimall(myform.firstname.value);
	retval = IsFieldEmpty(fieldval);
	if (retval) {
		alert("Please enter your firstname");
		setClass(myform.firstname, "badFieldEntry");
		myform.firstname.focus();
		return 0;
	}//if
	setClass(myform.firstname, "normalFieldEntry");
	
	// check lastname----------------------------------------------------------------
	fieldval = trimall(myform.lastname.value);	
	retval = IsFieldEmpty(fieldval);
	if (retval) {
		alert("Please enter your lastname");
		setClass(myform.lastname, "badFieldEntry");
		myform.lastname.focus();
		return 0;
	}//if	
	setClass(myform.lastname, "normalFieldEntry");
	
	//check if this is an existing member then validate fields-----------------------
	if (IsThisAMember == 1) {
		// check member number
		fieldval = trimall(myform.membernumber.value);	
		retval = IsFieldEmpty(fieldval);
		if (retval) {
			alert("Please enter your member number");
			setClass(myform.membernumber, "badFieldEntry");
			myform.membernumber.focus();
			return 0;
		}//if
		setClass(myform.membernumber, "normalFieldEntry");	
	}
    // phone number ------------------------------------
	fieldval = trimall(myform.phone.value);
	var phoneNo = new RegExp (/^(?:\([2-9]\d{2}\)\ ?|[2-9]\d{2}(?:\-?|\ ?))[2-9]\d{2}[- ]?\d{4}$/);
	retval = IsFieldEmpty(fieldval);
	if ( (!retval) &&  (!phoneNo.test(fieldval)) ) {
           alert("Invalid Phone Number. Please enter in the following format: (555)555-1234");
 	  	   setClass(myform.phone, "badFieldEntry");
		   	myform.phone.focus();
 		  return 0;
	}//if
	setClass(myform.phone, "normalFieldEntry");		
	// (0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d
	
  
	// check email----------------------------------------------------------------
	fieldval = trimall(myform.email.value);
	var eAddress = new RegExp(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/);
	retval = IsFieldEmpty(fieldval);
	if (retval) {
		alert("Please enter your email");
		setClass(myform.email, "badFieldEntry");
		myform.email.focus();
		return 0;
	}//if	
	retval = eAddress.test(fieldval);
	if (!retval) {
		alert("Invalid email address");
		setClass(myform.email, "badFieldEntry");
		myform.email.focus();
		return 0;
	}//if
	setClass(myform.email, "normalFieldEntry");

	// check message type-----------------------------------------------------------
	//if (MessageType == 0) {
	//	alert("Please select message type");
	//	return 0;
	//}//if
	
	
	// check message----------------------------------------------------------------
	fieldval = myform.message.value;	
	retval = IsFieldEmpty(fieldval);
	if (retval) {
		alert("Please enter your message");
//		setClass(myform.message, "badFieldEntry");
		myform.message.focus();
		return 0;
	}//if
	if (fieldval.length >= 1500) {
		alert("Your message can only be 1500 characters");
//		setClass(myform.message, "badFieldEntry");
		myform.message.focus();
		return 0;
	}	
//	setClass(myform.message, "normalFieldEntry");
	
	
	//OK
	return 1;
}

/////////////////////////////////////////////////////////////////////
// VALIDATE AND SUBMIT FORM
function SubmitForm() {

	if (!testMe()) return false;
	
    //ok
    return true;
}

////////////////////////////////////////////////////////////////////////////////////////////////
// SELECT CHANGERS
// Creates text for area to left of second level SELECT box and passes choice on for 
// populating second level SELECT box (name = reason2) based on first select box (name = reason1) 
// choice.
/////////////////////////////////////////////////////////////////////////////////////////////////
function SelectChange(selector) {
	var sValue = selector.value;
	var thirdTier;
	if (document.getElementById("section2").style.display != "none"){
		document.getElementById("section2").style.display = "none";
	}
	switch(sValue){
	case "1":
		document.getElementById("section2_Text").innerHTML="Information about...";
		XpandOptions(1);
		break;
	case "2":
		document.getElementById("section2_Text").innerHTML="A Question about...";
		XpandOptions(1);
		break;
	case "3":
		document.getElementById("section2_Text").innerHTML="I've encountered an error with...";
		XpandOptions(2);
		break;
	case "4":
		topicValue = 6;
		ProvideLinks(77);
		break;
	default:
		return;
	}
}
/////////////////////////////////////////////////////////////////////////////////////////////////
// Populates second select (name = reason2) box and determines first select box (name = reason1) 
// variable for inner HTML text to left of second select box.  
/////////////////////////////////////////////////////////////////////////////////////////////////
function ChangeSelection(selection){
	var sel = selection.value;
	//alert("Selection is " + sel);
	var tude = document.getElementById("section2_Text").innerHTML;
		switch(sel){
			case "144":
				document.getElementById("finalInfo").style.display = "";
				addHiddenInputField('msgTopic',1);
				ProvideLinks(50);
				break;
			case "4":
				document.getElementById("finalInfo").style.display = "";
				addHiddenInputField('msgTopic',1);
				ProvideLinks(75);
				break;
			case "5":
				document.getElementById("section3_Text").innerHTML="NetBranch, Bill Payer, eStatements";
				thirdTier=1;
				FigureFunc();
				break;
			case "6":
				document.getElementById("section3_Text").innerHTML="Insurance and Investment Products";
				thirdTier=2;
				FigureFunc();
				break;
			case "7":
				document.getElementById("section3_Text").innerHTML="Products and Services";
				thirdTier=3;
				FigureFunc();
				break;
			case "8":
				document.getElementById("section3_Text").innerHTML="Membership";
				thirdTier=4;
				FigureFunc();
				break;
			case "9":
				document.getElementById("section3_Text").innerHTML="Mortgages";
				thirdTier=5;
				FigureFunc();
				break;
			case "10":
				document.getElementById("section3_Text").innerHTML="Fees";
				thirdTier=8;
				FigureFunc();
				break;
			case "11":
				document.getElementById("section3_Text").innerHTML="Something Else";
				break;
			case "12":
				document.getElementById("section3_Text").innerHTML="Community Outreach";
				thirdTier=9;
				FigureFunc();
				break;
			case "13":
				document.getElementById("section3_Text").innerHTML="Vehicle Title/Lien";
				thirdTier=7;
				FigureFunc();
				break;
		}
	function FigureFunc(){
		if (tude =="A Question about..."){
			FinalizeQuestion(thirdTier);
		} else {
			FinalizeOptions(thirdTier);
			//alert (thirdTier);
		}
	}
}
//////////////////////////////////////////////////////////////////////////////////////////
// second level select box expansion and population of fields based on
// choice of first level selection	
//////////////////////////////////////////////////////////////////////////////////////////
function XpandOptions(digit){
	var encountered = digit;
	document.getElementById("section3").style.display = "none";
	document.getElementById("section2").style.display = "";
	document.getElementById("links").style.display = "none";
	document.getElementById("finalInfo").style.display = "none";
	document.myform.reason2.options.length = 0;
	if (encountered==2){
		document.myform.reason2.options[0] = new Option("NetBranch", "144", false, false);
		document.myform.reason2.options[1] = new Option("Applefcu.org website", "4", false, false);
		document.myform.reason2.options[2] = new Option("Appleservices.com website", "4", false, false);
		document.myform.reason2.options[3] = new Option("Apple's PAT phone system", "4", false, false);
		document.myform.reason2.options[4] = new Option("Other technical issue", "4", false, false);
		addHiddenInputField('msgChoice',"Report an Error");
		addHiddenInputField('msgTopic',3);
	} else {
		document.myform.reason2.options[0] = new Option("NetBranch, Bill Payer, eStatements", "5", false, false);
		document.myform.reason2.options[1] = new Option("Products and Services", "7", false, false);
		document.myform.reason2.options[2] = new Option("Membership", "8", false, false);
		document.myform.reason2.options[3] = new Option("Mortgages", "9", false, false);
		document.myform.reason2.options[4] = new Option("Fees", "10", false, false);
		document.myform.reason2.options[5] = new Option("Vehicle Title/Lien", "13", false, false);
		document.myform.reason2.options[6] = new Option("Insurance and Investment Products", "6", false, false);	
		document.myform.reason2.options[7] = new Option("Community Outreach", "12", false, false);
		document.myform.reason2.options[8] = new Option("Something else", "4", false, false);
	}
}
function FinalizeQuestion(thirdTier){
	var finisher = thirdTier;
	document.getElementById("section3").style.display = "";
	document.myform.reason3.options.length = 0;
	//alert("Finish=" + finisher);
	switch(thirdTier){
	//netbranch, billpayer, estatements
	case 1:
		document.myform.reason3.options[0] = new Option("How do I sign-up for NetBranch?", "6", false, false);
		document.myform.reason3.options[1] = new Option("Is NetBranch not working?", "4", false, false);
		document.myform.reason3.options[2] = new Option("Why aren't all my accounts showing in NetBranch?", "5", false, false);
		document.myform.reason3.options[3] = new Option("How do I sign-up for Bill Payer?", "1", false, false);
		document.myform.reason3.options[4] = new Option("What is Bill Payer?", "1", false, false);
		document.myform.reason3.options[5] = new Option("Why Didn't my Bill Payer payment go through?", "10", false, false);
		document.myform.reason3.options[6] = new Option("Why is my Bill Payer service listed as inactive?", "9", false, false);
		document.myform.reason3.options[7] = new Option("Why isn't my Bill Payer screen appearing?", "8", false, false);
		document.myform.reason3.options[8] = new Option("How do I get my password?", "2", false, false);
		document.myform.reason3.options[9] = new Option("How do I sign-up for eStatements?", "7", false, false);
		document.myform.reason3.options[10] = new Option("What is my user ID?", "3", false, false);
		document.myform.reason3.options[11] = new Option("Something else", "75", false, false);
		topicValue = 1;
		break;
	//insurance and investment products
	case 2:
		document.myform.reason3.options[0] = new Option("How do I start investing with Apple FCU?", "11", false, false);
		document.myform.reason3.options[1] = new Option("How do I get insurance with Apple FCU?", "11", false, false);
		document.myform.reason3.options[2] = new Option("What types of insurance do you offer?", "11", false, false);
		document.myform.reason3.options[3] = new Option("Can I apply for insurance online?", "11", false, false);
		document.myform.reason3.options[4] = new Option("Do you offer tax services to members?", "11", false, false);
		document.myform.reason3.options[5] = new Option("Something else", "75", false, false);
		topicValue = 5;
		break;
	//products and services
	case 3:
		document.myform.reason3.options[0] = new Option("How do I apply for a checking account?", "18", false, false);
		document.myform.reason3.options[1] = new Option("How do I open a savings account?", "19", false, false);
		document.myform.reason3.options[2] = new Option("What are the qualifications for opening an account?", "12", false, false);
		document.myform.reason3.options[3] = new Option("What kinds of savings accounts do you offer?", "19", false, false);
		document.myform.reason3.options[4] = new Option("How do I open an IRA?", "20", false, false);
		document.myform.reason3.options[5] = new Option("What is an eXtras student savings account?", "19", false, false);
		document.myform.reason3.options[6] = new Option("What is a CoreHealth loan?", "25", false, false);
		document.myform.reason3.options[7] = new Option("What are Education and Tuition Loans?", "28", false, false);
		document.myform.reason3.options[8] = new Option("How do I get a Credit Card?", "30", false, false);
		document.myform.reason3.options[9] = new Option("What is the Money Market/Super Money Market Account?", "35", false, false);
		document.myform.reason3.options[10] = new Option("What kinds of Certificates do you offer?", "21", false, false);
		document.myform.reason3.options[11] = new Option("How do I renew or withdraw a certificate that is maturing?", "22", false, false);
		document.myform.reason3.options[12] = new Option("What is the status of my existing loan application?", "23", false, false);
		document.myform.reason3.options[13] = new Option("How do I apply for a vehicle loan?", "24", false, false);
		document.myform.reason3.options[14] = new Option("What is a Signature loan?", "27", false, false);
		document.myform.reason3.options[15] = new Option("How do I increase my Line of Credit?", "29", false, false);
		document.myform.reason3.options[16] = new Option("What are the qualifications of applying for an Apple FCU Education or Tuition Loan?", "28", false, false);
		document.myform.reason3.options[17] = new Option("What kinds of credit cards do you offer?", "30", false, false);
		document.myform.reason3.options[18] = new Option("How do I request a Visa Check Card for my Apple FCU Checking Account?", "31", false, false);
		document.myform.reason3.options[19] = new Option("How do I report my card as lost/stolen?", "36", false, false);
		document.myform.reason3.options[20] = new Option("Why haven't I received the PIN for my replacement Visa Check Card?", "32", false, false);
		document.myform.reason3.options[21] = new Option("Something else", "75", false, false);
		topicValue = 1;
		break;
	//membership
	case 4:
		document.myform.reason3.options[0] = new Option("How do I become a member?", "12", false, false);
		document.myform.reason3.options[1] = new Option("Who is eligible for membership?", "12", false, false);
		document.myform.reason3.options[2] = new Option("How do I offer Apple membership to my employees?", "75", false, false);
		document.myform.reason3.options[3] = new Option("How do I get my employer listed on the Select Employer Group list?", "75", false, false);
		document.myform.reason3.options[4] = new Option("Something else", "75", false, false);
		topicValue = 4;
		break;
	//mortgages
	case 5:
		document.myform.reason3.options[0] = new Option("How do I apply for a mortgage?", "13", false, false);
		document.myform.reason3.options[1] = new Option("What fees/costs are there for a mortgage with Apple?", "14", false, false);
		document.myform.reason3.options[2] = new Option("What are your mortgage rates?", "13", false, false);
		document.myform.reason3.options[3] = new Option("How long will it take for decision on my mortgage application?", "37", false, false);
		document.myform.reason3.options[4] = new Option("What is my mortgage payoff?", "75", false, false);
		document.myform.reason3.options[5] = new Option("How can I make extra payments towards principal?", "15", false, false);
		document.myform.reason3.options[6] = new Option("How can I figure out what my new HELOC payment will be?", "16", false, false);
		document.myform.reason3.options[7] = new Option("What is my HELOC payoff amount?", "17", false, false);
		document.myform.reason3.options[8] = new Option("Something else", "75", false, false);
		topicValue = 1;
		break;
	//community outreach
	case 6:
		document.myform.reason3.options[0] = new Option("How do I  get information on the Scholarship Program?", "75", false, false);
		document.myform.reason3.options[1] = new Option("What kinds of Community Outreach Programs does AFCU participate in?", "75", false, false);
		document.myform.reason3.options[2] = new Option("Something else", "75", false, false);
		topicValue = 7;
		break;
	//vehicle liens
	case 7:
		document.myform.reason3.options[0] = new Option("How long will it take to recieve my vehicles title once the loan is paid off?", "33", false, false);
		document.myform.reason3.options[1] = new Option("Does Apple FCU need to be listed as the lien holder of my vehicle?", "34", false, false);
		document.myform.reason3.options[2] = new Option("Do I transfer the title of a car I purchased from a private party to Apple FCU?", "75", false, false);
		document.myform.reason3.options[3] = new Option("Something else", "75", false, false);
		topicValue = 1;
		break;
	//fees
	case 8:
		document.myform.reason3.options[0] = new Option("Why was I charged a maintenance fee?", "39", false, false);
		document.myform.reason3.options[1] = new Option("Why was I charged an overdraft or insufficent funds fee?", "40", false, false);
		document.myform.reason3.options[2] = new Option("Why was I charged a bad address fee?", "41", false, false);
		document.myform.reason3.options[3] = new Option("Why was I charged a dormant account fee?", "42", false, false);
		document.myform.reason3.options[4] = new Option("Why was I charged a transfer fee?", "43", false, false);
		document.myform.reason3.options[5] = new Option("Why was I charged a fee for my electronic payment or transfer?", "44", false, false);
		document.myform.reason3.options[6] = new Option("Why was I charged an ATM fee?", "45", false, false);
		document.myform.reason3.options[7] = new Option("Why was I charged a shared branch useage fee?", "46", false, false);
		topicValue = 2;
		break;
	//community outreach
	case 9:
		document.myform.reason3.options[0] = new Option("What community outreach programs are you involved with?", "75", false, false);
		document.myform.reason3.options[1] = new Option("How does Apple give back to the community?", "49", false, false);
		topicValue = 7;
		break;
		
	}
	addHiddenInputField('msgTopic',topicValue);
	//alert("Topic=" + topicValue);
}
//////////////////////////////////////////////////////
//				Request Information					//
//////////////////////////////////////////////////////
function FinalizeOptions(thirdTier){
	var finisher = thirdTier;
	var topicValue;
	document.getElementById("section3").style.display = "";
	document.myform.reason3.options.length = 0;
	switch(thirdTier){
	//netbranch, Bill Payer, estatements
	case 1:
		document.myform.reason3.options[0] = new Option("Bill Payer service", "1", false, false);
		document.myform.reason3.options[1] = new Option("Bill Payer payments", "10", false, false);
		document.myform.reason3.options[2] = new Option("eStatements", "7", false, false);
		document.myform.reason3.options[3] = new Option("Inaccessible account", "4", false, false);
		document.myform.reason3.options[4] = new Option("Information about my account", "5", false, false);
		document.myform.reason3.options[5] = new Option("NetBranch Enrollment", "6", false, false);
		document.myform.reason3.options[6] = new Option("NetBranch status", "4", false, false);
		document.myform.reason3.options[7] = new Option("Resetting my password", "2", false, false);
		document.myform.reason3.options[8] = new Option("Signing up", "1", false, false);
		document.myform.reason3.options[9] = new Option("Something else", "75", false, false);
		topicValue = 1;
		break;
	//insurance and investment products
	case 2:
		document.myform.reason3.options[0] = new Option("Apple Financial Services - Insurance, Investments, Tax Preperation", "11", false, false);
		document.myform.reason3.options[1] = new Option("Something else", "75", false, false);
		topicValue = 5;
		break;
	//products and services
	case 3:		
		document.myform.reason3.options[0] = new Option("Certificates", "21", false, false);
		document.myform.reason3.options[1] = new Option("Checking Accounts", "18", false, false);
		document.myform.reason3.options[2] = new Option("CoreHealth/Medical Loans", "25", false, false);
		document.myform.reason3.options[3] = new Option("Credit Cards", "30", false, false);
		document.myform.reason3.options[4] = new Option("Education and Tuition Loans", "28", false, false);
		document.myform.reason3.options[5] = new Option("Increase in Credit Line", "29", false, false);
		document.myform.reason3.options[6] = new Option("IRA", "20", false, false);
		document.myform.reason3.options[7] = new Option("Money Market Account", "35", false, false);
		document.myform.reason3.options[8] = new Option("Rates", "38", false, false);
		document.myform.reason3.options[9] = new Option("Savings Accounts", "19", false, false);
		document.myform.reason3.options[10] = new Option("Vehicle Loans", "24", false, false);
		document.myform.reason3.options[11] = new Option("Something else", "75", false, false);
		topicValue = 1;
		break;
	//membership
	case 4:
		document.myform.reason3.options[0] = new Option("Joining Apple Federal Credit Union", "12", false, false);
		document.myform.reason3.options[1] = new Option("Offering Apple Membership as an employer benefit", "48", false, false);
		document.myform.reason3.options[2] = new Option("Something else", "75", false, false);
		topicValue = 4;
		break;
	//mortgages
	case 5:
		document.myform.reason3.options[0] = new Option("Applying for a Mortgage", "13", false, false);
		document.myform.reason3.options[1] = new Option("Apple's CU Realty Rebate Program", "13", false, false);
		document.myform.reason3.options[2] = new Option("Costs associated with an Apple Mortgage", "14", false, false);
		document.myform.reason3.options[3] = new Option("First Mortgage payoff", "75", false, false);
		document.myform.reason3.options[4] = new Option("Home Equity, HELOC, Second Mortgage payoff/payment information", "17", false, false);
		document.myform.reason3.options[5] = new Option("Something else", "75", false, false);
		topicValue = 1;
		break;
	//vehicle liens
	case 7:
		document.myform.reason3.options[0] = new Option("Vehicles title after loan paid off", "33", false, false);
		document.myform.reason3.options[1] = new Option("Listing Apple as the lien holder of my vehicle", "34", false, false);
		document.myform.reason3.options[2] = new Option("Transfer the title of a car I purchased to Apple FCU", "75", false, false);
		document.myform.reason3.options[3] = new Option("Something else", "75", false, false);
		topicValue = 1;
		break;
	//fees
	case 8:
		document.myform.reason3.options[0] = new Option("ATM Fee", "45", false, false);
		document.myform.reason3.options[1] = new Option("Bad Address Fee", "41", false, false);
		document.myform.reason3.options[2] = new Option("Dormant Account Fee", "42", false, false);
		document.myform.reason3.options[3] = new Option("Electronic Payment/Transfer Fee", "44", false, false);
		document.myform.reason3.options[4] = new Option("Maintenance Fee (Advantage checking)", "39", false, false);
		document.myform.reason3.options[5] = new Option("Overdraft/Insufficient Funds Fee", "40", false, false);
		document.myform.reason3.options[6] = new Option("Transfer Fee", "43", false, false);
		document.myform.reason3.options[7] = new Option("Shared Branch Usage Fee", "46", false, false);
		document.myform.reason3.options[8] = new Option("Wire Transfer Fee", "47", false, false);
		topicValue = 2;
		break;
	//community outreach
	case 9:
		document.myform.reason3.options[0] = new Option("Scholarships", "49", false, false);
		topicValue = 7;
		break;
	}
	addHiddenInputField('msgTopic',topicValue);
}
function ProvideLinks(answer){
	var blankRE=/^\s*$/;
	var foo;
	var complainer;
	if (answer == 50){
		foo = "50";
	} else if (answer == 77){
		foo = "77";
	} else {
		foo = answer.value;
	}
	var message;
	var linksArray = new Array();
	switch(foo){
		//billpayer sign-up
		case "1":
			linksArray = new Array('https://www.applefcu.org/24hourservices.asp#billpayer','Sign-up for Bill Payer');
			break;
		//resetting password	
		case "2":
			linksArray = new Array('https://netbranch.applefcu.org/applefcu/passwordreset/passwordreset.aspx','Resetting your password','https://www.applefcu.org/nbsecurity.asp','NetBranch Security');
			break;
		//NetBranch User ID
		case "3":
			message = "Your User ID for NetBranch is your member number. Your member number can be found on your statements and is between 4-6 numbers long. If you do not know your member number or can not find it on your statement you must come in to any of our branch locations. Member numbers can not be given over the phone for security reasons."
			break;
		//NetBranch Technical difficulties
		case "4":
			message = "NetBranch may be experiencing technical difficulties. Please visit the home page of the website for an update. If there is no status update and the problem persists for 24 hours or longer please contact our Call Center at 703-788-4800."
			break;
		//Netbranch account visibility	
		case "5":
			message = "NetBranch may be experiencing technical difficulties resulting in all of your accounts not being visible. Please check the home page of the website for the status of NetBranch.<br><br>If you have an Apple FCU loan or Visa Credit Card that is delinquent you must contact our Call Center at 703-788-4800 or stop by any branch location.  You must bring your loan or Visa Credit Card up to date before it will appear online."
			break;
		//Netbranch sign-up
		case "6":
			message = "To sign up for NetBranch please either contact our Call Center at 703-788-4800 or stop by any of our branch locations to speak with a representative."
			break;
		//estatements	
		case "7":
			linksArray = new Array('https://clientadmin.digitalmailer.com/ClientFiles/106/pickupestatements.html','Signing Up for eStatements','https://www.applefcu.org/24hourservices.asp#estatements','What are eStatements?');
			break;
		//billpayer issue
		case "8":
			message = "The most common issues with Bill Payer not appearing are pop-up blockers and security settings. If you have a pop-up blocker enabled on your computer you must either turn it off or set it to allow pop-ups from the AFCU website. Also, if your internet security settings are set too high you will need to add the AFCU website to the list of trusted sites, or reduce the security settings on your computer. If neither of the above solves your problem please contact our call center at 703-788-4800."
			break;
		//billpayer account inactive
		case "9":
			message = "Bill Payer accounts are placed in an inactive status if they are not used for 6 months or longer. To reactivate your Bill Payer please contact our Call Center at 703-788-4800 or stop by any of our branch locations to speak with a representative."
			break;
		//billpayer payement not going thru
		case "10":
			message = "Your Bill Payer payment may not have gone through for a number of reasons. The most common reason is the payment being lost in the mail or lost in processing once it is received by the payee. To determine the exact reason and make arrangements to cancel the missing payment please contact our Call Center at 703-788-4800."
			break;
		//apple services
		case "11":
			linksArray = new Array('https://www.appleservices.com/investments.asp','Investing with Apple Financial Services','https://www.appleservices.com/insurance.asp','Purchasing Insurance','https://www.appleservices.com/carquote.asp','Purchasing Car Insurance','https://www.appleservices.com/homequote.asp','Purchasing Homeowners or Renters Insurance','https://www.appleservices.com/taxprep.asp','Tax Preperation Services');
			break;
		//membership
		case "12":
			linksArray = new Array('https://applefcu.umonitor.com/applefcu/welcome.do','Open an Account Now','https://www.applefcu.org/fom.asp','Membership Eligibility');
			break;
		//mortgage application
		case "13":
			linksArray = new Array('https://applefcu.mortgagewebcenter.com/ApplyNow/Application.asp?PID=1','Mortgage Application','https://www.applefcu.org/rates.asp?rateTabs=5','Current Mortgage Rates','http://applefcu.mortgagewebcenter.com/ResourceCenter/ResCtrInfo.asp?PID=120','Mortgage Center Resources','https://www.applefcu.org/curealty.asp','CURealty Rebate Program');
			break;
		//mortgage costs
		case "14":
			linksArray = new Array('http://applefcu.mortgagewebcenter.com/ResourceCenter/ResCtrInfo.asp?PID=120#1002562','Costs associated with a Mortgage at Apple','http://applefcu.mortgagewebcenter.com/ResourceCenter/ResCtrInfo.asp?PID=120','Mortgage Center Resources');
			break;
		//extra mortgage payments
		case "15":
			message = "In order to make extra payments towards the principal balance of your mortgage you must contact our Call Center at 703-788-4800. Please be sure to advise the representative on the phone that you wish to apply the extra payment towards principal only. Otherwise, the payment will be credited to principal and interest.";
			break;
		//heloc payment
		case "16":
			message = "Your new HELOC payment will be 1% of the balance after your advance. Your monthly payment will not change until you make an advance from your HELOC.";
			break;
		//heloc payoff	
		case "17":
			message = "You can view your HELOC payoff amount by logging into your account on NetBranch. If you are not a NetBranch user please contact our call center at 703-788-4800 or stop by any branch location to obtain your payoff information.";
			break;
		//checking accounts
		case "18":
			linksArray = new Array('https://www.applefcu.org/checking.asp','Apple\'s checking accounts','https://www.applefcu.org/check_chart.asp','Compare Apple Checking accounts');
			break;
		//savings accounts	
		case "19":
			linksArray = new Array('https://www.applefcu.org/savings.asp','Apple\'s savings accounts','https://www.applefcu.org/savings03.asp','Apple\'s eXtras Student Savings Account');
			break;
		//retirement accounts
		case "20":
			linksArray = new Array('https://www.applefcu.org/savings02.asp','Individual Retirement Accounts','https://www2.iraservicecenter.com/irasc/\?OrgNbr=904607','IRA Service Center','https://www.applefcu.org/rates.asp?rateTabs=1','Current Certificate Rates');
			break;
		//certificates
		case "21":
			linksArray = new Array('https://www.applefcu.org/savings01.asp','Certificates','https://www.applefcu.org/rates.asp?rateTabs=1','Current Certificate Rates');
			break;
		//certificate renewal
		case "22":
			message = "You should receive a maturity notice in the mail approximately two weeks prior to the maturity date of your certificate. You may fill out the renewal or withdrawal instructions on the notice and mail it back to us at the return address included. If you do not have your maturity notice you may contact our call center at 703-788-4800 or stop by any of our branch locations to speak with a representative.";
			break;
		//loan application status
		case "23":
			message = "To check the status of your existing loan application please contact our call center at 703-788-4800 or stop by any of our branch locations to speak with a representative.";
			break;
		//vehicle loans
		case "24":
			linksArray = new Array('https://www.applefcu.org/loan05.asp','Apple\'s vehicle loans','loanRedirect.asp','Apply for a vehicle loan','https://www.applefcu.org/rates.asp?rateTabs=2','Current vehicle loan rates','https://www.applefcu.org/loan05e.asp','Vehicle Purchase Resources');
			break;
		//corehealth and medical loans
		case "25":
			linksArray = new Array('https://www.applefcu.org/loan02.asp#health','Apple\'s CoreHealth Loan','https://www.applefcu.org/rates.asp?rateTabs=4','Current CoreHealth/Medical Loan ratea','loanRedirect.asp','Apply for a CoreHealth Loan');
			break;
		//home equity
		case "26":
			linksArray = new Array('https://www.applefcu.org/homequity.asp','Apple\'s Home Equity Line of Credit');
			break;
		//signature loans
		case "27":
			linksArray = new Array('https://www.applefcu.org/loan02.asp','Apple\'s Signature Loan');
			break;
		//education and tuition loans
		case "28":
			linksArray = new Array('https://www.applefcu.org/loan04.asp','Apple\'s Education and Tuition Loans','https://www.applefcu.org/rates.asp?rateTabs=4','Current rates on Education Loans');
			break;
		//line of credit increase
		case "29":
			message = "In order to increase your existing Line of Credit you must submit an application. Please contact our Call Center at 703-788-4800 or stop by any of our branch locations to speak with a representative about submitting an increase application.";
			break;
		//credit cards
		case "30":
			linksArray = new Array('https://www.applefcu.org/loan01.asp','Apple\'s Credit Cards','https://www.applefcu.org/ccdisclosure.asp','Visa Card Disclocure','loanRedirect.asp','Apply for a Credit Card');
			break;
		//check card request
		case "31":
			message = "To request a Visa Check Card for your Apple FCU Checking Account please contact our call center at 703-788-4800 or stop by any of our branch locations.";
			break;
		//PIN number for card
		case "32":
			message = "The PIN for your Visa Check Card should arrive within 2-3 days of your card being received. If it does not, please contact our call center at 703-788-4800 or stop by any of our branch locations so that we may order you a new one.";
			break;
		//title after payoff
		case "33":
			message = "Once your loan is paid in full you should receive your title within 2-3 weeks.";
			break;
		//lien holder
		case "34":
			message = "Yes, Apple Federal Credit Union must be listed as the lien holder of the vehicle until the loan is paid in full.";
			break;
		//money market
		case "35":
			 linksArray = new Array('https://www.applefcu.org/savings06.asp','Apple\'s Money Market Accounts','https://www.applefcu.org/rates.asp?rateTabs=0','Current rates on Money Market Accounts');
			 break;
		//lost or stolen cards	 
		case "36":
			 linksArray = new Array('http://applefcu.custhelp.com/cgi-bin/applefcu.cfg/php/enduser/std_adp.php?p_faqid=121&p_created=1111758675&p_sid=34OG3S7j&p_accessibility=0&p_redirect=&p_lva=&p_sp=cF9zcmNoPTEmcF9zb3J0X2J5PSZwX2dyaWRzb3J0PSZwX3Jvd19jbnQ9MiwyJnBfcHJvZHM9MjgmcF9jYXRzPTAmcF9wdj0xLjI4JnBfY3Y9JnBfc2VhcmNoX3R5cGU9YW5zd2Vycy5zZWFyY2hfbmwmcF9wYWdlPTEmcF9zZWFyY2hfdGV4dD1sb3N0&p_li=&p_topview=1','Report your card as lost/stolen');
			 break;
		//mortgage timing
		case "37":
			message = "Apple FCU strives to have all loans originated and closed within 30-45 days.";
			break;
		//rates
		case "38":
			linksArray = new Array('https://www.applefcu.org/rates.asp','Apple\'s Current Rates');
			break;
		//maintenance fee
		case "39":
			message = "The Advantage Checking maintenance fee is assessed when the requirements are not met. You must maintain a combined savings or loan balance of $20,000 or greater. If you do not meet the savings and loan balance requirement, you must have a mininum $1,000 direct deposit accompanied with two electronic(ACH) bill payments every month.<br><a href='rates.asp?rateTabs=7' class='alink'>Apple's Fee Schedule</a>";
			break;
		//overdraft fee
		case "40":
			message = "Overdraft fees are assessed if your account balance goes into a negative status due to a check, charge, or other transaction posting to your account when there are not enough funds. The overdraft fee is the cost associated with Apple FCU paying this charge through overdraft privilege on your account.<br><br> Insufficient funds fees are assessed when you have exceeded the amount allowed for overdraft privilege. Insufficient funds fees are also assessed if you do not have overdraft privilege, your overdraft privilege has been suspended for misuse, or the account being charged is not covered by overdraft privilege (savings, money market, etc.).<br><br>To avoid being charged an overdraft or insuffient funds fee it is necessary to monitor your account balances and keep track of what charges are pending, what charges have cleared, and any charges, checks, or electronic debits that may be outstanding.<br><a href='rates.asp?rateTabs=7' class='alink'>Apple's Fee Schedule</a>";
			break;
		//bad address fee
		case "41":
			message = "Bad Address fees are assessed when the address on your account is invalid or no longer current. If we receive returned mail from the post office , your account will be noted with a bad address status. If you stop receiving Apple FCU mail or statements it is a good idea to contact us at 703-788-4800 to ensure the address we have on file is current.<br><a href='rates.asp?rateTabs=7' class='alink'>Apple's Fee Schedule</a>";
			break;
		//dormant account fee
		case "42":
			message = "Savings accounts with a balance less than $100 will be charged a dormant account fee after one year of inactivity. Checking accounts with a balance less than $500 will be charged a dormant account fee after one year of inactivity.<br><a href='rates.asp?rateTabs=7' class='alink'>Apple's Fee Schedule</a>";
			break;
		//transfer fees
		case "43":
			message = "Transfer fees are assessed when funds are required to be automatically transferred from your savings to your checking account to cover a transaction. This can be avoided by ensuring you keep enough money in your checking account to cover all outstanding transactions.<br><a href='rates.asp?rateTabs=7' class='alink'>Apple's Fee Schedule</a>";
			break;
		//ACH fee
		case "44":
			message = "The $5 ACH fee is the cost associated with Apple FCU initiating an ACH payment.<br><a href='rates.asp?rateTabs=7' class='alink'>Apple's Fee Schedule</a>";
			break;
		//ATM fee
		case "45":
			message = "ATM fees are assessed if you exceed the amount of foreign ATM uses allotted. A+ checking offers two(2) free foreign ATM uses and Advantage checking offers unlimited foreign ATM use. Other institutions may impose a surcharge fee. Please read the surcharge disclosure on the ATM machine before finalizing your transaction.<br><a href='rates.asp?rateTabs=7' class='alink'>Apple's Fee Schedule</a>";
			break;
		//shared branch fee
		case "46":
			message = "Shared branch useage fees are assessed after two withdrawals from a shared branch location per calendar month.<br><a href='rates.asp?rateTabs=7' class='alink'>Apple's Fee Schedule</a>";
			break;
		//wire transfer fee
		case "47":
			message = "<a href='rates.asp?rateTabs=7' class='alink'>Apple's Fee Schedule</a>";
			break;
		case "48":
			linksArray = new Array('https://www.applefcu.org/benefits.asp','Offering Apple Membership as a Benefit');
			break;
		//Apple Education Foundation
		case "49":
			linksArray = new Array('http://www.afcufoundation.org/','Apple\'s Education Foundation');
			break;
		//DI and f'in ELS bullshit response Stupid talking monkeys
		case "50":
			message = "An Apple Representative will be available to assist you with trouble-shooting current NetBranch issues, during our operating hours. Please use the form below to submit your issues in detail; include your browser (i.e. Internet Explorer 7.0, Mac OS 5) and complete contact information (phone and email).";
			break;
		//Complaint
		case "77":
			message = "Apple appreciates your concerns, and we look forward to assisting you.  Please tell us a little more by completing the Secure Form Information Request below.  Remember to include only details that will aid in providing the most thorough resolution possible.  The Credit Union's Message Center staff will then review this information and respond within 1-2 business days.";
			complainer = "bogus";
			break;
		//default	
		default:
			message = "We're sorry; the answer to your question is very specific and cannot be answered in this forum. However, our Message Center staff is an excellent resource for this information. Please complete our Secure Form Information Request, and we will respond usually within 1-2 business days.";		
	}
	document.getElementById("links").style.display = "";
	document.getElementById("finalInfo").style.display = "";
	var foobar = " ";
	if (!message) {
		document.getElementById("helpText").innerHTML = "Other members have found these links helpful:";
		for (i=0;i<linksArray.length;i++)
		{				
			foobar = foobar + "<strong><a href='" + linksArray[i] + "' class='alink'>" + linksArray[++i] + "</a></strong><br>";
		}
		document.getElementById("section4_Text").innerHTML = foobar;
	} else {
		if (complainer != "bogus")  {
			//alert(complainer);
			document.getElementById("helpText").innerHTML = "Possible Solution:";
			document.getElementById("section4_Text").innerHTML = "<p class='hptext'>" + message + "</p>";
		} else {
			//alert(complainer);
			document.getElementById("helpText").innerHTML = "Thank You for Bringing This to Our Attention.";
			document.getElementById("section4_Text").innerHTML = "<p class='hptext'>" + message + "</p>";
			addHiddenInputField('msgTopic',topicValue);
			endValue = "Complaint";
		}
	}
	if (document.getElementById("section2").style.display != "none" || blankRE.test(document.getElementById("section2").style.display)){
		endValue = document.myform.reason2.options[document.forms.myform.reason2.selectedIndex].text;
	}
	if (document.getElementById("section3").style.display != "none" || blankRE.test(document.getElementById("section3").style.display)){
		endValue = document.myform.reason3.options[document.forms.myform.reason3.selectedIndex].text;
	}
	addHiddenInputField('msgChoice',endValue);
	//alert("The final value = " + endValue);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Adds hidden input field to determine message type and routing
///////////////////////////////////////////////////////////////////////////////////////////////////////
function addHiddenInputField(fieldName, fieldValue) {
   var choice = fieldValue;
   var inputElement = document.createElement('input');
   inputElement.name = fieldName;
   inputElement.type = "hidden";
   inputElement.value = fieldValue;
   document.myform.appendChild(inputElement);
   return;
}