var currbox,prevbox;var dx,dy; var x,y;var t;var release;
forgeturl=0;savecommand=0;accum="";mousemoving=0;filnaminput=0;showhich=0;sb=0
grpmov=0;clockon=1;clktimer=30000
objs=new Array(20);
ns = window.Event ? true : false;
document.write("<link rel=stylesheet type='text/css' href='"+stylfile+".css'>")

function setobj(obj,parm,val){document.getElementById(obj).style[parm] = val;}
function getobj(obj,parm,st){currp=document.getElementById(obj).style[parm];if(!st)stripunits();return(currp)}
function stripunits(){currp=parseInt(currp.substring(0,currp.length-2));}
function insert(div,text,html){!html?document.getElementById(div).innerHTML=text:document.getElementById(div).innerText=text}
function getext(div){return(document.getElementById(div).innerHTML)}
function comm(text,html){insert('info',text,html)}
function show (nam) {setobj(nam,'visibility','visible')}
function hide (nam) {setobj(nam,'visibility','hidden')}
function strip1st(n,altbox){bnum=(altbox?altbox:currbox).substring(n,(altbox?altbox:currbox).length);return(bnum)}
function getkeydown(e){
  if(release)return(0)
  if(ns)e.preventDefault();
  if(ns)code=e.which;else code=e.keyCode
  if(code==39)keyleft(1)     //  box left
  if(code==37)keyleft(0)     //  box right
  if(code==38)keyup(1)       //  box up
  if(code==40)keyup(0)       //  box dn

  if(code==65)comm(screen.height+" "+screen.width+" "+getbrowidth() +" "+getbrowheight()) //document.body.clientWidth+" "+document.body.clientHeight)
    if(code==66)window.moveTo(100,100)
    if(code==71)grpmov=grpmov?0:1   // Group move on/off
    if(code==79)comm(objs)          // Objs
    if(code==86)getallobjs(1)       // View Obj locs
    if(code==83)getallobjs(0)       // Save Obj locs
  
    if(code==82)randomlayout()   // Random layout
    if(code==78)layout()         // Normal Layout
  
    if(code==74){clearInterval(t);trigjig()} // Jiggle
    if(code==69){stopjig();}                 // End Jiggle
    if(code==84){togglejiggle()}             // Toggle jiggle
//   }
  if(!ns && code!=32 && (code<41 || e.ctrlKey))e.returnValue=false;
}
function getkeypress(e) {
  if(release)return(0)
  if(ns)e.preventDefault()
  if(!ns)e.returnValue=false
}
function getidobjs(){
  currnode=document.getElementById('bodynode').childNodes
  accum=""
  for(i=0;currnode[i];i++)if(currnode[i].id)accum+=currnode[i].id+" "
  objs=accum.split(" ")
  nobjs=objs.length-2
  return(accum)
}
function getallobjs(viewonly){
  collstr=""
  for (i=1;i<=nobjs;i++){
    j=objs[i]
    if(viewonly)collstr+=j+".top0="+getobj(j,'top')+";"+j+".left0="+getobj(j,'left')+";"+String.fromCharCode(13)
      else {
        currobj="document.getElementById('"+j+"')"
        collstr+="if("+currobj+"){"+currobj+".top0="+getobj(j,'top')+";"+currobj+".left0="+getobj(j,'left')+";}"+String.fromCharCode(13)
       }
   }
  comm(collstr)
  if(!viewonly)savbrks()
}
function savbrks0(savstr) {
   stats='toolbar=no,location=no,directories=no,status=no,menubar=no,'
   stats += 'scrollbars=no,resizable=no,width=300,height=300'
   win1=window.open("","testwindow",stats)
   win1.document.open("text/html")
   win1.document.write(collstr)
   win1.document.close ()
}
function savbrks() {
   win1=window.open("","testwindow","scrollbars=yes,menubar=yes,status=yes,height=402,width=602")
   win1.document.open("text/html")
   win1.document.write(collstr)
   win1.document.close ()
}
function div(id,clas,styl){
    if(!styl)styl="" //
    tp=Math.round(Math.random()*(300));lft=Math.round(Math.random()*(300))
//    tp=0;lft=0
   document.write("<div id="+id+" onmouseDown='omd(this.id)' style='position:absolute;top:"+tp+";left:"+lft+";"+styl+"' class="+clas+">")
}
function togglejiggle(){if(jiggle){clearInterval(t);jiggle=0} else {jiggle=1;trigobjs()}}
function trigobjs(){if(jiggle){clearInterval(t);t=setInterval("jigglerange(8,12)",50)}}

