
/*************************************************
* Produced by #colcode, www.colcode.com
* (c)2009 Colcode
 ************************************************/

IEX = (navigator.appVersion.indexOf('MSIE') > 0)? 1 : 0;
NS4 = (document.layers)? 1 : 0;
BV5 = (document.getElementById)? 1: 0; // browser version 5, gecko, opera, etc
IE7 = (navigator.appVersion.indexOf('MSIE 7') > 0)? 1 : 0;
IE5 = (IEX && BV5)? 1 : 0;  // IE5 and IE6
IE4 = (IEX && !BV5)? 1 : 0;

MOUSE_LEFT   = 1;

KEYB_BACKSPC = 8;
KEYB_TAB     = 9;
KEYB_RETURN  = 13;
KEYB_ENTER   = KEYB_RETURN;

KEYB_SHIFT   = 16;
KEYB_CTRL    = 17;
KEYB_ALT     = 18;
KEYB_BRK     = 19;
KEYB_CAPS    = 20;

KEYB_ESC     = 27;

KEYB_SPACE   = 32;
KEYB_SPC     = KEYB_SPACE;
KEYB_PGUP    = 33;
KEYB_PGDN    = 34;
KEYB_END     = 35;
KEYB_HO_me    = 36;
KEYB_LEFT    = 37;
KEYB_UP      = 38;
KEYB_RIGHT   = 39;
KEYB_DOWN    = 40;

KEYB_INS     = 45;
KEYB_DEL     = 46;

KEYB_LOGO    = 91;
KEYB_WIN     = 91;

KEYB_F1      = 112;
KEYB_F2      = 113;
KEYB_F3      = 114;
KEYB_F4      = 115;
KEYB_F5      = 116;
KEYB_F6      = 117;
KEYB_F7      = 118;
KEYB_F8      = 119;
KEYB_F9      = 120;
KEYB_F10     = 121;
KEYB_F11     = 122;
KEYB_F12     = 123;

KEYB_SCROLL  = 145;
KEYB_SCRLK   = KEYB_SCROLL;
KEYB_SCRLOCK = KEYB_SCROLL;

var _pdim;  // dim layer
var _pwin;  // popup window
var _ptop;  // popup window list
var _pttl;  // popup window title
var _pfrm;  // popup content, iframe
var _dwin;  // dialog window
var _dtop;  // dialog window list
var _dttl;  // dialog window title
var _dtxt;  // dialog content
var _drag;  // active drag object

var _mx   = 0; // mouse X
var _my   = 0; // mouse Y
var _sx   = 0; // scroll X
var _sy   = 0; // scroll Y
var _winW = 0;
var _winH = 0;

var _init = 0;

window.onload = pageInit;

function testPopup()
{
   var msg;
   msg  = 'Din webbläsare skall nu öppna ett sk. \'popup\' fönster\n';
   msg += 'Om så inte sker så har du troligtvis någon form av popup\n';
   msg += 'blockerare som hindrar detta. Eventuellt måste du ställa\n';
   msg += 'in din webbläsare att tillåta popup på Live it hemsida.\n\n';
   
   msg += 'Klicka på OK för att testa popup.';
   
   alert(msg);
   
   popupOpen('/popup/om_popups.php', 'Om popup', 370, 500);
}

function pageInit()
{
   if(!_init)
   {
      _init = 1;

      _drag = 0;
      if(!(_pdim = document.getElementById('popdim'))) return;
      
      if(!(_pwin = document.getElementById('popwin'))) return;
      if(!(_ptop = document.getElementById('poptop'))) return;
      if(!(_pttl = document.getElementById('popttl'))) return;
      if(!(_pfrm = document.getElementById('popfrm'))) return;

      if(!(_dwin = document.getElementById('dlgwin'))) return;
      if(!(_dtop = document.getElementById('dlgtop'))) return;
      if(!(_dttl = document.getElementById('dlgttl'))) return;
      if(!(_dtxt = document.getElementById('dlgtxt'))) return;
      
      _dtop.onmousedown = drag_init;
      _ptop.onmousedown = drag_init;
      
      document.onmousemove = captureMouse;
      document.body.onresize = pageInit;
      _init = 1;
      
      if(document.getElementById('out'))
      {
         out_elem = document.getElementById('out');
         out_text  = out_elem.innerHTML;
         out_class = out_elem.className;
      }
   }
   
   _winW = (IEX)? document.body.offsetWidth : window.innerWidth;
   
   if(window.innerHeight)
      _winH = window.innerHeight;
   else if(document.documentElement && document.documentElement.clientHeight)
      _winH = document.documentElement.clientHeight;
   else if(document.body && document.body.clientHeight)
      _winH = document.body.clientHeight;
   else
      _winH = 850;      
}

function dragObject(obj, tgt)
{
   this.obj    = obj;
   this.tgt    = tgt;
   this.origX  = parseInt(obj.style.left);
   this.origY  = parseInt(obj.style.top);
   this.evtX   = _mx;
   this.evtY   = _my;
   this.curX   = this.origX;
   this.curY   = this.origY;
   this.active = true;
   
   this.tgt.style.cursor = 'move';
   
   this.drag = function()
   {
      if(this.active)
      {
         this.curX = (_mx + this.origX - this.evtX);
         this.curY = (_my + this.origY - this.evtY);
         this.obj.style.top  = this.curY +'px';
         this.obj.style.left = this.curX +'px';
         
         window.status = 'cX:'+ this.curX +', cY:'+ this.curY +', eX:'+ this.evtX +', eY:'+ this.evtY +', oX:'+ this.origX +', oY:'+ this.origY;
      }
   };
   
   this.obj.onmouseup = function()
   {
      if(_drag)
      {
         _drag.active = 0;
         _drag.tgt.style.cursor = 'default';
         _drag = null;
      }
   };
}

