
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.offsetY) return e.offsetY; } 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;
  }

function absolute_x() {
  var canvas=document.getElementsByTagName(document.compatMode && document.compatMode=="CSS1Compat"?"HTML":"BODY")[0];

  }

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.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.done();
      }
    else {
//      alert('HTTP error: '+this.req.status+' '+this.req.statusText);
      this.error=this.req.status;
      this.onerror();
      }
    this.loading=false;
    }
  }

ajax.prototype.request=function(url,async) {
  if (!async) async=true;
  if (!url) { alert('AJAX.REQUEST: No url!'); return; }
  this.url=url;
  if (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.REQUEST: Cannot send XMLHttpRequest!');
      this.error=true; return false;
      }
    }
  var here=this;
  this.req.onreadystatechange = function () { here.process(); }
  this.req.open("get", url, async);
  this.loading=true;
  this.req.send(null);
  if (!async) this.progress(0);
  return this.req;
  }

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;
  }
