
<!-- Original:  Randy Bennett (rbennett@thezone.net) -->
<!-- Web Site:  http://home.thezone.net/~rbennett/sitemap.htm -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- modifications by dale welch (www.babbler.org)
<!-- Begin
N = (document.all) ? 0 : 1;
var nn4=0;
var nn6=0;
var ie=0;
var mythisbrowser = "dale ";
var cnt = 0;
var ob;

var dragging=false; //dale
var traddrag=false; //dale
var mydb=false;


function mywhatbrowser() {
nn4 = 0; nn6=0; ie=0;
//        mythisbrowser="dale2";
        if(document.layers){
            mythisbrowser="nn4";
            nn4 = 1;
        }
        if(document.all){
            mythisbrowser="ie";
            ie=1;
        }
        if(!document.all && document.getElementById){
            mythisbrowser="nn6";
            nn6=1;
        }
   return mythisbrowser;
}

var cntr=0;

function zindexchange(e)
{
var oi;
  if (mydb)
  window.status = 'zIndex target name:'+e.target.name;
  if (nn6)  
  {
  if (mydb)
    window.status = 'zindex-nn6 target name:'+e.target.name;
    ob = document.getElementById(e.target.name);
    oi = parseInt(ob.style.zIndex);
  if (mydb)
    window.status = 'zindex-nn6 target name:'+e.target.name+ '   zi='+oi;
    if (e.shiftKey)
    {
      if (parseInt(oi) > 2) oi = parseInt(oi) - 1;
    }
    if (e.ctrlKey)
    {
      oi = parseInt(oi) + 1;
    }
    ob.style.zIndex = oi;
  }
}


function processIEkpEvent(e)
{
var kc,oi;
  if (ie)  
  {
    e = event;
  if (mydb)
    window.status = 'IEKP zindex-ie target name:'+e.srcElement.name+ '   ='+ob.name;
//    ob = document.getElementById(e.target.name);
    oi = parseInt(ob.zIndex);
  if (mydb)
    window.status = 'IEKP2 zindex target name:'+e.srcElement.name+ '  kc=' + e.keycode 
                    + ' which=' + e.which + '  zi='+oi;
    kc = parseInt(e.keyCode);
    if (kc > 95) kc = kc - 32;
    if ((kc == 90) && (oi > 1))
    {
      oi = parseInt(oi) - 1;
    }
    if (kc == 65)
    {
      oi = parseInt(oi) + 1;
    }
    window.status = 'zindex-nn6 = ' + oi;
    ob.zIndex = oi;
  }
}


function processkpEvent(e)
{
var kc,oi;
  if (mydb)
    window.status = 'KeyPress zIndex target name:'+e.target.name;
  if (nn6)  
  {
  if (mydb)
    ob = document.getElementById(e.target.name);
    oi = parseInt(ob.style.zIndex);
    window.status = 'zindex-nn6 = ' + oi;
  if (mydb)
    window.status = 'KP2 zindex-nn6 target name:'+e.target.name+ '  kc=' + e.keycode 
                    + ' which=' + e.which + '  zi='+oi;
    kc = parseInt(e.which);
    if (kc > 95) kc = kc - 32;
    if ((kc == 90) && (oi > 1))
    {
     
      oi = parseInt(oi) - 1;
    }
    if (kc == 65)
    {
      oi = parseInt(oi) + 1;
    }
    ob.style.zIndex = oi;
  }
}

