

//load handler
window.onload = function()
{
	//insantiate the color picker ('canvas-id', 'swatch-id', 'field-id')
	var picker = new colorPicker('canvas', 'swatch', 'usr_req_color');
	
}



//color picker 
function colorPicker(canvas, swatch, field)
{
	//display area
	canvas = document.getElementById(canvas); 
	
	//hidden field
	field = document.getElementById(field); 
	
	//swatch
	try{
	this.swatch = document.getElementById(swatch); 
	
	//bind click handler to swatch
	this.swatch.onclick = function(e)
	{
		//store event argument, converting argument for IE
		this.target = !e ? window.event.srcElement : e.target;
		
		//if the target is a text node
		//this is for safari, in which events can come from text nodes
		if(this.target.nodeName == '#text')
		{
			//convert reference to parent
			this.target = this.target.parentNode;
		}
		
		//if the target is a link
		if(/^[a]/i.test(this.target.nodeName))
		{
			//get color from qStr value
			this.color = this.target.href.split('=')[1];
			
			//set display area background - check if starting with a hash
			if (this.color.charAt(0)!='#') this.color='#'+this.color;
			canvas.style.background = this.color;
			
			//write value to hidden field
			field.value = this.color;
			
			//don't follow the link
			return false;
		}
	}
	}catch(e)
	{
	//no swatch	
	}
};


