var m_strBrowser = "";

function SetBrowser() {
 
 
 /////////////////////////////////////////////////////////////////
 //  first check for browser 
 /////////////////////////////////////////////////////////////////

 	if (navigator.family == 'nn4') {
	     m_strBrowser = "nn4";
 	}

	if (navigator.family == 'ie4' && navigator.version >=4 && navigator.version < 5) {
	     m_strBrowser = "ie4";
	}

	if (document.getElementById) {
	    m_strBrowser = "standard";
	     
	}
	
 }
 
 
 SetBrowser();

 //
 /////////////////////////////////////////////////////////////////
 //  misc. functions 
 /////////////////////////////////////////////////////////////////
 //

 function abs(a) {
    if (a < 0) return -a; 
    else return a;
 }


function GetWinWidth()
{
	
   if (m_strBrowser == 'nn4') {
		return window.innerWidth
    }
    else if (m_strBrowser == 'ie4') {
        return document.body.offsetWidth;
    }
    else if (m_strBrowser == 'standard') {
		if (document.body.offsetWidth ==0) return window.innerWidth;
        else                               return document.body.offsetWidth;
    }
	else return 0;
}
 //
 /////////////////////////////////////////////////////////////////
 //  box class 
 /////////////////////////////////////////////////////////////////
 //

 function box(id, left, top, width, height) {
 // 
 // properties
 //
    this.left = left;
    this.top = top;
    this.width = width;
    this.height = height;
    this.id     = id;
 // 
 // methods
 //
    this.show = boxshow;
    this.hide = boxhide;
    this.moveto = boxmoveto;   
    this.resize = boxresize;
    this.clip = boxclip;
    this.settextsize = boxsettextsize;
    
    this.getwidth  = boxgetwidth;
    this.getheight = boxgetheight;
    this.getleft   = boxgetleft;
    this.gettop    = boxgettop;
    
    //alert(m_strBrowser);
    this.resize(width,height);
    this.moveto(left,top);
    
 }
 
 function boxsettextsize(size) {
    if (m_strBrowser == 'nn4') {
       myBox=document.layers[this.id];
	   myBox.fontSize=size;	 
    }
    else if (m_strBrowser == 'ie4') {
       myBox=this.id;
	   myBox.style.fontSize=size; 
    }
    else if (m_strBrowser == 'standard') {
   	   myBox = document.getElementById(this.id);
	   myBox.style.fontSize=size;
    }
 }
 
 function boxclip(left,top,bottom,right) {
    if (m_strBrowser == 'nn4') {

          myBox=document.layers[this.id];
          myBox.clip.bottom = bottom;
   	      myBox.clip.left = left;
	      myBox.clip.right = right;
	      myBox.clip.top = top;
       }
       else if (m_strBrowser == 'ie4') {
          myBox=this.id; 
          myBox.style.clip = "rect(" + top + "px " + right + "px " + bottom + "px " + left + "px)";
       }
       else if (m_strBrowser == 'standard') {
       	  myBox = document.getElementById(this.id);
      	  myBox.style.clip = "rect(" + top + "px " + right + "px " + bottom + "px " + left + "px)";
       }
 }
 
 
 function boxgetwidth() {
    if (m_strBrowser == 'nn4') {
         myBox=document.layers[this.id];
		 return myBox.width;	 
      }
      else if (m_strBrowser == 'ie4') {
         myBox=this.id;
		 return myBox.style.width; 
      }
      else if (m_strBrowser == 'standard') {
     	 myBox = document.getElementById(this.id);
		 return myBox.style.width;
      }
 }

 function boxgetheight() {
    if (m_strBrowser == 'nn4') {
         myBox=document.layers[this.id];
		 return myBox.height;	 
      }
      else if (m_strBrowser == 'ie4') {
         myBox=this.id; 
		 return myBox.style.height;
      }
      else if (m_strBrowser == 'standard') {
     	myBox = document.getElementById(this.id);
		return myBox.style.height;
      }
 }
 
  function boxgetleft() {
     if (m_strBrowser == 'nn4') {
          myBox=document.layers[this.id];
		  return myBox.left;	 
       }
       else if (m_strBrowser == 'ie4') {
          myBox=this.id;
		  return myBox.style.left; 
       }
       else if (m_strBrowser == 'standard') {
          myBox = document.getElementById(this.id);
		  return myBox.style.left;
       }
   }

 function boxgettop() {
    if (m_strBrowser == 'nn4') {
         myBox=document.layers[this.id];	 
         return myBox.top;
     }
      else if (m_strBrowser == 'ie4') {
         myBox=this.id; 
         return myBox.style.top;
      }
      else if (m_strBrowser == 'standard') {
     	myBox = document.getElementById(this.id);
        return myBox.style.top;
    }

  }

 function boxresize(width,height) {
    if (m_strBrowser == 'nn4') {
         //alert(this.id);
         myBox=document.layers[this.id];	 
	 myBox.position="absolute";
         myBox.width=width;
         myBox.height=height;
      }
      else if (m_strBrowser == 'ie4') {
         myBox=this.id; 
         myBox.style.position="absolute";
         myBox.style.width=width;
         myBox.style.height=height;
      }
      else if (m_strBrowser == 'standard') {
     	 myBox = document.getElementById(this.id);
     	 myBox.style.position="absolute";
         myBox.style.width=width;
         myBox.style.height=height;
      }
      this.width = width;
      this.height = height;
 
 }
 
 
 function boxmoveto(left, top) {
    if (m_strBrowser == 'nn4') {
        myBox=document.layers[this.id];	 
        myBox.position="absolute";
        myBox.top=top;
        myBox.left=left;

     }
     else if (m_strBrowser == 'ie4') {
        myBox=this.id; 
        myBox.style.position="absolute";
        myBox.style.top=top;
        myBox.style.left=left;
     }
     else if (m_strBrowser == 'standard') {
    	myBox = document.getElementById(this.id);
        myBox.style.position="absolute";
        myBox.style.top=top;
        myBox.style.left=left;
     }
     
     this.top = top;
     this.left = left;
 }
 
 function boxshow() {
    if (m_strBrowser == 'nn4') {
       myBox=document.layers[this.id];	 
       myBox.fontFamily="Verdana, Arial, Helvetica, sans-serif";     
       myBox.fontStyle="normal";
       myBox.fontWeight="normal";
       myBox.visibility ="visible";
    }
    else if (m_strBrowser == 'ie4') {
       myBox=this.id; 
       myBox.style.fontFamily="Verdana, Arial, Helvetica, sans-serif";     
       myBox.style.fontStyle="normal";
       myBox.style.fontWeight="normal";
       myBox.style.visibility ="visible";
    }
    else if (m_strBrowser == 'standard') {
   	   myBox = document.getElementById(this.id);
       myBox.style.fontFamily="Verdana, Arial, Helvetica, sans-serif";     
       myBox.style.fontStyle="normal";
       myBox.style.fontWeight="normal";
       myBox.style.visibility ="visible";
    }
  }
 
  
  
  function boxhide() {
     if (m_strBrowser == 'nn4') {
         myBox=document.layers[this.id];	 
         myBox.visibility ="hidden";
      }
      else if (m_strBrowser == 'ie4') {
         myBox=this.id; 
         myBox.style.visibility ="hidden";
      }
      else if (m_strBrowser == 'standard') {
     	myBox = document.getElementById(this.id);
     	myBox.style.visibility="hidden";
      }
  
  }
 

