function confirmDelete(message) {
	return (confirm(message) ? true : false);
}

function revisarFormulario(form, campo){
	var ok = true;
	if (campo.value == ""){
		var ok = false;
		alert ("Debe escoller un formato de descarga.");
	}
	
	if (ok)
		form.submit();
}

function Dopop(link) {
	// 07/08/2008 - Juan Romay
	var anchoVentana = 800;
	var altoVentana = 500;
	var posicionIzquierda = ( screen.width - anchoVentana ) / 2;
	var posicionArriba = (screen.height - altoVentana) / 2;
	var ventana=window.open(link,'popup','width=' + anchoVentana + ',height=' + altoVentana + ',left=' + posicionIzquierda + ',top=' + posicionArriba + ',scrollbars=yes,resizable=yes');
	// Cierre
	//newin=window.open(link,'popup','width=700,height=500,toolbar=false,scrollbars=yes,resizeable=yes');
}

// ID 0001518 - 12/06/2008
// Juan F. Romay
function comprobarEjemplaresDisponibles(){
	var campos = document.getElementsByTagName('input');
	var rsp = document.getElementById('ReservasSoloPrestados').value;
	var i;
	var habilitados = false;
	for (i=0;i<campos.length;i++){
		//Verificamos que ese input sea un checkbox de un item (checkitem)
		if (campos[i].getAttribute('name') == 'checkitem'){
			if (campos[i].getAttribute('estado') == 'habilitado'){
				habilitados = true;
			}
		}
	}
	
	if (habilitados){
		document.getElementById('botonSolicitarProxima').disabled=false;
	}else{
		document.getElementById('mensajeSolicitarProxima0').style.display='block';
		document.getElementById('mensajeSolicitarProxima1').style.display='none';
		document.getElementById('botonSolicitarProxima').disabled=true;
	}
	if (rsp == '0'){
		document.getElementById('solicitarReserva').style.display='none';
	}
}
//Cierre

function SetImageBiblio(source){
	imagen = new Image();
	imagen.src = source;
	SetDimensionImage (imagen, 100, 150, 'imageBiblio');
}

function SetDimensionImage(imagen,maxW, maxH, destino){
	var actualWidth = imagen.width;
	var actualHeight = imagen.height;
	var newWidth = actualWidth;
	var newHeight = actualHeight;
	var ratioW;
	var ratioH;
	var ratio;
	var resizeW = false;
	var resizeH = false;
	
	if(maxW && actualWidth > maxW){
		ratioW = maxW / actualWidth;
		resizeW = true;
	}
	if(maxH && actualHeight > maxH){
		ratioH = maxH / actualHeight;
		resizeH = true;
	}
	if(resizeW && resizeH){
		if(ratioW < ratioH){
			ratio = ratioW;
		}else{
			ratio = ratioH;
		}
	}else{
		if(resizeW)
			ratio = ratioW;
		if(resizeH)
			ratio = ratioH;
	}
	
	
	
	newWidth = parseInt(actualWidth * ratio);
	newHeight = parseInt(actualHeight * ratio);
	
	if (isNaN(newWidth)) newWidth = maxW;
	if (isNaN(newHeight)) newHeight = maxH;
	
	document.images[destino].setAttribute('width', newWidth);
	document.images[destino].setAttribute('height', newHeight);
	document.images[destino].src = imagen.src;
}

$(document).ready(function(){
	$(".close").click(function(){
		window.close();
	});
	// clear the basket when user logs out
	$("#logout").click(function(){
		var nameCookie = "bib_list";
	    var valCookie = readCookie(nameCookie);
		if (valCookie) { // basket has contents
			updateBasket(0,null);
			delCookie(nameCookie);
			return true;
		} else {
			return true;
		}
	});
});

// build Change Language menus
YAHOO.util.Event.onContentReady("changelanguage", function () {
                var oMenu = new YAHOO.widget.Menu("sublangs", { zindex: 2 });
	            function positionoMenu() {
                    oMenu.align("bl", "tl");
                }
                oMenu.subscribe("beforeShow", function () {
                    if (this.getRoot() == this) {
						positionoMenu();
                    }
                });
                oMenu.render();
				oMenu.cfg.setProperty("context", ["showlang", "bl", "tl"]);
				function onYahooClick(p_oEvent) {
                    // Position and display the menu        
                    positionoMenu();
                    oMenu.show();
                    // Stop propagation and prevent the default "click" behavior
                    YAHOO.util.Event.stopEvent(p_oEvent);
                }
				YAHOO.util.Event.addListener("showlang", "click", onYahooClick);
				YAHOO.widget.Overlay.windowResizeEvent.subscribe(positionoMenu);
            });
			
// Build lists menu
YAHOO.util.Event.onContentReady("listsmenu", function () {
    $("#listsmenu").css("display","block").css("visibility","hidden");
	$("#listsmenulink").attr("href","#").find("span:eq(0)").append("<img src=\"/opac-tmpl/prog/images/list.gif\" width=\"5\" height=\"6\" alt=\"\" border=\"0\" />");
	var listMenu = new YAHOO.widget.Menu("listsmenu");
		listMenu.render();
		listMenu.cfg.setProperty("context", ["listsmenulink", "tr", "br"]);
		listMenu.cfg.setProperty("effect",{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.05});
		listMenu.subscribe("beforeShow",positionlistMenu);
		listMenu.subscribe("show", listMenu.focus);
        function positionlistMenu() {
                    listMenu.align("tr", "br");
		}
		YAHOO.util.Event.addListener("listsmenulink", "click", listMenu.show, null, listMenu);
		YAHOO.widget.Overlay.windowResizeEvent.subscribe(positionlistMenu);
 });

 var Utf8 = {

	// public method for url encoding
	encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// public method for url decoding
	decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

}