﻿var limit = "0:15"

if (document.images) {
    var parselimit = limit.split(":")
    parselimit = parselimit[0] * 60 + parselimit[1] * 1
}
function beginrefresh() {
    if (!document.images)
        return
    if (parselimit == 1) {
        var isDisplayed = document.getElementById('divAuctionDetail').style.display;

        if (isDisplayed != "none") {
            var timeDuration = document.getElementById('jsalarm_ct').innerHTML;
            if (timeDuration != "0:00:00") {
                BeginViewAuctionProcess(0);
            }
        }
        parselimit = limit.split(":")
        parselimit = parselimit[0] * 60 + parselimit[1] * 1
    }
    else {
        parselimit -= 1
    }
    setTimeout("beginrefresh()", 1000)
}


var jsalarm = {
    padfield: function(f) {
        return (f < 10) ? "0" + f : f
    },
    showcurrenttime: function() {
        var dateobj = new Date();
        //document.getElementById('spanEndDate').innerHTML = "2009;3;13;13;10;0";

        var endDate = document.getElementById('spanEndDate').innerHTML;
        var parseEndDate = endDate.split(";")

        var dateendobj = new Date(parseInt(parseEndDate[0]), parseInt(parseEndDate[1]) - 1, parseInt(parseEndDate[2]), parseInt(parseEndDate[3]), parseInt(parseEndDate[4]), parseInt(parseEndDate[5]));


        var ct_diff = "0:00:00";
        if (dateendobj > dateobj) {
            if (document.getElementById('divSaleOperation').style.display == "none") {
                document.getElementById('divSaleOperation').style.display = "block";
                document.getElementById('divSaleEnded').style.display = "none";
            }

            var aaa = dateendobj - dateobj;
            var hour_diff = parseInt(aaa / (1000 * 60 * 60));
            var min_diff = parseInt(aaa / (1000 * 60)) - (parseInt(aaa / (1000 * 60 * 60)) * 60);
            var sec_diff = parseInt(aaa / (1000)) - (parseInt(aaa / (1000 * 60)) * 60);

            ct_diff = hour_diff + ":" + this.padfield(min_diff) + ":" + this.padfield(sec_diff)
        }
        else {
            if (document.getElementById('divSaleOperation').style.display != "none") {
                document.getElementById('divSaleOperation').style.display = "none";
                document.getElementById('divSaleEnded').style.display = "block";

                BeginViewAuctionProcess(0);
            }
        }
        if (document.getElementById('divAuctionDetail').style.display == "none") {
            document.getElementById('divSaleOperation').style.display = "none";
        }

        this.ctref.innerHTML = ct_diff;
        this.ctref.setAttribute("title", ct_diff)

    },
    init: function() {
        var dateobj = new Date()
        this.ctref = document.getElementById("jsalarm_ct")
        jsalarm.showcurrenttime()
        jsalarm.timer = setInterval(function() { jsalarm.showcurrenttime() }, 1000)
    }
}





function BeginAuctionProcess(auctiontype) {
    if (auctiontype == "active") {
        var divIndicator = document.getElementById('divIndicator1');
        divIndicator.style.display = "block";
        document.getElementById('divActiveAuctions').innerHTML = "";

        addiframe("/js/JS_Auctions.aspx?auctiontype=active");
    }

    if (auctiontype == "pasive") {
        var divIndicator = document.getElementById('divIndicator2');
        divIndicator.style.display = "block";
        document.getElementById('divPasiveAuctions').innerHTML = "";

        addiframe("/js/JS_Auctions.aspx?auctiontype=pasive");
    }
}


function FillActiveAuctionProgress(activeauctions, activecount, refreshtime) {
    if (activeauctions != "") {
        document.getElementById('divActiveAuctions').innerHTML = activeauctions;
        document.getElementById('spanActiveCount').innerHTML = activecount;
        document.getElementById('spanRefreshTime').innerHTML = refreshtime;
    }
    var divIndicator = document.getElementById('divIndicator1');
    divIndicator.style.display = "none";

}

function FillPasiveAuctionProgress(pasiveauctions, pasivecount) {
    if (pasiveauctions != "") {
        document.getElementById('divPasiveAuctions').innerHTML = pasiveauctions;
        document.getElementById('spanPasiveCount').innerHTML = pasivecount;
    }
    var divIndicator = document.getElementById('divIndicator2');
    divIndicator.style.display = "none";

}

function BeginViewAuctionProcess(saleid) {
    if (saleid == 0) {
        saleid = document.getElementById('spanSaleId').innerHTML;
    }
    else {
        ClearFields();
        toggleLayer('divDeneme', 'divAuctionDetail');
    }

    if (saleid != 0) {
        var divIndicator = document.getElementById('divIndicatorDetail');
        divIndicator.style.display = "block";

        addiframe("/js/JS_Auctions.aspx?auctiontype=detail&id=" + saleid);
    }

}

function BeginBidAuctionProcess() {

    var saleId = document.getElementById('spanSaleId').innerHTML;
    var price = document.getElementById('txtBid').value;
    var bidRegxp = /^([0-9]{1,11})$/;
    if (bidRegxp.test(price) == true) {
        var isok = confirm("İşleme devam etmek istediğinize emin misiniz?");
        if (isok) {
            if (saleId != "") {
                addiframe("/js/JS_Auctions.aspx?auctiontype=bid&id=" + saleId + "&price=" + price);
            }
        }
        else {
        }
    }
    else {
        alert("Lütfen fiyat giriniz.");
    }
}


