﻿/*----------------------------------------------------------------
Copyright (C) 2009 Subcon China Corporation
File function:常用JS函数于功能模块(依赖于jquery)
Create tag:lyan 2009-5-13
----------------------------------------------------------------*/
// get the culture of client
jQuery.GetLang = function() {
    var language = "";
    // custom variables of calendar
    var MonthConfig, WeekConfig, CloseConfig, TodayConfig, ClearConfig;
    var cookieValue = null;
    
    if (document.cookie && document.cookie != '') {
        var cookies = document.cookie.split(';');
        for (var i = 0; i < cookies.length; i++) {
            var cookie = cookies[i].replace(/(^\s*)|(\s*$)/g, "") ;
            if (cookie.substring(0, "CultureName".length + 1) == ("CultureName" + '=')) {
                cookieValue = decodeURIComponent(cookie.substring("CultureName".length + 1));
                break;
            }
        }
    }
    
    if (cookieValue) {
        language = cookieValue;
    }
    else {
        if (navigator.appName == "Netscape") {
            language = navigator.language;
        }
        else {
            language = navigator.browserLanguage;
        }
    }
    language = language.toLowerCase();
    
    return language;
}

if (jQuery.GetLang().toLowerCase().indexOf("zh-cn") >= 0) {
    document.writeln("<script src='/javascript/Lang/zh-cn.js' type='text/javascript'></script>");
}
else {
    document.writeln("<script src='/javascript/Lang/en.js' type='text/javascript'></script>");
}

// check if form value changed
// true if changed else false
jQuery.IsFormChanged = function() {
    var isChanged = false;
    var form = document.forms[0];
    for (var i = 0; i < form.elements.length; i++) {
        var element = form.elements[i];
        var type = element.type;
        if (type == "text" || type == "hidden" || type == "textarea" || type == "button") {
            if (element.value != element.defaultValue) {
                isChanged = true;
                break;
            }
        } else if (type == "radio" || type == "checkbox") {
            if (element.checked != element.defaultChecked) {
                isChanged = true;
                break;
            }
        } else if (type == "select-one" || type == "select-multiple") {
            for (var j = 0; j < element.options.length; j++) {
                if (element.options[j].selected != element.options[j].defaultSelected) {
                    isChanged = true;
                    break;
                }
            }
        } else {
            //  etc...
        }
    }
    return isChanged;
}

