// Title: Tigra Color Picker
// URL: http://www.softcomplex.com/products/tigra_color_picker/
// Version: 1.1
// Date: 06/26/2003 (mm/dd/yyyy)
// Feedback: feedback@softcomplex.com (specify product title in the subject)
// Note: Permission given to use this script in ANY kind of applications if
//    header lines are left unchanged.
// Note: Script consists of two files: picker.js and picker.html
// About us: Our company provides offshore IT consulting services.
//    Contact us at sales@softcomplex.com if you have any programming task you
//    want to be handled by professionals. Our typical hourly rate is $20.

var TCP = new TColorPicker();

function TCPopup(field, palette) {
	this.field = field;
	this.initPalette = !palette || palette > 2 ? 0 : palette;
	var w = 194, h = 150,
	move = screen ? 
		',left=' + ((screen.width - w) >> 1) + ',top=' + ((screen.height - h) >> 1) : '', 
	o_colWindow = window.open('/javascript/picker.htm', null, "help=no,status=no,scrollbars=no,resizable=no" + move + ",width=" + w + ",height=" + h + ",dependent=yes", true);
	o_colWindow.opener = window;
	o_colWindow.focus();
}

function TCBuildCell (R, G, B, w, h) {
	return '<td bgcolor="#' + this.dec2hex((R << 16) + (G << 8) + B) + '"><a href="javascript:P.S(\'' + this.dec2hex((R << 16) + (G << 8) + B) + '\')" onmouseover="P.P(\'' + this.dec2hex((R << 16) + (G << 8) + B) + '\')"><img src="/images/pixel.gif" width="' + w + '" height="' + h + '" border="0"></a></td>';
}

function TCSelect(c) {
	this.field.value = '#' + c.toUpperCase();
	this.win.close();
}

function GetCString ( c ) 
{
	var cString = '';
		
	if ( c.toUpperCase() == 'D6B264' ) cString = 'Butterscotch';
	if ( c.toUpperCase() == '335058' ) cString = 'Petrel';
	if ( c.toUpperCase() == '4F438F' ) cString = 'Prussian Blue';
	if ( c.toUpperCase() == 'E1433A' ) cString = 'Japan Red';
	if ( c.toUpperCase() == '9C9B80' ) cString = 'Grey Marle';
	if ( c.toUpperCase() == '7DB246' ) cString = 'Fluro Lime';
	if ( c.toUpperCase() == '2F4366' ) cString = 'Denim';
	if ( c.toUpperCase() == '7B9AC6' ) cString = 'Cronnula Blue';

	if ( c.toUpperCase() == '7E6135' ) cString = 'Olive';
	if ( c.toUpperCase() == 'A49159' ) cString = 'Khaki';
	if ( c.toUpperCase() == '7E7C87' ) cString = 'Slate Grey';
	if ( c.toUpperCase() == 'EE9BC9' ) cString = 'Pink';
	if ( c.toUpperCase() == '554A96' ) cString = 'Flag Blue';
	if ( c.toUpperCase() == 'E65133' ) cString = 'Flag Red';
	if ( c.toUpperCase() == 'A63845' ) cString = 'Dark Red';
	if ( c.toUpperCase() == '1E4160' ) cString = 'Oxford Blue';

	if ( c.toUpperCase() == '86363F' ) cString = 'Cardinal';
	if ( c.toUpperCase() == '5D7EC5' ) cString = 'Sky';
	if ( c.toUpperCase() == '000000' ) cString = 'Black';
	if ( c.toUpperCase() == 'FFFFFF' ) { cString = 'White'; bg = 'black' }
	if ( c.toUpperCase() == 'C7CCD0' ) cString = 'Light Grey';
	if ( c.toUpperCase() == '5D7EC5' ) cString = 'Royal';
	if ( c.toUpperCase() == '343B45' ) cString = 'Navy';
	if ( c.toUpperCase() == '794A89' ) cString = 'Violet';

	if ( c.toUpperCase() == '582E3A' ) cString = 'Maroon';
	if ( c.toUpperCase() == '5C4130' ) cString = 'Brown';
	if ( c.toUpperCase() == 'F7AE2E' ) cString = 'Gold O';
	if ( c.toUpperCase() == 'F58533' ) cString = 'Florida Gold';
	if ( c.toUpperCase() == 'F15F2E' ) cString = 'Orange';
	if ( c.toUpperCase() == 'E5403C' ) cString = 'Red';
	if ( c.toUpperCase() == 'BD3F4A' ) cString = 'Scarlet';
	if ( c.toUpperCase() == 'F5EED2' ) { cString = 'Natural'; bg = 'black' }

	return cString;
}

