function $(id)
{
  return document.getElementById(id);
}

function popup (file)
{
  var scrl = 'no';
  var ww = 390;
  var hh = 350;
  if (arguments.length > 1) ww = arguments[1];
  if (arguments.length > 2) hh = arguments[2];
  if (arguments.length > 3 && arguments[3] == 1) scrl = 'yes';

  var pname = 'wnd'+ww;
  var dati = 'width='+ww+',height='+hh+',menubar=no,toolbar=no,location=no,scrollbars='+scrl+',resizeable=no,'+center_window (ww,hh);
  var wnd = window.open(file, pname, dati);
  wnd.focus();
}

function center_window (w, h)
{
  var left = Math.round (screen.availWidth / 2) - Math.round (w / 2);
  var top = Math.round (screen.availHeight / 2) - Math.round (h / 2);
  return 'left='+left+',top='+top;
}

function showpic (pic, ww, hh)
{
  if(ww==''||hh=='') return;
  var rww=ww;var rhh=hh;var scr='no';
  var sww=screen.availWidth;var shh=screen.availHeight-30;
  var cww=Math.round(sww/2)-Math.round(ww/2); var chh=Math.round(shh/2)-Math.round(hh/2);
  if(ww>sww){cww=0;ww=sww;}if(hh>shh){chh=0;hh=shh;ww+=16;scr='yes';}if(ww>sww){ww -= 22;}
  var wnd=window.open('','','menubar=no,width='+ww+',height='+hh+',scrollbars='+scr+',resizeable=no,left='+cww+',top='+chh);
  wnd.document.open();
  var doc = wnd.document;
  doc.write('<html><head><title>Preview</title><head><body>');
  if (pic.substr (pic.length-4,4) != '.swf') doc.write('<img src="'+pic+'" border="0" width="'+rww+'" height="'+rhh+'" style="position:absolute;left:0px;top:0px">');
  else doc.write('<OBJECT style="position:absolute;left:0px;top:0px" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" WIDTH='+rww+' HEIGHT='+rhh+'><PARAM NAME=movie VALUE="'+pic+'"> <PARAM NAME=quality VALUE=high><PARAM NAME=menu VALUE=false><EMBED style="position:absolute;left:0px;top:0px" src="'+pic+'" quality=high bgcolor=#FFFFFF  WIDTH='+rww+' HEIGHT='+rhh+' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED></OBJECT>');
  doc.write('</body></html>');
  wnd.document.close();
  wnd.focus();
}

function go (f) { window.location = "#" + f; }

function _e(v)
{ return document.getElementById ? document.getElementById(v) : (document.all ? document.all[v] : 0);}

function dump(obj)
{
	var s = "";
	var cnt = 0;
  var once = true;
  for (key in obj)
	{
		cnt++;
		s += key + " -> " + obj[key] + "\n";
	  if (cnt > 25)
	  {
	   once = false;
     alert(s);
	   s = "";
	   cnt = 0;
	  }
	}
  
  if (once) { alert(s); }
}

var DocInit = new docLoader();

function docLoader() { }

docLoader.prototype.Init = function()
{
  this.DetectOS();
  this.DetectBrowser();
  this.HrefRemoveFocus();
  this.PNGFixLoader();
};

docLoader.prototype.DetectOS = function()
{
};

docLoader.prototype.DetectBrowser = function()
{
  this.userAgent = navigator.userAgent;
  this.isFirefox = this.userAgent.indexOf("Firefox/");
  this.isIE = this.userAgent.indexOf("MSIE");
  this.appVersion = navigator.appVersion;
  if (this.isFirefox != -1) { this.appVersion = this.userAgent.split("Firefox/"); }
  else if (this.isIE != -1) { this.appVersion = this.appVersion.split("MSIE"); }
  
  this.appVersion = parseFloat(this.appVersion[1]);
};

docLoader.prototype.HrefRemoveFocus = function()
{
  var col = document.getElementsByTagName("A");
  var cnt = col.length;
  for (i = 0; i < cnt; i++)
  {
    if (this.isFirefox != -1) { col[i].setAttribute("onfocus", "this.blur()"); }
    else if (this.isIE != -1) { col[i].onfocus = new Function ("return this.blur()"); }
  }
};

