var config = [
	{
		"name": "Sign up for Services",
		"serviceid": "82",
		"secondaryissues": [
			{"name": "Cable"},
			{"name": "Internet"},
			{"name": "Phone"},
			{"name": "Bundles"},
			{"name": "Transfer Services"}
		],
		"links": [
			"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/189/Cable/Service-Locator\">Service Locator</a>",
			"<a target=\"_blank=\" href=\"http://www.midcocomm.com/cable/programming/channellineups/\">Channel Line-Ups</a>",
			"<a target=\"_blank=\" href=\"http://www.midcocomm.com/aboutmidcontinent/locations/\">Visit us at a Customer Service Center</a>",
			"Call 1.800.888.1300"
		]
	},
	{
		"name": "Billing",
		"serviceid":"80",
		"secondaryissues": [
			{
				"name": "Online Billpayment (EZ-Pay)",
				"links": [
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/11/Welcome--New-Charter-Customers/EZ-Pay-Overview\">How to use EZ-Pay</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/14/Customer-Service--Understanding-Your-Bill/EZ-Pay-FAQs\">EZ-Pay FAQ's</a>"
				]
			},
			{
				"name": "Payment Inquiry",
				"links": [
					"To check the status of your payment, please call 1-800-888-1300 and use our self help option.",
					"To make a payment arrangement please call us at 1-800-888-1300."
				]
			},
			{
				"name": "Questions about my bill",
				"links": [
					"<a target=\"_blank=\" href=\"http://midcocomm.com/classlibrary/page/resourcecenter/files/27.pdf\">How to Read Your Bill</a>",
					"<a target=\"_blank=\" href=\"http://midcocomm.com/resourcecenter/index.cfm/105/Customer-Service--Understanding-Your-Bill/What-are-the-taxes-and-fees-on-my-telephone-bill-\">Phone Taxes on My Bill</a>",
					"<a target=\"_blank=\" href=\"http://midcocomm.com/resourcecenter/index.cfm/20/Customer-Service--Understanding-Your-Bill/Why-does-my-have-more-than-1-months-charges\">Why do I have more than 1 month of charges?</a>"
				]
			},
			{ "name": "Coupon Redemption " }
		]
	},
	{
		"name": "Cable TV Support",
		"serviceid": "81",
		"secondaryissues": [
			{
				"name": "Cable Service Issues",
				"links": [
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/50/Cable/My-cable-is-not-working-what-should-I-do-\">My Cable is not working, what should I do?</a>"
				]
			},
			{
				"name": "Cable Equipment",
				"links": [
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/classlibrary/page/resourcecenter/files/43.pdf\">Digital Receiver Manual - DCT 2000</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/classlibrary/page/resourcecenter/files/45.pdf\">Digital Receiver Manual - DCT 6200</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/classlibrary/page/resourcecenter/files/44.pdf\">Digital Receiver Manual - DCT 2500</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/classlibrary/page/resourcecenter/files/46.pdf\">Digital Receiver Manual - DCT 6208</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/classlibrary/page/resourcecenter/files/36.pdf\">DCH 5712/2416 Manual</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/classlibrary/page/resourcecenter/files/32.pdf\">DCH 6416 Manual</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/classlibrary/page/resourcecenter/files/110.pdf\">HD/DVR Self Install Guide </a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/classlibrary/page/resourcecenter/files/25.pdf\">DVR How To Guide</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/classlibrary/page/resourcecenter/files/24.pdf\">i-Guide User Manual </a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/50/Cable/My-cable-is-not-working-what-should-I-do-\">My Cable is not working, what should I do?</a>",
					"<a target=\"_blank\" onclick=\"window.open('/ClassLibrary/_includes/dvr/index.htm','tut_win','height=650,width=770'); return false;\" href=\"/ClassLibrary/_includes/dvr/index.htm\">DVR Tutorial</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/7-4/DVR#item__29\">DVR FAQs </a>"
				]
			},
			{
				"name": "Remote Control ",
				"links": [
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/266/Cable--Your-Remote/Remote-Controls\">Remote Control User Guides </a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/51/Cable/My-remote-is-not-working-what-should-I-do-\">My remote is not working, what should I do?</a>"
				]
			},
			{
				"name": "Pay-Per-View/VOD ",
				"links": [
					"<a target=\"_blank\" onclick=\"window.open('/ClassLibrary/_includes/ondemand/index.htm','tut_win','height=650,width=770'); return false;\" href=\"/ClassLibrary/_includes/ondemand/index.htm\">On Demand Tutorial</a>"
				]
			},
			{
				"name": "HD Questions",
				"links": [
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/7/Cable--HD/Is-it-HD\">Is it HD?</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/21/Cable--HD/Does-HD-service-cost-more\">Does HD service cost more?</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/17/Cable--HD/What-type-of-equipment-will-I-need-to-receive-the-HD-signal-\">What type of equipment do I need to receive the HD signal?</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/6/Cable--HD/HD-Televisions\">HD Televisions</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/classlibrary/page/resourcecenter/files/110.pdf\">HD/DVR Self Install Guide </a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/6/HD#item__15\">HD FAQ's</a>"
				]
			}
		]
	},
	{
		"name": "Programming",
		"serviceid": "80",
		"secondaryissues": [
			{
				"name": "Comment about channel/program",
				"links": [
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/cable/programming/channellineups/\">Channel Line-Ups </a>"
				]
			},
			{
				"name": "Request a New Channel ",
				"links": [
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/cable/programming/channellineups/\">Channel Line-Ups </a>"
				]
			},
			{
				"name": "Parental Controls",
				"links": [
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/168/Cable/Digital-Family-Tier-Information\">Digital Family Friendly Tier Information</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/165/Cable/Parental-Controls\">Parental Controls</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/classlibrary/page/resourcecenter/files/74.pdf\">V-Chip</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/23/Cable/Do-I-need-special-equipment-to-block-a-channel\">Do I need Special Equipment to Block a Channel?</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/24/Cable/Does-FREE-Channel-Blocking-control-all-TV-sets-in-my-house-\">Does free Channel Blocking control all TV sets in my house?</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/25/Cable/How-can-I-restrict-objectionable-content-on-my-television-\">How can I restrict objectionable content on my television?</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/47/Cable/If-I-have-lost-power-will-I-lose-my-ParentalPurchase-Codes-Favorites-Reminders-or-Locks\">If I lost power, will I lose my Parental Codes?</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/53/Cable/What-does-it-cost-to-block-channels-I-feel-are-inappropriate-\">What does it cost to block channels I feel are inappropriate?</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/31/Cable/What-should-I-do-if-I-forget-the-Parental-or-Purchasing-lock-codes-\">What should I do if I forget the Parental lock codes?</a>"
				]
			},
			{
				"name": "Premium Digital Channels",
				"links": [
					"<a target=\"_blank=\" href=\"http://www.hbo.com/\">HBO</a>",
					"<a target=\"_blank=\" href=\"http://www.starz.com/\">Starz</a> and <a target=\"_blank=\" href=\"http://www.starz.com/channels/encore/\">Encore</a>",
					"<a target=\"_blank=\" href=\"http://www.sho.com/site/index.html\">Showtime</a> and <a target=\"_blank=\" href=\"http://www.sho.com/site/tmc/flash_home.do?pass_variable=&amp;pass_variable_2=&amp;pass_variable_3=&amp;altContentURL=/site/tmc/getflash.do?pass_variable=&amp;pass_variable_2=&amp;pass_variable_3=\">The Movie Channel</a>",
					"<a target=\"_blank=\" href=\"http://www.cinemax.com/\">Cinemax</a>"
				]
			},
			{
				"name": "On Demand/Pay Per View",
				"links": [
					"<a target=\"_blank\" onclick=\"window.open('/ClassLibrary/_includes/ondemand/index.htm','tut_win','height=650,width=770'); return false;\" href=\"/ClassLibrary/_includes/ondemand/index.htm\">On Demand Tutorial</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/139/Cable--On-Demand/New-Releases\">New Releases</a>"
				]
			},
			{
				"name": "DTV Questions ",
				"links": [
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/140/Cable--DTV-Transition/What-is-the-Digital-Transition\">What is the Digital Transition?  </a>"
				]
			}
		]
	},
	{
		"name": "Internet Support",
		"serviceid": "81",
		"secondaryissues": [
			{
				"name": "Internet Service Issues",
				"links": [
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/111/MidcoNet-Broadband/How-do-I-reboot-my-cable-modem-\">How do I reboot my cable modem?</a> (<a target=\"_blank=\" href=\"http://www.midcocomm.com/classlibrary/page/resourcecenter/files/100.pdf#page=13&amp;zoom=100,0,0\">Midconet User's Guide</a>)",
					"<a target=\"_blank=\" href=\"http://support-test.midco.net/\">Internet Speed Test</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/classlibrary/page/resourcecenter/files/100.pdf#page=7&amp;zoom=100,0,0\">Midconet User's Guide</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/108/MidcoNet-Broadband/Why-does-my-Internet-speed-seem-to-be-slower\">Why does my Internet speed seem to be slower?</a>"
				],
				"note": "Please provide any available details about your operating system, the current program you've experienced issues with and any error messages you may be receiving"
			},
			{
				"name": "Wireless Questions",
				"links": [
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/classlibrary/page/resourcecenter/files/100.pdf#page=14&amp;zoom=100,0,0\">Midconet User's Guide</a>"
				],
				"note": "Please provide any available details about your operating system, the current program you've experienced issues with and any error messages you may be receiving"
			},
			{
				"name": "Personal WebSpace",
				"links": [
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/classlibrary/page/resourcecenter/files/100.pdf#page=11&amp;zoom=100,0,0\">Midconet User's Guide</a>"
				],
				"note": "Please provide any available details about your operating system, the current program you've experienced issues with and any error messages you may be receiving"
			}
		]
	},
	{
		"name": "MyMidco/Online Ordering",
		"serviceid": "81",
		"secondaryissues": [
			{
				"name": "Report an Error",
				"note": "Please provide any available details about your operating system, the current program you've experienced issues with and any error messages you may be receiving"
			},
			{
				"name": "Help Creating an Account",
				"links": [
					"<a href=\"http://www.midcocomm.com/resourcecenter/index.cfm/326/MyMidco-User-Guide--Online-Bill-Pay/Setting-up-for-your-MyMidco-account-with-Online-Bill-Pay-for-a-New-User-\">Setting-up for your MyMidco account with Online Bill Pay for a New User</a>",
					"<a href=\"http://www.midcocomm.com/resourcecenter/index.cfm/327/MyMidco-User-Guide--Online-Bill-Pay/Setting-up-for-your-MyMidco-account-with-Online-Bill-Pay-for-existing-EZ-Pay-User-\">Setting-up for your MyMidco account with Online Bill Pay for existing EZ Pay User </a>"
				]
			},
			{
				"name": "Help Changing Account Information",
				"links": [
					"<a href=\"http://www.midcocomm.com/resourcecenter/index.cfm/366/MyMidco-User-Guide/Changing-Your-Email-or-Phone-Numbers\">Changing your Email or Phone numbers</a>",
					"<a href=\"http://www.midcocomm.com/resourcecenter/index.cfm/370/MyMidco-User-Guide/Changing-Your-Password-Forgot-Password\">Changing your Password/Forgot Password</a>"
				]
			},
			{
				"name": "Help Cancelling an Account",
				"note": "Contact Midcontinent Customer Service at 1.800.888.1300"
			},
			{
				"name": "Help Setting up an Authorized User",
				"links": [
					"<a href=\"http://www.midcocomm.com/resourcecenter/index.cfm/369/MyMidco-User-Guide/Adding-Authorized-Users\">Adding Authorized Users</a>"
				]
			},
			{
				"name": "Help Using Online Bill pay",
				"links": [
					"<a href=\"http://www.midcocomm.com/resourcecenter/index.cfm/326/MyMidco-User-Guide--Online-Bill-Pay/Setting-up-for-your-MyMidco-account-with-Online-Bill-Pay-for-a-New-User-\">Setting-up for your MyMidco account with Online Bill Pay for a New User</a>",
					"<a href=\"http://www.midcocomm.com/resourcecenter/index.cfm/327/MyMidco-User-Guide--Online-Bill-Pay/Setting-up-for-your-MyMidco-account-with-Online-Bill-Pay-for-existing-EZ-Pay-User-\">Setting-up for your MyMidco account with Online Bill Pay for an Existing EZ Pay User</a>",
					"<a href=\"http://www.midcocomm.com/resourcecenter/index.cfm/328/MyMidco-User-Guide--Online-Bill-Pay/Logging-into-Online-Bill-Pay-as-an-Existing-MyMidco-User\">Logging into Online Bill Pay as an Existing MyMidco User </a>",
					"<a href=\"http://www.midcocomm.com/resourcecenter/index.cfm/329/MyMidco-User-Guide--Online-Bill-Pay/Make-a-Payment-\">Make a Payment</a>",
					"<a href=\"http://www.midcocomm.com/resourcecenter/index.cfm/330/MyMidco-User-Guide--Online-Bill-Pay/View-Your-Bill\">View Bills</a>",
					"<a href=\"http://www.midcocomm.com/resourcecenter/index.cfm/331/MyMidco-User-Guide--Online-Bill-Pay/File-Your-Bill\">File Bills</a>",
					"<a href=\"http://www.midcocomm.com/resourcecenter/index.cfm/332/MyMidco-User-Guide--Online-Bill-Pay/Check-the-Status-of-a-Pending-Payment\">Check the Status of a Pending Payment</a>",
					"<a href=\"http://www.midcocomm.com/resourcecenter/index.cfm/333/MyMidco-User-Guide--Online-Bill-Pay/Payment-History\">View Payment History</a>",
					"<a href=\"http://www.midcocomm.com/resourcecenter/index.cfm/334/MyMidco-User-Guide--Online-Bill-Pay/Set-a-Recurring-Payment\">Set up a Recurring Payment</a>",
					"<a href=\"http://www.midcocomm.com/resourcecenter/index.cfm/335/MyMidco-User-Guide--Online-Bill-Pay/Set-Payment-Reminders\">Set up Payment Reminders</a>"
				]
			},
			{
				"name": "Help with Notifications",
				"links": [
					"<a href=\"http://www.midcocomm.com/resourcecenter/index.cfm/371/MyMidco-User-Guide/Accessing-Notifications\">Accessing Notifications</a>",
					"<a href=\"http://www.midcocomm.com/resourcecenter/index.cfm/372/MyMidco-User-Guide/Deleting-Notifications\">Deleting Notifications</a>"
				]
			},
			{
				"name": "Help with Online Ordering",
				"links": [
					"<a href=\"http://www.midcocomm.com/resourcecenter/index.cfm/375/MyMidco-User-Guide/Online-Ordering-FAQs\">FAQs</a>"
				]
			}
		]
	},
	{
		"name": "Email Support",
		"serviceid": "81",
		"secondaryissues": [
			{
				"name": "Email Issues",
				"links": [
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/classlibrary/page/resourcecenter/files/100.pdf#page=8&amp;zoom=100,0,0\">Midconet Users Guide</a>"
				],
				"note": "Please provide any available details about your operating system, the current program you've experienced issues with and any error messages you may be receiving"
			},
			{
				"name": "Setting Up Email Accounts",
				"links": [
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/classlibrary/page/resourcecenter/files/100.pdf#page=9&amp;zoom=100,0,0\">Midconet Users Guide</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/86/MidcoNet-Broadband/Webmail-Help\">Webmail Help </a>"
				],
				"note": "Please provide any available details about your operating system, the current program you've experienced issues with and any error messages you may be receiving"
			},
			{
				"name": "Spam/Virus Concerns ",
				"links": [
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/classlibrary/page/resourcecenter/files/100.pdf#page=4&amp;zoom=100,0,0\">Midconet User's Guide</a>"
				],
				"note": "Please provide any available details about your operating system, the current program you've experienced issues with and any error messages you may be receiving"
			},
			{
				"name": "Webmail Problems ",
				"links": [
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/10/Using-Webmail\">Webmail Resource Page</a>"
				],
				"note": "Please provide any available details about your operating system, the current program you've experienced issues with and any error messages you may be receiving"
			}
		]
	},
	{
		"name": "Telephone Support",
		"serviceid": "81",
		"secondaryissues": [
			{
				"name": "Service Issues ",
				"links": [
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/115/Digital-Phone/What-should-I-do-if-I-dont-have-a-dial-tone-\">What should I do if I don't have dial tone?</a>"
				]
			},
			{
				"name": "Phone Feature Usage ",
				"links": [
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/classlibrary/page/resourcecenter/files/83.pdf\">Digital Phone Guide</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/classlibrary/page/resourcecenter/files/80.pdf\">Digital Phone Guide - Aberdeen</a>"
				]
			},
			{
				"name": "Long Distance Service ",
				"links": [
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/digitalphone/internationalphonerates/\">International Calling Rates</a>",
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/resourcecenter/index.cfm/103/Digital-Phone/How-can-I-make-an-International-call-\">Why can't I make an international call?</a>"
				]
			},
			{ "name": "Directory" },
			{
				"name": "Telephone Assistance Program",
				"links": [
					"<a target=\"_blank=\" href=\"http://www.midcocomm.com/digitalphone/lifelineassistanceprogram/\">Lifeline Assistance Program</a>"
				]
			}
		]
	},
	{
		"name": "General",
		"serviceid": "80",
		"secondaryissues": [
			{"name": "Company Information"},
			{"name": "General Comment/Questions"},
			{"name": "Vendor Inquiries"},
			{"name": "Web Site Comments"}
		]
	}
];

