var optName;var oSelectedCube;var oBtn;drawPalette();function togglePalette(myOBtn,myOptName){var oPalette=document.getElementById('colorPalette');if((myOptName==null||myOptName==optName)&&oPalette.style.display==""){hidePalette();}else{showPalette(myOBtn,myOptName);}}function showPalette(myOBtn,myOptName){var oPalette=document.getElementById('colorPalette');optName=myOptName;oBtn=myOBtn;oPalette.style.display="";var offsetLeft=getOffsetLeft(myOBtn);var screenWidth=(window.innerWidth)?window.innerWidth-25:document.body.clientWidth;var paletteWidth=document.getElementById('paletteTable').offsetWidth;if((offsetLeft+paletteWidth)>screenWidth)offsetLeft=screenWidth-paletteWidth;oPalette.style.left=offsetLeft+"px";oPalette.style.top=getOffsetTop(myOBtn)+myOBtn.offsetHeight+"px";if(oSelectedCube){var oTempCube=oSelectedCube;oSelectedCube=null;cubeOut(oTempCube);}var oTextbox=getField(optName);if(oTextbox){oSelectedCube=document.getElementById('color'+oTextbox.value);if(oSelectedCube){cubeOver(oSelectedCube);}else{updatePreview(oTextbox.value);}}draggedElem=document.getElementById('colorPalette');modifyEventListener("add","onmousedown",document,checkClosePalette);modifyEventListener("add","onkeypress",document,checkClosePalette);}function hidePalette(){var oPalette=document.getElementById('colorPalette');oPalette.style.display="none";modifyEventListener("remove","onmousedown",document,checkClosePalette);modifyEventListener("remove","onkeypress",document,checkClosePalette);}function checkClosePalette(evt){var elem=getEventObjectsElement(evt);var inPalette=0;while(elem.parentNode){if(elem.id=='colorPalette'||elem==oBtn)return;elem=elem.parentNode;}hidePalette();}function changeColor(newcolor){var oTextbox=getField(optName);var oSample=document.getElementById(optName+'_sample');if(oSample){oSample.style.backgroundColor=newcolor;oSample.style.color=newcolor;}if(oTextbox){oTextbox.value=newcolor;oTextbox.focus();}hidePalette();}function UpdateSample(tb){oSample=document.getElementById(tb.name+'_sample');if(oSample){try{oSample.style.backgroundColor=tb.value;}catch(e){oSample.style.backgroundColor="white";}}}function drawPalette(){var z=0;var defcolorlist=new Array("000000","333333","666666","999999","CCCCCC","FFFFFF","FF0000","00FF00","0000FF","FFFF00","00FFFF","FF00FF");var colorlist=new Array("00","33","66","99","CC","FF");document.writeln('<div id=colorPalette style="width:1px; height: 1px; display: none; position:absolute;">');document.writeln('<table border=0 cellpadding=0 cellspacing=0 align=center><tr><td bgcolor="#000000">');document.writeln('<table border=0 cellpadding=0 cellspacing="1" id="paletteTable">');document.writeln('<tr><td colspan=19 bgcolor="#92C3E4"><table width=100% border="0" cellpadding="2" cellspacing=0 class="text"><tr><td id="paletteTitle" style="cursor:move;" onmousedown="paletteDoOnMouseDown(event);" onmouseup="paletteDoOnMouseUp(event);"><b>Color Selection</b></td>');document.writeln('<td align=right width=50><div id="palettePreview" style="border:1px solid black; margin: 1px; width:100%;">&nbsp;</div></td><td width=1><img src="/clear.gif" height=1 width=1></td>');document.writeln('</tr></table></td></tr>');function drawRow(start,end){for(var i=0;i<6;i++){document.write('<tr>');drawCube(defcolorlist[z]);z++;for(var j=start;j<end;j++){for(var k=0;k<6;k++){drawCube(colorlist[j]+colorlist[k]+colorlist[i]);}}document.writeln('</tr>');}function drawCube(color){document.write('<td id="color#'+color+'" style="background-color:#'+color+';" onmouseover="cubeOver(this);" onmouseout="cubeOut(this);">');document.write('<a href="#" onClick="changeColor(\'#'+color+'\'); return false;">');document.write('<img src="/clear.gif" height="7" width="7" title="#'+color+'" style="border:1px dotted #'+color+';"></a></td>');}}drawRow(0,3);drawRow(3,6);document.writeln('</table></td></tr></table></div>');}function cubeOver(oCube){oCube.firstChild.firstChild.style.borderColor="white";updatePreview(oCube.style.backgroundColor);}function cubeOut(oCube){if(oCube!=oSelectedCube)oCube.firstChild.firstChild.style.borderColor=oCube.style.backgroundColor;var oTextbox=getField(optName);if(oTextbox)updatePreview(oTextbox.value);}function updatePreview(color){try{document.getElementById('palettePreview').style.backgroundColor=color;}catch(e){document.getElementById('palettePreview').style.backgroundColor="white";}}function getField(name){for(i=0;i<document.forms.length;++i){var obj=document.forms[i].elements[name];if(obj)return obj;}}function getOffsetTop(elm){var mOffsetTop=elm.offsetTop;var mOffsetParent=elm.offsetParent;while(mOffsetParent){mOffsetTop+=mOffsetParent.offsetTop;mOffsetParent=mOffsetParent.offsetParent;}return mOffsetTop;}function getOffsetLeft(elm){var mOffsetLeft=elm.offsetLeft;var mOffsetParent=elm.offsetParent;while(mOffsetParent){mOffsetLeft+=mOffsetParent.offsetLeft;mOffsetParent=mOffsetParent.offsetParent;}return mOffsetLeft;}var draggedElem;var x,y;function paletteDoOnMouseMove(evt){evt=getEventObject(evt);if(evt&&draggedElem){draggedElem.style.marginLeft=0+"px";draggedElem.style.marginTop=0+"px";draggedElem.style.left=(temp1+evt.clientX-x)+"px";draggedElem.style.top=(temp2+evt.clientY-y)+"px";return false;}}function paletteDoOnMouseDown(evt){evt=getEventObject(evt);var elem=draggedElem;temp1=(elem.offsetLeft);temp2=(elem.offsetTop);x=evt.clientX;y=evt.clientY;modifyEventListener("add","onmousemove",document,paletteDoOnMouseMove);modifyEventListener("add","onmousedown",document,disableSelect);modifyEventListener("add","onmouseup",document,returnTrue);}function paletteDoOnMouseUp(){if(draggedElem){modifyEventListener("remove","onmousemove",document,paletteDoOnMouseMove);}modifyEventListener("remove","onmousedown",document,disableSelect);modifyEventListener("remove","onmouseup",document,returnTrue);}function modifyEventListener(psAction,psEventName,poElement,poFunction){var isAdd=((psAction=="add")||(psAction=="attach"))?true:false;psEventName=psEventName.toLowerCase();if(psEventName.substring(0,2)!="on"){psEventName="on"+psEventName;}if(poElement.addEventListener){if(isAdd){poElement.addEventListener(psEventName.substr(2),poFunction,false);}else{poElement.removeEventListener(psEventName.substr(2),poFunction,false);}return true;}else if(poElement.attachEvent){if(isAdd){poElement.attachEvent(psEventName,poFunction);}else{poElement.detachEvent(psEventName,poFunction);}return true;}else if(document.getElementById){if(poElement.captureEvents){var sFunc=(isAdd)?"captureEvents":"releaseEvents";eval("poElement."+sFunc+"(Event."+psEventName.substr(2).toUpperCase()+");");}var sFunc=(isAdd)?(poFunction.toString().split(' ')[1].split('(')[0]):"null";eval("poElement."+psEventName+" = "+sFunc+";");return true;}return false;}function getEventObject(evt){return(evt)?evt:((window.event)?event:null);}function getEventObjectsElement(evt){evt=(evt)?evt:((window.event)?event:null);if(evt){var elem=(evt.target)?evt.target:((evt.srcElement)?evt.srcElement:null);while(elem.nodeType==3){elem=elem.parentNode;}return elem;}return null;}function returnTrue(){return true;}function disableSelect(evt){var omitFormTags="input|textarea|select";if(omitFormTags.indexOf(getEventObjectsElement(evt).tagName.toLowerCase())==-1){if(evt.preventDefault)evt.preventDefault();return false;}}
