if(typeof(_sysAjax)=="undefined")alert("_sysAjax is not defined!");
function ETSOOFloorChoose(sName,aFields,sXml)
{
    this.name=sName;
    this.fields=aFields;
    this.paraFields=[];
    this.currentIndex=-1;
    this.xml=sXml;
    this.seperator="-";
    this.defaultValueType=0;
    this.refresh=true;
    this.paras=[]; //[Key,Value]
    this.status=0;
}
ETSOOFloorChoose.prototype.setup=function(oContainer)
{
    var aFields=this.fields;
    if(oContainer&&this.name&&aFields&&this.xml&&this.status==0)
    {
        var o=this;
        this.container=oContainer;
        this.fieldObjects={};
        var iLen=aFields.length;
        if(iLen<2)return;
        for(var i=0;i<iLen;i++)
        {
            var sName=aFields[i];
            if(i>0)
            {
                oContainer.appendChild(document.createTextNode(this.seperator));
            }
            var oS=_sysDom.createObject(document,"select",["name",sName,"size",1,"Index",i]);
            oContainer.appendChild(oS);
            _sysDom.createOption(oS,"---","",false,document);
            oS.onchange=function(iType)
            {
                if(o._currentDS.isLoading)return;
                _sysDom.setCookie(this.name+"Cookie",this.options[this.selectedIndex].text);
                var iIndex=parseInt(this.getAttribute("Index"));
                if(!isNaN(iIndex))
                {
                    if(iIndex<o.fields.length)o._update(iIndex+1);
                }
            }
            this.fieldObjects[sName]=oS;
        }
        var oSpan=document.createElement("span");
        oContainer.appendChild(oSpan);
        this.reportSpan=oSpan;
        var oField=_sysDom.createInput(document,"hidden",this.name);
        oContainer.appendChild(oField);
        this.valueField=oField;
        this.status=1;
        this._update(0);
    }
}
ETSOOFloorChoose.prototype.clearCookies=function()
{
    var iLen=this.fields.length;
    for(var i=0;i<iLen;i++)
    {
        var sName=this.fields[i];
        _sysDom.setCookie(sName+"Cookie","");
    }
}
ETSOOFloorChoose.prototype.getField=function(iIndex)
{
    var sName=this.fields[iIndex];
    if(sName!=null)
    {
        return this.fieldObjects[sName];
    }
}
ETSOOFloorChoose.prototype.setField=function(iIndex,sValue)
{
    var sName=this.fields[iIndex];
    if(sName!=null)
    {
        _sysDom.setCookie(sName+"Cookie",sValue);
    }
}
ETSOOFloorChoose.prototype._update=function(iIndex)
{
    var sXml=this.xml;
    var bLastEmpty=false;
    for(var i=0;i<iIndex;i++)
    {
        var sName=this.fields[i];
        var oField=this.fieldObjects[sName];
        var sValue=oField.options[oField.selectedIndex].text;
        if(i==(iIndex-1)&&oField.value=="")
        {
            bLastEmpty=true;
            break;
        }
        var sPara=this.paraFields[i];
        if(sPara==null)sPara=sName;
        sXml=_sysDom.addPara(sXml,sPara,sValue);
    }
    if(this._currentDS==null||!this._currentDS.isLoading)
    {
        var oCurrentField=this.getField(iIndex);
        if(bLastEmpty)
        {
            if(this.currentIndex>iIndex-1)this.currentIndex=iIndex-1;
            if(oCurrentField)
            {
                oCurrentField.options.length=1;
                oCurrentField.options[0].selected=true;
                if(oCurrentField.onchange)oCurrentField.onchange(1);
            }
        }
        else
        {
            this.currentIndex=iIndex;
            if(oCurrentField)
            {
                var iLen=this.paras.length;
                for(var i=0;i<iLen;i+=2)
                {
                    sXml=_sysDom.addPara(sXml,this.paras[i],this.paras[i+1]);
                }
                var sDefault=_sysDom.getCookie(oCurrentField.name+"Cookie");
                var oDS=new ETSOODSObject(oCurrentField,sXml,sDefault);
                oDS.defaultValueType=this.defaultValueType;
                this._currentDS=oDS;
                oDS.refresh=this.refresh;
                oDS.textField=null;
                oDS.update();
            }
        }
        var sValue="";
        if(this.currentIndex>0)
        {
            sValue=this.getField(this.currentIndex-1).value;
        }
        this.valueField.value=sValue;
        if(sValue=="")
        {
            sValue="-";
        }
        this.reportSpan.innerHTML='<span class="Focus">('+sValue+')</span>';
    }
}
