var today = new Date()

var expires = new Date();


// fix the bug in Navigator 2.0, Macintosh
 
fixDate(expires);
expires.setTime(expires.getTime() + 365 * 24 * 60 * 60 * 1000);

function setCookie(name, value, expires, path, domain, secure) {
 
 var curCookie = name + "=" + escape(value) +
 ((expires) ? "; expires=" + expires.toGMTString() : "") +
 ((path) ? "; path=" + path : "") +
 ((domain) ? "; domain=" + domain : "") +
 ((secure) ? "; secure" : "");
 document.cookie = curCookie;
}

function getCookie(name) {
 var dc = document.cookie;
 var prefix = name + "=";
 var begin = dc.indexOf("; " + prefix);
 if (begin == -1) {
 begin = dc.indexOf(prefix);
 if (begin != 0) return null;
 } else
 begin += 2;
 var end = document.cookie.indexOf(";", begin);
 if (end == -1)
 end = dc.length;
 return unescape(dc.substring(begin + prefix.length, end));
}



function FullEstil(nouTamany){

 	setCookie("FullEstilIrta", nouTamany, expires,"/");

	if (getCookie("FullEstilIrta"))
	{
		window.self.location.reload();
		//parent.inferior.principal.location.reload();
		parent.frames[1].frames[1].location.reload();
	}else{
	
		alert("Enable cookies for the change of text size be permanent in all pages.");
		cadena = new String(window.self.location);
		str = cadena.toString();
		if (str.indexOf("?")==-1){
			window.location=str+"?estil="+nouTamany;
		}else{
			window.location=str.substr(0,str.indexOf("?"))+"?estil="+nouTamany;
		
		}
	}
	
	return null;

}

function ConsultaEstil(){

	// Comprovem que s'accepten cookies
	 setCookie("Existencia", "1", expires,"/");
	
	if (getCookie("Existencia")){
		var fulla = getCookie('FullEstilIrta');
	
		if (fulla==null || fulla == "" || fulla=="undefined"){
			fulla = "normal";
			setCookie("FullEstilIrta", fulla, expires, "/");
		}
	
		return fulla;	
	}
	else{
		//si no hi ha info sobre cookies assigno 11 a pinyó
		fulla = "normal";
	}

	return fulla;
}

function whichPath(URL){

	for ( var pos=0; pos < URL.length; pos++){
		var sByte = URL.substring(pos,pos+1);
		if ( sByte=="/" ){
			Posicio = pos 
			}
		}
	return  URL.substring(0,Posicio);
}

function deleteCookie(name, path, domain) {
 
 if (getCookie(name)) {
 document.cookie = name + "=" +
 ((path) ? "; path=" + path : "") +
 ((domain) ? "; domain=" + domain : "") +
 "; expires=Thu, 01-Jan-70 00:00:01 GMT";
 }
 
}


function fixDate(date) {
var base = new Date(0);
var skew = base.getTime();
if (skew > 0)
date.setTime(date.getTime() - skew);
}

function replace(string,text,by) 
{
	var strLength = string.length, txtLength = text.length;
	if ((strLength == 0) || (txtLength == 0)) return string;
	var i = string.indexOf(text);
	if ((!i) && (text != string.substring(0,txtLength))) return string;
	if (i == -1) return string;
	var newstr = string.substring(0,i) + by;
	if (i+txtLength < strLength)
		newstr += replace(string.substring(i+txtLength,strLength),text,by);
	return newstr;
}

//****************************************************************************************************************************************************************************

cadena = new String(window.self.location);
str = cadena.toString();
var tamanyCSS ="";
 

if (str.indexOf("?estil=")==-1){
	tamanyCSS= ConsultaEstil();
	}
else{
	tamanyCSS=str.substr(str.indexOf("=")+1,str.length);
	}
 

	Estils_Path = whichPath(window.top.location.pathname);
	Estils_Path = replace(Estils_Path,'/cat','');
	Estils_Path = replace(Estils_Path,'/eng','');
	Estils_Path = replace(Estils_Path,'/esp','');

	if (document.layers) {
		if (tamanyCSS == "normal")	
			document.write("<link rel=stylesheet href='"+Estils_Path+"/fulla_estil.css'>");
		if (tamanyCSS == "gran")	
			document.write("<link rel=stylesheet href='"+Estils_Path+"/fulla_estil_gran.css'>");
		if (tamanyCSS == "extra")	
			document.write("<link rel=stylesheet href='"+Estils_Path+"/fulla_estil_extra.css'>");				
	}
	else{
		if (tamanyCSS == "normal")
			document.write("<link rel=stylesheet href='"+Estils_Path+"/fulla_estil.css'>");
		if (tamanyCSS == "gran")
			document.write("<link rel=stylesheet href='"+Estils_Path+"/fulla_estil_gran.css'>");
		if (tamanyCSS == "extra")
			document.write("<link rel=stylesheet href='"+Estils_Path+"/fulla_estil_extra.css'>");
	
	}