var dom = document.getElementById ? true:false;
var ns4 = document.layers ? true:false;
var ie4 = document.all ? true:false;
var mac = navigator.appVersion.indexOf('Mac')!=-1 ? true:false;

function init() {
	blurLinks();
}

function preload(imgObj,imgSrc) {
	eval(imgObj+" = new Image()");
	eval(imgObj+".src = '"+imgSrc+"'");
}

function changeImg(imgObj,imgSrc) {
	if (navigator.appVersion >= "3") {
		var imatge = eval(imgSrc+".src");
		document.images[imgObj].src = imatge;
	}
}

function blurLinks() {
	if (dom) {
		lnks = document.getElementsByTagName('a');
		for (i=0;i<lnks.length;i++) {
			lnks[i].onfocus = new Function("if(this.blur) this.blur()");
		}
	} else if (ie4) {
		for (var i in document.links) {
			document.links[i].onfocus = document.links[i].blur;
		}
	}
}

tabs = new Array(), first_treatments = new Array();

function toggleTab(tab) {
	for (i in tabs) {
		if (i!=tab) {
			document.getElementById("tab_"+i).style.display = "none";
		}
	}
	document.getElementById("tab_"+tab).style.display = "";
}

function gotoCategory(id) {
	window.location = "treatments.php?category="+id;
}

for (i=1;i<=5;i++) {
	preload("op_"+i+"_off","img/l/"+l+"/ops/"+i+"_off.gif");
	preload("op_"+i+"_on","img/l/"+l+"/ops/"+i+"_on.gif");
}

function saveCookie(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;
}

function deleteCookie(name) {
	saveCookie(name,"",-1);
}

function changeFont(what) {
	var cookie = readCookie("tb_fontsize");
	cookie = cookie ? cookie : 2;
	if (cookie == 'null') {
		cookie = 2;
	}
	cookie = parseInt(cookie);
	if ( (what==0) || ( (what==-1)&&(cookie>1) ) || ( (what==1)&&(cookie<5) ) ) {
		cookie += what;
		saveCookie("tb_fontsize", cookie, 365);
		setActiveStyleSheet("style"+cookie);
	}
}

function setActiveStyleSheet(title) {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if ( (a.getAttribute("rel").indexOf("style")!= -1) && (a.getAttribute("title")) ) {
			if(a.getAttribute("title") == title) {
				a.disabled = false;
			} else {
				a.disabled = true;
			}
		}
	}
}

changeFont(0);