// JavaScript Document
//  requiere varias.js

	var newWin_doc = null;
	var newWin = null;
	var returnObj = null;
	var returnType = 0;


/********************************************************************************************************************************************************************/
/** EG - 21/08/2008 Interferia con la funcion trim de AXYS
	function trim(strText) {
    	while (strText.substring(0,1) == ' ')
        	strText = strText.substring(1, strText.length);
    	while (strText.substring(strText.length-1,strText.length) == ' ')
        	strText = strText.substring(0, strText.length-1);
   		return strText;
	}
*/

/********************************************************************************************************************************************************************/
	function verifycolor() {
		oCH = oBusca('ColorHex'+returnObj);
		string = oCH.value;
		if (string == "") {alert("Color Invalido!!!"); return null;};

		string = string.replace(/#/,"");
		string = trim(string);
		if (string.length != 6) {alert("Color Invalido!!!"); return null;};
	  	stdstr = '0123456789abcdefABCDEF';

	  	for (i=0; i<string.length; i++) {
	    	chr = string.charAt(i);
	   		if (stdstr.indexOf(chr) == -1) {alert("Color Invalido!!!"); return null;};
	  	}
	  	return string;
	}

/********************************************************************************************************************************************************************/
	function complementacolor(color) {
		string = color;
		if (string == "") {alert("Color Invalido!!!"); return null;};

		string = string.replace(/#/,"");
		string = string.toUpperCase();
		string = trim(string);
		if (string.length != 6) {alert("Color Invalido!!!"); return null;};

  		cad = "";
	  	for (i=0; i<string.length; i++) {
	    	chr = string.charAt(i);
			switch(chr)
			{
			 case '0':
			   cad = cad + 'F';
			   break;
			 case '1':
			   cad = cad + 'E';
			   break;
			 case '2':
			   cad = cad + 'D';
			   break;
			 case '3':
			   cad = cad + 'C';
			   break;
			 case '4':
			   cad = cad + 'B';
			   break;
			 case '5':
			   cad = cad + 'A';
			   break;
			 case '6':
			   cad = cad + '9';
			   break;
			 case '7':
			   cad = cad + '8';
			   break;
			 case '8':
			   cad = cad + '7';
			   break;
			 case '9':
			   cad = cad + '6';
			   break;
			 case 'A':
			   cad = cad + '5';
			   break;
			 case 'B':
			   cad = cad + '4';
			   break;
			 case 'C':
			   cad = cad + '3';
			   break;
			 case 'D':
			   cad = cad + '2';
			   break;
			 case 'E':
			   cad = cad + '1';
			   break;
			 case 'F':
			   cad = cad + '0';
			   break;
			}
	  	}
	  	return cad;
	}
/********************************************************************************************************************************************************************/
	function customcolor(){
		str = verifycolor();
		if (str != null){preview(str)};
	}

/********************************************************************************************************************************************************************/
	function preview(color) {
		//alert("testing" + color);
		oCP = oBusca('ColorPreview'+returnObj);
		oCH = oBusca('ColorHex'+returnObj);
 		oCP.style.backgroundColor = '#' + color;
 		oCH.value = '#' + color;
	}

/********************************************************************************************************************************************************************/
	function returncolor() {
  		color = verifycolor();
  		oRet = oBusca(returnObj);
  		if (color == null) {alert("Color Invalido!!!");}
  		else {
			if (returnType == 0) {
    			oRet.value = '#' + color.toUpperCase();
			} else if (returnType == 1) {
				oRet.style.backgroundColor = '#' + color.toUpperCase();
				oRet.style.color = '#' + complementacolor(color);
				//oRet.style.borderColor = '#' + color.toUpperCase();
			} else {
				oRet.value = '#' + color.toUpperCase();
				oRet.style.backgroundColor = '#' + color.toUpperCase();
				oRet.style.color = '#' + complementacolor(color);
				//oRet.style.borderColor = '#' + color.toUpperCase();
			}
    		Mostrar_CP(returnObj);
  		}
	}

/********************************************************************************************************************************************************************/
	function _init(){
		var count = 0;
		var rbg = new Array("00", "33","66", "99", "cc","ff");
		var color = "000000";
		_html = "<table class=\"mytable\"><tr>";
		for (var i=0; i<rbg.length; i++){
			for (var j=0; j<3; j++){
    			for (var k=0; k<rbg.length; k++){
					color = rbg[j] + rbg[k] + rbg[i];
    				_html += "<td onmouseover=\"preview('" + color + "');\" onclick=\"returncolor();\" width=8 height=11 bgcolor=" + color + "> </td>";
					count++;
					if ((count % 18) == 0) {
						_html += "</tr><tr>";
					}
				}
			}
		}
		for (var i=0; i<rbg.length; i++){
			for (var j=3; j<rbg.length; j++){
    			for (var k=0; k<rbg.length; k++){
					color = rbg[j] + rbg[k] + rbg[i];
    				_html += "<td onmouseover=\"preview('" + color + "');\" onclick=\"returncolor();\" width=8 height=11 bgcolor=" + color + "> </td>";
					count++;
					if ((count % 18) == 0) {
						_html += "</tr><tr>";
					}
				}
			}
		}
		_html +="</tr></table>";
		
return _html;
	}

/********************************************************************************************************************************************************************/
function show_color_dialog(apunta, type) {

	returnType = 0;
	if (type) {returnType = type;}
 oVentana.size();
 var x = oVentana.width;
 var y = oVentana.height;
 var titulo = "Selector de Color";
 	_html1 = "<link rel='stylesheet' href='"+dirLibsPHP+"css/librerias.css'>" +
 	"<a href=\"javascript:Mostrar_CP('" + apunta + "')\"><img src=\""+dirLibImages+"color.png\" border='0' alt='Color'><\/a>" +
	"<img id=\"img_"+apunta+"\" src=\""+dirLibImages+"bg.png\" width=\""+x+"\" height=\""+y+"\" style='display:none' class=\"xHabilita\" >" +
	"<div id=\"ColorPicker['" + apunta +"']\" style='display:none' class='ColorPicker'>" +
   "<table width='100%' height='100%' border='0' cellSpacing='0' cellPadding='0'>  " +
   "<tr class='titulo'> " +
	"<td width='95%'> " + titulo +
	"<\/td> " +
	"<td> " +
	"<a href=\"javascript:Mostrar_CP('" + apunta + "')\"><img src=\""+dirLibImages+"x.gif\" border='0' alt='Cerrar'><\/a> " +
	"<\/td> " +
	"<\/tr> " +
	"<tr>" +
	"<td colSpan='2'> " +
	"<table border=0 cellspacing=0 cellpadding=4 width=100%><tr>" +
	"<td style='background-color: buttonface;' valign=center><div style='background-color: #000000; padding: 1; height: 21px; width: 50px'><div id='ColorPreview"+apunta+"' style='height: 100%; width: 100%'></div></div></td>" +
	"<td style='background-color: buttonface;' valign=center><input type='text' id='ColorHex"+apunta+"' value='#000000' size=9 style='font-size: 11px'></td>" +
	"<td style='background-color: buttonface;' valign=center><button onclick='customcolor();'>Ver</button></td>" +
	"<td style='background-color: buttonface;' valign=center><button onclick='returncolor();'>Aceptar</button></td>" +
	"<td style='background-color: buttonface;'' width=100%></td></tr></table>" +
	"<table><tr><td>" +
	"<table><tr><td onmouseover=\"preview('000000');\" onclick=\"returncolor();\" width=8 height=11 bgcolor='#000000'> </td></tr>" +
	"<tr><td onmouseover=\"preview('333333');\" onclick=\"returncolor();\" width=8 height=11 bgcolor='#333333'> </td></tr>" +
	"<tr><td onmouseover=\"preview('666666');\" onclick=\"returncolor();\" width=8 height=11 bgcolor='#666666'> </td></tr>" +
	"<tr><td onmouseover=\"preview('999999');\" onclick=\"returncolor();\" width=8 height=11 bgcolor='#999999'> </td></tr>" +
	"<tr><td onmouseover=\"preview('cccccc');\" onclick=\"returncolor();\" width=8 height=11 bgcolor='#cccccc'> </td></tr>" +
	"<tr><td onmouseover=\"preview('ffffff');\" onclick=\"returncolor();\" width=8 height=11 bgcolor='#ffffff'> </td></tr>" +
	"<tr><td onmouseover=\"preview('ff0000');\" onclick=\"returncolor();\" width=8 height=11 bgcolor='#ff0000'> </td></tr>" +
	"<tr><td onmouseover=\"preview('00ff00');\" onclick=\"returncolor();\" width=8 height=11 bgcolor='#00ff00'> </td></tr>" +
	"<tr><td onmouseover=\"preview('0000ff');\" onclick=\"returncolor();\" width=8 height=11 bgcolor='#0000ff'> </td></tr>" +
	"<tr><td onmouseover=\"preview('ff00ff');\" onclick=\"returncolor();\" width=8 height=11 bgcolor='#ff00ff'> </td></tr>" +
	"<tr><td onmouseover=\"preview('ffff00');\" onclick=\"returncolor();\" width=8 height=11 bgcolor='#ffff00'> </td></tr>" +
   "<tr><td onmouseover=\"preview('00ffff');\" onclick=\"returncolor();\" width=8 height=11 bgcolor='#00ffff'> </td></tr>" +
	"</table></td><td>";

	_html2 = _init();

	_html3 = "</td></tr></table>" +
   "<\/td><\/tr>" +
	"<\/tbody><\/table><\/div>";
	
	_html = _html1 + _html2 + _html3;
   oDest = oBusca("cCP_" + apunta);
   oDest.innerHTML = _html;
}

/********************************************************************************************************************************************************************/
     function Mostrar_CP(apunta)
	  {
       var img_disable = "img_" + apunta;
       var oDestino = oBusca("ColorPicker['" + apunta +"']");
	   if(oDestino.style.display == 'none')
	   {
	    obj_show(oDestino);
		 _img = oBusca("img_"+apunta);
	    oVentana.size();
		 _w = oVentana.width;
		 _h = oVentana.height;
		 obj_setStyle(_img,"width",_w);
		 obj_setStyle(_img,"height",_h);
   	 obj_show(_img);
   	 returnObj = apunta;
	   }
	   else
		{
		 obj_hide(oDestino);
	 	 obj_hide(oBusca(img_disable));
	 	 returnObj = null;
	   }
  	  }
  	  
