Page = function () {};

Page.showPicture = function (imgNode, src, w, h, title) 
{
   var ImgDiv = document.getElementById('page-orig-image');
   
   if (ImgDiv) {
      if (ImgDiv.parentNode) {
         ImgDiv.parentNode.removeChild(ImgDiv);
      };
      var TitleDiv = ImgDiv.getElementsByTagName('div')[0];
      var Img = ImgDiv.getElementsByTagName('img')[0];
   } else {
      ImgDiv = document.createElement('div');
      ImgDiv.id = 'page-orig-image';
      ImgDiv.style.position = 'fixed';
      if (document.all && !window.Opera) {
         ImgDiv.style.position = 'absolute';
      };
      
      ImgDiv.style.left = '0';
      ImgDiv.style.textAlign = 'center';
      ImgDiv.style.width = '100%';
      
      TitleDiv = document.createElement('div');
      
      ImgDiv.onclick = function () {this.parentNode.removeChild(this)};
      
      var Img = document.createElement('img');
      ImgDiv.appendChild(TitleDiv);
      ImgDiv.appendChild(Img);
   };
   
   var vp = Page.getViewport();
   
   Img.src = '';
   Img.src = src;
   
   var pomerX = w/(vp.x-4);
   var pomerY = h/(vp.y-4-20);
   
   if (pomerX>1 || pomerY>1) {
      var pomerMax = pomerX > pomerY ? pomerX : pomerY;
      w = Math.round(w/pomerMax);
      h = Math.round(h/pomerMax);
   };
   Img.width = w;
   Img.height = h;
   
   ImgDiv.style.top = ((vp.y/2)-(h/2)-2)+'px';
   Img.style.backgroundColor = 'white';
   
   Img.style.border = '2px solid black';
   
   if (!title) title = '';
   TitleDiv.innerHTML = title;
   
   document.body.appendChild(ImgDiv);
};

Page.getViewport = function () {
   var x,y;
   if (self.innerHeight) {
   	x = self.innerWidth;
   	y = self.innerHeight;
   } else if (document.documentElement && document.documentElement.clientHeight) {
   	x = document.documentElement.clientWidth;
   	y = document.documentElement.clientHeight;
   } else if (document.body) {
   	x = document.body.clientWidth;
   	y = document.body.clientHeight;
   };
   return {'x' : x, 'y' : y};
};

Page.sDefense = function ($fEl) {
   var $fc = document.createElement('input');
   $fc.type = 'hidden';
   $fc.name = 'defense';
   $fc.value = '1';
   $fEl.appendChild($fc);
};

/**
     * gets reference to textarea element of wysiwyg
   */
Page.getWswRef = function(id_iframe) {
   try {
   //NORMAL browsery
      var wswRef = document.getElementById(id_iframe).contentWindow.document.getElementById('content');
   } catch (e) {
   //IE...
      var wswRef = document.frames(id_iframe).document.getElementById('content');
   }
   
   return wswRef;
};
