var activeauctions ={};
activeauctions.container = null;activeauctions.activeAuctions = null;
activeauctions.dispCount = 3;activeauctions.reportLink = "reports.html#active";
activeauctions.params = {
    select : "auction_id,title,current_bid",
    _limit : 3,
    _orderby : "creation_time",
    orderdir : "DESC"
};

activeauctions.renderActiveAuctions = function(data){
    activeauctions.activeAuctions = data;  
    var activeHtml = '<div class="activeHeader"><div><h2 style="float:left">Active Auctions</h2></div><div class="currentBidButton">CURRENT BID</div></div><div class="activeRowCont">';
    if(activeauctions.activeAuctions.result.length == 0){
        activeHtml +='<div style="text-align: center; margin-top: 85px;font-size:11px;color:#333;">No active auctions found.</div>';
    } else if (activeauctions.activeAuctions.result != undefined && activeauctions.activeAuctions.result != null && activeauctions.activeAuctions.result.length > 0){
        var showCount = activeauctions.activeAuctions.result.length;
        if(showCount > activeauctions.dispCount){
            showCount = activeauctions.dispCount;
        }
        for(var ct = 0; ct < showCount;ct++){
            activeHtml +='<div class="tableAuctionsRow">';
            activeHtml +=   '<div class="dashboardAuctionID"><a href="javascript:void(0);" onclick="activeauctions.launchpreview(\''+activeauctions.activeAuctions.result[ct].auction.id+'\');">'+activeauctions.activeAuctions.result[ct].auction.id+'</a></div>'+
            '<div class="dashboardAuctionTitleSmall"><label>'+activeauctions.activeAuctions.result[ct].title.wordwrap()+'</label></div>'+
            '<div class="dashboardCurrentBid"><label>GBP &nbsp;</label><div>'+activeauctions.activeAuctions.result[ct].current_bid+'</div></div>'+
            '</div>';
        }
//        activeHtml+='</div>';
    }else if (activeauctions.activeAuctions.error != undefined && activeauctions.activeAuctions.error != null &&  activeauctions.activeAuctions.error.length > 0){
        activeHtml +='<div style="text-align: center; margin-top: 85px;">This information is currently unavailable.</div>';
    }
     activeHtml +='</div><div class="allAuctionContainer">'+
    '<a><label class="allAuctionsButton" id="activaAuctionsLink" onmouseOver="this.className=\'allAuctionsButtonHover\';" onmouseOut="this.className=\'allAuctionsButton\';">'+
    '</label></a></div>';
    document.getElementById(activeauctions.container).innerHTML = activeHtml;
    $('#activaAuctionsLink').bind("click",function(){
        window.location.href = activeauctions.reportLink;
    })
};
activeauctions.launchpreview = function(auctionId){
    var prevUrl = Invoker.GetActiveAuctionPreview(auctionId);
    var aucPrev = window.open(prevUrl,"auction"+auctionId,"copyhistory=no,menubar=yes,status=no,directories=no,location=no,toolbar=no,height=600,width=700,resizable=no,scrollbars=yes");  
    if(aucPrev!=null){
        aucPrev.focus();
    }else{
        Info.Show.errorMsg("Please enable popups and try again.")
    }
}
activeauctions.showActiveAuctions = function(container,user_id){
    this.params.user_id = user_id;
    this.container = container;
    //show loader
    var activeHtml = '<div class="activeHeader"><div><h2 style="float:left">Active Auctions</h2></div><div class="currentBidButton">CURRENT BID</div></div><div class="activeRowCont">'+
    '<div style="text-align: center; margin-top: 75px;margin-left:85px;"><div style="padding: 0px;" ><div class="loading"><label>Loading...</label></div></div></div></div>';
    document.getElementById(activeauctions.container).innerHTML = activeHtml;
    Invoker.GetActiveAuctions(activeauctions.params, activeauctions.renderActiveAuctions);
};  