function stopjig(){clearInterval(t);}
function trigjig(){t=setInterval("jigglerange(1,5)",50) }
function jigglerange(from,to){
  njigs=to-from
  objn=Math.round(Math.random()*(njigs))+from
  flip=Math.round(Math.random()*100)
  if(flip>50)parm="top";else parm="left"
  flip=Math.round(Math.random()*100)
  if(flip>50)dir=1;else dir=-1
  incr=dir
  setobj(objs[objn],parm,incr+getobj(objs[objn],parm))
}
function randomlayout(){
  for(i=1;i<=nobjs;i++){
      if(document.getElementById(objs[i]) && document.getElementById(objs[i]).top0){
        setobj(objs[i],"top",Math.round(Math.random()*(200))+100)
        setobj(objs[i],"left",Math.round(Math.random()*(300))+200)
       }
   }
}
function layout(){
  for(i=1;i<=nobjs;i++){
     currobj=document.getElementById(objs[i])
      if(currobj && currobj.top0){
        setobj(objs[i],"top",currobj.top0)
        setobj(objs[i],"left",currobj.left0)
	 }
      else {setobj(objs[i],"top",0);setobj(objs[i],"left",0)}
   }
}

function movegroup(){
 grpcode=currbox.substr(0,2)
 for (i=1;i<=nobjs;i++){
   j=objs[i]
   if(j.indexOf(grpcode)==0 && j!=currbox){
      boxleft(boxleft(0,j)-dxx,j);
      boxtop (boxtop (0,j)-dyy,j);
    }
  }
}
function keyleft(left){
  currbox=prevbox
  boxleft(boxleft()+ (dxx=(left?1:-1)))
  dyy=0;dxx=-dxx
  if(grpmov)movegroup()
  currbox=0
}
function keyup(up){
  currbox=prevbox
  boxtop(boxtop()+ (dyy=up?-1:1))
  dxx=0;dyy=-dyy
  if(grpmov)movegroup()
  currbox=0
}

