﻿// JScript File

function ChooseCountry(ClientId)
{
    this.LoadCountries = 
        function ()
        {
	        var i = 0;
	        var len = this.lstCountries.options.length;
        	
	        for(i = 0; i < len; i++)
	        {
		        this.g_arrCountries[i] = new Array();
		        this.g_arrCountries[i][0] = this.lstCountries.options[i].text;
		        this.g_arrCountries[i][1] = this.lstCountries.options[i].value;
	        }
        }
        
    this.Init = 
        function()
        {
            this.txtSelectCountry = document.getElementById(this.ClientId + '_txtSelectCountry');
            this.lstCountries = document.getElementById(this.ClientId + '_lstCountries');
            this.LoadCountries();
        }
        
    this.CleanField = 
        function ()
        {
            this.txtSelectCountry.value = "";
	        this.txtSelectCountry.className = "SelectdeChooseCountryInputTextDes";
        }
        
    this.UpdateCountries = 
        function ()
        {
        	var value = this.txtSelectCountry.value;
	        
	        while(this.lstCountries.length > 0)
	        {
		        this.lstCountries.remove(0);
        	}
	        
	        var oOption;
	        for(var i = 0; i < this.g_arrCountries.length; i++)
	        {
		        if(this.g_arrCountries[i][0].indexOf(value) == 0)
		        {
			        oOption = document.createElement("OPTION");
			        this.lstCountries.options.add(oOption);
        		
			        oOption.text = this.g_arrCountries[i][0];
			        oOption.value = this.g_arrCountries[i][1];
		        }
	        }
        }
    
    this.CountrySelected = 
        function()
        {
            var countryName = this.GetSelectedCountry();
            this.txtSelectCountry.value = countryName;
        }
            
    this.GetSelectedCountry = 
        function()
        {
            var res = '';
            if(this.lstCountries.selectedIndex != -1)
            {
                res = this.lstCountries.options[this.lstCountries.selectedIndex].text;
            }
            
            return res;
        }

    this.GetSelectedCountryValue = 
        function()
        {
            var res = '';
            if(this.lstCountries.selectedIndex != -1)
            {
                res = this.lstCountries.options[this.lstCountries.selectedIndex].value;
            }
            
            return res;
        }
        
    this.ClientId = ClientId;
    this.txtSelectCountry = null;
    this.lstCountries = null;
    this.g_arrCountries = new Array();
}