var winglb = null;

function win(cont, sb, sb_pos, left, top) {

////
///   cont: id of content box
//    sb:   id of scrollbar box
//    sb_pos:  0: vertical, 1: horizontal


////
///  properties
//
   this.content   = cont;
   this.scrollbar = sb;
   this.scrollbar_pos = sb_pos;
   this.ClientTop       = top;
   this.ClientLeft      = left;
   this.ClientWidth     = this.content.width;
   this.ClientHeight    = this.content.height;
   this.nocscroll       = false;

////
///  methods
//
   this.show     = winshow;
   this.hide     = winhide;
   this.moveto   = winmoveto;
   this.scroll   = winscroll;
   this.scrollto = winscrollto;
   this.setscrollrange = winsetscrollrange;
////
/// window properties
//
   this.gap = 0;
   this.sbleft = false;
   this.scrollwidth = 00;
   this.scrollpos   = 0;
   this.scrollrange = 1919;
   this.scrolltopos = 0;
   this.scrollinprogress = 0;
   // -1: down; +1: up; 0: undef
   this.scrolldir = 0;     

   this.content.moveto(left,top);
   this.content.resize(this.content.width,this.scrollrange);
   this.content.clip(0,0,this.ClientHeight,this.ClientWidth);

   left = this.content.left + this.content.width + this.gap;
   
   if (this.scrollbar_pos == 0) 
   {
       // vertical scrollbar
	   this.scrollbar.moveto(left,top);
	   this.scrollbar.resize(this.scrollwidth,this.ClientHeight);
   } else
   {
   	   // horizontal scrollbar
	   this.scrollbar.moveto(this.content.left,top + this.ClientHeight + this.gap );
	   this.scrollbar.resize(this.ClientWidth,20);
   }
}


