<!--
/**********LEAVE**COPYRIGHT**INTACT*********************************************
Copyright (C) 2001 Dan Pupius (dan@pupius.net)
I have made most of this script from scratch, using a variety of sources for
ideas and code snippets.  Probably most influential is Thomas Brattli at
www.bratta.com.
 
Here is his original copyright statement that appears in his scripts:

Copyright (C) 1999 Thomas Brattli
This script is made by and copyrighted to Thomas Brattli at www.bratta.com
Visit for more great scripts. This may be used freely as long as this msg is intact!
I will also appriciate any links you could give me.
********************************************************************************/
  
  function BrowserObject(){		// BRATTA'S CHECK BROWSER CODE
    this.ver=navigator.appVersion;
    this.agent=navigator.userAgent;
    this.product=navigator.product;
    this.vendor=navigator.vendor;
    this.dom=document.getElementById?1:0;
    this.ie9=(this.ver.indexOf("MSIE 9")>-1 && this.dom)?1:0;
    this.ie8=(this.ver.indexOf("MSIE 8")>-1 && this.dom)?1:0;
    this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom)?1:0;
    this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0; 
    this.ie4=(document.all && !this.dom)?1:0;
    this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
    this.ns4=(document.layers && !this.dom)?1:0;
    this.mac=this.agent.indexOf("Mac")>-1;

    if(this.product) 
      this.r_kon=(this.product.indexOf("Konqueror")>-1 && this.vendor.indexOf("KDE")>-1)?1:0; 
    else 
      this.r_kon=0;
    this.r_lun=(this.agent.indexOf("Lunascape")>-1)?1:0; 
    this.r_apl=(this.agent.indexOf("AppleWebKit")>-1 && this.vendor.indexOf("Apple")>-1 && !this.r_lun)?1:0; 
    this.r_and=(this.agent.indexOf("Android")>-1 && this.agent.indexOf("AppleWebKit")>-1 && this.agent.indexOf("Safari")>-1 && this.agent.indexOf("Mozilla")>-1)?1:0;
    this.r_gcr=(this.agent.indexOf("Chrome")>-1 || this.agent.indexOf("Iron")>-1)?1:0; 
    this.r_KHTML=(this.r_kon || this.r_apl);
    this.r_op9=(window.opera && (this.agent.indexOf("Opera 9")>-1 || this.agent.indexOf("Opera/9")>-1) && !this.r_KHTML)?1:0;
    this.r_op7=(window.opera && (this.agent.indexOf("Opera 8")>-1 || this.agent.indexOf("Opera/8")>-1 || this.agent.indexOf("Opera 7")>-1 || this.agent.indexOf("Opera/7")>-1) && !this.r_KHTML)?1:0;
    this.r_opr=(this.agent.indexOf("Opera")>-1 && !this.r_op7 && !this.r_op9 && !this.r_KHTML)?1:0;
    this.r_cas=(this.r_op7 || this.r_op9 || this.r_opr || this.r_KHTML || this.r_lun || this.r_gcr || this.r_and);
    this.r_ie9=(this.ie9 && !this.r_cas)?1:0;
    this.r_ie8=(this.ie8 && !this.r_cas)?1:0;
    this.r_ie7=(this.ie7 && !this.r_cas)?1:0;
    this.r_ie6=(this.ie6 && !this.r_cas)?1:0;
    this.r_xp6=(this.agent.indexOf("NT 5.1")>-1 && this.ver.indexOf("NT 5.1")>-1 && (this.r_ie6 || this.r_ie7 || this.r_ie8))?1:0;
    this.r_ie5=(this.ie5 && !this.r_cas)?1:0; 
    this.r_ie4=(this.ie4 && !this.r_cas)?1:0;
    this.r_ie =(this.r_ie9 || this.r_ie8 || this.r_ie7 || this.r_ie6 || this.r_ie5)?1:0;
    this.r_moz=(this.ns5 && !document.all && this.agent.indexOf("Gecko")>-1 && this.vendor.indexOf("Netscape6")==-1 && !this.r_cas)?1:0;
    this.r_gp3=(this.r_moz && this.agent.indexOf("GranParadiso")>-1)?1:0;
    this.r_m16=(this.r_moz && (parseInt(navigator.productSub) >= 20040113))?1:0;
    this.r_ns6=(this.ns5 && !document.all && !this.r_moz && !this.r_cas)?1:0;
    this.r_ns5=(this.ns5 && !this.r_ns6 && !this.r_moz && !this.r_cas)?1:0;
    this.r_ns4=(this.ns4 && !this.r_cas)?1:0;

    this.ie=(this.ie4||this.ie5||this.ie6||this.ie7||this.ie8||this.ie9);
    this.nn=(this.ns4||this.ns5);
    this.bw=(this.ie||this.nn);
    return this
  }

  var browser = new BrowserObject();

  function PageObject(){		// BRATTA'S CODE TO CALCULATE PAGE SIZE
    this.x = 0;
    if(browser.nn) this.x2 = innerWidth;
    else this.x2 = document.body.offsetWidth-20;
    this.y=0;
    if(browser.nn) this.y2 = innerHeight;
    else this.y2 = document.body.offsetHeight-4;
    this.x50=this.x2/2;
    this.y50=this.y2/2;
    return this;
  }	


  var page = new PageObject(); 
  
  function MathObject() {		// My alternative math object - not much code yet
    function f_abs(x) {
      if(x < 0) x = x * -1;
      return x;
    }
    this.abs = f_abs;
    return this
  }
  
  MyMath = new MathObject();


  function DhtmlObject(el,objName, parentEl, parentParentEl) {	// MY DHTML OBJECT - USED FOR MOVING DIVS CROSSBROWSER should support ie4+, ns4+ including ns6
     

    function f_x() {
      if(!browser.ie) return parseInt(this.css.left);
      else return this.css.pixelLeft;
    }  
  
    function f_y() {
      if(!browser.ie) return parseInt(this.css.top);
      else return this.css.pixelTop;
    }
  
    function f_height() {
      if(browser.ie || browser.ns5) return this.obj.offsetHeight;
      else if(browser.nn) return this.css.height;
      else return parseInt(this.css.height);
    }

    function f_setHeight(h) {
      if(h<=0) this.css.height = 1;
      else  this.css.height = h;
    }

    function f_setWidth(w) {
      if(w<=0) this.css.width = 1;
      else  this.css.width = w;
    }

    function f_width() {
      if(browser.ie || browser.ns5) return this.obj.offsetWidth;
      else if(browser.nn) return this.css.width;
      else return parseInt(this.css.width);
    }
  
    function f_moveMe(x,y) {
      this.name;
      this.css.top = parseInt(y);
      this.css.left = parseInt(x);
    }
  
    function f_show() {
      this.css.visibility = "visible";
    }

    function f_hide() {
      this.css.visibility = "hidden";
    }
  
    function f_moveBy(x,y) {
      this.moveMe(this.x() + x, this.y() + y);
    }
  
    function f_moveToAux(xx,yy,speed,func) {
      if(this.cancelling) {
        this.cancelling = false;
        this.moving = false;
      } else {     
        var x = xx - this.x();
        var y = yy - this.y();
        if(!speed) speed = 5;
        if( (MyMath.abs(this.x()-xx) < speed) && (MyMath.abs(this.y()-yy) < speed) ) {  //Not at destination as x & y = 0
          this.moveMe(xx,yy);
          this.moving = false;
	  if(func != "") setTimeout(func,10);
     
        } else {  
    
          // Find modulus of vector
          var mod = Math.sqrt(x*x + y*y);
      
          //Get unit vector and multiply by speed
          var dx = Math.round(x / mod * speed);
          var dy = Math.round(y / mod * speed);

          //Move towards target
          this.moveBy(dx,dy);
      
          timeout = setTimeout(this.name + ".moveToAux(" + xx + "," + yy + "," + speed + ",'" + func + "');",20);      
        }
      }
    
    }
  
    function f_moveTo(xx,yy,speed,func) {
      if(!func) func = "";
      if(this.moving) { //Wait until last movement has finished before starting newone
        timeout = setTimeout(this.name + ".moveTo(" + xx + "," + yy + "," + speed + ",'" + func + "');",20);
    
      } else {
        //alert("Starting Movement To: (" + xx + "," + yy + ")");
        this.moving = true;
        this.moveToAux(xx,yy,speed,func);
      }
    }

    function f_moveToPlusAux(xx,yy,destspeed,curspeed,acc) {
      if(this.cancelling) {
        this.cancelling = false;
        this.moving = false;

      } else {
        var x = xx - this.x();
        var y = yy - this.y();
        if(!destspeed) destspeed = 5;
        if(!curspeed) curspeed = 0;
        if(!acc) acc = 1;
      
        if( (MyMath.abs(this.x()-xx) < curspeed) && (MyMath.abs(this.y()-yy) < curspeed) ) {  //Not at destination as x & y = 0

          this.moveMe(xx,yy);
          this.moving = false;
          //alert("Movement Ended: (" + objBomberman.x() + "," + objBomberman.y() + ")");
     
        } else {  
    
          // Find modulus of vector
          var mod = Math.sqrt(x*x + y*y);
        
          curspeed += acc;
          if(curspeed > destspeed) curspeed = destspeed;
        
          //Get unit vector and multiply by speed
          var dx = Math.round(x / mod * curspeed);
          var dy = Math.round(y / mod * curspeed);

          //Move towards target
          this.moveBy(dx,dy);
      
          timeout = setTimeout(this.name + ".moveToPlusAux(" + xx + "," + yy + "," + destspeed + "," + curspeed + "," + acc + ");",20);      
        }
      }
    
    }
  
    function f_moveToPlus(xx,yy,speed,acc) {
      if(this.moving) { //Wait until last movement has finished before starting newone
        timeout = setTimeout(this.name + ".moveToPlus(" + xx + "," + yy + "," + speed + "," + acc + ");",20);
    
      } else {
        //alert("Starting Movement To: (" + xx + "," + yy + ")");
        this.moving = true;
        this.moveToPlusAux(xx,yy,speed,0,acc);
      }
    }

    function f_cancelMove() {
      if(this.moving) this.cancelling = true;

    }
  
   
    //BEGIN CONSTRUCTION OF OBJECT 			
    //============================
   
    if(browser.dom) {
      //alert("DOM: Making Object: '" + el + "'");
      this.css = document.getElementById(el).style;
      this.obj = document.getElementById(el);
      
    } else if(browser.ie) {
      //alert("IE: Making Object: '" + el + "'");
      this.css = document.all[el].style;
      this.obj = document.all[el];
      
    } else if(browser.nn) {
      //alert("NN: Making Object: '" + el + "'");
      if(parentEl != null) {
	   //alert("Object needs parent");
          if(parentParentEl != null) {
	  	this.css = document.layers[parentEl].document.layers[parentParentEl].document.layers[el];
          	this.obj = document.layers[parentEl].document.layers[parentParentEl].document.layers[el];	  
	  } else {
	  	this.css = document.layers[parentEl].document.layers[el];
          	this.obj = document.layers[parentEl].document.layers[el];
	  }
      } else {
        //alert("Object doesn't need parent - " + el);
	     this.css = document.layers[el];
         this.obj = document.layers[el];
      }      
    }
    
    //Behaviour Functions
    this.moveMe = f_moveMe;
    this.moveBy = f_moveBy;
    this.moveTo = f_moveTo;
    this.moveToAux = f_moveToAux;
    this.moveToPlus = f_moveToPlus;
    this.moveToPlusAux = f_moveToPlusAux;
    this.show = f_show;
    this.hide = f_hide;
    this.cancelMove = f_cancelMove;
    this.setHeight = f_setHeight;
    this.setWidth = f_setWidth;

    //Retrieval Functions
    this.y = f_y;
    this.x = f_x;    
    this.height = f_height;
    this.width = f_width;
    this.startX = this.x()
    this.startY = this.y();
    
    //Variables:
    this.name = objName;
    this.moving = false;

    //used for drag objects
    this.drap = false;
    this.angle = 0;
    this.mousex = 0;
    this.mousey = 0;
    this.cancelling = 0;

    return this;
  }


  var oldwin = null;

  function popupWindow(filename, title, width, height, x, y,scrollbars,statusbar) {
	if(x=='c') x = (screen.width / 2) - (width / 2)
	if(y=='c') y = (screen.height / 2) - (height / 2)
		
	if(scrollbars == null) scrollbars='yes'
	if(statusbar == null) statusbar='no'
	
	
	NewWindow = window.open("", title, "status=no,scrollbars=no,width=1,height=1,left=1,top=1");
	NewWindow.close();

	NewWindow = window.open(filename, title, "status="+statusbar+",scrollbars="+scrollbars+",width="+width+",height="+height+",left="+x+",top="+y);
               
  	if(!NewWindow.opener) {
  		NewWindow.opener = self;
		oldwin = NewWindow;
  	}	
  	NewWindow.focus();
   }

  function isnumeric(value) {
  	var checkOK = "0123456789-,";
  	var allValid = true;
  	for (i=0; i<value.length; i++) {
   		ch = value.charAt(i);
   		for (j=0; j<checkOK.length; j++)
    		if (ch!=checkOK.charAt(j)) allValid = false;
	}
  }

//-->
