﻿    
function formatString(str)
{                                            
    for(i = 1; i < arguments.length; i++)
    {
        str = str.replace("{" + (i - 1) + "}", arguments[i]);
    }
    
    return str;
}

function CurrentX(event)
{
    return event.clientX+(document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
}

function CurrentY(event)
{
    return event.clientY+(document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
}

function attachToEvent(eventOwner,eventName,delegate)
 {    
      if(window.addEventListener)
      { // Mozilla, Opera, Safari
        if(eventName.substring(0,2) == "on")
        {
            eventName = eventName.substring(2,eventName.length-1);
        }
        
        eventOwner.addEventListener(eventName,delegate,false);
      }
      else//IE
      {
        if(eventName.substring(0,2) != "on")
        {
            eventName = "on"+ eventName;
        }
        eventOwner.attachEvent(eventName,delegate);
      }

      
 }

 function getWindowHeight() {
			var windowHeight = 0;
			if (typeof(window.innerHeight) == 'number') {
				windowHeight = window.innerHeight;
			}
			else {
				if (document.documentElement && document.documentElement.clientHeight) {
					windowHeight = document.documentElement.clientHeight;
				}
				else {
					if (document.body && document.body.clientHeight) {
						windowHeight = document.body.clientHeight;
					}
				}
			}
			return windowHeight;
		}
function getWindowWidth() {
			var windowWidth = 0;
			if (typeof(window.innerWidth) == 'number') {
				windowWidth = window.innerWidth;
			}
			else {
				if (document.documentElement && document.documentElement.clientWidth) {
					windowWidth = document.documentElement.clientWidth;
				}
				else {
					if (document.body && document.body.clientWidth) {
						windowWidth = document.body.clientWidth;
					}
				}
			}
			return windowWidth;
		}

 var net = new Object();
  //Констркуктор прототипа для progressbar
    net.PerisProgressBar = function(path)
    {
        this.divProgressBar = null;
        this.path = path;
        if(document.body==null){
                        document.write("<Body></Body>");
        }
        this.blockUp = new net.ActivityBlocker("ProgressBackground");
    }
    // начало тела прототипа
    net.PerisProgressBar.prototype ={
        //показывает прогресс бар
        ShowProgressBar:function(type){
            var divProgressBar = document.getElementById("__PERIS_PROGRESS_BAR");
                this.blockUp.Block();
                var pb = this;
                if(divProgressBar==null)
                {
                    divProgressBar = document.createElement("DIV");
                    divProgressBar.id = "__PERIS_PROGRESS_BAR";
                    var imgBody = document.createElement("IMG");
                    imgBody.setAttribute("src",this.path);//"../Images/BMS/Images/ajax-loader.gif");
                    imgBody.width = "32";
                    imgBody.height = "32";
                    //imgBody.setAttribute("src","../../Images/ajax-loader-attention.gif");
                    divProgressBar.appendChild(imgBody);
                    divProgressBar.style.width = imgBody.style.width;
                    divProgressBar.style.height = imgBody.style.height;
                    divProgressBar.style.position = "absolute";
                    
                    
                    document.body.appendChild(divProgressBar);
                    
                    
                    attachToEvent(window,"onresizeend",function(){pb.progressAlignCenter();})
                    attachToEvent(window,"onscroll",function(){pb.progressAlignCenter();})
                    
                    attachToEvent(imgBody,"ondblclick",function(){pb.CloseProgressBar();});
                    attachToEvent(divProgressBar,"ondblclick",function(){pb.CloseProgressBar;});
                    
                    this.divProgressBar = divProgressBar;
                    
                }
                this.progressAlignCenter.call(this);
                divProgressBar.style.zIndex = 10001;
                divProgressBar.style.visibility = "visible";

            
        },
        //Скрывает прогесс бар
        CloseProgressBar:function(){
            this.divProgressBar.style.visibility = "hidden";
            this.blockUp.UnBlock();
        },
        //Выравнивает прогресс бар по центру страницы
        progressAlignCenter:function(){
            if (document.getElementById) {
				var windowHeight = getWindowHeight();
				if (windowHeight > 0) {
				    if(this.divProgressBar){
					    var contentElement = this.divProgressBar;
					    var contentHeight = contentElement.offsetHeight;
					    if (windowHeight - contentHeight > 0) {
						    //contentElement.style.position = 'relative';
						    contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2));
						    contentElement.style.left = document.body.clientWidth/2;
						    contentElement.children[0].style.top = contentElement.style.top;
						    contentElement.children[0].style.left = contentElement.style.left;
					    }
					    else {
						    contentElement.style.position = 'static';
					    }
			        }
				}
			}
        }
     //окончание тела прототипа
     }
 //прототип блокиратора действий пользователя
    net.ActivityBlocker=function(css,timeOut)
    {
        this.timeOut = timeOut;
        this.blockerDiv = document.getElementById("__PERIS_BLOCKER");
        if(this.blockerDiv==null){
         this.blockerDiv = document.createElement("DIV");
         this.blockerDiv.id = "__PERIS_BLOCKER";
         
        this.blockerDiv.className = css;
        this.blockerDiv.style.zIndex = 10001;
        this.blockerDiv.style.width = getWindowWidth();
        this.blockerDiv.style.height = getWindowHeight();
        this.blockerDiv.style.position = "absolute";
        this.blockerDiv.style.visibility = "hidden";
        document.body.appendChild(this.blockerDiv);
        }
    }
    net.ActivityBlocker.prototype={
        Block:function(){
        
            this.blockerDiv.style.visibility = "visible";
          
        },
        UnBlock:function(){
            this.blockerDiv.style.visibility = "hidden";
        }
    }
    
    