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 EstiloACC(nouTamany){
 	setCookie("EstiloACC", nouTamany, expires,"/");
	if (getCookie("EstiloACC"))
	{
		window.self.location.reload();
	}else{
	
		alert("Has d'activar les cookies del teu navegador per tal que el canvi de tamany de lletra sigui permanent en totes les pàgines.");
		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 ConsultaEstiloACC(){

	// Comprovem que s'accepten cookies
	 setCookie("Existencia", "1", expires,"/");
	
	if (getCookie("Existencia"))
	{
		var fulla = getCookie('EstiloACC');
	
		if (fulla==null || fulla == "" || fulla=="undefined"){
			fulla = "";			
		}
	
		return fulla;	
	}
	else{
		//si no hi ha info sobre cookies assigno 11 a pinyó
		fulla = "";
	}
	return fulla;
}

function CambiarImagenACC(imgName,imgObjName) {
	if (document.images) {  
 		document.images[imgName].src = imgObjName;
	};
}

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);
}