function winshow() {
   this.content.show();
   if (!this.noscroll) {
      this.scrollbar.show();
   }
}

function winhide() {
   content.hide();
   if (!this.noscroll) {
      scollbar.hide();
   }
}

function winmoveto(left,top) {
   this.content.moveto(left,top);
   this.scrollbar.moveto(left + this.content.width + this.gap);

   this.ClientTop = top;
   this.ClientLeft = left;
}

function winsetscrollrange(range) {
    this.scrollrange = range;
}

function winscroll(pos) {

////
/// sa: # number of pixels to scroll
//

   if (this.noscroll) return;
   
   this.scrollpos = this.scrollpos + pos;
   if (this.scrollpos < 0) this.scrollpos = 0;
   if (this.scrollpos > this.scrollrange - GetWinWidth()) this.scrollpos = this.scrollrange - GetWinWidth() ;
  
   if (this.scrollbar_pos == 0)
   { 
      // vertical scrollbar
	   this.content.moveto(this.ClientLeft,this.ClientTop-this.scrollpos);
	   this.content.clip(0,this.scrollpos,this.scrollpos+this.ClientHeight,this.content.left+this.content.width);
   } else
   {
      // horizontal scrollbar
	   this.content.moveto(this.ClientLeft-this.scrollpos,this.ClientTop);
	   this.content.clip(this.scrollpos,0,this.ClientHeight,this.ClientWidth+this.scrollpos);
   }
}


function winscrollto(pos) {

////
/// sa: position to scroll to
//
   if (this.noscroll) return;
   winglb = this;
   if (this.scrollinprogress && (pos != 4711)) return;                       // save pointer
   if (!this.scrollinprogress) {
      this.scrolltopos = pos;
      if (this.scrollpos < this.scrolltopos) this.scrolldir = +1; // scroll down
      if (this.scrollpos > this.scrolltopos) this.scrolldir = -1; // scroll up
      if (this.scrollpos == this.scrolltopos) return;
      this.scrollinprogress = 1;
   }
   
   pos = this.scrolltopos;  // restore
   var step = 0;
   
   if (abs(this.scrollpos-pos) >  400)  step = 80;
   if (abs(this.scrollpos-pos) <= 400)  step = 40;
   if (abs(this.scrollpos-pos) <= 200)  step = 20;
   if (abs(this.scrollpos-pos) <= 100)  step = 10;
   if (abs(this.scrollpos-pos) <= 15)   step = 1;

   if (this.scrolldir == -1) step = -step;
   this.scrollpos = this.scrollpos + step;
   if (this.scrollpos <= 0) {
      this.scrollpos = 0;
      this.scrollinprogress = 0;
      this.scrolldir = 0;
      return;
   }
   if (this.scrollpos >= this.scrollrange) {
      this.scrollpos = this.scrollrange;
      this.scrollinprogress = 0;
      this.scrolldir = 0;
      return;
   }

   if (this.scrolldir == +1) {
      if (this.scrollpos >= pos) {
         this.scrollpos = pos;
         this.scrollinprogress = 0;
         this.scrolldir = 0;
         return;
      }
   }
   if (this.scrolldir == -1) {
      if (this.scrollpos <= pos) {
         this.scrollpos = pos;
         this.scrollinprogress = 0;
         this.scrolldir = 0;
         return;
      }
   }

   if (this.scrolldir == 0) return;
   this.content.moveto(this.ClientLeft,this.ClientTop-this.scrollpos);
   this.content.clip(0,this.scrollpos,this.scrollpos+this.ClientHeight,this.content.left+this.content.width);
   setTimeout('winglb.scrollto(4711)',5);
}



