

//-----------------------------------
//    Rainbow Color grid
//    copyright@isdntek 2005
//    do not copy without permission
//-----------------------------------

//-----------------------------------
//    global variables
//-----------------------------------
quot="'"
var R=0
var G=0
var B=0
var paletteDrag=false       // this indicates whether the mouse is dragging.
var palettecellwidth=8      // program definable cell sizes
var palettecellheight=6     // 
var palettetranscell=true   // use the clickable transparent cell
var palettecellpadding=3    // to hold open cells in smallest direction 294
var paletteisIE=document.all;
var paletteymax=48 
var palettexstep=32  
var verticalpalette=false
var palettehex="0123456789ABCDEFabcdef"
var xhairTable='<style>.xhr {width:7px; height:7px; border:1px inset silver; font-size:1px;}</style>'+
	'<table cellpadding=0 cellspacing=1 border=0 >'+
	'<tr><td><div class="xhr" style="border-width:0 1 1 0"></div></td>'+
	'<td><div class="xhr" style="border-width:0 0 1 1"></div></td></tr>'+
	'<tr><td><div class="xhr" style="border-width:1 1 0 0"></div></td>'+
	'<td><div class="xhr" style="border-width:1 0 0 1"></div></td></tr>'+
	'</table>'


var palettenamedcolors=new Array(
"#F0F8FF","Aliceblue",
"#FAEBD7","Antiquewhite",
"#00FFFF","Aqua",
"#7FFFD4","Aquamarine",
"#F0FFFF","Azure",
"#F5F5DC","Beige",
"#FFE4C4","Bisque",
"#000000","Black",
"#FFEBCD","Blanchedalmond",
"#0000FF","Blue",
"#8A2BE2","Blueviolet",
"#A52A2A","Brown",
"#DEB887","Burlywood",
"#5F9EA0","Cadetblue",
"#7FFF00","Chartreuse",
"#D2691E","Chocolate",
"#FF7F50","Coral",
"#6495ED","Cornflowerblue",
"#FFF8DC","Cornsilk",
"#DC143C","Crimson",
"#00FFFF","Cyan",
"#00008B","Darkblue",
"#008B8B","Darkcyan",
"#B8860B","Darkgoldenrod",
"#A9A9A9","Darkgray",
"#006400","Darkgreen",
"#BDB76B","Darkkhaki",
"#8B008B","Darkmagenta",
"#556B2F","Darkolivegreen",
"#FF8C00","Darkorange",
"#9932CC","Darkorchid",
"#8B0000","Darkred",
"#E9967A","Darksalmon",
"#8FBC8F","Darkseagreen",
"#483D8B","Darkslateblue",
"#2F4F4F","Darkslategray",
"#00CED1","Darkturquoise",
"#9400D3","Darkviolet",
"#FF1493","Deeppink",
"#00BFFF","Deepskyblue",
"#696969","Dimgray",
"#1E90FF","Dodgerblue",
"#B22222","Firebrick",
"#FFFAF0","Floralwhite",
"#228B22","Forestgreen",
"#FF00FF","Fuchsia",
"#DCDCDC","Gainsboro",
"#F8F8FF","Ghostwhite",
"#FFD700","Gold",
"#DAA520","Goldenrod",
"#808080","Gray",
"#008000","Green",
"#ADFF2F","Greenyellow",
"#F0FFF0","Honeydew",
"#FF69B4","Hotpink",
"#CD5C5C","Indianred",
"#4B0082","Indigo",
"#FFFFF0","Ivory",
"#F0E68C","Khaki",
"#E6E6FA","Lavender",
"#FFF0F5","Lavenderblush",
"#7CFC00","Lawngreen",
"#FFFACD","Lemonchiffon",
"#ADD8E6","Lightblue",
"#F08080","Lightcoral",
"#E0FFFF","Lightcyan",
"#FAFAD2","Lightgoldenrodyellow",
"#90EE90","Lightgreen",
"#D3D3D3","Lightgrey",
"#FFB6C1","Lightpink",
"#FFA07A","Lightsalmon",
"#20B2AA","Lightseagreen",
"#87CEFA","Lightskyblue",
"#778899","Lightslategray",
"#B0C4DE","Lightsteelblue",
"#FFFFE0","Lightyellow",
"#00FF00","Lime",
"#32CD32","Limegreen",
"#FAF0E6","Linen",
"#FF00FF","Magenta",
"#800000","Maroon",
"#66CDAA","Mediumauqamarine",
"#0000CD","Mediumblue",
"#BA55D3","Mediumorchid",
"#9370D8","Mediumpurple",
"#3CB371","Mediumseagreen",
"#7B68EE","Mediumslateblue",
"#00FA9A","Mediumspringgreen",
"#48D1CC","Mediumturquoise",
"#C71585","Mediumvioletred",
"#191970","Midnightblue",
"#F5FFFA","Mintcream",
"#FFE4E1","Mistyrose",
"#FFE4B5","Moccasin",
"#FFDEAD","Navajowhite",
"#000080","Navy",
"#FDF5E6","Oldlace",
"#808000","Olive",
"#688E23","Olivedrab",
"#FFA500","Orange",
"#FF4500","Orangered",
"#DA70D6","Orchid",
"#EEE8AA","Palegoldenrod",
"#98FB98","Palegreen",
"#AFEEEE","Paleturquoise",
"#D87093","Palevioletred",
"#FFEFD5","Papayawhip",
"#FFDAB9","Peachpuff",
"#CD853F","Peru",
"#FFC0CB","Pink",
"#DDA0DD","Plum",
"#B0E0E6","Powderblue",
"#800080","Purple",
"#FF0000","Red",
"#BC8F8F","Rosybrown",
"#4169E1","Royalblue",
"#8B4513","Saddlebrown",
"#FA8072","Salmon",
"#F4A460","Sandybrown",
"#2E8B57","Seagreen",
"#FFF5EE","Seashell",
"#A0522D","Sienna",
"#C0C0C0","Silver",
"#87CEEB","Skyblue",
"#6A5ACD","Slateblue",
"#708090","Slategray",
"#FFFAFA","Snow",
"#00FF7F","Springgreen",
"#4682B4","Steelblue",
"#D2B48C","Tan",
"#008080","Teal",
"#D8BFD8","Thistle",
"#FF6347","Tomato",
"#40E0D0","Turquoise",
"#EE82EE","Violet",
"#F5DEB3","Wheat",
"#FFFFFF","White",
"#F5F5F5","Whitesmoke",
"#FFFF00","Yellow",
"#9ACD32","YellowGreen"
)
//-----------------------------------
//    color table
//-----------------------------------


