// ----- Specific global values
var MixerDestObject;
var MixerDestProperty;

// ----- Start color chooser
function MixerColorChooser(destobject, destproperty)
{
	// ----- Store the destination object
	MixerDestObject = destobject;
	if (destproperty == "")
		MixerDestProperty = "value";
	else
		MixerDestProperty = destproperty;

	// ----- Get the initial value
	eval("MixerInternalSelectColor(MixerDestObject."+MixerDestProperty+")");

	// ----- Select the ilayer
	var obj = document.all['MixerPopup'];

	// ----- Set the popup position
	obj.style.left = document.body.scrollLeft+event.clientX;
	obj.style.top	= document.body.scrollTop+event.clientY;

	// ----- Close the ilayer
	obj.style.visibility = "visible";
}

// ----- Close function for color chooser without selection
function MixerInternalClosePopup()
{
	// ----- Select the ilayer
	var obj = document.all['MixerPopup'];

	// ----- Close the ilayer
	obj.style.visibility = "hidden";
}

// ----- Close function for color chooser with selection
function MixerInternalSelectClose(){
	// ----- Select the ilayer
	var obj = document.all['MixerPopup'];

	// ----- Get the value and paste it to destination object
	MixerDestObject.value = document.forms.mixerform.hexval.value;

	// ----- Look for object type
	eval("MixerDestObject."+MixerDestProperty+" = document.forms.mixerform.hexval.value");

	// ----- Close the ilayer
	obj.style.visibility = "hidden";
}

// ----- Internal color selection
function MixerInternalSelectColor(hexval){
	// ----- Paste the color value
	document.forms.mixerform.hexval.value = hexval;

	// ----- Change the color viewer
	document.all.mixercell.bgColor = hexval;
}

// ----- Popup window creator
function MixerGeneratePopup(){
	// ----- Generate the div tag

var butt_on = "<img src=images/x.gif border=0 onClick='MixerInternalClosePopup()'>";
var name_on = "<font style='font-family:arial;font-size:10pt;font-weight:bold;color:white'>&nbsp;&nbsp;Color Mixer</font>";
var r_word = "<font style='font-family:arial;font-size:10pt;font-weight:bold;color:white'>Red";
var b_word = "<font style='font-family:arial;font-size:10pt;font-weight:bold;color:white'>Blue";
var g_word = "<font style='font-family:arial;font-size:10pt;font-weight:bold;color:white'>Green";

	document.write("<div id=MixerPopup style='position:absolute; left:118px; top:214px; width:212px; height:112px; z-index:1; visibility:hidden; background-color: #FFFFFF; layer-background-color: #FFFFFF; border: 1px none #000000'> ");
	document.write("<table width=100% border=0 cellspacing=0 cellpadding=1 bgcolor=#CCCDDD>");
	document.write("<tr><td align=left bgcolor=#CCCDDD>"+name_on+"</td>");
	document.write("<td align=right bgcolor=#CCCDDD>"+butt_on+"</td></tr>");
	document.write("<tr><td align=center colspan=2> ");
	document.write("<form name=mixerform method=post><table border=0 cellspacing=0 width=100% bgcolor=#FFFFFF><tr><td align=center>");
	
	document.write("<table border=0 cellspacing=0 width=80%>");
	document.write("<tr>");
	document.write("<td width=33% align=center bgcolor=red>"+r_word+"</td>");
	document.write("<td width=33% align=center bgcolor=green>"+g_word+"</td>");
	document.write("<td width=33% align=center bgcolor=blue>"+b_word+"</td>");
	document.write("</tr>");
	document.write("<tr>");
	document.write("<td width=33% align=center bgcolor='red'><input type='text' name='red' size='4'></td>");
	document.write("<td width=33% align=center bgcolor='green'><input type='text' name='green' size='4'></td>");
	document.write("<td width=33% align=center bgcolor='blue'><input type='text' name='blue' size='4'></td>");
	document.write("</tr>");
	document.write("</table>");
	
	document.write("<table border='0' cellspacing='0' width='80%' bgcolor='#FFFFFF'>");
	document.write("<tr><td align=center valign=middle><input type=text name=hexval size=7></td></tr>");
	document.write("<tr><td id='mixercell' align='center' valign='middle' height='50'>&nbsp;</td></tr>");
	document.write("</table>");
	
	document.write("<table border='0' cellspacing='0' width='100%' bgcolor='#FFFFFF'>");
	document.write("<tr><td align=center>");
	document.write("<input type=button value='Test' onClick='showRGB(this.form)'> <input type=button name=select value=Select onClick='MixerInternalSelectClose()'>");
	document.write("</td></tr></table>");
	document.write("<p align=left style='margin-left:5px'><font style='font-family:arial;font-size:8pt;color:green'><b>Help:</b>");

	document.write("<br>1. 255 is lightest (White)");
	document.write("<br>2. 0 is heavest (Saturation)");
	document.write("<br>3. Mixtures of RGB create colors");
	document.write("<br>4. Change RGB numbers - click Test");
	document.write("<br>5. When happy click Select");
	document.write("<br>6. Enter RGB numbers (0 to 255)");
	document.write("<br>7. All three numbers required");
	document.write("<br>8. Numbers Greater Than 255 ignored</p>");

	document.write("</td></tr></table>");
	document.write("</td></tr></table></div></form>");



}

// ----- Call the Color Chooser Popup Window generator function
MixerGeneratePopup();