var dropglb = null;

function drop(cont, left, top) {

////
///   cont: id of content box
//    


////
///  properties
//
   this.content         = cont;
   this.ClientTop       = top;
   this.ClientLeft      = left;
   this.ClientWidth     = this.content.width;
   this.ClientHeight    = this.content.height;
   
   this.tmp1            = 0;

////
///  methods
//
   this.show     = dropshow;
   this.hide     = drophide;
   this.moveto   = dropmoveto;
   this.dropdown = dropdropdown;
   this.closeup  = dropcloseup;
   this.dropdown2 = dropdropdown2;
   this.closeup2  = dropcloseup2;

////
/// dropdown properties
//
   this.dropspeed = 1;
   this.droppos   = 0;

   this.content.moveto(left,top);
   this.content.clip(0,0,0,0);

   this.state  = 0;   // 0: closed; 1: opened;  2: in progress
}


function dropshow() {
   this.content.show();
}

function drophide() {
   this.content.hide();
}

function dropmoveto(left,top) {
   this.content.moveto(left,top);
   this.ClientTop = top;
   this.ClientLeft = left;
}

function dropdropdown() {
   dropglb = this;
   this.droppos = this.droppos + 20;
   if (this.droppos <= (this.ClientHeight)) {
      this.state = 2;
      this.content.clip(0,0,this.droppos,this.content.width);
      setTimeout('dropglb.dropdown()',dropglb.dropspeed);
   } else {
   	this.state = 1;
   }
}

function dropcloseup() {
   dropglb = this;
   this.droppos = this.droppos - 20;
   if (this.droppos > -10) {
      this.state = 2;
      this.content.clip(0,0,this.droppos,this.content.width);
      setTimeout('dropglb.closeup()',dropglb.dropspeed);
   } else {
      this.state = 0;
   }
}

function dropdropdown2() {
   dropglb = this;
   dropskip = 2;
   this.droppos = this.droppos + dropskip;
   if (this.droppos <= (this.ClientHeight)) {
      if (!this.tmp1) {
         this.content.moveto(this.content.left,this.content.top-this.ClientHeight);
         this.tmp1 = 1;
      }
      this.state = 2;
      this.content.moveto(this.content.left,this.content.top+dropskip);
      this.content.clip(0,this.ClientHeight-this.droppos,this.ClientHeight,this.content.width);
      setTimeout('dropglb.dropdown2()',dropglb.dropspeed);
   }
   else {
      this.droppos = this.ClientHeight;
      this.state = 1;
   }
}

function dropcloseup2() {
   dropglb = this;
   dropskip = 2;
   this.droppos = this.droppos - dropskip;
   if (this.droppos > 0) {
      this.state = 2;
      this.content.moveto(this.content.left,this.content.top-dropskip);
      this.content.clip(0,this.ClientHeight-this.droppos,this.ClientHeight,this.content.width);
      setTimeout('dropglb.closeup2()',dropglb.dropspeed);
   }
   else {
      this.droppos = 0;
      this.content.clip(0,0,0,0);
      this.state = 0;
   }
}


