var contador=1;
var end;
var ruta;
var rutalib;
var rutabase='../../../biblioteca/';
var titulo;


function cerrar()
{
	if (confirm("Do you really want to close the book?")) {
		window.close();
		}
}

function makevisible(cur,which)
	{
	strength=(which==0)? 1 : 0.7
	if (cur.style.MozOpacity)
	cur.style.MozOpacity=strength
	else if (cur.filters)
	cur.filters.alpha.opacity=strength*100
	}


function ocultarDirover()
{
window.status='Descarga el libro que estas leyendo en formato PDF';
}
function ocultarDirout()
{
window.status='';
}

function goto()
{
	var digito=/[1-9]+/
	var abc=/[a-zA-Z_]/
	var pagina=$("ir_a_texto").value
	var comp=pagina.match(digito);
	var compa=pagina.match(abc);
	if ((parseInt(pagina)>end) || (pagina=="") || comp==null || compa!=null)
	{
		alert("No puedes ir a una pagina que no existe!\nIntenta con otro numero de pagina.");	
	}
	else{
	var nombre='Lib_Lps_Pag_'+pagina;
	$("libro").src=ruta+nombre+".html";
	$("titulo_libro").innerHTML=titulo+" "+pagina+"/"+end;
		
	}
}

function next()
{
	if (contador>=end)
	{
	 contador=1;		
	}
	else
	{
		contador=contador+1;
	}
	var nombre='Lib_Lps_Pag_'+contador;	
	$("libro").src=ruta+nombre+".html";
	$("titulo_libro").innerHTML=titulo+" "+contador+"/"+end;
}

function last()
{
	if (contador>1)
	{
		contador=contador-1;
	}
	else
	{
		contador=1;
	}
	var nombre='Lib_Lps_Pag_'+contador;
	$("libro").src=ruta+nombre+".html";
	$("titulo_libro").innerHTML=titulo+" "+contador+"/"+end;
}

function getPageDimensions(){
		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(windowWidth,windowHeight,pageWidth,pageHeight) 
		return arrayPageSize;
	}


function centrar(){
	
		var windowSize = getPageDimensions();
		var window_width  = windowSize[0];
		var window_height = windowSize[1];

		var scrollY = 0;
		if ( document.documentElement && document.documentElement.scrollTop ){
			scrollY = document.documentElement.scrollTop;
		}else if ( document.body && document.body.scrollTop ){
			scrollY = document.body.scrollTop;
		}else if ( window.pageYOffset ){
			scrollY = window.pageYOffset;
		}else if ( window.scrollY ){
			scrollY = window.scrollY;
		}
	
		$('adelante').style.left = ((window_width/2)+416)+ "px";
		$('atras').style.left = ((window_width/2)-480) + "px";
		$('adelante').style.top = (310)+ "px";
		$('atras').style.top = (310) + "px";
		$('close').style.left = ((window_width/2)+360) + "px";
		//$('descargar').style.left = ((window_width/2)-380) + "px";
		$('ir_a').style.left = ((window_width/2)-380) + "px";
		$('close').style.top = (130)+ "px";			
		//$('divtitulo').style.top=(0) + "px";
		//$('descargar').style.top = ((window_height/2)-237) + "px";
		$('ir_a').style.top = 70 + "px";
		/*if(navigator.appName=="Netscape")
		{
		$('close').style.top = (130)+ "px";			
		//$('divtitulo').style.top=(0) + "px";
		//$('descargar').style.top = ((window_height/2)-237) + "px";
		$('ir_a').style.top = 70 + "px";
		}
		else
		{
			$('close').style.top = (130)+ "px";			
			//$('descargar').style.top = ((window_height/2)-222) + "px";
			$('ir_a').style.top = 0 + "px";
		}*/
	}
	
function abrirLibro(idcat,url,titulo)

{
window.open("includes/lib/visor/procesarLibro.php?categoria="+idcat+"&url="+url+"&titulo="+Url.encode(titulo),url,"width=1024,height=720,top=0,left=0,toolbar=0,scrollbar=0,status=0");

}


