/*	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", "IT", "IT", "en", "it");
DocLocCountryList[5]= new Array("false", "NL", "NL", "en", "nl");
DocLocCountryList[6]= new Array("true", "UK", "GB", "en");

var DocLocZipCodeInput;
var DocLocCountrySelect;


var DocLocBoxStringList = new Array(); // (Variation1,Name, Value)

DocLocBoxStringList["en"]  =   { "Title" : "Find a practitioner",
                               "InnerHTML" : "Find an Invisalign provider near you. Enter postal code and select country.",
                              "ButtonImage" : "/SiteCollectionImages/doc_search.jpg",
                              "TeenInnerHTML" : "Find an Invisalign Teen provider near you. Enter postal code and select country.",
                              "TeenButtonImage" : "/SiteCollectionImages/teenpage_search.jpg" };
                       
DocLocBoxStringList["es"]  =   { "Title" : "Encuentre un odont\u00F3logo",
                               "InnerHTML" : "Encuentre un proveedor Invisalign cerca de su domicilio.  Introduzca el c\u00F3digo postal y seleccione el pa\u00EDs.",
                              "ButtonImage" : "/SiteCollectionImages/es/buscar_bg_purple.jpg",
                              "TeenInnerHTML" : "Encuentre un proveedor Invisalign Teen cerca de su domicilio. Introduzca el c\u00F3digo postal y seleccione el pa\u00EDs.",
                              "TeenButtonImage" : "/SiteCollectionImages/es/buscar.jpg" };

       
DocLocBoxStringList["it"]  =   { "Title" : "Trova un medico",
                               "InnerHTML" : "Trova un professionista Invisalign nella tua zona. Inserisci il CAP e seleziona il paese.",
                              "ButtonImage" : "/SiteCollectionImages/it/cerca_purple.jpg",
                              "TeenInnerHTML" : "Trova un professionista Invisalign Teen nella tua zona. Inserisci il CAP e seleziona il paese.",
                              "TeenButtonImage" : "/SiteCollectionImages/it/cerca.jpg" };
                              
                    

function  initDocLocLang(teen){


  var DocLocatorSearchBoxTD = document.getElementById("DocLocatorSearchBoxTD");
  var DocLocatorSearchBoxDIV = document.getElementById("DocLocatorSearchBoxDIV");
  var DocLocatorSearchBoxText = document.getElementById("DocLocatorSearchBoxText");
  var DocLocatorSearchBoxButton = document.getElementById("DocLocatorSearchBoxButton");
  
  var StringList = DocLocBoxStringList[getCurrentVariation()];
  
  if(teen){
     DocLocatorSearchBoxTD.className = "invPodOrange";
	 DocLocatorSearchBoxDIV.className = "invH2Orange40";
	 DocLocatorSearchBoxButton.onclick = function(){openDocLocUrl('teen')};
	 DocLocatorSearchBoxDIV.innerHTML = StringList["Title"];
	 DocLocatorSearchBoxText.innerHTML = StringList["TeenInnerHTML"];
	 DocLocatorSearchBoxButton.src = StringList["TeenButtonImage"];

  } else {
  

  try {
      DocLocatorSearchBoxTD.className = "invPodPurple";
	  DocLocatorSearchBoxDIV.className = "invH2Purple";
	  DocLocatorSearchBoxButton.onclick = function(){openDocLocUrl()};
      DocLocatorSearchBoxDIV.innerHTML = StringList["Title"];
	  DocLocatorSearchBoxText.innerHTML = StringList["InnerHTML"];
	  DocLocatorSearchBoxButton.src = StringList["ButtonImage"];
	  }catch (e) {
	  alert(e);
	  }
  }
  }
						
		
          

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;
}