function paletteStartup(){ //-- set the startup default values
	showPreviewcolor('#808080')
	document.getElementById('selectedColor').style.backgroundColor=document.getElementById('previewColor').style.backgroundColor
	document.getElementById('selectedValue').value=document.getElementById('previewValue').value
	setTimeout("xhairLoc()",50)
}

function makeColorTable(w,h,v,omit) { //-- create the color chart structure
  if (omit) {palettetranscell=false}
  if (v){verticalpalette=true}
  if (w) {palettecellwidth=w}
  if (h) {palettecellheight=h}
  if (palettecellheight<palettecellwidth){palettecellpadding=palettecellheight/2}else{palettecellpadding=palettecellwidth/2}
  var tablewidth=(palettecellwidth*3*512/palettexstep)
  var dragzone=3

  document.write('<table  align=left border=0 width='+(tablewidth+(4*dragzone))+'  cellpadding=0 cellspacing=0  onmousedown="paletteDrag=true; xhairOff(); " onmouseup="paletteDrag=false; xhairOn();" >')
  document.write('<tr><td  style="height:'+(2*dragzone)+'; width:100%" colspan=3 onmouseover="paletteDrag=false; return false;"></td></tr>')
  //------------
  document.write('<tr><td  style="padding:'+(dragzone)+'; width:'+(2*dragzone)+';" onmouseover="paletteDrag=false; return false;"></td><td >')
  makePalette() //-- fill in the color grid
  document.write('</td><td style="padding:'+(dragzone)+'; width:'+(2*dragzone)+';"  onmouseover="paletteDrag=false; return false;"></td></tr>')
  document.write('<tr><td  style="height:'+(2*dragzone)+'; width:100%" colspan=3 onmouseover="paletteDrag=false; return false;"></td></tr></table>')
 //-- set crosshair to bottom center
  paletteStartup()


}

  
//--------------------------
//    color grid in table
//--------------------------
function makePalette() { //-- create the glide-over color chart
    //--colorizer code copyright@isdntek 2005
    var y=0; var j=0
    var ymax=paletteymax
    var step=palettexstep
    var cellwidth=palettecellwidth
    var cellheight=palettecellheight
    var tablewidth=(cellwidth*48) 
    var cell=' class="pcell" title="" onmouseover="showPreviewcolor(this.style.backgroundColor); '+
	     '  this.title=this.style.backgroundColor; '+ 
	     ' if (paletteDrag==true){setPreviewColor(this.style.backgroundColor);changeShades(this.style.backgroundColor);xhairLoc(this);}; return false;" '+
 	     ' onclick="setPreviewColor(this.style.backgroundColor);changeShades(this.style.backgroundColor);xhairLoc(this); return false;" '

  document.write('<table ><tr><td colspan=2 valign=bottom>')
  //-- add dropdown list -table	
	document.write('<table width=100% align=left><tr><td align=left valign=bottom>'+makeColorList())
      	if (verticalpalette==true && palettetranscell==true) { //-- add transparent button
       	document.write('</td><td align=left width=30% valign=bottom>');makeTransparentButton();}
	document.write('</td></tr></table>')
	
  //-- transparent button
    if (verticalpalette==false){
    	document.write('</td><td></td><td  valign=bottom align=center>')
    	makeTransparentButton()
    } //--else add it above

  //--color palette -table
  document.write('</td></tr><tr><td width='+tablewidth+' valign=top align=left>')
      document.write('<style type=text/css>.pcell  {width:'+cellwidth+'px; height:'+cellheight+'px;} </style>'+
	     '<div style="position:relative; left:0px; top:0px; ">'+
	     '<table id=colorCells width='+tablewidth+' cellspacing=0 cellpadding='+palettecellpadding+'  bgcolor=tan >')

      for (y=0; y<=ymax; y++){ j=0
        document.write('<tr>')
        for (var i=0; i<3; i++){
          for (var h=0; h<512; ){h=h + step
		aa=(512-h); 	if (aa>255){aa=255}
		bb=(h);		if (bb>255){bb=255}
		cc=0
		a=aa-((aa-128)*(y/ymax))
		b=bb-((bb-128)*(y/ymax))
		c=128*(y/ymax)
		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 id="cell_'+j+'_'+y+'" '+cell+' style="background-color:rgb('+newcolor+');"></td>')
		j=j+1
	  }
        }  
        document.write('</tr>')
      }
      document.write('</table>')
  //-- crosshair marker
      document.write('<div id=xhair style="position:absolute; left:0px; top:0px;" '+
			'onmousedown="paletteDrag=true; xhairOff(); colorunderxhair();">'+xhairTable+'</div>') 
      document.write('</div>')
  document.write('</td><td valign=top align=left>')

  //-- shade column (table)
    var cell=' class="pcell" title="" onmouseover="showPreviewcolor(this.style.backgroundColor); '+
	     '  this.title=this.style.backgroundColor; '+ 
	     ' if (paletteDrag==true){setPreviewColor(this.style.backgroundColor);}; return false;" '+
 	     ' onclick="setPreviewColor(this.style.backgroundColor); return false;" '

		document.write('<table  width='+(palettecellwidth*4)+' cellspacing=0 cellpadding='+palettecellpadding+' border=0 bgcolor=tan style="margin-top:'+palettecellheight+'px">')
		for (i=0; i<ymax; i++){
		newcolor=colorBrightness("#808080",(ymax-1-i)/(ymax-1))
			document.write('<tr><td id=colorShades'+i+' '+cell+' style="background-color:'+newcolor+';"></td></tr>')
		}	
        	document.write('</table>')

  //-- selection column
   	if (verticalpalette==false){document.write('</td><td style="width:20px" >&nbsp;</td><td  valign=top align=center>')}else{document.write('</td></tr><tr><td colspan=2 valign=top align=center>')}
	makePreviewSwatches()
  document.write('</td></tr></table>')
}



