<?php

/**
 * CountrySelectorWidget
 *
 * @author   Vladimir Galajda <galajda@gmail.com>
 **/
class CountrySelectorWidget extends CWidget
{
    /**
     * @var string
     */
    public $name;

    /**
     * @var string
     */
    public $value;

    /**
     * @var boolean
     */
    public $useCountryCode = true;

    /**
     * @var boolean
     */
    public $firstEmpty = true;

    /**
     * @var string
     */
    public $firstText;


    /**
     * @var string
     */
    public $defaultValue = NULL;
	
	 /**
     * @var string
     */
    public $class = NULL;


    public function init()
    {
        parent::init();

        if (empty($this->value)) {
            $this->value = $this->defaultValue;
        }

        $this->firstText = Yii::t('application', '(please select a nationality)');
    }

    public function run()
    {
        $content = "<select class=\"{$this->class}\"  name=\"{$this->name}\" id=\"{$this->id}\">";

        if ($this->firstEmpty) {
            $content .= "<option value=\"\">{$this->firstText}</option>";
        }

        $content .= $this->countriesForSelect();
        $content .= "</select>";

        echo $content;
    }

    public function countriesForSelect()
    {
        $ret = '';

        foreach ($this->countries as $code => $name) {
            $value = $this->useCountryCode ? $code : $name;
            $selected = $this->value == $value ? ' selected="selected"' : '';
            $ret .= '<option value="'.$value.'"'.$selected.'>'.$name.'</option>';
        }

        return $ret;
    }
		


