window.onload = initCSS;

function initCSS() {
	var style = readCookie("mystyle");
	if (style) {
		activeCSS(style);
	}
}
// Set Cookie
function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = ";expires="+date.toGMTString();
	} else {
	  expire = "";
	}
	document.cookie = name+"="+value+expires;
		
}


// activeCSS: Set de Hojas de Estilo para activar
function activeCSS(title)
{	var i, oneLink;

	for (i = 0; (oneLink = document.getElementsByTagName("link")[i]); i++)
	{

		if (oneLink.getAttribute("title") && findWord("stylesheet",oneLink.getAttribute("rel")))
		{

			oneLink.disabled = true;
			if (oneLink.getAttribute("title") == title)
			{

				oneLink.disabled = false;
			}
		}
	}
	setCookie("mystyle", title, 365);
}

// findWord: Used to find a full word (needle) in a string (haystack)
function findWord(needle, haystack) {
	return haystack.match(needle + "\\b");
}

// Read the Cookie
function readCookie(name) {
	var needle = name + "=";
	var cookieArray = document.cookie.split(';');
	for(var i=0;i < cookieArray.length;i++) {
		var pair = cookieArray[i];
		while (pair.charAt(0)==' ') {
			pair = pair.substring(1, pair.length);
		}
		if (pair.indexOf(needle) == 0) {
			return pair.substring(needle.length, pair.length);
		}
	}
	
	return null;
}

var tooltipayuda;

//Comienza el script para el tooltip
var ns4 = (document.layers)? true:false
            var ie4 = (document.all)? true:false
            var ns6 = (window.document.getElementById && !document.all) ? true: false;
            var coorX, coorY;

            if (ns6) document.addEventListener("mousemove", mouseMove, true)
            if (ns4) {document.captureEvents(Event.MOUSEMOVE); document.mousemove = mouseMove;}

            function mouseMove(e)    {
                if (ns4||ns6)    {
                    coorX = e.pageX;
                    coorY = e.pageY;
                }
                if (ie4)    {
                    coorX = event.x;
                    coorY = event.y;
                }
                coorX += document.body.scrollLeft;
                coorY += document.body.scrollTop;
                return true;
            }

            function ini()    {
                if (ie4)    document.body.onmousemove = mouseMove;
            }

            function mostrar(dato)    {
                tooltipayuda = window.document.getElementById("ayuda");
                mover();
                with(tooltipayuda)    {
                    style.visibility = "visible";
                    innerHTML = dato;
                }
            }

            function ocultar()    {
                tooltipayuda.style.visibility = "hidden";
            }

            function mover()
            {						
						
						with (tooltipayuda)
						{
					   
                    	style.top = (coorY + 10).toString()+"px";
                    	style.left = (coorX + 10).toString()+"px";
                   }

            }
