// CONSTANTES
COLORREF = "#FF0000"
FREQREF = 4;
COLORLINIA = "#000000";
FREQLINIA = 3;

COLORINACTIVO = "#999999";
COLORACTIVO = "#000000";
COLORATENUADO = "#999999";
FONDOATENUADO = "#FFFFFF";
COLORRESALTADO = "#000000";
FONDOFRASE = "#FFFFFF";

var arrayDeColores = new Array();
//blau
arrayDeColores[0] = 'CCCCFF';
//**rosa fluix
arrayDeColores[1] = 'FFCCCC';
//verd blau
arrayDeColores[2] = 'CCFFFF';
//**cremae¡
arrayDeColores[3] = 'FFFFCC';
//gris
arrayDeColores[4] = 'EEEEEE';
//**verd fuix
arrayDeColores[5] = 'CCFFCC';
//merda oca
arrayDeColores[6] = 'CCCC99';
//**salmó
arrayDeColores[7] = 'FFCC99';
//blau
arrayDeColores[8] = '99CCFF';
var MAXCOLORES = 9;


// FUNCIONES
function cruzCerrar(fAccionCerrar){
 var temp = ''
 temp = ''
 temp += '<table style="cursor: hand" border="0" cellspacing="0" cellpadding="0" onClick="' + fAccionCerrar + '">\n'
 temp += ' <tr>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += ' </tr>\n'
 temp += ' <tr>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += ' </tr>\n'
 temp += ' <tr>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += ' </tr>\n'
 temp += ' <tr>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += ' </tr>\n'
 temp += ' <tr>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += ' </tr>\n'
 temp += ' <tr>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += ' </tr>\n'
 temp += ' <tr>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += ' </tr>\n'
 temp += ' <tr>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += ' </tr>\n'
 temp += ' <tr>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += '  <td width=1 height=1 bgcolor="#000000"></td>\n'
 temp += ' </tr>\n'
 temp += '</table>\n'
 return  temp
}

function hacerTrim(texto)
{
	while ((texto.length>=0) && (texto.charAt(0)==" "))
		texto = texto.substring(1);
	while ((texto.length>=0) && (texto.charAt(texto.length-1)==" "))
		texto = texto.substring(0, texto.length-1);
	return texto;
}

var letrasEsp  = "ÀÁÂÃÄÅÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåèéêëìíîïòóôõöùúûüýÿ";
var letrasEspTrad = "AAAAAAEEEEIIIIOOOOOUUUUYaaaaaaeeeeiiiiooooouuuuyy";

function eliminarAcentos(pTexto)
{
	var res="";
	var i;
	var letra;
	var pos;
	for(i=0;i<pTexto.length;i++)
	{
		letra = pTexto.charAt(i);
		pos = letrasEsp.indexOf(letra);
		if (pos!=-1)
			letra = letrasEspTrad.charAt(pos);
		res = res + letra;
	}
	return res;
}

function substituirCaracteres(pTexto)
{
	var resultado = pTexto;
	var re = /'/gi;
	resultado = resultado.replace(re, "&#39;");
	re = /"/gi;
	resultado = resultado.replace(re, "&quot;");
	return resultado;
}

function comparar(pTexto1, pTexto2)
{
//	alert(pTexto1+ ' , ' +  pTexto2)
	var res = 0;
	var texto1 = hacerTrim(pTexto1.toLowerCase());
	var texto2 = hacerTrim(pTexto2.toLowerCase());
	var texto1Sin = eliminarAcentos(texto1);
	var texto2Sin = eliminarAcentos(texto2);
	if(texto1Sin > texto2Sin) res= -1;
	if(texto1Sin < texto2Sin) res= 1;
	if(texto1Sin == texto2Sin)
	{
		if(texto1>texto2) res = -1;
		if(texto1<texto2) res = 1;
	}
	return res;
}



function pintarPunto(pX, pY, pColor)
{
	var codigo = "";
	codigo = codigo
		+ '<DIV id="p' + pX +'_' + pY + '" style="position:absolute;'
		+ 'left:' + pX + 'px;'
		+ 'top:' + pY + 'px;'
		+ 'width:1px;height:1px;'
		+ 'z-index:0;">'
		+ '<table width="1" height="1" cellspacing="0" cellpadding="0" border="0" style="font-family:Arial;font-size:10px;color:' + pColor + ';">'
		+ '<tr><td width="1" height="1">&middot;</tr></td>'
		+ '</table>'
		+ '</div>\n'
	return(codigo);
}


function distancia(pXInicio, pYInicio, pXFinal, pYFinal)
{
	var d = Math.sqrt(
		((pXInicio-pXFinal) * (pXInicio-pXFinal))
		+ ((pYInicio-pYFinal) * (pYInicio-pYFinal)));
	return d;
}

function dibujarLinia(pXInicio, pYInicio, pXFinal, pYFinal, pColor, pFreq)
{
	var uX = pXFinal - pXInicio;
	var uY = pYFinal - pYInicio;
	var i;
	var x,y;
	var lambda = distancia(pXInicio, pYInicio, pXFinal, pYFinal)/pFreq;
	var codigo = "";
	for (i=0;i<lambda;i++)
	{
		x = pXInicio + ((i/lambda) * uX)
		y = pYInicio + ((i/lambda) * uY)
		codigo = codigo + pintarPunto(x,y, pColor);
	}
	return codigo;
}

function comprobarNumero(pNumero)
{
	var res=0;
	if (pNumero == "") res = -1
	else
	{
		if (isNaN(pNumero)) res = -2;
	}
	return res;
}