home *** CD-ROM | disk | FTP | other *** search
/ ftp.swcp.com / ftp.swcp.com.zip / ftp.swcp.com / mac / mozilla-macos9-1.3.1.sea.bin / Mozilla1.3.1 / Chrome / comm.jar / content / editor / EdImageMapShapes.js < prev    next >
Text File  |  2003-06-08  |  30KB  |  872 lines

  1. /* 
  2.  * The contents of this file are subject to the Netscape Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/NPL/
  6.  *  
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  *  
  12.  * The Original Code is Mozilla Communicator client code, released
  13.  * March 31, 1998.
  14.  * 
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation. Portions created by Netscape are
  17.  * Copyright (C) 1999-2000 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  * 
  20.  * Contributor(s): 
  21.  *   Dan Haddix (dan6992@hotmail.com)
  22.  */
  23.  
  24. var downTool = false;
  25. var dragActive = false;
  26. var dragObject = false;
  27. var startX = null;
  28. var startY = null;
  29. var endX = null;
  30. var endY = null;
  31. var downTool = false;
  32. var currentElement = [];
  33. var currentTool = "pointer";
  34. var currentRect = null;
  35. var currentCir = null;
  36. var currentPoly = null;
  37. var currentPoint = null;
  38. var rectCount = 1;
  39. var cirCount = 1;
  40. var polyCount = 1;
  41. var pointCount = 1;
  42. var xlock = false;
  43. var ylock = false;
  44. var resize = false;
  45. var currentZoom = 1;
  46. var clipBoard = [];
  47.  
  48. function Rect(coords, href, target, alt, construct){
  49.   newRect = frameDoc.createElement("div");
  50.   newRect.setAttribute("class", "rect");
  51.   newRect.setAttribute("id", "rect"+rectCount++);
  52.   newRect.setAttribute("name", "hotspot");
  53.   currentRect = selectElement(frameDoc.body.appendChild(newRect));
  54.  
  55.   // Add resize handles
  56.   // waiting for better drawing code
  57.   handletl = frameDoc.createElement("div");
  58.   handletl.setAttribute("class", "handletl");
  59.   handletl.setAttribute("name", "handle");
  60.   handletr = frameDoc.createElement("div");
  61.   handletr.setAttribute("class", "handletr");
  62.   handletr.setAttribute("name", "handle");
  63.   handlebl = frameDoc.createElement("div");
  64.   handlebl.setAttribute("class", "handlebl");
  65.   handlebl.setAttribute("name", "handle");
  66.   handlebr = frameDoc.createElement("div");
  67.   handlebr.setAttribute("class", "handlebr");
  68.   handlebr.setAttribute("name", "handle");
  69.   handlet = frameDoc.createElement("div");
  70.   handlet.setAttribute("class", "handlet");
  71.   handlet.setAttribute("name", "handle");
  72.   handlel = frameDoc.createElement("div");
  73.   handlel.setAttribute("class", "handlel");
  74.   handlel.setAttribute("name", "handle");
  75.   handler = frameDoc.createElement("div");
  76.   handler.setAttribute("class", "handler");
  77.   handler.setAttribute("name", "handle");
  78.   handleb = frameDoc.createElement("div");
  79.   handleb.setAttribute("class", "handleb");
  80.   handleb.setAttribute("name", "handle");
  81.   currentRect.appendChild(handletl);
  82.   currentRect.appendChild(handletr);
  83.   currentRect.appendChild(handlebl);
  84.   currentRect.appendChild(handlebr);
  85.   currentRect.appendChild(handlet);
  86.   currentRect.appendChild(handlel);
  87.   currentRect.appendChild(handler);
  88.   currentRect.appendChild(handleb);
  89.  
  90.   if (!coords){
  91.     currentRect.style.left = startX+"px";
  92.     currentRect.style.top = startY+"px";
  93.     //currentRect.style.width = endX+"px";
  94.     //currentRect.style.height = endX+"px";
  95.   }
  96.   else{
  97.     var coordArray = coords.split(',');
  98.     currentRect.style.left = coordArray[0]+"px";
  99.     currentRect.style.top = coordArray[1]+"px";
  100.     currentRect.style.width = (parseInt(coordArray[2])-parseInt(coordArray[0]))+"px";
  101.     currentRect.style.height = (parseInt(coordArray[3])-parseInt(coordArray[1]))+"px";
  102.     if (href)
  103.       currentRect.setAttribute("hsHref", href);
  104.     if (target)
  105.       currentRect.setAttribute("hsTarget", target);
  106.     if (alt)
  107.       currentRect.setAttribute("hsAlt", alt);
  108.   }
  109.   if (construct)
  110.     currentRect = null;
  111. }
  112.  
  113. function Circle(coords, href, target, alt, construct){
  114.   newCir = frameDoc.createElement("div");
  115.   newCir.setAttribute("class", "cir");
  116.   newCir.setAttribute("id", "cir"+cirCount++);
  117.   newCir.setAttribute("name", "hotspot");
  118.   currentCir = selectElement(frameDoc.body.appendChild(newCir));
  119.  
  120.   // Add resize handles
  121.   handletl = frameDoc.createElement("div");
  122.   handletl.setAttribute("class", "handletl");
  123.   handletl.setAttribute("name", "handle");
  124.   handletr = frameDoc.createElement("div");
  125.   handletr.setAttribute("class", "handletr");
  126.   handletr.setAttribute("name", "handle");
  127.   handlebl = frameDoc.createElement("div");
  128.   handlebl.setAttribute("class", "handlebl");
  129.   handlebl.setAttribute("name", "handle");
  130.   handlebr = frameDoc.createElement("div");
  131.   handlebr.setAttribute("class", "handlebr");
  132.   handlebr.setAttribute("name", "handle");
  133.   currentCir.appendChild(handletl);
  134.   currentCir.appendChild(handletr);
  135.   currentCir.appendChild(handlebl);
  136.   currentCir.appendChild(handlebr);
  137.  
  138.   if (!coords){
  139.     currentCir.style.left = startX+"px";
  140.     currentCir.style.top = startY+"px";
  141.     //currentCir.style.width = endX+"px";
  142.     //currentCir.style.height = endX+"px";
  143.   }
  144.   else{
  145.     var coordArray = coords.split(',');
  146.     radius = parseInt(coordArray[2]);
  147.     currentCir.style.left = (parseInt(coordArray[0])-radius)+"px";
  148.     currentCir.style.top = (parseInt(coordArray[1])-radius)+"px";
  149.     currentCir.style.width = (radius*2)+"px";
  150.     currentCir.style.height = (radius*2)+"px";
  151.     if (href)
  152.       currentCir.setAttribute("hsHref", href);
  153.     if (target)
  154.       currentCir.setAttribute("hsTarget", target);
  155.     if (alt)
  156.       currentCir.setAttribute("hsAlt", alt);
  157.   }
  158.   if (construct)
  159.     currentCir = null;
  160. }
  161.  
  162. function Poly(coords, href, target, alt, construct){
  163.   dump('Poly Called\n');
  164.   newPoly = frameDoc.createElement("div");
  165.   newPoly.setAttribute("class", "poly");
  166.   newPoly.setAttribute("id", "poly"+polyCount++);
  167.   newPoly.setAttribute("name", "hotspot");
  168.   currentPoly = selectElement(frameDoc.body.appendChild(newPoly));
  169.   if (currentZoom > 1){
  170.     currentPoly.style.width = imageEl.offsetWidth+"px";
  171.     currentPoly.style.height = imageEl.offsetHeight+"px";
  172.   }
  173.   if (!coords){
  174.     addPoint(null, startX, startY, true);
  175.     //currentPoly.onclick = addPoint;
  176.     currentPoly.style.cursor = "crosshair";
  177.   }
  178.   else{
  179.     var coordArray = coords.split(',');
  180.     var len = coordArray.length;
  181.     for (i=0; i<len; i++){
  182.       addPoint(null, coordArray[i], coordArray[i+1]);
  183.       i++;
  184.     }
  185.     if (href)
  186.       currentPoly.setAttribute("hsHref", href);
  187.     if (target)
  188.       currentPoly.setAttribute("hsTarget", target);
  189.     if (alt)
  190.       currentPoly.setAttribute("hsAlt", alt);
  191.     polyFinish(null, construct);
  192.   }
  193. }
  194.  
  195. function addPoint(event, pointX, pointY, start){
  196.   if (event){
  197.     dump('addPoint Called with event\n');
  198.     pointX = event.clientX+window.frames[0].pageXOffset;
  199.     pointY = event.clientY+window.frames[0].pageYOffset;
  200.     event.preventBubble();
  201.     if (event.detail == 2){
  202.       polyFinish();
  203.       return;
  204.     }
  205.   }
  206.   else
  207.     dump('addPoint Called\n');
  208.   newPoint = frameDoc.createElement("div");
  209.   newPoint.setAttribute("class", "point");
  210.   newPoint.setAttribute("id", "point"+pointCount++);
  211.   newPoint.style.left = pointX+"px";
  212.   newPoint.style.top = pointY+"px";
  213.   if (start){
  214.     newPoint.setAttribute("class", "pointStart");
  215.     newPoint.style.cursor = "pointer";
  216.     //newPoint.onclick = polyFinish;
  217.     //newPoint.addEventListener("click", polyFinish, false);
  218.   }
  219.   currentPoly.appendChild(newPoint);
  220. }
  221.  
  222. function polyFinish(event, construct){
  223.   dump("polyfinish called\n");
  224.   var len = currentPoly.childNodes.length;
  225.   if (len >=3){
  226.     var polyLeft = 1000000;
  227.     var polyTop = 1000000;
  228.     var polyWidth = 0;
  229.     var polyHeight = 0;
  230.     for(p=0; p<len; p++){
  231.       var curEl = currentPoly.childNodes[p];
  232.       curEl.setAttribute("class", "point");
  233.       curEl.style.cursor = "default";
  234.       pointLeft = parseInt(curEl.style.left);
  235.       pointTop = parseInt(curEl.style.top);
  236.       polyLeft = Math.min(polyLeft, pointLeft);
  237.       polyTop = Math.min(polyTop, pointTop);
  238.       dump(polyLeft+"\n");
  239.     }
  240.     for(p=0; p<len; p++){
  241.       var curEl = currentPoly.childNodes[p];
  242.       curEl.style.left = (parseInt(curEl.style.left)-polyLeft)+"px";
  243.       curEl.style.top = (parseInt(curEl.style.top)-polyTop)+"px";
  244.     }
  245.     for(p=0; p<len; p++){
  246.       var curEl = currentPoly.childNodes[p];
  247.       polyWidth = Math.max(polyWidth, (parseInt(curEl.style.left)+3));
  248.       polyHeight = Math.max(polyHeight, (parseInt(curEl.style.top)+3));
  249.     }
  250.     if (parseInt(currentPoly.style.left) >= 0){
  251.       polyLeft += parseInt(currentPoly.style.left);
  252.       polyTop += parseInt(currentPoly.style.top);
  253.     }
  254.     currentPoly.style.left = polyLeft+"px";
  255.     currentPoly.style.top = polyTop+"px";
  256.     currentPoly.style.width = polyWidth+"px";
  257.     currentPoly.style.height = polyHeight+"px";
  258.     //currentPoly.childNodes[0].onclick = null;
  259.     //currentPoly.onclick = null;
  260.     currentPoly.style.cursor = "auto";
  261.     //currentPoly.childNodes[0].removeEventListener("click", polyFinish, false);
  262.     //currentPoly.removeEventListener("click", addPoint, true);
  263.     if (!construct)
  264.       hotSpotProps(currentPoly);
  265.   }
  266.   else
  267.     deleteElement(currentPoly);
  268.   if (event)
  269.     event.preventBubble();
  270.  
  271.   currentPoly = null;
  272. }
  273.  
  274. function deleteElement(el){
  275.   if (el){
  276.     if (el.length){
  277.       var len = currentElement.length;
  278.       for(i=0; i<len; i++)
  279.         frameDoc.body.removeChild(currentElement[i]);
  280.     }
  281.     else
  282.       frameDoc.body.removeChild(el);
  283.   }
  284. }
  285.  
  286. function selectAll(){
  287.   objList = frameDoc.getElementsByName("hotspot");
  288.   listLen = objList.length;
  289.   var objCount = 0;
  290.   for(a=0; a<listLen; a++){
  291.      selectElement(objList[a], objCount);
  292.      objCount++;
  293.   }
  294. }
  295.  
  296. function selectElement(el, add){
  297.   if (add){
  298.     if (currentElement[0].getAttribute("class") != "poly"){
  299.       len = currentElement[0].childNodes.length;
  300.       for(i=0; i<len; i++)
  301.         currentElement[0].childNodes[i].style.visibility = "hidden";
  302.     }
  303.     currentElement.push(el);
  304.     document.getElementById("Map:Cut").setAttribute("disabled", "false");
  305.     document.getElementById("Map:Copy").setAttribute("disabled", "false");
  306.     return currentElement[currentElement.length-1];
  307.   }
  308.   else{
  309.     if (currentElement[0]){
  310.       if (currentElement[0].getAttribute("class") != "poly"){
  311.         len = currentElement[0].childNodes.length;
  312.         for(i=0; i<len; i++)
  313.           currentElement[0].childNodes[i].style.visibility = "hidden";
  314.       }
  315.     }
  316.     currentElement = null;
  317.     currentElement = [];
  318.     currentElement[0] = el;
  319.     if (el != null){
  320.     if (currentElement[0].getAttribute("class") != "poly"){
  321.       len = currentElement[0].childNodes.length;
  322.       for(i=0; i<len; i++)
  323.         currentElement[0].childNodes[i].style.visibility = "visible";
  324.     }
  325.       document.getElementById("Map:Cut").setAttribute("disabled", "false");
  326.       document.getElementById("Map:Copy").setAttribute("disabled", "false");
  327.     return currentElement[0];
  328.   }
  329.     else{
  330.       document.getElementById("Map:Cut").setAttribute("disabled", "true");
  331.       document.getElementById("Map:Copy").setAttribute("disabled", "true");
  332.     }
  333.   }
  334. }
  335.  
  336. function deSelectElement(el){
  337.   var len = currentElement.length;
  338.   var j=0;
  339.   for(i=0; i<len; i++){
  340.     dump(j+"\n");
  341.     currentElement[j] = currentElement[i];
  342.     if (currentElement[i] != el)
  343.       j++;
  344.   }
  345.   currentElement.pop();
  346.   if (currentElement.length == 1){
  347.     selectElement(currentElement[0]);
  348.   }
  349.   if (currentElement.length >= 1){
  350.     document.getElementById("Map:Cut").setAttribute("disabled", "false");
  351.     document.getElementById("Map:Copy").setAttribute("disabled", "false");
  352.   }
  353.   else{
  354.     document.getElementById("Map:Cut").setAttribute("disabled", "true");
  355.     document.getElementById("Map:Copy").setAttribute("disabled", "true");
  356.   }
  357. }
  358.  
  359. function marqueeSelect(){
  360.   marTop = parseInt(marquee.style.top);
  361.   marLeft = parseInt(marquee.style.left);
  362.   marRight = parseInt(marquee.style.width)+marLeft;
  363.   marBottom = parseInt(marquee.style.height)+marTop;
  364.   marquee.style.visibility = "hidden";
  365.   marquee.style.top = "-5px";
  366.   marquee.style.left = "-5px";
  367.   marquee.style.width = "1px";
  368.   marquee.style.height = "1px";
  369.   marquee = null;
  370.   objList = frameDoc.getElementsByName("hotspot");
  371.   listLen = objList.length;
  372.   var objCount = 0;
  373.   for(a=0; a<listLen; a++){
  374.     objTop = parseInt(objList[a].style.top);
  375.     objLeft = parseInt(objList[a].style.left);
  376.     objRight = parseInt(objList[a].style.width)+objLeft;
  377.     objBottom = parseInt(objList[a].style.height)+objTop;
  378.     if ((objTop >= marTop) && (objLeft >= marLeft) && (objBottom <= marBottom) && (objRight <= marRight)){
  379.        //objList[i].style.borderColor = "#ffff00";
  380.        selectElement(objList[a], objCount);
  381.        objCount++;
  382.     }
  383.   }
  384. }
  385.  
  386. function upMouse(event){
  387.   if (currentTool != "poly"){
  388.     if (marquee){
  389.       marqueeSelect();
  390.     }
  391.     if (currentRect){
  392.       if (!resize)
  393.         hotSpotProps(currentRect);
  394.       else
  395.          resize = false;
  396.     }
  397.     else if (currentCir){
  398.       if (!resize)
  399.         hotSpotProps(currentCir);
  400.       else
  401.         resize = false;
  402.     }
  403.     else if (currentPoint)
  404.       polyFinish(null, true);
  405.       
  406.     currentRect = null;
  407.     currentCir = null;
  408.     currentPoint=null;
  409.     downTool = false;
  410.     dragActive = false;
  411.     dragObject = false;
  412.     xlock = false;
  413.     ylock = false;
  414.   }
  415. }
  416.  
  417. function moveMouse(event){
  418.   if (downTool){
  419.     endX = event.clientX+window.frames[0].pageXOffset;
  420.     endY = event.clientY+window.frames[0].pageYOffset;
  421.  
  422.     if (dragActive){
  423.       if (currentElement.length > 0){
  424.         if (currentCir){
  425.           radiusWidth = Math.abs((endX-startX));
  426.           radiusHeight = Math.abs((endY-startY));
  427.           circleRadius = Math.max(radiusWidth, radiusHeight);
  428.           currentCir.style.top = Math.max(startY-circleRadius, 0)+"px";
  429.           currentCir.style.left = Math.max(startX-circleRadius, 0)+"px";
  430.           currentCir.style.width = (circleRadius*2)+"px";
  431.           currentCir.style.height = (circleRadius*2)+"px";
  432.         }
  433.         else if (currentRect || marquee){
  434.           var rectObject = (currentRect)? currentRect : marquee;
  435.           if (!xlock){
  436.             if (endX > startX){
  437.               rectWidth = endX-startX;
  438.               rectObject.style.left = Math.max(startX, 0 )+"px";
  439.               rectObject.style.width = rectWidth+"px";
  440.             }
  441.             else{
  442.               rectWidth = startX-endX;
  443.               rectObject.style.left = Math.max(endX, 0)+"px";
  444.               rectObject.style.width = rectWidth+"px";
  445.             }
  446.           }
  447.           if (!ylock){
  448.             if (endY > startY){
  449.               rectHeight = endY-startY;
  450.               rectObject.style.top = startY+"px";
  451.               rectObject.style.height = rectHeight+"px";
  452.             }
  453.             else{
  454.               rectHeight = startY-endY;
  455.               rectObject.style.top = endY+"px";
  456.               rectObject.style.height = rectHeight+"px";
  457.             }
  458.           }
  459.         }
  460.       }
  461.     }
  462.     else{
  463.       if (currentTool == "rect"){
  464.         if ((((endX-startX) > 1) || ((endX-startX) < -1)) && (((endY-startY) > 1) || ((endY-startY) < -1))){
  465.           Rect();
  466.           dragActive = true;
  467.         }
  468.       }
  469.       if (currentTool == "cir"){
  470.         if ((((endX-startX) > 1) || ((endX-startX) < -1)) && (((endY-startY) > 1) || ((endY-startY) < -1))){
  471.           Circle();
  472.           dragActive = true;
  473.         }
  474.       }
  475.       if (currentTool == "pointer"){
  476.         if (dragObject){
  477.           var len = currentElement.length;
  478.           var maxX = false;
  479.           var maxY = false;
  480.           for(i=0; i<len; i++){
  481.             newX = Math.max(0, (endX-currentElement[i].startX));
  482.             newY = Math.max(0, (endY-currentElement[i].startY));
  483.             if (newX == 0)
  484.               maxX = true;
  485.             if (newY == 0)
  486.               maxY = true;
  487.           }
  488.           for(i=0; i<len; i++){
  489.             newX = Math.max(0, (endX-currentElement[i].startX));
  490.             newY = Math.max(0, (endY-currentElement[i].startY));
  491.             if ((newX > 0) && (maxX != true))
  492.               currentElement[i].style.left = newX+"px";
  493.             if ((newY >0) && (maxY != true))
  494.               currentElement[i].style.top = newY+"px";
  495.           }
  496.         }
  497.         else if (currentPoint){
  498.            endX = endX-parseInt(currentPoint.parentNode.style.left);
  499.            endY = endY-parseInt(currentPoint.parentNode.style.top);
  500.            newX = Math.max((0-parseInt(currentPoint.parentNode.style.left)), (endX-currentPoint.startX));
  501.            newY = Math.max((0-parseInt(currentPoint.parentNode.style.top)), (endY-currentPoint.startY));
  502.            currentPoint.style.left = newX+"px";
  503.            currentPoint.style.top = newY+"px";
  504.         }
  505.         else{
  506.           marquee = frameDoc.getElementById("marquee");
  507.           marquee.style.visibility = "visible";
  508.           dragActive = true;
  509.         }
  510.       }
  511.     }
  512.   }
  513. }
  514.  
  515.  
  516. function downMouse(event){
  517.   dump(event.target.parentNode.id+"\n");
  518.   if (event.button == 0){
  519.     if (currentTool != "poly"){
  520.       startX = event.clientX+window.frames[0].pageXOffset;
  521.       startY = event.clientY+window.frames[0].pageYOffset;
  522.       downTool = true;
  523.       if (currentTool == "pointer"){
  524.         if (event.target.getAttribute("name") == "hotspot"){
  525.           var el = event.target;
  526.           var isSelected = false;
  527.  
  528.           if (event.target.getAttribute("cir") == "true")
  529.             el = event.target.parentNode;
  530.  
  531.           if (event.shiftKey){
  532.             var len = currentElement.length;
  533.             var deselect = false;
  534.             for(i=0; i<len; i++){
  535.               if (currentElement[i] == el){
  536.                 deSelectElement(el);
  537.                 return;
  538.               }
  539.             }
  540.             selectElement(el, true);
  541.             isSelected = true; 
  542.           }
  543.           else{
  544.             var len = currentElement.length;
  545.             for(i=0; i<len; i++){
  546.               if (currentElement[i] == el)
  547.                 isSelected = true;
  548.             }
  549.           }
  550.  
  551.           if (isSelected){
  552.             var len = currentElement.length;
  553.             for(i=0; i<len; i++){
  554.               currentElement[i].startX = parseInt(event.clientX+window.frames[0].pageXOffset)-parseInt(currentElement[i].style.left);
  555.               currentElement[i].startY = parseInt(event.clientY+window.frames[0].pageYOffset)-parseInt(currentElement[i].style.top);
  556.             }
  557.           }
  558.           else{
  559.             curObj = selectElement(el);
  560.             curObj.startX = parseInt(event.clientX+window.frames[0].pageXOffset)-parseInt(curObj.style.left);
  561.             curObj.startY = parseInt(event.clientY+window.frames[0].pageYOffset)-parseInt(curObj.style.top);
  562.           }
  563.           dragObject = true;
  564.         }
  565.         else if (event.target.getAttribute("name") == "handle"){
  566.           dump("down on a handle\n");
  567.           resize = true;
  568.           el = event.target;
  569.           curObj = selectElement(el.parentNode);
  570.           if (curObj.className == "rect"){
  571.             currentRect = curObj;
  572.             switch (el.className){
  573.               case "handletl":
  574.                 startX = parseInt(curObj.style.left)+parseInt(curObj.style.width);
  575.                 startY = parseInt(curObj.style.top)+parseInt(curObj.style.height);
  576.                 break;
  577.               case "handletr":
  578.                 startX = parseInt(curObj.style.left);
  579.                 startY = parseInt(curObj.style.top)+parseInt(curObj.style.height);
  580.                 break;
  581.               case "handlebl":
  582.                 startX = parseInt(curObj.style.left)+parseInt(curObj.style.width);
  583.                 startY = parseInt(curObj.style.top);
  584.                 break;
  585.               case "handlebr":
  586.                 startX = parseInt(curObj.style.left);
  587.                 startY = parseInt(curObj.style.top);
  588.                 break;
  589.               case "handlet":
  590.                 xlock = true;
  591.                 startY = parseInt(curObj.style.top)+parseInt(curObj.style.height);
  592.                 break;
  593.               case "handleb":
  594.                 xlock = true;
  595.                 startY = parseInt(curObj.style.top);
  596.                 break;
  597.               case "handlel":
  598.                 ylock = true;
  599.                 startX = parseInt(curObj.style.left)+parseInt(curObj.style.width);
  600.                 break;
  601.               case "handler":
  602.                 ylock = true;
  603.                 startX = parseInt(curObj.style.left);
  604.                 break;
  605.               default:
  606.                 return;
  607.             } 
  608.           }
  609.           else{
  610.             currentCir = curObj;
  611.             startX = parseInt(curObj.style.left)+(parseInt(curObj.style.width)/2);
  612.             startY = parseInt(curObj.style.top)+(parseInt(curObj.style.height)/2);
  613.           }
  614.         }
  615.         else if (event.target.getAttribute("class") == "point"){
  616.           dump("down on a point\n");
  617.           selectElement(event.target.parentNode);
  618.           currentPoint = event.target;
  619.           currentPoint.startX = parseInt(event.clientX+window.frames[0].pageXOffset)-(parseInt(currentPoint.style.left)+parseInt(currentPoint.parentNode.style.left));
  620.           currentPoint.startY = parseInt(event.clientY+window.frames[0].pageYOffset)-(parseInt(currentPoint.style.top)+parseInt(currentPoint.parentNode.style.top));
  621.           currentPoly = currentPoint.parentNode;
  622.         }
  623.         else{
  624.           dump(event.target+"\n");
  625.           selectElement(null);
  626.         }
  627.       }
  628.     }
  629.   }
  630. }
  631.  
  632. function clickMouse(event){
  633.   if (event.button == 0){
  634.     dump("body clicked\n");
  635.     //alert(frameDoc.+'\n');
  636.     startX = event.clientX+window.frames[0].pageXOffset;
  637.     startY = event.clientY+window.frames[0].pageYOffset;
  638.     if (currentTool == "poly"){
  639.       if (event.target != currentPoly){
  640.         if (currentPoly != null){
  641.           if (event.target == currentPoly.childNodes[0]){
  642.             polyFinish();
  643.           }
  644.           else if (event.detail == 2){
  645.             polyFinish();
  646.           }
  647.         }
  648.         else{
  649.           Poly();
  650.         }
  651.       }
  652.       else{
  653.         addPoint(event);          
  654.       }
  655.     }
  656.   }
  657. }
  658.  
  659. function changeTool(event, what){
  660.   if (!currentPoly){
  661.     for(i=0; i<4; i++){
  662.       buttonArray[i].setAttribute("toggled", 0);
  663.       if (event.target == buttonArray[i]){
  664.         buttonArray[i].setAttribute("toggled", 1);
  665.       }
  666.     }
  667.     currentTool = what;
  668.     if (currentTool != "pointer"){
  669.       frameDoc.getElementById("bgDiv").style.cursor = "crosshair";
  670.       frameDoc.body.style.cursor = "crosshair";
  671.     }
  672.     else{
  673.       frameDoc.getElementById("bgDiv").style.cursor = "default";
  674.       frameDoc.body.style.cursor = "default";
  675.     }
  676.  
  677.     dump(what+" selected\n");
  678.   }
  679.   else {
  680.     for(i=0; i<4; i++){
  681.       if (event.target == buttonArray[i]){
  682.         buttonArray[i].setAttribute("toggled", 0);
  683.       }
  684.     }
  685.   }
  686. }
  687.  
  688. function zoom(direction, ratio){
  689.   dump('zoom called; ratio='+ratio+'\n');
  690.   if (direction == "in")
  691.     ratio = currentZoom*2;
  692.   else if (direction == "out")
  693.     ratio = currentZoom/2;
  694.  
  695.   if (ratio > 4 || ratio < 1 || ratio == currentZoom)
  696.     return;
  697.  
  698.   if (ratio == 1){
  699.     document.getElementById('Map:ZoomIn').setAttribute('disabled', 'false');
  700.     document.getElementById('Map:ZoomOut').setAttribute('disabled', 'true');
  701.     document.getElementById('Map:Apercent').setAttribute('checked', 'true');
  702.     document.getElementById('Map:Bpercent').setAttribute('checked', 'false');
  703.     document.getElementById('Map:Cpercent').setAttribute('checked', 'false');
  704.   }
  705.   else if (ratio == 4){
  706.     document.getElementById('Map:ZoomIn').setAttribute('disabled', 'true');
  707.     document.getElementById('Map:ZoomOut').setAttribute('disabled', 'false');
  708.     document.getElementById('Map:Apercent').setAttribute('checked', 'false');
  709.     document.getElementById('Map:Bpercent').setAttribute('checked', 'false');
  710.     document.getElementById('Map:Cpercent').setAttribute('checked', 'true');
  711.   }
  712.   else {
  713.     document.getElementById('Map:ZoomIn').setAttribute('disabled', 'false');
  714.     document.getElementById('Map:ZoomOut').setAttribute('disabled', 'false');
  715.     document.getElementById('Map:Apercent').setAttribute('checked', 'false');
  716.     document.getElementById('Map:Bpercent').setAttribute('checked', 'true');
  717.     document.getElementById('Map:Cpercent').setAttribute('checked', 'false');
  718.   }
  719.  
  720.   objList = frameDoc.getElementsByName("hotspot");
  721.   len = objList.length;
  722.   for(i=0; i<len; i++){
  723.     if (ratio > currentZoom){
  724.       objList[i].style.width = (parseInt(objList[i].style.width)*(ratio/currentZoom))+"px";
  725.       objList[i].style.height = (parseInt(objList[i].style.height)*(ratio/currentZoom))+"px";
  726.       objList[i].style.top = (parseInt(objList[i].style.top)*(ratio/currentZoom))+"px";
  727.       objList[i].style.left = (parseInt(objList[i].style.left)*(ratio/currentZoom))+"px";
  728.     }
  729.     else{
  730.       objList[i].style.width = (parseInt(objList[i].style.width)/(currentZoom/ratio))+"px";
  731.       objList[i].style.height = (parseInt(objList[i].style.height)/(currentZoom/ratio))+"px";
  732.       objList[i].style.top = (parseInt(objList[i].style.top)/(currentZoom/ratio))+"px";
  733.       objList[i].style.left = (parseInt(objList[i].style.left)/(currentZoom/ratio))+"px";
  734.     }
  735.     if (objList[i].getAttribute("class") == "poly"){
  736.       pointList = objList[i].childNodes;
  737.       plen = pointList.length;
  738.       dump('i='+i+'\n');
  739.       for(j=0; j<plen; j++){
  740.         dump('i='+i+'\n');
  741.         if (ratio > currentZoom){
  742.           pointList[j].style.top = (parseInt(pointList[j].style.top)*(ratio/currentZoom))+"px";
  743.           pointList[j].style.left = (parseInt(pointList[j].style.left)*(ratio/currentZoom))+"px";
  744.         }
  745.         else{
  746.           pointList[j].style.top = (parseInt(pointList[j].style.top)/(currentZoom/ratio))+"px";
  747.           pointList[j].style.left = (parseInt(pointList[j].style.left)/(currentZoom/ratio))+"px";
  748.         }
  749.       }
  750.       currentPoly = objList[i];
  751.       polyFinish(null, true);
  752.       currentPoly = null;
  753.     }
  754.     dump('i='+i+'\n');
  755.   }
  756.   
  757.   imgEl = frameDoc.getElementById("mainImg");
  758.   bgDiv = frameDoc.getElementById("bgDiv");
  759.   dump(imgEl.getAttribute("width")+'\n');
  760.   if (ratio > currentZoom){
  761.     imgEl.setAttribute("width", (parseInt(imgEl.offsetWidth)*(ratio/currentZoom)));
  762.     imgEl.setAttribute("height", (parseInt(imgEl.offsetHeight)*(ratio/currentZoom)));
  763.     bgDiv.style.width = imgEl.offsetWidth;
  764.     bgDiv.style.height = imgEl.offsetHeight;
  765.   }
  766.   else{
  767.     imgEl.setAttribute("width", (parseInt(imgEl.offsetWidth)/(currentZoom/ratio)));
  768.     imgEl.setAttribute("height", (parseInt(imgEl.offsetHeight)/(currentZoom/ratio)));
  769.     bgDiv.style.width = imgEl.offsetWidth;
  770.     bgDiv.style.height = imgEl.offsetHeight;
  771.   }
  772.   currentZoom = ratio;  
  773. }
  774.  
  775. function cutCopy(cut){
  776.   len = currentElement.length;
  777.   if (len >= 1){
  778.     clipBoard = [];
  779.     for (i=0; i<len; i++){
  780.       el = currentElement[i];
  781.       if (el.className == 'rect'){
  782.         coords = parseInt(el.style.left)+","+parseInt(el.style.top)+","+(parseInt(el.style.left)+parseInt(el.style.width))+","+(parseInt(el.style.top)+parseInt(el.style.height));
  783.         href = el.getAttribute('hsHref');
  784.         target = el.getAttribute('hsTarget');
  785.         alt = el.getAttribute('hsAlt');
  786.         clipBoard[i] = 'Rect(\"'+coords+'\", \"'+href+'\", \"'+target+'\", \"'+alt+'\", true)';
  787.       }
  788.       else if (el.className == 'cir'){
  789.         radius = Math.floor(parseInt(el.style.width)/2);
  790.         coords = (parseInt(el.style.left)+radius)+","+(parseInt(el.style.top)+radius)+","+radius;
  791.         href = el.getAttribute('href');
  792.         target = el.getAttribute('hsTarget');
  793.         alt = el.getAttribute('hsAlt');
  794.         clipBoard[i] = 'Circle(\"'+coords+'\", \"'+href+'\", \"'+target+'\", \"'+alt+'\", true)';
  795.       }
  796.       else{
  797.         var coords = '';
  798.         var pointlen = el.childNodes.length;
  799.         for(j=0; j<pointlen; j++){
  800.           coords += (parseInt(el.style.left)+parseInt(el.childNodes[j].style.left))+","+(parseInt(el.style.top)+parseInt(el.childNodes[j].style.top))+",";
  801.         }
  802.         coords = coords.substring(0, (coords.length-1));
  803.         href = el.getAttribute('href');
  804.         target = el.getAttribute('hsTarget');
  805.         alt = el.getAttribute('hsAlt');
  806.         clipBoard[i] = 'Poly(\"'+coords+'\", \"'+href+'\", \"'+target+'\", \"'+alt+'\", true)';
  807.       }
  808.       if (cut){
  809.         deleteElement(el);
  810.       }
  811.     }
  812.     document.getElementById('Map:Paste').setAttribute('disabled', 'false');
  813.   }
  814. }
  815.  
  816. function paste(){
  817.   len = clipBoard.length;
  818.   func = '';
  819.   for (i=0; i<len; i++){
  820.     func += clipBoard[i]+'\;';
  821.   }
  822.   eval(func);
  823. }
  824.  
  825.   function nudge(event, dir){
  826.   /*prevent scrolling
  827.   event.stopPropagation(); 
  828.   event.preventDefault();*/
  829.  
  830.   len = currentElement.length;
  831.   amount = 1;
  832.   if (event.shiftKey)
  833.     amount = 5;
  834.  
  835.   
  836.   boundRectTop = 1000000;
  837.   boundRectLeft = 1000000;
  838.   for (i=0; i<len; i++){
  839.     curTop = parseInt(currentElement[i].style.top);
  840.     curLeft = parseInt(currentElement[i].style.left);
  841.     if (curTop < boundRectTop)
  842.       boundRectTop = curTop;
  843.     if (curLeft < boundRectLeft)
  844.       boundRectLeft = curLeft;
  845.   }
  846.  
  847.   for (i=0; i<len; i++){
  848.     if (dir == "up"){
  849.       curTop = parseInt(currentElement[i].style.top);
  850.       if (boundRectTop >= amount)
  851.         currentElement[i].style.top = (curTop-amount) + "px";
  852.       else
  853.         currentElement[i].style.top = (curTop-boundRectTop) + "px";
  854.     }
  855.     else if (dir == "left"){
  856.       curLeft = parseInt(currentElement[i].style.left);
  857.       if (boundRectLeft >= amount)
  858.         currentElement[i].style.left = (curLeft-amount) + "px";
  859.       else
  860.         currentElement[i].style.left = (curLeft-boundRectLeft) + "px";
  861.     }
  862.     else if (dir == "down"){
  863.       curTop = parseInt(currentElement[i].style.top);
  864.       currentElement[i].style.top = (curTop+amount) + "px";
  865.     }
  866.     else if (dir == "right"){
  867.       curLeft = parseInt(currentElement[i].style.left);
  868.       currentElement[i].style.left = (curLeft+amount) + "px";
  869.     }
  870.   }
  871. }
  872.