var whereDate={"cateGory":"{$cateGorycolor}","type":"{$typecolor}","special":"{$specialcolor}"};

$(function(){
 
    $.get('{url("archive/getScreening/langurl/".lang::getistemplate())}', function(data){
        var dataObj = JSON.parse(data);
        var cateGoryData=dataObj['cateGoryData'];
        var cateGory=document.getElementById('cateGory');
        setHtml(cateGoryData,cateGory,'cateGory');
        var typeData=dataObj['typeData'];
        var type=document.getElementById('type');
        setHtml(typeData,type,'type');
        var specialData=dataObj['specialData'];
        var special=document.getElementById('special');
        setHtml(specialData,special,'special');
        if(cateGoryData.length==0 && typeData.length==0 && specialData.length==0){
            $("#sxid").remove();
        }
    });
    function setHtml(data,elementStr,name) {
        if(data.length>0){
            var str='';
            var strcolor=false;
            for(var i=0;i<data.length;i++){
                var reg=/[`~！!@#$%^&*_+<>{}\/'[\]]/g;
                data[i].name=data[i].name.replace(reg,'-');
                if((name=='cateGory' && '{$cateGorycolor}'==data[i].id ) || (name=='type' && '{$typecolor}'==data[i].id)
                    || (name=='special' && '{$specialcolor}'==data[i].id)){
                    str =str+ '  <a href="javascript:void(0)" class="on" onclick="setWhere(\''+name+'\','+data[i].id+',this)" rel="'+data[i].name+'"  name="'+name+'" >'+data[i].name;+'</a>  '
                    whereDate['name']=data[i].id;
                    strcolor=true;
                }else{
                    str =str+ '  <a href="javascript:void(0)" onclick="setWhere(\''+name+'\','+data[i].id+',this)" rel="'+data[i].name+'"  name="'+name+'">'+data[i].name;+'</a>  '
                }

            }
            var strhead='';
            var classtype="";
            if(!strcolor){
                classtype="class=\"on\"";
                whereDate['name']='';
            }
            if(name=='cateGory' ){
                strhead='<a href="javascript:void(0)" '+classtype+'  rel="" onclick="setWhere(\''+name+'\',\'\',this)" name="'+name+'" >{lang('all_columns')}</a>';
            }else if (name=='type' ) {
                strhead='<a href="javascript:void(0)" '+classtype+' rel="" onclick="setWhere(\''+name+'\',\'\',this)" name="'+name+'" >{lang('all_type')}</a>';
            }else if (name=='special' ) {
                strhead='<a href="javascript:void(0)" '+classtype+'  rel="" onclick="setWhere(\''+name+'\',\'\',this)" name="'+name+'" >{lang('all_special')}</a>';
            }

            str=strhead+str;
            elementStr.innerHTML=str;
        }else{

            $(elementStr).parent().remove();
            whereDate['name']='';
        }
    }
});

function setWhere(name,key,setcolor){
    whereDate[name]=key;

    $("[name="+name+"]").removeClass("on");
    $(setcolor).addClass("on");

}

function getWhere(){

    var newpath="{url('archive/listservice-info/langurl/'.lang::getistemplate())}";
    for ( var key in whereDate) {
        newpath =newpath+'&'+key+'='+whereDate[key];
    }
    if($('#minprice').val() != '' ){
        newpath=newpath+'&minprice='+$('#minprice').val();
    }
    if($('#maxprice').val() != ''){
        newpath=newpath+'&maxprice='+$('#maxprice').val();
    }
    window.location.href = newpath;
}