/*	Invisalign Country Selector Javascript */

var CountryList = new Array();
//CountryList[0]= new Array("Austria",        new Array("Deutsch",    "de-AT"), new Array("English", "en-AT"));
//CountryList[1]= new Array("Germany",        new Array("Deutsch",    "de-DE"), new Array("English", "en-DE"));
//CountryList[2]= new Array("Italy",          new Array("Italiano",   "it-IT"), new Array("English", "en-IT"));
//CountryList[3]= new Array("Netherlands",    new Array("Nederlands", "nl-NL"), new Array("English", "en-NL"));
//CountryList[4]= new Array("Spain",          new Array("Espagnol",   "es-ES"), new Array("English", "en-ES"));
//CountryList[5]= new Array("Switzerland",    new Array("Deutsch",    "de-CH"), new Array("English", "en-CH"));
//CountryList[6]= new Array("United Kingdom", new Array("English",    "en-UK"));


CountryList[0]= new Array("Australia", new Array("Australia",    "http://www.invisalign.com.au/"));
CountryList[1]= new Array("Brazil", new Array("Brazil",    "http://www.invisalign.com/generalapp/br/pt/index.html"));
CountryList[2]= new Array("Canada", new Array("Canada",    "http://www.invisalign.com/"));
CountryList[3]= new Array("France", new Array("France",    "http://www.invisalign.com/generalapp/fr/fr/index.html"));
CountryList[4]= new Array("Germany", new Array("Germany",    "http://www.invisalign.com/generalapp/de/de/index.html"));
CountryList[5]= new Array("Hong Kong", new Array("Hong Kong",    "http://www.invisalign.com.hk/opening.htm"));
CountryList[6]= new Array("Italy",          new Array("Italiano",   "it"), new Array("English", "en"));
CountryList[7]= new Array("Japan", new Array("Japan",    "http://www.invisalign.com/generalapp/jp/ja/index.html"));
CountryList[8]= new Array("Latin America", new Array("Latin America",    "http://www.invisalign.com.mx"));
CountryList[9]= new Array("New Zealand", new Array("New Zealand",    "http://www.invisalign.co.nz/"));
CountryList[10]= new Array("Spain", new Array("Spain",    "http://www.invisalign.com/generalapp/es/es/index.html"));
CountryList[11]= new Array("Singapore", new Array("Singapore",    "http://www.invisalign.com.sg"));
CountryList[12]= new Array("South Korea", new Array("South Korea",    "http://www.invisalign.co.kr"));
CountryList[13]= new Array("United Kingdom", new Array("United Kingdom",    "http://www.invisalign.co.uk/"));
CountryList[14]= new Array("United States", new Array("United States",    "http://www.invisalign.com/"));
CountryList[15]= new Array("Thailand", new Array("Thailand",    "http://www.invisalign.com.au/"));


var CountryType = new Array();
CountryType[0] = 'remote';
CountryType[1]='remote';
CountryType[2]='remote';
CountryType[3]='remote';
CountryType[4]='remote';
CountryType[5]='remote';
CountryType[6]='local';
CountryType[7]='remote';
CountryType[8]='remote';
CountryType[9]='remote';
CountryType[10]='remote';
CountryType[11]='remote';
CountryType[12]='remote';
CountryType[13]='remote';
CountryType[14]='remote';
CountryType[15]='remote';

	

function initCopyright(){
   if('it' == getCurrentVariation().toLowerCase()){
	  var copy = document.getElementById("align_copyright");
	  copy.innerHTML = "<p>&copy; 2000-2009 Align Technology, Inc. Tutti i diritti riservati.</p>";
   }
}
			       
							   

function initCountrySelect(countrySelectId, languageSelectId)
{

	var countrySelect = document.getElementById(countrySelectId);
	var selected = getCurrentCountry();	
	
	
	var variation =  getCurrentVariation().toLowerCase();
	var url = document.URL;
	
	var searchStr = '/'+variation+'/';
	var i = url.indexOf(searchStr);
	i += searchStr.length;
	var pageURL = url.substring(i-1);
	var page = 0;  
	
	if (countrySelect)
	{	
		for (var i=0; i<CountryList.length; i++)
		{	if ( CountryType[i] == 'local') {	
			countrySelect.options[i]=new Option(CountryList[i][0], "location.href='/" + CountryList[i][1][1] + "'", i==0, i==selected);
		} else {
      		countrySelect.options[i]=new Option(CountryList[i][0], "location.href='" + CountryList[i][1][1] + "'", i==0, i==selected);
	}
		}

		var languageSelect = document.getElementById(languageSelectId);	
		
		if (languageSelect)
		{
			var country = CountryList[selected];		
			if (country)
			{		
				var html='';				
				var lang=1;			
				while (country[lang])
				{
					if (html!='') html += '&nbsp;|&nbsp;';						
					html += '<a href="/' + country[lang][1]  + pageURL + '">' + country[lang][0] +'</a>';
					lang++;
				}
				languageSelect.innerHTML = html;	
			}	
		}
	}
}


function getCurrentCountry()
{
	var variation = getCurrentVariation();
	for (var i=0; i<CountryList.length; i++)
	{		
		var country = CountryList[i];		
		var lang=1;			
		while (country[lang])
		{
			if (country[lang][1].toLowerCase() == variation.toLowerCase()) 
			{
				return i; 
			}
			lang++;
		}
	}
	return 0;
}

function getCurrentVariation()
{
	var url = location.href;
	return url.substr(url.indexOf("://")+3).split("/")[1];   
}
