function resizeContent(containerDiv, widthPercentage, heightPercentage, useScrollBars) {
	var width = getWindowWidth(useScrollBars);
	var height = getWindowHeight(useScrollBars);

	containerDiv.style.width = width * (widthPercentage / 100) + "px";
	containerDiv.style.height = height * (heightPercentage / 100) + "px";
}

function centerContent(content, useScrollBars, centerHeight, centerWidth) {
	var width = getWindowWidth(useScrollBars);
	var height = getWindowHeight(useScrollBars);

	var top = (parseInt(height) - parseInt(content.offsetHeight)) / 2;
	var left = (parseInt(width) - parseInt(content.offsetWidth)) / 2;

	if (content.parentNode != undefined) {
		top -= content.parentNode.offsetTop;
		left -= content.parentNode.offsetLeft;
	}

	if (centerHeight) {
		content.style.top = top + "px";
	}
	if (centerWidth) {
		content.style.left = left + "px";
	}
}

/* --- Manejador de divs, mostrar y ocultar --- */
function hideDiv(divId) {
	var div = document.getElementById(divId);
	if (div.style.display == "") {
		div.style.display = "none";
	} else {
		div.style.display = "";
	}
}
/* -------------------------------------------- */

/* --- Manejador del div de "Cargando..." --- */
function createLoadingDiv(message) {
	var loadingDiv = document.createElement("DIV");

	loadingDiv.id = "loadingDiv";

	loadingDiv.innerHTML = message;
	loadingDiv.className = "loadingDiv";

	document.body.appendChild(loadingDiv);

	centerContent(loadingDiv, false, false, true);
	loadingDiv.style.display = 'none';
}

function showLoadingDiv() {
	var loadingDiv = document.getElementById("loadingDiv");
	if (loadingDiv != undefined) {
		loadingDiv.style.display = '';
	}
}

function hideLoadingDiv() {
	var loadingDiv = document.getElementById("loadingDiv");
	if (loadingDiv != undefined) {
		loadingDiv.style.display = 'none';
	}
	if (fixPngs != undefined) {
		fixPngs();
	}
}
/* ------------------------------------------ */

/* --- Cambiador de leyenda de información --- */
function changeInformationLegend(newLegend) {
	var information = document.getElementById("information");
	var informationText = document.getElementById("informationText");
	informationText.innerHTML = newLegend;
	information.style.visibility = 'visible';
	setTimeout("hideInformationLegend();", (30 * 1000));
}

function hideInformationLegend() {
	var information = document.getElementById("information");
	information.style.visibility = 'hidden';
}
/* ------------------------------------------- */

/* --- Genera curvas en los bordes de objetos --- */
function roundCorners(page, roundType, cornerSize, borderSize, shadowSize) {
	var options = new Object();
	options.corner = 8;
	options.shadow = 0;
	options.border = 1;

	if (roundType != undefined) {
		options.edges = roundType;
	}

	if (cornerSize != undefined) {
		options.corner = cornerSize;
	}

	if (borderSize != undefined) {
		options.border = borderSize;
	}

	if (shadowSize != undefined) {
		options.shadow = shadowSize;
	}

	var shadedBorder = RUZEE.ShadedBorder.create(options);

	shadedBorder.render(page);
}

function roundCornersOld(page, borderColor, roundType) {
	if (checkRico()) {
		var roundCorners = Rico.Corner.round.bind(Rico.Corner);
		var options = new Object();

		if (borderColor != undefined) {
			options.border = borderColor;
		}
		if (roundType != undefined) {
			options.corners = roundType;
		}
		roundCorners(page, options);
	} else {
		if (borderColor != undefined) {
			var div = document.getElementById(page);
			div.style.border = "1px solid " + borderColor;
		}
	}
}

function roundTableCorners(borderColor) {
	var tds = document.getElementsByTagName("td");

	if (checkRico()) {
		var roundCorners = Rico.Corner.round.bind(Rico.Corner);
		for (var i = 0; i < tds.length; i++) {
			if (borderColor != undefined) {
				roundCorners(tds[i], {border: borderColor});
			} else {
				roundCorners(tds[i]);
			}
		}
	} else {
		if (borderColor != undefined) {
			for (var i = 0; i < tds.length; i++) {
				tds[i].style.border = "1px solid " + borderColor;
			}
		}
	}
}

function checkRico() {
	var usingRico;

	//--- Verifico si existe Rico ---
	try {
		usingRico = (Rico != undefined) && (Rico.Corner != undefined);
	} catch (e) {
		usingRico = false;
	}
	//-------------------------------

	return usingRico;
}
/* ---------------------------------------------- */

function resizeToScroll(divElement) {
	if (isSafari()) {
		if (divElement.style != undefined) {
			divElement.style.width = divElement.offsetWidth - 17 + "px";
		}
	} else if (isInternetExplorer()) {
		divElement.style.width = divElement.offsetWidth - 21 + "px";
	} else if (isFireFox()) {
		if (divElement.style != undefined) {
			divElement.style.width = divElement.offsetWidth - 17 + "px";
		}
	}
}

function setHeight(divElement, newHeight) {
	if (isSafari()) {
		divElement.style.height = newHeight + "px";
	} else if (isInternetExplorer()) {
		divElement.style.height = newHeight;
	} else if (isFireFox()) {
		divElement.style.height = newHeight + "px";
	}
}

function setWidth(divElement, newWidth) {
	if (isSafari()) {
		divElement.style.width = newWidth + "px";
	} else if (isInternetExplorer()) {
		divElement.style.width = newWidth;
	} else if (isFireFox()) {
		divElement.style.width = newWidth + "px";
	}
}

function getWindowHeight(useScrollBars) {
	var height = 460;

	if (isSafari()) {
		//Si es Safari
		height = parseInt(window.innerHeight);
		if (useScrollBars) {
			height = height - 16;
		}
	} else if (isInternetExplorer()) {
		//Si es Internet Explorer
		height = parseInt(document.documentElement.offsetHeight);
		if (useScrollBars) {
			height = height - 20;
		}
	} else if (isFireFox()) {
		//Si es FireFox
		height = parseInt(window.innerHeight);
		if (useScrollBars) {
			height = height - 16;
		}
	}

	return height;
}

function getWindowWidth(useScrollBars) {
	var width = 630;

	if (isSafari()) {
		//Si es Safari
		width = parseInt(window.innerWidth);
		if (useScrollBars) {
			width = width - 16;
		}
	} else if (isInternetExplorer()) {
		//Si es Internet Explorer
		width = parseInt(document.documentElement.offsetWidth);
		if (useScrollBars) {
			width = width - 20;
		}
	} else if (isFireFox()) {
		//Si es FireFox
		width = parseInt(window.innerWidth);
		if (useScrollBars) {
			width = width - 16;
		}
	}

	return width;
}

function isFireFox() {
	if (parseInt(navigator.appVersion) > 3) {
	        if (navigator.appName == "Netscape") {
	        	return true;
	        }
	}
	return false;
}

function isInternetExplorer() {
	if (parseInt(navigator.appVersion) > 3) {
	        if (navigator.appName.indexOf("Microsoft") != -1) {
	        	return true;
	        }
	}
	return false;
}

function isSafari() {
	if (parseInt(navigator.appVersion) > 3) {
		if (navigator.appVersion.indexOf("Safari") != -1) {
			if (navigator.appName == "Netscape") {
				return true;
			}
		}
	}
	return false;
}