function setColorExample(aa)
{
    var clr=colorcode(aa);
    document.getElementById('colorExample').innerHTML = clr;  
    document.getElementById('colorExample').style.backgroundColor=clr;  
}
function setColor(aa)
{
    var clr=colorcode(aa);
    if ( document.frmStyleUpdate.colorSelector[0].checked )
        document.frmStyleUpdate.backgroundColor.value = clr;
    else
        document.frmStyleUpdate.textColor.value = clr;
}
function makeColorArea() {
    var y=0
    var ymax=16     
    var step=32
    var cellwidth=5
    var cellheight=5
    var grays=26
    var tablewidth=(cellwidth*49) 
    var cell=' onmouseover="setColorExample(this.style.backgroundColor);"  onclick="setColor(this.style.backgroundColor);"  style="width:'+cellwidth+'; height:'+cellheight+';'

    document.write('<table id=colorCells align=center  width='+tablewidth+' cellspacing=0 cellpadding=1 border=0 bgcolor=tan >')
    var grayscale=0

    for (z=1; z<=3; z++){ymax=20-(z*4) 
      for (y=1; y<=ymax; y++){ 
        document.write('<tr>')
        for (var i=0; i<3; i++)
          {for (var h=0; h<512; ){h=h+step
	    if (z==1){
		a=(512-h)*(y/ymax);	if (a>256*(y/ymax)){a=256*(y/ymax)}
		b=h*(y/ymax);		if (b>256*(y/ymax)){b=256*(y/ymax)}
		c=0
		}
	    if (z==2){
		a=256*(y/ymax)+(512-h)*(ymax-y)/ymax    ;if (a>255){a=255}
		b=256*(y/ymax)+(h*(ymax-y)/ymax)	;if (b>255){b=255}
		c=256*(y/ymax);	 			;if (c>255){c=255}
		}
	    if (z==3){
		a=256*((ymax-y)/ymax)+(512-h)*(y)/ymax  ;if (a>255){a=255}
		b=256*((ymax-y)/ymax)+(h)*(y)/ymax	;if (b>255){b=255}
		c=256*((ymax-y)/ymax);	 		;if (c>255){c=255}
		var mute=.67
		var abc=(a+b+c)/3
		a=Math.round(a-((a-abc)*mute))
		b=Math.round(b-((b-abc)*mute))
		c=Math.round(c-((c-abc)*mute))
		}
		if (i==0){newcolor=Math.round(a)+','+Math.round(b)+','+Math.round(c)}
		if (i==1){newcolor=Math.round(c)+','+Math.round(a)+','+Math.round(b)}
		if (i==2){newcolor=Math.round(b)+','+Math.round(c)+','+Math.round(a)}
		document.write('<td '+cell+' background-color:rgb('+newcolor+');"></td>')
	  }}
          document.write('<td '+cell+' background-color:rgb('+Math.round(grayscale)+','+Math.round(grayscale)+','+Math.round(grayscale)+');"></td>')
          document.write('</tr>')
          grayscale=grayscale+256/grays
      }  
    }
    document.write('</table>')
}
function colorcode(paintcolor) 
{
	paintcolor=paintcolor.toUpperCase()
	if (paintcolor.indexOf("RGB")>-1){paintcolor=rgb2hex(paintcolor)}
	if (paintcolor.indexOf(",")>-1){paintcolor=rgb2hex(paintcolor)}
	return paintcolor
  }
function rgb2hex(rgbWord) 
{
	if (rgbWord.indexOf("RGB")>-1){rgbWord=rgbWord.substr(4,rgbWord.length-5)}
	//rgbWord=rgbWord.substr(4,rgbWord.length-5)
	R=rgbWord.substr(0,rgbWord.indexOf(","))
	  if (R>255){R=255}; if (R<0){R=0}
	rgbWord=rgbWord.substring(rgbWord.indexOf(",")+1,rgbWord.length)
	G=rgbWord.substring(0,rgbWord.indexOf(","))
	  if (G>255){G=255}; if (G<0){G=0}
	rgbWord=rgbWord.substring(rgbWord.indexOf(",")+1,rgbWord.length)
	B=rgbWord
	  if (B>255){B=255}; if (B<0){B=0}
	return dec2hex(R,G,B);
  }
function dec2hex(R,G,B) 
{
	var hexTest="0123456789ABCDEF";
	Rd_hi=R/16; Rd_lo=R%16;
        Rd=hexTest.substr(Rd_hi,1)+hexTest.substr(Rd_lo,1)
	Gn_hi=G/16; Gn_lo=G%16;
        Gn=hexTest.substr(Gn_hi,1)+hexTest.substr(Gn_lo,1)
	Bu_hi=B/16; Bu_lo=B%16;
        Bu=hexTest.substr(Bu_hi,1)+hexTest.substr(Bu_lo,1)
	hexval='#'+Rd+Gn+Bu
	return hexval;
  }