function getNextHighestZindex(obj){
   var highestIndex = 0;
   var currentIndex = 0;
   var elArray = Array();
   if(obj){ elArray = obj.getElementsByTagName('*'); }else{ elArray = document.getElementsByTagName('*'); }
   for(var i=0; i < elArray.length; i++){
      if (elArray[i].currentStyle){
         currentIndex = parseFloat(elArray[i].currentStyle['zIndex']);
      }else if(window.getComputedStyle){
         currentIndex = parseFloat(document.defaultView.getComputedStyle(elArray[i],null).getPropertyValue('z-index'));
      }
      if(!isNaN(currentIndex) && currentIndex > highestIndex){ highestIndex = currentIndex; }
   }
   return(highestIndex+1);
} 
scrollCachePosition = 0;
function popupCssShow (URL, width, height, modifier) {
	if (modifier==undefined) {
		modifier="";
	}
	var capaBg="#cssBackground"+modifier;
	var capaCt="#cssPopupContainer"+modifier;
	var capaPu="#cssPopup"+modifier;
	
	if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
		$("body","html").css({height: "100%", width: "100%"});
		//$("html").css("overflow","hidden");
	}
	if (!$(capaBg).length>0) {
		$("body").append("<div id=\"cssBackground"+modifier+"\" class=\"cssBackground\"></div><div id=\"cssPopupContainer"+modifier+"\" class=\"cssPopupContainer\"><div id=\"cssPopup"+modifier+"\" class=\"cssPopup\"></div></div>");
	}
	if (width!=undefined) {
		$(capaPu).css("width",width);
	}
	if (height!=undefined && height!=0) {
		$(capaPu).css("height",height);
		$(capaPu).css("overflow","auto");
	}
	$(capaBg).css({'z-index': getNextHighestZindex(window.document)});
	$(capaCt).css({'z-index': getNextHighestZindex(window.document)});
	$(capaBg).slideDown("slow");
	//$(capaPu).css("background-color","#ececec");
	scrollCachePosition = $(window).scrollTop();
	window.top.scroll(0,0);

	$(capaPu).load(URL,function(){
		//$(capaCt).center();
		$(capaCt).css("top",50);
		ancho=$(window).width();
		$(capaCt).slideDown("fast", function () {
			anchopopup=$(capaPu).width();
			$(capaCt).css("width",ancho);			
		});
	});
}

function popupCssHide (modifier) {
	if (modifier==undefined) {
		modifier="";
	}
	var capaBg="#cssBackground"+modifier;
	var capaCt="#cssPopupContainer"+modifier;
	var capaPu="#cssPopup"+modifier;
	
	$(capaCt).slideUp("fast", function () {
		$(capaBg).fadeOut("fast",function () {
			$(capaBg).remove();
			$(capaCt).remove();
		});
	});
	if (scrollCachePosition > 0) {
		window.top.scroll(0,scrollCachePosition);
		//Reseteamos la variable scrollCachePosition a 0 para poder ejecutar el script tantas veces sea necesario.
		scrollCachePosition = 0;
	}
}

