/*	Invisalign Country Selector Javascript */

var DocLocCountryList = new Array(); // (CurrentSite, Name, Value, Variation1, Variation2, ..)

DocLocCountryList[0]= new Array("false", "AT", "AT", "en", "de");
DocLocCountryList[1]= new Array("false", "CH", "CH", "en", "ch");
DocLocCountryList[2]= new Array("false", "DE", "DE", "en", "de");
DocLocCountryList[3]= new Array("false", "ES", "ES", "en", "es");
DocLocCountryList[4]= new Array("false", "IE", "IE", "en", "ie");
DocLocCountryList[5]= new Array("false", "IT", "IT", "en", "it");
DocLocCountryList[6]= new Array("false", "NL", "NL", "en", "nl");
DocLocCountryList[7]= new Array("true", "UK", "GB", "en");

var DocLocZipCodeInput;
var DocLocCountrySelect;

function initDocLocSearchBox(countrySelectId, zipCodeInputId)
{
	DocLocCountrySelect = document.getElementById(countrySelectId);
	DocLocZipCodeInput = document.getElementById(zipCodeInputId);

	var selected = getCurrentDocLocCountry();	
	
	if (DocLocCountrySelect)
	{	
		for (var i=0; i<DocLocCountryList.length; i++)
		{		
			DocLocCountrySelect.options[i]=new Option(DocLocCountryList[i][1], DocLocCountryList[i][2], i==0, i==selected);
		}
	}
}

function getCurrentDocLocCountry()
{
	var variation = getCurrentVariation();
	for (var i=0; i<DocLocCountryList.length; i++)
	{		
		var country = DocLocCountryList[i];		
		if (country[0] == "true")
		{		
			var lang=3;			
			while (country[lang])
			{
				if (country[lang].toLowerCase() == variation.toLowerCase()) 
				{
					return i; 
				}
				lang++;
			}
		}
	}
	return 0;
}

function openDocLocUrl(teen)
{
	var zipcode = DocLocZipCodeInput ? DocLocZipCodeInput.value : "";
	var country = DocLocCountrySelect ? DocLocCountrySelect.options[DocLocCountrySelect.selectedIndex].value : "";
	var redirectUrl = "/" + getCurrentVariation() + "/Find-Invisalign-Doctor/Pages/Search.aspx?zipcode=" + zipcode + "&country=" + country;
	if (teen) redirectUrl += "&teen=1";
	location.href = redirectUrl;
}
