﻿var InfoHelper={RootCategorySelect:null,SubCategorySelect:null,TypeSelect:null,AreaSelect:null,Categories:null,AllowEmptyOption:false,Init:function(rcselect,scselect,typeselect,areaselect,categories,allowemptyoption)
{with(this)
{RootCategorySelect=rcselect;SubCategorySelect=scselect;TypeSelect=typeselect;AreaSelect=areaselect;Categories=categories;AllowEmptyOption=allowemptyoption;ShowSubCategories();ShowTypes();RootCategorySelect.onchange=function(e){InfoHelper.ShowSubCategories();}
SubCategorySelect.onchange=function(e){InfoHelper.ShowTypes();}}},ShowSubCategories:function()
{with(this)
{if(!Categories||!SubCategorySelect||!RootCategorySelect)
return;_clearOptions(SubCategorySelect);var rootcid=RootCategorySelect.value;_buildOptions(SubCategorySelect,Categories[rootcid],AllowEmptyOption);ShowTypes();}},ShowTypes:function()
{with(this)
{if(!Categories||!SubCategorySelect||!RootCategorySelect||!TypeSelect)
return;_clearOptions(TypeSelect);var rootcid=RootCategorySelect.value;var cid=parseInt(SubCategorySelect.value);var types=null;if(!isNaN(cid))
{var subcs=Categories[rootcid];for(var i=0;i<subcs.length;i++)
if(subcs[i][0]==cid)
{types=subcs[i][2];break;}}
_buildOptions(TypeSelect,types,AllowEmptyOption);}},AttachSelectValues:function(categoryid,subcategoryid,typeid,areaid)
{with(this)
{if(categoryid>0)
_selectOption(RootCategorySelect,categoryid);ShowSubCategories()
if(subcategoryid>0)
_selectOption(SubCategorySelect,subcategoryid);ShowTypes();if(typeid>0)
_selectOption(TypeSelect,typeid);if(areaid>0)
_selectOption(AreaSelect,areaid);}},_selectOption:function(select,nvalue)
{if(!select)
return;with(select)
for(var i=0,il=options.length;i<il;i++)
options[i].selected=options[i].value==nvalue;},_clearOptions:function(select)
{if(!select)
return;for(var i=0,il=select.options.length;i<il;i++)
select.remove(0);},_buildOptions:function(select,data,allowempty)
{if(!select)
return;if(!data||data.length==0)
return select.options.add(this._buildOption("","---"));if(allowempty)
select.options.add(this._buildOption("","---"));for(var i=0;i<data.length;i++)
select.options.add(this._buildOption(data[i][0],data[i][1]));},_buildOption:function(value,text)
{var o=document.createElement("option");o.value=value;o.text=text;return o;}}