function drag_init(evt)
{
   if(typeof evt == 'undefined' || !evt) var evt = window.event;
   
   if(evt.target)
      var tgt = evt.target;
   else if(evt.srcElement)
      var tgt = evt.srcElement;
   else
      return true;
   
   if(tgt.className.indexOf('drag') == -1) return true;
   
   _drag = new dragObject(tgt.parentNode, tgt);
   
   return false;
}

function captureMouse(evt)
{
   var mode;
   
   if(typeof evt == 'undefined' || !evt) var evt = window.event;
   
   if(document.body && evt.clientX && evt.clientY)
   {
      mode = 1;
      _mx = evt.clientX;
      _my = evt.clientY;
      _sx = (IEX)? document.documentElement.scrollLeft : (evt.pageX - _mx);
      _sy = (IEX)? document.documentElement.scrollTop  : (evt.pageY - _my);
   }
   else if(evt.pageX || evt.pageY)
   {
      mode = 2;
      _sx = (document.documentElement.scrollLeft)? document.documentElement.scrollLeft : 0;
      _sy = (document.documentElement.scrollTop)? document.documentElement.scrollTop : 0;
      _mx = evt.pageX - _sx;
      _my = evt.pageY - _sy;
   }
   else
   {
      mode = 0;
      _sx = 0;
      _sx = 0;
      _mx = 275;
      _my = 150;
   }
   
   if(_drag) _drag.drag();
   
   //window.status = 'mode1: '+ mode +', '+ _mx + ', mouseY: ' + _my + ' winW: ' + _winW + ', winH: ' + _winH +', scrollX:'+ _sx +', scrollY:'+ _sy;
}

function dialogOpen(txt, tl, sx, sy, px, py)
{
   if(typeof tl == 'undefined' || !tl) tl = 'Dialog';
   if(typeof sx == 'undefined' || !sx || sx == 'auto') sx = 300;
   if(typeof sy == 'undefined' || !sy || sy == 'auto') sy = 0;
   if(typeof px == 'undefined' || !px) px = parseInt(_mx - sx + _sx);
   if(typeof py == 'undefined' || !py) py = parseInt(_my - sy + _sy);
   
   if(px == 'c' || px == 'auto') px = parseInt((_winW - sx) / 2) + _sx;
   if(py == 'c' || py == 'auto') py = parseInt(_my - (sy / 2)) + _sy;
   
   if(py < 10) py = 10;
   if(px < 10) px = 10;
   
   //if(!confirm('_winW'+_winW+', _winH'+_winH+' sx:'+sx+', sy:'+sy+', px:'+px+', py:'+py+', _mx:'+_mx+', _my:'+_my+', _sx:'+_sx+', _sy:'+_sy)) return;
   
   _dwin.style.left = px + 'px';
   _dwin.style.top = py + 'px';
   _dwin.style.width = sx + 'px';
   _dwin.style.height = (sy)? sy + 'px' : 'auto';
   _dtxt.innerHTML = txt;
   _dttl.innerHTML = tl;
   _pdim.style.display = 'block';
   _dwin.style.display = 'block';
}

function dialogClose()
{
   _dtxt.innerHTML = '';
   _dttl.innerHTML = '';
   _dwin.style.display = 'none';
   _pdim.style.display = 'none';
}

function popupClose(uri)
{
   _pdim = document.getElementById('popdim');
   _pwin = document.getElementById('popwin');
   _pfrm = document.getElementById('popfrm');
   
   _pwin.style.display = 'none';
   _pdim.style.display = 'none';
   _pfrm.src = '/js/empty.html';
   
   if(typeof uri != 'undefined') location = uri;
}

function popupOpen(uri, title, sx, sy)
{
   var px, py;
      
   sx = (typeof sx == 'undefined')? 450 : parseInt(sx);
   sy = (typeof sy == 'undefined')? 500 : parseInt(sy);
   
   if(sx < 250) sx = 250;
   if(sy < 200) sy = 200;
   if(sx > (_winW - 20)) sx = _winW - 20;
   if(sy > (_winH - 50)) sy = _winH - 50;
   
   px = parseInt((_winW - sx) / 2) + _sx;
   py = parseInt((_winH - sy) / 2) + _sy;
   if(py < 10) py = 10;
   if(px < 10) px = 10;
   
   _pfrm.style.height = sy + 'px';
   _pfrm.style.width  = sx + 'px';
   
   sy += 40; // add the space needed by top and bot
   
   _pwin.style.height = sy + 'px';
   _pwin.style.width  = sx + 'px'; 
   _pwin.style.top    = py + 'px';
   _pwin.style.left   = px + 'px';
   _pttl.innerHTML = title;
   
   //if(!confirm('_winW'+_winW+', _winH'+_winH+' sx:'+sx+', sy:'+sy+', px:'+px+', py:'+py+', _mx:'+_mx+', _my:'+_my+', _sx:'+_sx+', _sy:'+_sy)) return;
   _pfrm.src = uri;
   _pdim.style.display = 'block';
   _pwin.style.display = 'block';
}

/* not truncated */