function makePreviewSwatches(){
    if (verticalpalette==true){swatchWid=palettecellwidth*19;swatchHt=40}else {swatchWid=75;swatchHt=palettecellheight*12}
    document.write('<table border=0 cellspacing=0 cellpadding=0 width=100%><tr><td valign=top align=center>')
    //--preview swatch
	document.write(
	'<div style="font-size:11px; font-family: arial;">PREVIEW</div>'+
	'<div id=previewColor title+"" style="width:'+swatchWid+'px; height:'+swatchHt+'px; border:0px inset white; padding-top:'+((swatchHt-32)/2)+'px; text-align:center'+
	' background-color:#808080" onmouseover="this.title=hex2rgb(colorcode(this.style.backgroundColor));">'+
	'<span id=previewValue1 style="font-size:12px; font-family: arial; color:white"></span><br>'+
	'<span id=previewValue2 style="font-size:12px; font-family: arial; color:black"></span>'+
	'</div>'+
	'<input type=text id=previewValue style="display:none; width:'+swatchWid+'px;border:0px solid #444444; background-color:#c0c0c0" value="#808080">')
    //-- text swatch
	document.write('<div id=previewText style="width:'+swatchWid+'px; height:22px; font-family: arial; font-size:16px; text-align:center; ">'+
	'<div style="background-color:white; width:'+(swatchWid/2)+'; height:22px; float:left">text</div>'+
	'<div style="background-color:black; width:'+(swatchWid/2-1)+'; height:22px; float:right">text</div></div>')
    	if (verticalpalette==true){
		document.write('</td><td >&nbsp;</td><td valign=top align=center>')}else
		{document.write('<div style="font-size:6px; font-family: arial;">&nbsp;</div>')}
    //--selection swatch
    	document.write(
	'<div style="font-size:11px; font-family: arial;">SELECTION</div>'+
	'<div id=selectedColor title="" style="width:'+swatchWid+'px; height:'+swatchHt+'px; border:2px inset white ; background-color:#808080; " '+
	' onmouseover="this.title=hex2rgb(colorcode(this.style.backgroundColor));" ></div>'+
	'<input type=text id=selectedValue style="width:'+swatchWid+'px;border:2px inset white;" value="#808080"'+
	' onkeydown="if (event.keyCode==13){sendColor(this.value);}"  onblur="sendColor(this.value);"><br>')
    //--make color available for application
    if (verticalpalette==true){document.write('</td><td >&nbsp;</td><td valign=bottom align=center>')}
    	document.write(
	'<input type="button" style="margin-top:5px;" onclick="clickPaletteButton();" value="apply">')
    document.write('</td></tr></table>')

}



