/**include
//_javascript/js-wrapper.js;
//_javascript/load-wrapper.js;
*/
var select_brend = function (aDataBrands, aCountryBrand, oSelectCountry, oSelectBrand, winWr)
{
    this.winWr   = typeof(winWr)   != "undefined" ? winWr : _wrapper;

    this.aDataBrands = aDataBrands;

    this.aCountryBrand = aCountryBrand;

    this.oSelectCountry = oSelectCountry;
    this.oSelectBrand = oSelectBrand;

    this.winWr.setOnloadListener(this);
}

select_brend.prototype = {

    onload : function(evtWr)
    {
		var oSelectCountry = this.winWr.getElement(this.oSelectCountry);
		this.oSelectBrand = this.winWr.getElement(this.oSelectBrand);
		oSelectCountry.addListener(this, "onchange");
    },

    onchange : function(evtWr)
    {
        while(this.oSelectBrand.elm.firstChild) {
			this.oSelectBrand.elm.removeChild(this.oSelectBrand.elm.firstChild);
		}
		this.addOption(this.oSelectBrand, "all", 'Марка');
	    for(var id in this.aCountryBrand[evtWr.elmWr.elm.value]) {
            var brand = this.aDataBrands[this.aCountryBrand[evtWr.elmWr.elm.value][id]];
            this.addOption(this.oSelectBrand, brand.value, brand.text);
        }
    },

    addOption : function (element, value, text, defaultId)
	{
	    var opt = this.winWr.doc.createElement("option");
		opt.setAttribute("value", value);
		if (defaultId == value){
            opt.setAttribute("selected", "selected");
		}
		opt.appendChild(this.winWr.doc.createTextNode(text));
		element.elm.appendChild(opt);
	}
}