/// <reference name="MicrosoftAjax.js"/>


Type.registerNamespace("RatingsAndCommentingCntrls");

RatingsAndCommentingCntrls.CommentsClientControl = function(element) {
    RatingsAndCommentingCntrls.CommentsClientControl.initializeBase(this, [element]);
    this._btnAddCommentID = null;
    this._btnSaveID = null;
    this._btnCancelID = null;
    this._rowInputID = null;
    this._hiddenFieldID = null;
}

RatingsAndCommentingCntrls.CommentsClientControl.prototype = {
    initialize: function() {
        RatingsAndCommentingCntrls.CommentsClientControl.callBaseMethod(this, 'initialize');
        // Add custom initialization here  
        if (this._btnAddCommentID != null && this._btnSaveID != null)
        {
            $addHandlers($get(this._btnAddCommentID),
                { 'click' : this._onAddComment }, this); 
            $addHandlers($get(this._btnSaveID),
                { 'click' : this._onSave }, this);
            $addHandlers($get(this._btnCancelID),
                { 'click' : this._onCancel }, this);  
        }    
    },
    dispose: function() {        
        //Add custom dispose actions here
        if (this._btnAddCommentID != null) $clearHandlers($get(this._btnAddCommentID));
        if (this._btnSaveID != null) $clearHandlers($get(this._btnSaveID));
        if (this._btnCancelID != null) $clearHandlers($get(this._btnCancelID));
        RatingsAndCommentingCntrls.CommentsClientControl.callBaseMethod(this, 'dispose');
    },
    // Property Accessors
    get_btnAddCommentID: function() {
        return this._btnAddCommentID;
    },
    set_btnAddCommentID: function(value) {
        if (this._btnAddCommentID != value) {
            this._btnAddCommentID = value;
            this.raisePropertyChanged('btnAddCommentID');
        }
    },
    get_btnSaveID: function() {
        return this._btnSaveID;
    },
    set_btnSaveID: function(value) {
        if (this._btnSaveID != value) {
            this._btnSaveID = value;
            this.raisePropertyChanged('btnSaveID');
        }
    },
    get_btnCancelID: function() {
        return this._btnCancelID;
    },
    set_btnCancelID: function(value) {
        if (this._btnCancelID != value) {
            this._btnCancelID = value;
            this.raisePropertyChanged('btnCancelID');
        }
    },
    get_rowInputID: function() {
        return this._rowInputID;
    },
    set_rowInputID: function(value) {
        if (this._rowInputID != value) {
            this._rowInputID = value;
            this.raisePropertyChanged('rowInputID');
        }
    },
    get_hiddenFieldID: function() {
        return this._hiddenFieldID;
    },
    set_hiddenFieldID: function(value) {
        if (this._hiddenFieldID != value) {
            this._hiddenFieldID = value;
            this.raisePropertyChanged('hiddenFieldID');
        }
    },
    // Event Handlers
    _onAddComment: function() {
        var btnAddComment = $get(this._btnAddCommentID);
        var rowInput = $get(this._rowInputID);
        rowInput.style.display = "";
        btnAddComment.style.display = "none";
    },
    _onSave : function() {
        var btnSave = $get(this._btnSaveID);
        var input = btnSave.parentNode.getElementsByTagName('textarea')[0];
        var hiddenField = $get(this._hiddenFieldID);
        hiddenField.value = input.value;
        __doPostBack(this._hiddenFieldID, input.value)
    },
    _onCancel : function() {
        var btnAddComment = $get(this._btnAddCommentID);
        var rowInput = $get(this._rowInputID);
        rowInput.style.display = "none";
        btnAddComment.style.display = "";
    }
}

RatingsAndCommentingCntrls.CommentsClientControl.registerClass('RatingsAndCommentingCntrls.CommentsClientControl', Sys.UI.Control);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
Type.registerNamespace('RatingsAndCommentingCntrls');RatingsAndCommentingCntrls.Resource={};
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();