function  makeColorList(){ //-- list of named colors
	listCode='<select onclick="doNamedColors(this.value); this.value='+quot+'(Named Colors)'+quot+'" style="width:100%; ">'
		listCode=listCode+'<option style="background-color:#f0f0f0" value="(Named Colors)" selected>(Named Colors)</option>'
	for (var k=0; k<palettenamedcolors.length; k++){k=k+1;
		listCode=listCode+'<option style="background-color:'+palettenamedcolors[k-1]+'" value="'+palettenamedcolors[k-1]+'" title="'+palettenamedcolors[k-1]+'">'+palettenamedcolors[k]+'</option>'
	}
	listCode=listCode+'</select>'
	return listCode
}

function makeTransparentButton(){ //-- set transparent color (or null background)
  	if (palettetranscell==true){
  	document.write('<div style="background-color:; text-align:center; font-family:sans-serif; '+
  	'   font-size:11; margin-bottom:5px; margin-top:5px; border:1px outset white; cursor:pointer;  padding2px; color:#444444" '+
  	'   onmouseover="showPreviewcolor(this.style.backgroundColor); '+
  	'   if (paletteDrag==true){setPreviewColor(this.style.backgroundColor)}; return false;" '+
  	'   onclick="setPreviewColor(this.style.backgroundColor); return false;" ><nobr>NO COLOR</nobr></div> ')
	}
}

