var isIE = window.navigator.userAgent.indexOf("MSIE")>-1;
var GlassWindow=null;
var Dialog=null;

Lib = {};
Lib.Browser = {
    IE:     !!(window.attachEvent && !window.opera),
    Opera:  !!window.opera,
    WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
    Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1
  };
/**
   * Lib.ScreenUtils
   */

Lib.ScreenUtils = {
    getSize: function() {
      return {
        width: this.getWidth(),
        height: this.getHeight()
      };
    },
    getWidth: function() {
      return window.innerWidth || (document.documentElement && document.documentElement.clientWidth) || document.body.clientWidth;
    },
    getHeight: function() {
      return window.innerHeight || (document.documentElement && document.documentElement.clientHeight) || document.body.clientHeight;
    },
    getScroll: function() {
      return {
        left: this.getScrollLeft(),
        top: this.getScrollTop()
      };
    },
    getScrollLeft: function() {
      return window.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || document.body.scrollLeft;
    },
    getScrollTop: function() {
      return window.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;
    },
    getScrollWidth: function() {
      if (Lib.Browser.IE) {
        return Math.max(document.documentElement.offsetWidth, document.body.scrollHeight);
      }
      return (document.documentElement && document.documentElement.scrollWidth) || document.body.scrollWidth;
    },
    getScrollHeight: function() {
      if (Lib.Browser.IE) {
        return Math.max(document.documentElement.offsetHeight, document.body.scrollHeight);
      }
      return (document.documentElement && document.documentElement.scrollHeight) || document.body.scrollHeight;
    }
  };


// MAIN SERVICE CLASS
// constructor
function Service(){
	if (window.ActiveXObject) {
		this.xhtml = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest) {
		this.xhtml = new XMLHttpRequest();
	}
	return this;
}

Service.prototype = {}
// send request
Service.prototype.send = function(script,postparam,handler){
	this.xhtml.open('POST',script,true);	
	this.xhtml.onreadystatechange = handler;
	this.xhtml.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	this.xhtml.send(postparam);
}
// return init object from xhttprequest or activexobject
Service.prototype.getXHTML = function(){
	return this.xhtml;
}
// return current state
Service.prototype.getState = function(){
	return this.xhtml.readyState;
}
// return current status
Service.prototype.getStatus = function(){
	return this.xhtml.status;
}
// return request by text
Service.prototype.getXhtmlText = function(){
	return this.xhtml.responseText;
}
// return request by XML
Service.prototype.getXhtmlXML = function(){
	return this.xhtml.responseXML;
}
// create or destroy Splash screen
Service.prototype.showSplash = function(wid,time){
	
}

Service.prototype.getWidth = function(elem){
//function getWidth(elem){
	 return elem.offsetWidth || getStyle(elem,'width') || getStyle(elem,'min-width') || elem.width;
}
Service.prototype.getHeight = function(elem){
//function getHeight(elem){
	return elem.offsetHeight || getStyle(elem,'height') || getStyle(elem,'min-height') || elem.height;
}
Service.prototype.getHeight = function(elem,property){
//function getStyle(elem,property) {
      property = property == 'float' ? 'cssFloat' : property;
      var value = elem.style[property];
      if (!value) {
        if (document.defaultView && document.defaultView.getComputedStyle) {
          value = document.defaultView.getComputedStyle(elem, null)[property] || null;
        } else if (window.getComputedStyle) {
          value = window.getComputedStyle(elem, null)[property] || null;
        } else if (elem.currentStyle) {
          value = elem.currentStyle[property] || null;
        }
      }
      if (property == 'opacity') {
        return value ? parseFloat(value) : 1.0;
      }
      return value == 'auto' ? null : value;
}

// create or destroy Modal window
Service.prototype.showModalWindow = function(show,wid){
	// background
	if(GlassWindow==null){
		GlassWindow=document.createElement('DIV');
		with(GlassWindow.style){
			display='none';
			position='absolute';
			height=0;	
			width=0;	
			zIndex=2;
			if(isIE){
				backgroundColor = '#FFFFFF';
				filter="progid:DXImageTransform.Microsoft.Alpha(Opacity=40, Style=0)";
			}
			else
				backgroundImage = 'url(images/modal.png)';
			}
		document.body.appendChild(GlassWindow);
	}
	if(show){
		with(GlassWindow.style){
			left = 0;
			top = 0;
			width = Lib.ScreenUtils.getWidth()+'px';
			height = Lib.ScreenUtils.getHeight()+Lib.ScreenUtils.getScrollTop()+'px';
			position = 'absolute';
			display = 'block';
		}
	}else{
		display = 'none';
	}
	// create window
	if(Dialog==null) Dialog=document.getElementById(wid);
	if(show){
		Dialog.style.zIndex  = -1;
		Dialog.style.display = 'block';
		dh = parseInt(Lib.ScreenUtils.getHeight()/2+Lib.ScreenUtils.getScrollTop()-this.getHeight(Dialog)/2);
		dw = parseInt(Lib.ScreenUtils.getWidth()/2)-parseInt(this.getWidth(Dialog)/2);
		Dialog.style.top = dh+'px';
		Dialog.style.left = dw+'px';
		Dialog.style.zIndex  = 10;
		Dialog.focus();
	}else{
		Dialog.style.display = 'none';
		with(GlassWindow.style){
			display='none';
			position='absolute';
			height=0;	
			width=0;	
			zIndex=-1;
			}
	}
}
//=========================================================================
//=========================================================================
//=========================================================================

