document.documentElement.className = 'jsEnabled_acctSelect_live';
$(document).ready(function(){
	$("select#sList").attr("selectedIndex", 0);
	$("select#sList").change(function(){
		var URLs_AT = new Array();
		
//----------Add / edit button URLS below: ----------//
			URLs_AT["Default"] = "https://secure2.fxcorporate.com/fxtr/?ib=fxcmuk_cfd_xtp";
			URLs_AT["US"] = "https://secure2.fxcorporate.com/fxtr/?ib=fxcmuk_us_xtp";
			URLs_AT["AU"] = "https://secure2.fxcorporate.com/fxtr/?ib=fxcmau_active_trader";
			
		var URLs_MT = new Array();
			URLs_MT["Default"] = "/metatrader-apply.jsp";
			URLs_MT["AU"] = "http://www.forextrading.com.au/metatrader-apply.jsp";
			
//		var URLs_CFD = new Array();
//			URLs_CFD["Default"] = "/cfd-account-international.jsp";
//			URLs_CFD["AU"] = "http://www.forextrading.com.au/cfd-product-info.jsp";
			
		var URLs_FX = new Array();
			URLs_FX["Default"] = "/forex-account-us.jsp";
			
		var URLs_CFD = new Array();
			URLs_CFD["Default"] = "/forex-account-international.jsp";
			URLs_CFD["US"] = "/forex-account-us.jsp";
			URLs_CFD["AU"] = "http://www.forextrading.com.au/open-an-account-international.jsp";
			URLs_CFD["IT"] = "http://www.fxcm.it/apri-un-conto.jsp";
			
		var URLs_SB = new Array();
			URLs_SB["Default"] = "/spread-betting-account.jsp"
		
//----------When adding new accounts, be sure to add the reference below as well as above ---//
		var $URLs = new Array ();
			$URLs["AT"] = URLs_AT;
			$URLs["MT"] = URLs_MT;
			$URLs["SB"] = URLs_SB;
			$URLs["FX"] = URLs_FX;
			$URLs["CFD"] = URLs_CFD;
	
			var accts = $("ul#acctBoxWrap").children("li.acctBox");		
			var customGrp = $(".customGrp");	
			var selectedCountryTitle = $("h4#selectedCountry");
			var selectedOption = $(this).children("option:selected");
			var selectedClass = $(selectedOption).attr("class");
			
			//reset all elements
			$(selectedCountryTitle).removeClass("on").text("");
			$(accts).hide();
			$(customGrp).children().hide();
			
			if (selectedOption.val() != "") {
				var acctsToShow = $(accts).filter(".for" + selectedClass);	
				//	if selected class is empty, set acctsToShow to default
				if (selectedClass == "") {
					acctsToShow = $(accts).filter(".forDefault");
					selectedClass = "Default"
				}
				else if (selectedClass != "") {
					//check for existence of div.acctBox with the the class of selectedClass
					if (acctsToShow.length != 0) {
						acctsToShow = $(accts).filter(".for" + selectedClass);
					}
					else if (acctsToShow.length == 0) {
						acctsToShow = $(accts).filter(".forDefault");
					}
				}
				// loop through each acct box
				for (var i = 0; i < acctsToShow.length; i++) {
					var currAcct = $(acctsToShow).eq(i);
					var currAcctType = $(currAcct).attr("id");
					if($(currAcct).attr("class").indexOf("customBox") == -1 ){
						//display customGrp elements
						var currCustomGrps = $(currAcct).find(".customGrp");
						for (var n = 0; n < currCustomGrps.length; n++){
							var thisGrp = $(currCustomGrps).eq(n).children();
							if (selectedClass == "Default") {
								$(thisGrp).filter(".for" + selectedClass).show();
							}
							else if (selectedClass != "Default"){ 
							if (($(thisGrp).filter(".for" + selectedClass).length == 0) && ($(thisGrp).filter(".not" + selectedClass).length == 0)) {
									$(thisGrp).filter(".forDefault").show();
								}
								else {
									$(thisGrp).filter(".for" + selectedClass).show();
								}
							}
						}
						//determine correct url to  use
						var currBtn = $(currAcct).children("a.sBtn");
						var currAcctURLArray = $URLs[currAcctType];
						var currAcctURL = $URLs[currAcctType][selectedClass];
						if (currAcctURL == undefined) {
							currAcctURL = $URLs[currAcctType]["Default"];
						}
						//feed  url to submit button's href
						$(currBtn).attr("href", currAcctURL);
						//add target blank to external URLs
						if (currAcctURL.indexOf("http") != -1) {
							$(currBtn).attr("target", "_blank");
						}
					}
					//add margin to even boxes
					if (i%2 == 0) {
						$(currAcct).addClass("addMargin");
					}
					else if (i%2 != 0) {
						$(currAcct).removeClass("addMargin");
					}
				}
				$(selectedCountryTitle).addClass("on").text(selectedOption.val());
				$(acctsToShow).show();
			}
		});
 });  
// For instructions, please see: /2009_JAVA/FXCM_UK/web/js/content/acctSelect_live_instructions.doc 
//	
//	11.26.09:
//	Ammended customGrp functionality to allow exclusion of one country. ie, adding "notXX" to prevent a default element from displaying in the case of the selected country not having an associated custom element
//