function MD(e) {
  if (mydb)
  window.status = 'down1(' + cntr + ')  dragging==' + dragging + ' ' + traddrag;
  if (nn6) {
   if (e.altKey || e.shiftKey || e.ctrlKey)
   {
     zindexchange(e);
  return;
   }
  }
  if (!traddrag)    //dale
  {                      //dale
    if (dragging)  //dale
    {
      cntr = cntr + 1;  
      dragging = false;  //dale
  if (mydb)
      window.status = 'down1.3 dragging=' + dragging + '  (' + cntr + ') ' + ob.id;
//     ob = null;       //dale
  if (mydb)
      window.status = 'down1.5 dragging=' + dragging + '  (' + cntr + ') ' + ob.id;
      return;        //dale
    }               //dale
  if (mydb)
  window.status = 'down1.6 dragging=' + dragging + '  (' + cntr + ') ' + ob.id;
  }
  if (mydb)
  window.status = 'down2';
  if (ie)
  { 
  if (mydb)
  window.status = 'down3 event='+event.srcElement.id + "  = "+event.srcElement.name;
    //if (event.srcelement)
    if (event.srcElement.name !== "") 
    {
  if (mydb)
  window.status = 'down3.5 event='+event.srcElement.id + "  = "+event.srcElement.name;
      ob = event.srcElement.parentElement.style; //this is why everything moves.
      X = event.offsetX;
      Y = event.offsetY;
      dragging = true; //dale
    }
  }
  else
  if (nn4) {
    ob = document.layers[e.target.name];
    X = e.x;
    Y = e.y;
    if (ob) { 
      dragging=true; //dale
      return false;
    }
    else //Jim
    {
//        routeevent(e); //pass it on to normal processing
	return; //Jim
    }
  }
  else
  if (nn6) {
  if (mydb)
  window.status = 'down-nn6 target name:'+e.target.name;
    ob = document.getElementById(e.target.name);
  if (mydb)
  window.status = 'down-nn63 target name:'+e.target.name;
//    ob = document.layers[e.target.name];
    X = parseInt(ob.style.left);
    Y = parseInt(ob.style.top);
    XO = e.pageX - X;
    YO = e.pageY - Y;
  if (mydb)
  window.status = 'down-nn64';
//    ob.style.top = Y + 10;//x + 29+"px";
//    ob.style.top = parseInt(ob.style.top) + 20;
  if (mydb)
  window.status = 'down-nn6-2';
//document.getElementById('p2').style.top=20 +"px";
  if (mydb)
  window.status = 'down nn6 '+e.type + '  ' + e.target.id + ' name: ' + e.target.name + ' XY(' + e.pageX+','+e.pageY+') xy('+X+','+Y+') altkey=' + e.altKey+' dragging='+dragging;
    if (ob) { 
      dragging = true; //dale
      return false;
    }
  }
}


function MM(e) {
 if (dragging)
 {
   if (ie) 
   {
     ob.pixelLeft = event.clientX-X + document.body.scrollLeft;
     ob.pixelTop  = event.clientY-Y + document.body.scrollTop;
     return false;
   }
   else
   if (nn4) {
     ob.moveTo((e.pageX-X), (e.pageY-Y));
   }
   else
   if (nn6) {
  if (mydb)
  window.status = 'nn6 mm'; 
     cnt = cnt + 1;
//     ob.moveTo((e.pageX-X), (e.pageY-Y));
     ob.style.left = e.pageX - XO;  //-X + document.body.scrollLeft;
     ob.style.top  = e.pageY - YO;  //-Y + document.body.scrollTop;
   }
 }
}


function MU() 
{
  if (mydb)
window.status="MU-2 traddrag="+traddrag+" dragging="+dragging;
  if (traddrag==true)    //dale
  {                      //dale
   ob = null; 
//   dragging=false;
   window.status = "MU dragging turned off."; 
  } //dale
}

function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be attached");
  }
}


function processmdEvent(e){
  var color;
//  window.status = e.type + '  ' + e.target.id + ' : ' + e.target.name + ' (' + e.pageX + ',' + e.pageY+') ' + e.altKey;


  MD(e);
}

function processmuEvent(e){
  var color;
  if (mydb)
  window.status = e.type;
//  if (e.type=="mouseover") color = "green";
//  else color = "red";
//  divTag.style.backgroundColor = color;
  MU(e);
}


function processmmEvent(e)
{
//  window.status = mythisbrowser+': ' + e.type + ' ('+cnt+') '+ob.id + ' - ' + ob.name;
  if (mydb)
  window.status = mythisbrowser+'MM('+cnt+')'+': ' + e.type + '  ' + e.target.id + '  name: ' + e.target.name + ' XY(' + e.pageX+','+e.pageY+') xy('+X+','+Y+') ' + e.altKey+' dragging='+dragging + '  ob='+ob.id+ '   ctrl=' + e.ctrlKey + '  shiftKey=' + e.shiftKey;
  MM(e);
}


mywhatbrowser();

if (nn4) {
  document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
document.onmousedown = MD;
document.onmousemove = MM;
document.onmouseup   = MU;
}

if (nn6) {
//  document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
document.addEventListener("mousedown", processmdEvent, false);
document.addEventListener("mouseup", processmuEvent, false);
document.addEventListener("mousemove", processmmEvent, false);
document.addEventListener("keypress", processkpEvent, false);
}
if (ie) {
document.onmousedown = MD;
document.onmousemove = MM;
document.onmouseup   = MU;
document.onkeypress = processIEkpEvent;
}

//  End -->

// 2 L shaped connectors and two t shaped connectors. (small - connect to 2 liter bottle)
