function OpenImg(url, width, height) {
  wo(url, '', width, height);
}

function ShowImgWindow(name, url, width, height) {
  wo(url, '', width, height);
}

function wo(src, hide, width, height) {
  var page_size = getPageSize();
  if( hide && typeof(hide) != 'string' ) {
    width  = hide;
    height = width;
  }
  var page_scroll = getPageScroll();
  var posY = page_scroll[1] + ((page_size[3] - height) / 2);
  var posX = (page_size[0] - width) / 2;
  var div = document.getElementById('imageshow');
  if( div.style.display == '' ) {}
  div.style.display ='';
  div.style.left = posX + 'px';
  div.style.top  = posY + 'px';
  var img = document.getElementById('imagesshowcont');
  img.src = src;
  img.setAttribute('width', width);
  img.setAttribute('height', height);
  img.style.border = '10px solid #DFDFDF';
  //div.appendChild(img);
}

function hideImg() {
  var div = document.getElementById('imageshow');
  div.style.display ='none';
  document.getElementById('imagesshowcont').src='';
//  while(div.childNodes.length>0) {
//    div.removeChild(div.firstChild);
//  }  
} 
 
function getMouseX( e ) {
  return e.pageX || ( e.clientX + ( document.documentElement.scrollLeft || document.body.scrollLeft ) );
}
     
function getMouseY( e ) {
  return e.pageY || ( e.clientY + ( document.documentElement.scrollTop || document.body.scrollTop ) );
}

function show_object(src, width, height, event) {
   var div = document.getElementById('image_show_preview');
   if( div.style.display == 'none' ) {
     div.style.display = '';
     div.style.width = width+'px';
     div.style.height = height+'px';
     var e = event || window.event;
     div.style.top = getMouseY(e)+10+'px';
     div.style.left = getMouseX(e)+10+'px';
     var img = document.createElement('img');
     img.setAttribute('src', src);
     img.style.border = '4px solid #DFDFDF';
     div.appendChild(img);
   }
}

function hide_object() {
  var div = document.getElementById('image_show_preview');
  div.style.display = 'none';
  while(div.childNodes.length>0) {
    div.removeChild(div.firstChild);
  }
}

function getElementPosition(elemid) {
  var offsetTrail = elemid;
  var offsetLeft  = 0;
  var offsetTop   = 0;
  while(offsetTrail) {
    offsetLeft += offsetTrail.offsetLeft;
    offsetTop  += offsetTrail.offsetTop ;
    offsetTrail = offsetTrail.offsetParent;
  }
  if( navigator.userAgent.indexOf("Mac") != -1 &&
      typeof(document.body.leftMargin) != 'undefined' ) {
    offsetLeft += document.body.leftMargin;
    offsetTop  += document.body.topMargin;
  }
  return {left:offsetLeft, top:offsetTop};
}

function ShowImagePreview(src, width, height, elem) {
  var imgpreview = document.getElementById('imgpreview');
  var position  = getElementPosition(elem);
  imgpreview.style.display = '';
  if( typeof(preloadBar) == 'undefined' ) {
    preloadBar = new Image();
    preloadBar.src = '/img/load.gif';
  }
  var img = document.getElementById('imgpreviewimg');
  var previmg = document.getElementById('rightdoor');
  previmg.style.display = 'none';
  img.src = src;
}

function HideDiv() {
  var imgpreview = document.getElementById('imgpreview');
  imgpreview.style.display = 'none';
  var img = document.getElementById('imgpreviewimg');
  img.src  = '/img/load.gif';
  var previmg = document.getElementById('rightdoor');
  previmg.style.display = '';
}

function getScreenSize() {
  if( typeof( window.innerWidth ) == 'number' ) {
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return {'width': myWidth, 'height': myHeight};
}

function getPageSize(){
  
  var xScroll, yScroll;
  
  if (window.innerHeight && window.scrollMaxY) {  
    xScroll = document.body.scrollWidth;
    yScroll = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ 
    xScroll = document.body.scrollWidth;
    yScroll = document.body.scrollHeight;
  } else { 
    xScroll = document.body.offsetWidth;
    yScroll = document.body.offsetHeight;
  }
  
  var windowWidth, windowHeight;
  if (self.innerHeight) {  
    windowWidth = self.innerWidth;
    windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { 
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  } else if (document.body) { 
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }  
  
  if(yScroll < windowHeight){
    pageHeight = windowHeight;
  } else { 
    pageHeight = yScroll;
  }

  if(xScroll < windowWidth){  
    pageWidth = windowWidth;
  } else {
    pageWidth = xScroll;
  }

  arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
  return arrayPageSize;
}

function getPageScroll(){

  var yScroll;

  if (self.pageYOffset) {
    yScroll = self.pageYOffset;
  } else if (document.documentElement && document.documentElement.scrollTop){   
    yScroll = document.documentElement.scrollTop;
  } else if (document.body) {
    yScroll = document.body.scrollTop;
  }

  arrayPageScroll = new Array('',yScroll) 
  return arrayPageScroll;
}

function addEvent(elem, evtType, func, capture) {
   capture = (capture) ? capture : false;
   if (elem.addEventListener) {
      elem.addEventListener(evtType, func, capture);
   } else if (elem.attachEvent) {
      elem.attachEvent("on" + evtType, func);
   } else {
      elem["on" + evtType] = func;
   }
}

function removeEvent(elem, evtType, func, capture) {
   capture = (capture) ? capture : false;
   if (elem.removeEventListener) {
      elem.removeEventListener(evtType, func, capture);
   } else if (elem.attachEvent) {
      elem.detachEvent("on" + evtType, func);
   } else {
      elem["on" + evtType] = null;
   }
}