var post_path = 'http://24.220.76.4/CCPROChat/CPChatMain.jsp?ChatSrvr=10.128.0.55&AllowPush=1&Orientation=-2147483647&SeperateWindow=-2147483647&Port=194&PrimaryIP=10.128.0.55&PrimaryPort=195&SecondaryIP=&SecondaryPort=';

// Array Remove - By John Resig (MIT Licensed)
Array.remove = function(array, from, to) {
  var rest = array.slice((to || from) + 1 || array.length);
  array.length = from < 0 ? array.length + from : from;
  return array.push.apply(array, rest);
};

function init() {
	
	var comments = document.getElementById('comments');
	if(comments != null) {
		// On the email form, remove Payment Inquiry from the Billing section.
		var billing = findInArray('Billing', config, 'name');
		Array.remove(billing.secondaryissues,1);
	}
	
	document.getElementById('primaryissue').onchange = primaryChanged;
	document.getElementById('secondaryissue').onchange = secondaryChanged;
	document.getElementById('contactform').onsubmit = formsubmitted;
}

init();

function primaryChanged() {
	var me = document.getElementById('primaryissue');
	
	// Clear the "secondary issue" select.
	var subissueSelect = document.getElementById('secondaryissue');
	var options = subissueSelect.getElementsByTagName('option');
	for(var i = options.length - 1; i > 0; i--)
		subissueSelect.removeChild(options[i]);
	
	// Get the main issue.
	var mainIssue = findInArray(me.value, config, 'name');
	if(mainIssue == null) {
		// Not found?  Hide secondary issue, exit.
		document.getElementById('secondary').style.display = 'none';
		showHelp(null);
		return true;
	}
	
	if(mainIssue.secondaryissues && mainIssue.secondaryissues.length > 0) {
		// If there are secondary issues...
		document.getElementById('secondary').style.display = 'block';
		
		for(var x=0; x<mainIssue.secondaryissues.length; x++) {
			var option = subissueSelect.appendChild(document.createElement('option'));
			option.value = mainIssue.secondaryissues[x].name;
			option.appendChild(document.createTextNode(mainIssue.secondaryissues[x].name));
		}
	} else {
		// No secondary issues, hide secondary issues row.
		document.getElementById('secondary').style.display = 'none';
	}
	
	showHelp(mainIssue);
	
	return true;
}

