/* pendent passar a jquery */
function BotoBS(id,b,t,l,m) {
	if (m=='+'){
		$('bookshelf').innerHTML="<a href=\"/bin/bookshelf.pl?l="+l+"&amp;id="+id+"&amp;a=del\" onclick=\"Bookshelf('"+id+"','"+b+"','"+t+"','"+l+"','-'); return false;\"><img src=\"/img/cbsoff.gif\" alt=\""+t+"\" title=\""+t+"\" /></a>";
	}else{
		$('bookshelf').innerHTML="<a href=\"/bin/bookshelf.pl?l="+l+"&amp;id="+id+"\" onclick=\"Bookshelf('"+id+"','"+b+"','"+t+"','"+l+"','+'); return false;\"><img src=\"/img/cbs.gif\" alt=\""+b+"\" title=\""+b+"\" /></a>";
	}
}

function Bookshelf(id,b,t,l,m) {
	if(m=='+'){
		BSadd(id);
	}else{
		BSdel(id);
	}
	BotoBS(id,b,t,l,m);
}

function NovaF(url,nom,w,h,scroll) { 
	nova=window.open(url,nom, "width="+w+",height="+h+",status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars="+scroll);
	nova.focus();
	return true;
}

function WinNote(titol,text,wn,hn) {
	var win = new Window("window_id_"+Math.random(), {className: "alphacube", width:wn, height:hn, zIndex: 100, resizable: true, title: titol});
	win.getContent().innerHTML= "<blockquote id=\"contingutnota\"><div id=\"textnota\">"+text+"<\/div><\/blockquote>";
	win.showCenter();
}

function fontsizeup() {
  active = getActiveStyleSheet();
  switch (active) {
    case 'A--' : 
      setActiveStyleSheet('A-');
      break;
    case 'A-' : 
      setActiveStyleSheet('A');
      break;
    case 'A' : 
      setActiveStyleSheet('A+');
      break;
    case 'A+' : 
      setActiveStyleSheet('A++');
      break;
    case 'A++' :
      break;
    default :
      setActiveStyleSheet('A');
      break;
  }
}

function fontsizedown() {
  active = getActiveStyleSheet();
  switch (active) {
    case 'A++' : 
      setActiveStyleSheet('A+');
      break;
    case 'A+' : 
      setActiveStyleSheet('A');
      break;
    case 'A' : 
      setActiveStyleSheet('A-');
      break;
    case 'A-' : 
      setActiveStyleSheet('A--');
      break;
    case 'A--' : 
       break;
    default :
      setActiveStyleSheet('A--');
      break;
  }
}

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  return ('A');
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

window.onload = function(e) {
	var cookie = readCookie("style");
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);

	if (document.images){
		var url = new Array();
		var img = new Array();
		url[0] = "/css/ext/window/alphacube/left-top.gif";
		url[1] = "/css/ext/window/alphacube/top-middle.gif";
		url[2] = "/css/ext/window/alphacube/right-top.gif";
		url[3] = "/css/ext/window/alphacube/frame-left.gif";
		url[4] = "/css/ext/window/alphacube/frame-right.gif";
		url[5] = "/css/ext/window/alphacube/bottom-left-c.gif";
		url[6] = "/css/ext/window/alphacube/bottom-middle.gif";
		url[7] = "/css/ext/window/alphacube/bottom-right-c.gif";

		url[8] = "/css/ext/window/alphacube/button-close-focus.gif";
		url[9] = "/css/ext/window/alphacube/button-min-focus.gif";
		url[10] = "/css/ext/window/alphacube/button-max-focus.gif";

		url[11] = "/img/cbsoff.gif";

		url[12] = "/img/kittscanner.gif";

		for(var i=0; i<url.length; i++) {
			img[i] = new Image();
			img[i].src = url[i];
		}
	}
}

window.onunload = function(e) {
	var title = getActiveStyleSheet();
	createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
if (title == 'null') title = getPreferredStyleSheet();

setActiveStyleSheet(title);
