﻿function IsNumeric(input) {
    return (input - 0) == input && input.length > 0;
}

function setLinkfancybox() {
    //最新出價, 出價紀錄
    $(".history").fancybox({
        'type': 'iframe',
        'autoScale': 'false',
        'width': 930,
        'height': "85%"
    });
    //加價說明
    $(".PriceDesc").fancybox({
        'type': 'iframe',
        'autoScale': 'false',
        'width': 930,
        'height': "98%"
    });
    //我要出價
    $(".PostPriceConfirmDirect").fancybox({
        'type': 'iframe',
        'autoScale': 'false',
        'width': 872,
        'height': 458
    });
    //自動加價
    $(".PostPriceConfirmAuto").fancybox({
        'type': 'iframe',
        'autoScale': 'false',
        'width': 930,
        'height': "98%"
    });
    //網拍協議
    $(".bargain").fancybox({
        'type': 'iframe',
        'autoScale': 'false',
        'width': 920,
        'height': "98%"
    });
    //網拍保證金
    $(".margin").fancybox({
        'type': 'iframe',
        'autoScale': 'false',
        'width': 930,
        'height': "98%"
    });
    //登入
    $(".auctionLogin").fancybox({
        'type': 'iframe',
        'autoScale': true,
        'width': 370,
        'height': 230
    });
}

function checkPrice(Price) {
    if (!IsNumeric(Price)) {
        alert("價格請填入數字 !!");
        return false;
    } else {
        if (Price > 0) {
            if ((Price % 100) != 0) {
                alert("金額錯誤 !!\r\n\r\n出價最小單位為百元。");
                return false;
            }
        } else {
            alert("請填寫出價金額 !!");
            return false;
        }
    }
    return true;
}
function getCNY(birdId, price) {
    $.ajax({
        url: "BirdList.aspx",
        async: false,
        type: "POST",
        data: ({
            Price: price,
            Action: "getCNY"
        }),
        dataType: "html",
        success: function(msg) {
            var oRes = eval(msg);
            if (oRes.success) {
                console
                $("#txtPriceCNY_" + birdId).html(oRes.PriceCNY);
            }
        },
        error: function(xhr, ajaxOptions, thrownError) {
        }
    })
}
function getEUR(birdId, price) {
    $.ajax({
        url: "BirdList.aspx",
        async: false,
        type: "POST",
        data: ({
            Price: price,
            Action: "getEUR"
        }),
        dataType: "html",
        success: function (msg) {
            var oRes = eval(msg);
            if (oRes.success) {
                $("#txtPriceEUR_" + birdId).html(oRes.PriceEUR);
            }
        },
        error: function (xhr, ajaxOptions, thrownError) {
        }
    })
}


function showConfirm(BirdId) {
    var price = $("#txtPrice_" + BirdId).val();

    if (checkPrice(price)) {
        //取消密碼檢查, Reiko, 2013/03/05
        //if ($('#txtPassword_' + BirdId).val() == '') {
        //    alert("請填入密碼 !!")
        //    return;
        //}
        $(".eventMsg" + BirdId).attr("href", "/Bid/PostPriceConfirm.aspx?Id=" + BirdId + "&Price=" + price + "&pw=" + $('#txtPassword_' + BirdId).val());
        $(".eventMsg" + BirdId).trigger("click");
    }
}

//我要出價
function showConfirmDirect(BirdId) {
    var price = $("#txtPrice_" + BirdId).val();

    if (checkPrice(price)) {
        //取消密碼檢查, Reiko, 2013/03/05
        //if ($('#txtPassword_' + BirdId).val() == '') {
        //    alert("請填入密碼 !!")
        //    return;
        //}
        $(".hlkDirect" + BirdId).attr("href", "/Bid/PostPriceConfirm_Direct.aspx?Id=" + BirdId + "&Price=" + price + "&pw=" + $('#txtPassword_' + BirdId).val());
        $(".hlkDirect" + BirdId).trigger("click");
    }
}
//自動加價
function showConfirmAuto(BirdId) {
    var price = $("#txtPrice_" + BirdId).val();

    if (checkPrice(price)) {
        //取消密碼檢查, Reiko, 2013/03/05
        //if ($('#txtPassword_' + BirdId).val() == '') {
        //    alert("請填入密碼 !!")
        //    return;
        //}
        $(".hlkAuto" + BirdId).attr("href", "/Bid/PostPriceConfirm_Auto.aspx?Id=" + BirdId + "&Price=" + price + "&pw=" + $('#txtPassword_' + BirdId).val());
        $(".hlkAuto" + BirdId).trigger("click");
    }
}

function CloseFancyBox() {
    try
        { parent.$.fancybox.close(); }
    catch (e)
        { top.$.fancybox.close(); }
}
function CloseFancyBoxAndRefreshParent() {
    CloseFancyBox();

    if (parent.window.location.href.indexOf("#") > -1) {
        parent.window.location.replace(parent.window.location.href.substr(0, parent.window.location.href.indexOf("#")));
    } else {
        parent.window.location.replace(parent.window.location.href);
    }
}


function getTF() {
    var d, s = "";
    d = new Date();
    s = d.getFullYear() + (d.getMonth() + 1) + d.getDate() + d.getHours() + d.getMinutes() + d.getSeconds();
    return (s);
}