﻿jQuery.fn.search = function(){
    $(this).each(function(){
        var sObj = $(this);
        
        if($(this).attr("type")=="text"){
            sObj.keypress(function(event){
                if(event.keyCode==13){
                    var key=$("#keyword").val(),catspell=$("#catspell").val(),city=$("#areaNo").val(),discount=$("#discount").val(),recommend=$("#recommend").val(),card=$("#consumecard").val();
                    var sParam="";
                    if(city){
                        sParam+="&city="+city;
                    }
                    if(catspell){
                        sParam+="&cate="+catspell
                    }
                    if(discount){
                        sParam+="&discount="+discount;
                    }
                    if(recommend){
                        sParam+="&recommend="+recommend;
                    }
                    if(card){
                        sParam+="&iscard="+card;
                    }
                    jQuery.post("/action/filter",{keyword:key},function(data){
                        window.location.href = "/zhaosheng/list.html?keyword="+ encodeURI(data) + sParam;
                    })
                }
            });
        }else if($(this).attr("type")=="checkbox"){
            sObj.click(function(){
                if($(this).attr("checked")){
                    $(this).val("1");
                }else{
                    $(this).val("0");
                }
                var key=$("#keyword").val(),catspell=$("#catspell").val(),city=$("#areaNo").val(),discount=$("#discount").val(),recommend=$("#recommend").val(),card=$("#consumecard").val();
                var sParam="";
                if(city){
                    sParam+="&city="+city;
                }
                if(catspell){
                    sParam+="&cate="+catspell
                }
                if(discount){
                    sParam+="&discount="+discount;
                }
                if(recommend){
                    sParam+="&recommend="+recommend;
                }
                if(card){
                    sParam+="&iscard="+card;
                }
                jQuery.post("/action/filter",{keyword:key},function(data){
                    window.location.href = "/zhaosheng/list.html?keyword="+ encodeURI(data) + sParam;
                })
            });
        }else if($(this).attr("type")=="image"){
            sObj.click(function(){
                var key=$("#keyword").val(),catspell=$("#catspell").val(),city=$("#areaNo").val(),discount=$("#discount").val(),recommend=$("#recommend").val(),card=$("#consumecard").val();
                var sParam="";
                if(city){
                    sParam+="&city="+city;
                }
                if(catspell){
                    sParam+="&cate="+catspell
                }
                if(discount){
                    sParam+="&discount="+discount;
                }
                if(recommend){
                    sParam+="&recommend="+recommend;
                }
                if(card){
                    sParam+="&iscard="+card;
                }
                jQuery.post("/action/filter",{keyword:key},function(data){
                    window.location.href = "/zhaosheng/list.html?keyword="+ encodeURI(data) + sParam;
                })
            });
        }else{
            $("#sareaNo option").each(function(){
                if($(this).val()==$("#areaNo").val()){
                    $("#sareaNo").val($("#areaNo").val());
                    return false;
                }else{
                    $("#sareaNo").val('');
                }
            });
            sObj.change(function(){
                var key=$("#keyword").val(),catspell=$("#catspell").val(),city=$("#sareaNo").val(),discount=$("#discount").val(),recommend=$("#recommend").val(),card=$("#consumecard").val();
                var sParam="";
                if(city!=-1){
                    sParam+="&city="+city;
                }
                if(catspell){
                    sParam+="&cate="+catspell
                }
                if(discount){
                    sParam+="&discount="+discount;
                }
                if(recommend){
                    sParam+="&recommend="+recommend;
                }
                if(card){
                    sParam+="&iscard="+card;
                }
                jQuery.post("/action/filter",{keyword:key},function(data){
                    window.location.href = "/zhaosheng/list.html?keyword="+ encodeURI(data) + sParam;
                })
            });
        }       
    });
}
