var MSIE=navigator.userAgent.indexOf("MSIE")>=0?true:false;var navigatorVersion=navigator.appVersion.replace(/.*?MSIE (\d\.\d).*/g,"$1")/1;var colorPickerCtx="";var slider_handle_image_obj=false;var sliderObjectArray=new Array();var slider_counter=0;var slideInProgress=false;var handle_start_x;var event_start_x;var currentSliderIndex;var color_picker_div=false;var color_picker_active_tab=false;var color_picker_form_field=false;var color_picker_active_input=false;var forCards=false;function form_widget_cancel_event(){return false}function getImageSliderHeight(){if(!slider_handle_image_obj){slider_handle_image_obj=new Image();slider_handle_image_obj.src=this.colorPickerCtx+"/download/resources/com.pyxis.greenhopper.jira:greenhopper-webactions/js/lib/colorpicker/images/slider_handle.gif"}if(slider_handle_image_obj.width>0){return }else{setTimeout("getImageSliderHeight()",50)}}function positionSliderImage(E,D,A){if(this){A=this}if(!D){D=A.getAttribute("sliderIndex")}var F=$("slider_handle"+D);var C=sliderObjectArray[D]["width"]/(sliderObjectArray[D]["max"]-sliderObjectArray[D]["min"]);var B=sliderObjectArray[D]["formTarget"].value-sliderObjectArray[D]["min"];F.style.left=B*C+"px";setColorByRGB()}function adjustFormValue(C){var D=$("slider_handle"+C);var B=sliderObjectArray[C]["width"]/(sliderObjectArray[C]["max"]-sliderObjectArray[C]["min"]);var A=D.style.left.replace("px","");sliderObjectArray[C]["formTarget"].value=Math.round(A/B)+sliderObjectArray[C]["min"]}function initMoveSlider(A){if(document.all){A=event}slideInProgress=true;event_start_x=A.clientX;handle_start_x=this.style.left.replace("px","");currentSliderIndex=this.id.replace(/[^\d]/g,"");return false}function startMoveSlider(e){if(document.all){e=event}if(!slideInProgress){return }var leftPos=handle_start_x/1+e.clientX/1-event_start_x;if(leftPos<0){leftPos=0}if(leftPos/1>sliderObjectArray[currentSliderIndex]["width"]){leftPos=sliderObjectArray[currentSliderIndex]["width"]}$("slider_handle"+currentSliderIndex).style.left=leftPos+"px";adjustFormValue(currentSliderIndex);if(sliderObjectArray[currentSliderIndex]["onchangeAction"]){eval(sliderObjectArray[currentSliderIndex]["onchangeAction"])}}function stopMoveSlider(){slideInProgress=false}function form_widget_amount_slider(G,B,A,E,H,C){if(!slider_handle_image_obj){getImageSliderHeight()}slider_counter=slider_counter+1;sliderObjectArray[slider_counter]=new Array();sliderObjectArray[slider_counter]={width:A-9,min:E,max:H,formTarget:B,onchangeAction:C};B.setAttribute("sliderIndex",slider_counter);B.onchange=positionSliderImage;var D=document.createElement("DIV");D.style.width=A+"px";D.style.height="12px";D.style.position="relative";D.id="slider_container"+slider_counter;$(G).appendChild(D);var F=document.createElement("DIV");F.className="form_widget_amount_slider";F.innerHTML="<span></span>";F.style.width=A+"px";F.id="slider_slider"+slider_counter;F.style.position="absolute";F.style.bottom="0px";D.appendChild(F);var I=document.createElement("IMG");I.style.position="absolute";I.style.left="0px";I.style.zIndex=5;I.src=slider_handle_image_obj.src;I.id="slider_handle"+slider_counter;I.onmousedown=initMoveSlider;if(document.body.onmouseup){if(document.body.onmouseup.toString().indexOf("stopMoveSlider")==-1){alert("You allready have an onmouseup event assigned to the body tag")}}else{document.body.onmouseup=stopMoveSlider;document.body.onmousemove=startMoveSlider}I.ondragstart=form_widget_cancel_event;D.appendChild(I);positionSliderImage(false,slider_counter)}function baseConverter(E,B,A){E=E+"";E=E.toUpperCase();var G="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";var H=0;for(var D=0;D<=E.length;D++){H+=(G.indexOf(E.charAt(D)))*(Math.pow(B,(E.length-D-1)))}E="";var F=Math.floor((Math.log(H))/(Math.log(A)));for(var D=F;D>=0;D--){var C=Math.floor(H/Math.pow(A,D));E=E+G.charAt(C);H-=C*(Math.pow(A,D))}if(E.length==0){E=0}return E}function colorPickerGetTopPos(A){var B=A.offsetTop;while((A=A.offsetParent)!=null){B+=A.offsetTop}return B}function colorPickerGetLeftPos(A){var B=A.offsetLeft;while((A=A.offsetParent)!=null){B+=A.offsetLeft}return B}function cancelColorPickerEvent(){return false}function showHideColorOptions(G,D){var B=this;if(D){var F=D.parentNode;B=D}else{var F=this.parentNode}var A=false;var H=F.getElementsByTagName("DIV")[0];counter=0;var I=10;var C=$("color_picker_content").getElementsByTagName("DIV")[0];do{if(H.tagName=="DIV"&&H.className!="colorPickerCloseButton"){if(H==B){B.className="colorPickerTab_active";B.style.zIndex=50;var E=B.getElementsByTagName("IMG")[0];E.src=colorPickerCtx+"/download/resources/com.pyxis.greenhopper.jira:greenhopper-webactions/js/lib/colorpicker/images/tab_right_active.gif";E.src=E.src.replace(/inactive/,"active");C.style.display="block";A=C}else{H.className="colorPickerTab_inactive";var E=H.getElementsByTagName("IMG")[0];E.src=colorPickerCtx+"/download/resources/com.pyxis.greenhopper.jira:greenhopper-webactions/js/lib/colorpicker/images/tab_right_inactive.gif";if(A){H.style.zIndex=I-counter}else{H.style.zIndex=counter}C.style.display="none"}counter++}H=H.nextSibling;if(C.nextSibling){C=C.nextSibling}}while(H)}function createColorPickerTopRow(E){var I=["Color slider","Named colors"];var F=[70,90];var B=document.createElement("DIV");B.className="colorPicker_topRow";E.appendChild(B);var D=0;for(var J=0;J<I.length;J++){var H=document.createElement("DIV");H.onselectstart=cancelColorPickerEvent;H.ondragstart=cancelColorPickerEvent;if(J==0){suffix="active";color_picker_active_tab=this}else{suffix="inactive"}H.id="colorPickerTab"+J;H.onclick=showHideColorOptions;if(J==0){H.style.zIndex=50}else{H.style.zIndex=1+(I.length-J)}H.style.left=D+"px";H.style.position="absolute";H.className="colorPickerTab_"+suffix;var G=document.createElement("SPAN");G.innerHTML=I[J];H.appendChild(G);var A=document.createElement("IMG");A.src=colorPickerCtx+"/download/resources/com.pyxis.greenhopper.jira:greenhopper-webactions/js/lib/colorpicker/images/tab_right_"+suffix+".gif";H.appendChild(A);B.appendChild(H);if(navigatorVersion<6&&MSIE){G.style.position="relative";A.style.position="relative";A.style.left="-3px";H.style.cursor="hand"}D=D+F[J]}var C=document.createElement("DIV");C.className="colorPickerCloseButton";C.innerHTML="x";C.onclick=closeColorPicker;C.onmouseover=toggleCloseButton;C.onmouseout=toggleOffCloseButton;B.appendChild(C)}function toggleCloseButton(){this.style.color="#FFF";this.style.backgroundColor="#317082"}function toggleOffCloseButton(){this.style.color="";this.style.backgroundColor=""}function closeColorPicker(){GH.Util.hide(color_picker_div)}function createWebColors(D){var I=document.createElement("DIV");I.style.paddingTop="1px";I.style.display="none";D.appendChild(I);for(var A=15;A>=0;A-=3){for(var G=0;G<=15;G+=3){for(var H=0;H<=15;H+=3){var C=baseConverter(A,10,16)+"";var F=baseConverter(G,10,16)+"";var J=baseConverter(H,10,16)+"";var E="#"+C+C+F+F+J+J;var B=document.createElement("DIV");B.style.backgroundColor=E;B.innerHTML="<span></span>";B.className="colorSquare";B.title=E;B.onclick=forCards?chooseCardColor:chooseCurveColor;B.setAttribute("rgbColor",E);I.appendChild(B)}}}}function createAllColorDiv(B){var F=document.createElement("DIV");F.style.display="";F.className="js_color_picker_allColorDiv";F.style.paddingLeft="3px";F.style.paddingTop="5px";F.style.paddingBottom="5px";B.appendChild(F);var E=document.createElement("DIV");E.className="colorSliderLabel";E.innerHTML="R";F.appendChild(E);var A=document.createElement("DIV");A.className="colorSlider";A.id="sliderRedColor";F.appendChild(A);var D=document.createElement("DIV");D.className="colorInput";var H=document.createElement("INPUT");H.id="js_color_picker_red_color";H.maxlength=3;H.style.width="48px";H.style.fontSize="11px";H.name="redColor";H.value=0;D.appendChild(H);F.appendChild(D);var E=document.createElement("DIV");E.className="colorSliderLabel";E.innerHTML="G";F.appendChild(E);var A=document.createElement("DIV");A.className="colorSlider";A.id="sliderGreenColor";F.appendChild(A);var D=document.createElement("DIV");D.className="colorInput";var H=document.createElement("INPUT");H.id="js_color_picker_green_color";H.maxlength=3;H.style.width="48px";H.style.fontSize="11px";H.name="GreenColor";H.value=0;D.appendChild(H);F.appendChild(D);var E=document.createElement("DIV");E.className="colorSliderLabel";E.innerHTML="B";F.appendChild(E);var A=document.createElement("DIV");A.className="colorSlider";A.id="sliderBlueColor";F.appendChild(A);var D=document.createElement("DIV");D.className="colorInput";var H=document.createElement("INPUT");H.id="js_color_picker_blue_color";H.maxlength=3;H.style.width="48px";H.style.fontSize="11px";H.name="BlueColor";H.value=0;D.appendChild(H);F.appendChild(D);var G=document.createElement("DIV");G.className="colorPreviewDiv";G.id="colorPreview";G.style.backgroundColor="#000000";G.innerHTML="<span></span>";G.title="Click on me to assign color";F.appendChild(G);G.onclick=forCards?chooseCardColor:chooseCurveColor;var I=document.createElement("DIV");I.className="colorCodeDiv";var H=document.createElement("INPUT");H.id="js_color_picker_color_code";I.appendChild(H);H.maxLength=7;H.style.fontSize="11px";H.style.width="48px";H.value="#000000";H.onchange=setPreviewColorFromTxt;H.onblur=setPreviewColorFromTxt;F.appendChild(I);var C=document.createElement("DIV");C.style.clear="both";F.appendChild(C);form_widget_amount_slider("sliderRedColor",$("js_color_picker_red_color"),170,0,255,"setColorByRGB()");form_widget_amount_slider("sliderGreenColor",$("js_color_picker_green_color"),170,0,255,"setColorByRGB()");form_widget_amount_slider("sliderBlueColor",$("js_color_picker_blue_color"),170,0,255,"setColorByRGB()")}function initSlider(A){if(A){if(A=="red"){A="#FF0000"}else{if(A=="blue"){A="#0000FF"}else{if(A=="green"){A="#007F00"}else{if(A=="orange"){A="#FF9922"}else{if(A=="yellow"){A="#FFFF00"}}}}}var B=convertColor(A);$("js_color_picker_red_color").value=B[0];$("js_color_picker_green_color").value=B[1];$("js_color_picker_blue_color").value=B[2];positionSliderImage(false,1,$("js_color_picker_red_color"));positionSliderImage(false,2,$("js_color_picker_green_color"));positionSliderImage(false,3,$("js_color_picker_blue_color"));setColorByRGB()}showHideColorOptions(null,$("colorPickerTab0"))}function setPreviewColorFromTxt(){if(this.value.match(/\#[0-9A-F]{6}/g)){$("colorPreview").style.backgroundColor=this.value;var C=this.value.substr(1,2);var B=this.value.substr(3,2);var A=this.value.substr(5,2);$("js_color_picker_red_color").value=baseConverter(C,16,10);$("js_color_picker_green_color").value=baseConverter(B,16,10);$("js_color_picker_blue_color").value=baseConverter(A,16,10);positionSliderImage(false,1,$("js_color_picker_red_color"));positionSliderImage(false,2,$("js_color_picker_green_color"));positionSliderImage(false,3,$("js_color_picker_blue_color"))}}function chooseCardColor(){var A=this.getAttribute("rgbColor")?this.getAttribute("rgbColor"):$("js_color_picker_color_code").value;for(var B=0;B<color_picker_form_field.length;B++){color_picker_form_field[B].setStyle({backgroundColor:A})}GH.Util.hide(color_picker_div);GreenHopper.setCardColor($F("issueTypeSel"),A)}function chooseCurveColor(){var A=this.getAttribute("rgbColor")?this.getAttribute("rgbColor"):$("js_color_picker_color_code").value;GH.Util.hide(color_picker_div);Boards.setCurveColor($F("curveSel"),A)}function showCardColor(A,C){forCards=true;var B=$(A);showColorPicker(B,C);if(color_picker_div.style.display=="none"||color_picker_active_input!=B){color_picker_div.style.display="block"}else{GH.Util.hide(color_picker_div)}color_picker_form_field=(C?[$(C)]:[$("summary_"+$F("issueTypeSel")),$("card_"+$F("issueTypeSel")),$("list_"+$F("issueTypeSel"))]);color_picker_div.style.left=colorPickerGetLeftPos(B)+"px";color_picker_div.style.top=colorPickerGetTopPos(B)+B.offsetHeight+2+"px";color_picker_active_input=B;initSlider((C?$(C).style.backgroundColor:$("card_"+$F("issueTypeSel")).style.backgroundColor))}function showCurveColor(A,C){var B=$(A);showColorPicker(B,C);if(color_picker_div.style.display=="none"||color_picker_active_input!=B){color_picker_div.style.display="block"}else{GH.Util.hide(color_picker_div)}color_picker_form_field=C;color_picker_active_input=B;color_picker_div.style.left=colorPickerGetLeftPos(B)+"px";color_picker_div.style.top=colorPickerGetTopPos(B)+B.offsetHeight+2+"px";initSlider((C?$(C).style.backgroundColor:$("card_"+$F("issueTypeSel")).style.backgroundColor))}function showColorPicker(){if(!color_picker_div){color_picker_div=document.createElement("DIV");color_picker_div.id="dhtmlgoodies_colorPicker";color_picker_div.style.display="none";document.body.appendChild(color_picker_div);createColorPickerTopRow(color_picker_div);var A=document.createElement("DIV");A.id="color_picker_content";color_picker_div.appendChild(A);createAllColorDiv(A);createWebColors(A)}}function setColorByRGB(){var C=$("js_color_picker_red_color").value.replace(/[^\d]/,"");var B=$("js_color_picker_green_color").value.replace(/[^\d]/,"");var A=$("js_color_picker_blue_color").value.replace(/[^\d]/,"");if(C/1>255){C=255}if(B/1>255){B=255}if(A/1>255){A=255}C=baseConverter(C,10,16)+"";B=baseConverter(B,10,16)+"";A=baseConverter(A,10,16)+"";if(C.length==1){C="0"+C}if(B.length==1){B="0"+B}if(A.length==1){A="0"+A}$("colorPreview").style.backgroundColor="#"+C+B+A;$("js_color_picker_color_code").value="#"+C+B+A}function convertColor(A){var B=new Object();if(A[0]=="r"){A=A.substring(A.indexOf("(")+1,A.indexOf(")"));B=A.split(",",3);B[0]=parseInt(B[0]);B[1]=parseInt(B[1]);B[2]=parseInt(B[2])}else{if(A.substring(0,1)=="#"){B[0]=A.substring(1,3);B[1]=A.substring(3,5);B[2]=A.substring(5,7);B[0]=parseInt(B[0],16);B[1]=parseInt(B[1],16);B[2]=parseInt(B[2],16)}}return B};
