		// Déposé par Frosty sur www.toutjavascript.com
		// 27/5/2003 - Ajout compatibilité IE5 sur MacOS
		// 5/6/2003  - Ajout compatibilité Mozilla

		/*****************************************************************
		* Script Color Picker écrit par Frosty (Maxime Pacary) - Mai 2003
		******************************************************************/
		

// var. globale
		var detail = 50; // nombre de nuances de couleurs dans la barre de droite
		
		// ne pas modifier
		var strhex = "0123456789ABCDEF";
		var i;
		
		// conversion decimal (0-255) => hexa
		function dechex(n) {
			return strhex.charAt(Math.floor(n/16)) + strhex.charAt(n%16);
		}

		// détection d'un clic souris sur la "palette" (à gauche)
		function mouse_click(e)
		{
			
			x = e.offsetX ? e.offsetX : e.clientX-e.target.x;
			y = e.offsetY ? e.offsetY : e.clientY-e.target.y;
			
			// calcul de la couleur à partir des coordonnées du clic
			var part_width = document.all ? document.all.color_picker.width/6 : document.getElementById('color_picker').width/6;
			var part_detail = detail/2;
			var im_height = document.all ? document.all.color_picker.height : document.getElementById('color_picker').height;
			
			
			var red = (x >= 0)*(x < part_width)*255
					+ (x >= part_width)*(x < 2*part_width)*(2*255 - x * 255 / part_width)
					+ (x >= 4*part_width)*(x < 5*part_width)*(-4*255 + x * 255 / part_width)
					+ (x >= 5*part_width)*(x < 6*part_width)*255;
			var blue = (x >= 2*part_width)*(x < 3*part_width)*(-2*255 + x * 255 / part_width)
					+ (x >= 3*part_width)*(x < 5*part_width)*255
					+ (x >= 5*part_width)*(x < 6*part_width)*(6*255 - x * 255 / part_width);
			var green = (x >= 0)*(x < part_width)*(x * 255 / part_width)
					+ (x >= part_width)*(x < 3*part_width)*255
					+ (x >= 3*part_width)*(x < 4*part_width)*(4*255 - x * 255 / part_width);
			
			var coef = (im_height-y)/im_height;
			
			// composantes de la couleur choisie sur la "palette"
			red = 128+(red-128)*coef;
			green = 128+(green-128)*coef;
			blue = 128+(blue-128)*coef;
			
			// mise à jour de la couleur finale
			changeFinalColor('#' + dechex(red) + dechex(green) + dechex(blue));
			
			
			// mise à jour de la barre de droite en fonction de cette couleur
			for(i = 0; i < detail; i++)
			{
				if ((i >= 0) && (i < part_detail))
				{
					var final_coef = i/part_detail ;
					var final_red = dechex(255 - (255 - red) * final_coef);
					var final_green = dechex(255 - (255 - green) * final_coef);
					var final_blue = dechex(255 - (255 - blue) * final_coef);
				}
				else
				{
					var final_coef = 2 - i/part_detail ;
					var final_red = dechex(red * final_coef);
					var final_green = dechex(green * final_coef);
					var final_blue = dechex(blue * final_coef);
				}
				color = final_red + final_green + final_blue ;
				document.all ? document.all('gs'+i).style.backgroundColor = '#'+color : document.getElementById('gs'+i).style.backgroundColor = '#'+color;
			}	
		}
		
		// pour afficher la couleur finale choisie
		function changeFinalColor(color)
		{
			document.forms['colpick_form'].elements['btn_choose_color'].style.backgroundColor = color;
			document.forms['colpick_form'].elements['btn_choose_color'].style.borderColor = color;
			document.forms['colpick_form'].elements['html_code'].value = color;
		}

		
		// "renvoyer" la couleur en cliquant sur OK
		function send_color(field)
		{

			   var new_color = document.forms['colpick_form'].elements['btn_choose_color'].style.backgroundColor;
			   exp_rgb = new RegExp("rgb","g");
			   if (exp_rgb.test(new_color))
			   {
			   	exp_extract = new RegExp("[0-9]+","g");
			   	var tab_rgb = new_color.match(exp_extract);
			   	
			      new_color = dechex(parseInt(tab_rgb[0]))+dechex(parseInt(tab_rgb[1]))+dechex(parseInt(tab_rgb[2]));
			   }
           		    
			    new_color = new_color.replace("#", "");
			    document.getElementById('input['+field+']').value = new_color;
			    document.getElementById('picker['+field+']').style.background = new_color;
			    parent.ShowDivModify('off');
		            change_preview(field, new_color);
		}
		
		window.focus();
		