function secondaryChanged() {
	var me = document.getElementById('secondaryissue');
	
	var mainIssue = findInArray(
		document.getElementById('primaryissue').value, 
		config,
		'name'
	);
	
	if(mainIssue == null)
		return;
	
	var secondaryIssue = findInArray(
		me.value, 
		mainIssue.secondaryissues,
		'name'
	);
	
	if(secondaryIssue == null)
		return true;
	
	if(!mainIssue.links || mainIssue.links.length == 0)
		showHelp(secondaryIssue);
	
	return true;
}



function showHelp(issue) {
	var hideHelp = true;
	
	
	document.getElementById('help').style.display = 'none';
	document.getElementById('helplinks').innerHTML = '';
	document.getElementById('note').innerHTML = '';
	
	if(issue && issue.links && issue.links.length > 0) {
		var html = "";
		for(var x = 0; x < issue.links.length; x++) {
			html += '<div class="link">' + issue.links[x] + '</div>';
		}
		document.getElementById('helplinks').innerHTML = html;
		document.getElementById('help').style.display = 'block';
	}
	
	if(issue && issue.note) {	
		document.getElementById('note').innerHTML = issue.note;
		document.getElementById('help').style.display = 'block';
	}
}




function findInArray(key, arr, searchKey) {
	var x = arr.length - 1;
	while (x >= 0) {
		if(arr[x][searchKey] == key)
			return arr[x];
		x--;
	}
	return null;
}


