window.name = "Main";
var MY_REGIONS = "My Regions";
var ALL_REGIONS = "All Regions";
var OTHER_REGIONS = "Other Regions";
var OTHER_REGIONS_COOKIE = "OtherRegionsPref";
var IDRAC_NUM = "IDRAC Number";
var MY_REGIONS_COOKIE = "MyRegionsPref";
var invalidText="";
var invalidTextCount=0;

//-------------------------------------------------------------------------
function OpenOtherRegions()
{
	// Check if Other Region cookie dosn't exists.  If it doesnt', display Other Region selection
	if( GetCookie(OTHER_REGIONS) == null ){
	var orPath = document.getElementById("ctl00_TopBannerItem_OtherRegionsPath").getAttribute("value");
	
		newwin=window.open(orPath, null, "scrollbars=no,width=700,height=690");
		newwin.moveTo(0,0);
	};
	
}



//-------------------------------------------------------------------------
function OnChangeCountry(countryDropDown, IsNeedOtherRegionPopup)
		{
			if( countryDropDown == 'undefined' )
				return;

			var optionValue = countryDropDown.options[countryDropDown.selectedIndex].text;

			//launch the other regions dialog if user selects from the drop down
			if (( optionValue == OTHER_REGIONS ) && ( IsNeedOtherRegionPopup ))
			{
				OpenOtherRegions();
		}		

			//now update the region globe
			//if( optionValue != OTHER_REGIONS )
			//{

				if( optionValue == MY_REGIONS )
					document.forms[0].ctl00_TopBannerItem_RegionsImage.title = "My Regions: " + GetCountriesFromCookie(MY_REGIONS_COOKIE, countryDropDown);
				else if( optionValue == ALL_REGIONS )
					document.forms[0].ctl00_TopBannerItem_RegionsImage.title = "All Regions: " + GetAllCountries(countryDropDown);
				else if( optionValue == IDRAC_NUM )
					document.forms[0].ctl00_TopBannerItem_RegionsImage.title = "IDRAC Number";
				else if( optionValue == OTHER_REGIONS )
				  document.forms[0].ctl00_TopBannerItem_RegionsImage.title = "Other Regions: " + 
				  GetCountriesFromCookie(OTHER_REGIONS_COOKIE, countryDropDown);
				else
					document.forms[0].ctl00_TopBannerItem_RegionsImage.title = "Region: " + optionValue;
			//}
		}

//-------------------------------------------------------------------------
function GetAllCountries(countryDropDown)
{
   
	var countries = "";
	var country = "";

	for( i = 0; i < countryDropDown.options.length; i++ )
	{
		country = countryDropDown.options[i].text;

		if( country != MY_REGIONS && country != ALL_REGIONS && country != OTHER_REGIONS && country != IDRAC_NUM )
		{
			countries += country;
			if( i != ( countryDropDown.options.length - 1 ) )
				countries += ", ";
		}
	}

	return countries;
}

//-------------------------------------------------------------------------
function GetCountriesFromCookie( cookie, countryDropDown )
{
   
	if ( countryDropDown == null)
	{
	return;
	}
	var countries = "";
	var countryId = "";
	var CountryArray = new Array();
	var CountryNames = new Array();

	if( GetCookie(cookie) == null )
		return "None";
		
	CountryArray = decommifyArray(GetCookie(cookie));

	if( CountryArray.length > 0 )
	{
		for( i = 0; i < CountryArray.length; i++ )
		{
			for( ii = 0; ii < countryDropDown.options.length - 1; ii++ )
			{
			  
			  country = countryDropDown.options[ii].value;
			  		  			  					
				if( country == CountryArray[i] )
				{
				
					CountryNames[CountryNames.length] = countryDropDown.options[ii].text;
					break;
				}
			}
		}

		CountryNames = CountryNames.sort(CaseInsensitiveComparer);
		countries = CountryNames.toString();
		countries = countries.replace(/,/g, ", ");
	}
	else
		return "None";

	return countries==""?"None":countries;
}

//-------------------------------------------------------------------------
function CaseInsensitiveComparer(String1, String2)
{
	
	if (String1.toLowerCase() < String2.toLowerCase()) return -1;
	if (String1.toLowerCase() > String2.toLowerCase()) return 1;
	return 0;
}

//-------------------------------------------------------------------------
function decommifyArray(obj)
{
  	var myArray = obj.split(",");
	return myArray;
}

//-------------------------------------------------------------------------
function runSimpleSearchOnEnterKey()
{
  var prefixID='ctl00_TopBannerItem_';	
  document.getElementById(prefixID+'GoBtn').click();   
}