//-----------------------------------
//    conversion functions
//-----------------------------------

function colorcode(paintcolor) { //--standardizes color code as hex value
	// gecko uses RGB and IE uses Hexvalues, so convert here
	// this routine expects mostly valid colors from the program or user.
	// User inputs should be specifically tested at the input function.
	// if (!paintcolor){return ""}
	// can't send null through here
	paintcolor=paintcolor.replace(/ /g,"").toUpperCase() 				//clear spaces, make uppercase
	if (paintcolor=="" || paintcolor=="NONE" || paintcolor=="TRANSPARENT" ){return ""} //-- do we want to return the "none" if passed?
	if (paintcolor.indexOf("#")<0){
		if (paintcolor.indexOf("RGB")>-1){paintcolor=rgb2hex(paintcolor)}   	//--RGB value
		else if (paintcolor.indexOf(",")>-1){paintcolor=rgb2hex(paintcolor)} 	//--comma-delimited decivalues
		else {paintcolor=fromcolorname(paintcolor)} 				//--check for named colors, or return same if not found
	}										// all of the above functions prepend the #-sign
	return paintcolor
  }

function userColorTesting(usercode) { //-- test user inputs for proper format
	//-- the code has already passed through the colorcode routine and is only used to check user inputs
	usercode=validateHex(usercode) 							//-- check for valid characters
	if (usercode=="error"){return "error"}
	if ((usercode.length==3 && usercode.indexOf("#")<0)||
		(usercode.length==4 && usercode.indexOf("#")>=0)){
		usercode=hex2hex(usercode)} 						//-- double up the short codes and add #
	else if (usercode!="" && usercode.indexOf("#")<0){usercode="#"+usercode}	//-- or add missing # if hex number 
	if (usercode.length>7 ){alert(usercode+" is too long" );return "error"}
	if (usercode.length<7 && usercode.length>0){alert(usercode+" is too short" );return "error"} //-- report if wrong size
	return usercode
}


function validateHex(testCode) { //-- test hex color for valid characters
	// -- this code is only used to to test user inputs.
	HexCode=testCode
	if (HexCode.charAt(0)=='#') {HexCode=HexCode.substring(1,HexCode.length)} 
	for (var i=0; i<HexCode.length; i++){
		if (palettehex.indexOf(HexCode.substr(i,1))<0){
		alert(testCode+' is not a valid color');return "error"}
	}
	return testCode;
}


function hex2hex(HexCode) { //-- convert 3-digit hex to 6-digit hex
	if (HexCode.charAt(0)=='#') {HexCode=HexCode.substring(1,HexCode.length)} 
	newCode=HexCode.charAt(0)+HexCode.charAt(0)+
		HexCode.charAt(1)+HexCode.charAt(1)+
		HexCode.charAt(2)+HexCode.charAt(2)
	return "#"+newCode
}


