﻿//==================================================
// Ranking object
//==================================================
function escaperanklogin(sURL) { 
top.location.href=sURL; 
} 
function vwcRanking(target, ticket, portalId, userId, tableName, columnName, itemId, currentRank)
{
	// This is the constructor function
	// It is called automatically when you create a new object.
	// For example:
	// vRank = new vwcRanking();
	
	this._target = target;
	this._ticket = ticket;
	this._portalId = portalId;
	this._userId = userId;
	this._tableName = tableName;
	this._columnName = columnName;
	this._itemId = itemId;
	this._currentRank = currentRank;
	
	// Controls	
	this.uLink;
	this.uLinkD;
	this.dLink;
	this.dLinkD;
    this.rankCtr;
	this.rankPgs;
	this.rankedControl;
	this.rankedButtons;
	this.rankedUpButton;
	this.rankedDnButton;
	
	// Initial
	this.initComponents = function(){
	    this.uLink = $get(this._target.replace("RankingPanel","RankUpLink"));
        this.uLinkD = $get(this._target.replace("RankingPanel","RankUpLinkD"));
       
        this.dLink = $get(this._target.replace("RankingPanel","RankDnLink"));
        this.dLinkD = $get(this._target.replace("RankingPanel","RankDnLinkD"));
            
        this.rankCtr = $get(this._target.replace("RankingPanel","RankControl"));
        this.rankPgs = $get(this._target.replace("RankingPanel","RankAnim"));        
        
        this.configControl(this._currentRank);
	}
	
	this.updateRank = function(rank){
        this.manageAnimation(true);
        if (vwcWebService == null) vwcWebService = new Venexus.WebControls.WebControlsWS();           
        vwcWebService.UpdateRank(this._ticket, this._portalId, this._userId, this._tableName, this._columnName, this._itemId, rank, SucceededCallback, FailedCallback, this);           
	}
	
	this.displayRank = function(rank){
	    if (rank != null)
        {
            this.rankCtr = $get(this._target.replace("RankingPanel","RankControl"));
            if (document.all)
            {
                this._currentRank = parseInt(this.rankCtr.innerText);
                this.rankCtr.innerText = rank;
            }
            else
            {
                this._currentRank = parseInt(this.rankCtr.textContent);
                this.rankCtr.textContent = rank;
            }
            
            
            if (rank > this._currentRank)
            {
                this.configControl(1);
            }
            else
            {
                this.configControl(-1);
            }            
        }        
	}
	
	this.manageAnimation = function(show){
        if (this.uLink) this.uLink.style.display = show ? "none" : "";
        if (this.uLinkD) this.uLinkD.style.display = show ? "" : "none";
        
        if (this.dLink) this.dLink.style.display = show ? "none" : "";
        if (this.dLinkD) this.dLinkD.style.display = show ? "" : "none";
            
        if (this.rankCtr) this.rankCtr.style.display = show ? "none" : "";
        if (this.rankPgs) this.rankPgs.style.display = show ? "" : "none";
	}    
	
	this.configControl = function(rank)
	{
	    this.rankedButtons = $get("RankButtons" + this._itemId);             
        if (this.rankedButtons) this.rankedButtons.style.display = (rank == 0) ? "" : "none";  
        
        this.rankedUpButton = $get(this._target.replace("RankingPanel","RankUp"));        
        if (this.rankedUpButton) this.rankedUpButton.style.display = (rank == 1) ? "" : "none";
        
        this.rankedDnButton = $get(this._target.replace("RankingPanel","RankDn"));        
        if (this.rankedDnButton) this.rankedDnButton.style.display = (rank == 1) ? "none" : "";
        
        this.rankedControl = $get("RankedControl" + this._itemId);
        if (this.rankedControl) this.rankedControl.style.display = (rank == 0) ? "none" : "";
	}
}