window.onload = LoadWindow;
window.onunload = UnloadWindow;
window.onresize = ResizeWindow;
window.onscroll = PositionUpdateProgress;

function LoadWindow() {
    ActiveXLoad();
    ResizeContentTable();
}

function UnloadWindow() {
    ActiveXUnload();
}
 
function ResizeWindow() {
    ResizeContentTable();
}

function ResizeContentTable() {
    var window_width = GetWindowWidth();
    var window_height = GetWindowHeight();
    var original_height = document.getElementById("ContentTable").offsetHeight;
    var content_width = window_width;

    if (window_width < 770) {
        content_width = 770;
        masthead_padding = 10;
    }
    if (window_width > 994) {
        content_width = 994;
        masthead_padding = 30;
    }
    document.getElementById("ContentTable").style.width = content_width + "px";

    if (original_height > window_height)
        document.getElementById("ContentTable").style.height = original_height + "px";
    else
        document.getElementById("ContentTable").style.height = window_height + "px";

    var masthead_padding = 10+(((window_width-770)/994)*100);
    document.getElementById("masthead").style.paddingLeft = masthead_padding + "px";
    
    PositionUpdateProgress();
}

function PositionUpdateProgress() {
    //center update progress flash
    var obj = document.getElementById("ctl00_Main_UpdateProgress1");
    //var obj = document.getElementById("UpdateProgress");
    if (obj) {
        obj.style.left = (GetScrollLeft() + (GetWindowWidth() - obj.offsetWidth)/2) + "px";
        obj.style.top = (GetScrollTop() + (GetWindowHeight() - obj.offsetHeight)/2) + "px";
        //alert("ScrollLeft: " + GetScrollLeft());
        //alert("WindowWidth: " + GetWindowWidth());
        //alert("OffsetWidth: " + obj.offsetWidth);
        //alert("Left: " + obj.style.left);
        //alert("ScrollTop: " + GetScrollTop());
        //alert("WindowHeight: " + GetWindowHeight());
        //alert("OffsetHeight: " + obj.offsetHeight);
        //alert("Top: " + obj.style.top);
    }
}

function GetScrollTop() {
    return document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
    //return window.pageYOffset || document.documentElement.scrollTop || 0;
}

function GetScrollLeft() {
    return document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft;
    //return window.pageXOffset || document.documentElement.scrollLeft || 0;
}

function GetWindowWidth() {
  var myWidth = 0;
  var myHeight = 0;
  if (typeof(window.innerWidth) == 'number')
    myWidth = window.innerWidth;
  else if (document.documentElement && document.documentElement.clientWidth)
    myWidth = document.documentElement.clientWidth;
  else if (document.body && document.body.clientWidth)
    myWidth = document.body.clientWidth;
  return myWidth;
}

function GetWindowHeight() {
  var myHeight = 0;
  if (typeof(window.innerHeight) == 'number')
    myHeight = window.innerHeight;
  else if (document.documentElement && document.documentElement.clientHeight)
    myHeight = document.documentElement.clientHeight;
  else if (document.body && document.body.clientHeight)
    myHeight = document.body.clientHeight;
  return myHeight;
}

function GetRealLeft(el) {
    xPos = el.offsetLeft;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    }
    return xPos;
}

function GetRealTop(el) {
    yPos = el.offsetTop;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
    return yPos;
}

//used to get a querystring value in javascript
function querystring(name) {  // returns a named value from the querystring
   var tmp = ( location.search.substring(1) );
   var i   = tmp.toUpperCase().indexOf(name.toUpperCase()+"=");

   if ( i >= 0 )
   {
      tmp = tmp.substring( name.length+i+1 );
      i = tmp.indexOf("&");
      return unescape( tmp = tmp.substring( 0, (i>=0) ? i : tmp.length ));
   }

   return("");
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function HandleShowHide(obj, id) {
    var pnl = document.getElementByid(id);
    alert(obj.id);
}