﻿/*******************************
* Oran Day
* Jul 4, 2008
*******************************/
var $$ = {};
function $j(elmId) { return $("#" + elmId); }
function $tv(elmId) { return $.trim($v(elmId)); }
function $c(elmId) { return $("#" + elmId).attr("checked"); }
function $v(elmId, val) {
    if (val == null) {
        var o = $j(elmId).attr("value");
        if (o == null || o == undefined)
            return "";
        return o;
    } else {
        return $j(elmId).attr("value", val);
    }
}
function max(v1, v2) {
    return (v1 > v2 ? v1 : v2);
}
/**common**/

//提示框
/*  
*   隐藏下拉框函数  
*/
function hideDdl(cntrId) {
    var arrTags = ["select", "applet", "object"];
    var jCntr = $(document.body);
    if (cntrId != null)
        jCntr = $j(cntrId);
    for (var i = 0; i < arrTags.length; ++i) {
        jCntr.find(arrTags[i]).css("visibility", "hidden");
    }
}
function showDdl() {
    var arrTags = ["select", "iframe", "applet", "object"];
    for (var i = 0; i < arrTags.length; ++i) {
        $(arrTags[i]).css("visibility", "visible");
    }
}
//message box
$(function() {
    //--
    $(window).resize(function() { relocationMsg(); });
    $(window).scroll(function() { relocationMsg(); });
    //--
    $("input[type=button]").hover(function() { $(this).addClass("btn_hover"); },
        function() { $(this).toggleClass("btn_hover"); });
    $("input[type=submit]").hover(function() { $(this).addClass("btn_hover"); },
        function() { $(this).toggleClass("btn_hover"); });
    $(".focus").find("input,textarea").focus(function() { $(this).addClass("tfocus"); }).blur(function() { $(this).removeClass("tfocus"); });
});
function relocationMsg() {
    var dd = document.documentElement;
    var jShadow = $j("msg_shadow");
    jShadow.css("margin-top", (dd.scrollTop - 75 + "px"));

    var jBg = $j("msg_bg");
    var sWidth = dd.scrollWidth;
    var sHeight = dd.scrollHeight;
    var cH = dd.clientHeight;
    var cW = dd.clientWidth;
    if (sHeight < cH)
        sHeight = cH;
    if (sWidth < cW)
        sWidth = cW;
    jBg.css({ "height": sHeight, "width": sWidth });
}
function oran_msg(msg) {
    window.onload = function() {
        $a(msg);
    }
}
function $a(sBody, sTitle, focusElmId, boxType, behavior) {
    hideDdl();
    var jBg = $j("msg_bg").show();
    var jShadow = $j("msg_shadow").show();
    var jCntr = $j("msg_cntr");
    var jTitle = $j("msg_title");
    var jCont = $j("msg_cont");
    var jClose = $j("msg_close");
    var jBtn = $j("msg_btn");
    var dd = document.documentElement;

    var sWidth = dd.scrollWidth;
    var sHeight = dd.scrollHeight;
    var cH = dd.clientHeight;
    var cW = dd.clientWidth;
    if (sHeight < cH)
        sHeight = cH;
    if (sWidth < cW)
        sWidth = cW;
    jBg.css({ "height": sHeight, "width": sWidth });
    jShadow.css("margin-top", (dd.scrollTop - 75 + "px"));

    if (sTitle == null)
        sTitle = "Message";
    jTitle.html(sTitle);
    jCont.html(sBody);

    var btnHtml;
    if (boxType == null)
        boxType = "ok";
    switch (boxType.toLowerCase()) {
        case "yesno": btnHtml = "<input type='button' value='是' id='msg_btn_yes' onclick=\"$j('msg_close').click();return true;\" /><input type='button' id='msg_btn_no' value='否' class='ml10' onclick=\"$j('msg_close').click();return false;\" />"; break;
        default: btnHtml = "<input type='button' value='确定' id='msg_btn_ok' onclick=\"$j('msg_close').click()\" />"; break;
    }
    jBtn.html(btnHtml);

    jClose.removeAttr("onclick");
    jClose.click(function() {
        hideMsg();
        if (focusElmId != null)
            $j(focusElmId).focus();
        if (behavior != null)
            behavior();
    });
}
function hideMsg() {
    showDdl();
    var jBg = $j("msg_bg");
    var jShadow = $j("msg_shadow");
    jBg.hide();
    jShadow.fadeOut(100);
}
function showBigMsg(src, url) {
    hideDdl();
    var jShadow = $j("big_msg_bg");
    var jFrm = $j("big_msg_frm");
    jFrm.attr("src", url);
    jShadow.css("top", ($(src).offset().top - 400) + "px");
    jShadow.show();
}
function limitLen(src, byteLength, elmInputdId, elmLeaveId) {
    var val = src.value;
    var length = val.length;
    if (length > byteLength) {
        val = val.substr(0, byteLength);
        length = val.length;
        src.value = val;
        src.scrollTop = 99999999;
    }
    if (elmInputdId != null) {
        $j(elmInputdId).html(length.toString());
        var leave = byteLength - length;
        $j(elmLeaveId).html(leave.toString());
    }
}
function limitLength(src) {
    var value = src.value;
    var byteLength = parseInt($(src).attr("max"));
    var attribute = src.id;
    var newvalue = value.replace(/[^\x00-\xff]/g, "**");
    var length = newvalue.length;

    //当填写的字节数小于设置的字节数
    if (length * 1 <= byteLength * 1) {
        return;
    }
    var limitDate = newvalue.substr(0, byteLength);
    var count = 0;
    var limitvalue = "";
    for (var i = 0; i < limitDate.length; i++) {
        var flat = limitDate.substr(i, 1);
        if (flat == "*") {
            count++;
        }
    }
    var size = 0;
    var istar = newvalue.substr(byteLength * 1 - 1, 1); //校验点是否为“×”

    //if 基点是×; 判断在基点内有×为偶数还是奇数 
    if (count % 2 == 0) {
        //当为偶数时
        size = count / 2 + (byteLength * 1 - count);
        limitvalue = value.substr(0, size);
    } else {
        //当为奇数时
        size = (count - 1) / 2 + (byteLength * 1 - count);
        limitvalue = value.substr(0, size);
    }
    alert("最大输入" + byteLength + "个字节（相当于" + byteLength / 2 + "个汉字）！");
    document.getElementById(attribute).value = limitvalue;
    return;
}
function $g(elmId) { return document.getElementById(elmId); }
function $name(nm) { return document.getElementsByName(nm); }
function $tag(cntr, tagName) {
    var o = cntr;
    if (o != Object) o = $g(cntr);
    return o.getElementsByTagName(tagName);
}
function donly(e) {
    var key = window.event ? event.keyCode : e.which;
    if (key < 27 || key > 128)
        return true;
    else if (key >= 48 && key <= 57)
        return true;
    else
        return false;
}
function ce(src, batch) {
    if (batch == null)
        batch = false;
    if (batch) {
        var ptn = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*(;\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*/;
        return ptn.test(src);
    } else {
        var ptn = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
        return ptn.test(src);
    }
}
function $o(url, w, h) {
    if (url == null || url == "")
        return;
    var features = "location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0;top=0,left=0";
    if (w)
        features += ",width=" + w;
    if (h)
        features += ",height=" + h;
    window.open(url, "", features, false);
}
function slideToggle(elmId, speed) {
    if (speed == null) speed = "fast";
    if ($("#" + elmId).is(":visible")) $("#" + elmId).slideUp(speed);
    else $("#" + elmId).slideDown(speed);
}
function checkEmailFmt(email) {
    var ptn = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
    return ptn.test(email);
}
//empty textbox
function etb(cntrId) {
    var jTxts;
    if (cntrId == null)
        jTxts = $("body").find("input[type=text]");
    else
        jTxts = $j(cntrId).find("input[type=text]");
    jTxts.each(function() {
        $(this).attr("value", "");
    });
    if (cntrId == null)
        jTxts = $("body").find("textarea");
    else
        jTxts = $j(cntrId).find("textarea");
    jTxts.each(function() {
        $(this).attr("value", "");
    });
}
//设置 cookie
$$.cookie = function(name, val, expire) {
    if (val == null && expire == null) {
        var search = name + "=";
        begin = document.cookie.indexOf(search);
        if (begin != -1) {
            begin += search.length;
            end = document.cookie.indexOf(";", begin);
            if (end == -1) end = document.cookie.length;
            return document.cookie.substring(begin, end);
        }
        return null;
    } else if (typeof (val) == "boolean") {
        $$.cookie(name, "", -86400000);
    } else {
        if (expire == null) expire = 9986400000;
        var today = new Date();
        var expireDay = new Date();
        var msPerMonth = expire;
        expireDay.setTime(today.getTime() + msPerMonth);
        document.cookie = name + "=" + val + ";expires=" + expireDay.toGMTString();
    }
}
function $qs(paraNm) {
    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('=');
        if (!pos) continue;
        var paraNm2 = pairs[i].substring(0, pos);
        var vlu = pairs[i].substring(pos + 1);
        vlu = decodeURIComponent(vlu);
        args[paraNm2] = vlu;
    }
    return args[paraNm];
}
function selectAll(src, cntrId) {
    var chks = $tag(cntrId, "input");
    for (var i = 0; i < chks.length; ++i) {
        chks[i].checked = src.checked;
    }
}
function invertSelect(cntrId, exceptive, escRow) {
    var chks = $tag(cntrId, "input");
    for (var i = 0; i < chks.length; ++i) {
        if (exceptive == null) {
            chks[i].checked = !chks[i].checked;
        } else {
            if (chks[i].name != exceptive)
                chks[i].checked = !chks[i].checked;
        }
    }
    if (escRow != null) chks[escRow].checked = false;
}
function getPageFilename() {
    var path = location.pathname;
    var pos = path.lastIndexOf('/') + 1;
    var filename = path.substring(pos, path.length);
    return filename;
}
function getRawUrl() {
    var path = location.href;
    var pos = path.lastIndexOf('/') + 1;
    var filename = path.substring(pos, path.length);
    pos = filename.lastIndexOf('#');
    filename = filename.substring(0, pos);
    return filename;
}
function getIntactRawUrl() {
    var path = location.href;
    var pos;
    pos = path.lastIndexOf('#');
    path = path.substring(0, pos);
    return path;
}
function $oid(paraName) {
    var fileName = location.pathname;
    var pos = fileName.lastIndexOf('-');
    var posDot = fileName.lastIndexOf('.');
    if (pos != -1 && posDot != -1)
        return fileName.substring(pos + 1, posDot);
    return null;
}
$$.pageFilename = function() {
    var path = location.pathname;
    var pos = path.lastIndexOf('/') + 1;
    var filename = path.substring(pos, path.length);
    return filename;
};
$$.intactRawUrl = function() {
    return $$.rawUrl();
};
$$.rawUrl = function() {
    var path = location.href;
    var pos;
    pos = path.indexOf('#');
    if (pos != -1)
        path = path.substring(0, pos);
    return path;
};
$$.toggleArg = function(name, val) {
    var url = $$.intactRawUrl();
    var pos = url.indexOf('?');
    if (pos == -1) {
        return url + "?" + name + "=" + val;
    } else {
        var args = url.substring(pos);
        var path = url.substring(0, pos);
        var patten = new RegExp("&?" + name + "=?\\w*\\[?\\w*\\]?\\|?\\d?", "i");
        args = args.replace(patten, "");
        if (args.length == 1) {//没有任何参数，只有?
            args += name + "=" + val;
        } else {
            args += "&" + name + "=" + val;
        }
        return path + args;
    }
};
function increase(elmId, visibility) {
    if (visibility == null)
        visibility = "show";
    var jO = $j(elmId);
    jO.animate({
        height: visibility,
        width: visibility,
        opacity: visibility
    }, "fast");
}
function fadeToggle(elmId, speed) {
    if (speed == null) speed = "fast";
    if ($("#" + elmId).is(":visible")) $("#" + elmId).fadeOut(speed);
    else $("#" + elmId).fadeIn(speed);
}
function clearAllElms(cntrId, focusClass) {
    clearDdls(cntrId, focusClass);
    clearTextBoxes(cntrId, focusClass);
    clearRdos(cntrId, focusClass);
    clearChks(cntrId, focusClass);
}
function clearRdos(cntrId, focusClass) {
    if (focusClass == null)
        focusClass = "tfocus";
    var txts = $j(cntrId).find("input[type=radio]");
    txts.focus(function() { $(this).addClass(focusClass); });
    txts.blur(function() { $(this).removeClass(focusClass); });
}
function clearChks(cntrId, focusClass) {
    if (focusClass == null)
        focusClass = "tfocus";
    var txts = $j(cntrId).find("input[type=checkbox]");
    txts.focus(function() { $(this).addClass(focusClass); });
    txts.blur(function() { $(this).removeClass(focusClass); });
}
function clearDdls(cntrId, focusClass) {
    if (focusClass == null)
        focusClass = "tfocus";
    var txts = $j(cntrId).find("select");
    txts.focus(function() { $(this).addClass(focusClass); });
    txts.blur(function() { $(this).removeClass(focusClass); });
}
function clearTextBoxes(cntrId, focusClass) {
    if (focusClass == null)
        focusClass = "tfocus";
    var txts = $j(cntrId).find("input[type=text]");
    txts.focus(function() { $(this).addClass(focusClass); });
    txts.blur(function() { $(this).removeClass(focusClass); });
    txts = $j(cntrId).find("input[type=password]");
    txts.focus(function() { $(this).addClass(focusClass); });
    txts.blur(function() { $(this).removeClass(focusClass); });
    txts = $j(cntrId).find("textarea");
    txts.focus(function() { $(this).addClass(focusClass); });
    txts.blur(function() { $(this).removeClass(focusClass); });
}
function addBookmark(url, title) {
    if (window.sidebar) {
        window.sidebar.addPanel(title, url, "");
    } else if (document.all) {
        window.external.AddFavorite(url, title);
    } else if (window.opera && window.print) {
        return true;
    }
}

