//
// Copyright 2007, 2008 Zebek. All rights reserved.
//
// Duplication, reproduction or use of any kind without explicit written permission from
// Zebek is strictly prohibited.
//
//
//
function OpenPopup(path)
{
  window.open(path,'',"menubar=no,width=480,height=420,toolbar=0");
}

function showSimplePopup(url, xx, yy)
{
  var x = (xx) ? xx : 410;
  var y = (yy) ? yy : 420;
  
  sm('waitDiv',x, y, 0, 0, true);
  loaddetailsdata(url,'divcontents');

  return;
}
   
function showpopup(url, detail_url, objTid)
{
  var objTid = (objTid == null) ? 'waitDiv' : objTid;

  if (detail_url != "")
  {
    document.getElementById("lnkDetail").style.display = "block";
    document.getElementById("lnkDetail").href =	
      "javascript:sm('" + objTid + "',700,700,0,0,true);loaddetailsdata('"+detail_url+"','divcontents');";
  }
  else
  {
    document.getElementById("lnkDetail").style.display = "none";
  }
	
  var objTarget = document.getElementById(objTid);
  var top = 150;
  var left =400;

  if (url.indexOf('?') > 0)
    url+="&guid="+Math.random() * 9999999999999.999999999999999;
  else
    url+="?guid="+Math.random() * 9999999999999.999999999999999;

  hm();
  sm(objTid,180,180,top,left,false);
  loaddata(url,'divcontents');
	
  return false;
}

function loaddetailsdata(url,target)
{
  loaddata(url,target);
  document.getElementById("lnkDetail").style.display = "none";
}

function loaddata(url, target)
{
  document.getElementById(target).innerHTML = 'Fetching Data ......';
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() {callback(url, target);};
    req.open("GET", url, true);
    req.send("");
  }
}

function callback(url, target)
{
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
    } else {
      document.getElementById(target).innerHTML=" AHAH Error:\n"+ req.status + "\n" +req.statusText;
    }
  }
}

function getAbsoluteLeft(objectId)
{
  // Get an object left position from the upper left viewport corner
  o = document.getElementById(objectId);
  oLeft = o.offsetLeft;            // Get left position from the parent object
  while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
    oParent = o.offsetParent;    // Get parent object reference
    oLeft += oParent.offsetLeft; // Add parent left position
    o = oParent;
  }
  return oLeft;
}

function getAbsoluteTop(objectId) 
{
  // Get an object top position from the upper left viewport corner
  o = document.getElementById(objectId);
  oTop = o.offsetTop;            // Get top position from the parent object
  while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
    oParent = o.offsetParent;  // Get parent object reference
    oTop += oParent.offsetTop; // Add parent top position
    o = oParent;
  }
  return oTop;
}

function pageWidth()
{
  return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;
}
function pageHeight() {
  return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;
}
function posLeft() {
  return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;
}
function posTop() {
  return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;
}
function $(x){
  return document.getElementById(x);
}
function scrollFix(){
  var obol=$('ol');
  //obol.style.top=posTop()+'px';
  //obol.style.left=posLeft()+'px';
  obol.style.top = '0px';
  obol.style.left = '0px';	
}
function sizeFix(){
  var obol=$('ol');
  //obol.style.height=pageHeight()+'px';
  obol.style.height = '853px';
  obol.style.width=pageWidth()+'px';
}
function kp(e){
  ky=e?e.which:event.keyCode;
  if(ky==88||ky==120)hm();
  return false;
}
function inf(h){
  tag=document.getElementsByTagName('select');
  for(i=tag.length-1;i>=0;i--)
    tag[i].style.visibility=h;
  tag=document.getElementsByTagName('iframe');
  for(i=tag.length-1;i>=0;i--)
    tag[i].style.visibility=h;
  tag=document.getElementsByTagName('object');

  for(i=tag.length-1;i>=0;i--)
    tag[i].style.visibility=h;
}
function sm(obl, wd, ht,top,left,center)
{
  var h='hidden';
  var b='block';
  var p='px';
  var obol=$('ol');
  var obbxd = $('mbd');
  $('mbd').innerHTML = $(obl).innerHTML;
  //obol.style.height=ht+p;
  obol.style.height = '853px';
  //obol.style.left=left+p;
  obol.style.left = '0px';
  obol.style.width=pageWidth()+p;
  /*obol.style.top=posTop()+p;
    obol.style.left=posLeft()+p;*/
  //obol.style.top=top+p;
  obol.style.top = '0px';
  obol.style.display=b;
  var tp,lt;	
  if (center)
  {
    tp = posTop()+((pageHeight()-ht)/2)-12;
    lt = posLeft()+((pageWidth()-wd)/2)-12;
  }
  else
  {
    tp = top;
    lt = left;
  }
  var obbx=$('mbox');
  obbx.style.top=(tp<0?0:tp)+p;
  obbx.style.left=(lt<0?0:lt)+p;
  obbx.style.width=wd+p;
  obbx.style.height=ht+p;
  inf(h);
  obbx.style.display=b;
  return false;
}
function hm()
{
  try{
    var v='visible';
    var n='none';
    $('ol').style.display=n;
    $('mbox').style.display=n;
    inf(v);
    document.onkeypress='';
  }
  catch(e){}
}
function initmb()
{
  var ab='absolute';
  var n='none';
  var obody=document.getElementsByTagName('body')[0];
  var frag=document.createDocumentFragment();
  var obol=document.createElement('div');
  obol.setAttribute('id','ol');
  obol.style.display=n;
  obol.style.position=ab;
  obol.style.top=0;
  obol.style.left=0;
  obol.style.zIndex=998;
  obol.style.width='100%';
  frag.appendChild(obol);
  var obbx=document.createElement('div');
  obbx.setAttribute('id','mbox');
  obbx.style.display=n;
  obbx.style.position=ab;
  obbx.style.zIndex=999;
  var obl=document.createElement('span');
  obbx.appendChild(obl);
  var obbxd=document.createElement('div');
  obbxd.setAttribute('id','mbd');
  obl.appendChild(obbxd);
  frag.insertBefore(obbx,obol.nextSibling);
  obody.insertBefore(frag,obody.firstChild);
}

function registration_mb(xx, yy)
{
  alert ("what?");
  var x = (xx) ? xx : 410;
  var y = (yy) ? yy : 420;

  sm('waitDiv', x, y, 0, 0, true);
  loaddetailsdata('/register_form.php', 'divcontents');
  return true;
}

