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

    var debug = 0;

    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;

        var slidx = document[formName][sendName].selectedIndex;
            
        if ( slidx != -1 )
            sendValue = document[formName][sendName].options[slidx].value;
        else
            sendValue = 0;
            
        toBeFilled = selNames[no];
        toBeTitle = selTitles[no];
        
        var dela = no;
        if( document[formName][sendName].id.indexOf('ditg') == 1 )
        {
	        if( slidx == 1 )
	        {
        		if(document[formName][sendName].options[1].text == 'Select this and type new option')
        			document[formName][sendName].options[1].text = '';
        		var gas = document[formName][toBeFilled];
        		gas.disabled = false;
        		dela = no + 1;
        		
	        }
	        else
	        	if(document[formName][sendName][1].text == '')
	        	{
        			document[formName][sendName][1].text = 'Select this and type new option';
        			document[formName][sendName][1].value = '';
				}
		}
		
        if( document[formName][toBeFilled] != null )
        {
			if( document[formName][toBeFilled].id.indexOf('ditg') == 1 )
		    {
	            document[formName][toBeFilled].options[1] = new Option( 'Select this and type new option', '');
	            document[formName][toBeFilled].options[1].style.color = '#ffffff';
	           	document[formName][toBeFilled].options[1].style.backgroundColor = '#005C43';
	            document[formName][toBeFilled].length = 2;
	            pls = 1;
		    }
        }
        
        if ( toBeFilled != null )
        {
            if ( sendValue == '' )
            {
                for (var i = dela; i < selNames.length; i++)
                {
                    currentSel = document[formName][selNames[i]];
                    currentSel.length = 0;
                    currentSel.options[0] = new Option( selTitles[i] , '');
                    currentSel.disabled = true;
                }
            }
            else
            {
                if ( param != 0 )
                    ExecuteA(path+"AJAX/"+formName+".php", sndName+"="+sendValue+param, FillCascade);    
                else
                    ExecuteA(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, '');

        if( slOras != 0 )
        {
        	toBeValue = slOras;
        	slOras = 0;
        }
        
        serverResponse = serverResponse.replace( /\\'/g, "'" );

        var pls = 0;
        if( workOnSel.id.indexOf('ditg') == 1 )
        {
            workOnSel.options[1] = new Option( 'Select this and type new option', '');
            workOnSel.options[1].style.color = '#ffffff';
           	workOnSel.options[1].style.backgroundColor = '#005C43';
            pls = 1;
        }
        
        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+pls] = new Option(aOptions[1], aOptions[0]);
                if ( aOptions[0] == toBeValue )
                    workOnSel.options[i+1+pls].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
            {
            	//alert( sndName+"="+sendValue );
                ExecuteA(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, '');

            serverResponse = serverResponse.replace( /\\'/g, "'" );

            var aOptionPairs = serverResponse.split('|');
            
            var pls = 0;
            if( workOnSel.id.indexOf('ditg') == 1 )
            {
            	workOnSel.options[1] = new Option( 'Select this and type new option', '');
            	workOnSel.options[1].style.color = '#ffffff';
            	workOnSel.options[1].style.backgroundColor = '#005C43';
            	
            	pls = 1;
            }
            
            for( var i = 0; i < aOptionPairs.length; i++ )
            {
                if (aOptionPairs[i].indexOf('~') != -1) 
                {
                    var aOptions = aOptionPairs[i].split('~');
                    workOnSel.options[i+1+pls] = new Option(aOptions[1], aOptions[0]);
                    if ( refillValues[cursor] != null )
                        if ( aOptions[0] == refillValues[cursor+1] )
                            workOnSel.options[i+1+pls].selected = true; 
                }
            }

            cursor ++;
            if ( cursor >= refillValues.length )
            {
                cursorS++;
                getSet();
            }
            else
                CascadeR();
    }