function FillBidAuctionProgress(saleId) {
    addiframe("/js/JS_Auctions.aspx?auctiontype=detail&id=" + saleId);
}



function FillViewAuctionProgress(title, owner, saleStart, saleEnd, buyNowPrice, saleId, buyNowPriceInt, refreshTime, endDateTime, currency, saleStatus, canCancel, isOwner, loggeduser) {
    if (canCancel == 1) {
        document.getElementById('btnBid').style.display = "none";
        if (document.getElementById('spanBidUsers').innerHTML == "") {
            document.getElementById('btnCancelBid').style.display = "none";
        } else {
            document.getElementById('btnCancelBid').style.display = "inline";
        }
        
    }
    else {
        document.getElementById('btnBid').style.display = "inline";
        document.getElementById('btnCancelBid').style.display = "none";
    }
    
    if (title != "") {

        document.getElementById('spanEndDate').innerHTML = endDateTime;

        document.getElementById('spanMessage').innerHTML = saleStatus;


        document.getElementById('spanSaleId').innerHTML = saleId;
        document.getElementById('spanTitle').innerHTML = title;
        document.getElementById('spanDomainName').innerHTML = "<a href=\"/Domain.aspx?id=" + title + "\" >" + title + "</a>";
        document.getElementById('spanOwner').innerHTML = owner;
        document.getElementById('spanSaleStart').innerHTML = saleStart;
        document.getElementById('spanSaleEnd').innerHTML = saleEnd;
        document.getElementById('txtCur').value = currency;
        
        var bidPrice = document.getElementById('txtBid').value;
        if (bidPrice < parseInt(buyNowPriceInt - (buyNowPriceInt * 20 / 100))) {
            document.getElementById('spanBuyNowPrice').innerHTML = buyNowPrice;
            document.getElementById('btnBuyNow1').style.display = "inline";
        }
        else {
            document.getElementById('spanBuyNowPrice').innerHTML = "-";
            document.getElementById('btnBuyNow1').style.display = "none";
        }
        if (isOwner == 1) {
            document.getElementById('btnBuyNow1').style.display = "none";
        }
    }
    else {
        toggleLayer('divDeneme', 'divAuctionDetail');
    }
    document.getElementById('spanDetailRefreshTime').innerHTML = refreshTime;
    var divIndicator = document.getElementById('divIndicatorDetail');
    divIndicator.style.display = "none";
}

function ClearFields() {
    document.getElementById('btnBid').style.display = "none";
    document.getElementById('btnCancelBid').style.display = "none";
    document.getElementById('spanEndDate').innerHTML = "";

    document.getElementById('spanMessage').innerHTML = "";
    document.getElementById('spanSaleId').innerHTML = "0";
    document.getElementById('spanTitle').innerHTML = "";
    document.getElementById('spanDomainName').innerHTML = "";
    document.getElementById('spanOwner').innerHTML = "";
    document.getElementById('spanSaleStart').innerHTML = "";
    document.getElementById('spanSaleEnd').innerHTML = "";
    document.getElementById('txtCur').value = "";
    document.getElementById('spanBuyNowPrice').innerHTML = "";
    document.getElementById('btnBuyNow1').style.display = "none";
    document.getElementById('spanDetailRefreshTime').innerHTML = "";

}

function FillViewAuctionBidUsersProgress(bidUsers, currentPrice, nextPrice) {
    document.getElementById('spanCurrentPrice').innerHTML = currentPrice;
    document.getElementById('spanBidUsers').innerHTML = bidUsers;
    document.getElementById('txtBid').value = nextPrice;
}


function MustLogin(msg) {
    alert(msg);
    toggleLayer('divDeneme', 'divAuctionDetail');
}

function ConfirmBuyNow() {
    var saleId = document.getElementById('spanSaleId').innerHTML;
    var isok = confirm('HEMEN AL ile alım yapmak üzeresiniz. Onaylamanız durumunda 2 gün içerisinde ödeme yapmanız gerekmektedir. Lütfen bunu göz önünde bulundurunuz. Aksi taktirde, satıcı olumsuz yorum hakkına sahip olacaktır. Tekrarlayan defalar yanıltıcı ve gerçek dışı HEMEN AL satış türünü kullanmanız durumunda, Domain Shopman yönetimi tarafından sistemden çıkartılabileceğinizi bilmelisiniz.');
    if (isok) {
        isok = confirm("İşleme devam etmek istediğinize emin misiniz?");
        if (isok) {
            if (saleId != "") {
                addiframe("/js/JS_Auctions.aspx?auctiontype=bid&id=" + saleId);
            }
        }
    }
}


function ConfirmCancelBid() {
    var saleId = document.getElementById('spanSaleId').innerHTML;
    var isok = confirm('Teklifi iptal etmek üzeresiniz. Devam etmeniz durumunda son teklif verenin tüm teklifleri silinecek diğer teklif veren kişilerin teklifleri tekrar hesaplanacaktır. Teklifi iptal edilen kişi bu satışa bir daha teklif veremez. Yanıltıcı ve gerçek dışı TEKLIF İPTALİ ni kullanmanız durumunda, Domain Shopman yönetimi tarafından sistemden çıkartılabileceğinizi bilmelisiniz.');
    if (isok) {
        isok = confirm("İşleme devam etmek istediğinize emin misiniz?");
        if (isok) {
            if (saleId != "") {
                addiframe("/js/JS_Auctions.aspx?auctiontype=bid&id=" + saleId + "&op=cancel");
            }
        }
    }
}
