﻿//==================================================
// Rating object
//==================================================
function escaperatelogin(sURL) { 
    top.location.href=sURL; 
} 
function vwcRating(target, ticket, portalId, moduleId, userId, columnName, itemId)
{
	// This is the constructor function
	// It is called automatically when you create a new object.
	// For example:
	// vRank = new vwcRating();
	
	this._target = target;
	this._ticket = ticket;
	this._portalId = portalId;
	this._moduleId = moduleId;
	this._userId = userId;
	this._columnName = columnName;
	this._itemId = itemId;

	// Controls	
	this.ratingButton;
	this.averageCtr;
	this.messageCtr;
    this.ratingCtr;
	this.ratingPgs;
	
	this.t;
	
	// Initial
	this.initComponents = function() {
        this.ratingButton = $get(this._target.replace("RatingPanel","RatingButton"));
        
        this.messageCtr = $get(this._target.replace("RatingPanel","ThankYouLabel"));
        this.hasRatingCtr = $get(this._target.replace("RatingPanel","HasRating"));
        this.noRatingCtr = $get(this._target.replace("RatingPanel","NoRating"));
                    
        this.ratingCtr = $get(this._target.replace("RatingPanel","RatingControl"));
        this.ratingPgs = $get(this._target.replace("RatingPanel","RatingLoading"));
	}
	
	this.updateRating = function() {
	    this._ratingControl.disable();
        this.manageAnimation(true);
        if (vwcWebService == null) vwcWebService = new Vivo.WebControls.WebControlsWS();           
        vwcWebService.UpdateRating(this._ticket, this._portalId, this._moduleId, this._userId, this._columnName, this._itemId, this._ratingControl.options.value, SucceededCallback, FailedCallback, this);
	}

	this.displayRating = function(rate) {
	    if (rate != null) {
	        this.messageCtr = $get(this._target.replace("RatingPanel", "ThankYouLabel"));
	        if (jQuery(this.messageCtr).attr("alertmessage") != null) {
	            alert(jQuery(this.messageCtr).text());
	        }
	        else {
	            //if (jQuery(this.messageCtr).css('position') != "absolute")
	            jQuery(this.messageCtr).css("position", "absolute").css("width", "180px").css("padding", "4px").addClass("ui-state-highlight ui-corner-all").show();
	            //this.messageCtr.style.display = "";
	            //window.setTimeout("function () { jQuery('#" + this.messageCtr.id + "').hide(); }", 2500);
	            setTimeout("HideElement('" + this._target.replace("RatingPanel", "ThankYouLabel") + "')", 2500);
	            //eval("setTimeout(function() { alert('Hide');jQuery('#" + this.messageCtr.id + "').hide(); }, 2500");
	        }

	        this.averageCtr = $get(this._target.replace("RatingPanel", "AverageLabel"));
	        if (this.averageCtr) {
	            if (document.all) { this.averageCtr.innerText = rate; }
	            else { this.averageCtr.textContent = rate; }
	        }

	        this._ratingControl.select(this._ratingControl.options.value);

	        this.noRatingCtr = $get(this._target.replace("RatingPanel", "NoRating"));
	        if (this.noRatingCtr) this.noRatingCtr.style.display = "none";
	    }
	}
	
	this.manageAnimation = function(show){
        if (this.ratingButton) this.ratingButton.style.display = "none";
        if (this.ratingPgs) this.ratingPgs.style.display = show ? "" : "none";
	}    
}
