

var ColorHex=new Array('00','33','66','99','CC','FF')
var SpColorHex=new Array('FF0000','00FF00','0000FF','FFFF00','00FFFF','FF00FF')
var current=null

function intocolor()
{
var colorTable=''
for (i=0;i<2;i++)
{
   for (j=0;j<6;j++)
    {
     colorTable=colorTable+'<tr height=12>'
     colorTable=colorTable+'<td width=11 style="background-color:#000000">'
   
     if (i==0){
     colorTable=colorTable+'<td width=11 style="background-color:#'+ColorHex[j]+ColorHex[j]+ColorHex[j]+'">'}
     else{
     colorTable=colorTable+'<td width=11 style="background-color:#'+SpColorHex[j]+'">'}

   
     colorTable=colorTable+'<td width=11 style="background-color:#000000">'
     for (k=0;k<3;k++)
      {
        for (l=0;l<6;l++)
        {
         colorTable=colorTable+'<td width=11 style="background-color:#'+ColorHex[k+i*3]+ColorHex[l]+ColorHex[j]+'">'
        }
      }
   }
}
colorTable='<table width=253 border="0" cellspacing="0" cellpadding="0" style="border:1px #000000 solid;border-bottom:none;border-collapse: collapse" bordercolor="000000">'
            +'<tr height=30><td colspan=21 bgcolor=#cccccc>'
            +'<table cellpadding="0" cellspacing="1" border="0" style="border-collapse: collapse">'
            +'<tr><td width="3"><td><input type="text" name="DisColor" id="DisColor" size="6" disabled style="border:solid 1px #000000;background-color:#ffff00"></td>'
            +'<td width="3"><td><input type="text" name="HexColor" id="HexColor" size="7" style="border:inset 1px;font-family:Arial;" value="#000000"></td></tr></table></td></table>'
            +'<table border="1" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="000000" onmouseover="doOver(event)" onmouseout="doOut()" onclick="doclick(event)" style="cursor:hand;">'
            +colorTable+'</table>';         
 document.getElementById("colorpanel").innerHTML=colorTable;
}


//将颜色值字母大写
function doOver(event) {
   var event = event? event: window.event ;
   var srcObj = event.srcElement ? event.srcElement : event.target;
  
       if ((srcObj.tagName=="TD") && (current!=srcObj)) {
         if (current!=null){current.style.backgroundColor = current._background}    
        srcObj._background = srcObj.style.backgroundColor;
   var outColor = rgb2hex(srcObj.style.backgroundColor).toUpperCase();
  
         document.getElementById('DisColor').style.backgroundColor = outColor;
         document.getElementById('HexColor').value = outColor;
         srcObj.style.backgroundColor = "white";
         current = srcObj;
       }
}


//将颜色值字母大写
function doOut() {

     if (current!=null) current.style.backgroundColor = current._background;
}


function doclick(event)
{
var event = event? event: window.event ;
var srcObj = event.srcElement ? event.srcElement : event.target;
     if (srcObj.tagName == "TD")
     {
         var clr = srcObj._background;
         clr = clr.toUpperCase(); //将颜色值大写
         if (targetElement)
         {
    clr=rgb2hex(clr).toUpperCase();
             //给目标无件设置颜色值
             targetElement.value = clr;
             var select=document.getElementById("select");
             select.style.backgroundColor = clr;
         }
         DisplayClrDlg(false);
  
         return clr;
     }
}
function zero_fill_hex(num, digits) {
var s = num.toString(16);
while (s.length < digits)
    s = "0" + s;
return s;
}
function rgb2hex(rgb) {
//nnd, Firefox / IE not the same, fxck
if (rgb.charAt(0) == '#')
    return rgb;
var n = Number(rgb);
var ds = rgb.split(/\D+/);
ds[1]=ds[1].substr(0);
ds[2]=ds[2].substr(0);
ds[3]=ds[3].substr(0);
var decimal = Number(ds[1]) * 65536 + Number(ds[2]) * 256 + Number(ds[3]);
return "#" + zero_fill_hex(decimal, 6);

}
//应用颜色对话框必须注意两点：
//颜色对话框 id : colorpanel 不能变
//触发颜色对话框显示的文本框（或其它）必须有 alt 属性，且值为 clrDlg（不能忽略大小写）

//如果需要在一个html多次运用颜色选择器,只需要增加以下改进部分

var targetElement = null; //接收颜色对话框返回值的元素

//当点下鼠标时，确定显示还是隐藏颜色对话框
//点击颜色对话框以外其它区域时，让对话框隐藏
//点击颜色对话框色区时，由 doclick 函数来隐藏对话框


//显示颜色对话框
//display 决定显示还是隐藏
//自动确定显示位置
function DisplayClrDlg(display,event)
{ var event = event? event: window.event ;

     var clrPanel = document.getElementById("colorpanel");
     if (display)
     {
  
         var left = document.body.scrollLeft + event.clientX;
         var top = document.body.scrollTop + event.clientY;
  
  
         if (event.clientX+clrPanel.style.width > document.body.clientWidth)
         {
             //对话框显示在鼠标右方时，会出现遮挡，将其显示在鼠标左方
            
    left -= clrPanel.style.pixelWidth;
   
   
         }
         if (event.clientY+clrPanel.style.height > document.body.clientHeight)
         {
             //对话框显示在鼠标下方时，会出现遮挡，将其显示在鼠标上方
             top -= clrPanel.style.pixelHeight;
         }
       
         clrPanel.style.left = left;
         clrPanel.style.top = top;
         clrPanel.style.display = "block";
     }
     else
     {
         clrPanel.style.display = "none";
     }
}

function zhuqungu(event)
{
     var srcElement = document.getElementById('SiteContent_waterTextColor');
     
     if (srcElement.alt == "clrDlg"||srcElement.alt=="color1"||srcElement.alt=="color2")
     {
         //显示颜色对话框
  
         targetElement = document.getElementById('SiteContent_waterTextColor');
         DisplayClrDlg(true,event);
     }
     else
     {
         //是否是在颜色对话框上点击的
         while (srcElement && srcElement.id!="colorpanel")
         {
             srcElement = srcElement.parentNode;
         }
         if (!srcElement)
         {
             //不是在颜色对话框上点击的
             DisplayClrDlg(false,event);
         }
     }
}