﻿
Type.registerNamespace('CustomExtenders');
Type.registerNamespace('AjaxControlToolkit');

var raisefeedback  = false;

CustomExtenders.ConfirmationPopUpBehaviour = function(element)
{
    CustomExtenders.ConfirmationPopUpBehaviour.initializeBase(this, [element]);
    this._successfullAlert = null; 
    this._reloadonclose = null; 
    this._successTriggerControlClientID = null;    
    this._counttextlength = false;
    this._updateprogressid = null;
    this._closehandlerids = null;
    this._closeClickHandler = Function.createDelegate(this, this._oncloseClick);
    this.handlearray = new Array();
}

CustomExtenders.ConfirmationPopUpBehaviour.prototype = {
           
        initialize : function() {       
        if (this._closehandlerids){
            this.handlearray = this._closehandlerids.split(",");        
            for (var i=0; i<this.handlearray.length; i++)
            {
                $addHandler($get(this.handlearray[i]), "click", this._closeClickHandler); 
            }
        }
        CustomExtenders.ConfirmationPopUpBehaviour.callBaseMethod(this, 'initialize');              
        
                    
    },
      
    dispose : function() {
        if (this._closeClickHandler) {           
           for (var i=0; i<this.handlearray.length; i++)
           {              
             Sys.UI.DomEvent.clearHandlers($get(this.handlearray[i]));
           }
           this._closeClickHandler = null;
        }
        CustomExtenders.ConfirmationPopUpBehaviour.callBaseMethod(this, 'dispose');
    },
    _layout : function() {
        /// <summary>
        /// Position the modal dialog in the center of the screen
        /// </summary>
        
        var scrollLeft =  getScrollXY().X;
        var scrollTop = getScrollXY().Y;
        
        var clientBounds = CommonToolkitScripts.getClientBounds();
        
        var clientWidth = clientBounds.width;
        if(clientWidth==0 && document.body.clientWidth)
            clientWidth = document.body.clientWidth;
        var clientHeight = clientBounds.height;    
        if(clientHeight==0 && document.body.clientHeight)   
            clientHeight =  document.body.clientHeight;   
        this._foregroundElement.style.position = "absolute";
        if(scrollLeft+((clientWidth-this._foregroundElement.offsetWidth)/2)>=0)
                this._foregroundElement.style.left = scrollLeft+((clientWidth-this._foregroundElement.offsetWidth)/2)+'px';        
        else
                this._foregroundElement.style.left = '0px';
        if(scrollTop+((clientHeight-this._foregroundElement.offsetHeight)/2)>=0) 
                this._foregroundElement.style.top = scrollTop+((clientHeight-this._foregroundElement.offsetHeight)/2)+'px';
        else
                this._foregroundElement.style.top = '0px';                        
    },

 get_SuccessTriggerControlClientID : function()
 {
    return this._successTriggerControlClientID;
 },
 set_SuccessTriggerControlClientID : function(value)
 {
    this._successTriggerControlClientID = value;
 },
 
 get_SuccessfullAlert : function()
 {
    return this._successfullAlert;
 },  
 
 set_SuccessfullAlert : function(value)
 {
    this._successfullAlert = value;
 },
 
 get_ReloadOnClose : function()
 {
    return this._reloadonclose;
 },
 
 set_ReloadOnClose : function(value)
 {
    this._reloadonclose = value;   
 },
 
 get_Counttextlength : function()
 {
    return this._counttextlength;
 },
 
 set_Counttextlength : function(value)
 {
    this._counttextlength = value;
 },
 
 get_UpdateProgressControlID : function()
 {
    return this._updateprogressid;
 },
 set_UpdateProgressControlID : function(value)
 {
    this._updateprogressid = value;
 },
 
  get_CloseHandlerIds : function(){
         return this._closehandlerids;
  },
  set_CloseHandlerIds : function(value){        
        this._closehandlerids = value;        
  },
    
  _oncloseClick : function(e) {          
        if (!this.get_ReloadOnClose())             
            this.hide();
        else
            window.location.reload();    
  },
    
  _partialUpdateEndRequest : function(sender, endRequestEventArgs){                
        AjaxControlToolkit.ModalPopupBehavior.callBaseMethod(this, '_partialUpdateEndRequest', [sender, endRequestEventArgs]);            
        if (this.get_SuccessfullAlert() && endRequestEventArgs.get_error() == null 
        && raisefeedback)
        {             
           $get("SuccessPopUp").style.display = "block";
           LayoutSuceessPopUp();
        }
        else if (endRequestEventArgs.get_error() != null)
        {
            $get(this.get_PopupControlID()).style.display = "none";
        }
        else{
        }
                
        if(this.get_Counttextlength()  ) { setMaxLength(); }
        

    },
    
     _partialUpdateBeginRequest : function(sender, beginRequestEventArgs){        
        AjaxControlToolkit.ModalPopupBehavior.callBaseMethod(this, '_partialUpdateBeginRequest', [sender, beginRequestEventArgs]);                    
        raisefeedback  = false;                  
                    
        if (this.get_SuccessTriggerControlClientID() == beginRequestEventArgs._postBackElement.id)
        {                       
            raisefeedback = true;
        }        
    }      
 }
 
 CustomExtenders.ConfirmationPopUpBehaviour.registerClass
('CustomExtenders.ConfirmationPopUpBehaviour', AjaxControlToolkit.ModalPopupBehavior);
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();