﻿jQuery.fn.search = function(){
    $(this).each(function(){
        var sObj = $(this);
        
        if($(this).attr("type")=="text"){
            sObj.keypress(function(event){
                if(event.keyCode==13){
                    if($("#keyword1")){
                        if($("#keyword1").val()!="输入关键字，搜你想要的课程"){
                            $("#keyword").val($("#keyword1").val());
                        }
                    }
                    var key=$.trim($("#keyword").val()),city=$("#cityid").val(),catspell=$("#catspell").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;
                    }
                    if(key){
                        jQuery.post("/action/filter",{keyword:key},function(data){
                            window.location.href = "http://www.tostudy.com.cn/zhaosheng/list.html?keyword="+ encodeURI(data) + sParam;
                        })
                    }else{
                        window.location.href = "http://www.tostudy.com.cn/zhaosheng/list.html?keyword=" + sParam;
                    }
                }
            });
        }else{
            sObj.click(function(){
                if($("#keyword1")){
                    if($("#keyword1").val()!="输入关键字，搜你想要的课程"){
                        $("#keyword").val($("#keyword1").val());
                    }
                }
                var key=$.trim($("#keyword").val()),city=$("#cityid").val(),catspell=$("#catspell").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;
                }
                if(key){
                    jQuery.post("/action/filter",{keyword:key},function(data){
                        window.location.href = "http://www.tostudy.com.cn/zhaosheng/list.html?keyword="+ encodeURI(data) + sParam;
                    })
                }else{
                    window.location.href = "http://www.tostudy.com.cn/zhaosheng/list.html?keyword=" + sParam;
                }
            });
        }        
    });
}
