/* Copyright 2001 Adobe Systems. You may copy, modify, and distribute
*  this file, if you include this notice & do not charge for the distribution.
*  This file is provided "AS-IS" without warranties of any kind, including any
*  implied warranties.
*
*  Initial Author and Architect:  Glen H. Gersten
*
*/
var path = location.href.substring(0, location.href.lastIndexOf('/'))
var thisPath = path + '/'
var isNav
var screenWidth, screenHeight, screenCenterX, screenCenterY
var bgWidth, bgHeight
var mapDoc = "svg/draw.svgz"
var textFile = thisPath + "text.html"
var textFileSize = "WIDTH=400,HEIGHT=270,resizable,dependent"
var bgFile = thisPath + "bgrounds.html"
var bgFileSize = "WIDTH=420,HEIGHT=270,resizable,dependent"
var mapWidthSmall = 440
var mapHeightSmall = 280
var mapWidthLarge = 600
var mapHeightLarge = 440
var palWidthSmall = 440
var palHeightSmall = 120
var palWidthLarge = 600
var palHeightLarge = 160
var symbolDim = 25
var origX, origY, endX, endY
var imgPath = thisPath + 'images/'
var SVGDoc, paletteDoc, text, drawBoard, protoPath, protoElem
var crosshair, cursRect, cursEllipse, cursLine
var buttonState
var pointCount = -1
var lastX, lastY
var pointIncr = 5
var drawNum = 0
var rectNum = 0
var ellipseNum = 0
var lineNum = 0
var pencilNum = 0
var hilighterNum = 0
var symbolNum = 0
var textNum = 0
var drawIntervalID
var tool = "select"
var toolType = "select"
var itemSelected = "select"
var oldSelect = "select"
var tabSelected = "drawButton"
var onWidth = 3
var offWidth = 1
var selColor = "#F8C412"
var normColor = "#FFFFFF"
var onTabColor = selColor
var offTabColor = "#1A5EA8"
var onTextColor = "#333333"
var offTextColor = "#FFFFFF"
var setFill = "none"
var setStroke = "#000000"
var setStrokeWidth = "1"
var setOpacity = "none"
var hiStroke = "#00FFFF"
var hiStrokeWidth = "8"
var hiOpacity = ".50"
var setFont = "AdobeCorpID-MyriadBdScn"
var setFontName = "Myriad"
var setFontSize = "18"
var tmpFont, tmpFontName, tmpFontSize
var preSelColor = "#333333"
var tmpSelColor = "blue"
var buttonFG = "#E6E6E6"
var buttonBG = "#000000"
var symbolWidth = 20
var symbolHeight = 20
var oldStyle
var oldSel
var oldOptionStyle
var oldOptionSel
var oldRoll
var oldTab, oldText, oldButton, oldTip
var elemType, elemSelected, elemStyle, elemTransform
var xOrig, yOrig
var xPos, yPos
var xDiff, yDiff
var xTrans, yTrans
var isTrans
var moveable
var rotatable
var boxDistWidth = 25
var boxDist = boxDistWidth /2
var boxWidth, boxHeight
var minSize = boxDistWidth +5
var rectHeight, rectWidth
var centerX, centerY
var endX, endY
var menuStatus = "closed"
var textStatus = "closed"
var selBoxGroup
var selectType
var newWindow
var curText
var textMode 
var textChange
var textStyleChange
var oldTextElem
var drawState = ""
var closingStatus
var curZoom = 1
var curZoomLevel = 2
var initDrawZoomLevel
var drawZoom = 1
var deleteTrack
var intervalID
var curWindow
var bgCur = "blank.gif"
var bgTmp
var bgSave = bgCur
var bgSaveID = "thumb_1"
var optionSelID
var optionSelected
var moveHandler = nothing
var upHandler = nothing
points = new Array()
overlayNames = new Array()
menuOn = hideMult
menuOff = showMult
var checkNS = navigator.appName.indexOf("Netscape") != -1;
var checkVer = navigator.appVersion.substring(0, 1)
if (checkNS && checkVer < 5) isNav = true
function init() {
SVGDoc = this.document.map.getSVGDocument()
SVGElem = SVGDoc.getFirstChild()
 crosshair = SVGDoc.getElementById('crosshair')
frame = SVGDoc.getElementById('bg')
drawBoard = SVGDoc.getElementById('drawBoard')
canvas = SVGDoc.getElementById('canvas')
background = SVGDoc.getElementById('background')
handler = SVGDoc.getElementById('handler')
bgControl = SVGDoc.getElementById('bgControl')
overlays = SVGDoc.getElementById('overlays')
selControl = SVGDoc.getElementById('selControl')
preSelBox = SVGDoc.getElementById('preSelBox')
selBoxGroup = SVGDoc.getElementById('selBox')
selBoxes = SVGDoc.getElementById('boxes')
selBoxTool_1 = SVGDoc.getElementById('tool_1')
selBoxTool_2 = SVGDoc.getElementById('tool_2')
selBoxTool_3 = SVGDoc.getElementById('tool_3')
selBoxTool_4 = SVGDoc.getElementById('tool_4')
if (isNav) {
if (defSize == "large") {
screenWidth = mapWidthLarge
screenHeight = mapHeightLarge
} else {
screenWidth = mapWidthSmall
screenHeight = mapHeightSmall
}
} else {
screenWidth = document.map.getAttribute('width')
screenHeight = document.map.getAttribute('height')
}
screenCenterX = screenWidth/2
screenCenterY = screenHeight/2
bgWidth = screenWidth
bgHeight = screenHeight
if (splashLoad == "false" && ! isNav) mapSize(screenWidth, screenHeight)
show(frame)
show(background)
var mapLink = background.getAttribute('xlink:href')
mapSrc = mapLink.substring(mapLink.indexOf('/') +1)
}
function initPal() {
paletteDoc = this.document.palette.getSVGDocument()
paletteElem = paletteDoc.getFirstChild()
selectRoll = paletteDoc.getElementById('selectRoll')
pencilRoll = paletteDoc.getElementById('pencilRoll')
hilighterRoll = paletteDoc.getElementById('hilighterRoll')
rectRoll = paletteDoc.getElementById('rectRoll')
ellipseRoll = paletteDoc.getElementById('ellipseRoll')
lineRoll = paletteDoc.getElementById('lineRoll')
textRoll = paletteDoc.getElementById('textRoll')
protoRectangle = paletteDoc.getElementById('protoRectangle')
protoEllipse = paletteDoc.getElementById('protoEllipse')
protoLine = paletteDoc.getElementById('protoLine')
protoPath = paletteDoc.getElementById('protoPath')
colorMenu = paletteDoc.getElementById('colorMenu')
fillColor = paletteDoc.getElementById('fillColor')
noFillColor = paletteDoc.getElementById('noFillColor')
strokeColor = paletteDoc.getElementById('strokeColor')
noStrokeColor = paletteDoc.getElementById('noStrokeColor')
strokeWidth = paletteDoc.getElementById('strokeWidth')
strokeDisplay = paletteDoc.getElementById('strokeDisplay').getFirstChild().getFirstChild()
strokeWidthMenu = paletteDoc.getElementById('strokeWidthMenu')
strokeWidthOptions = paletteDoc.getElementById('strokeWidthOptions')
opacityDisplay = paletteDoc.getElementById('opacityDisplay').getFirstChild().getFirstChild()
opacityExp = paletteDoc.getElementById('opacityExp')
opacityMenu = paletteDoc.getElementById('opacityMenu')
opacityOptions = paletteDoc.getElementById('opacityOptions')
optionMenu = paletteDoc.getElementById('optionMenu')
deleteFlyout = paletteDoc.getElementById('deleteFlyout')
paletteCover = paletteDoc.getElementById('paletteCover')
fillCover = paletteDoc.getElementById('fillCover')
nullColorCover = paletteDoc.getElementById('nullColorCover')
lineCover = paletteDoc.getElementById('lineCover')
widthCover = paletteDoc.getElementById('widthCover')
editCover = paletteDoc.getElementById('editCover')
deleteCover = paletteDoc.getElementById('deleteCover')
bgCover = paletteDoc.getElementById('bgCover')
skinsCover = paletteDoc.getElementById('skinsCover')
delElementCover = paletteDoc.getElementById('delElementCover')
if (splashLoad == "false") {
smMapCover = paletteDoc.getElementById('smMapCover')
largeMapCover = paletteDoc.getElementById('largeMapCover')
if (isNav) {
if (defSize == "large") {
paletteWidth = palWidthLarge
} else {
paletteWidth = palWidthSmall
}
} else {
paletteWidth = document.palette.getAttribute('width') -0
}
if (paletteWidth > 450) {
curMapSize = "big"
if (smMapCover && largeMapCover) {
menuOn(smMapCover)
menuOff(largeMapCover)
}
} else {
curMapSize = "small"
} 
panelSwitch('navButton')
hide(paletteCover)
menuOff(bgCover)
}
}
function initOverlay(oName) {
loaderDoc = this.document.loader.getSVGDocument()
loadData = loaderDoc.getElementById(oName)
var newOverlay = nodeClone(loadData)
show(newOverlay)
overlays.appendChild(newOverlay)
}
function initText() {
textDoc = newWindow.document.textMenu.getSVGDocument()
typeFaceMenu = textDoc.getElementById('typeFaceMenu')
typeDisplay = textDoc.getElementById('typeDisplay').getFirstChild()
fontSizeMenu = textDoc.getElementById('fontSizeMenu')
fontSizeDisplay = textDoc.getElementById('fontSizeDisplay').getFirstChild().getFirstChild()
textPrep()
}
function initTextBanner() {
textBannerDoc = newWindow.document.textBanner.getSVGDocument()
textBanner = textBannerDoc.getElementById('textBanner').getFirstChild().getFirstChild()
}
function initBg() {
bgDoc = newWindow.document.bgrounds.getSVGDocument()
var selBgElem = bgDoc.getElementById(bgSaveID)
var selBgOutline = selBgElem.getFirstChild().getNextSibling()
show(selBgOutline)
optionSelected = selBgOutline
optionSelID = bgSaveID
}
function initButtons() {
buttonDoc = newWindow.document.buttons.getSVGDocument()
okButton = buttonDoc.getElementById('OK')
if (curWindow == "bgrounds") {
okButton.setAttribute('onclick', 'mainWin.bgOK()')
}
}
function buttonDown(mouseEvt) {
if (mouseEvt.getButton() == 0) {
hide(preSelBox)
menuOff(delElementCover)
elemSelected = null
elemType = null
buttonState = "down"
switch (tool) {
case "draw":
drawNum++
break
case "rect":
rectNum++
break
case "ellipse":
ellipseNum++
break
case "line":
lineNum++
break
case "pencil":
pencilNum++
break
case "hilighter":
hilighterNum++
break
}
origX = mouseEvt.getClientX()
origY = mouseEvt.getClientY()
pointCount = 0
}
}
function buttonUp() {
if (buttonState) {
if (drawIntervalID) {
clearInterval(drawIntervalID)
drawIntervalID = null
}
drawPath()
var elemName = tool + "_" + eval(tool + "Num")
var elemNode = SVGDoc.getElementById(elemName)
if (elemNode) {
elemSelected = elemNode
selectType = "temp"
var thisElem = elemSelected.getFirstChild().getNextSibling()
elemStyle = thisElem.getStyle()
elemType = tool
elemTransform = null
boxer(thisElem)
boxTransform(preSelBox)
boxMove(preSelBox)
preSelBox.getStyle().setProperty('stroke', tmpSelColor)
show(preSelBox)
menuOn(delElementCover)
}
buttonState = null
origX = null
origY = null
lastX = null
lastY = null
thisX = null
thisY = null
rectHeight = null
rectWidth = null
radiusX = null
radiusY = null
centerX = null
centerY = null
endX = null
endY = null
pointCount = -1
points = new Array()
}
}
function moveCursor(mouseEvt) {
var X = mouseEvt.getClientX()
var Y = mouseEvt.getClientY()
var transform = "translate(" + X + " " + Y + ")";
crosshair.setAttribute("transform", transform )
if (buttonState == "down") {
if (toolType == "Path") {
if (pointCount != "-1") {
if (! lastX && ! lastY) {
lastX = Math.abs(X)
lastY = Math.abs(Y)
}
thisX = Math.abs(X)
thisY = Math.abs(Y)
var changeX = Math.abs(eval(lastX - thisX))
var changeY = Math.abs(eval(lastY - thisY))
if (changeX >= pointIncr || changeY >= pointIncr) {
pointCount++
points[pointCount] = X + " " + Y
lastX = thisX
lastY = thisY
}
}
if (! drawIntervalID) {
drawIntervalID = setInterval("drawPath()", 50)
}
} else if (toolType == "Rectangle") {
if (Y - origY > 5) {
rectHeight = Y - origY
} else {
rectHeight = 5
}
if (X - origX > 5) {
rectWidth = X - origX
} else {
rectWidth = 5
}
if (! drawIntervalID) {
drawIntervalID = setInterval("drawRect()", 50)
}
} else if (toolType == "Ellipse") {
if (X - origX > 5) {
radiusX = (X - origX)/2
} else {
radiusX = 2
}
if (Y - origY > 5) {
radiusY = (Y - origY)/2
} else {
radiusY = 2
}
centerX = origX + radiusX
centerY = origY + radiusY
if (! drawIntervalID) {
drawIntervalID = setInterval("drawEllipse()", 50)
}
} else if (toolType == "Line") {
endX = X
endY = Y
if (! drawIntervalID) {
drawIntervalID = setInterval("drawLine()", 50)
}
}
}
}
function drawPath() {
var origin = "M " + origX + " " + origY + " L"
var pointStr = points.join(" ")
var thisPath = origin + pointStr
if (pointStr.length > 2) {
var pathID = tool + "_" + eval(tool + "Num")
var oldCheck = SVGDoc.getElementById(pathID)
if (oldCheck) {
var oldPath = oldCheck.getFirstChild().getNextSibling()
oldPath.setAttribute('d', thisPath)
} else {
newNode = nodeClone(protoElem)
newNode.setAttribute('id', pathID)
newPath = newNode.getFirstChild().getNextSibling()
var styleStr = whichStyle()
newPath.setAttribute('style', styleStr)
newPath.setAttribute('d', thisPath)
drawBoard.appendChild(newNode)
}
}
}
function drawRect() {
var elemID = "rect_" + rectNum
var oldCheck = SVGDoc.getElementById(elemID)
if (oldCheck) {
var oldElem = oldCheck.getFirstChild().getNextSibling()
oldElem.setAttribute('height', rectHeight)
oldElem.setAttribute('width', rectWidth)
} else {
newNode = nodeClone(protoElem)
newNode.setAttribute('id', elemID)
newElem = newNode.getFirstChild().getNextSibling()
newElem.setAttribute('x', origX)
newElem.setAttribute('y', origY)
newElem.setAttribute('height', rectHeight)
newElem.setAttribute('width', rectWidth)
var styleStr = whichStyle()
newElem.setAttribute('style', styleStr)
drawBoard.appendChild(newNode)
}
}
function drawEllipse() {
var elemID = "ellipse_" + ellipseNum
var oldCheck = SVGDoc.getElementById(elemID)
if (oldCheck) {
var oldElem = oldCheck.getFirstChild().getNextSibling()
oldElem.setAttribute('cx', centerX)
oldElem.setAttribute('cy', centerY)
oldElem.setAttribute('rx', radiusX)
oldElem.setAttribute('ry', radiusY)
} else {
newNode = nodeClone(protoElem)
newNode.setAttribute('id', elemID)
newElem = newNode.getFirstChild().getNextSibling()
newElem.setAttribute('cx', centerX)
newElem.setAttribute('cy', centerY)
newElem.setAttribute('rx', radiusX)
newElem.setAttribute('ry', radiusY)
var styleStr = whichStyle()
newElem.setAttribute('style', styleStr)
drawBoard.appendChild(newNode)
}
}
function drawLine() {
var elemID = "line_" + lineNum
var oldCheck = SVGDoc.getElementById(elemID)
if (oldCheck) {
var oldElem = oldCheck.getFirstChild().getNextSibling()
oldElem.setAttribute('x2', endX)
oldElem.setAttribute('y2', endY)
} else {
newNode = nodeClone(protoElem)
newNode.setAttribute('id', elemID)
newElem = newNode.getFirstChild().getNextSibling()
newElem.setAttribute('x1', origX)
newElem.setAttribute('y1', origY)
newElem.setAttribute('x2', endX)
newElem.setAttribute('y2', endY)
var styleStr = whichStyle()
newElem.setAttribute('style', styleStr)
drawBoard.appendChild(newNode)
}
}
function onCanvas() {
show(crosshair)
}
function offCanvas() {
hide(crosshair)
}
function textPrep() {
if (newWindow) {
var textForm = newWindow.document.textForm
if (textMode) {
var textStr = textMode + "  Text"
textBanner.setData(textStr)
}
if (curText) {
textForm.textStr.value = curText
}
menuSet('font-family', 'font-size')
}
}
function text() {
if (newWindow) {
textHandler('ok')
}
}
function textApply() {
if (newWindow) {
textHandler('apply')
}
}
function textEdit() {
textMode = "Edit"
textRead()
windowOpen('text')
}
function textHandler(button) {
var textForm = newWindow.document.textForm
var thisText = textForm.textStr.value + ""
if (thisText) {
if (elemSelected) {
if (curText && curText != thisText) {
textCreate(thisText, 'temp')
textChange = "yes"
}
if (tmpFont) {
elemStyle.setProperty('font-family', tmpFont)
if (button == "ok") {
setFont = tmpFont
setFontName = tmpFontName
}
textStyleChange = "yes"
}
if (tmpFontSize) {
var thisSize = tmpFontSize
if (isMac == "yes") {
var lines = thisText.split('\r')
} else {
var lines = thisText.split('\n')
}
if (lines.length >1) {
var t
var tspanLevelY = 0
var tspanList = elemSelected.getElementsByTagName('tspan')
for (t=0; t < tspanList.getLength(); t++) {
tspanList.item(t).setAttribute('y', tspanLevelY)
tspanLevelY = tspanLevelY + thisSize
}
}
elemStyle.setProperty('font-size', tmpFontSize)
if (button == "ok") setFontSize = tmpFontSize
textStyleChange = "yes"
}
if (textStyleChange) {
textSelect(elemSelected.getAttribute('id'))
if (button == "ok") textStyleChange = null
}
if (button == "ok") {
textChange = null
newWindow.close()
}
} else {
if (button == "ok") {
textCreate(thisText, 'final')
textChange = null
textStyleChange = null
} else {
textCreate(thisText, 'temp')
textChange = "yes"
}
}
} else {
alert("You must enter a text string or click Cancel.\nTo delete text, please use the delete option")
}
}
function textCreate(thisText, state) {
tool = 'text'
if (state == "temp") {
if (tmpFont || tmpFontName || tmpFontSize) {
var curFont = setFont
var curFontName = setFontName
var curFontSize = setFontSize
}
curText = thisText
}
if (tmpFont) setFont = tmpFont
if (tmpFontName) setFontName = tmpFontName
if (tmpFontSize) setFontSize = tmpFontSize
var thisHeight = 0
var thisSize = setFontSize -0
textNum++
if (isMac == "yes") {
var lines = thisText.split('\r')
} else {
var lines = thisText.split('\n')
}
var groupElem = SVGDoc.createElement('g')
var nameStr = "text_" + textNum
groupElem.setAttribute('id', nameStr)
var textElem = SVGDoc.createElement('text')
if (lines.length == 1) {
var textNode = SVGDoc.createTextNode(thisText)
textElem.appendChild(textNode)
} else {
var tspan, textNode, i
var tspanLevelY = 0
for (i=0; i < lines.length; i++) {
tspan = SVGDoc.createElement('tspan')
tspan.setAttribute('x', '0')
tspan.setAttribute('y', tspanLevelY)
var returnLoc = lines[i].indexOf("\r")
if (returnLoc != -1) {
lines[i] = lines[i].substring(0, returnLoc)
}
textNode = SVGDoc.createTextNode(lines[i])
tspan.appendChild(textNode)
textElem.appendChild(tspan)
tspanLevelY = tspanLevelY + thisSize + 5
}
thisHeight = tspanLevelY
}
if (setFill == "none") setFill = "#000000"
var styleStr = whichStyle()
textElem.setAttribute('style', styleStr)
if (state == "temp" && curFont) {
setFont = curFont
setFontName = curFontName
setFontSize = curFontSize
}
groupElem.appendChild(textElem)
var textX = screenCenterX
var textY = screenCenterY - thisHeight/2
if (elemSelected) {
elemTransform = elemSelected.getAttribute('transform')
}
if (! elemTransform) {
var thisTransform = 'matrix(1 0 0 1 30 ' + textY + ')'
} else {
var thisTransform = elemTransform
}
groupElem.setAttribute('transform', thisTransform)
if (elemSelected) {
 drawBoard.replaceChild(groupElem, elemSelected)
if (! oldTextElem) oldTextElem = elemSelected
} else {
drawBoard.appendChild(groupElem)
}
if (state == "final") {
newWindow.close()
}
textSelect(nameStr)
}
function textSelect(nameStr) {
elemType = "text"
var thisGroup = SVGDoc.getElementById(nameStr)
var thisList = thisGroup.getElementsByTagName('text')
var thisElem = thisList.item(0)
elemSelected = thisGroup
elemStyle = thisElem.getStyle()
elemTransform = thisGroup.getAttribute('transform')
selectBox(thisElem)
menuUpdate()
}
function textRead() {
var thisElem, c, childNode, nodeType, thisText
curText = null
var thisList = elemSelected.getElementsByTagName('text')
thisElem = thisList.item(0)
var children = thisElem.getChildNodes()
var childNum = children.getLength()
for (c=0; c < childNum; c++) {
childNode = children.item(c)
nodeType = childNode.getNodeType() -0
while (nodeType != 3) {
childNode = childNode.getFirstChild()
nodeType = childNode.getNodeType() -0
}
thisText = childNode.getData()
if (curText) {
curText = curText + "\n" + thisText
} else {
curText = thisText
}
}
}
function textDelete() {
deleter(elemSelected)
textNum--
}
function fontDiv(thisFont) {
var thisDiv = 0.0
switch (thisFont) {
case "AdobeCorpID-MyriadBdScn":
thisDiv = 2.0
break
case "Impact":
thisDiv = 1.9
break
case "Palatino-Bold":
thisDiv = 1.6
break
case "Kaufmann":
thisDiv = 2.4
break
case "ComicSansMS":
thisDiv = 1.8
break
}
return thisDiv
}
function nodeClone(thisNode) {
var newCopy = nodeCloneShallow(thisNode)
var children = thisNode.getChildNodes()
var childNum = children.getLength()
var c;
for (c=0; c < childNum; c++) {
var childNode = children.item(c)
var nodeType = childNode.getNodeType() -0
var newChild = nodeClone(childNode)
newCopy.appendChild(newChild)
}
return newCopy
}
function nodeCloneShallow(thisNode) {
var i;
var nodeType = thisNode.getNodeType() -0
var newNode, attrs, attrsLen
switch (nodeType) {
case 1:
newNode = SVGDoc.createElement(thisNode.getTagName())
attrs = thisNode.getAttributes()
attrsLen = attrs.getLength()
for (i = 0; i < attrsLen; i++) {
attrNode = attrs.item(i)
newNode.setAttribute(attrNode.getNodeName(),attrNode.getNodeValue())
}
break
case 2:
newNode = SVGDoc.createAttributeNode(thisNode.getNodeName(), thisNode.getNodeValue())
break
case 3:
newNode = SVGDoc.createTextNode(thisNode.getData())
break
case 8:
newNode = SVGDoc.createCommentNode(thisNode.getData())
break
}
return newNode
}
function cloner(mouseEvt) {
var elemOK, nodeType, tagName
var groupElem = getGroup(mouseEvt)
var thisNode = groupElem.getFirstChild()
while (! elemOK) {
nodeType = thisNode.getNodeType() -0
if (nodeType == 1) {
tagName = thisNode.getTagName() + ""
if (tagName == "g") {
elemOK = "yes"
break
}
}
thisNode = thisNode.getNextSibling()
}
var newSymbol = nodeClone(thisNode)
symbolNum++
var thisName = "symbol_" + symbolNum
newSymbol.setAttribute('id', thisName)
var thisElem = newSymbol.getLastChild().getPreviousSibling()
elemType = "symbol"
boxer(thisElem)
var thisX = screenCenterX - xPos - symbolDim/2 - boxDist
var thisY = screenCenterY - yPos - symbolDim/2 - boxDist
var thisM = new transMatrix(thisX, thisY)
var thisTrans = matrixToString(thisM)
newSymbol.setAttribute('transform', thisTrans)
drawBoard.appendChild(newSymbol)
elemSelected = SVGDoc.getElementById(thisName)
elemStyle = elemSelected.getStyle()
elemTransform = thisTrans
var selElem = elemSelected.getLastChild().getPreviousSibling()
selectBox(thisElem)
menuUpdate()
}
function onTool(mouseEvt) {
var groupElem = getGroup(mouseEvt)
var thisID = groupElem.getAttribute('id') + ""
if (thisID != itemSelected) {
var thisRoll = eval(thisID + 'Roll')
show(thisRoll)
oldRoll = thisRoll
}
var tipName = thisID + "Tip"
var thisTip = paletteDoc.getElementById(tipName)
oldTip = thisTip
show(thisTip)
}
function offTool() {
if (oldRoll) {
hide(oldRoll)
oldRoll = null
}
if (oldTip) {
hide(oldTip)
oldTip = null
}
}
function selectTool(mouseEvt) {
if (mouseEvt.getButton() == 0) {
if (newWindow) {
windowClose()
}
var groupElem = getGroup(mouseEvt)
var thisID = groupElem.getAttribute('id') + ""
doTool(thisID)
}
}
function doTool(thisID) {
if (thisID != itemSelected) {
if (itemSelected) {
var tmpElem = paletteDoc.getElementById(itemSelected)
var unElem = tmpElem.getFirstChild().getNextSibling()
hide(unElem)
unElem.getStyle().setProperty('fill', normColor)
}
itemSelected = thisID
var thisRoll = eval(thisID + 'Roll')
thisRoll.getStyle().setProperty('fill', selColor)
show(thisRoll)
oldRoll = null
var sepIndex = thisID.lastIndexOf('_')
if (sepIndex != "-1") {
tool = thisID.substring(0, sepIndex)
} else {
tool = thisID
}
if (tool != "select") {
deSelector()
show(canvas)
}
switch (tool) {
case "select":
hide(canvas)
toolType = "Select"
protoElem = null
if (elemSelected && selectType == "temp") {
var thisElem = elemSelected.getFirstChild().getNextSibling()
hide(preSelBox)
selectBox(thisElem)
}
break
case "rect":
toolType = "Rectangle"
break
case "ellipse":
toolType = "Ellipse"
break
case "line":
toolType = "Line"
if (setStroke == "none") setStroke = "#000000"
break
case "pencil":
toolType = "Path"
if (setStroke == "none") setStroke = "#000000"
break
case "hilighter":
toolType = "Path"
if (hiStroke == "none") hiStroke = "#00FFFF"
break
case "draw":
toolType = "Path"
setProto(groupElem)
if (setStroke == "none") setStroke = "#000000"
break
case "symbol":
toolType = "Clone"
setProto(groupElem)
break
case "text":
hide(canvas)
toolType = "Text"
if (setFill == "none") setFill = "#000000"
curWindow = "text"
windowOpen('text')
break
}
if (tool != "select" && tool != "draw" &&
tool != "symbol" && tool != "text") {
protoElem = eval("proto" + toolType)
}
if (unElem) menuUpdate() 
}
}
function onItem(mouseEvt) {
var groupElem = getGroup(mouseEvt)
var thisID = groupElem.getAttribute('id') + ""
if (thisID != itemSelected  && thisID != optionSelID) {
var outElem = groupElem.getFirstChild().getNextSibling()
show(outElem)
oldOptionSel = outElem
if (thisID == "op_delete") {
show(deleteFlyout)
} else if (thisID == "op_skins") {
hide(deleteFlyout)
} else if (thisID == "op_back" || thisID == "op_edit"){
hide(deleteFlyout)
}
}
var tipName = thisID + "Tip"
var thisTip = paletteDoc.getElementById(tipName)
if (thisTip) {
oldTip = thisTip
show(thisTip)
}
}
function offItem() {
if (oldOptionSel) {
hide(oldOptionSel)
oldOptionSel = null
}
if (oldTip) {
hide(oldTip)
oldTip = null
}
}
function selOption(mouseEvt) {
if (mouseEvt.getButton() == 0) {
var groupElem = getGroup(mouseEvt)
var thisID = groupElem.getAttribute('id') + ""
var outElem = groupElem.getFirstChild().getNextSibling()
if (thisID != optionSelID) {
if (optionSelected) {
hide(optionSelected)
}
}
optionSelID = thisID
optionSelected = outElem
oldOptionSel = null
}
}
function onOutline(mouseEvt) {
var groupElem = getGroup(mouseEvt)
var thisID = groupElem.getAttribute('id') + ""
if (thisID != itemSelected) {
var outElem = groupElem.getFirstChild().getNextSibling()
var styleStr = outElem.getAttribute('style') + ""
var thisStroke = getStyleValue(styleStr, 'stroke-width') -0
if (! thisStroke) thisStroke = 0
oldOptionSel = outElem.getStyle()
oldOptionStyle = thisStroke
var newStroke = thisStroke + 2
oldOptionSel.setProperty('stroke-width', newStroke)
oldOptionSel.setProperty('stroke', '#000000')
}
}
function offOutline() {
if (oldOptionSel) {
oldOptionSel.setProperty('stroke-width', oldOptionStyle)
oldOptionSel = null
oldOptionStyle = null
}
}
function onTab(mouseEvt) {
var groupElem = getGroup(mouseEvt)
var thisID = groupElem.getAttribute('id') + ""
if (thisID != tabSelected) {
thisText = groupElem.getLastChild().getPreviousSibling()
thisTab = thisText.getPreviousSibling().getPreviousSibling().getStyle()
thisText = thisText.getFirstChild().getStyle()
thisTab.setProperty('fill', onTabColor)
thisText.setProperty('fill', onTextColor)
oldTab = thisTab
oldText = thisText
}
}
function offTab() {
if (oldTab && oldText) {
oldTab.setProperty('fill', offTabColor)
oldText.setProperty('fill', offTextColor)
oldTab = null
oldText = null
}
}
function selTab(mouseEvt) {
var groupElem = getGroup(mouseEvt)
var thisID = groupElem.getAttribute('id') + ""
panelSwitch(thisID)
offTab()
}
function panelSwitch(newTab) {
if (newTab != tabSelected) {
var oldTab = tabSelected
var oldName = oldTab.substring(0, oldTab.indexOf("Button")) + 'Tab'
var newName = newTab.substring(0, newTab.indexOf("Button")) + 'Tab'
var oldPanel = paletteDoc.getElementById(oldName)
var newPanel = paletteDoc.getElementById(newName)
hide(oldPanel)
show(newPanel)
tabSelected = newTab
if (oldName == "drawTab") doTool('select')
if (newName != "drawTab") deSelector()
if (newWindow) windowClose()
if (menuStatus != "closed") popper()
}
}
function popper(menu) {
hideMult(colorMenu, strokeWidthMenu, opacityMenu, optionMenu, deleteFlyout)
offTab()
if (newWindow) windowClose()
if (menu && (menuStatus == "closed" || menuStatus != menu)) {
if (menu == "fill") {
colorMenu.setAttribute('transform', 'translate(340,0)')
show(colorMenu)
menuStatus = "fill"
} else if (menu == "stroke") {
colorMenu.setAttribute('transform', 'translate(0,0)')
show(colorMenu)
menuStatus = "stroke"
} else if (menu == "strokeWidth") {
show(strokeWidthMenu)
menuStatus = "strokeWidth"
} else if (menu == "opacity") {
show(opacityMenu)
menuStatus = "opacity"
} else if (menu == "option") {
show(optionMenu)
menuStatus = "option"
}
} else {
menuStatus = "closed"
}
}
function popperText(menu) {
hideMult(typeFaceMenu, fontSizeMenu)
offTab()
if (menu && (textStatus == "closed" || textStatus != menu)) {
if (menu == "font-family") {
show(typeFaceMenu)
textStatus = "font-family"
} else if (menu == "font-size") {
show(fontSizeMenu)
textStatus = "font-size"
}
} else {
textStatus = "closed"
}
}
function selectOption(mouseEvt) {
var optionCall
thisOption = strip(mouseEvt)
if (menuStatus == "option") {
if (thisOption == "delElement") {
deleter(elemSelected)
} else if (thisOption == "delAll" ) {
deleteAll()
} else if (thisOption == "edit" ) {
optionCall = "text"
} else if (thisOption == "back" ) {
optionCall = "bgrounds"
}
} else {
if (newWindow) {
setStyle(textStatus)
menuSet(textStatus)
} else {
setStyle(menuStatus)
menuSet(menuStatus)
}
}
if (newWindow) {
popperText()
} else {
if (thisOption != "delete" && thisOption != "skins") popper()
}
if (optionCall == "text") {
curWindow = "text"
textEdit()
} else if (optionCall == "bgrounds") {
if (tool != "select") doTool('select')
deSelector()
curWindow = "bgrounds"
windowOpen('bgrounds')
}
}
function onSel(mouseEvt, isItem) {
var thisElem = mouseEvt.getTarget()
if (! elemSelected) {
var thisGroup = getGroup(mouseEvt)
elemType = labelGet(thisGroup)
elemTransform = thisGroup.getAttribute('transform')
if (elemType == "text") {
var thisList = thisGroup.getElementsByTagName('text')
thisElem = thisList.item(0)
} else if (elemType == "symbol") {
thisElem = thisGroup.getLastChild().getPreviousSibling()
}
boxer(thisElem)
boxTransform(preSelBox)
boxMove(preSelBox)
preSelBox.getStyle().setProperty('stroke', preSelColor)
disp(preSelBox, 'inline')
}
}
function offSel() {
if (! elemSelected) {
disp(preSelBox, 'none')
elemType = null
elemTransform = null
selectType = null
}
}
function selector(mouseEvt) {
if (mouseEvt.getButton() == 0) {
panelSwitch('drawButton')
var thisElem = mouseEvt.getTarget()
var thisGroup = getGroup(mouseEvt)
if (elemSelected && elemSelected != thisGroup) deSelector()
if (! elemSelected) {
offSel()
elemType = labelGet(thisGroup)
elemSelected = thisGroup
var styleElem = thisElem
elemTransform = elemSelected.getAttribute('transform')
if (elemType == "text") {
var thisList = thisGroup.getElementsByTagName('text')
thisElem = thisList.item(0)
styleElem = thisElem
} else if (elemType == "symbol") {
styleElem = elemSelected
thisElem = thisGroup.getLastChild().getPreviousSibling()
}
selectBox(thisElem)
var styleStr = styleElem.getAttribute('style') + ""
stylePairs = styleStr.split(';')
for (i=0; i < stylePairs.length; i++) {
data = stylePairs[i].split(':')
var styleProp = data[0]
thisOption = data[1]
setStyle(styleProp, 'selector')
}
elemStyle = styleElem.getStyle()
menuUpdate()
}
}
}
function deSelector() {
if (newWindow) windowClose()
if (elemSelected) {
disp(selBoxGroup, 'none')
disp(preSelBox, 'none')
elemSelected = null
elemStyle = null
elemTransform = null
elemType = null
selectType = null
}
if (menuStatus != "closed") popper()
menuUpdate()
}
function selectBox(thisElem) {
var handleState = boxer(thisElem)
boxTransform(selBoxGroup)
boxMove(selBoxes)
boxToolsMove()
boxHandles(handleState)
show(selBoxGroup)
}
function boxer(thisElem) {
var handleState
if (elemType == "pencil" || elemType == "hilighter" || elemType == "draw") {
var thisData = thisElem.getAttribute('d')
lIndex = thisData.indexOf('L')
coordStr = thisData.substring(2, lIndex -1) +
thisData.substring(lIndex +1)
coords = new Array()
coords = coordStr.split(' ')
var xLarge, xSmall
for (x=0; x < coords.length; x++) {
thisX = coords[x] -0
if (! xLarge) {
xLarge = thisX
} else {
if (thisX > xLarge) xLarge = thisX
}
if (! xSmall) {
xSmall = thisX
} else {
if (thisX < xSmall) xSmall = thisX
}
x++
}
var yLarge, ySmall
for (y=1; y < coords.length; y++) {
thisY = coords[y] -0
if (! yLarge) {
yLarge = thisY
} else {
if (thisY > yLarge) yLarge = thisY
}
if (! ySmall) {
ySmall = thisY
} else {
if (thisY < ySmall) ySmall = thisY
}
y++
}
boxWidth = xLarge - xSmall + boxDistWidth
boxHeight = yLarge - ySmall + boxDistWidth
xPos = xSmall - boxDist
yPos = ySmall - boxDist
if (xPos < 0) xPos = 0
if (yPos < 0) yPos = 0
handleState = 'none'
} else if (elemType == "rect") {
var thisX = thisElem.getAttribute('x') -0
var thisY = thisElem.getAttribute('y') -0
var thisWidth = thisElem.getAttribute('width') -0
var thisHeight = thisElem.getAttribute('height') -0
boxWidth = thisWidth + boxDistWidth
boxHeight = thisHeight + boxDistWidth
xPos = thisX - boxDist
yPos = thisY - boxDist
handleState = 'inline'
} else if (elemType == "ellipse") {
var cX = thisElem.getAttribute('cx') -0
var cY = thisElem.getAttribute('cy') -0
var rX = thisElem.getAttribute('rx') -0
var rY = thisElem.getAttribute('ry') -0
boxWidth = (rX * 2) + boxDistWidth
boxHeight = (rY *2) + boxDistWidth
xPos = cX - rX - boxDist
yPos = cY - rY - boxDist
handleState = 'inline'
} else if (elemType == "line") {
var X1 = thisElem.getAttribute('x1') -0
var Y1 = thisElem.getAttribute('y1') -0
var X2 = thisElem.getAttribute('x2') -0
var Y2 = thisElem.getAttribute('y2') -0
boxWidth = Math.abs(X1 - X2) + boxDistWidth
boxHeight = Math.abs(Y1 - Y2) + boxDistWidth
if (X1 < X2) {
xPos = X1 - boxDist
} else {
xPos = X2 - boxDist
}
if (Y1 < Y2) {
yPos = Y1 - boxDist
} else {
yPos = Y2 - boxDist
}
handleState = 'inline'
} else if (elemType == "text") {
var thisX = thisElem.getAttribute('x') -0
var thisY = thisElem.getAttribute('y') -0
var styleStr = thisElem.getAttribute('style') + ""
var thisFont = getStyleValue(styleStr, 'font-family') + ""
var thisSize = getStyleValue(styleStr, 'font-size') -0
xPos = thisX - boxDist
yPos = thisY - thisSize - boxDist
var children = thisElem.getChildNodes()
var childNum = children.getLength()
var lines = 0
var longest = 1
var numChars = 1
var thisNode, c
for (c=0; c < childNum; c++) {
var childNode = children.item(c)
var nodeType = childNode.getNodeType() -0
while (nodeType != 3) {
childNode = childNode.getFirstChild()
nodeType = childNode.getNodeType() -0
}
numChars = childNode.getLength() -0
if (longest < numChars) longest = numChars
lines++
}
var thisDiv = fontDiv(thisFont)
boxWidth = longest * (thisSize/thisDiv) + boxDistWidth
boxHeight = (thisSize + thisSize/4) * lines + boxDistWidth
handleState = 'none'
} else if (elemType == "symbol") {
var re1 = /\d+/
var re2 = /,\d+/
var thisData = thisElem.getAttribute('d')
var result1 = re1.exec(thisData)
var result2 = re2.exec(thisData)
var xCoord = result1[0]
var yCoord = result2[0].substring(1)
xPos = xCoord - symbolDim - boxDist - 2
yPos = yCoord - symbolDim - boxDist
boxWidth = symbolDim + boxDistWidth
boxHeight = symbolDim + boxDistWidth
handleState = 'none'
}
if (! drawState) {
var groupFind = drawBoard.getElementsByTagName('g')
if (groupFind.getLength() > 0) {
drawState = "yes"
menuOn(deleteCover)
initDrawZoomLevel = curZoomLevel
}
} else {
menuOn(deleteCover)
}
return handleState
}
function boxMove(parent) {
var children = parent.getChildNodes()
var childNum = children.getLength()
var c;
for (c=0; c < childNum; c++) {
var childNode = children.item(c)
var nodeType = childNode.getNodeType() -0
if (nodeType == 1) {
var thisTag = childNode.getTagName() +""
if (thisTag == "rect") {
childNode.setAttribute('x', xPos)
childNode.setAttribute('y', yPos)
childNode.setAttribute('width', boxWidth)
childNode.setAttribute('height', boxHeight)
}
}
}
}
function boxToolsMove() {
var x1 = xPos -20
var y1 = yPos -20
var x2 = x1 + boxWidth -50
var y2 = y1 + boxHeight -50
selBoxTool_1.setAttribute('transform', "translate(" + x1 + ", " + y1 + ")")
selBoxTool_2.setAttribute('transform', "translate(" + x2 + ", " + y1 + ")")
selBoxTool_3.setAttribute('transform', "translate(" + x1 + ", " + y2 + ")")
selBoxTool_4.setAttribute('transform', "translate(" + x2 + ", " + y2 + ")")
}
function boxHandles(state) {
var h, thisID, thisHandle
for (h=1; h <= 4; h++) {
thisID = 'handle_' + h
thisHandle = SVGDoc.getElementById(thisID)
disp(thisHandle, state)
}
}
function boxTransform(thisGroup) {
if (elemTransform) {
thisGroup.setAttribute('transform', elemTransform)
} else {
var checkTransform = thisGroup.getAttribute('transform')
if (checkTransform) thisGroup.removeAttribute('transform')
}
}
function movePrep(mouseEvt) {
if (mouseEvt.getButton() == 0) {
if (elemType != "symbol") panelSwitch('drawButton')
var X = mouseEvt.getClientX() -0
var Y = mouseEvt.getClientY() -0
xDiff = xPos - X
yDiff = yPos - Y
xOrig = xPos
yOrig = yPos
currentM = new getTrans()
moveable = "yes"
var evt
moveHandler = mover
upHandler = moveStop
show(handler)
}
}
function moveStop() {
moveable = null
xDiff = null
yDiff = null
xOrig = null
yOrig = null
isTrans = null
hide(handler)
moveHandler = nothing
upHandler = nothing
}
function mover(mouseEvt) {
if (mouseEvt.getButton() == 0) {
if (moveable == "yes" && xDiff && yDiff) {
var X = mouseEvt.getClientX() -0
var Y = mouseEvt.getClientY() -0
var newX = X + xDiff - xOrig
var newY = Y + yDiff - yOrig
var thisM = new transMatrix(newX, newY)
if (isTrans) {
var transM = new matrixMult(thisM, currentM)
} else {
var transM = thisM
}
var thisTransform = matrixToString(transM)
elemSelected.setAttribute("transform", thisTransform )
selBoxGroup.setAttribute("transform", thisTransform )
}
}
}
function rotatePrep(mouseEvt) {
if (mouseEvt.getButton() == 0) {
if (elemType != "symbol") panelSwitch('drawButton')
var X = mouseEvt.getClientX() -0
var Y = mouseEvt.getClientY() -0
currentM = new getTrans()
boxCx = xPos + boxWidth/2
boxCy = yPos + boxHeight/2
if (isTrans) {
centerM = new matrixPointMult(currentM, boxCx, boxCy)
cX = centerM.x
cY = centerM.y
} else {
cX = boxCx
cY = boxCy
}
p1x = X - cX
p1y = Y - cY
if (p1y != 0 && p1x != 0) {
angle1 = Math.atan2(p1y,p1x)
} else {
angle1 = 0
}
rotatable = "yes"
var evt
moveHandler = rotater
upHandler = rotateStop
show(handler)
}
}
function rotateStop() {
rotatable = null
p1x = null
p1y = null
selCenterX = null
selCenterY = null
p1Length = null
hide(handler)
moveHandler = nothing
upHandler = nothing
}
function rotater(mouseEvt) {
if (mouseEvt.getButton() == 0) {
if (rotatable == "yes") {
var X = mouseEvt.getClientX() -0
var Y = mouseEvt.getClientY() -0
var p2x = X - cX
var p2y = Y - cY
if (p2y != 0 && p2x != 0) {
var angle2 = Math.atan2(p2y, p2x)
} else {
var angle2 = 0
}
var angle = angle2 - angle1
var originM = new transMatrix(-boxCx , -boxCy)
var rotateM = new rotMatrix(angle)
var backM = new transMatrix(boxCx, boxCy)
var tempM = new matrixMult(rotateM, originM)
var transM = new matrixMult(backM, tempM)
if (isTrans) {
var newM = new matrixMult(currentM, transM)
} else {
var newM = transM
}
var thisTransform = matrixToString(newM)
selBoxGroup.setAttribute("transform", thisTransform)
elemSelected.setAttribute("transform", thisTransform)
}
}
}
function raiseElem() {
if (elemType != "symbol") panelSwitch('drawButton')
var nextElem = elemSelected.getNextSibling()
if (nextElem) {
if (nextElem.getNodeType() == 1) {
drawBoard.insertBefore(nextElem, elemSelected)
}
}
}
function lowerElem() {
if (elemType != "symbol") panelSwitch('drawButton')
var prevElem = elemSelected.getPreviousSibling()
if (prevElem) {
if (prevElem.getNodeType() == 1) {
drawBoard.insertBefore(elemSelected, prevElem)
}
}
}
function editElemPrep(mouseEvt) {
if (mouseEvt.getButton() == 0) {
panelSwitch('drawButton')
var X = mouseEvt.getClientX() -0
var Y = mouseEvt.getClientY() -0
currentM = new getTrans()
handleName = mouseEvt.getTarget().getAttribute('id') +""
xOrig = X
yOrig = Y
oXPos = xPos
oYPos = yPos
oBoxWidth = boxWidth
oBoxHeight = boxHeight
editable = "yes"
var evt
moveHandler = editElem
upHandler = editElemStop
show(handler)
}
}
function editElemStop() {
editable = null
xOrig = null
yOrig = null
oXPos  = null
oYPos = null
oBoxWidth = null
oBoxHeight = null
handleName = null
hide(handler)
moveHandler = nothing
upHandler = nothing
}
function editElem(mouseEvt) {
if (mouseEvt.getButton() == 0) {
if (editable == "yes" && xOrig && yOrig) {
var X = mouseEvt.getClientX() -0
var Y = mouseEvt.getClientY() -0
if (isTrans) {
var invM = new matrixInvert(currentM)
var origM = new matrixPointMult(invM, xOrig, yOrig)
var thisM = new matrixPointMult(invM, X, Y)
var newX = thisM.x - origM.x
var newY = thisM.y - origM.y
} else {
var newX = X - xOrig
var newY = Y - yOrig
}
if (handleName == "handle_1") {
if (newX < oBoxWidth - minSize) {
xPos = oXPos + newX
boxWidth = oBoxWidth - newX
}
if (newY < oBoxHeight - minSize) {
yPos = oYPos + newY
boxHeight = oBoxHeight - newY
}
} else if (handleName == "handle_2") {
if (newX + oBoxWidth > minSize) {
boxWidth = oBoxWidth + newX
}
if (newY < oBoxHeight - minSize) {
yPos = oYPos + newY
boxHeight = oBoxHeight - newY
}
} else if (handleName == "handle_3") {
if (newX < oBoxWidth - minSize) {
xPos = oXPos + newX
boxWidth = oBoxWidth - newX
}
if (newY + oBoxHeight > minSize) {
boxHeight = oBoxHeight + newY
}
} else if (handleName == "handle_4") {
if (newX + oBoxWidth > minSize) {
boxWidth = oBoxWidth + newX
}
if (newY + oBoxHeight > minSize) {
boxHeight = oBoxHeight + newY
}
}
var elemX = xPos + boxDist
var elemY = yPos + boxDist
var elemWidth = boxWidth - boxDistWidth
var elemHeight = boxHeight - boxDistWidth
var thisElem = elemSelected.getFirstChild().getNextSibling()
boxMove(selBoxes)
boxToolsMove()
if (elemType == "rect") {
thisElem.setAttribute('x', elemX)
thisElem.setAttribute('y', elemY)
thisElem.setAttribute('width', elemWidth)
thisElem.setAttribute('height', elemHeight)
} else if (elemType == "ellipse") {
var radiusX = elemWidth/2
var radiusY = elemHeight/2
var centerX = elemX + radiusX
var centerY = elemY + radiusY
thisElem.setAttribute('rx', radiusX)
thisElem.setAttribute('ry', radiusY)
thisElem.setAttribute('cx', centerX)
thisElem.setAttribute('cy', centerY)
} else if (elemType == "line") {
var x2 = elemX + elemWidth
var y2 = elemY + elemHeight
var curX1 = thisElem.getAttribute('x1') -0
var curX2 = thisElem.getAttribute('x2') -0
var curY1 = thisElem.getAttribute('y1') -0
var curY2 = thisElem.getAttribute('y2') -0
if (curX1 < curX2) {
thisElem.setAttribute('x1', elemX)
thisElem.setAttribute('x2', x2)
} else {
thisElem.setAttribute('x2', elemX)
thisElem.setAttribute('x1', x2)
}
if (curY1 < curY2) {
thisElem.setAttribute('y1', elemY)
thisElem.setAttribute('y2', y2)
} else {
thisElem.setAttribute('y2', elemY)
thisElem.setAttribute('y1', y2)
}
}
}
}
}
function deleter(delElem, parentNode) {
if (! parentNode) {
parentNode = drawBoard
}
parentNode.removeChild(delElem)
deSelector()
if (drawState) {
var groupFind = drawBoard.getElementsByTagName('g')
if (groupFind.getLength() < 1) {
drawState = null
menuOff(deleteCover, editCover)
initDrawZoomLevel = null
drawZoom = 1
var drawTrans = drawBoard.getAttribute('transform')
if (drawTrans) drawBoard.removeAttribute('transform')
}
}
}
function deleteAll() {
if (drawState) {
var thisNode, childType, i
var c=0
deSelector()
var children = drawBoard.getChildNodes()
var childNum = children.getLength()
for (i=0; i < childNum; i++) {
thisNode = children.item(c)
if (thisNode) {
childType = thisNode.getNodeType() -0
if (childType == 1) {
drawBoard.removeChild(thisNode)
} else {
c++
}
}
}
drawState = null
deleteTrack = null
menuOff(deleteCover, editCover)
initDrawZoomLevel = null
drawZoom = 1
var delTrans = drawBoard.getAttribute('transform')
if (delTrans) drawBoard.removeAttribute('transform')
}
}
function deleteBox(msgType) {
var msg, response
if (! deleteTrack) {
if (msgType == "zoom") {
msg = "You have zoomed out to a point\n" +
"where your drawn elements cannot\n" +
"easily be seen.\n\n" +
"Would you like to delete these elements?"
} else if (msgType == "pan") {
msg = "You have panned to a point where\n" +
"your drawn elements cannot be seen.\n" +
"Would you like to delete these elements?"
}
response = confirm(msg)
if (response) {
deleteAll()
} else {
deleteTrack = "no deletes"
}
} else {
response = false
}
return response
}
function keys(mouseEvt) {
var key = mouseEvt.getKeyCode() +""
if (key == "8" || key == "127") {
if (elemSelected) deleter(elemSelected)
}
}
function getGroup(mouseEvt) {
var thisElem = mouseEvt.getTarget().getParentNode()
var groupElem = getG(thisElem)
return groupElem
}
function getG(groupElem) {
var thisType = groupElem.getTagName() +""
var labelStatus = labelCheck(groupElem)
if (labelStatus == "bad") thisType = "bad"
while (thisType != "g") {
groupElem = groupElem.getParentNode()
thisType = groupElem.getTagName() +""
if (thisType == "g") {
var labelStatus = labelCheck(groupElem)
if (labelStatus == "bad") thisType = "bad"
}
}
return groupElem
}
function labelCheck(elem) {
var thisLabel = labelGet(elem)
if (thisLabel != "draw" && thisLabel != "select" &&
thisLabel == "") {
var labelStatus = "bad"
}
return labelStatus
}
function labelGet(elem) {
var thisID = elem.getAttribute('id') +""
if (thisID == "null") thisID = ""
var sepIndex = thisID.lastIndexOf('_') +""
if (sepIndex != "-1") {
var thisLabel = thisID.substring(0, sepIndex)
} else {
var thisLabel = thisID
}
return thisLabel
}
function show(elem) {
elem.getStyle().setProperty('display', 'inline')
}
function showMult(params) {
var args = showMult.arguments
var argNum = args.length
var a
for (a=0; a < argNum; a++) {
show(args[a])
}
}
function hide(elem) {
elem.getStyle().setProperty('display', 'none')
}
function hideMult(params) {
var args = hideMult.arguments
var argNum = args.length
var a
for (a=0; a < argNum; a++) {
hide(args[a])
}
}
function disp(elem, state) {
elem.getStyle().setProperty('display', state)
}
function strip(mouseEvt) {
var thisOption = mouseEvt.getTarget().getAttribute('id') +""
var unIndex = thisOption.lastIndexOf('_')
if (unIndex != -1 && unIndex > 2) {
thisOption = thisOption.substring(0, unIndex)
}
unIndex = thisOption.indexOf('_') +1
if (unIndex != -1) {
thisOption = thisOption.substring(unIndex)
}
return thisOption
}
function getTrans(thisElem) {
if (thisElem) {
isTrans = thisElem.getAttribute('transform')
} else {
isTrans = elemSelected.getAttribute('transform')
}
if (isTrans) {
var newMatrix = new transStrToMatrix(isTrans)
if (newMatrix.a != "-999999") {
return newMatrix
}
}
}
function setProto(groupElem) {
protoElem = groupElem.getLastChild().getPreviousSibling()
}
function whichStyle() {
var styleStr
if (tool == "rect" || tool == "ellipse") {
styleStr = 'fill:' + setFill + ';stroke:' + setStroke +
';stroke-width:' + setStrokeWidth + ';opacity:' +
setOpacity
} else if (tool == "pencil" || tool == "line") {
styleStr = 'fill:none;stroke:' + setStroke + ';stroke-width:' +
setStrokeWidth + ';opacity:' + setOpacity
} else if (tool == "hilighter") {
styleStr = 'fill:none; ' +
'stroke:' + hiStroke + ';stroke-width:' +
hiStrokeWidth + ';opacity:' + hiOpacity
} else if (tool == "symbol") {
var styleStr = 'opacity:' + hiOpacity
} else if (tool == "text") {
styleStr = 'font-family:' + setFont +';font-size:' +
setFontSize + ';fill:' + setFill + ';opacity:' +
setOpacity + ';text-rendering:geometricPrecision'
}
return styleStr
}
function setStyle(thisStyle, thisCaller) {
var thisTool
if (elemType) {
thisTool = elemType
} else {
thisTool = tool
}
if (thisTool == "hilighter") {
if (thisStyle == "fill") {
var thisValue = thisOption.substring(thisOption.indexOf('_')+1)
if (thisValue.indexOf('#') == -1 && thisValue != "none") {
hiFill = '#' + thisValue
} else {
hiFill = thisValue
}
thisOption = hiFill
} else if (thisStyle == "stroke") {
var thisValue = thisOption.substring(thisOption.indexOf('_')+1)
if (thisValue.indexOf('#') == -1 && thisValue != "none") {
hiStroke = '#' + thisValue
} else {
hiStroke = thisValue
}
thisOption = hiStroke
} else if (thisStyle == "strokeWidth" || thisStyle == "stroke-width") {
widthOption = thisOption.substring(thisOption.indexOf('_')+1)
hiStrokeWidth = widthOption
thisOption = widthOption
} else if (thisStyle == "opacity") {
opacityOption = thisOption.substring(thisOption.indexOf('_')+1) + ""
if (opacityOption == "none") {
hiOpacity = opacityOption
opacityDisplay.setData('100%')
} else {
if (opacityOption.indexOf('.') != -1) {
opacityOption = opacityOption.substring(1)
}
hiOpacity = '.' + opacityOption
}
thisOption = hiOpacity
}
} else if (thisTool == "symbol") {
if (thisStyle == "opacity") {
opacityOption = thisOption.substring(thisOption.indexOf('_')+1) + ""
if (opacityOption == "none") {
setOpacity = opacityOption
opacityDisplay.setData('100%')
} else {
if (opacityOption.indexOf('.') != -1) {
opacityOption = opacityOption.substring(1)
}
setOpacity = '.' + opacityOption
}
thisOption = setOpacity
}
} else {
if (thisStyle == "fill") {
var thisValue = thisOption.substring(thisOption.indexOf('_')+1)
if (setStroke == "none" && thisValue == "none" && thisCaller != "selector") {
alert('Line and Fill Colors cannot both be set to none.')
} else {
if (thisValue.indexOf('#') == -1 && thisValue != "none") {
setFill = '#' + thisValue
} else {
setFill = thisValue
}
}
thisOption = setFill
} else if (thisStyle == "stroke") {
var thisValue = thisOption.substring(thisOption.indexOf('_')+1)
if (setFill == "none" && thisValue == "none") {
alert('Line and Fill Colors cannot both be set to none.')
} else {
if (thisValue.indexOf('#') == -1 && thisValue != "none") {
setStroke = '#' + thisValue
} else {
setStroke = thisValue
}
}
thisOption = setStroke
} else if (thisStyle == "strokeWidth" || thisStyle == "stroke-width") {
widthOption = thisOption.substring(thisOption.indexOf('_')+1)
setStrokeWidth = widthOption
thisOption = widthOption
} else if (thisStyle == "opacity") {
opacityOption = thisOption.substring(thisOption.indexOf('_')+1) + ""
if (opacityOption == "none") {
setOpacity = opacityOption
opacityDisplay.setData('100%')
} else {
if (opacityOption.indexOf('.') != -1) {
opacityOption = opacityOption.substring(1)
}
setOpacity = '.' + opacityOption
}
thisOption = setOpacity
} else if (thisStyle == "font-family") {
var thisValue = thisOption.substring(thisOption.indexOf('_')+1)
switch (thisValue) {
case "Myriad":
tmpFont = "AdobeCorpID-MyriadBdScn"
break
case "Impact":
tmpFont = "Impact"
break
case "Palatino":
tmpFont = "Palatino-Bold"
break
case "Kaufmann":
tmpFont = "Kaufmann"
break
case "Comic":
thisValue = "Comic Sans"
tmpFont = "ComicSansMS"
break
case "AdobeCorpID-MyriadBdScn":
thisValue = "Myriad"
tmpFont = "AdobeCorpID-MyriadBdScn"
break
case "Palatino-Bold":
thisValue = "Palatino"
tmpFont = "Palatino-Bold"
break
case "ComicSansMS":
thisValue = "Comic Sans"
tmpFont = "ComicSansMS"
break
}
tmpFontName = thisValue
thisOption = null
} else if (thisStyle == "font-size") {
var thisValue = thisOption.substring(thisOption.indexOf('_')+1) -0
tmpFontSize = thisValue
thisOption = null
}
}
if (elemSelected && elemStyle && thisOption) {
if (thisStyle == "strokeWidth") thisStyle = "stroke-width"
elemStyle.setProperty(thisStyle, thisOption)
}
}
function menuUpdate() {
var thisTool
if (elemType) {
thisTool = elemType
} else {
thisTool = tool
}
if (thisTool == "pencil" || thisTool == "line" || thisTool == "hilighter") {
menuOn(lineCover, widthCover)
menuOff(fillCover, nullColorCover, editCover)
menuSet('stroke', 'stroke-width', 'opacity')
} else if (thisTool == "text") {
menuOn(fillCover, editCover)
menuOff(lineCover, widthCover, nullColorCover)
menuSet('fill', 'opacity')
} else if (thisTool == "symbol") {
menuOff(fillCover, lineCover, widthCover)
menuSet('opacity')
} else {
menuOn(fillCover, lineCover, widthCover, nullColorCover)
menuOff(editCover)
menuSet('fill', 'stroke', 'stroke-width', 'opacity')
}
if (elemSelected) {
menuOn(delElementCover)
} else {
menuOff(delElementCover)
}
}
function menuSet(params) {
var args = menuSet.arguments
var argNum = args.length
var a, thisStyle
for (a=0; a < argNum; a++) {
thisStyle = args[a]
var thisTool
if (elemType) {
thisTool = elemType
} else {
thisTool = tool
}
if (thisStyle == "fill") {
thisValue = setFill
if (thisValue == "none") {
show(noFillColor)
fillColor.getStyle().setProperty('fill', 'white')
if (setStroke != "none") {
var opColor = setStroke
} else {
var opColor = '#000000'
}
opacityOptions.getStyle().setProperty('fill', opColor)
opacityExp.getStyle().setProperty('fill', opColor)
} else {
hide(noFillColor)
fillColor.getStyle().setProperty('fill', thisValue)
opacityOptions.getStyle().setProperty('fill', thisValue)
opacityExp.getStyle().setProperty('fill', thisValue)
}
} else if (thisStyle == "stroke") {
if (thisTool == "hilighter") {
thisValue = hiStroke
} else {
thisValue = setStroke
}
if (thisValue == "none") {
show(noStrokeColor)
strokeColor.getStyle().setProperty('fill', 'white')
} else {
hide(noStrokeColor)
strokeColor.getStyle().setProperty('fill', thisValue)
if (thisValue == "#FFFFFF") thisValue = "#000000"
strokeWidth.getStyle().setProperty('stroke', thisValue)
strokeWidthOptions.getStyle().setProperty('stroke', thisValue)
if (thisTool == "pencil" || thisTool == "line" || thisTool == "hilighter") { 
opacityOptions.getStyle().setProperty('fill', thisValue)
opacityExp.getStyle().setProperty('fill', thisValue)
}
}
} else if (thisStyle == "strokeWidth" || thisStyle == "stroke-width") {
if (thisTool == "hilighter") {
thisValue = hiStrokeWidth
} else {
thisValue = setStrokeWidth
}
strokeWidth.getStyle().setProperty('stroke-width', thisValue)
var thisText = thisValue + 'pt'
strokeDisplay.setData(thisValue)
} else if (thisStyle == "opacity") {
if (thisTool == "hilighter") {
thisValue = hiOpacity
} else {
thisValue = setOpacity
}
if (thisValue == "none") {
opacityDisplay.setData('100%')
opacityExp.getStyle().setProperty('opacity', 'none')
} else {
if (thisValue.indexOf('.') != -1) {
thisValue = thisValue.substring(1)
}
opacityDisplay.setData(thisValue + '%')
opacityExp.getStyle().setProperty('opacity', '.' + thisValue)
}
} else if (thisStyle == "font-family") {
if (tmpFontName) {
thisValue = tmpFontName
} else {
thisValue = setFontName
}
if (newWindow) {
typeDisplay.setData(thisValue)
}
} else if (thisStyle == "font-size") {
if (tmpFontSize) {
thisValue = tmpFontSize
} else {
thisValue = setFontSize
}
if (newWindow) {
fontSizeDisplay.setData(thisValue)
}
}
}
}
function getStyleValue(styleStr, styleProp) {
var i
stylePairs = styleStr.split(';')
for (i=0; i < stylePairs.length; i++) {
data = stylePairs[i].split(':')
var thisProp = data[0]
var thisValue = data[1]
if (thisProp.indexOf(styleProp) != -1) {
var styleValue = thisValue
break
}
}
return styleValue
}
function windowOpen(winName) {
var thisFile, thisSize
if (! newWindow) {
if (winName == "text") {
thisFile = textFile
thisSize = textFileSize
} else if (winName == "bgrounds") {
thisFile = bgFile
thisSize = bgFileSize
}
if (thisFile && thisSize) {
newWindow = window.open(thisFile, "", thisSize)
newWindow.opener = window
}
}
}
function windowClose() {
if (newWindow) {
newWindow.close()
}
}
function windowReset() {
newWindow = null
if (curWindow == "text") {
if (textChange && elemSelected) {
if (oldTextElem) {
var origElem = drawBoard.replaceChild(oldTextElem, elemSelected)
textSelect(origElem.getAttribute('id'))
} else {
textDelete()
}
}
if (textStyleChange && elemSelected) {
elemStyle.setProperty('font-family', setFont)
elemStyle.setProperty('font-size', setFontSize)
textSelect(elemSelected.getAttribute('id'))
}
} else if (curWindow == "bgrounds") {
if (bgCur != bgSave) changeImg(bgSave)
}
if (tool != "select") doTool('select')
window.focus()
varReset()
}
function varReset() {
curWindow = null
newWindow = null
oldButton = null
curText = null
textMode = "Add"
tmpFont = null
tmpFontName = null
tmpFontSize = null
oldTextElem = null
textDoc = null
typeFaceMenu = null
typeDisplay = null
fontSizeMenu = null
fontSizeDisplay = null
textChange = null
textStyleChange = null
bgTmp = null
optionSelected = null
optionSelID = null
closingStatus = null
}
function onButton(mouseEvt) {
var groupElem = getGroup(mouseEvt)
var fg = groupElem.getLastChild().getPreviousSibling()
var bg = fg.getPreviousSibling().getPreviousSibling()
fg.getStyle().setProperty('stroke', buttonBG)
bg.getStyle().setProperty('stroke', buttonFG)
oldButton = groupElem
}
function offButton() {
if (oldButton) {
var fg = oldButton.getLastChild().getPreviousSibling()
var bg = fg.getPreviousSibling().getPreviousSibling()
fg.getStyle().setProperty('stroke', buttonFG)
bg.getStyle().setProperty('stroke', buttonBG)
oldButton = null
}
}
function splash(mouseEvt) {
if (mouseEvt.getButton() == 0) {
if (intervalID) {
clearInterval(intervalID)
intervalID = null
}
if (splashLoad == "true") {
var x, y
splashCount = 0
intervalID = setInterval("changeWait()", 1)
} else {
hide(paletteCover)
}
}
}
function changeWait() {
if (splashCount >= 0) {
if (intervalID) {
clearInterval(intervalID)
intervalID = null
}
document.map.setSrc(mapDoc)
hide(paletteCover)
}
splashCount++
}
function nothing() {
}
function bgSelect(mouseEvt) {
selOption(mouseEvt)
var groupElem = getGroup(mouseEvt)
var thisList = groupElem.getElementsByTagName('image')
var thisElem = thisList.item(0)
var thisDoc = thisElem.getAttribute('xlink:href') +""
var baseName = thisDoc.substring(thisDoc.lastIndexOf('/') +1, thisDoc.lastIndexOf('_') +1)
var thisExt = thisDoc.substring(thisDoc.lastIndexOf('.'))
if (baseName == "blank") {
bgTmp = baseName + thisExt
} else {
bgTmp = baseName + 'lg' + thisExt
}
if (bgTmp != bgCur) changeImg(bgTmp)
}
function bgOK() {
if (bgTmp && bgTmp != bgSave) {
bgSave = bgTmp
bgSaveID = optionSelID
if (bgTmp != bgCur) changeImg(bgSave)
newWindow.close()
}
}
function changeImg(thisName) {
var imgName = imgPath + thisName
background.setAttribute('xlink:href', imgName)
bgCur = thisName
}
function matrixCreate(thisString) {
var vals = thisString.split(' ')
this.a = vals[0] -0
this.b = vals[1] -0
this.c = vals[2] -0
this.d = vals[3] -0
this.x = vals[4] -0
this.y = vals[5] -0
}
function matrixToString(thisMatrix) {
return "matrix(" + thisMatrix.a + " " + thisMatrix.b + " " +
thisMatrix.c + " " + thisMatrix.d + " " + thisMatrix.x +
" " + thisMatrix.y + ")"
}
function matrixMult(m1, m2) {
this.a = m1.a * m2.a + m1.c * m2.b
this.b = m1.b * m2.a + m1.d * m2.b
this.c = m1.a * m2.c + m1.c * m2.d
this.d = m1.b * m2.c + m1.d * m2.d
this.x = m1.a * m2.x + m1.c * m2.y + m1.x
this.y = m1.b * m2.x + m1.d * m2.y + m1.y
}
function matrixPointMult(m, X, Y) {
this.x = m.a * X + m.c * Y + m.x
this.y = m.b * X + m.d * Y + m.y
}
function transMatrix(thisX, thisY) {
if( ! thisX || thisX == "" ) thisX = 0
if( ! thisY || thisY == "" ) thisY = 0
this.a = 1
this.b = 0
this.c = 0
this.d = 1
this.x = thisX
this.y = thisY
}
function rotMatrix(thisAngle) {
if (! thisAngle || thisAngle == "") thisAngle = 0
var cosAngle = Math.cos(thisAngle)
var sinAngle = Math.sin(thisAngle)
var thisString = cosAngle  + " " + sinAngle + " " +
-sinAngle + " " + cosAngle  + " 0 0"
this.a = cosAngle
this.b = sinAngle
this.c = -sinAngle
this.d = cosAngle
this.x = 0
this.y = 0
}
function scaleMatrix(scaleX, scaleY) {
if (! scaleX || scaleX == "") scaleX = 1
if (! scaleY || scaleY == "") scaleY = 1
this.a = scaleX
this.b = 0
this.c = 0
this.d = scaleY
this.x = 0
this.y = 0
}
function transStrToMatrix(thisStr) {
thisStr = thisStr + ""
var numTrans = 0
order = new Array()
var matrixStart = thisStr.indexOf( "matrix(" ) +1
var translateStart = thisStr.indexOf( "translate(" ) +1
var rotateStart = thisStr.indexOf( "rotate(" ) +1
if (matrixStart) {
matrixStart = matrixStart +6
var matrixEnd = thisStr.indexOf( ")", matrixStart )
if (matrixEnd != -2) {
var matrixValue = thisStr.substring(matrixStart, matrixEnd)
}
if (matrixValue) {
var matrixM = new matrixCreate(matrixValue)
numTrans++
order[numTrans] = new matrixOrder(matrixStart, matrixM)
}
}
if (translateStart) {
translateStart = translateStart +9
var translateEnd = thisStr.indexOf( ")", translateStart )
if (translateEnd != -2) {
var translateValue = thisStr.substring(translateStart, translateEnd)
}
if (translateValue) {
var translateM = new transMatrix(translateValue)
numTrans++
order[numTrans] = new matrixOrder(translateStart, translateM)
}
}
if (rotateStart) {
rotateStart = rotateStart +9
var rotateEnd = thisStr.indexOf( ")", rotateStart )
if (rotateEnd != -2) {
var rotateAngle = thisStr.substring(rotateStart, rotateEnd)
}
var rotateValue = rotateAngle *0.017453293
if (rotateValue) {
var rotateM = new rotMatrix(rotateValue)
numTrans++
order[numTrans] = new matrixOrder(rotateStart, rotateM)
}
}
if (numTrans == 0 ) {
this.a = "-999999"
} else if (numTrans == 1) {
return order[numTrans].matrix
} else {
var mNum
var temp = new Object()
for (mNum = 1; mNum < numTrans; mNum++) {
var mCount = mNum
while (mCount < numTrans) {
if (order[mNum].start > order[mCount +1].start) {
temp.start = order[mCount +1].start
temp.matrix = order[mCount +1].matrix
order[mCount +1].start = order[mNum].start
order[mCount +1].matrix = order[mNum].matrix
order[mNum].start = temp.start
order[mNum].matrix = temp.matrix
}
mCount++
}
}
for (mNum = numTrans; mNum > 1; mNum--) {
order[numTrans -1].matrix = matrixMult(order[numTrans -1].matrix, order[numTrans].matrix)
}
return order[1].matrix
}
}
function matrixOrder(start, thisMatrix) {
this.start = start
this.matrix = thisMatrix
}
function matrixInvert(m) {
var detInv = 1 / (m.a * m.d - m.b * m.c);
this.a = m.d * detInv;
this.d = m.a * detInv;
this.x = (m.y * m.c - m.x * m.d) * detInv;
this.y = (m.x * m.b - m.y * m.a) * detInv;
detInv = -detInv;
this.b = m.b * detInv;
this.c = m.c * detInv;
}