function hex2rgb(HexCode) { //- Changes Hex to RGB values (uses 2 functions)
	if (!HexCode){return}
	HexCode=HexCode.toUpperCase()
	if (HexCode.charAt(0)=='#') {HexCode=HexCode.substring(1,7)} 
	R=(hex2dec(HexCode.charAt(0))*16)+hex2dec(HexCode.charAt(1)); 
	G=(hex2dec(HexCode.charAt(2))*16)+hex2dec(HexCode.charAt(3)); 
	B=(hex2dec(HexCode.charAt(4))*16)+hex2dec(HexCode.charAt(5)); 
	return 'rgb('+R+','+G+','+B+')'
  }
function hex2dec(hchar) { //--Returns a decimal value from a single hex byte
	// determine value by position
	var hexTest="0123456789ABCDEF";
	return hexTest.indexOf(hchar);
  }


function rgb2hex(rgbWord) { //--Parses the R-G-B components of RGB-string and returns 3 values
	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) { //--Converts three R-G-B components to a single internet hex color
	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;
  }

function fromcolorname(cname){ //--converts named internet colors to hex values from the table
	for (var c=0; c<palettenamedcolors.length; c++){
		if (palettenamedcolors[c].toUpperCase()==cname.toUpperCase()&& cname.indexOf("#")<0){
		cname=(palettenamedcolors[c-1])
		}
	}
	return cname;
}

function tocolorname(cname){ //--converts hex values to named colors from the table
	for (var c=0; c<palettenamedcolors.length; c++){
		if (palettenamedcolors[c].toUpperCase()==cname.toUpperCase()&& cname.indexOf("#")>-1){
		cname=(palettenamedcolors[c+1])
		}
	}
	return cname;
}

function colorBrightness(color,shadeRatio){ //--create a shade as a percentage of the submitted color
	//-- where higher percentages are lighter and lower percentages are darker
	var newColor=colorcode(color)
	var rgb=hex2rgb(newColor)
	if (shadeRatio>.5){
	R=R+(2*shadeRatio-1)*(255-R)
	G=G+(2*shadeRatio-1)*(255-G)
	B=B+(2*shadeRatio-1)*(255-B)
	}else{
	R=2*shadeRatio*R
	G=2*shadeRatio*G
	B=2*shadeRatio*B
	}
	return dec2hex(R,G,B)
}


//-----------------------------------
//    palette functions
//-----------------------------------

function doNamedColors(ncolor) { //--process selections from the color list
	if (ncolor!="(Named Colors)"){
		showPreviewcolor(ncolor)
		setPreviewColor(ncolor); 
		changeShades(ncolor)
	}
}

function changeShades(color){ //--update the vertical column of light/dark shades
	var ymax=paletteymax
	if (!color){return}
	for (i=0; i<ymax; i++){
	document.getElementById('colorShades'+i).style.backgroundColor=colorBrightness(color,(ymax-1-i)/(ymax-1))
	}
}


function clickPaletteButton(){ //--button click to apply the color
	setColor(colorcode(document.getElementById('selectedColor').style.backgroundColor))
}

function showPreviewcolor(paintcolor) { //--dynamically change colors on test swatch
	    paintcolor=colorcode(paintcolor)
	    document.getElementById('previewColor').style.backgroundColor=paintcolor;  
	    document.getElementById('previewValue').value=paintcolor 
	    document.getElementById('previewValue1').innerHTML=paintcolor 
	    document.getElementById('previewValue2').innerHTML=paintcolor 
	    document.getElementById('previewText').style.color=paintcolor; 
	    if (paletteDrag==true) {setDynaColor(paintcolor)} // make color available to the application
}

function setPreviewColor(palettecolor) { //--set the selected color swatch to the preview color
	    palettecolor=colorcode(palettecolor)
	    document.getElementById('selectedColor').style.backgroundColor=document.getElementById('previewColor').style.backgroundColor
	    document.getElementById('selectedValue').value=document.getElementById('previewValue').value
	    setDynaColor(palettecolor) // make color available to the application
}


