﻿Type.registerNamespace("Arcadix.Framework.Controls");

var enumProgressTextType = { Custom : 1, Loading : 2, Saving : 3 };

Arcadix.Framework.Controls.Animation = function(strControlId) {
    ///<summary>Animation class, to show and hide animation when certain process in going on. eg: Updatepanel or Webservice Call</summary>
    this.ProgressText = "";
    this.UpdatePanelAnimationId = "";
    this.ProgressTextType = "";
    if (strControlId != null) {
        this.UpdatePanelAnimationId = strControlId;//eval(strControlId + "_UpdatePanelAnimationId");
    }
    this.AnimationDiv = document.getElementById(this.UpdatePanelAnimationId + "_ProgressText");
    this.ShowAnimationImage = true;

    this.Show = function(objShowAnimationOnElement) {
        ///<summary>Method show the animation</summary>             
        //Set the Progress Text.
        var strProgressText = "";
        if (this.ProgressTextType == "2") {
            if(document.getElementById(this.UpdatePanelAnimationId + "_hdnLoadingText") != null)
            {
                strProgressText = document.getElementById(this.UpdatePanelAnimationId + "_hdnLoadingText").value;
            }
        }
        else if (this.ProgressTextType == "3") {
            if(document.getElementById(this.UpdatePanelAnimationId + "_hdnSavingText") != null)
            {
                strProgressText = document.getElementById(this.UpdatePanelAnimationId + "_hdnSavingText").value;
            }
        }
        else if (this.ProgressTextType == "1") {
            strProgressText = this.ProgressText;
        }
        if (document.getElementById(this.UpdatePanelAnimationId + "_ProgressText") != null) {
            document.getElementById(this.UpdatePanelAnimationId + "_ProgressText").innerHTML = "";
        }
        if (strProgressText != "") {
            document.getElementById(this.UpdatePanelAnimationId + "_ProgressText").innerHTML = strProgressText;
        }
        else if (document.getElementById(this.UpdatePanelAnimationId + "_ProgressText") != null) {
            if (document.getElementById(this.UpdatePanelAnimationId + "_hdnProgressText") != null) {
                document.getElementById(this.UpdatePanelAnimationId + "_ProgressText").innerHTML = document.getElementById(this.UpdatePanelAnimationId + "_hdnProgressText").value;
            }
        }

        var objdiv = document.getElementById(this.UpdatePanelAnimationId + "_divUpdatePanelAnimation");
        if (objdiv != null) {
            var objImagePlaceHolder = document.getElementById(this.UpdatePanelAnimationId + "_tblImagePlaceHolder");
            var objDateTime = new Date();
            objdiv.Time = objDateTime.getTime();

            var intNewHeight = document.body.scrollHeight;
            var intNewWidth = document.body.scrollWidth;

            if (window.frameElement != null) {
                if (intNewWidth < window.frameElement.clientWidth) {
                    intNewWidth = window.frameElement.clientWidth;
                }

                if (intNewHeight < window.frameElement.clientHeight) {
                    intNewHeight = window.frameElement.clientHeight;
                }
            }

            var intAnimationOnElementTop = 0;
            var intAnimationOnElementLeft = 0;
            var intAnimationOnElementWidth = intNewWidth;
            var intAnimationOnElementHeight = intNewHeight;

            if (objShowAnimationOnElement != null) {
                var objPosition = GetPosition(objShowAnimationOnElement);
                intAnimationOnElementTop = objPosition.y;
                intAnimationOnElementLeft = objPosition.x;
                intAnimationOnElementWidth = objShowAnimationOnElement.offsetWidth;
                intAnimationOnElementHeight = objShowAnimationOnElement.offsetHeight;
            }
            objdiv.style.top = intAnimationOnElementTop + 'px';
            objdiv.style.left = intAnimationOnElementLeft + 'px';
            objdiv.style.width = intAnimationOnElementWidth + "px";
            objdiv.style.height = intAnimationOnElementHeight + "px";
            objdiv.style.display = "block";
	  

            // HideDropdown(this.UpdatePanelAnimationId+"_divUpdatePanelAnimation");

            if (this.ShowAnimationImage) {
                objImagePlaceHolder.style.display = "block";
 		objImagePlaceHolder.style.visibility = "visible";
                var intTop = ((document.body.clientHeight - objImagePlaceHolder.offsetHeight) / 2) + document.body.scrollTop;
                var intLeft = ((document.body.clientWidth - objImagePlaceHolder.offsetWidth) / 2) + document.body.scrollLeft;
                objImagePlaceHolder.style.top = intTop + "px";
                objImagePlaceHolder.style.left = intLeft + "px";
            }
            else {
 		objImagePlaceHolder.style.visibility = "hidden";                
		objImagePlaceHolder.style.display = "none";
            }
        }
    }

    function GetPosition(e) {
        ///<summary>Get final xy coordiantes according to the element position.</summary>
        ///<param name="ev" type="Object"></param>
        var left = 0;
        var top = 0;
        if (e != null) {
            left += e.offsetLeft;
            top += e.offsetTop;
        }
        return { x: left, y: top };
    }

    /*function GetPosition(e,left,top)
    {
    ///<summary>Get final xy coordiantes according to the element position.</summary>
    ///<param name="ev" type="Object"></param>
    if(left == null)
    {
    left = 0;
    }   
    if(top == null)
    {
    top  = 0;
    }
    if(e != null && e.offsetLeft && e.offsetTop)
    {	        
    left += e.offsetLeft;
    top  += e.offsetTop;            
    }
    if(e.parentElement != null)
    {
    var objPosition = GetPosition(e.parentElement,left,top);
    left = objPosition.x;
    top = objPosition.y;
    }
    return {x:left, y:top};
    }*/

    this.Hide = function() {
        ///<summary>Method hide the animation</summary>
        if (document.getElementById(this.UpdatePanelAnimationId + "_divUpdatePanelAnimation") != null) {
             document.getElementById(this.UpdatePanelAnimationId + "_divUpdatePanelAnimation").style.display = "none";
        }
        //window.clearTimeout();
        //ShowDropdown();
    }

    this.IsShown = function()
    {
         var blnReturnValue = false;
         var objdiv = document.getElementById(this.UpdatePanelAnimationId + "_divUpdatePanelAnimation");
         if (objdiv != null) 
         {
            if(objdiv.style.display.toUpperCase() == "BLOCK")
            {
                blnReturnValue = true;
            }
         }
         return blnReturnValue;
    }

}

Arcadix.Framework.Controls.Animation.registerClass('Arcadix.Framework.Controls.Animation',null,Sys.IDisposable);
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