function TCPaint(c, b_noPref) {
	var bg = 'white';
	
	var cString = GetCString( c );
	
	c = (b_noPref ? '' : '#') + c.toUpperCase();
	if (this.o_samp) 
		this.o_samp.innerHTML = '<font face=Tahoma size=2 color=' + bg + '>' + cString +' <font color=' + bg + '>' + c + '</font></font>'
	if(this.doc.layers)
		this.sample.bgColor = c;
	else { 
		if (this.sample.backgroundColor != null) this.sample.backgroundColor = c;
		else if (this.sample.background != null) this.sample.background = c;
	}
}

function TCGenerateSafe() {
	var s = '';
	for (j = 0; j < 12; j ++) {
		s += "<tr>";
		for (k = 0; k < 3; k ++)
			for (i = 0; i <= 5; i ++)
				s += this.bldCell(k * 51 + (j % 2) * 51 * 3, Math.floor(j / 2) * 51, i * 51, 8, 10);
		s += "</tr>";
	}
	return s;
}

function TCGenerateWin() {
	var s = '';
	for (j = 0; j < 12; j ++) {
		s += "<tr>";
		for (k = 0; k < 3; k ++)
			for (i = 0; i <= 5; i++)
				s += this.bldCell(i * 51, k * 51 + (j % 2) * 51 * 3, Math.floor(j / 2) * 51, 8, 10);
		s += "</tr>";
	}
	return s	
}

function TCGenerateStud() {
	var s = '';
	// row 1
	s += "<tr>";
	s += this.bldCell(214, 178, 100, 12, 15); 	// Butterscotch
	s += this.bldCell(51, 80, 88, 12, 15); 		// Petrel		
	s += this.bldCell(79, 67, 143, 12, 15);		// Prussian Blue
	s += this.bldCell(225, 67, 58, 12, 15);		// Japan Red
	s += this.bldCell(156, 155, 128, 12, 15);	// Grey Marle
	s += this.bldCell(125, 178, 70, 12, 15); 	// Fluro Lime
	s += this.bldCell(47, 67, 102, 12, 15); 	// Denim
	s += this.bldCell(123, 154, 198, 12, 15);	// Cronnula Blue
	s += "</tr>";
	s += "<tr>";
	s += this.bldCell(126, 97, 53, 12, 15); 	// Olive
	s += this.bldCell(164, 145, 89, 12, 15); 	// Khaki		
	s += this.bldCell(126, 124, 135, 12, 15);	// Slate Grey
	s += this.bldCell(238, 155, 201, 12, 15);	// Pink
	s += this.bldCell(85, 74, 150, 12, 15); 	// Flag Blue
	s += this.bldCell(230, 81, 51, 12, 15);		// Flag Red
	s += this.bldCell(166, 56, 69, 12, 15);		// Dark Red
	s += this.bldCell(30, 65, 96, 12, 15);		// Oxford Blue
	s += "</tr>";
	s += "<tr>";
	s += this.bldCell(134, 54, 63, 12, 15); 	// Cardinal
	s += this.bldCell(93, 126, 197, 12, 15); 	// Sky		
	s += this.bldCell(0, 0, 0, 12, 15);			// Black
	s += this.bldCell(255, 255, 255, 12, 15);	// White
	s += this.bldCell(199, 204, 208, 12, 15); 	// Light Grey
	s += this.bldCell(93, 126, 197, 12, 15); 	// Royal		
	s += this.bldCell(52, 59, 69, 12, 15);		// Navy
	s += this.bldCell(121, 74, 137, 12, 15);	// Violet
	s += "</tr>";

	s += "<tr>";
	s += this.bldCell(88, 46, 58, 12, 15); 		// Maroon
	s += this.bldCell(92, 65, 48, 12, 15);		// Brown
	s += this.bldCell(247, 174, 46, 12, 15);	// Gold O
	s += this.bldCell(245, 133, 51, 12, 15);	// Flrida Gold
	s += this.bldCell(241, 95, 46, 12, 15);		// Orange 
	s += this.bldCell(229, 64, 60, 12, 15);		// Red
	s += this.bldCell(189, 63, 74, 12, 15);		// Scarlet
	s += this.bldCell(245, 238, 210, 12, 15); 	// Natural	
	s += "</tr>";
	return s	
}


