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=ORSADA_BILISIM_HIZM_PAZ";
			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.php";
			URLs_MT["AU"] = "http://www.forextrading.com.au/metatrader-apply.jsp";
			
		var URLs_CFD = new Array();
			URLs_CFD["Default"] = "/cfd-account-international.php";
			URLs_CFD["AU"] = "http://www.forextrading.com.au/cfd-product-info.jsp";
			
		var URLs_FX = new Array();
			URLs_FX["Default"] = "/forex-account-international.php";
			URLs_FX["US"] = "/forex-account-us.jsp";
			URLs_FX["AU"] = "http://www.forextrading.com.au/open-an-account-international.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["CFD"] = URLs_CFD;
			$URLs["SB"] = URLs_SB;
			$URLs["FX"] = URLs_FX;
	
			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(".forDefault").show();
								}
								else {
									$(thisGrp).filter(".for" + selectedClass).show();
								}
							}
						}
						//feed correct url to submit buttons
						var currBtn = $(currAcct).children("a.sBtn");
						var currAcctURLArray = $URLs[currAcctType];
						var currAcctURL = $URLs[currAcctType][selectedClass];
						if (currAcctURL == undefined) {
							currAcctURL = $URLs[currAcctType]["Default"];
						}
						$(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();
			}
		});
 });  
/*
Instructions:
For any country that needs a custom treatment, (either a special URL, custom text, or for specific accounts to show for that country) do the following:

   1) In the global country select list, add a class to the particular country. 
      - Please use the two-letter abbreviations, in caps -- ie "AU" or "US"
 	  - You'll need to add the same class to each time that country appears in the dropdown, or to associated countries (For instance, "Australia" and "New Zealand" will both get "AU")
		 
   2) To customize which information displays:
   
      a. To display a particular set of accounts for a country, add the class "forXX" (ie "forAU" or "forUS") to the <li.acctBox> of each account that must show for that particular country. 
         Be sure to use the exact spelling / caps pattern in both places.
		 
	  b. For a URL other than the default URL:
  		 Add the new value in the acctSelect_live.js file in the appropriate array, and be sure to reference the same classname as you used in the dropdown country list.
		 
	  c. For a newly-added account box:
  		 Add a new array with the link values, and a new call to that array in "$URLs".
		 
	  d. For any custom acctBox text that needs to change for a country:
	     - Wrap the text in any element
		 - give this wrap the classname "customGrp"
		 - additionally, wrap each version of the alternate content in an element with the classname "forXX"
		 
		 ex:
			<div class="customGrp">
				<h4 class="forDefault">Minimum: 2000 EURO, GBP, USD to open</h4>
				<h4 class="forAU">Minimum: 300 AUD, NZD, USD, EURO, GBP to open</h4>
			</div>
			OR
			<span class="customGrp">
				<span class="forDefault">default info</span>
				<span class="forUK">united kingdom info</span>
			</span>

*/