﻿/// <reference name="MicrosoftAjax.js" />

Type.registerNamespace('iFramework.Bll');

iFramework.Bll.Page = function(preloaderID, backgroundElementID, activeCssClass, inActiveCssClass) {
  
  this.preloader = $get(preloaderID);
  
  this.backgroundElement = $get(backgroundElementID);
    
  this.activeCssClass = activeCssClass;
  
  this.inActiveCssClass = inActiveCssClass;
  
  this.initLoadingHint();
};

iFramework.Bll.Page.goOnPageTop = false;

iFramework.Bll.Page.showLoadingHint = function (instance) {
  instance.showLoadingHint();
};

iFramework.Bll.Page.hideLoadingHint = function (instance) {
  instance.hideLoadingHint();
};

iFramework.Bll.Page.prototype = {

    initLoadingHint : function() {
      if (Sys && Sys.WebForms) {
        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(Function.createDelegate(this, this.showLoadingHint));
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(Function.createDelegate(this, this.hideLoadingHint));
      }
    },
    
    showLoadingHint : function() {
      if (this.preloader) {
        iFramework.Core.setClass(this.preloader, this.activeCssClass);
      }
      if (this.backgroundElement)
      {  
        windowSize = iFramework.Browser.getActiveWindowSize();
        this.backgroundElement.style.display = '';
        this.backgroundElement.style.width = windowSize.getX() - 20 + 'px';
        this.backgroundElement.style.height = windowSize.getY() + 'px';
      }
    },

    hideLoadingHint : function()
    {  
      if (iFramework.Bll.Page.goOnPageTop)
      {
	      window.setTimeout(function() { scroll(0,0);}, 1000);
	      iFramework.Bll.Page.goOnPageTop = false;
	    }
      if (this.preloader) {
        iFramework.Core.setClass(this.preloader, this.inActiveCssClass);
      }
      if (this.backgroundElement)
      {
        this.backgroundElement.style.display = 'none';
        this.backgroundElement.style.width = '0px';
        this.backgroundElement.style.height = '0px';
      }  
    }    
}

iFramework.Bll.Page.registerClass('iFramework.Bll.Page');
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();