/*--------------------------------------------------------------------------------------------------------------------------------------------------------*/
	var expires=';expires=Fri, 01 Jan 2999 00:00:00 UTC; path=/'; // Constant de data molt llunyana
	function Cookie(name)
	{
	//Inicialització de la Classe.
		this.ValueSeparator="@[]@";
		this.FieldSeparator="@()@";
		if (name==null) {name='cookie_nonamed'}
		
	// Si no existeix la cookie la creem.
		if (document.cookie.indexOf(name)==-1) {document.cookie = name+'='+expires;} 
		
	//Definició del prototip.
		this.set = cookie_class_Set;
		this.clear = cookie_class_Clear;
		this.erase =cookie_class_Erase;
		this.exists = cookie_class_Exists;
		this.name = name;
		this.content = cookie_class_Content;
		this.value = cookie_class_Value;
		this.defaultValue;
	}
/*--------------------------------------------------------------------------------------------------------------------------------------------------------*/
	function cookie_class_Clear(){document.cookie = this.name+'='+expires;}
	function cookie_class_Exists(Key){return (this.content().indexOf(this.FieldSeparator+Key+this.ValueSeparator)!=-1);}
	function cookie_class_Erase(){this.clear();document.cookie = name+'=;expires=-1'};
/*--------------------------------------------------------------------------------------------------------------------------------------------------------*/
	function cookie_class_Set(Key,Value)
	{
		with(this)
		{
			if (!exists(Key)) {document.cookie=name+'='+content()+FieldSeparator+Key+ValueSeparator+Value+expires;return;}
			var data=this.content().split(this.FieldSeparator);var FaV
			for (var bucle=0;bucle<=data.length-1;bucle++)
			{
				FaV = data[bucle].split(this.ValueSeparator)
				if (FaV[0]==Key) {data[bucle]=Key+ValueSeparator+Value}
			}
			document.cookie=name+'='+data.join(FieldSeparator)+expires	;
		}
	}

/*--------------------------------------------------------------------------------------------------------------------------------------------------------*/
	function cookie_class_Content()
	{
		var nameEQ = this.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);	 // Fem un trim dels espais;
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return '';
	}
/*--------------------------------------------------------------------------------------------------------------------------------------------------------*/
	function cookie_class_Value(Key)
	{
		if (!this.exists(Key)){return this.defaultValue;}
		var content=this.content().split(this.FieldSeparator);var FaV
		for (var bucle=0;bucle<=content.length-1;bucle++)
			{FaV = content[bucle].split(this.ValueSeparator);if (FaV[0]==Key) {return FaV[1];}}
		return this.defaultValue;
	}
/*--------------------------------------------------------------------------------------------------------------------------------------------------------*/
	function form_to_cookie(formId)
	{
		var f = document.getElementById(formId);var count=0;
		for (var bucle=0;bucle<f.all.length;bucle++)
			{if (f.all[bucle].type=='text'){cookie.add(formId+'_'+count++,f.all[bucle].value);}}
	}
/*--------------------------------------------------------------------------------------------------------------------------------------------------------*/
	function cookie_to_form(formId)
	{
		var f = document.getElementById(formId);var count=0;
		for (var bucle=0;bucle<f.all.length;bucle++)
			{if (f.all[bucle].type=='text'){f.all[bucle].value=cookie.value(formId+'_'+count++);}}
	}
/*--------------------------------------------------------------------------------------------------------------------------------------------------------*/
	//function table_to_cookie(){}
/*--------------------------------------------------------------------------------------------------------------------------------------------------------*/
	//function cookie_to_table(){}
/*--------------------------------------------------------------------------------------------------------------------------------------------------------*/
	function cookie_to_cart(cookie)
	{
		//--- Si no tenim la referencia a Ajax, marxem.
		if (!AJAX_Loaded()) {return false;}
		
		//--- Resetejem el cistell.
		httpRequest('../../kernel/target.asp','gotourl=null&command=CART_RESET',null)
		
		//--- Buclem totes les referencies de la cookie.
		for (var bucle=1;bucle<=carro_cookie.value('RecordCount');bucle++)
		{
			httpRequest('../../kernel/target.asp','gotourl=null&command=CART_ADD_STREAM&stream='+URLEncode(cookie.value('L'+bucle)),null)
		}
		return true;
	}
/*--------------------------------------------------------------------------------------------------------------------------------------------------------*/
	function cart_to_cookie(cookie,CART)
	{
		//--- Si no tenim la referencia a Ajax, marxem.
		if (!AJAX_Loaded()) {return false;}

		//--- Netejem la cookie, i li establim el nombre d'items.
		cookie.erase();
		cookie.set('RecordCount',CART.RecordCount)

		//--- Creem un vector temporal per després fer-hi el join.
		var data= new Array()
		
		//--- Patejem tot el carro i nem guardant els streams a la cookie.
		for(var bucle=0;bucle<CART.RecordCount;bucle++)
		{
			data[0] = 'Descripcio=.';
			data[1] = 'Article='+CART.Item[bucle].ARTICLE;
			data[2] = 'Unitats='+CART.Item[bucle].UNITATS;
			data[3] = 'Notes1='+CART.Item[bucle].NOTES1;
			cookie.set('L'+(bucle+1),data.join('&'))
		}
		return true;
	}
/*--------------------------------------------------------------------------------------------------------------------------------------------------------*/
	function AJAX_Loaded()
	{
		var AJAX = false; try {AJAX=(AJAX_Enabled==1 || AJAX_Enabled)}catch(e){e}
		if (!AJAX) {alert('Error: AJAX module not loaded.');}
		return AJAX;
	}
/*--------------------------------------------------------------------------------------------------------------------------------------------------------*/
