﻿// ==UserScript==
// @name                head部的搜索框js
// @description         搜索js
// @created date        2009/9/26   14:16
// @created author      Tiger(tigershi0507@gmail.com)
// @version             1.0.1
// @version owner       Copyright (C) 2009-2010 keerr.com All rights reserved.
// ==/UserScript==

/*************************************************
verified time 	:	2009/9/26   15:23
verified author	:	Tiger
verified purpose:	修改了search input的keyup时间，统一到了keeerr.toggleTabs.js中去了
**************************************************/
/********************************************************************
verified time   : 2009/11/6   15:41
verified author : Martin
verified purpose: 修改提交方式，统一为地址栏传值
*********************************************************************/
$(function() {
    initHeadSearch();
});

function initHeadSearch() {
    $SearchInput = $("#search_input");
    //    $SearchInput.keyup(function(e) {      //  这里的keyup事件在keerr.toggleTabs.js中已经定义，不需要重复定义
    //        e = e || window.event;
    //        ;
    //        if (e.keyCode === 13) {
    //            doSearch(encodeURIComponent($.trim(this.value)));
    //        }
    //    });

    $("#searchBtn").click(function() {
        doSearch(encodeURIComponent($.trim($SearchInput.val())), $SearchInput);
    });

    $("form#head_search_form").submit(function() {

    });

}

function doSearch(v, $SearchInput) {
    var $SearchButton = $("#searchBtn");
    //    if ($.cookie("fang0_Searchhistorytypes") != null && $.cookie("fang0_SearchhistorytxtSearchKws") != null) {
    //        var co1s = $.cookie("fang0_Searchhistorytypes").split(",");
    //        var co2s = $.cookie("fang0_SearchhistorytxtSearchKws").split(",");
    //        var co1 = $("#hl_header_search_type").attr("value");
    //        var co2 = v;
    //        var cnt = 1;
    //        for (var i = 0; i < co1s.length && cnt < 10; i++) {
    //            if ($("#hl_header_search_type").attr("value") == co1s[i] && v == co2s[i]) {
    //                continue;
    //            }
    //            else {
    //                co1 += "," + co1s[i];
    //                co2 += "," + co2s[i];
    //                cnt++;
    //            }
    //        }
    //        $.cookie("fang0_Searchhistorytypes", co1);
    //        $.cookie("fang0_SearchhistorytxtSearchKws", co2);
    //    }
    //    else {
    //        $.cookie("fang0_Searchhistorytypes", $("#hl_header_search_type").attr("value"));
    //        $.cookie("fang0_SearchhistorytxtSearchKws", v);
    //    }
    //
    switch (headSearchType) {
        case 0: //全部
//            window.location.href = "/search.aspx?txtSearchKw=" + v;
//            return false;
        case 1: //资讯
            if (v === "" || v === encodeURIComponent("输入资讯标题或内容的关键字进行查询")) {
                $SearchInput.val("输入资讯标题或内容的关键字进行查询");
                return false;
            }
            window.location.href = "/news/newsearch.aspx?txtSearchKw=" + v;
            return true;
        case 2: //楼盘
            if (v === "" || v === encodeURIComponent("输入楼盘项目名称、地址等关键字进行查询")) {
                $SearchInput.val("输入楼盘项目名称、地址等关键字进行查询");
                return false;
            }
            window.location.href = "/lp/lp_search.aspx?txtSearchKw=" + v;
            return true;
        case 3: //二手房
            if (v === "" || v === encodeURIComponent("输入二手房地址等关键字进行查询")) {
                $SearchInput.val("输入二手房地址等关键字进行查询");
                return false;
            }
            window.location.href = "/fy/secsearch.aspx?txtSearchKw=" + v;
            return true;

        case 4: //租房
            if (v === "" || v === encodeURIComponent("输入租房地址等关键字进行查询")) {
                $SearchInput.val("输入租房地址等关键字进行查询");
                return false;
            }
            window.location.href = "/fy/zf_search.aspx?txtSearchKw=" + v;
            return true;
            //        case 5: //知识林
            //            document.location.href = "/know/zsksearch.aspx?txtSearchKw=" + v;
            //            break;
        case 8: //商林
            window.location.href = "/shl/shlsearch.aspx?txtSearchKw=" + v;
            return true;
        case 7: //问答
            window.location.href = "/know/knowsearch.aspx?txtSearchKw=" + v;
            return true;
        case 5: //地图
            if (v === "" && v === encodeURIComponent("输入楼盘名称进行查询")) {
                $SearchInput.val("输入楼盘名称进行查询");
                return true;
            }
            else {
                window.location.href = "/map/index.aspx?txtSearchKw=" + v; //decodeURI(v);
                return false;
            }
        case 6: //活动
            //document.location.href = "/map/index.aspx?txtSearchKw=" + v;
            break;
        //        case 9: //图片 
        //            document.location.href = "/pic/index.aspx?txtSearchKw=" + v; 
        //            break; 
        //        case 10: //社区 
        //            break; 
        default: //全站
            //document.location.href = "/search.aspx?txtSearchKw=" + v; break;
    }
    return false;
}