//--void this function
function drabColor(inputColor) { //--called from user application
	//-- generates a color that is more toward gray
	//gecko stores RGB 
	a=hex2rgb(colorcode(inputColor))
	a=(R+G+B)/3
	R=Math.round(R-((R-a)*.2))
	G=Math.round(G-((G-a)*.2))
	B=Math.round(B-((B-a)*.2))
	showPreviewcolor(dec2hex(R,G,B))
}

function noColor() { //-- this function may be obsolete
	//-- it returns the word 'none' as the color.
	//   the application could also test for an empty value
	//   as would be sent by the 'transparent' button
	showPreviewcolor('none')
}


function xhairLoc(cell){ //-- position the crosshair
	var CrossHair=document.getElementById('xhair')
	if (!cell){cell=(document.getElementById('cell_'+(3*512/palettexstep/2)+'_'+paletteymax))}
	CrossHair.style.left=cell.offsetLeft+ (cell.offsetWidth- CrossHair.offsetWidth)/2
	CrossHair.style.top =cell.offsetTop + (cell.offsetHeight-CrossHair.offsetHeight)/2
}
function xhairOff(){document.getElementById('xhair').style.visibility='hidden'}
function xhairOn(){document.getElementById('xhair').style.visibility='visible'}

function colorunderxhair() {//-- when user clicks again on the crosshair to reacquire color
	// needs more work - this is mousedown, but mouseup on cell is also seen in IE6.
	var CrossHair=document.getElementById('xhair')
	crosshairx=Math.floor((CrossHair.offsetLeft+CrossHair.offsetWidth/2)/palettecellwidth)
	crosshairy=Math.floor((CrossHair.offsetTop+CrossHair.offsetHeight/2)/palettecellheight)
	showPreviewcolor(document.getElementById('cell_'+crosshairx+'_'+crosshairy).style.backgroundColor)
	setPreviewColor(document.getElementById('cell_'+crosshairx+'_'+crosshairy).style.backgroundColor)
	changeShades(document.getElementById('cell_'+crosshairx+'_'+crosshairy).style.backgroundColor)
}


function sendColor(newcolor) {//--receive color from application or keyboard and send to palette
	newcolor=userColorTesting(colorcode(newcolor))
	if (newcolor=="error") {return}
	showPreviewcolor(newcolor)
	setPreviewColor(newcolor)
	changeShades(newcolor)
}


//------------------------------------------------
//   these user functions go on user page
//------------------------------------------------
/*

//----
// functions to receive palette values
//----

	// palettecolor will be a hex value or empty value.
	// The NO COLOR button returns a null color value.
	// The application should address empty values as an
	// attempt to remove a color and apply it accordingly.
	// HTML and CSS values for foreground elements, borders, 
	// and backgrounds must each be handled differently.
	// User inputs of improperly formatted color codes will
	// be trapped and return an alert message. 
	// The erroneous value will not pass to the application.

function setColor(palettecolor) { 
	// This function must be in the application.
   	// This value arrives when the user clicks the Apply button.
	if (palettecolor!=''){
	document.bgColor=palettecolor}
	//if (palettecolor=="") {document.bgColor='none'//-process 'none' 
	//}else{document.bgColor=palettecolor}
}

function setDynaColor(palettecolor){
	// This function must be in the application.
	// When the user clicks a color cell or holds down 
	// the mouse button while dragging over the palette, 
	// the colors will arrive here.  The application may 
	// use these value or the activity can be ignored by 
	// not writing any code for this function.
	if (palettecolor!=''){
	document.bgColor=(palettecolor)}
}

//----
// function calls to set palette values
//----

//--pass color up from application software or keyboard input
//-- this function will also invoke the setDynaColor function with the palette results.
  	sendColor(color)


//-- create the color table in the application
//   set values as necessary or omit all values for default
//-- cellWid, cellHt, vertical or empty, omit transparent button or empty to show button
makeColorTable("","","","") //--w,h,v,omit

*/



//-----------------------------------
//    end
//-----------------------------------

