
function nothing() { };

function strip_px(s) {
  if (!s) { alert('STRIP_PX !s'); return 0; }
  if (s.substring(s.length-2)!='px') return s;
  return Number(s.substring(0,s.length-2));
  }

function event_x(e) {
  try { if (e.clientX) return e.clientX; } catch (a) {};
  try { if (e.screenX) return e.screenX; } catch (a) {};
  }

function event_y(e) {
  try { if (e.clientY) return e.clientY; } catch (a) {};
  try { if (e.screenY) return e.screenY; } catch (a) {};
  }

function event_ok(e,msg) {
  if (!e) {
    if (!window.event) { alert(msg); return false; }
    return window.event;
    }
  return e;
  }

var inie=navigator.appName=='Microsoft Internet Explorer'?true:false;

function event_but(e) {
  if (inie) { return(e.button); }
  else return(e.which);
  }

function add_class(obj,c) {
  if (obj.className.indexOf(' '+c)<0) {
    obj.className=obj.className+' '+c;
    return true;
    }
  return false;
  }

function del_class(obj,c) {
  var result=false;
  while (obj.className.indexOf(' '+c)>=0) {
    obj.className=obj.className.replace(' '+c,'');
    result=true;
    }
  return result;
  }

function view_get_dx() {
  var vx=(window.innerWidth)?window.innerWidth:
    ((document.all)?document.body.offsetWidth-3:null);
  return vx;
  }
function view_get_dy() {
  var vy=(window.innerHeight)?window.innerHeight:
    ((document.all)?document.body.offsetHeight-3:null);
  return vy;
  }

var timers=new Array();

timer=function(ms) {
  this.ms=ms?ms:100;
  this.count=0;
  this.active=false;
  this.loop=function() { };
  }
timer.prototype.start=function() {
  this.active=true;
  this.num=timers.length;
  timers.push(this);
  this.process();
  }
timer.prototype.stop=function() {
  this.active=false;
  for (var i=this.num; i<timers.count-1; i++) timers[i]=timers[i+1];
  timers.pop();
  }
timer.prototype.process=function() {
  this.loop();
  this.count+=this.ms;
  setTimeout('timers['+this.num+'].process()',this.ms);
  }

ajax=function() {
  this.clean();
  }

ajax.prototype.clean=function() {
  this.error=false;
  this.txt=false;
  this.xml=false;
  this.state=0;
  this.loading=false;
  this.done=nothing;
  this.onerror=nothing;
  this.async=true;
  }

ajax.prototype.progress=function(i) {
  };

ajax.prototype.process=function() {
  if (!this.loading) return;
  this.state=this.req.readyState;
  this.progress(this.state);
  if (this.state == 4) {
    if (this.req.status == 200) {
      this.txt=this.req.responseText;
      this.xml=this.req.responseXML;
      this.progress(0);
      this.done();
      }
    else {
//      alert('HTTP error: '+this.req.status+' '+this.req.statusText);
      this.error=this.req.status;
      this.progress(0);
      this.onerror();
      }
    this.loading=false;
    }
  }

ajax.prototype.sendget=function(url) {
  if (!url) { alert('AJAX.SENDGET: No url!'); return; }
  this.url=url;
  if (this.async) this.progress(0);
  if (window.XMLHttpRequest) {
    this.req = new XMLHttpRequest();
    }
  else if (window.ActiveXObject) {
    this.req = new ActiveXObject("Microsoft.XMLHTTP");
    if (!this.req)
      this.req = new ActiveXObject("Msxml2.XMLHTTP");
    if (!this.req) {
      alert('AJAX.SENDGET: Cannot send XMLHttpRequest!');
      this.error=true; return false;
      }
    }
  var here=this; this.req.onreadystatechange=function () { here.process(); }
  this.req.open('get',url,this.async);
  this.req.send(null);
  this.loading=true;
  if (!this.async) this.progress(0);
  return true;
  }

