PageSourceSearch

https://www.scienze-astratte.it/res/x5cartengine.js?1975

js scienze-astratte.it collected 2026-10-03 00:18:43 UTC 60,337 bytes, 1,164 lines download raw bytes

1/**
2 * This file contains the class used to run the E-Commerce cart
3 * @author Incomedia Srl (http://www.incomedia.eu)
4 * @copyright Incomedia Srl
5 * @version 9.0.10.1842
6 */
7_jq.extend(x5engine.imCart, {
8
9	_restoreSpecialChars: function (str) {
10		return str.replace(/\{1\}/g, "'").replace(/\{2\}/g, "\"").replace(/\{3\}/g, "\\").replace(/\{4\}/g, "<").replace(/\{5\}/g, ">");
11	},
12
13	// Test if cookies are working in the current browser
14	_testCookie: function () {
15		_jq.imCookie("imCookieTest", "test_content");
16		if (_jq.imCookie("imCookieTest") == "test_content") return true;
17		return false;
18	},
19
20	// Get the product array from cookie
21	_getCart: function () {
22		try {
23			if (_jq.imCookie(x5engine.imCart.costants.COOKIE_NAME, null, { path: '/'}) !== null)
24				return _jq.parseJSON(_jq.imCookie(x5engine.imCart.costants.COOKIE_NAME, null, {path: '/'}));
25			else
26				return [];
27		} catch (e) {
28			_jq.imCookie(x5engine.imCart.costants.COOKIE_NAME, {}, { path: '/' });
29			return [];
30		}
31	},
32
33	// Save the product array to the cookie
34	_setCart: function (products) {
35		if (!x5engine.imCart._testCookie()) {
36			alert(x5engine.l10n.getLocalization("cart_err_cookie"));
37			return false;
38		}
39
40		var json = [];
41		for (var i = 0, j = 0; i < products.length; i++)
42		if (products[i] !== null && products[i] !== undefined) {
43			json[j] = "{\"id\": \"" + products[i].id + "\", \"quantity\": " + products[i].quantity + ", \"option\": \"" + products[i].option + "\"}";
44			j++;
45		}
46		json = json.join(",");
47		json = "[" + json + "]";
48
49		_jq.imCookie(x5engine.imCart.costants.COOKIE_NAME, json, {
50			path: '/'
51		});
52	},
53
54	// Save the form data in a cookie
55	_setFormData: function (post) {
56		var json;
57		for (var i = 0; i < post.length; i++) {
58			post[i] = "{\"id\": \"" + post[i].id + "\", \"val\": \"" + post[i].val + "\"}";
59		}
60		json = "[" + post.join(",") + "]";
61		_jq.imCookie(x5engine.imCart.costants.COOKIE_FORM_NAME, json);
62	},
63
64	// Get the form data from the cookie
65	_getFormData: function () {
66		try {
67			return _jq.parseJSON(_jq.imCookie(x5engine.imCart.costants.COOKIE_FORM_NAME));
68		} catch (e) {
69			_jq.imCookie(x5engine.imCart.costants.COOKIE_FORM_NAME, {});
70			return null;
71		}
72	},
73
74	// Set the currency format
75	_setCurrency: function (n, format, currency) {
76		var decsep = "";
77		var thsep = "";
78		var integer;
79		var decimal = "";
80		currency = currency || x5engine.imCart.settings.currency;
81		if (format === null || format === undefined) format = x5engine.imCart.settings.currency_format;
82		var value = "";
83
84		// Find the decimal separator
85		decsep = Math.max(format.lastIndexOf("."), format.lastIndexOf(","));
86		thsep = Math.min(format.indexOf("."), format.indexOf(","));
87		if (thsep == -1 && format.indexOf(".") != -1) thsep = format.indexOf(".");
88		if (thsep == -1 && format.indexOf(",") != -1) thsep = format.indexOf(",");
89
90		if (decsep != -1) {
91			integer = format.substr(0, decsep);
92			decimal = format.substr(decsep + 1);
93		} else integer = format;
94
95		// Set the precision
96		var counter = 0, i;
97		for (i = 0; i < decimal.length; i++)
98		if (decimal.charAt(i) == '@') counter++;
99
100		value = new Number(n);
101		value = value.toFixed(counter);
102		var int_value = Math.floor(value);
103		var dec_value = value.toString();
104		dec_value = dec_value.substring(dec_value.length - counter);
105
106		if (decsep != thsep && thsep != -1) thsep = format.charAt(thsep);
107		else thsep = "";
108		if (decsep == -1) decsep = "";
109		else decsep = format.charAt(decsep);
110
111		// Format the int part
112		int_value += "";
113		value = "";
114		for (i = 0; i < Math.max(integer.length, int_value.length); i++) {
115			if (i % 3 === 0 && i !== 0 && (int_value.length - i > 0 || integer.charAt(integer.length - 2 - i) == "@")) {
116				value = thsep + value;
117			}
118			if (int_value.length - 1 - i >= 0)
119				value = int_value.charAt(int_value.length - 1 - i) + value;
120			else if (integer.charAt(integer.length - 1 - i) == "@")
121				value = "0" + value;
122		}
123
124		if (counter === 0 && dec_value > 0) {
125			counter = 2;
126			decimal = "@@";
127		}
128
129		// Add the decimal part
130		value = value + decsep.toString() + dec_value;
131		decimal = decimal.replace("[C]", "");
132
133		// Add the currency symbol
134		if (format.indexOf("[C]") === 0) value = currency + value;
135		else if (format.indexOf("[C]") != -1) value += currency;
136
137		return value;
138	},
139
140	// Get the value of the key
141	_getValueFromKey: function (key, array) {
142		var value;
143		if (array["0"] === null || array["0"] === undefined)
144			value = 0;
145		else
146			value = array["0"];
147
148		if (key * 1 > 0) for (var property in array)
149		if (property * 1 <= key * 1) value = array[property];
150
151		return value;
152	},
153
154	// Get the shipping price
155	_getShippingPrice: function (shipping, subtotal, total_quantity, total_weight, vat) {
156		if (vat === null || vat === undefined)
157			vat = true;
158		if (shipping.price !== null && shipping.price !== undefined) {
159			switch (shipping.type) {
160			case "WEIGHT":
161				price = x5engine.imCart._getValueFromKey(total_weight, shipping.price);
162				break;
163			case "QUANTITY":
164				price = x5engine.imCart._getValueFromKey(total_quantity, shipping.price);
165				break;
166			case "AMOUNT":
167				price = x5engine.imCart._getValueFromKey(subtotal, shipping.price);
168				break;
169			default:
170				price = shipping.price;
171				break;
172			}
173			if (shipping.vat !== null && shipping.vat !== undefined && vat)
174				price += price * shipping.vat;
175			return price;
176		}
177
178		return 0;
179	},
180
181	// Set the payment type
182	_setPayment: function (n) {
183		_jq.imCookie(x5engine.imCart.costants.PAYMENT_COOKIE_NAME, n, {
184			path: '/'
185		});
186		x5engine.imCart.payment_type = n;
187	},
188
189	// Get the payment type
190	_getPayment: function () {
191		if ((x5engine.imCart.payment_type === null || x5engine.imCart.payment_type === undefined) && _jq.imCookie(x5engine.imCart.costants.PAYMENT_COOKIE_NAME) !== null && _jq.imCookie(x5engine.imCart.costants.PAYMENT_COOKIE_NAME) !== undefined) {
192			x5engine.imCart.payment_type = _jq.imCookie(x5engine.imCart.costants.PAYMENT_COOKIE_NAME) * 1;
193			x5engine.imCart.email_data.payment = x5engine.imCart.payment_type;
194		}
195		return x5engine.imCart.payment_type;
196	},
197
198	// Set the shipping type
199	_setShipping: function (n) {
200		_jq.imCookie(x5engine.imCart.costants.SHIPPING_COOKIE_NAME, n, {
201			path: '/'
202		});
203		x5engine.imCart.shipping_type = n;
204	},
205
206	// Get the shipping type
207	_getShipping: function () {
208		if ((x5engine.imCart.shipping_type === null || x5engine.imCart.shipping_type === undefined) && _jq.imCookie(x5engine.imCart.costants.SHIPPING_COOKIE_NAME) !== null && _jq.imCookie(x5engine.imCart.costants.SHIPPING_COOKIE_NAME) !== undefined) {
209			x5engine.imCart.shipping_type = _jq.imCookie(x5engine.imCart.costants.SHIPPING_COOKIE_NAME) * 1;
210			x5engine.imCart.email_data.shipping = x5engine.imCart.shipping_type;
211		}
212		return x5engine.imCart.shipping_type;
213	},
214
215	// Empty the cookie and reset the cart
216	_realEmptyCart: function () {
217		x5engine.imCart._setCart([]);
218		x5engine.imCart.updateWidget();
219		if (_jq("#imInputTotalPrice").length > 0) x5engine.imCart.showCart();
220	},
221
222	// Create a string ready to be used in an HTML/JS string
223	_htmlOutput: function (str) {
224		return str.replace(/\"/g, "''").replace(/\</g, "&lt;").replace(/\>/g, "&gt;");
225	},
226
227	// Create the order number
228	_createOrderNo: function (format) {
229		if (format === null || format === undefined)
230			format = x5engine.imCart.settings.order_no_format;
231		var date = new Date();
232		var day = date.getDate();
233		var month = date.getMonth() + 1;
234		var shortYear = date.getYear().toString();
235		shortYear = shortYear.substring(shortYear.length - 2);
236		if (parseInt(day, 10) < 10)
237			day = "0" + day;
238		if (parseInt(month, 10) < 10)
239			month = "0" + month;
240
241		format = format.replace(/\[dd\]/g, day);
242		format = format.replace(/\[mm\]/g, month);
243		format = format.replace(/\[yy\]/g, shortYear);
244		format = format.replace(/\[yyyy\]/g, date.getFullYear());
245		while (format.match(/\[A-Z\]/)) format = format.replace(/\[A-Z\]/, String.fromCharCode(Math.round(Math.random() * 25 + 65)));
246		while (format.match(/\[a-z\]/)) format = format.replace(/\[a-z\]/, String.fromCharCode(Math.round(Math.random() * 25 + 97)));
247		while (format.match(/\[0-9\]/)) format = format.replace(/\[0-9\]/, Math.round(Math.random() * 9));
248
249		return format;
250	},
251
252	// Create the correct HTML code for operational purposes
253	_createPaymentHtml: function (paymentHtml) {
254
255		// Replaces the keywords
256		if (x5engine.imCart.email_data.order_no === null || x5engine.imCart.email_data.order_no === undefined || x5engine.imCart.email_data.order_no === "")
257			x5engine.imCart.email_data.order_no = x5engine.imCart._createOrderNo();
258		paymentHtml = paymentHtml.replace(/\[ORDER_NO\]/g, x5engine.imCart.email_data.order_no);
259		paymentHtml = paymentHtml.replace(/\[EX_ORDER_NO\]/g, escape(x5engine.imCart.email_data.order_no)); // URL-escaped order number (to be enclosed in a link)
260		paymentHtml = paymentHtml.replace(/\[QUANTITY\]/g, x5engine.imCart.email_data.total_quantity);
261		paymentHtml = paymentHtml.replace(/\[EX_QUANTITY\]/g, escape(x5engine.imCart.email_data.total_quantity)); // URL-escaped quantity
262		paymentHtml = paymentHtml.replace(/\[WEIGHT\]/g, x5engine.imCart.email_data.total_weight);
263		paymentHtml = paymentHtml.replace(/\[EX_WEIGHT\]/g, escape(x5engine.imCart.email_data.total_weight)); // URL-escaped weight
264		var price = x5engine.imCart.email_data.clear_total;
265		// Format the price
266		var format = x5engine.imCart.settings.cart_price;
267		if (format.multiplier !== null && format.multiplier !== undefined)
268			price *= format.multiplier;
269		price = x5engine.imCart._setCurrency(price.toString(), format.format);
270		paymentHtml = paymentHtml.replace(/\[PRICE\]/g, price);
271		paymentHtml = paymentHtml.replace(/\[EX_PRICE\]/g, escape(price)); // URL-escaped price
272		// Unsecaped custom-format price
273		while (paymentHtml.match(/\[PRICE,\s*([0-9]+),\s*([\w#@\.,\[\]]+)\]/)) {
274			price = x5engine.imCart.email_data.clear_total;
275			price *= parseInt(RegExp.$1, 10);
276			price = x5engine.imCart._setCurrency(price.toString(), RegExp.$2);
277			paymentHtml = paymentHtml.replace(/\[PRICE,\s*([0-9]+),\s*([\w#@\.,\[\]]+)\]/, price);
278		}
279		// Escaped custom-format price
280		while (paymentHtml.match(/\[EX_PRICE,\s*([0-9]+),\s*([\w#@\.,\[\]]+)\]/)) {
281			price = x5engine.imCart.email_data.clear_total;
282			price *= parseInt(RegExp.$1, 10);
283			price = x5engine.imCart._setCurrency(price.toString(), RegExp.$2);
284			paymentHtml = paymentHtml.replace(/\[EX_PRICE,\s*([0-9]+),\s*([\w#@\.,\[\]]+)\]/, escape(price));
285		}
286
287		//Customer data fields
288		post = x5engine.imCart.email_data.form;
289		if (post != null && post["imCartName_shipping"] != null && post["imCartName_shipping"] != "") {
290			// Unescaped values
291			paymentHtml = paymentHtml.replace(/\[FIRST_NAME\]/g, ((post["imCartName_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartName_shipping"].imValue) : ""));
292			paymentHtml = paymentHtml.replace(/\[LAST_NAME\]/g, ((post["imCartLastName_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartL
292astName_shipping"].imValue) : ""));
293			paymentHtml = paymentHtml.replace(/\[ADDRESS1\]/g, ((post["imCartAddress1_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartAddress1_shipping"].imValue) : ""));
294			paymentHtml = paymentHtml.replace(/\[ADDRESS2\]/g, ((post["imCartAddress2_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartAddress2_shipping"].imValue) : ""));
295			paymentHtml = paymentHtml.replace(/\[CITY\]/g, ((post["imCartCity_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartCity_shipping"].imValue) : ""));
296			paymentHtml = paymentHtml.replace(/\[STATE\]/g, ((post["imCartStateRegion_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartStateRegion_shipping"].imValue) : ""));
297			paymentHtml = paymentHtml.replace(/\[COUNTRY\]/g, ((post["imCartCountry_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartCountry_shipping"].imValue) : ""));
298			paymentHtml = paymentHtml.replace(/\[ZIP\]/g, ((post["imCartZipPostalCode_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartZipPostalCode_shipping"].imValue) : ""));
299			paymentHtml = paymentHtml.replace(/\[EMAIL\]/g, ((post["imCartEmail_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartEmail_shipping"].imValue) : ""));
300
301			// Escaped values
302			paymentHtml = paymentHtml.replace(/\[EX_FIRST_NAME\]/g, ((post["imCartName_shipping"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartName_shipping"].imValue)) : ""));
303			paymentHtml = paymentHtml.replace(/\[EX_LAST_NAME\]/g, ((post["imCartLastName_shipping"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartLastName_shipping"].imValue)) : ""));
304			paymentHtml = paymentHtml.replace(/\[EX_ADDRESS1\]/g, ((post["imCartAddress1_shipping"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartAddress1_shipping"].imValue)) : ""));
305			paymentHtml = paymentHtml.replace(/\[EX_ADDRESS2\]/g, ((post["imCartAddress2_shipping"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartAddress2_shipping"].imValue)) : ""));
306			paymentHtml = paymentHtml.replace(/\[EX_CITY\]/g, ((post["imCartCity_shipping"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartCity_shipping"].imValue)) : ""));
307			paymentHtml = paymentHtml.replace(/\[EX_STATE\]/g, ((post["imCartStateRegion_shipping"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartStateRegion_shipping"].imValue)) : ""));
308			paymentHtml = paymentHtml.replace(/\[EX_COUNTRY\]/g, ((post["imCartCountry_shipping"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartCountry_shipping"].imValue)) : ""));
309			paymentHtml = paymentHtml.replace(/\[EX_ZIP\]/g, ((post["imCartZipPostalCode_shipping"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartZipPostalCode_shipping"].imValue)) : ""));
310			paymentHtml = paymentHtml.replace(/\[EX_EMAIL\]/g, ((post["imCartEmail_shipping"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartEmail_shipping"].imValue)) : ""));
311		} else if (post != null) {
312			// Unescaped values
313			paymentHtml = paymentHtml.replace(/\[FIRST_NAME\]/g, ((post["imCartName"] != null) ? x5engine.imCart._htmlOutput(post["imCartName"].imValue) : ""));
314			paymentHtml = paymentHtml.replace(/\[LAST_NAME\]/g, ((post["imCartLastName"] != null) ? x5engine.imCart._htmlOutput(post["imCartLastName"].imValue) : ""));
315			paymentHtml = paymentHtml.replace(/\[ADDRESS1\]/g, ((post["imCartAddress1"] != null) ? x5engine.imCart._htmlOutput(post["imCartAddress1"].imValue) : ""));
316			paymentHtml = paymentHtml.replace(/\[ADDRESS2\]/g, ((post["imCartAddress2"] != null) ? x5engine.imCart._htmlOutput(post["imCartAddress2"].imValue) : ""));
317			paymentHtml = paymentHtml.replace(/\[CITY\]/g, ((post["imCartCity"] != null) ? x5engine.imCart._htmlOutput(post["imCartCity"].imValue) : ""));
318			paymentHtml = paymentHtml.replace(/\[STATE\]/g, ((post["imCartStateRegion"] != null) ? x5engine.imCart._htmlOutput(post["imCartStateRegion"].imValue) : ""));
319			paymentHtml = paymentHtml.replace(/\[COUNTRY\]/g, ((post["imCartCountry"] != null) ? x5engine.imCart._htmlOutput(post["imCartCountry"].imValue) : ""));
320			paymentHtml = paymentHtml.replace(/\[ZIP\]/g, ((post["imCartZipPostalCode"] != null) ? x5engine.imCart._htmlOutput(post["imCartZipPostalCode"].imValue) : ""));
321			paymentHtml = paymentHtml.replace(/\[EMAIL\]/g, ((post["imCartEmail"] != null) ? x5engine.imCart._htmlOutput(post["imCartEmail"].imValue) : ""));
322
323			// Escaped values
324			paymentHtml = paymentHtml.replace(/\[EX_FIRST_NAME\]/g, ((post["imCartName"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartName"].imValue)) : ""));
325			paymentHtml = paymentHtml.replace(/\[EX_LAST_NAME\]/g, ((post["imCartL
325astName"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartLastName"].imValue)) : ""));
326			paymentHtml = paymentHtml.replace(/\[EX_ADDRESS1\]/g, ((post["imCartAddress1"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartAddress1"].imValue)) : ""));
327			paymentHtml = paymentHtml.replace(/\[EX_ADDRESS2\]/g, ((post["imCartAddress2"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartAddress2"].imValue)) : ""));
328			paymentHtml = paymentHtml.replace(/\[EX_CITY\]/g, ((post["imCartCity"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartCity"].imValue)) : ""));
329			paymentHtml = paymentHtml.replace(/\[EX_STATE\]/g, ((post["imCartStateRegion"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartStateRegion"].imValue)) : ""));
330			paymentHtml = paymentHtml.replace(/\[EX_COUNTRY\]/g, ((post["imCartCountry"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartCountry"].imValue)) : ""));
331			paymentHtml = paymentHtml.replace(/\[EX_ZIP\]/g, ((post["imCartZipPostalCode"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartZipPostalCode"].imValue)) : ""));
332			paymentHtml = paymentHtml.replace(/\[EX_EMAIL\]/g, ((post["imCartEmail"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartEmail"].imValue)) : ""));
333		}
334
335		return paymentHtml;
336	},
337
338	_updateOption: function (id, old_option, new_option, quantity, obj) {
339		x5engine.imCart.addProduct(id, 0, old_option, true, false);
340		x5engine.imCart.addProduct(id, quantity, new_option);
341		x5engine.imCart.showCart(_jq(obj).attr("id"), 1);
342	},
343
344	cartPage: function () {
345		var category = x5engine.utils.getParam("category");
346		if (category != null && category != "") x5engine.imCart.showCategory(x5engine.utils.getParam("category"));
347		else x5engine.imCart.showCart();
348	},
349
350	// Save the current page and go to the cart
351	gotoCart: function (in_cart) {
352		if (typeof in_cart == "string") {
353			_jq.imCookie("imShopPage", window.location.href, {
354				path: '/'
355			});
356			location.href = in_cart + "cart/index.html";
357			return true;
358		} else {
359			if (in_cart == null) in_cart = false;
360			if (!in_cart) {
361				_jq.imCookie("imShopPage", window.location.href, {
362					path: '/'
363				});
364				location.href = "cart/index.html";
365			} else {
366				location.href = "index.html";
367			}
368		}
369
370		return false;
371	},
372
373	gotoCategory: function (id) {
374		_jq.imCookie("imShopPage", window.location.href);
375		location.href = "cart/index.html?category=" + id;
376	},
377
378	// Continue shopping button
379	continueShopping: function () {
380		var oldPage = _jq.imCookie("imShopPage", null, {
381			path: '/'
382		});
383		if (oldPage != null) {
384			window.location.href = oldPage;
385		} else window.location.href = x5engine.imCart.settings.continue_shopping_page;
386	},
387
388	// Add a product quantity to the cart
389	// If force is true, quantity overrides the actual quantity in the cart. If force is false the quantity is added to the existing one
390	addProduct: function (id, quantity, option, force, message) {
391		if (message === null || message === undefined) message = true;
392		if (quantity === null || quantity === undefined) quantity = 1;
393		if (force === null || force === undefined) force = false;
394		if (option === null || option === undefined) option = "null";
395
396		if (x5engine.imCart.products[id].min_quantity !== null && x5engine.imCart.products[id].min_quantity !== undefined && quantity < x5engine.imCart.products[id].min_quantity && quantity !== 0) {
397			alert((x5engine.l10n.getLocalization("cart_err_quantity")).replace("[QUANTITY]", x5engine.imCart.products[id].min_quantity));
398			return false;
399		}
400
401		var products = x5engine.imCart._getCart();
402		if ((products === null || products === undefined) && quantity > 0) {
403			x5engine.imCart._setCart([{
404				"id": id,
405				"quantity": quantity,
406				"option": escape(option)
407			}]);
408		} else {
409			var found = false;
410			for (var i = 0; i < products.length; i++) {
411				if (products[i].id == id && unescape(products[i].option) == unescape(option)) {
412					found = true;
413					if (!force) products[i].quantity = products[i].quantity * 1 + quantity * 1;
414					else {
415						if (quantity > 0) products[i].quantity = quantity * 1;
416						else if (message && confirm(x5engine.l10n.getLocalization("cart_remove_q"))) products[i] = null;
417						else if (!message) products[i] = null;
418					}
419				}
420			}
421
422			if (!found && quantity > 0) products[products.length] = {
423				"id": id,
424				"quantity": quantity,
425				"option": escape(option)
426			};
427
428			x5engine.imCart._setCart(products);
429		}
430	},
431
432	// Add a product to the cart
433	addToCart: function (id, quantity, in_cart, option) {
434		var product = x5engine.imCart.products[id];
435		if (quantity == null) quantity = _jq("#" + x5engine.imCart.costants.QUANT_FIELD_NAME.replace("{id}", id)).val();
436		if (quantity == null) quantity = 1;
437		if (option == null) {
438			if (_jq("#" + x5engine.imCart.costants.OPT_FIELD_NAME.replace("{id}", id)).length > 0) option = _jq("#" + x5engine.imCart.costants.OPT_FIELD_NAME.replace("{id}", id)).val();
439			else option = "null";
440		}
441
442		if (in_cart == null) in_cart = false;
443
444		if (/^[0-9]+$/.test(quantity) == false) {
445			alert(x5engine.l10n.getLocalization("cart_err_qty"));
446			return false;
447		}
448
449		x5engine.imCart.addProduct(id, quantity, option);
450		x5engine.imCart.updateWidget();
451		x5engine.imCart.gotoCart(in_cart);
452	},
453
454	// Remove a product from the cart
455	removeFromCart: function (id, option, obj) {
456		x5engine.imCart.addProduct(id, 0, option, true);
457		x5engine.imCart.updateWidget();
458		x5engine.imCart.showCart(obj, 1);
459	},
460
461	// Update the quantity of a product in the cart
462	updateCart: function (id, obj, updateScreen, option) {
463		if (updateScreen == null) updateScreen = false;
464		var quantity = _jq(obj).val();
465		if (/^[0-9]+$/.test(quantity) == false) {
466			alert(x5engine.l10n.getLocalization("cart_err_qty"));
467			return false;
468		}
469		var products = x5engine.imCart._getCart();
470		if ( !option )
471			option = "null";
472		else
473			option = $("#" + option).val();
474		var total_quantity = 0;
475		var total_weight = 0;
476
477		for (var i = 0; i < products.length; i++) {
478			if (products[i].id == id && (products[i].option == "null" || unescape(products[i].option) == unescape(option))) {
479				option = products[i].option;
480				total_weight += x5engine.imCart.products[id].weight * quantity;
481				total_quantity += quantity;
482			} else {
483				total_weight += x5engine.imCart.products[id].weight * products[i].quantity;
484				total_quantity += products[i].quantity;
485			}
486		}
487
488		x5engine.imCart.addProduct(id, quantity, option, true);
489		x5engine.imCart.updateWidget();
490		if (updateScreen)
491			x5engine.imCart.showCart(null, 1);
492
493		x5engine.imCart.updateTotalPrice(total_quantity, total_weight);
494	},
495
496	// Update the widget
497	updateWidget: function () {
498		var products = x5engine.imCart._getCart();
499		var sum = 0;
500		var total_vat = 0;
501		var total = 0;
502
503		_jq(".widget_quantity_total").each(function () {
504			if (products != null) {
505				for (var i = 0; i < products.length; i++) {
506					if (x5engine.imCart.products[products[i].id] != null) sum += products[i].quantity;
507				}
508			}
509			_jq(this).html(sum);
510		});
511		_jq(".widget_amount_total").each(function () {
512			if (products != null) {
513				for (var i = 0; i < products.length; i++) {
514					var id = products[i].id;
515					if (x5engine.imCart.products[id] != null) {
516						var quantity = products[i].quantity;
517						var option = products[i].option;
518						var discounts = x5engine.imCart.products[id].discounts;
519						var weight = x5engine.imCart.products[id].weight;
520						if (weight == null) weight = 0;
521						var discount = 0;
522						var subtot = 0;
523						var vat;
524
525						if (x5engine.imCart.products[id].vat != null) vat = x5engine.imCart.products[id].vat;
526						else if (x5engine.imCart.settings.vat != null) vat = x5engine.imCart.settings.vat;
527						else vat = 0;
528
529						if (discounts != null) discount = x5engine.imCart._getValueFromKey(quantity, discounts);
530
531						subtot = quantity * x5engine.imCart.products[id].price;
532						subtot -= (subtot * discount);
533
534						total_vat += subtot + subtot * vat;
535					}
536				}
537				sum = total_vat;
538			}
539			_jq(this).html(x5engine.imCart._setCurrency(sum));
540		});
541	},
542
543	// Empty the cart
544	emptyCart: function (getConfirmation) {
545		if (getConfirmation == null) getConfirmation = true;
546		if (getConfirmation == true) {
547			if (confirm(x5engine.l10n.getLocalization("cart_empty"))) x5engine.imCart._realEmptyCart();
548		} else x5engine.imCart._realEmptyCart();
549		return false;
550	},
551
552	// Show a category
553	showCategory: function (id, obj) {
554		obj = obj || "#imCartContainer";
555		_jq(obj).empty().prepend("<h2 id=\"imPgTitle\" class=\"imTitleMargin\">" + x5engine.l10n.getLocalization('cart_step1') + "</h2>\n<div style=\"height: 15px;\">&nbsp;</div>" + x5engine.l10n.getLocalization('cart_step1_descr') + "<br /><br /><br />");
556		var html = "<table id=\"imCartProductsTable\"><tr class=\"imCartHeader\">";
557		html += "<td>" + x5engine.l10n.getLocalization("cart_descr") + "</td>";
558		html += "<td>" + x5engine.l10n.getLocalization("cart_opt") + "</td>";
559		html += "<td>" + x5engine.l10n.getLocalization("cart_price") + "</td>";
560		if (!x5engine.imCart.settings.vatincluded) html += "<td>" + x5engine.l10n.getLocalization("cart_vat") + "</td>";
561		html += "<td>" + x5engine.l10n.getLocalization("cart_qty") + "</td>";
562		html += "</tr>";
563		var str_eval = "";
564		for (var pid in x5engine.imCart.products) {
565			var product = x5engine.imCart.products[pid];
566			if (product.category == id) {
567				html += "<tr><td><b>" + product.name + "</b><br />" + product.description + "</td>";
568				html += "<td>";
569				if (product.options != null && product.options.length > 0) {
570					html += "<select id=\"product_" + pid + "_opt\">";
571					for (var option in product.options)
572					html += "<option value=\"" + product.options[option] + "\">" + x5engine.imCart._restoreSpecialChars(unescape(product.options[option])) + "</option>";
573					html += "</select>";
574				}
575				html += "</td>";
576				html += "<td style=\"text-align: right;\">" + x5engine.imCart._setCurrency(product.price) + "</td>";
577				if (!x5engine.imCart.settings.vatincluded) html += "<td style=\"text-align: right;\">" + ((product.vat != null && product.vat > 0) ? (product.vat * 100).toFixed(2) + "%" : " - ") + "</td>";
578				html += "<td style=\"text-align: right;\"><input type=\"text\" value=\"1\" id=\"product_" + pid + "_qty\" size=\"3\" style=\"text-align: right\"/>";
579				html += "<img id=\"buy_" + pid + "\" style=\"cursor: pointer; vertical-align: middle; margin-left: 5px;\" src=\"../" + x5engine.imCart.settings.add_to_cart_icon + "\" alt=\"" + x5engine.l10n.getLocalization("cart_add") + "\" title=\"" + x5engine.l10n.getLocalization("cart_add") + "\" /></td>";
580				str_eval += "_jq('#buy_" + pid + "').unbind('click').click(function () { x5engine.imCart.addToCart('" + pid + "', null, true); });";
581				html += "</tr>";
582			}
583		}
584
585		html += "</table>";
586		html += "<div style=\"text-align: center; margin-top: 20px;\">";
587		html += "<input type=\"button\" id=\"imCartButtonBack\" value=\"" + x5engine.l10n.getLocalization("cart_continue_shopping") + "\" style=\"margin-right: 5px;\" />";
588		html += "<input type=\"button\" id=\"imCartButtonNext\" value=\"" + x5engine.l10n.getLocalization("cart_goshop") + "\" style=\"margin-right: 5px;\" />";
589		html += "</div>";
590
591		_jq(obj).append(html);
592		eval(str_eval);
593		_jq("#imCartButtonBack").unbind("click").click(x5engine.imCart.continueShopping);
594		_jq("#imCartButtonNext").unbind("click").click(function () {
595			x5engine.imCart.showCart();
596		});
597		_jq("#imContent").triggerHandler("change");
598	},
599
600	// Show the cart
601	showCart: function (obj, time) {
602		var email_data = {};
603		var str_eval = "";
604
605		_jq(".imTip").fadeOut(100, function () {
606			_jq(".imTip").remove();
607		});
608
609		obj = obj || "#imCartContainer";
610		obj = _jq(obj);
611		if (time == null) time = 100;
612
613		var products = x5engine.imCart._getCart();
614		var filtered_products = new Array();
615		// Filter the products (if the cookie contains products not in the cart anymore)
616		for (var i = 0; i < products.length; i++) {
617			if (x5engine.imCart.products[products[i].id] != null) filtered_products[filtered_products.length] = products[i];
618		}
619		products = filtered_products;
620
621		if (products != null && products.length > 0) {
622			obj.fadeOut(time, function () {
623				obj.empty().prepend("<h2 id=\"imPgTitle\" class=\"imTitleMargin\">" + x5engine.l10n.getLocalization('cart_step2') + "</h2>\n");
624
625				var html = "<p>" + x5engine.l10n.getLocalization('cart_step2_cartlist') + "</p>";
626
627				// Products
628				html += "<table id=\"imCartProductsTable\"><tr class=\"imCartHeader\">";
629				html += "<td>" + x5engine.l10n.getLocalization("cart_descr") + "</td>";
630				html += "<td>" + x5engine.l10n.getLocalization("cart_opt") + "</td>";
631				html += "<td>" + x5engine.l10n.getLocalization("cart_price") + "</td>";
632				html += "<td>" + x5engine.l10n.getLocalization("cart_qty") + "</td>";
633				html += "<td>" + x5engine.l10n.getLocalization("cart_subtot") + "</td>";
634				if (!x5engine.imCart.settings.vatincluded) html += "<td>" + x5engine.l10n.getLocalization("cart_vat") + "</td>";
635				html += "<td></td></tr>";
636				var total = 0;
637				var total_vat = 0;
638				var grand_vat = 0;
639				var shipping_total = 0;
640				var shipping_total_vat = 0;
641				var total_quantity = 0;
642				var total_weight = 0;
643
644				for (var i = 0; i < products.length; i++) {
645					var id = products[i].id;
646					var quantity = products[i].quantity;
647					var option = products[i].option;
648					var discounts = x5engine.imCart.products[id].discounts;
649					var weight = x5engine.imCart.products[id].weight;
650					if (weight == null) weight = 0;
651					var discount = 0;
652					var subtot = 0;
653					var vat;
654
655					if (x5engine.imCart.products[id].vat != null) vat = x5engine.imCart.products[id].vat;
656					else if (x5engine.imCart.settings.vat != null) vat = x5engine.imCart.settings.vat;
657					else vat = 0;
658
659					if (discounts != null) discount = x5engine.imCart._getValueFromKey(quantity, discounts);
660
661					total_weight += weight * quantity;
662					total_quantity += quantity;
663					subtot = quantity * x5engine.imCart.products[id].price;
664					subtot -= (subtot * discount);
665
666					total += subtot;
667					grand_vat += subtot * vat;
668					total_vat += subtot + subtot * vat;
669
670					var cart_p = x5engine.imCart.products[id];
671					email_data[id + "_" + option] = {
672						id_user: cart_p.id_user,
673						name: cart_p.name,
674						description: cart_p.description,
675						single_price: x5engine.imCart._setCurrency(x5engine.imCart.products[id].price - x5engine.imCart.products[id].price * discount),
676						price: x5engine.imCart._setCurrency(subtot),
677						price_vat: x5engine.imCart._setCurrency(subtot + subtot * vat),
678						clean_vat: subtot * vat,
679						option: option,
680						quantity: quantity,
681						vat: vat,
682						vat_f: x5engine.imCart._setCurrency(vat * (x5engine.imCart.products[id].price - x5engine.imCart.products[id].price * discount))
683					};
684
685					html += "<tr><td>" + x5engine.imCart.products[id].id_user + (x5engine.imCart.products[id].description != "" ? " - " + x5engine.imCart.products[id].description : "") + "</td>";
686					html += "<td>";
687					var freeid = "product_" + id + "_" + x5engine.utils.imHash(option) + "_opt";
688					if (option != "null") {
689						html += "<select id=\"" + freeid + "\">";
690						for (var j = 0; j < x5engine.imCart.products[id].options.length; j++) {
691							html += "<option value=\"" + x5engine.imCart.products[id].options[j] + "\" " + ((x5engine.imCart.products[id].options[j] == unescape(option)) ? "selected" : "") + ">" + x5engine.imCart._restoreSpecialChars(unescape(x5engine.imCart.products[id].options[j])) + "</option>";
692							str_eval += "_jq('#" + freeid + "').unbind('change').change(function () {x5engine.imCart._updateOption('" + id + "', '" + option + "', _jq('#" + freeid + "').val() , " + quantity + ", '" + _jq(obj).attr("id") + "')});";
693						}
694						html += "</select>";
695					}
696					html += "</td>";
697					html += "<td style=\"text-align: right;\">" + x5engine.imCart._setCurrency(x5engine.imCart.products[id].price - x5engine.imCart.products[id].price * discount) + "</td>";
698					html += "<td style=\"text-align: right;\"><input style=\"text-align: right;\" id=\"qty_product_" + i + "\" type=\"text\" value=\"" + quantity + "\" size=\"2\"></td>";
699					str_eval += "_jq('#qty_product_" + i + "').unbind('change').change(function () {x5engine.imCart.updateCart('" + id + "', this, true, '" + freeid + "');});";
700					html += "<td style=\"text-align: right;\">" + x5engine.imCart._setCurrency(subtot) + "</td>";
701					if (!x5engine.imCart.settings.vatincluded)
702						html += "<td style=\"text-align: right;\">" + ((vat) ? x5engine.imCart._setCurrency(subtot * vat) + " (" + (vat * 100).toFixed(2) + "%)" : "-") + "</td>";
703					html += "<td style=\"text-align: center\"><img id=\"remove_product_" + i + "\" style=\"vertical-align: middle; cursor: pointer;\" src=\"../" + x5engine.imCart.settings.remove_from_cart_icon + "\" alt=\"" + x5engine.l10n.getLocalization("cart_remove") + "\" title=\"" + x5engine.l10n.getLocalization("cart_remove") + "\" /></td></tr>";
704					str_eval += "_jq('#remove_product_" + i + "').click(function () { return x5engine.imCart.removeFromCart('" + id + "', '" + option + "', '#" + _jq(obj).attr('id') + "'); });";
705				}
706
707				x5engine.imCart = _jq.extend(x5engine.imCart, {
708					'product_price_plus_vat': total_vat,
709					'product_price_no_vat': total,
710					'product_vat': grand_vat
711				});
712				if (x5engine.imCart.email_data == null) x5engine.imCart.email_data = {};
713				x5engine.imCart.email_data.products = email_data;
714
715				html += "<tr style=\"text-align: right;\"><td style=\"border-width: 0; background-color: transparent;\" colspan=\"" + (x5engine.imCart.settings.vatincluded ? 3 : 4) + "\"></td><td class=\"nostyle\">" + x5engine.l10n.getLocalization("cart_total") + "</td><td class=\"nostyle\">" + x5engine.imCart._setCurrency(total) + "</td>" + (x5engine.imCart.settings.vatincluded ? '<td style="border: none; background-color: transparent;"></td>' : '') + "</tr>";
716				if (!x5engine.imCart.settings.vatincluded) {
717					html += "<tr style=\"text-align: right;\"><td style=\"border-width: 0; background-color: transparent;\" colspan=\"4\"></td><td class=\"nostyle\">" + x5engine.l10n.getLocalization("cart_vat") + "</td><td class=\"nostyle\">" + x5engine.imCart._setCurrency(grand_vat) + "</td></tr>";
718					//html += "<tr style=\"text-align: right;\"><td style=\"border-width: 0; background-color: transparent;\" colspan=\"4\"></td><td class=\"nostyle\">" + x5engine.l10n.getLocalization("cart_total_vat") + "</td><td class=\"nostyle\">" + x5engine.imCart._setCurrency(total_vat) + "</td></tr>";
719				}
720
721				html += "</table>";
722				html += "<input type=\"hidden\" id=\"imInputTotalPrice\" name=\"imInputTotalPrice\" value=\"" + total_vat + "\"/>";
723
724				// Payment
725				html += "<p>" + x5engine.l10n.getLocalization('cart_step2_shiplist') + "</p><table id=\"imCartPaymentsTable\">";
726				html += "<tr class=\"imCartHeader\"><td colspan=\"2\">" + x5engine.l10n.getLocalization('cart_payment') + "</td><td>" + x5engine.l10n.getLocalization("cart_price") + "</td></tr>";
727				var payments = x5engine.imCart.payments;
728
729				for (var i = 0; i < payments.length; i++) {
730					var price = payments[i].price || 0;
731					if (payments[i].vat != null) price += price * payments[i].vat;
732					html += "<tr><td style=\"width: 5%\"><input type=\"radio\" name=\"imPaymentType\" value=\"" + i + "\" id=\"cart_payment_" + i + "\" " + ((x5engine.imCart._getPayment() == i && x5engine.imCart.email_data.payment != null) ? "checked" : "") + "/></td><td style=\"width: 80%\"><label for=\"cart_payment_" + i + "\"><b>" + payments[i].name + ":</b> " + payments[i].description + "</label></td><td style=\"width: 15%; text-align: right;\">" + ((price > 0) ? x5engine.imCart._setCurrency(price) : "-") + "</td></tr>";
733					str_eval += "_jq('#cart_payment_" + i + "').unbind('click').click(function () { x5engine.imCart.updatePayment(" + i + ", " + total_quantity + ", " + total_weight + ")});";
734					if (x5engine.imCart._getPayment() == i) {
735						total_vat += price;
736						x5engine.imCart.updatePayment(i, total_quantity, total_weight);
737					}
738				}
739				html += "</table>";
740
741				// Shipping
742				html += "<br /><table id=\"imCartShippingsTable\">";
743				html += "<tr class=\"imCartHeader\"><td colspan=\"2\">" + x5engine.l10n.getLocalization('cart_shipping') + "</td><td>" + x5engine.l10n.getLocalization("cart_price") + "</td></tr>";
744				var shippings = x5engine.imCart.shippings;
745
746				for (var i = 0; i < shippings.length; i++) {
747					var price = x5engine.imCart._getShippingPrice(shippings[i], x5engine.imCart.product_price_plus_vat, total_quantity, total_weight);
748					html += "<tr><td style=\"width: 5%\"><input type=\"radio\" name=\"imShippingType\" value=\"" + i + "\" id=\"cart_shipping_" + i + "\" " + ((x5engine.imCart._getShipping() == i && x5engine.imCart.email_data.shipping != null) ? "checked" : "") + "/></td><td style=\"width: 80%\"><label for=\"cart_shipping_" + i + "\"><b>" + shippings[i].name + ":</b> " + shippings[i].description + "</label></td><td style=\"width: 15%; text-align: right;\">" + ((price > 0) ? x5engine.imCart._setCurrency(price) : "-") + "</td></tr>";
749					str_eval += "_jq('#cart_shipping_" + i + "').unbind('click').click(function () {x5engine.imCart.updateShipping(" + i + ", " + total_quantity + ", " + total_weight + ");});";
750					if (x5engine.imCart._getShipping() == i) {
751						total_vat += price;
752						x5engine.imCart.updateShipping(i, total_quantity, total_weight);
753					}
754				}
755				html += "</table><br />";
756
757				// Price summary
758				html += "<div><div id=\"imCartTotalPriceCont\">" + x5engine.l10n.getLocalization('cart_total_vat') + ": <span id=\"imDivTotalPrice\">" + x5engine.imCart._setCurrency(total_vat) + "</span></div></div>";
759
760				// Currency conversion disable
761				if (x5engine.utils.isOnline() && false) {
762					var currencies = x5engine.imCart.settings.currencies;
763					if (currencies != null && currencies.length > 0) {
764						html += "<select id=\"imCurrencyConversion\" style=\"margin-left: 10px\">";
765						str_eval += "_jq('#imCurrencyConversion').unbind('change').change(function () { x5engine.imCart.currencyConversion(this); });";
766						html += "<option value=\"\">" + x5engine.l10n.getLocalization("cart_currency_conversion") + "</option>";
767						for (i = 0; i < currencies.length; i++) {
768							html += "<option value=\"" + currencies[i].value + "\">" + currencies[i].value + " - " + currencies[i].text + "</option>";
769						}
770						html += "</select><div id=\"currencyConvResult\">Risultato conversione</div>";
771					}
772				}
773
774				html += "<br /><br /><br />";
775				html += "<div style=\"text-align: center; margin-top: 30px;\">";
776				html += "<input type=\"button\" id=\"imCartButtonBack\" value=\"" + x5engine.l10n.getLocalization("cart_continue_shopping") + "\" style=\"margin-right: 5px;\" />";
777				html += "<input type=\"button\" id=\"imCartButtonEmpty\" value=\"" + x5engine.l10n.getLocalization("cart_empty_button") + "\" style=\"margin: 0 5px;\" />";
778				html += "<input type=\"button\" id=\"imCartButtonNext\" value=\"" + x5engine.l10n.getLocalization("cart_step1_gonext", x5engine.l10n.getLocalization("cart_gonext")) + "\" style=\"margin-left: 5px;\"/>";
779				html += "</div>";
780
781				obj.append(html).fadeIn(time, function () {
782					_jq("#imContent").triggerHandler("change");
783				});
784				_jq("#imCartButtonBack").unbind("click").click(x5engine.imCart.continueShopping);
785				_jq("#imCartButtonEmpty").unbind("click").click(function () {
786					x5engine.imCart.emptyCart(true);
787				});
788				_jq("#imCartButtonNext").unbind("click").click(function () {
789					x5engine.imCart.showForm('#' + _jq(obj).attr("id"));
790				});
791				eval(str_eval);
792				_jq("#imInputTotalPrice").val(total_vat);
793			});
794		} else {
795			obj.fadeOut(time, function () {
796				obj.empty().prepend("<h2 id=\"imPgTitle\" class=\"imTitleMargin\">" + x5engine.l10n.getLocalization('cart_step2') + "</h2>\n<div style=\"height: 15px;\">&nbsp;</div><br />");
797				obj.append("<div style=\"text-align: center; font-weight: bold; font-size: 12px;\">" + x5engine.l10n.getLocalization("cart_err_emptycart") + "</div><br /><br />");
798				obj.append("<div style=\"text-align: center\"><input type=\"button\" id=\"imCartButtonBack\" value=\"" + x5engine.l10n.getLocalization("cart_continue_shopping") + "\" style=\"margin-right: 5px;\" /></div>");
799				_jq("#imCartButtonBack").unbind("click").click(x5engine.imCart.continueShopping);
800				obj.fadeIn(time);
801			});
802		}
803
804		return false;
805	},
806
807	// Convert currency using Google
808	currencyConversion: function (obj) {
809		if (obj.selectedIndex != 0) {
810			if (x5engine.imCart.email_data.clear_total != null) {
811				_jq.ajax({
812					url: x5engine.imCart.settings.post_url + "?action=currency&amount=" + x5engine.imCart.email_data.clear_total + "&from=" + x5engine.imCart.settings.currency_id + "&to=" + _jq(obj).val(),
813					type: "GET",
814					dataType: "json",
815					success: function (data) {
816						_jq("#currencyConvResult").html(x5engine.imCart._setCurrency(data.value, x5engine.imCart.settings.currency_format, _jq(obj).val()));
817					},
818					error: function () {
819						_jq("#currencyConvResult").html(x5engine.l10n.getLocalization("cart_err_currency_conversion"));
820					}
821				});
822			} else {
823				obj.selectedIndex = 0;
824			}
825		} else {
826			_jq("#currencyConvResult").empty();
827		}
828	},
829
830	// Show the user data form
831	showForm: function (obj) {
832		if (x5engine.imCart._getPayment() == null) {
833			alert(x5engine.l10n.getLocalization("cart_err_payment"));
834			return false;
835		}
836		if (x5engine.imCart._getShipping() == null) {
837			alert(x5engine.l10n.getLocalization("cart_err_shipping"));
838			return false;
839		}
840
841		if (x5engine.imCart.settings.minimum_amount > 0 && _jq("#imInputTotalPrice").val() * 1 < x5engine.imCart.settings.minimum_amount) {
842			alert(x5engine.l10n.getLocalization('cart_err_minimum_price').replace(/\[PRICE\]/g, x5engine.imCart._setCurrency(x5engine.imCart.settings.minimum_amount)));
843			return false;
844		}
845
846		obj = obj || "#imCartContainer";
847		obj = _jq(obj);
848
849		obj.fadeOut(100, function () {
850			obj.empty().prepend("<h2 id=\"imPgTitle\" class=\"imTitleMargin\">" + x5engine.l10n.getLocalization('cart_step3') + "</h2>\n");
851
852			var html = "<p>" + x5engine.l10n.getLocalization('cart_step3_descr') + "</p>";
853			html += "<form id=\"imCartUserDataForm\">" + x5engine.imCart.html_form + "<br />";
854			html += "<div style=\"text-align: center\">";
855			html += "<input type=\"button\" id=\"imCartButtonBack\" value=\"" + x5engine.l10n.getLocalization("cart_goback") + "\" style=\"margin-right: 5px;\"/>";
856			html += "<input type=\"button\" id=\"imCartUserFormSubmit\" value=\"" + x5engine.l10n.getLocalization("cart_step2_gonext", x5engine.l10n.getLocalization("cart_gonext")) + "\" style=\"margin-right: 5px;\" /></form>";
857			html += "</div>";
858
859			obj.append(html).fadeIn(100, function () {
860				_jq("#imContent").triggerHandler("change");
861			});
862
863			_jq("#imCartButtonBack").unbind("click").click(function () {
864				x5engine.imCart.saveForm(obj);
865				x5engine.imCart.showCart('#' + obj.attr("id"));
866			});
867			_jq("#imCartUserFormSubmit").unbind("click").click(function () {
868				x5engine.imCart.showOrderSummary('#' + obj.attr("id"));
869			});
870
871			if (x5engine.imCart.settings.form_autocomplete) {
872				var json = x5engine.imCart._getFormData();
873				if (json != null) for (var i = 0; i < json.length; i++)
874				_jq("#" + json[i].id).val(json[i].val);
875			}
876		});
877	},
878
879	saveForm: function (obj) {
880		var fields = _jq("#imCartUserDataForm");
881		var post = {};
882		var form = [];
883		_jq(fields).find(":input").each(function () {
884			if (_jq(this).attr("id") != null && _jq(this).attr("id") != "" && !_jq(this).is("label") && _jq(this).attr("type") != "submit" && _jq(this).attr("type") != "button" && _jq(this).attr("type") != "reset") {
885				var fieldName = _jq("label[for=" + _jq(this).attr("id") + "] span").html();
886				try {
887					if (fieldName.charAt(fieldName.length - 1) == ":") fieldName = fieldName.substr(0, fieldName.length - 1);
888					post[_jq(this).attr("id")] = {
889						name: fieldName,
890						imValue: (_jq(this).is(":checkbox") ? (_jq(this).prop("checked") ? "yes" : "no") : x5engine.imCart._htmlOutput(_jq(this).val()))
891					};
892					form[form.length] = {
893						"id": _jq(this).attr("id"),
894						"val": (_jq(this).is(":checkbox") ? (_jq(this).prop("checked") ? "yes" : "no") : x5engine.imCart._htmlOutput(_jq(this).val()))
895					};
896				} catch (e) {}
897			}
898		});
899
900		if (x5engine.imCart.settings.form_autocomplete) x5engine.imCart._setFormData(form);
901		x5engine.imCart.email_data.form = post;
902	},
903
904	// Show the order summary
905	showOrderSummary: function (obj) {
906		obj = obj || "#imCartContainer";
907		obj = _jq(obj);
908		if (x5engine.imForm.validate("#imCartUserDataForm", {
909			type: x5engine.imCart.settings.form_validation,
910			showAll: true,
911			position: "right"
912		})) {
913			obj.fadeOut(100, function () {
914				var post;
915				x5engine.imCart.saveForm(obj);
916				post = x5engine.imCart.email_data.form;
917
918				obj.empty().prepend("<h2 id=\"imPgTitle\" class=\"imTitleMargin\">" + x5engine.l10n.getLocalization('cart_step4') + "</h2>\n");
919
920				/*
921				|--------------
922				|	Summary
923				|--------------
924				 */
925
926				// Products
927				var html = "<p>" + x5engine.l10n.getLocalization('cart_step4_descr') + "</p>";
928				html += "<table id=\"imCartProductsTable\">";
929				html += "<tr class=\"imCartHeader\">";
930				html += "<td style=\"width: " + (x5engine.imCart.settings.vatincluded ? "48" : "35") + "%\">" + x5engine.l10n.getLocalization("cart_descr") + "</td>";
931				html += "<td style=\"width: 13%\">" + x5engine.l10n.getLocalization("cart_qty") + (x5engine.l10n.getLocalization("cart_single_price") != "" ? " x " + x5engine.l10n.getLocalization("cart_single_price") : "") + "</td>";
932				if (!x5engine.imCart.settings.vatincluded)
933					html += "<td style=\"width: 13%\">" + x5engine.l10n.getLocalization("cart_vat") + "</td>";
934				html += "<td style=\"width: 13%\">" + x5engine.l10n.getLocalization("cart_price") + "</td>";
935				html += "</tr>";
936
937				var data = x5engine.imCart.email_data;
938
939				for (var product in data.products) {
940					html += "<tr valign=\"top\"><td>" + data.products[product].name + ((data.products[product].option != "null") ? " - " + x5engine.imCart._restoreSpecialChars(unescape(data.products[product].option)) : "") + (data.products[product].description != "" ? "<p>" + data.products[product].description + "</p>" : "") + "</td>";
941					html += "<td style=\"text-align: right;\">" + data.products[product].quantity + " x " + data.products[product].single_price + "</td>";
942					if (!x5engine.imCart.settings.vatincluded)
943						html += "<td style=\"text-align: right;\">" + ((data.products[product].vat != null && data.products[product].vat > 0) ? (x5engine.imCart._setCurrency(data.products[product].clean_vat) + " (" + (data.products[product].vat * 100).toFixed(2) + "%)") : "-") + "</td>";
944					html += "<td style=\"text-align: right;\">" + data.products[product].price + "</td>";
945					html += "</tr>";
946				}
947
948				html += "<tr style=\"text-align: right; font-weight: bold;\"><td class=\"nostyle\" colspan=\"" + (x5engine.imCart.settings.vatincluded ? 1 : 2) + "\"></td><td class=\"imCartHeader\">" + x5engine.l10n.getLocalization('cart_subtot') + "</td><td>" + x5engine.imCart._setCurrency(x5engine.imCart.product_price_no_vat) + "</td></tr>";
949
950				// Payment
951				var payment = x5engine.imCart.payments[x5engine.imCart._getPayment()];
952
953				// Separator
954				html += "<tr style=\"height: 10px;\"><td style=\"background-color: transparent; border: none;\" colspan=\"" + (x5engine.imCart.settings.vatincluded ? 3 : 4) + "\"></td></tr>"
955
956				html += "<tr class=\"imCartHeader\">";
957				html += "<td colspan=\"2\">" + x5engine.l10n.getLocalization("cart_payment") + "</td>";
958				if (!x5engine.imCart.settings.vatincluded)
959						html += "<td>" + x5engine.l10n.getLocalization("cart_vat") + "</td>";
960				html += "<td>" + x5engine.l10n.getLocalization("cart_price") + "</td>";
961				html += "</tr>";
962				html += "<tr valign=\"top\">";
963				html += "<td colspan=\"2\"><b>" + payment.name + "</b><p>" + payment.description + "</p></td>";
964				if (!x5engine.imCart.settings.vatincluded) {
965					html += "<td style=\"text-align: right;\">" + (x5engine.imCart.email_data.payment.price != null ? x5engine.imCart._setCurrency(payment.price * payment.vat) + " (" + (payment.vat * 100).toFixed(2) + "%)" : "-") + "</td>";
966					html += "<td style=\"text-align: right;\">" + (x5engine.imCart.email_data.payment.price != null ? x5engine.imCart._setCurrency(payment.price) : "-") + "</td>";
967				} else {
968					html += "<td style=\"text-align: right;\">" + (x5engine.imCart.email_data.payment.price != null ? x5engine.imCart.email_data.payment.price : "-") + "</td>";
969				}
970				html += "</tr>";
971
972				// Shipping
973				var shipping = x5engine.imCart.shippings[x5engine.imCart._getShipping()];
974				var shipping_price = x5engine.imCart._getShippingPrice(shipping, x5engine.imCart.product_price_plus_vat, x5engine.imCart.email_data.total_quantity, x5engine.imCart.email_data.total_weight, false) * 1;
975
976				// Separator
977				html += "<tr style=\"height: 10px;\"><td style=\"background-color: transparent; border: none;\" colspan=\"" + (x5engine.imCart.settings.vatincluded ? 3 : 4) + "\"></td></tr>"
978
979				html += "<tr class=\"imCartHeader\">";
980				html += "<td colspan=\"2\">" + x5engine.l10n.getLocalization("cart_shipping") + "</td>";
981				if (!x5engine.imCart.settings.vatincluded)
982					html += "<td>" + x5engine.l10n.getLocalization("cart_vat") + "</td>";
983				if (x5engine.imCart.email_data.shipping.price != null)
984					html += "<td style=\"width: 15%\">" + x5engine.l10n.getLocalization("cart_price") + "</td>";
985				html +=  "</tr>";
986
987				html += "<tr valign=\"top\"><td colspan=\"2\"><b>
987" + shipping.name + "</b><br />" + shipping.description;
988				html += "<p><b>" + x5engine.l10n.getLocalization("cart_shipping_address") + ":</b></p>";
989				if (post["imCartName_shipping"] != null) {
990					html += ((post["imCartCompany_shipping"] != null && post["imCartCompany_shipping"] != "") ? post["imCartCompany_shipping"].imValue + " - " : "");
991					html += ((post["imCartName_shipping"] != null) ? post["imCartName_shipping"].imValue + " " : "");
992					html += ((post["imCartLastName_shipping"] != null) ? post["imCartLastName_shipping"].imValue : "");
993					html += " " + ((post["imCartEmail_shipping"] != null) ? ("(" + post["imCartEmail_shipping"].imValue + ")") : "") + "<br />";
994					html += ((post["imCartAddress1_shipping"] != null) ? (post["imCartAddress1_shipping"].imValue + "<br />") : "");
995					html += ((post["imCartAddress2_shipping"] != null) ? (post["imCartAddress2_shipping"].imValue + "<br />") : "");
996					html += ((post["imCartCity_shipping"] != null) ? (post["imCartCity_shipping"].imValue) : "");
997					html += ((post["imCartStateRegion_shipping"] != null) ? (" (" + post["imCartStateRegion_shipping"].imValue + ")") : "");
998					html += ((post["imCartZipPostalCode_shipping"] != null) ? (", " + post["imCartZipPostalCode_shipping"].imValue + "<br />") : "");
999					html += ((post["imCartCountry_shipping"] != null) ? (post["imCartCountry_shipping"].imValue + "<br />") : "");
1000					html += ((post["imCartPhone_shipping"] != null) ? (post["imCartPhone_shipping"].imValue + "<br />") : "");
1001				} else if (post["imCartName"] != null) {
1002					html += ((post["imCartCompany"] != null && post["imCartCompany"] != "") ? post["imCartCompany"].imValue + " - " : "");
1003					html += ((post["imCartName"] != null) ? post["imCartName"].imValue + " " : "");
1004					html += ((post["imCartLastName"] != null) ? post["imCartLastName"].imValue : "");
1005					html += " " + ((post["imCartEmail"] != null) ? ("(" + post["imCartEmail"].imValue + ")") : "") + "<br />";
1006					html += ((post["imCartAddress1"] != null) ? (post["imCartAddress1"].imValue + "<br />") : "");
1007					html += ((post["imCartAddress2"] != null) ? (post["imCartAddress2"].imValue + "<br />") : "");
1008					html += ((post["imCartCity"] != null) ? (post["imCartCity"].imValue) : "");
1009					html += ((post["imCartStateRegion"] != null) ? (" (" + post["imCartStateRegion"].imValue + ")") : "");
1010					html += ((post["imCartZipPostalCode"] != null) ? (", " + post["imCartZipPostalCode"].imValue + "<br />") : "");
1011					html += ((post["imCartCountry"] != null) ? (post["imCartCountry"].imValue + "<br />") : "");
1012					html += ((post["imCartPhone"] != null) ? (post["imCartPhone"].imValue + "<br />") : "");
1013				}
1014				html += "</td>";
1015				if (!x5engine.imCart.settings.vatincluded) {
1016					html += "<td style=\"text-align: right\">" + (x5engine.imCart.email_data.shipping.price != null ? x5engine.imCart._setCurrency(shipping_price * shipping.vat)  + " (" + (shipping.vat * 100).toFixed(2) + "%)" : "-") + "</td>";
1017					html += "<td style=\"text-align: right\">" + (x5engine.imCart.email_data.shipping.price != null ? x5engine.imCart._setCurrency(shipping_price) : "-") + "</td>";
1018				} else { 
1019					html += "<td style=\"text-align: right\">" + (x5engine.imCart.email_data.shipping.price != null ? x5engine.imCart.email_data.shipping.price : "-") + "</td>";
1020				}
1021				html += "</tr>";
1022
1023				// Separator
1024				html += "<tr style=\"height: 10px;\"><td style=\"background-color: transparent; border: none;\" colspan=\"" + (x5engine.imCart.settings.vatincluded ? 3 : 4) + "\"></td></tr>"
1025
1026				// Total
1027				if (!x5engine.imCart.settings.vatincluded)
1028					html += "<tr style=\"text-align: right;\"><td class=\"nostyle\" colspan=\"2\"></td><td class=\"imCartHeader\">" + x5engine.l10n.getLocalization("cart_vat") + "</td><td>" + x5engine.imCart._setCurrency(x5engine.imCart.product_vat + payment.price * payment.vat + shipping_price * shipping.vat) + "</td></tr>";
1029				html += "<tr style=\"text-align: right; font-weight: bold;\"><td class=\"nostyle\" colspan=\"" + (x5engine.imCart.settings.vatincluded ? 1 : 2) + "\"></td><td class=\"imCartHeader\">" + x5engine.l10n.getLocalization('cart_total_vat') + "</td><td>" + x5engine.imCart.email_data.total + "</td></tr>";
1030				html += "</table>";
1031
1032				// Next/Previous button
1033				html += "<br /><br /><br />";
1034				html += "<div style=\"text-align: center; clear: both; margin-top: 30px;\">";
1035				html += "<input type=\"button\" id=\"imCartButtonBack\" value=\"" + x5engine.l10n.getLocalization("cart_goback") + "\" style=\"margin-right: 5px;\" />";
1036				html += "<input type=\"button\" id=\"imCartUserFormSubmit\" value=\"" + x5engine.l10n.getLocalization("cart_step3_gonext", x5engine.l10n.getLocalization("cart_gonext")) + "\" style=\"margin-left: 5px;\" />";
1037
1038				obj.append(html).fadeIn(100, function () {
1039					_jq("#imContent").triggerHandler("change");
1040				});
1041
1042				_jq("#imCartButtonBack").unbind("click").click(function () {
1043					x5engine.imCart.showForm('#' + obj.attr("id"));
1044				});
1045				_jq("#imCartUserFormSubmit").unbind("click").click(function () {
1046					x5engine.imCart.sendOrderEmail('#' + obj.attr("id"));
1047				});
1048			});
1049
1050		} else _jq("#imCartUserFormSubmit").attr("disabled", false);
1051	},
1052
1053	// Send the email and shows the payment
1054	sendOrderEmail: function (obj) {
1055		_jq("#imCartUserFormSubmit").attr("disabled", true);
1056		if (x5engine.imCart.email_data.order_no == null || x5engine.imCart.email_data.order_no == "") x5engine.imCart.email_data.order_no = x5engine.imCart._createOrderNo();
1057		var pid = x5engine.imCart._getPayment();
1058		if (x5engine.imCart.payments[pid].html != null) x5engine.imCart.email_data.payment.html = x5engine.imCart._createPaymentHtml(x5engine.imCart.payments[pid].html);
1059		if (x5engine.utils.isOnline()) {
1060			_jq("#imCartUserFormSubmit").val(x5engine.l10n.getLocalization('cart_order_process')).css({
1061				cursor: "wait"
1062			});
1063			_jq("#imCartButtonBack").remove();
1064			_jq.ajax({
1065				type: "POST",
1066				url: x5engine.imCart.settings.post_url,
1067				data: x5engine.imCart.email_data,
1068				success: function (a) {
1069					x5engine.imCart.showPayment(obj);
1070				},
1071				error: function (XMLHttpRequest, textStatus, errorThrown) {
1072					x5engine.imCart.showPayment(obj);
1073				}
1074			});
1075		} else {
1076			x5engine.utils.showOfflineMessage(x5engine.l10n.getLocalization('cart_err_offline_email').replace(/\[MAIL\]/g, x5engine.imCart.email_data.form.imCartEmail.imValue));
1077			x5engine.imCart.showPayment(obj);
1078		}
1079	},
1080
1081	// Shows the payment method
1082	showPayment: function (obj) {
1083		var payment = x5engine.imCart.payments[x5engine.imCart._getPayment()];
1084		_jq(obj).empty().prepend("<h2 id=\"imPgTitle\" class=\"imTitleMargin\">" + x5engine.l10n.getLocalization('cart_step5') + "</h2>");
1085		var html = "<p>" + x5engine.l10n.getLocalization('cart_step5_descr') + "</p>";
1086		html += "<div id=\"imCartOrderNumber\">" + x5engine.imCart.email_data.order_no + "</div>";
1087		html += "<p><b>" + payment.name + "</b><br />" + payment.description + "<br /><br />";
1088		html += payment.email + "</p>";
1089
1090		if (payment.html != null) {
1091			html += "<br /><br /><div style=\"text-align: center\">" + x5engine.imCart._createPaymentHtml(payment.html) + "</div>";
1092		}
1093
1094		_jq(obj).fadeOut(100, function () {
1095			_jq(obj).append(html).fadeIn(100, function () {
1096				x5engine.imCart.emptyCart(false);
1097				x5engine.imCart.email_data = null;
1098				x5engine.imCart._setShipping(null);
1099				x5engine.imCart._setPayment(null);
1100				_jq("#imContent").triggerHandler("change");
1101			});
1102		});
1103	},
1104
1105	// Update the shipping type and price
1106	updateShipping: function (n, total_quantity, total_weight) {
1107		x5engine.imCart._setShipping(n);
1108		x5engine.imCart.updateTotalPrice(total_quantity, total_weight);
1109	},
1110
1111	// Update the payment type and the price
1112	updatePayment: function (n, total_quantity, total_weight) {
1113		x5engine.imCart._setPayment(n);
1114		x5engine.imCart.updateTotalPrice(total_quantity, total_weight);
1115	},
1116
1117	// Update the total price
1118	updateTotalPrice: function (total_quantity, total_weight) {
1119		var price = x5engine.imCart.product_price_plus_vat;
1120		var pid;
1121		var sid;
1122		var shipping_price = 0;
1123		var payment_price = 0;
1124		x5engine.imCart.email_data.total_quantity = total_quantity;
1125		x5engine.imCart.email_data.total_weight = total_weight;
1126		if (x5engine.imCart._getShipping() != null) {
1127			sid = x5engine.imCart._getShipping();
1128			shipping_price += x5engine.imCart._getShippingPrice(x5engine.imCart.shippings[sid], x5engine.imCart.product_price_plus_vat, total_quantity, total_weight) * 1;
1129			x5engine.imCart.email_data.shipping = {
1130				id: sid,
1131				price: x5engine.imCart._setCurrency(shipping_price),
1132				name: x5engine.imCart.shippings[sid].name,
1133				description: x5engine.imCart.shippings[sid].description,
1134				email: x5engine.imCart.shippings[sid].email
1135			};
1136			if (shipping_price == 0) {
1137				x5engine.imCart.email_data.shipping.price = null;
1138			}
1139		}
1140		if (x5engine.imCart._getPayment() != null) {
1141			pid = x5engine.imCart._getPayment();
1142			if (x5engine.imCart.payments[pid].price != null) {
1143				payment_price += x5engine.imCart.payments[pid].price;
1144				if (x5engine.imCart.payments[pid].vat != null) payment_price += x5engine.imCart.payments[pid].price * x5engine.imCart.payments[pid].vat;
1145			}
1146			x5engine.imCart.email_data.payment = {
1147				id: pid,
1148				price: x5engine.imCart._setCurrency(payment_price),
1149				name: x5engine.imCart.payments[pid].name,
1150				description: x5engine.imCart.payments[pid].description,
1151				email: x5engine.imCart.payments[pid].email
1152			};
1153			if (x5engine.imCart.payments[pid].html != null) x5engine.imCart.email_data.payment.html = x5engine.imCart._createPaymentHtml(x5engine.imCart.payments[pid].html);
1154			if (payment_price == 0) {
1155				x5engine.imCart.email_data.payment.price = null;
1156			}
1157		}
1158		price += shipping_price + payment_price;
1159		x5engine.imCart.email_data.total = x5engine.imCart._setCurrency(price);
1160		x5engine.imCart.email_data.clear_total = price;
1161		_jq("#imDivTotalPrice").html(x5engine.imCart._setCurrency(price));
1162		x5engine.imCart.total_price = price;
1163	}
1164});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.