﻿function pxrequest() {
  this.getRequest = function () {
    var req = null;
    try {
      req = new XMLHttpRequest();
    } catch (err1) {
      try {
        req = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (err2) {
        try {
          req = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (err3) {
          req = false;
        }
      }
    }
    req.parent = this;
    return req;
  }
  
  this.onloaddata = function () {
    var pj = this;
    if (this.parent)
      pj = this.parent;

    if (pj.onloadok)
      return;
    if (this.loader != null) {
      this.loader.close();
    }
    pj.onloadok = true;
    pj.onload(pj);

  }

  this.loader = null
  this.onloadok = false
  this.onload = null
  this.request = null
  this.url = ""
  this.getData = function (pUrl) {
    this.onloadok = false;
    this.url = pUrl;
    this.request = this.getRequest();
    this.request.open("GET", pUrl, true);
    this.request.send();
    this.request.onload = this.onloaddata;
    this.request.onreadystatechange = this.onreadystatechange;

    if (this.loader != null) {
      this.loader.open();
      this.loader.movepercentage(50,50);
    }
  }
  
  this.onreadystatechange = function () {
    var pj = this;
    if (this.parent)
      pj = this.parent;

    if (pj.request.readyState == 4) {
      if (pj.request.status == 200) {
        pj.onloaddata();
      }
    }
  }
}
//*********************************************************************************
//*********************************************************************************
function pxwindow() {
  
  var that = this
  
  this.winelement = null

  this.open = function () {
    that.winelement.style.display = 'block';
    document.onclick = this.keydown;
    document.onkeydown = this.keydown;
  }

  this.close = function () {
    that.winelement.style.display = 'none';
    document.onclick = null;
    document.onkeydown = null;
  }

  this.onkeydown = null
  this.keydown = function (pev) {
    var ev = pev || window.event;
    var key = ev.keyCode ? ev.keyCode : ev.which ? ev.which : ev.charCode;
    if (key == 27) {
      that.close();
    }
    if (that.onkeydown != null) {
      that.onkeydown(ev, key);
    }
  }

  this.movepercentage = function (px, py) {
    that.winelement.style.position = 'absolute';
    that.winelement.style.top = (this.getPosition(this.clientheight(), that.winelement.offsetHeight, px) + this.clientscrolltop()) + 'px';
    that.winelement.style.left = (this.getPosition(this.clientwidth(), that.winelement.offsetWidth, px) + this.clientscrollleft()) + 'px';
  }

  this.getPosition = function (pParentSize, pElementSize, pPosition) {
    var i = pParentSize - pElementSize;
    if (i <= 1 || pPosition <= 0)
      return 0;

    return Math.round(i * pPosition / 100);
  }

  this.clientwidth = function() {
    return this.clientfilter(
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
  }

  this.clientheight = function() {
    return this.clientfilter(
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
  }

  this.clientscrollleft = function() {
    return this.clientfilter(
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
  }

  this.clientscrolltop = function() {
    return this.clientfilter(
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
  }

  this.clientfilter = function(n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
      n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
  }

  function getLeft(o) {

    if (o == null) {
      return 0;
    }
    else {
      return o.offsetLeft + getLeft(o.offsetParent);
    }
  }

  function getTop(o) {
    if (o == null)
      return 0;
    else
      return o.offsetTop + getTop(o.offsetParent);
  }
}
