﻿function blockUI() {
    $.blockUI({
        message: $("#loading"),
        css: {
            border: 'none',
            top: ($(window).height() - 36) / 2 + 'px',
            left: ($(window).width() - 138) / 2 + 'px',
            width: '138px'
        },
        baseZ: 9999999
    });
}

function ShareToPlurk(DesignerMemberID) {
    GetShareBonus(DesignerMemberID, 'plurk');
    window.open('http://www.plurk.com/?qualifier=shares&status='.concat(encodeURIComponent(location.href)).concat(' (').concat(encodeURIComponent(document.title)).concat(')'));
}
function ShareToTwitter(DesignerMemberID) {
    GetShareBonus(DesignerMemberID, 'twitter');
    window.open('http://twitter.com/home/?status='.concat(encodeURIComponent(document.title)).concat(' ').concat(encodeURIComponent(location.href)));
}
function ShareToFacebook(DesignerMemberID) {
    GetShareBonus(DesignerMemberID, 'facebook');
    window.open('http://www.facebook.com/share.php?u='.concat(encodeURIComponent(location.href)) + '&t=' + encodeURIComponent(document.title));
}

function GetShareBonus(DesignerMemberID, ShareWebsite) {
    $.post("/Ashx/GetShareWebsiteBonus.ashx", "DesignerMemberID=" + DesignerMemberID + "&ShareWebsite=" + ShareWebsite);
}

//設定位置
//setBoxPosition({ "refer": $("#xxx"), "my": $("#yyy"), "top":-250  });
//*refer: 參考物件, *my:要被設定位置的物件, top:加減top的值, left:加減left的值, *號必填
var setBoxPosition = function (data) {
    if (data != undefined && data.refer.length == 1 && typeof (data.refer.offset) == "function") {
        if (data.top != undefined) {
            data.my.css({ "top": (data.refer.offset().top + parseInt(data.top)) + "px" });
        }
        if (data.left != undefined) {
            data.my.css({ "left": (data.refer.offset().left + parseInt(data.left)) + "px" });
        }
    }
}

// 驗證非法字元
function checkIllegalWords(word) {
    var returnValue = true;
    $.ajax({
        type: 'POST',
        cache: false,
        async: false,
        url: '/Ashx/CheckIllegalWords.ashx',
        data: { word: word },
        success: function (data) {
            if (data == 'N') {
                // 驗證完成
                returnValue = false;
            }
        },
        error: function () {
            returnValue = true;
        }
    });
    return returnValue;
}

// ===== 動態顯示已輸入多少字 =====
function wKeyIn(txtID, wordLength, target) {
    var wordNum = $("#" + txtID).val().length;
    if (wordNum > wordLength) {
        alert("您所輸入的內容已達" + wordLength + "字之限制字數，請略作刪減後才能再輸入新的內容，謝謝！");
        $("#" + txtID).val($("#" + txtID).val().substr(0, wordLength));
        wordNum = $("#" + txtID).val().length;
    }

    if (target === undefined) {
        target = "p";
    }
    var wordSpan = '限 <span class="txt_07 txt_00">' + wordLength + '</span> 字，已輸入 <span class="txt_00"><strong>' + wordNum + '</strong></span> 字。';
    $("." + txtID).filter(target).html(wordSpan);
}
