﻿				var nActiveRegionID = 0;
				var arRollover = new Array();
				var arSelected = new Array();
				var arRegions = new Array(); // for sorted Regions-only array
				var arCountries = new Array();	// for sorted Countries-only array
				var showAlldiv = document.getElementById('ShowAllLink');
				var showAll;
				var showAllText = "";
				var tooltip = document.getElementById("tooltipdiv");
	            tooltip.style.display = "none";				
				if (showAlldiv != null) {
				        var showAll = showAlldiv.getElementsByTagName('a')[0];
				        if (showAll != null)
				        {
				            showAllText = showAll.innerHTML
				            showAll.href = "javascript:goRegion('ww')";
				        }
				    }
				function makeSortableArrays()
				 {
					var nCountry = 0;
					for (var x = 1; x <= arSubs.length; x++) 
					{
						// Put the Region into an array
						if (arSubs[x]) 
						{
						    arRegions[x] = [arSubs[x][0][0], x];
						    var region = arSubs[x][0][1];
						    var regionArea = document.getElementById(region + "Region");
						    if (regionArea != null)
						    {
						        regionArea.title = arSubs[x][0][0];
						    }
							for (var y = 1; y < arSubs[x].length; y++) 
							{
								arCountries[nCountry] = [arSubs[x][y][0], arSubs[x][y][1]];
								nCountry++;
							}
						}
					}
					arRegions = arRegions.sort(sortArray);
					arCountries = arCountries.sort(sortArray);
				}
				
				function dictRegions(regionName)
				{
				    for (y = 0; y < arSubs.length; y++)
					 {
					    if (regionName == arSubs[y][0][1])
					    {
					        return y;
					    }
					 }
				}
				
				function sortArray(a1, a2)
				 {
					return 	a1[0] < a2[0] ? -1 :
							a1[0] > a2[0] ? 1 : 0;
				}
				
				function loadRegionalImages(x) 
				{				    				    				    
					arSelected[x] = new Image(415,227);
					arSelected[x].src = '/Content/Images/ChangeGeo/' + arSubs[x][0][1] + '_selected_.gif';
					arRollover[x] = new Array();
					arRollover[x][0] = new Image(415, 227);
					if (x == 0)
					{
					    arRollover[x][0].src = '/Content/Images/ChangeGeo/spacer.gif';
					}
					else
					{
					    arRollover[x][0].src = '/Content/Images/ChangeGeo/' + arSubs[x][0][1] + '_rollover_.gif';
					}
					for (y = 0; y < arSubs.length; y++)
					 {
						if (x != y) 
					  	{ // make sure we're not creating ww_select_ww_roll or similar redundencies
							if (arSubs[x][0][1] != 'cac') 
							{ // don't preload for Central America / Carribean
								arRollover[x][y] = new Image(415,227);
								arRollover[x][y].src = '/Content/Images/ChangeGeo/' + arSubs[x][0][1] + '_select_' + arSubs[y][0][1] + '_roll_.gif';
							}
						}
					}
				}		

                function ShowToolTip(object,RegionAbbr)
                {
                }
				function Swapin(RegionAbbr)
				{
					if (document.images) 
					{
						var nMORegionID = dictRegions(RegionAbbr);
						if (nMORegionID != nActiveRegionID) 
						{
							document.getElementById('wwimage').src = arRollover[nActiveRegionID][nMORegionID ].src;
						}
					}
				}
				
				function Swapout()
				{
					if (document.images) 
					{
						document.getElementById('wwimage').src = arSelected[nActiveRegionID].src;
					}
				}				

				function goRegion(RegionAbbr) 
				{
				    var oSelTitle = document.getElementById('selCountryTitle');
				    var oSel = document.getElementById('selCountry');
					nActiveRegionID = dictRegions(RegionAbbr);
					oSel.innerHTML = '';
					loadRegionalImages(nActiveRegionID);
					document.getElementById('wwimage').src = arSelected[nActiveRegionID].src;
					if (nActiveRegionID==0) 
					{
					    oSelTitle.innerHTML = sSelDefault;
					    oSelTitle.style.color = "#333333";
					    if (showAll != null) {
						    showAll.innerHTML = "";
						    //Fix. default highlight the "World Wide Partner Portal Home page"
						    document.getElementById('selCountry').focus();
						}
						//  Add all countries sorted by alpha
						addOption(arWW[0],arWW[1]);
						for (var s = 0; s < arCountries.length; s++) 
						{
						    if (s == 0)
						    {
						        addOption(arCountries[s][0],arCountries[s][1]);
						    }
						    else
						    {
	
						       if (arCountries[s][0] != arCountries[s-1][0])
						        {
						            addOption(arCountries[s][0],arCountries[s][1]);
						        }
						    }							
						}
					} 
					else 
					{
					   	addCountries(nActiveRegionID);

						// display title when selected
						oSelTitle.innerHTML = arSubs[nActiveRegionID][0][0],-1;
						if (showAll != null) {
						    showAll.innerHTML = showAllText;
						}
						oSelTitle.style.color = "";
					}
					oSel.selectedIndex = 0;
				}
				
				function addCountries(RegionID)
				{
				    // Put all Geos for region into a new array
				    var arSortedRegionGeos = new Array();
				    var nCountry = 0;
				    for (var y = 1; y < arSubs[RegionID].length; y++) 
					{
					    arSortedRegionGeos[nCountry] = [arSubs[RegionID][y][0], arSubs[RegionID][y][1]];
						nCountry++;
					}
				    // Sort the list of Geos for this region
				    arSortedRegionGeos.sort(sortArray);
				    
				    // Add the sorted list of Geos to the geo selector
				    for (var c = 0; c < arSortedRegionGeos.length; c++) 
					{
					    addOption(arSortedRegionGeos[c][0],arSortedRegionGeos[c][1]);
					}
				}
				
				function addOption(name, value) 
				{
					var oSel = document.getElementById('selCountry');
					if (name == '' && value == 0) 
					{
						oSel.innerHTML = '';
					} 
					else 
					{
						oSel.options[oSel.options.length] = new Option(name, value);
					}
				}
				
				// sort arrays for alphabetical listing of all countries
				makeSortableArrays();
				// on page load, load all countries (ww)
				goRegion('ww');