    var formName;
    var setID;
    var toBeFilled;
    var toBeTitle;
    var toBeValue;

    var debug = 0;

    var refillForm;
    var refillSets = new Array();
    var refillNames = new Array();
    var refillTitles = new Array();
    var refillValues = new Array();
    
    var cursorS=0, cursor=1;
 
    function Cascade(no,set,obj,param)
    {
        formName = obj.name;
        setID = set;
        selNames = Forms[formName][set]['n'].split(",");
        selTitles = Forms[formName][set]['t'].split(",");
        
        if ( Forms[formName][set]['v'] != null )
        {
            selValues = Forms[formName][set]['v'].split(",");
            toBeValue = selValues[no];
        }
        
        sendName = selNames[no-1];
        if ( sendName.indexOf("rq_") >= 0 )
            sndName = sendName.substr(3);
        else 
            sndName = sendName;    
        
        if ( document[formName][sendName].selectedIndex != -1 )
            sendValue = document[formName][sendName][document[formName][sendName].selectedIndex].value;
        else
            sendValue = 0;
        toBeFilled = selNames[no];
        toBeTitle = selTitles[no];
        
        if ( toBeFilled != null )
        {
            if ( sendValue == '' )
            {
                for (var i = no; i < selNames.length; i++)
                {
                    currentSel = document[formName][selNames[i]];
                    currentSel.length = 0;
                    currentSel.options[0] = new Option( selTitles[i] , '');
                    currentSel.disabled = true;
                }
            }
            else
            {
				//alert(site_path+"ajax/"+formName+".php");
                if ( param != 0 )
                    ExecuteA(site_path+"ajax/"+formName+".php", sndName+"="+sendValue+param, FillCascade);    
                else
                    ExecuteA(site_path+"ajax/"+formName+".php", sndName+"="+sendValue, FillCascade);
            }
                
        }
    }
    
    function FillCascade()
    {
        workOnSel = document[formName][toBeFilled];
        workOnSel.disabled = false;
        
        if (xhReq.readyState != 4) 
        { 
            return; 
        }
        var serverResponse = xhReq.responseText;

	if ( debug )        
	    alert (serverResponse);
        
        workOnSel.length = 0;
        workOnSel.options[0] = new Option(toBeTitle, '');
        
        var aOptionPairs = serverResponse.split('|');
        for( var i = 0; i < aOptionPairs.length; i++ )
        {
            if (aOptionPairs[i].indexOf('~') != -1) 
            {
                var aOptions = aOptionPairs[i].split('~');
                workOnSel.options[i+1] = new Option(aOptions[1], aOptions[0]);
                if ( aOptions[0] == toBeValue )
                    workOnSel.options[i+1].selected = true; 
            }  
        }
    }
    
    function CascadeRefill()
    {
        for( var frm in Forms )
        {
            if ( document[frm].sentFormName != null )
                if ( frm == document[frm].sentFormName.value )
                {
                    refillForm = frm;
                    break;
                }
        }
        
        i = 0;
        for ( var set in Forms[refillForm] )
        {
            refillSets[i] = set;
            i++;
        }
        getSet();
    }
    
    function getSet()
    {
        if ( cursorS < refillSets.length )
        {
            refillNames = Forms[refillForm][refillSets[cursorS]]['n'].split(",");
            refillTitles = Forms[refillForm][refillSets[cursorS]]['t'].split(",");
            if ( Forms[refillForm][refillSets[cursorS]]['v'] != null )
                refillValues = Forms[refillForm][refillSets[cursorS]]['v'].split(",");
                
            cursor = 0;
            CascadeR();
        }
    }
    
    function CascadeR()
    {
        sendName = refillNames[cursor];
        if ( sendName.indexOf("rq_") >= 0 )
            sndName = sendName.substr(3);
        else 
            sndName = sendName;    
        
        if ( cursor+1 < refillNames.length )
        {
            sendValue = refillValues[cursor];
            toBeFilled = refillNames[cursor+1];
            toBeTitle = refillTitles[cursor+1];

            if ( sendValue == '' )
            {
                for (var i = cursor+1; i < refillNames.length; i++)
                {
                    currentSel = document[refillForm][refillNames[i]];
                    currentSel.length = 0;
                    currentSel.options[0] = new Option( refillTitles[i] , '');
                    currentSel.disabled = true;
                }
            }
            else
                ExecuteA(site_path+"ajax/"+refillForm+".php", sndName+"="+sendValue, FillCascadeR);
        }
        else
        {
            cursorS++;
            getSet();
        }
    }
    
    function FillCascadeR()
    {
            workOnSel = document[refillForm][refillNames[cursor+1]];
            workOnSel.disabled = false;
            
            if (xhReq.readyState != 4) 
            { 
                return; 
            }
            var serverResponse = xhReq.responseText;   

            if (debug)	
            	alert (serverResponse);
            
            workOnSel.length = 0;
            workOnSel.options[0] = new Option(toBeTitle, '');
            
            var aOptionPairs = serverResponse.split('|');
            for( var i = 0; i < aOptionPairs.length; i++ )
            {
                if (aOptionPairs[i].indexOf('~') != -1) 
                {
                    var aOptions = aOptionPairs[i].split('~');
                    workOnSel.options[i+1] = new Option(aOptions[1], aOptions[0]);
                    if ( refillValues[cursor] != null )
                        if ( aOptions[0] == refillValues[cursor+1] )
                            workOnSel.options[i+1].selected = true; 
                }  
            }
            
            cursor ++;
            if ( cursor >= refillValues.length )
            {
                cursorS++;
                getSet();
            }
            else
                CascadeR();
        
    }