function formsubmitted() {
	// Validate form.
	var fname = document.getElementById('firstname');
	var lname = document.getElementById('lastname');
	var email = document.getElementById('email');
	var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var phone = document.getElementById('phone');
	var address = document.getElementById('address');
	var city = document.getElementById('city');
	var state = document.getElementById('state');
	var zip = document.getElementById('zip');
	var account = document.getElementById('acctnum');
	var verifyCode = document.getElementById('verifyCode');
	var primaryissue = document.getElementById('primaryissue');
	var secondaryissue = document.getElementById('secondaryissue');
	// contact method is no longer on the form.
	// var method = document.getElementById('contactmethod');
	var comments = document.getElementById('comments');
	
	fname.className = (fname.value == '') ? "error" : "ok";
	lname.className = (lname.value == '') ? "error" : "ok";
	email.className = (email.value == '') ? "error" : "ok";
	email.className = (email.value.match(emailRegEx)) ? "ok" : "error";
	address.className = (address.value == '') ? "error" : "ok";
	city.className = (city.value == '') ? "error" : "ok";
	state.className = (state.value == '') ? "error" : "ok";
	verifyCode.className = (verifyCode.value == '') ? "error" : "ok";
	// zip.className = (zip.value == '') ? "error" : "ok";
	primaryissue.className = (primaryissue.value == 'Did not select') ? "error" : "ok";
	secondaryissue.className = (secondaryissue.value == 'Did not select') ? "error" : "ok";
	
	// Phone is only required when it exsits, and users
	// have "phone" selected as the contact method.
	/* - Contact method has been removed from the form.
	phone.className = 'ok';
	if(method != null) {
		if(method.value == 'Phone') {
			phone.className = (phone.value == '') ? "error" : "ok";
		}
	}
	*/
	
	var wasError = fname.className == 'error' ||
		lname.className == 'error' ||
		email.className == 'error' ||
		phone.className == 'error' ||
		address.className == 'error' ||
		city.className == 'error' ||
		state.className == 'error' ||
		zip.className == 'error' ||
		account.className == 'error' ||
		verifyCode.className == 'error' ||
		primaryissue.className == 'error' ||
		secondaryissue.className == 'error';
	
	if(wasError) {
		alert("We're sorry, we could not process this request.  Please fill in the all the required fields (marked with asterisks).");
		return false;
	}
	
	// If this is a chat launch
	if(comments == null) {
		var mainIssue = findInArray(primaryissue.value, config, 'name');
		if(mainIssue == null)
			mainIssue = config[config.length - 1];
		var serviceID = mainIssue.serviceid;
		
		
		var custname = fname.value + ' ' + lname.value;
		
		/*
		var url = post_path +
			'&CustName=' + escape(custname) +
			"&ServiceID=" + escape(serviceID) +
			'&firstname=' + escape(fname.value) +
			'&lastname=' + escape(lname.value) +
			'&email=' + escape(email.value) +
			'&phone=' + escape(phone.value) +
			'&address=' + escape(address.value) +
			'&city=' + escape(city.value) +
			'&state=' + escape(state.value) +
			'&zip=' + escape(zip.value) +
			'&account=' + escape(account.value) +
			'&primary=' + escape(primaryissue.value) +
			'&secondary=' + escape(secondaryissue.value);
		*/
		
		var url = post_path +
			'&CustName=' + escape(custname) +
			'&UserDefined1=' + escape(primaryissue.value) +
			'&UserDefined2=' + escape(secondaryissue.value) +
			'&UserDefined3=' + escape(custname) +
			'&UserDefined4=' + '' + // Company
			'&UserDefined5=' + escape(address.value) +
			'&UserDefined6=' + escape(city.value) +
			'&UserDefined7=' + escape(state.value) +
			'&UserDefined8=' + escape(zip.value) +
			'&UserDefined9=' + escape(phone.value) +
			'&UserDefined10=' + escape(account.value) +
			'&ServiceID=' + mainIssue.serviceid;
		
		//Open the window
		var ChatWindow = window.open('', 'ChatWindow', 'width=500,height=700');
		try {
			if (ChatWindow.location.href == 'about:blank') {
				ChatWindow.location.href = url;
			}
		}
		catch(err) {}
		ChatWindow.focus()
		return false;
	}
	
	return true;
}