function catchclick(){if(forgeturl){forgeturl=0;return false} else return true }
function startmov(e){blurinputs();mousemoving=1;forgeturl=0;mousxy(e);} // mousedown anywhere in doc
function stopmove(e){mousemoving=0;mousxy(e);if(currbox){prevbox=currbox;currbox=0}} // mouseup		"
function mover(e){if(mousemoving){forgeturl=1;mousxy(e);}} // mousemove		"
function mousxy(e){
  if(release)return(0)
  if(ns){x=e.clientX;y=e.clientY}
    else {x=event.clientX;y=event.clientY;}
  if(!ns || e.target.type!="text")ns?e.preventDefault():event.returnValue=false
  if(currbox){
     prvx=boxleft();prvy=boxtop()
     boxleft(x-dx);boxtop(y-dy);
     dxx=prvx-boxleft();dyy=prvy-boxtop()
  if(grpmov)movegroup()
   }
//  if(debug)comm(x+","+y+" "+currbox+" left="+ (currbox?boxleft():'') +" top="+ (currbox?boxtop():'') +" width="+ (currbox?boxwidth():'')+ " fsiz="+fsiz) // +" "+e.target.className + e.target.tagName)
   if(debug)comm(currbox)
}
function omd (boxid) {
   currbox=boxid
   if(!ns){x=event.clientX;y=event.clientY;}
   dx=x-boxleft();dy=y-boxtop()
}
function blurinputs(){
  allinputs=document.getElementsByTagName('input')
  numinputs=allinputs.length
  for (i=0;i<numinputs;i++) allinputs.item(i).blur()
}
if(ns){
  document.captureEvents(Event.MOUSEDOWN);document.onmousedown=startmov;
  document.captureEvents(Event.MOUSEUP);document.onmouseup=stopmove;
//  document.captureEvents(Event.KEYDOWN);document.onkeydown=getkeydown;
  document.captureEvents(Event.MOUSEMOVE);document.onmousemove=mover;
}
function boxtop(yval,forbox){if(!forbox)forbox=currbox;if(!yval)return(getobj(forbox,"top")); else setobj(forbox,"top",yval);}
function boxleft(xval,forbox){if(!forbox)forbox=currbox;if(!xval)return(getobj(forbox,"left")); else setobj(forbox,"left",xval);}
function boxcont(contents,forbox){
  if(!contents)return(document.getElementById(forbox).innerHTML);
    else insert(forbox,contents);
}
function boxwidth(width,forbox){if(!forbox)forbox=currbox;if(!width)return(getobj(forbox,"width"));else setobj(forbox,"width",width) }
function boxheight(height,forbox){if(!forbox)forbox=currbox;if(!height)return(getobj(forbox,"height"));else setobj(forbox,"height",height) }
function getbrowidth(){
 if(self.innerWidth)browidth=self.innerWidth;
   else if(document.documentElement && document.documentElement.clientWidth)browidth=document.documentElement.clientWidth;
 	 else if (document.body)browidth=document.body.clientWidth;
 return(browidth)
}
function getbrowheight(){
 if(self.innerHeight)browheight=self.innerHeight;
   else if(document.documentElement && document.documentElement.clientHeight)browheight=document.documentElement.clientHeight;
 	 else if (document.body)browheight=document.body.clientHeight;
 return(browheight)
}
function blogdate(daynum,ins){
  updateparms(daynum)
  str=parent.parent.days[dayofwk]+", "+parent.parent.months[monthnum] +" "+ parent.parent.dayofmo+", 20"+ parent.parent.year
  if(!ins)document.write(str); else return(str)
}
function bogontime(daynum,ins){
  updateparms(daynum)
  ampm="AM";if(hrs>=12)ampm="PM";if(hrs>12)hrs=hrs-12;if(hrs==0){hrs=12;ampm="AM";}
  str=hrs+":"+ mins + " "+ ampm;if(!ins)document.write(str); else return(str)
}
function showdatime(){
  insert("datime1",bogontime(1,1));
  insert("datime2",blogdate (1,1));
}
function runclock(){showdatime();if(clockon)tt=setInterval('showdatime()',clktimer);}

function getprops(obj){accum=""; for(var i in eval(obj))accum=accum+" "+i;  return(accum)}
function hgetprops(obj){
   accum="";
   for(var i in eval(obj))
   accum=accum+document.all[i].id+" "
   comm (accum)
}
document.write("<script src='datelib.js'><\/script>")
document.write("<\/head><body id=bodynode  onload='runclock();layout();showhides();self.focus()' onkeyPress='getkeypress(event);' onkeyDown='getkeydown(event);' onmouseMove='if(!ns)mover()' onmouseDown='if(!ns)startmov()' onmouseUp='if(!ns)stopmove()'>")
div('info','','font-family:verdana;font-size:10');document.write("</div>")


// objstr=""
// for (i=1;i<=nobjs;i++){
//   j=objs[i]
//   if(j.indexOf("hr")==0)objstr+=j+" "
//  }
//      boxleft(boxleft(0,j)-1,j);
//      boxtop(y-dy);
