﻿addDomLoad(function() {
    EventUtil.addEventHandler($("txtTopSearch"), "keydown", TopSearchBefore);
    EventUtil.addEventHandler($("btnTopSearch"), "click", TopSearch);
})

function TopSearchBefore() {
    if (EventUtil.getEvent().keyCode == 13)
        TopSearch();
}

function TopSearch() {
    var Keywords = $("txtTopSearch").value.Trim();

    if (Keywords.IsNullOrEmpty())
        return;
    else if (Keywords.IsChinese() || Keywords.IsHtml()) {
        alert("Please enter english characters only.");
        return;
    }
    else {
        var Url = "";
        Url += "key=" + escape(Keywords);
        window.location.href = "/search?" + Url;
    }
}

function LeftSearch() {
    var Keywords = $("txtLeftKey").value.Trim();
    
    if (Keywords.IsNullOrEmpty())
        return;
    else if (Keywords.IsChinese() || Keywords.IsHtml()) {
        alert("Please enter english characters only.");
        return;
    }
    else {
        var Url = "";
        Url += "key=" + escape(Keywords);
        window.location.href = "/search?" + Url;
    }
}

function lanTanggle() {
    if ($('lanList').style.display != 'block') {
        $('lanList').style.display = 'block';
    } else
    { $('lanList').style.display = 'none'; }
}
var out1 = false, out2 = false, timeOut;
addDomLoad(function() {
    var lanFm = $('lanFm');
    lanFm.onmouseover = function() {
        out1 = false;
        $('lanList').style.display = 'block';
        clearTimeout(timeOut);
    }
    lanFm.onmouseout = function() { out1 = true; lanout(); }
    $('lanList').onmouseout = lanout;

    function lanout() {
        if (out1 == true) {
            timeOut = setTimeout(function() {
                if ($('lanList').style.display == 'block')
                    $('lanList').style.display = 'none';
            }, 500);
        }

    }
});

function imgZoom(obj, maxWidth, maxHeight) {
    obj = $(obj);
    if (obj.width > maxWidth || obj.height > maxHeight) {
        if (obj.width / obj.height > maxWidth / maxHeight) {
            obj.height = maxWidth * obj.height / obj.width;
            obj.width = maxWidth;
        } else {
            obj.width = maxHeight * obj.width / obj.height;
            obj.height = maxHeight;
        }
    }
    obj.style.display = 'block';
    obj.style.visibility = 'visible';
    obj.style.marginTop = Math.round((maxHeight - obj.clientHeight) / 2) + 'px';
    obj.style.marginLeft = Math.round((maxWidth - obj.clientWidth) / 2) + 'px';
}

function getGoogleTrans(lan) {
    var url = 'http://translate.google.cn/translate?prev=hp&hl=zh-CN&js=y&u=' + window.location + '&sl=en&tl=' + lan + '&history_state0=';
    window.location = url;
}