// xss encode to forbid xxx hack
jQuery.XSSEncode = function(s) {
    if (!s.isEmpty()) {
        s = s.replace(/\'/g, "&#39;"); //no HTML equivalent as &apos is not cross browser supported
        s = s.replace(/\"/g, "&#34;"); //or &quot;
        s = s.replace(/</g, "&#60;");
        s = s.replace(/>/g, "&#62;");
        return s;
    } else {
        return "";
    }
}

// get the string lenth of chars
jQuery.StrCharLen = function (str) {
    var byteLen = 0, len = str.length;
    if (str) {
        for (var i = 0; i < len; i++) {
            if (str.charCodeAt(i) > 255) {
                byteLen += 2;
            }
            else {
                byteLen++;
            }
        }
        return byteLen;
    }
    else {
        return 0;
    }
}

// 获取窗体客户端的可见高度和宽度
// 用法:
// $.getClientSize(window)
jQuery.getClientSize = function(w) {
    if ($.browser.msie) {     //IE浏览器
        var oSize, doc = w.document.documentElement;
        oSize = (doc && doc.clientWidth) ? doc : w.document.body;

        if (oSize) {
            return { w: oSize.clientWidth, h: oSize.clientHeight }; //返回客户端宽度和高度
        }
        else {
            return { w: 0, h: 0 }; //否则都返回0
        }
    }
    else {
        return { w: w.innerWidth, h: w.innerHeight };
    }
}

// 获取scroll top of window
// 用法:
// $.getScrollTop()
jQuery.getScrollTop = function() {
    var scrollTop = 0;
    if (document.documentElement && document.documentElement.scrollTop) {
        scrollTop = document.documentElement.scrollTop;
    }
    else if (document.body) {
        scrollTop = document.body.scrollTop;
    }
    return scrollTop;
}

// 判断是否dtd模式
// 用法:
// $.isDTD(window.document)
jQuery.isDTD = function(doc) {
    return ('CSS1Compat' == (doc.compatMode || 'CSS1Compat'));
}

// 设置透明度
// e:要设置透明度的元素
// opac:透明度
// 用法:
// $.setOpacity(document.getElementById('div'), 0.50);
jQuery.setOpacity = function(e, opac) {
    if ($.browser.msie) {
        opac = Math.round(opac * 100);
        e.style.filter = (opac > 100 ? '' : 'alpha(opacity=' + opac + ')');
    }
    else {
        e.style.opacity = opac;
    }
}

// 获取页面元素的位置
// 用法:
// $.getWindowPosiotion(window)
jQuery.getWindowPosiotion = function(w) {
    if ($.browser.msie) {
        var doc = w.document;
        var oPos = { X: doc.documentElement.scrollLeft, Y: doc.documentElement.scrollTop };
        if (oPos.X > 0 || oPos.Y > 0) return oPos;
        return { X: doc.body.scrollLeft, Y: doc.body.scrollTop };
    }
    else {
        return { X: w.pageXOffset, Y: w.pageYOffset };
    }
}

// 为元素设置样式
// 用法:
// $.setStyle(document.getElementById('demo'), { 'width': '100%'});
jQuery.setStyle = function(e, dict) {
    var style = e.style;
    for (var n in dict) { style[n] = dict[n]; }
}

// 为弹出层设置固定样式
jQuery.popStyle = function(e) {
    e.style.cssText = 'margin:0;padding:0;background-image:none;background-color:transparent;border:0;';
}

// 取消默认事件
jQuery.notDoDefaultEvt = function(evt) {
    if (evt.preventDefault) {
        evt.preventDefault();
    } else {
        evt.returnValue = false;
    }
}

// 禁止冒泡
jQuery.cancelBubble = function(evt) {
    var e = (evt) ? evt : window.event;
    if (e.stopPropagation) {
        e.stopPropagation();
    } else {
        e.cancelBubble = true;
    }
}

// 为dom添加事件
// o:元素
// e:事件名称，去掉'on'
// l:处理事件handler
jQuery.addEvent = function(o, e, l) {
    if ($.browser.msie) {
        o.attachEvent('on' + e, l);
    }
    else {
        o.addEventListener(e, l, false);
    }
}

// 为dom移除事件
// o:元素
// e:事件名称，去掉'on'
// l:处理事件handler
jQuery.removeEvent = function(o, e, l) {
    if ($.browser.msie)
        o.detachEvent('on' + e, l);
    else
        o.removeEventListener(e, l, false);
}

// 取消右键事件
jQuery.cancelRMenu = function(doc) {
    doc.oncontextmenu = function(e) {
        e = e || event || this.parentWindow.event;
        var o = e.srcElement || e.target;
        if (!(o.type == 'password' || o.type == 'text' || o.type == 'textarea')) {
            if ($.browser.msie) {
                e.returnValue = false;
            } else {
                e.preventDefault();
            }
        }
    };
}

// 获取Document
jQuery.getDocument = function(e) {
    return e.ownerDocument || e.document;
}

// 移除节点
jQuery.removeNode = function (n) {
    return $(n).remove();
}
// jQuery操作cookie的插件
// 用法:
// $.cookie('the_cookie'); // 取得cookie
// $.cookie('the_cookie', 'the_value'); // 设置cookie
// $.cookie('the_cookie', 'the_value', { expires: 7 }); // 设置cookie并设置过期时间，如果设置整数会帮你自动转换为天，其它时间请自行定义
// $.cookie('the_cookie', '', { expires: -1 });// 删除cookie  或者$.cookie('the_cookie', null); 也可以
jQuery.cookie = function (name, value, options) {
    if (typeof value != 'undefined') {
        // 如果值和名字都有，那么就设置cookie
        options = options || {};
        if (value === null) {
            value = '';
            options = $.extend({}, options);
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number')) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + (options.path) : '; path=/';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

// 取得url中的参数QueryString，如果参数不存在，返回null
// 用法:
// value = $(document).getUrlParam("paramName"); // 取得当前页面的参数
// value = $('#imgLink').getUrlParam("paramName"); //取得指定元素的src或者href中的参数
jQuery.fn.extend({
    getUrlParam: function(strParamName) {

        strParamName = escape(unescape(strParamName)).toLowerCase();
        var returnVal = new Array();
        var qString = null;
        if ($(this).attr("nodeName") == "#document") {
            //document-handler
            if (window.location.search.toLowerCase().search(strParamName) > -1) {
                var s = window.location.search;
                var eindex = s.lastIndexOf("#");
                if (eindex > 0) {
                    s = s.substring(0, eindex);
                }
                qString = s.substr(1, window.location.search.length).split("&");
            }

        } else if ($(this).attr("src") != "undefined") {
            var strHref = $(this).attr("src");
            if (strHref.indexOf("?") > -1) {
                var strQueryString = strHref.substr(strHref.indexOf("?") + 1);
                qString = strQueryString.split("&");
            }
        } else if ($(this).attr("href") != "undefined") {
            var strHref = $(this).attr("href")
            if (strHref.indexOf("?") > -1) {
                var strQueryString = strHref.substr(strHref.indexOf("?") + 1);
                qString = strQueryString.split("&");
            }
        } else {
            return null;
        }
        if (qString == null) return null;

        for (var i = 0; i < qString.length; i++) {
            if (escape(unescape(qString[i].split("=")[0])).toLowerCase() == strParamName) {
                returnVal.push(qString[i].split("=")[1]);
            }
        }

        if (returnVal.length == 0) {
            return null;
        }
        else if (returnVal.length == 1) {
            return returnVal[0];
        }
        else {
            return returnVal;
        }
    }
});

// 切换语言环境
jQuery.changeLanguage = function (custLan) {
    //首先检测是否启用cookie，否则无法切换
    $.cookie('subcon_test_cookie_enable', 'testdata');
    if ($.cookie('subcon_test_cookie_enable') != 'testdata') {
        alert(g_lang_157 + "cookie, " + g_lang_158);
        return false;
    }
    // 删除测试用cookie
    $.cookie('subcon_test_cookie_enable', null);
    // 删除原来的信息
    $.cookie('CultureName', null);
    try {
        SUBCON.COMMON.AddCookie();
    }
    catch (e)
    { }

    // 添加新的信息
    $.cookie('CultureName', custLan, { expires: 1, path: '/' });
    location.reload(true);
}

/*----------------------------------------------------------------
下面是加入的一些后缀扩展
----------------------------------------------------------------*/

// 模仿C#中的String.Format功能
// 用法:
// var demo = "I Love {0}, and You Love {1} !How are {0}!";
// alert(demo.Format("You","Me"));
String.prototype.Format = function() {
    var args = arguments;
    return this.replace(/\{(\d+)\}/g, function(m, i) {
        return args[i];
    });
};

// 去除字符串两边的空格
// 用法:
// var value=$("#control").val().trim();  // 可以用jQuery的 $.trim($("#control").val());代替
String.prototype.trim = function() {
    return this.replace(/(^\s+)|(\s+$)/g, "");
}

// 检测字符串是否为空
// 用法:
// if(flag.isEmpty()){} //判断是否为空
String.prototype.isEmpty = function() {
    return !(/.?[^\s  ]+/.test(this));
}



/* ---------------------------------------
  一些特殊处理
-------------------------------------------*/
///错误处理
function GoToError() {
    alert(g_lang_161);
}

///表单提交
function SubmitForm(urlString, NewWindow) {
    var form = document.forms[0];
    form.action = urlString;
    if (NewWindow == "1") {
        form.target = "_blank";
    }
    else {
        form.target = "_self";
    }
    form.submit();
}

///联系客户
function ContactNowByLook() {
    var urlString = "", ActionType = "", ActionKeyId = "";
    ActionType = $.trim($("#ActionType").val());
    ActionKeyId = $.trim($("#ActionKeyId").val());
    if (ActionType != null && ActionKeyId != null && ActionType != "" && ActionKeyId != "") {
        urlString = "/Pages/SendMessage.aspx";
        SubmitForm(urlString, "1");
    }
    else {
        GoToError();
        return;
    }
}
// 联系客户
function contactNow(fid, type) {
    //判断用户是否是未审核用户
    var userType;
    $.get("/asmx/user/usertype.ashx?rond=" + Math.random, function (data) {
        userType = data;
        if (userType == "0") {
            ShowMsgTip({ tip: g_lang_User_Notapproved_notice2,
                icon: "diWarning",
                title: g_lang_OP_1,
                okayBtn: { show: true, text: g_lang_28, disabled: false }
            });
            return false;
        }
        else {
            //构造一个表单
            var form = $('#contextNowForm');
            if (!form.html()) {
                form = $('<form id="contextNowForm" action="/Pages/MessageSender.aspx" target="_blank" method="get"><input id="ActionType" type="hidden" name="ActionType" value="' + type + '" /><input type="hidden" id="ActionKeyId" name="ActionKeyId" value="' + fid + '"></form>');
                $('body').append(form);
            } else {
                $('#ActionKeyId').val(fid);
                $('#ActionType').val(type);
            }
            form.submit();
        }
    });

    
};
function urlParams() {
    var args = new Object();
    var query = location.search.substring(1); //获取查询串
    var pairs = query.split("&"); //在逗号处断开  
    for (var i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf('='); //查找name=value  
        if (pos == -1) continue; //如果没有找到就跳过  
        var argname = pairs[i].substring(0, pos); //提取name  
        var value = pairs[i].substring(pos + 1); //提取value  
        args[argname] = value; //存为属性  
    }
    return args; //返回对象  
}


/*------------------------------------------
    检索功能
--------------------------------------------*/
// generate search bar js functions
// ut: user type, 65 or 21
// searchId: the search div with css class "search"
// isManage: is in manage center
// txtSelectTade: use to init select trade win text
// txtSelectArea: use to init select area win text
// initTab: init the tab with given value, not the supplier or purchaser check
var GenerateHeadSearch = function (ut, searchId, isManage, txtSelectTade, txtSelectArea, txtSelectColumn, initTab) {
    var ths = this;
    ths.ut = ut;
    ths.cls = "";
    ths.act = "";
    ths.url = "";
    ths.isManage = isManage;
    ths.letterDivHead = $("#searchBarLetterDiv");
    ths.letterDivBody = $("#searchBarLetterDivBody");
    if (letterDivHead.length <= 0) {
        ths.letterDivHead = $('<div class="ddLetter_head" id="searchBarLetterDivHead"></div>').appendTo($(document.body));
        ths.letterDivBody = $('<div class="ddLetter_body" id="searchBarLetterDivBody"><iframe id="searchBarLetterFrm" scrolling="auto" width="100%" height="100%" frameborder="0" bordercolor="0" src="about:blank"></iframe></div>').appendTo($(document.body));
    }
    ths.letterFrm = $("#searchBarLetterFrm");
    ths.search = $("#" + searchId);
    ths.tabs = ths.search.find("ul.tab"); // tabs 
    ths.advButton = ths.search.find("a.lnkAdv"); // advanced search bar
    ths.txtKey = ths.search.find("input.txtKey"); // input key
    ths.searchBtn = ths.search.find("a.btnSch"); // search button
    ths.lettersContainer = ths.search.find("div.letter");
    ths.letters = ths.lettersContainer.find(">a"); // all letters
    ths.selectBtn = ths.search.find("a.btnSel");

    $.extend(ths, {
        ChangeTab: function (iobj) {
            tabs.find("a").removeClass("selected");
            $(iobj).addClass("selected");
            MakeSelectState();
        },
        StartHeadSearch: function () {
            var key, trade, area;
            key = $.trim(txtKey.val());
            if (key == txtKey.attr('refkey')) {
                txtKey.select();
                return;
            }
            // 增加关键词检索时的条件继承
            // by: Tianzhen, 20110705 16:03
            var _url = location.href.replace(/([,]?)word\:([^,\#]*)/gi, '');

            //提取Exp
            var re = /Exp=([^\&\#]*)/gi;
            var _exp = _url.match(re);
            var trade = $.cookie('cima');
            _url = url.split('?')[0];
            if (_exp != null) {
                _url += '?' + _exp + (key != '' ? (',word:' + encodeURIComponent(key)) : '');
            }
            else {
                if (trade) {
                    _url += (key != '' ? ('?Exp=trade:1074,word:' + encodeURIComponent(key)) : '');
                }
                else {
                    _url += (key != '' ? ('?Exp=word:' + encodeURIComponent(key)) : '');
                } 
            }
            window.location.href = _url;
        },
        StartHeadSearchCheck: function (e) {
            if (!e) var e = window.event;
            var kc = e.which || e.keyCode;
            if (kc == 13) {
                StartHeadSearch();
                return false;
            }
        },
        MakeSelectState: function () {
            var sobj = this.tabs.find("a.selected");
            cls = sobj.attr("rel");
            act = sobj.attr("act");
            url = sobj.attr("qurl");
            advButton.attr("href", sobj.attr("aurl"));
        },
        GetSearchUri: function () {
            var from = "";
            switch (cls) {
                case "1":
                    from = "supplier";
                    break;
                case "2":
                    from = "product";
                    break;
                case "3":
                    from = "order";
                    break;
                case "4":
                    from = "purchaser";
                    break;
                case "5":
                    from = "require";
                    break;
            }
            return from;
        },
        LetterSearch: function () {
            ths.letters.click(function (e) {
                $.cancelBubble(e);
                var w = lettersContainer.width();
                w = w < 650 ? 650 : w;
                var h = 200;
                var pos = lettersContainer.offset();
                var ltpos = $(this).offset();
                if (isManage) {
                    letterDivBody.css({ left: pos.left - 50, top: ltpos.top + 26, width: w, height: h });
                    letterDivHead.css({ left: ltpos.left + 1, top: ltpos.top + 20 });
                }
                else {
                    letterDivBody.css({ left: pos.left - 20, top: ltpos.top + 30, width: w, height: h });
                    letterDivHead.css({ left: ltpos.left + 4, top: ltpos.top + 24 });
                }
                letters.removeClass("selected");
                $(this).addClass("selected");
                letterFrm.unbind("load").load(function () {
                    letterDivHead.slideDown(10, function () {
                        letterDivBody.slideDown();
                    });
                });
                letterFrm.attr("src", "/PageLetters/Search/LetterQuery.aspx?root=/search/" + GetSearchUri() + ".aspx&letter=" + this.innerHTML.toString() + "&r=" + Math.random());
            });
            $("body").click(function () {
                CloseLetter();
            });
        },
        CloseLetter: function () {
            letterDivBody.hide();
            letterDivHead.hide();
        },
        DemandsHover: function () {
            var dtab = tabs.find("li.Demands");
            var dDiv = $("div.ddDemands").eq(0).appendTo($("body"));
            if (dtab.length > 0) {
                var tid = null;
                dtab.unbind("mouseover").mouseover(function () {
                    clearTimeout(tid);
                    CloseLetter();
                    var pos = dtab.offset();
                    if (isManage) {
                        dDiv.css({ left: pos.left - dDiv.width() + dtab.width() - 2, top: pos.top + 26 }).show();
                    }
                    else {
                        dDiv.css({ left: pos.left - dDiv.width() + dtab.width() - 2, top: pos.top + 34 }).show();
                    }
                    dtab.find("a").addClass("hover");
                }).unbind("mouseout").mouseout(function () {
                    tid = setTimeout(function () {
                        dDiv.hide();
                        dtab.find("a").removeClass("hover");
                    }, 100);
                });
                dDiv.unbind("mouseover").mouseover(function () {
                    clearTimeout(tid);
                }).unbind("mouseout").mouseout(function () {
                    tid = setTimeout(function () {
                        dDiv.hide();
                        dtab.find("a").removeClass("hover");
                    }, 100);
                });
            }
        },
        SearchLog: function () {
            var sLog = search.find("a.lnkLog");
            var logDivHead = $("div.ddSchLog_head").eq(0).appendTo($("body"));
            var logDivBody = $("div.ddSchLog_body").eq(0).appendTo($("body"));
            if (sLog.length > 0) {
                var tid = null;
                sLog.eq(0).unbind("click").click(function () {
                    var pos = $(this).offset();
                    logDivHead.css({ left: pos.left - 1, top: pos.top - 4 }).show();
                    var w = $(this).width();
                    logDivBody.css({ left: pos.left - logDivBody.width() + w + 21, top: pos.top + 23 }).show();
                    if ($('#myQueryLog').parent().css("display") == "none" && $('#autoQueryLog').parent().css("display") == "none") {
                        logDivBody.hide();
                    }
                });
                logDivHead.unbind("mouseover").mouseover(function () {
                    clearTimeout(tid);
                }).unbind("mouseout").mouseout(function () {
                    tid = setTimeout(function () {
                        logDivHead.hide();
                        logDivBody.hide();
                    });
                });
                logDivBody.unbind("mouseover").mouseover(function () {
                    clearTimeout(tid);
                }).unbind("mouseout").mouseout(function () {
                    tid = setTimeout(function () {
                        logDivHead.hide();
                        logDivBody.hide();
                    });
                });
                $("#viewFullLog").attr("href", "/Search/QueryLog.aspx");
            }
        },
        loadQueryLog: function () {
            var myurl = encodeURIComponent(tabs.find("a.selected").attr("qurl"));
            $.post('/Asmx/Search/LoadQueryLog.ashx', { from: url }, function (data) {
                if (data != 0) {
                    eval(data);
                    renderLogs(logs[0], 'myQueryLog');
                    renderLogs(logs[1], 'autoQueryLog');
                }
                if ($('#myQueryLog tr').length <= 0) {
                    var p = $('#myQueryLog').parent();
                    p.hide();
                    p.prev().hide()

                }
                if ($('#autoQueryLog tr').length <= 0) {
                    var p = $('#autoQueryLog').parent();
                    p.hide();
                    p.prev().hide()
                }
            });
        },
        renderLogs: function (logs, elId) {
            var el = $('#' + elId);
            if (logs.length == 0) {
                el.hide();
                return;
            }
            for (var i = 0; i < logs.length; i++) {
                el.append('<tr><td>&bull;' + logs[i].text + '</td></tr>');
            }
            el.parent().prev().find("span").html("(" + logs.length + ")");
        },
        BindEvents: function () {
            // bind input for key words
            txtKey.click(function () {
                if ($(this).val() == $(this).attr("refkey")) {
                    $(this).val('');
                }
            }).blur(function () {
                if ($(this).val() == "") {
                    $(this).val($(this).attr("refkey"));
                }
            }).keydown(function (e) {
                StartHeadSearchCheck(e);
            }).mouseover(function () {
                txtKey.select();
            });

            // only in mange pages head can change tab
            if (isManage) {
                this.tabs.find("a").each(function () {
                    $(this).mouseover(function () {
                        ChangeTab(this);
                    });
                });
            }
            searchBtn.click(function () {
                StartHeadSearch();
            });
            LetterSearch(); // letter query search

            if (initTab && initTab.length > 0) {
                tabs.find("a").removeClass("selected");
                tabs.find("a").each(function () {
                    if ($(this).attr("rel") == initTab) {
                        $(this).addClass("selected");
                    }
                });
            }
            else {
                // init data
                if (ut == "65") {
                    // supplier
                    tabs.find("a").removeClass("selected");
                    tabs.find("a").each(function () {
                        if ($(this).attr("rel") == "4") {
                            $(this).addClass("selected");
                        }
                    });
                }
                else {
                    // purchaser
                    tabs.find("a").removeClass("selected");
                    tabs.find("a").each(function () {
                        if ($(this).attr("rel") == "1") {
                            $(this).addClass("selected");
                        }
                    });
                }
            }
            MakeSelectState();

            if (initTab == "2" || initTab == "3") {
                selectBtn.eq(0).click(function () {
                    $().OpenWin.Popup(txtSelectColumn, '/PageLetters/Search/ColumnInfo.aspx?root=' + encodeURIComponent("/Search/" + GetSearchUri() + ".aspx"), 730, 520, true);
                });
            }
            else {
                // bind select trade and area
                selectBtn.eq(0).click(function () {
                    $().OpenWin.Popup(txtSelectTade, '/PageLetters/Search/TradeInfo.aspx?root=' + encodeURIComponent("/Search/" + GetSearchUri() + ".aspx"), 730, 520, true);
                });
            }
            selectBtn.eq(1).click(function () {
                $().OpenWin.Popup(txtSelectArea, '/PageLetters/Search/AreaInfo.aspx?root=' + encodeURIComponent("/Search/" + GetSearchUri() + ".aspx"), 730, 520, true);
            });
            DemandsHover(); // bind events for demands tab
            SearchLog(); // bind
            loadQueryLog();
        }
    });
    ths.BindEvents();
}
