


	function getCookie(NameOfCookie)
	{ 
		if (document.cookie.length > 0)
		{
			begin = document.cookie.indexOf(NameOfCookie+"=");
			if (begin != -1)
			{ 
				begin += NameOfCookie.length+1;
				end = document.cookie.indexOf(";", begin);
				if (end == -1) end = document.cookie.length;
					return unescape(document.cookie.substring(begin, end)); 
			}
		}
	return null;
	}


	function setCookie(NameOfCookie, value, expiredays)
	{ 
		var ExpireDate = new Date ();
		ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
		document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
	}

	function setCookie(NameOfCookie, value, expiredays, path)
	{ 
		var ExpireDate = new Date ();
		ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
		if(path == null || path == "") path = "/web/";
		document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()) + "; path=" + path;
	}
	

	function delCookie (NameOfCookie)
	{ 
		if (getCookie(NameOfCookie)) {
			document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
		}
	}

	function DoTheCookieStuff(lang,location){
		setCookie('idioma',lang,365);
		window.location=location;
	}


	function DoTheCookieStuffHome(){
	
		idioma=getCookie('idioma');
		switch (idioma){
	
			case 'CA': DoTheCookieStuff('CA','/web/catala/');  break;
			case 'ES': DoTheCookieStuff('ES','/web/castellano/');  break;
			case 'EN': DoTheCookieStuff('EN','/web/english/');  break;
			default:   window.location="/web/index_idiomes.html";

		}


	}


	