ajax.prototype.sendpost=function(id,url) {
  var f=document.getElementById(id);
  var a=new Array();
  for (var i=0; i<f.elements.length; i++) if (f.elements[i].name) {
    var s=encodeURIComponent(f.elements[i].name);
    s+="=";
    s+=encodeURIComponent(f.elements[i].value);
    a.push(s);
    }
  this.post=a.join("&");
  if (!url) { alert('AJAX.REQUEST: No url!'); return; }
  this.url=url;
  if (this.async) this.progress(0);
  if (window.XMLHttpRequest) {
    this.req = new XMLHttpRequest();
    }
  else if (window.ActiveXObject) {
    this.req = new ActiveXObject("Microsoft.XMLHTTP");
    if (!this.req)
      this.req = new ActiveXObject("Msxml2.XMLHTTP");
    if (!this.req) {
      alert('AJAX.SENDPOST: Cannot send XMLHttpRequest!');
      this.error=true; return false;
      }
    }
  var here=this; this.req.onreadystatechange=function () { here.process(); }
  this.req.open('post',url,this.async);
  this.req.setRequestHeader("Content-type","application/x-www-form-urlencoded, charset=utf-8");
  this.req.setRequestHeader("Content-length",this.post.length);
  this.req.setRequestHeader("Connection","close");
  this.req.send(this.post);
  this.loading=true;
  if (!this.async) this.progress(0);
  return true;
  }

ajax.prototype.request=function(url) {
  return this.sendget(url);
  }

function make_attr(a) {
  if (!a) a=new Array();
  var s='';
  for (var i=0; i<a.length; i++) {
    if (s!='') s=s+' ';
    if (!a[i][1]) s=s+a[i][0];
    else s=s+a[i][0]+'="'+a[i][1]+'"';
    }
  return s;
  }

function obj_setattr(o,a) {
  if (!o) { alert('OBJ_SETATTR: !o'); return; }
  if (!a) a=new Array();
  for (var i=0; i<a.length; i++) {
    if (!a[i][1]) o.setAttribute(a[i][0],'');
    else o.setAttribute(a[i][0],a[i][1]);
    }
  }

function create_obj(tag,a) {
  var o;
  if (!a) a=new Array();
  s='<'+tag+' '+make_attr(a)+'>';
  try { o=document.createElement(s); } catch (e) { }
  if (!o || o.nodeName!=tag.toUpperCase()) {
    o=document.createElement(tag);
    obj_setattr(o,a);
    }
  return o;
  }

function kill(el) { el.parentNode.removeChild(el); }

function flush(el) {
  if (el.hasChildNodes()) {
    while (el.childNodes.length>=1) el.removeChild(el.firstChild);
    }
  }

var tip=false;

var tip_width=400;

function tip_show(e,id,s) {
  if (tip) tip_hide();
  var st=document.documentElement.scrollTop;
  tip.borner=id;
  tip=create_obj('div',[['id','tooltip'],['class','tooltip']]);
  document.body.appendChild(tip);
  tip.innerHTML=s;
  tip.style.right=(view_get_dx()-event_x(e)+5)+'px';
  tip.style.top=(event_y(e)-tip.clientHeight+st)+'px';
  tip.style.display='block';
  tip.onmouseout=tip_hide;
  if (id) {
    document.getElementById(id).onmouseout=function(){};
    }
  return(false);
  }

function tip_hide() {
  if (!tip) return;
  document.body.removeChild(tip);
  tip=false;
  }

function show_hide(show,hide) {
  if (hide) document.getElementById(hide).style.display='none';
  if (show) document.getElementById(show).style.display='';
  }

var menu_now='';
var menu_stop=false;
function menu_on(id) {
  menu_now=id;
  menu_off();
  var m=document.getElementById(id);
  m.className='menu';
  m.style.zindex=100;
  return false;
  }
function menu_off() {
  if (menu_stop) return;
  var ms = document.getElementsByTagName('div');
  for (var i=0; i<ms.length; i++) {
    if ('menu'!=ms[i].className.substr(0,4)) { continue; }
    if (ms[i]==menu_now) continue;
    ms[i].className='menu_hidden';
    }
  return false;
  }