docLoader.prototype.PNGFixLoader = function()
{
  if (this.isIE != -1 && this.appVersion >= 5.5 && this.appVersion < 7 && document.body.filters)
  {
    var imgs = document.getElementsByTagName("IMG");
    for (key in imgs)
    {
      var o = imgs[key];
      if (typeof(o) == "object")
      {
        var imgSrc = imgs[key].src;
        if (imgSrc.substring(imgSrc.length - 3, imgSrc.length).toUpperCase() == "PNG")
        {
          imgs[key].src = "./img/pix.gif";
          imgs[key].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ imgSrc +"')";
        }
      }
    }
  }
};

function turn(id, mode)
{
  if(mode == 1) eval("setTimeout('turnon(" + id + "," + mode + ");', 0)");
  else eval("setTimeout('turnoff(" + id + "," + mode + ");', 0)");
}

function turnon(id)
{
  if(head[id])
  {
    cur = id;
    document.getElementById("menu" + id).style.display="block";
    var mmenu = document.getElementById("mmenu" + id);
    mmenu.style.cursor = "pointer";
    mmenu.className = 'smallBlue2Active';
  }
}

function turnoff(id)
{
  if(!menuAr[id])
  {
    document.getElementById("menu" + id).style.display="none";
    var mmenu = document.getElementById("mmenu" + id);
    mmenu.className = "smallBlue2";
  }
}

function newlayer (text, id, mode)
{
  var t = s = '';
  if (mode == 0) t = 'onmouseout="turn('+id+',0);menuAr['+id+']=0;";';
  s = '<div id="menu'+id+'" align="center" style="display:none; z-index:27;" onmouseover="menuAr['+id+']=1;" '+t+'>'+text+'</div>';
  document.write(s);
}

var ihttp = new InpapAjax();

function InpapAjax()
{
  this.reset = function()
  {
    this.url = '';
    this.params = {};
    this.method = 'GET';
    this.form = null;
    this.btn = null;
  };

  this.reset();
};

InpapAjax.prototype.sethttp = function()
{
  if(navigator.appName == 'Microsoft Internet Explorer')
  {
    this.obj = new ActiveXObject('Microsoft.XMLHTTP');
  }
  else
  {
    this.obj = new XMLHttpRequest();
  }
};

InpapAjax.prototype.param = function()
{
  var cnt = arguments.length;
  if (cnt==0 || cnt%2==1)
  {
    alert('InpapAjax error: Incorrect arguments count!');
    return;
  }
  this.params = {};
  for(i=0; i<arguments.length; i+=2) this.params[arguments[i]] = arguments[i + 1];
};

InpapAjax.prototype.send = function(f)
{
  var s='',l=0;
    for(k in this.params) s += k + '='+encodeURIComponent(this.params[k])+'&';
    l = s.length;
    s = s.substr(0, l - 1);

    this.sethttp();

    var copy = this;

    this.obj.onreadystatechange = function()
    {
    if (copy.obj.readyState == 4)
    {
      if (copy.obj.status == 200)
      {
        if (f) f();
      }
      else
      {
        alert('InpapAjax error: Loading failed!')
      }
    }
    };

    if (this.method.toUpperCase() == 'GET')
    {
    if (l) s = '?'+s;
    s = this.url+s;
    this.obj.open(this.method, s);
    this.obj.setRequestHeader('X_REQUESTED_WITH', 'XMLHttpRequest');
    this.obj.send(null);
    }
  else
  {
    this.obj.open(this.method, this.url);
    this.obj.setRequestHeader('X_REQUESTED_WITH', 'XMLHttpRequest');
    this.obj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    this.obj.send(s);
  }
};

InpapAjax.prototype.response = function()
{
  return this.obj.responseText;
};

InpapAjax.prototype.submitForm = function(form, func, btn)
{
  this.form = form;
  this.btn = btn;
  var c=form.length,e;

  for(i=0; i<c; i++)
  {
    e = form.elements[i];
    if(e.name=='') continue;

    if(e.type!='checkbox' && e.type!='radio')
    {
      this.params[e.name]=e.value;
    }
    else if(e.checked==true)
    {
      this.params[e.name]=e.value;
    }
  }

  this.method = form.method;
  this.url = form.action;

  this.send(func);
};