    private $countries = array(
       'Albanian'=>'Albanian',	'Algerian'=>'Algerian',	'American'=>'American',	'Andorran'=>'Andorran',	'Angolan'=>'Angolan',	'Antiguans'=>'Antiguans',	'Argentinean'=>'Argentinean',	'Armenian'=>'Armenian',	'Australian'=>'Australian',	'Austrian'=>'Austrian',	'Azerbaijani'=>'Azerbaijani',	'Bahamian'=>'Bahamian',	'Bahraini'=>'Bahraini',	'Bangladeshi'=>'Bangladeshi',	'Barbadian'=>'Barbadian',	'Barbudans'=>'Barbudans',	'Batswana'=>'Batswana',	'Belarusian'=>'Belarusian',	'Belgian'=>'Belgian',	'Belizean'=>'Belizean',	'Beninese'=>'Beninese',	'Bhutanese'=>'Bhutanese',	'Bolivian'=>'Bolivian',	'Bosnian'=>'Bosnian',	'Brazilian'=>'Brazilian',	'British'=>'British',	'Bruneian'=>'Bruneian',	'Bulgarian'=>'Bulgarian',	'Burkinabe'=>'Burkinabe',	'Burmese'=>'Burmese',	'Burundian'=>'Burundian',	'Cambodian'=>'Cambodian',	'Cameroonian'=>'Cameroonian',	'Canadian'=>'Canadian',	'Cape Verdean'=>'Cape Verdean',	'Central African'=>'Central African',	'Chadian'=>'Chadian',	'Chilean'=>'Chilean',	'Chinese'=>'Chinese',	'Colombian'=>'Colombian',	'Comoran'=>'Comoran',	'Congolese'=>'Congolese',	'Costa Rican'=>'Costa Rican',	'Croatian'=>'Croatian',	'Cuban'=>'Cuban',	'Cypriot'=>'Cypriot',	'Czech'=>'Czech',	'Danish'=>'Danish',	'Djibouti'=>'Djibouti',	'Dominican'=>'Dominican',	'Dutch'=>'Dutch',	'East Timorese'=>'East Timorese',	'Ecuadorean'=>'Ecuadorean',	'Egyptian'=>'Egyptian',	'Emirian'=>'Emirian',	'Equatorial Guinean'=>'Equatorial Guinean',	'Eritrean'=>'Eritrean',	'Estonian'=>'Estonian',	'Ethiopian'=>'Ethiopian',	'Fijian'=>'Fijian',	'Filipino'=>'Filipino',	'Finnish'=>'Finnish',	'French'=>'French',	'Gabonese'=>'Gabonese',	'Gambian'=>'Gambian',	'Georgian'=>'Georgian',	'German'=>'German',	'Ghanaian'=>'Ghanaian',	'Greek'=>'Greek',	'Grenadian'=>'Grenadian',	'Guatemalan'=>'Guatemalan',	'Guinea-Bissauan'=>'Guinea-Bissauan',	'Guinean'=>'Guinean',	'Guyanese'=>'Guyanese',	'Haitian'=>'Haitian',	'Herzegovinian'=>'Herzegovinian',	'Honduran'=>'Honduran',	'Hungarian'=>'Hungarian',	'Icelander'=>'Icelander',	'Indian'=>'Indian',	'Indonesian'=>'Indonesian',	'Iranian'=>'Iranian',	'Iraqi'=>'Iraqi',	'Irish'=>'Irish',	'Israeli'=>'Israeli',	'Italian'=>'Italian',	'Ivorian'=>'Ivorian',	'Jamaican'=>'Jamaican',	'Japanese'=>'Japanese',	'Jordanian'=>'Jordanian',	'Kazakhstani'=>'Kazakhstani',	'Kenyan'=>'Kenyan',	'Kittian and Nevisian'=>'Kittian and Nevisian',	'Kuwaiti'=>'Kuwaiti',	'Kyrgyz'=>'Kyrgyz',	'Laotian'=>'Laotian',	'Latvian'=>'Latvian',	'Lebanese'=>'Lebanese',	'Liberian'=>'Liberian',	'Libyan'=>'Libyan',	'Liechtensteiner'=>'Liechtensteiner',	'Lithuanian'=>'Lithuanian',	'Luxembourger'=>'Luxembourger',	'Macedonian'=>'Macedonian',	'Malagasy'=>'Malagasy',	'Malawian'=>'Malawian',	'Malaysian'=>'Malaysian',	'Maldivan'=>'Maldivan',	'Malian'=>'Malian',	'Maltese'=>'Maltese',	'Marshallese'=>'Marshallese',	'Mauritanian'=>'Mauritanian',	'Mauritian'=>'Mauritian',	'Mexican'=>'Mexican',	'Micronesian'=>'Micronesian',	'Moldovan'=>'Moldovan',	'Monacan'=>'Monacan',	'Mongolian'=>'Mongolian',	'Moroccan'=>'Moroccan',	'Mosotho'=>'Mosotho',	'Motswana'=>'Motswana',	'Mozambican'=>'Mozambican',	'Namibian'=>'Namibian',	'Nauruan'=>'Nauruan',	'Nepalese'=>'Nepalese',	'Netherlander'=>'Netherlander',	'New Zealander'=>'New Zealander',	'Ni-Vanuatu'=>'Ni-Vanuatu',	'Nicaraguan'=>'Nicaraguan',	'Nigerian'=>'Nigerian',	'Nigerien'=>'Nigerien',	'North Korean'=>'North Korean',	'Northern Irish'=>'Northern Irish',	'Norwegian'=>'Norwegian',	'Omani'=>'Omani',	'Pakistani'=>'Pakistani',	'Palauan'=>'Palauan',	'Panamanian'=>'Panamanian',	'Papua New Guinean'=>'Papua New Guinean',	'Paraguayan'=>'Paraguayan',	'Peruvian'=>'Peruvian',	'Polish'=>'Polish',	'Portuguese'=>'Portuguese',	'Qatari'=>'Qatari',	'Romanian'=>'Romanian',	'Russian'=>'Russian',	'Rwandan'=>'Rwandan',	'Saint Lucian'=>'Saint Lucian',	'Salvadoran'=>'Salvadoran',	'Samoan'=>'Samoan',	'San Marinese'=>'San Marinese',	'Sao Tomean'=>'Sao Tomean',	'Saudi'=>'Saudi',	'Scottish'=>'Scottish',	'Senegalese'=>'Senegalese',	'Serbian'=>'Serbian',	'Seychellois'=>'Seychellois',	'Sierra Leonean'=>'Sierra Leonean',	'Singaporean'=>'Singaporean',	'Slovakian'=>'Slovakian',	'Slovenian'=>'Slovenian',	'Solomon Islander'=>'Solomon Islander',	'Somali'=>'Somali',	'South African'=>'South African',	'South Korean'=>'South Korean',	'Spanish'=>'Spanish',	'Sri Lankan'=>'Sri Lankan',	'Sudanese'=>'Sudanese',	'Surinamer'=>'Surinamer',	'Swazi'=>'Swazi',	'Swedish'=>'Swedish',	'Swiss'=>'Swiss',	'Syrian'=>'Syrian',	'Taiwanese'=>'Taiwanese',	'Tajik'=>'Tajik',	'Tanzanian'=>'Tanzanian',	'Thai'=>'Thai',	'Togolese'=>'Togolese',	'Tongan'=>'Tongan',	'Trinidadian or Tobagonian'=>'Trinidadian or Tobagonian',	'Tunisian'=>'Tunisian',	'Turkish'=>'Turkish',	'Tuvaluan'=>'Tuvaluan',	'Ugandan'=>'Ugandan',	'Ukrainian'=>'Ukrainian',	'Uruguayan'=>'Uruguayan',	'Uzbekistani'=>'Uzbekistani',	'Venezuelan'=>'Venezuelan',	'Vietnamese'=>'Vietnamese',	'Welsh'=>'Welsh',	'Yemenite'=>'Yemenite',	'Zambian'=>'Zambian',	'Zimbabwean'=>'Zimbabwean',	
    );
}
?>