function checkRadio(cntrId, val) {
    var rdos = $j(cntrId).find("input[type=radio]");
    rdos.each(function(i) {
        var jT = $(this)
        jT.attr("checked", jT.attr("value") == val);
    });
}
/********************************/
function showVerifyCode(elmId, msgElmId, imgId, chgLnkId) {
    if (elmId == null)
        elmId = "spVerCode";
    if (msgElmId == null)
        msgElmId = "spVerCodeMsg";
    if (imgId == null)
        imgId = "imgVerCode";
    if (chgLnkId == null)
        chgLnkId = "spChgVerCode";
    var jImg = $j(elmId);
    var jMsg = $j(msgElmId);
    var jChgLnk = $j(chgLnkId);
    if (jImg.html() == "") {
        jMsg.html("loading...");
        jMsg.show();
        jImg.html("<img src='/Tools/ValidCode.aspx' style='display:none;' id='" + imgId + "' alt='Security Code' />");
    }
    var jVerCode = $j(imgId);
    jVerCode.load(function() {
        jMsg.hide();
        jVerCode.show();
        jChgLnk.show();
    });
}
function changeVerCode(elmId, msgElmId) {
    if (elmId == null)
        elmId = "imgVerCode";
    if (msgElmId == null)
        msgElmId = "spVerCodeMsg";
    var jImg = $j(elmId);
    var jMsg = $j(msgElmId);
    jMsg.html("refreshing...").show();
    jImg.attr({ src: "/Tools/ValidCode.aspx?x=" + Math.random(), alt: "Security Code" });
    jImg.hide();
    jImg.load(function() {
        jMsg.hide();
        jImg.show();
    });
}
function digistalOnly(src) {
    src.value = src.value.replace(/[^0-9]/g, '');
}
function showProc(src, show) {
    var oImg = $j("imgProc");
    if (show == null)
        show = true;
    if (show) {
        $(src).hide();
        if (oImg.length > 0)
            oImg.remove();
        $("<img src='img/processing.gif' id='imgProc' alt='processing' />").insertAfter(src);
    } else {
        $(src).show();
        oImg.remove();
    }
}
function enlarge(el) {
    if (el == null)
        el = true;
    var o = $j("cntrBody");
    var fontSize = parseInt(o.css("font-size"));
    if (isNaN(fontSize)) {
        fontSize = 12;
    }
    var newFontSize = (el ? fontSize * 1.2 : fontSize / 1.2);
    o.css("font-size", newFontSize + "px");
}
function searchFaq(kwd, catId) {
    if (catId == null)
        catId = -1;
    if (kwd == undefined || kwd.length == 0) {
        $a("Type keyword, please.", "Message", "txtKwd");
        return;
    }
    var url = "faq.aspx?kwd=" + encodeURI(kwd);
    if (catId > 0)
        url += "&oid=" + catId;
    location.href = url;
}
function searchByCat() {
    var val = $j("ddlCatHeader").val();
    var kwd = $tv("txtKwdHeader");
    if (kwd == "") {
        $a("Type keyword, please.");
        $j("txtKwdHeader").focus();
        return;
    }
    switch (val) {
        case "news": searchNews(kwd, -1); break;
        case "faq": searchFaq(kwd, -1); break;
        case "prod": searchProd(kwd, -1); break;
    }
}
function searchProd(kwd, catId) {
    if (catId == null)
        catId = "-2"; //所有商品
    if (kwd == undefined || kwd.length == 0) {
        $a("Type keyword, please.", "Message", "txtKwd");
        return;
    }
    var url = "product.aspx?kwd=" + encodeURI(kwd);
    url += "&oid=" + catId;
    location.href = url;
}
function searchNews(kwd, catId) {
    if (catId == null)
        catId = "-2"; //所有资讯
    if (kwd == undefined || kwd.length == 0) {
        $a("Type keyword, please.", "Message", "txtKwd");
        return;
    }
    var url = "news.aspx?kwd=" + encodeURI(kwd);
    url += "&oid=" + catId;
    location.href = url;
}
function clearProductHistory(historyKey, elmId) {
    if (elmId == null)
        elmId = "cntrProdHistory";
    $$.cookie(historyKey, '')
    $j(elmId).remove();
}
function procImg(src) {
    var img = new Image();
    img.src = src.src;
    if (img.width > 284) {
        $(src).css({ width: '284px', height: '284px' });
    } else {
        $(src).removeAttr("onmouseover");
    }
}
function increaseScroll(elmId, speed, maxLen) {
    var i = 1;
    var intVal1 = setInterval(function() { if (i > maxLen) window.clearInterval(intVal1); $g(elmId).scrollLeft += speed; i += speed; }, 1);
}
function decreaseScroll(elmId, speed, maxLen) {
    var i = 1;
    var intVal1 = setInterval(function() { if (i > maxLen) window.clearInterval(intVal1); $g(elmId).scrollLeft -= speed; i += speed; }, 1);
}
function scrollImg(src) {
    var jImg = $(src).find("img");
    var idx = parseInt(jImg.attr("idx"));
    $j("spCurIndex").html(idx + 1);
    $(".proj_bimg>img").attr("src", jImg.attr("big_img"));
    $(".proj_bimg>h1").html(jImg.attr("alt"));
    $j("spLocLast").html(jImg.attr("alt"));
    toNextImg();
}
function toNextImg() {
    var jImg = $(".proj_bimg img");
    var imgSrc = jImg.attr("src").toLowerCase();
    var jImgs = $("#divImgList img");
    for (var i = 0; i < jImgs.length; ++i) {
        if ($(jImgs[i]).attr("big_img").toLowerCase() == imgSrc) {
            var nextLnk = $(jImgs[i]).parent().next();
            if (nextLnk.length == 0) {
                nextLnk = $(jImgs[i]).parent().parent().find("a")[0];
            }
            proj_d_nextLnk = nextLnk;
        }
    }
}
