/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function addFilter(elem,param,paramtype){
    var parent = elem.parentNode;

    parent.removeChild(elem);
    if(paramtype == "site"){

        $("siteApplied").appendChild(elem);
        elem.onclick = function(){
            removeFilter(elem,param,paramtype);
        }
    
    }
    else if(paramtype == "type"){

        $("typeApplied").appendChild(elem);
        elem.onclick = function(){
            removeFilter(elem,param,paramtype);
        }

    }
    else{

        $("attribsApplied").appendChild(elem);
        elem.onclick = function(){
            removeFilter(elem,param,paramtype);
        }

    }
    applyFilter();
       
    

}

function removeFilter(elem,param,paramtype){
    var parent = elem.parentNode;

    parent.removeChild(elem);
    if(paramtype == "site"){

        $("siteNotApplied").appendChild(elem);
        elem.onclick = function(){
            addFilter(elem,param,paramtype);
        }

    }
    else if(paramtype == "type"){

        $("typeNotApplied").appendChild(elem);
        elem.onclick = function(){
            addFilter(elem,param,paramtype);
        }

    }
    else{

        $("attribsNotApplied").appendChild(elem);
        elem.onclick = function(){
            addFilter(elem,param,paramtype);
        }

    }
    applyFilter();
}

function applyFilter(){
    var filterString = "?";
    var buttons = $$("#appliedFilters .filterBox .filterButton");
    
    for(var i = 0; i < buttons.length;i++){
        var tmp = buttons[i].id;

        tmp = tmp.split("_");
        filterString += tmp[0]+"[]="+tmp[1]+"&";
    }
    filterString = filterString.substr(0, filterString.length-1);
    //alert(filterString);
    new Ajax.Request("pages/locations/ajax/searchDisplay.jsp"+filterString,{

        method:"get",
        onSuccess:function(str){
            $("mapContainer").innerHTML = str.responseText;
        }

    });


}
