function dynamicSelect(id1, id2, id3) {  
    // Feature test to see if there is enough W3C DOM support  
    if (document.getElementById && document.getElementsByTagName) {  
        // Obtain references to both select boxes  
        var sel1 = document.getElementById(id1);  
        var sel2 = document.getElementById(id2); 
        var sel3 = document.getElementById(id3); 
                
        // Clone the dynamic select box  
        var clone = sel2.cloneNode(true);  
                var clonex = sel3.cloneNode(true);
        // Obtain references to all cloned options  
        var clonedOptions = clone.getElementsByTagName("option"); 
                var clonedOptionsx = clonex.getElementsByTagName("option");
                
        // Onload init: call a generic function to display the related options in the dynamic select box  
        refreshDynamicSelectOptions(sel1, sel2, clonedOptions);  
                refreshDynamicSelectOptions2(sel1, sel3, clonedOptionsx);
        // Onchange of the main select box: call a generic function to display the related options in the dynamic select box  
        sel1.onchange = function() {  
            refreshDynamicSelectOptions(sel1, sel2, clonedOptions); 
                        refreshDynamicSelectOptions2(sel1, sel3, clonedOptionsx);
        
                } 
                
        //         sel2.onchange = function() {  
        //     refreshDynamicSelectOptions2(sel2, sel3, clonedOptionsx);  
        // }
                
    }  
}  

function refreshDynamicSelectOptions(sel1, sel2, clonedOptions) {  
    // Delete all options of the dynamic select box  
    while (sel2.options.length) {  
        sel2.remove(0);  
                    
    }  
        
        
        
    // Create regular expression objects for "select" and the value of the selected option of the main select box as class names  
    var pattern1 = /( |^)(select)( |$)/;  
    var pattern2 = new RegExp("( |^)(" + sel1.options[sel1.selectedIndex].value + ")( |$)");  
    // Iterate through all cloned options  
    for (var i = 0; i < clonedOptions.length; i++) {  
        // If the classname of a cloned option either equals "select" or equals the value of the selected option of the main select box  
        if (clonedOptions[i].className.match(pattern1) || clonedOptions[i].className.match(pattern2)) {  
            // Clone the option from the hidden option pool and append it to the dynamic select box  
            sel2.appendChild(clonedOptions[i].cloneNode(true));  
  
         
            }                  
    }  

}  





function refreshDynamicSelectOptions2(sel2, sel3, clonedOptionsx) {  
    // Delete all options of the dynamic select box  
    while (sel3.options.length) {  
        sel3.remove(0);  
                    
    }  
        
        
        
            // Create regular expression objects for "select" and the value of the selected option of the main select box as class names  
    var pattern1 = /( |^)(select)( |$)/;     
    var pattern2 = new RegExp("( |^)(" + sel2.options[sel2.selectedIndex].value + ")( |$)");  
    // Iterate through all cloned options  
    for (var i = 0; i < clonedOptionsx.length; i++) {  
        // If the classname of a cloned option either equals "select" or equals the value of the selected option of the main select box  
        if (clonedOptionsx[i].className.match(pattern1) ||clonedOptionsx[i].className.match(pattern2)) {  
            // Clone the option from the hidden option pool and append it to the dynamic select box  
            sel3.appendChild(clonedOptionsx[i].cloneNode(true));  
        }  
    }  

}  
 window.onload = function() {
     dynamicSelect("pclass", "price-min", "price-max");
 }

