/*	Invisalign Country Selector Javascript */

var localCountry='gb';
 
var CountryNames = new Array();


CountryNames['en'] = {
    "au" : "Australia",
    "at" : "Austria",
    "mx" : "Latin America",
    "ca" : "Canada",
    "ch" : "Switzerland",
    "es" : "Spain",
    "fr" : "France",
    "de" : "Germany",
    "gb" : "Great Britain",
    "hk" : "Hong Kong",
    "ie" : "Ireland",
    "it" : "Italy",
    "jp" : "Japan",
    "kr" : "South Korea",
    "nl" : "Netherlands",
    "nz" : "New Zealand",
    "sg" : "Singapore",
    "th" : "Thailand",
    "tw" : "Taiwan",
    "us" : "United States"
};


CountryNames['de'] = {
    "au" : "Australien",
    "at" : "Austria",
    "mx" : "Lateinamerika",
    "ca" : "Kanada",
    "ch" : "Switzerland",
    "es" : "Spanien",
    "fr" : "Frankreich",
    "de" : "Deutschland",
    "gb" : "Go\u00DFbritannien",
    "hk" : "Hong Kong",
    "ie" : "Irland",
    "it" : "Italien",
    "sp" : "Japan",
    "kr" : "S\u00FCd Korea",
    "nl" : "Niederlande",
    "nz" : "Neuseeland",
    "sg" : "Singapur",
    "th" : "Thailand",
    "tw" : "Taiwan",
    "us" : "Vereinigte Staaten"
}; 


CountryNames['es'] = {
    "au" : "Austrailia",
    "at" : "Austria",
    "mx" : "Am\u0450rica Latina",
    "ca" : "Canad\u00E1",
    "ch" : "Suiza",
    "es" : "Espa\u00F1a",
    "fr" : "Francia",
    "de" : "Alemania",
    "gb" : "Gran Breta\u00F1a",
    "hk" : "Hong Kong",
    "ie" : "Irlanda",
    "it" : "Italia",
    "jp" : "Jap\u006Fn",
    "kr" : "South Korea",
    "nl" : "Pa\u00EDses Bajos",
    "nz" : "Nueva Zelanda",
    "sg" : "Singapur",
    "th" : "Tailandia",
    "tw" : "Taiw\u00E1n",
    "us" : "Estados Unidos"
};

 
 
CountryNames['fr'] = {
    "au" : "Australie",
    "at" : "Autriche",
    "mx" : "Amérique latine",
    "ca" : "Canada",
    "ch" : "Suisse",
    "es" : "Espagne",
    "fr" : "France",
    "de" : "Allemagne",
    "gb" : "Great Britain",
    "hk" : "Hong Kong",
    "ie" : "Irlande",
    "it" : "Italie",
    "jp" : "Japon",
    "kr" : "South Korea",
    "nl" : "Pays-Bas",
    "nz" : "New Zeland",
    "sg" : "Singapour",
    "th" : "Thaïlande",
    "tw" : "Taiwan",
    "us" : "United States"
}; 

 
CountryNames['it'] = {
    "au" : "Austrailia",
    "at" : "Austria",
    "mx" : "America Latina",
    "ca" : "Canada",
    "ch" : "Svizzera",
    "es" : "Spagna",
    "fr" : "Francia",
    "de" : "Germania",
    "gb" : "Gran Bretagna",
    "hk" : "Hong Kong",
    "ie" : "Irlanda",
    "it" : "Italia",
    "kr" : "la Corea del Sud",
    "nl" : "Paesi Bassi",
    "nz" : "Nuova Zelanda",
    "sg" : "Singapore",
    "th" : "Thailandia",
    "tw" : "Taiwan",
    "us" : "Stati Uniti"
}; 
 
 
var CountryLinks = new Array();

CountryLinks = {
    "au" : "http://www.invisalign.com.au",
    "at" : "http://www.invisalign.com/generalapp/eu/eu/index.html",
    "ca" : "http://www.invisalign.com/",
    "ch" : "http://www.invisalign.com/generalapp/eu/eu/index.html",
    "es" : "http://www.invisalign.com/generalapp/es/es/index.html",
    "fr" : "http://www.invisalign.com/generalapp/fr/fr/index.html",
    "de" : "http://www.invisalign.com/generalapp/de/de/index.html",
    "gb" : "http://www.invisalign.co.uk",
    "hk" : "http://www.invisalign.com.hk",
    "ie" : "http://www.invisalign.co.uk",
    "it" : "http://www.invisalign.it",
    "jp" : "http://www.invisalign.com/generalapp/jp/ja/index.html",
    "kr" : "http://www.invisalign.co.kr",
    "mx" : "http://www.invisalign.com.mx",
    "nl" : "http://www.invisalign.com/generalapp/eu/eu/index.html",
    "nz" : "http://www.invisalign.co.nz",
    "sg" : "http://www.invisalign.com.sg",
    "th" : "http://www.invisalign.com.au",
    "tw" : "http://www.invisalign.com.tw",
    "us" : "http://www.invisalign.com/"
};


var CountryList = new Array();

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.de/"));
CountryList[5]= new Array("Hong Kong", new Array("Hong Kong",    "http://www.invisalign.com.hk/opening.htm"));
CountryList[6]= new Array("Italy",    new Array("Italy",    "http://www.invisalign.it/"));
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("Espa&ntilde;ol",   "es"), new Array("English", "en"));
CountryList[10]= new Array("Spain",  new Array("Espa&ntilde;ol",   "http://www.invisalign.es/"));
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[13]= new Array("United Kingdom", new Array("English",    "en"));
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]='remote';
CountryType[7]='remote';
CountryType[8]='remote';
CountryType[9]='remote';
CountryType[10]='remote';
CountryType[11]='remote';
CountryType[12]='remote';
CountryType[13]='local';
CountryType[14]='remote';
CountryType[15]='remote';

	

function initCopyright(){
    if('es' == getCurrentVariation().toLowerCase()){
        var copy = document.getElementById("align_copyright");
        copy.innerHTML = "<p>&copy; 2000-2009 Align Technology, Inc. Todos los derechos reservados.</p>";
        chooseCountry.innerHTML="Elija un pa&iacute;s:";
    }
}
			       
							   

function initCountrySelect(countrySelectId, languageSelectId)
{


        var variation =  getCurrentVariation().toLowerCase();
        var countrySelect = document.getElementById(countrySelectId);
        var selected = getCurrentCountry();
        var selectIndex = 0;
	
    
        var countryOrderKey = new Array();
        var countryOrderdList = new Array();
    
        var iCountryName;
        var iCountryCode ;
   
        for (iCountryCode in CountryNames[variation] ) {
            iCountryName = CountryNames[variation][iCountryCode];
            countryOrderdList[countryOrderdList.length] = iCountryName;
            countryOrderKey[iCountryName] = iCountryCode ;
        }
        countryOrderdList.sort();
    
  
        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<countryOrderdList.length; i++) {
                iCountryName = countryOrderdList[i];
                iCountryCode = countryOrderKey[iCountryName];
   		    
                if ( iCountryCode == localCountry ) {	
                    selectIndex = i;
                    countrySelect.options[i]=new Option(iCountryName, "location.href='/'", i==0, i==selectIndex );
                } else {
                    countrySelect.options[i]=new Option(iCountryName , "location.href='" + CountryLinks[iCountryCode] + "'", i==0, i==selectIndex);
                }
            }
            countrySelect.selectedIndex = selectIndex ;
        }
	
        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];   
}

