/* --- Manejador del div flotante --- */
function createFloatingDiv() {
	var floatingIFrame = document.createElement("IFRAME");
	var floatingShadow = document.createElement("DIV");
	var floatingContent = document.createElement("DIV");
	var floatingDivCorners = document.createElement("DIV");
	var headerDiv = document.createElement("DIV");
	var headerButton = document.createElement("DIV");
	var floatingDiv = document.createElement("DIV");

	floatingIFrame.id = "floatingIFrame";

	floatingShadow.id = "floatingShadow";

	floatingContent.id = "floatingDivContent";

	floatingDivCorners.id = "floatingDivCorners";

	floatingDiv.id = "floatingDiv";

	headerButton.id = "closeButton";
	headerButton.innerHTML = "cerrar";
	headerDiv.className = "floatingHeader";
	headerDiv.appendChild(headerButton);

	floatingDivCorners.appendChild(headerDiv);
	floatingDivCorners.appendChild(floatingDiv);

	floatingContent.appendChild(floatingDivCorners);

	floatingContent.style.display = 'none';
	floatingShadow.style.display = 'none';
	floatingIFrame.style.display = 'none';

	document.body.appendChild(floatingIFrame);
	document.body.appendChild(floatingShadow);
	document.body.appendChild(floatingContent);

	roundCorners('floatingDivCorners');

	/* --- Hago que la sombra sea clickeable para cerrar el flotante --- */
	headerButton.onclick = function() {
		var closeLink = document.getElementById("close");
		if (closeLink != undefined) {
			closeLink.onclick();
		}
	};
	
	floatingShadow.onclick = function() {
		var closeLink = document.getElementById("close");
		if (closeLink != undefined) {
			closeLink.onclick();
		}
	};
	/* ----------------------------------------------------------------- */
}

function showFloatingDiv() {
	var floatingDiv = document.getElementById("floatingDivContent");
	var floatingShadow = document.getElementById("floatingShadow");
	var floatingIFrame = document.getElementById("floatingIFrame");

	floatingDiv.style.display = '';
	floatingShadow.style.display = '';
	floatingIFrame.style.display = '';

	/* --- Centro el ancho --- */
	var width = getWindowWidth(true);
	var left = (parseInt(width) - parseInt(floatingDiv.offsetWidth)) / 2;
	if (floatingDiv.parentNode != undefined) {
		left -= floatingDiv.parentNode.offsetLeft;
	}
	floatingDiv.style.left = left + "px";
	/* ----------------------- */

	var contentToUpdate = document.getElementById("floatingDiv");
	contentToUpdate.innerHTML = "<div style='vertical-align: middle; font: Arial; color: #FFFFFF; font-size: 14px; font-weight: bold; text-align: center;'>Cargando detalle, por favor espere...</div>";
}

function hideFloatingDiv() {
	var floatingDiv = document.getElementById("floatingDivContent");
	var floatingShadow = document.getElementById("floatingShadow");
	var floatingIFrame = document.getElementById("floatingIFrame");

	floatingDiv.style.display = 'none';
	floatingShadow.style.display = 'none';
	floatingIFrame.style.display = 'none';
}
/* ---------------------------------- */

//--- Cargo la captura del scroll si estoy en IE6 ---
function captureScroll() {
	var arVersion = navigator.appVersion.split("MSIE");
	if (arVersion != undefined) {
		var version = parseFloat(arVersion[1]);

		if ((version >= 5.5) && (version < 7.0) && (document.body.filters)) {
			document.body.onscroll = function() {
				var floatingShadow = document.getElementById("floatingShadow");
				var floatingIFrame = document.getElementById("floatingIFrame");

				floatingShadow.style.top = document.body.scrollTop + "px";
				floatingShadow.style.left = document.body.scrollLeft + "px";

				floatingIFrame.style.top = document.body.scrollTop + "px";
				floatingIFrame.style.left = document.body.scrollLeft + "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;
}