function TCGenerateGray() {
	var s = '';
	for (j = 0; j <= 15; j ++) {
		s += "<tr>";
		for (k = 0; k <= 15; k ++) {
			g = Math.floor((k + j * 16) % 256);
			s += this.bldCell(g, g, g, 9, 7);
		}
		s += '</tr>';
	}
	return s
}

function TCDec2Hex(v) {
	v = v.toString(16);
	for(; v.length < 6; v = '0' + v);
	return v;
}

function TCChgMode(v) {
	for (var k in this.divs) this.hide(k);
	this.show(v);
}

function TColorPicker(field) {
	this.build0 = TCGenerateStud;
	this.build1 = TCGenerateSafe;
	//this.build1 = TCGenerateWind;
	this.build2 = TCGenerateGray;
	this.show = document.layers ? 
		function (div) { this.divs[div].visibility = 'show' } :
		function (div) { this.divs[div].visibility = 'visible' };
	this.hide = document.layers ? 
		function (div) { this.divs[div].visibility = 'hide' } :
		function (div) { this.divs[div].visibility = 'hidden' };
	// event handlers
	this.C       = TCChgMode;
	this.S       = TCSelect;
	this.P       = TCPaint;
	this.popup   = TCPopup;
	this.draw    = TCDraw;
	this.dec2hex = TCDec2Hex;
	this.bldCell = TCBuildCell;
	this.divs = [];
}

function TCDraw(o_win, o_doc) {
	this.win = o_win;
	this.doc = o_doc;
	var 
	s_tag_openT  = o_doc.layers ? 
		'layer visibility=hidden top=54 left=5 width=182' : 
		'div style=visibility:hidden;position:absolute;left:6px;top:54px;width:182px;height:0',
	s_tag_openS  = o_doc.layers ? 'layer top=32 left=6' : 'div',
	s_tag_close  = o_doc.layers ? 'layer' : 'div'
		
	this.doc.write('<' + s_tag_openS + ' id=sam name=sam><table cellpadding=0 cellspacing=0 border=1 width=181 align=center class=bd><tr><td align=center height=18><div id="samp"></div></td></tr></table></' + s_tag_close + '>');
	this.sample = o_doc.layers ? o_doc.layers['sam'] : 
		o_doc.getElementById ? o_doc.getElementById('sam').style : o_doc.all['sam'].style

	for (var k = 0; k < 3; k ++) {
		this.doc.write('<' + s_tag_openT + ' id="p' + k + '" name="p' + k + '"><table cellpadding=0 cellspacing=0 border=1 align=center>' + this['build' + k]() + '</table></' + s_tag_close + '>');
		this.divs[k] = o_doc.layers 
			? o_doc.layers['p' + k] : o_doc.all 
				? o_doc.all['p' + k].style : o_doc.getElementById('p' + k).style
	}
	if (!o_doc.layers && o_doc.body.innerHTML) 
		this.o_samp = o_doc.all 
			? o_doc.all.samp : o_doc.getElementById('samp');
	this.C(this.initPalette);
	if (this.field.value) this.P(this.field.value, true)
}
