// Heralsoft http://heralsoft.com
// Funciones javascript para mostrar un div de actividad
// basado en la libreria lightbox http://www.huddletogether.com/projects/lightbox2/
//


function insertOverlay(){
	// se inserta el div overlay al final del body
	var objBody = document.getElementsByTagName("body").item(0);
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','sOverlay');
	// se oculta el div
	objOverlay.style.display = 'none';
	// se sobreescribe el onclick
	objOverlay.onclick = function() { hideOverlay(); return false; }
	objBody.appendChild(objOverlay);

/*	// se inserta el div loading dentro del overlay
	var objLoading = document.createElement("div");
	objLoading.setAttribute('id','loading');
	objOverlay.appendChild(objLoading);

	// se inserta la imagen de indicacion de actividad
	var objLoadingImage = document.createElement("img");
	objLoadingImage.setAttribute('src', '/blog/images/loading.gif');
	objLoading.appendChild(objLoadingImage);*/
}


function showOverlay(){
	// insercion segura
	if ($('sOverlay')==null){
		insertOverlay();	
	}
	hideSelectBoxes();// se esconde las select para IE
	var arrayPageSize = getPageSize();
	// se redimensiona el div de overlay
    	$('sOverlay').style.height = arrayPageSize[1] +"px";
	new Effect.Appear('sOverlay', { duration: 0.2, from: 0.0, to: 0.8 });
	new Effect.Appear('sVentana', { duration: 0.2, from: 0.0, to: 1 });
}


function hideOverlay(){
	Element.hide('sOverlay', { duration: 0.2 });
	Element.hide('sVentana', { duration: 0.5 });

}



/* funciones de utilidad */

// oculta todas las selects ya que el explorer las muestra por encima
// del div de overlay
function hideSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

// Funcion "prestada" que retorna el tamaño del navegador en un array
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

