
String.prototype.trim = function() {
  return this.replace(/^\s+|\s+$/g, "");
};

function GetXmlHttpObject() {
  var xmlHttp=null;
  try {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  } catch (e) {
    // Internet Explorer
    try {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}

function GetWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
    
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
    
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return { width:myWidth, height:myHeight };
}

function GetScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
    
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
    
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return { x:scrOfX, y:scrOfY };
}

function ShowLightBox(url, w, h) {
  var windowSize = GetWindowSize();
  var scrollXY   = GetScrollXY();
  var width  = windowSize.width + scrollXY.x;
  var height = windowSize.height + scrollXY.y;

  var isIE = (navigator.userAgent.indexOf("MSIE") > -1);
  
  var layer = document.createElement("div");
  layer.style.zIndex = 2;
  layer.id = "lightbox_layer";
  layer.style.position = (isIE)? "absolute" : "fixed";
  layer.style.left = "0px";
  layer.style.top  = "0px";
  layer.style.width  = width + "px";
  layer.style.height = height + "px";
  layer.style.backgroundColor = "black";
  layer.style.opacity = "0.6";
  layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=60)");
  document.body.appendChild(layer);
  
  layer.onclick = function() {
    document.body.removeChild(document.getElementById("lightbox_box"));
    document.body.removeChild(document.getElementById("lightbox_layer"));
  };

  var x = 100;
  var y = 50;
  if(w>0) x = (windowSize.width - w) / 2;
  if(h>0) y = (windowSize.height - h) / 2;
  if(w<=0) w = windowSize.width - 130;
  if(h<=0) h = windowSize.height - 80;
  
  var box = document.createElement("div");
  box.style.zIndex = 3;
  box.id = "lightbox_box";
  box.style.position = (isIE)? "absolute" : "fixed";
  box.style.left = (isIE)? (scrollXY.x + x) + "px" : x + "px";
  box.style.top  = (isIE)? (scrollXY.y + y) + "px" : y + "px";
  box.style.backgroundColor = "white";
  box.style.border = "2px solid #aaaaaa";
  document.body.appendChild(box);
  
  var iframe = document.createElement("iframe");
  iframe.style.width  = w + "px";
  iframe.style.height = h + "px";
  iframe.style.border = "0";
  box.appendChild(iframe);

  iframe.src = url;
}

function HideLightBox() {
  document.body.removeChild(document.getElementById("lightbox_box"));
  document.body.removeChild(document.getElementById("lightbox_layer"));
}

function Test() {
  alert('Test');
}
