PageSourceSearch

https://www.viart.com/js/shopping.js?2025-03-04

js viart.com collected 2026-10-01 05:30:37 UTC 61,027 bytes, 1,718 lines download raw bytes

1// shopping javacript
2function reloadCartBlocks(responseData) {
3	if (typeof responseData === 'string') {
4		try { 
5			responseData = JSON.parse(responseData); 
6		} catch(e){
7			alert("Bad response: " + responseData);
8			console.log("Bad response: " + responseData);
9		}
10	}
11	var cart = responseData.cart; // check action: COMPARE / ADD / WISHLIST
12	var controlId = responseData.control_id; // cartParams[0];
13	var isErrors = (responseData.errors && responseData.errors != "");
14	if (controlId) { vaStopSpin(controlId);	}
15	
16	if (cart == "ADD") {
17		// check items indexes to show 'in cart' message
18		if (responseData.added_indexes) {
19			for (itemIndex in responseData.added_indexes) {
20				var inCartObj = document.querySelector("#in-cart"+itemIndex);
21				if (inCartObj) {
22					inCartObj.className = inCartObj.className.replace(/hidden-block/gi, "").trim();
23				}
24			}
25		}
26		// check items indexes to hide 'add to cart' button
27		if (responseData.hide_add_indexes) {
28			for (itemIndex in responseData.hide_add_indexes) {
29				var inCartObj = document.querySelector("#add"+itemIndex);
30				if (inCartObj) {
31					inCartObj.className += " hidden-block";
32				}
33			}
34		}
35	}
36
37	// set all quantity controls to zero if multi-add active
38	var multiAdd = 0; var itemsForm;
39	if (responseData.form_name) { itemsForm = document.forms[responseData.form_name];	}
40	if (itemsForm && itemsForm.multi_add) {
41		multiAdd = itemsForm.multi_add.value;
42	}
43	if (multiAdd == 1 && itemsForm.items_indexes && itemsForm.items_indexes.value != "") {
44		var indexes = itemsForm.items_indexes.value.split(",");
45		for (var i = 0; i < indexes.length; i++) {
46			var idx = indexes[i];
47			var controlName = "quantity" + idx;
48			if (itemsForm.elements[controlName]) {
49				var elementType = itemsForm.elements[controlName].type;
50				if (elementType == "text") {
51					itemsForm.elements[controlName].value = 0;
52				} else if (elementType == "select-one") {
53					itemsForm.elements[controlName].selectedIndex = 0;
54				}
55			}
56		}
57	}
58
59	if ((cart == "ADD" || cart == "QTY" || cart == "CLR" || cart == "RM") && !isErrors) {
60		var carts = document.querySelectorAll("[data-type='cart']");
61		for (var c = 0; c < carts.length; c++) {
62			var cartBlock = carts[c];	
63			if ((cartBlock.id || cartBlock.hasAttribute("data-id")) && cartBlock.hasAttribute("data-pb-id")) {
64				var pbId = cartBlock.getAttribute("data-pb-id");
65				var blockParentId = cartBlock.getAttribute("data-parent-id");
66				if (!blockParentId) { blockParentId = cartBlock.getAttribute("data-block-parent-id"); }
67				if (!blockParentId) { blockParentId = "pb_"+pbId; }
68				vaSpin(blockParentId);
69				reloadBlock(pbId, blockParentId, "pb_type=cart");
70			}
71		}
72		if (window.opener) { 
73			try {
74				var carts = window.opener.document.querySelectorAll("[data-type='cart']");
75				for (var c = 0; c < carts.length; c++) {
76					var cartBlock = carts[c];	
77					if ((cartBlock.id || cartBlock.hasAttribute("data-id")) && cartBlock.hasAttribute("data-pb-id")) {
78						var blockId = (cartBlock.hasAttribute("data-id")) ? cartBlock.getAttribute("data-id") : cartBlock.id;
79						var pbId = cartBlock.getAttribute("data-pb-id");
80						window.opener.vaSpin(blockId);
81						window.opener.reloadBlock(pbId, blockId, "pb_type=cart");
82					}
83				}
84			} catch(e){
85				//catch error 'Access Denied'
86			}
87		}
88	}
89
90	if (responseData.scripts) {
91		vaScripts(responseData.scripts);
92	}
93
94	if (responseData.block && responseData.block != "") {
95		// show cart message or block
96		showPopupFrame(responseData.block);
97	} else if (responseData.errors && responseData.errors != "") {
98		showMessageBlock(responseData.errors, controlId);
99	} else if (responseData.success == 1) {
100		if (responseData.message && responseData.message != "") {
101			showMessageBlock(responseData.message, controlId);
102		}
103	}
104
105}
106
107function confirmBuy(formName, selectedIndex, buttonType, controlId)
108{
109	var itemsForm;
110	if (formName instanceof HTMLElement) {
111		var buttonObj = formName;
112		formName = viartDataParam(buttonObj, ["form", "form-name", "formname"]);
113		if (!formName) {
114			itemsForm = vaParent(buttonObj, "FORM");
115			formName = itemsForm.name;
116		}
117		selectedIndex = viartDataParam(buttonObj, ["index", "item-index", "product-index"]);
118		buttonType = viartDataParam(buttonObj, ["button-type", "type"]);
119		controlId = viartDataParam(buttonObj, ["control-id", "message-control"]);
120		if (!controlId) {
121			if (!buttonObj.id) {
122				buttonObj.id = "id_"+Date.now().toString()+"_"+Math.random().toString().replace("0.",""); // generate unique id
123			}
124			controlId = buttonObj.id;
125		}
126	}
127
128	if (controlId && buttonType != "shipping") { 
129		// show spin until response won't be received
130		vaSpin(controlId);	
131	}
132	var scParams = safeJsonParse(formName, "sc_params");
133	var msgRequiredProperty = (scParams["msgRequiredProperty"]) ? scParams["msgRequiredProperty"]: "Please specify {property_name} for {product_name}!";
134	var msgMinMax = (scParams["msgMinMax"]) ? scParams["msgMinMax"] : "Please enter a value between {min_value} and {max_value}.";
135	var msgAddProduct = (scParams["msgAddProduct"]) ? scParams["msgAddProduct"] : "Add this product to your Shopping Cart?";
136	var msgSelectProduct = (scParams["msgSelectProduct"]) ? scParams["msgSelectProduct"] : "Please select at least one product first.";
137	var confirmAdd = (scParams["confirmAdd"]) ? scParams["confirmAdd"] : 1;
138
139	var itemsForm = document.forms[formName];
140	var siteUrl = (itemsForm.site_url) ? itemsForm.site_url.value : "";
141	if (itemsForm.item_index) {
142		itemsForm.item_index.value = selectedIndex; // assign index of product to be added to cart
143	} else {
144		addFormHidden(itemsForm, "item_index", selectedIndex);
145	}
146
147	var startIndex = 1;
148	if (itemsForm.start_index) {
149		startIndex = itemsForm.start_index.value;
150	}
151	var idx = selectedIndex;
152	// check and add cart redirect option
153	var redirectToCart = "3"; // 
154	if (itemsForm.redirect_to_cart) {
155		redirectToCart = itemsForm.redirect_to_cart.value;
156	} else {
157		addFormHidden(itemsForm, "redirect_to_cart", redirectToCart);
158	}
159	// add cart,form_name,control_id parameters if they doesn't exists
160	if (!itemsForm.cart) { addFormHidden(itemsForm, "cart", "ADD"); }
161	if (!itemsForm.form_name) { addFormHidden(itemsForm, "form_name", formName); } 
162	if (!itemsForm.control_id) {
163		addFormHidden(itemsForm, "control_id", controlId);
164	} else {
165		itemsForm.control_id.value = controlId;
166	}
167
168	if (buttonType == "wishlist") {
169		itemsForm.cart.value = "WISHLIST";
170	} else if (buttonType == "shipping") {
171		itemsForm.cart.value = "SHIPPING";
172	} else if (buttonType == "SHIPPINGADD" || buttonType == "CHECKOUT" || buttonType == "GOTOCHECKOUT") {
173		itemsForm.cart.value = buttonType;
174	} else if (buttonType == "compare") {
175		itemsForm.cart.value = "COMPARE";
176	} else if (buttonType == "options") {
177		itemsForm.cart.value = "OPTIONS";
178	} else {
179		itemsForm.cart.value = "ADD";
180	}
181
182	if (itemsForm.originalAction) {
183		itemsForm.target = "";
184		itemsForm.action = itemsForm.originalAction;
185	}
186	// check initial index if it wasn't selected
187	var indexes = new Array();
188	if (!itemsForm.elements["item_id"+idx]) {
189		if (itemsForm.items_indexes && itemsForm.items_indexes.value != "") {
190			indexes = itemsForm.items_indexes.value.split(",");
191			idx = indexes[0];
192		} else {
193			idx = startIndex;
194		}
195	}
196
197	// check products one by one
198	var selectedItems = 0;
199	var itemNo = 0;
200	do {
201		itemNo++;
202
203		// check product quantity
204		var quantity = 1;
205		if (itemsForm.elements["quantity"+idx]) {
206			if (itemsForm.elements["quantity"+idx].selectedIndex) {
207				quantity = parseInt(itemsForm.elements["quantity"+idx].options[itemsForm.elements["quantity"+idx].selectedIndex].value);
208			} else {
209				quantity = parseInt(itemsForm.elements["quantity"+idx].value);
210			}
211			if (isNaN(quantity)) { quantity = 1; } 
212		}
213
214		if (quantity > 0) {
215			selectedItems++;
216			var productData = getProductData(itemsForm, idx);
217			var params = productData;
218			var basePrice = params["base_price"];
219			// check what options were selected and what options is active
220			var returnedValues = checkOptions(itemsForm, idx);
221			var selectedOptions = returnedValues[0];
222			var activeOptions = returnedValues[1];
223			// check options for requirements
224			var prMessage = msgRequiredProperty;
225	
226			var productName = params["item_name"];
227			for (prID in activeOptions) {
228				if (itemsForm.elements["property_control"+idx+"_" + prID]) { // check if it is property control
229					var prRequired = itemsForm.elements["property_required"+idx+"_" + prID].value;
230					var prControl = itemsForm.elements["property_control"+idx+"_" + prID].value;
231					if (prRequired == 1 && activeOptions[prID] && !selectedOptions[prID]) {
232						var propertyName = itemsForm.elements["property_name"+idx+"_" + prID].value;
233						prMessage = prMessage.replace("\{property_name\}", propertyName);
234						prMessage = prMessage.replace("\{product_name\}", productName);
235						alert(prMessage);   
236						if (controlId) { vaStopSpin(controlId);	}
237						if (prControl == "WIDTH_HEIGHT") {
238							if (!itemsForm.elements["property_width"+idx+"_" + prID].value) {
239								itemsForm.elements["property_width"+idx+"_" + prID].focus();
240							} else {
241								itemsForm.elements["property_height"+idx+"_" + prID].focus();
242							}
243						} else if (prControl != "RADIOBUTTON" && prControl != "CHECKBOXLIST" && prControl != "TEXTBOXLIST" && prControl != "LABEL") {
244							itemsForm.elements["property"+idx+"_" + prID].focus();
245						}
246						return false;
247					}
248				}
249			}
250
251			// check for width & height control if data correct
252			for (prID in activeOptions) {
253				if (itemsForm.elements["property_control"+idx+"_" + prID]) { // check if it is property control
254					var prControl = itemsForm.elements["property_control"+idx+"_" + prID].value;
255					if (prControl == "WIDTH_HEIGHT") {
256						var widthValue = itemsForm.elements["property_width"+idx+"_" + prID].value;
257						var heightValue = itemsForm.elements["property_height"+idx+"_" + prID].value;
258						if (widthValue != "" || heightValue != "") {
259							widthValue = parseFloat(widthValue);
260							if (isNaN(widthValue)) { widthValue = 0; }
261							heightValue = parseFloat(heightValue);
262							if (isNaN(heightValue)) { heightValue = 0; }
263							var prices = productData["options"][prID]["prices"]; 
264							var minWidth; var maxWidth; var minHeight; var maxHeight;
265							for (var curWidth in prices) {
266								curWidth = parseFloat(curWidth);
267								if (minWidth > curWidth || minWidth === undefined) { minWidth = curWidth; }
268								if (maxWidth < curWidth || maxWidth === undefined) { maxWidth = curWidth; }
269								for (var curHeight in prices[curWidth]) {
270									curHeight = parseFloat(curHeight);
271									if (minHeight > curHeight || minHeight === undefined) { minHeight= curHeight; }
272									if (maxHeight < curHeight || maxHeight === undefined) { maxHeight = curHeight; }
273								}
274							}
275						  //*
276							if (widthValue < minWidth || widthValue > maxWidth) {
277								var msg = msgMinMax.replace("\{min_value\}", minWidth);
278								msg = msg.replace("\{max_value\}", maxWidth);
279								alert(msg);
280								itemsForm.elements["property_width"+idx+"_" + prID].focus();
281								if (controlId) { vaStopSpin(controlId);	}
282								return false;
283							}
284							if (heightValue < minHeight|| heightValue > maxHeight) {
285								var msg = msgMinMax.replace("\{min_value\}", minHeight);
286								msg = msg.replace("\{max_value\}", maxHeight);
287								alert(msg);
288								itemsForm.elements["property_height"+idx+"_" + prID].focus();
289								if (controlId) { vaStopSpin(controlId);	}
290								return false;
291							}//*/
292						}
293					}
294				}
295			}
296
297	  
298			// calculate price for selected options
299			var propertiesPrice = calculateOptionsPrice(itemsForm, idx, selectedOptions);
300			var isPriceEdit = params["pe"];
301			var productPrice = 0;
302			if (typeof(isPriceEdit) != "undefined" && isPriceEdit) {
303				var userPrice = parseFloat(itemsForm.elements["price"+idx].value);
304				productPrice = userPrice + params["comp_price"] + propertiesPrice;
305			} else {
306				productPrice = basePrice + params["comp_price"] + propertiesPrice;
307			}
308	  
309			if (params["zero_product_action"] == 2 && productPrice == 0) {
310				alert(params["zero_product_warn"]);
311				return false;
312			}
313		}
314
315		// check next index
316		idx = "";
317		if (selectedIndex == "") {
318			var nextIndex = "";
319			if (indexes.length > 0) {
320				nextIndex = (indexes.length > itemNo) ? indexes[itemNo] : "";
321			} else {
322				nextIndex = startIndex + itemNo;
323			}
324			if (nextIndex != "" && itemsForm.elements["item_id"+nextIndex]) {
325				idx = nextIndex;
326			}
327		}
328		// end index check
329		
330	} while (idx != "");
331
332
333  // submit form
334	if (buttonType == "wishlist") {
335		// add to wishlist with Ajax only
336		itemsForm.rnd.value = ""; // don't need random values for AJAX
337		var postParams = {"cms_index": vaCMSIndex()};
338		vaAjaxPost(siteUrl+"cart_add.php", reloadCartBlocks, "", itemsForm, postParams);
339		return false;
340	} else if (buttonType == "shipping") {
341		popupShippingFrame();
342		itemsForm.originalAction = itemsForm.action; // save original action value
343		itemsForm.action = "shipping_calculator.php?form_name="+encodeURIComponent(formName)+"&selected_index="+encodeURIComponent(selectedIndex)+"&control_id="+encodeURIComponent(controlId);
344		itemsForm.target = "shipping_frame";
345		itemsForm.submit();
346		return false;
347	} else if (buttonType == "CHECKOUT" || buttonType == "SHIPPINGADD") {
348		// for checkout process we don't need to confirm purchase
349		itemsForm.submit();
350		return false;
351	} else if (buttonType == "compare" || buttonType == "COMPARE") {
352		if (redirectToCart == "3" || redirectToCart == "ajax" || redirectToCart == "popup") {
353			itemsForm.rnd.value = ""; // don't need random values for AJAX
354			var postParams = {"cms_index": vaCMSIndex()};
355			vaAjaxPost(siteUrl+"cart_add.php", reloadCartBlocks, "", itemsForm, postParams);
356		} else {
357			itemsForm.submit();
358		}
359		return false;
360	} else {
361		if (selectedItems > 0) {
362			// check and submit form to add product to the cart
363			var submitForm = true;
364			if (buttonType == "cart" && confirmAdd == "1") {
365				submitForm = confirm(msgAddProduct);
366			}
367			if (submitForm) {
368				if (redirectToCart == "3" || redirectToCart == "ajax" || redirectToCart == "popup") {
369					// AJAX option selected
370					submitForm = false; // don't need to submit form
371					if (itemsForm.rnd) {
372						itemsForm.rnd.value = ""; // don't need random values for AJAX
373					}
374					//var cartParams = new Array(controlId, formName);
375					var postParams = {"cms_index": vaCMSIndex()};
376					vaAjaxPost(siteUrl+"cart_add.php", reloadCartBlocks, "", itemsForm, postParams);
377				} else {
378					itemsForm.submit();
379				}
380			} else {
381				if (controlId) { vaStopSpin(controlId);	}
382			}
383		} else {
384			if (controlId) { vaStopSpin(controlId);	}
385			alert(msgSelectProduct);
386		}
387		return false;
388	}
389}
390
391
392function cartItemRemoveMode(buttonObj)
393{
394	var cartItemObj = vaParent(buttonObj, "data-type", "cart-item");
395	if (cartItemObj) {
396		var itemMode = cartItemObj.getAttribute("data-mode");
397		if (itemMode == "remove") {
398			cartItemObj.removeAttribute("data-mode");
399		} else {
400			cartItemObj.setAttribute("data-mode", "remove");
401		}
402	}
403}
404
405function cartItemRemove(buttonObj)
406{
407	var cartItemObj = vaParent(buttonObj, "data-type", "cart-item");
408	if (cartItemObj) {
409		var cartItemIndex = cartItemObj.getAttribute("data-cart-item-id");
410		var postParams = {"cart": "RM", "cart_id": cartItemIndex, "cart_item_id": cartItemIndex};
411		vaAjaxPost("cart_add.php", reloadCartBlocks, "", null, postParams);
412	}
413}
414
415function cartItemQtyChange(controlObj)
416{
417	var cartItemObj = vaParent(controlObj, "data-type", "cart-item");
418	if (cartItemObj) {
419		var cartItemIndex = cartItemObj.getAttribute("data-cart-item-id");
420		var newQuantity = controlObj.value;
421		var postParams = {"cart": "QTY", "cart_id": cartItemIndex, "cart_item_id": cartItemIndex, "new_quantity": newQuantity};
422		vaAjaxPost("cart_add.php", reloadCartBlocks, "", null, postParams);
423	}
424}
425
426function cartItemQtyKey(e, controlObj)
427{
428	if (e.key == "Enter") {
429		cartItemQtyChange(controlObj);
430		return false;
431	} else {
432		return true;
433	}
434}
435
436
437function fastAdd(formName, controlId)
438{
439	var itemsForm = document.forms[formName];
440	// check global redirect option
441	var redirectToCart = "";
442	if (itemsForm.redirect_to_cart) {
443		redirectToCart = itemsForm.redirect_to_cart.value;
444	}
445	if (!itemsForm.form_name) { addFormHidden(itemsForm, "form_name", formName); } 
446	if (!itemsForm.control_id) {
447		addFormHidden(itemsForm, "control_id", controlId);
448	} else {
449		itemsForm.control_id.value = controlId;
450	}
451
452	// check and submit form to add product to the cart
453	if (redirectToCart == "3" || redirectToCart == "ajax" || redirectToCart == "popup") {
454		// AJAX option selected
455		if (itemsForm.rnd) {
456			itemsForm.rnd.value = ""; // don't need random values for AJAX
457		}
458		//var cartParams = new Array(controlId, formName);
459		var postParams = {"cms_index": vaCMSIndex()};
460		vaAjaxPost("cart_add.php", reloadCartBlocks, "", itemsForm, postParams);
461	} else {
462		itemsForm.submit();
463	}
464	return false;
465}
466
467function removeCartItem(cartId, pdId)
468{
469	var cartParams = new Array();
470	cartParams["blockParams"] = new Array();
471	cartParams["blockParams"]["active_pb_id"] = pdId;
472	var url = "cart_add.php?cart=RM&cart_id="+encodeURIComponent(cartId);
473	callAjax(url, reloadCartBlocks, cartParams);
474}
475
476function widgetCall(widgetAction, itemId, controlId, formName, itemIndex)
477{
478	if (controlId) { vaSpin(controlId);	}
479
480	var urlObj = document.getElementById(formName+"site_url");
481	var siteUrl = (urlObj) ? urlObj.value : "";
482	var qtyObj = document.getElementById("quantity"+formName+"_"+itemIndex);
483	var qty = 1;
484	if (qtyObj && qtyObj.value) {
485		qty = qtyObj.value;
486		if (isNaN(qty)) { qty = 1; }
487	}
488
489	var cartAddedPopup = 1;
490	var cartPopupView = 1;
491	var cartPopupCheckout = 1;
492
493	var cartUrl = siteUrl+"cart_add.php";
494	cartUrl += "?cart=" + encodeURIComponent(widgetAction);;
495	cartUrl += "&redirect_to_cart=3";
496	cartUrl += "&item_id=" + encodeURIComponent(itemId);
497	cartUrl += "&quantity=" + encodeURIComponent(qty);
498	cartUrl += "&form_name=" + encodeURIComponent(formName);
499	cartUrl += "&control_id=" + encodeURIComponent(controlId);
500	cartUrl += "&cart_added_popup=" + encodeURIComponent(cartAddedPopup);
501	cartUrl += "&cart_popup_view=" + encodeURIComponent(cartPopupView);
502	cartUrl += "&cart_popup_checkout=" + encodeURIComponent(cartPopupCheckout);
503	cartUrl += "&callback=reloadCartBlocks";
504
505	// check page language to use it for widget
506	var metaObj = document.querySelector("meta[http-equiv='Content-Language']")
507	if (metaObj) {
508		var languageCode = metaObj.getAttribute("content");
509		cartUrl += "&language_code="+ encodeURIComponent(languageCode);
510	}
511
512	var script = document.createElement('script');
513	script.type = 'text/javascript';
514	script.src = cartUrl;
515	document.getElementsByTagName("head")[0].appendChild(script);
516	return false;
517}
518
519function confirmSubscription(itemForm)
520{
521	var scParams = safeJsonParse(formName, "sc_params");
522	var msgAddSubscription = (scParams["msgAddSubscription"]) ? scParams["msgAddSubscription"] : "Add this subscription to your Shopping Cart?";
523	var confirmAdd = (scParams["confirmAdd"]) ? scParams["confirmAdd"] : 1;
524
525	if (confirmAdd == "1") {
526		return confirm(msgAddSubscription);
527	} else {
528		return true;
529	}
530}
531
532function addToWishlist()
533{
534	var formName = document.saved_types.form_name.value;
535	if (formName != "") {
536		var itemsForm = document.forms[formName];
537		var typesForm = document.saved_types;
538		var typesTotal = parseInt(document.saved_types.saved_types_total.value);
539		var typeId = "";
540		if (typesTotal > 1) {
541			typeId = document.saved_types.type_id.options[document.saved_types.type_id.selectedIndex].value;
542		} else {
543			typeId = (document.saved_types.type_id) ? document.saved_types.type_id.value : 0; 
544		}
545		if (typeId === "") {
546			alert("Please select a type");
547		} else {
548			var controlId = "";
549			if (itemsForm.control_id) {
550				controlId = itemsForm.control_id.value;
551			}
552			itemsForm.saved_type_id.value = typeId;
553			var itemIndex = typesForm.item_index.value;
554			hideWishlistTypes();
555			confirmBuy(formName, itemIndex, "wishlist", controlId);
556		}
557	} else {
558		alert("Error: can't find formName parameter.");
559	}
560}
561
562function popupShippingWin(shippingUrl)
563{
564	var shippingWin = window.open (shippingUrl, 'shippingWin', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=600,height=400');
565	shippingWin.focus();
566}
567
568function popupShippingFrame(itemForm)
569{							   
570	var shippingOpacity = document.getElementById("shipping_opacity");
571	shippingOpacity.style.opacity	= "0.6";
572	shippingOpacity.style.mozOpacity = "0.6";
573	shippingOpacity.style.filter	 = "alpha(opacity=60)";
574	var shippingShadow = document.getElementById("shipping_shadow");
575
576	var pageSize = getPageSize();
577	var pageScroll = getScroll();
578	var arrayPageSizeWithScroll = getPageSizeWithScroll();
579
580	var winLeft = 5; var winTop = 5;
581	if (pageSize[0] > 620) {
582		winLeft = pageScroll[0] + (pageSize[0]-600) / 2;
583	}
584	if (pageSize[1] > 420) {
585		winTop = pageScroll[1] + (pageSize[1]-400) / 2;
586	}
587	shippingShadow.style.left = winLeft + "px";
588	shippingShadow.style.top = winTop + "px";
589
590	shippingOpacity.style.width = arrayPageSizeWithScroll[0] + "px";
591	shippingOpacity.style.height = arrayPageSizeWithScroll[1] + "px";
592
593	shippingShadow.style.display = "block";		 
594	shippingOpacity.style.display = "block";			
595}
596
597function addFormHidden(formObj, hiddenName, hiddenValue)
598{
599	var inputObj = document.createElement('input');
600	inputObj.type = "hidden";
601	inputObj.name = hiddenName;
602	inputObj.value = hiddenValue;
603	formObj.appendChild(inputObj);
604}
605
606function hideShippingFrame()
607{							   
608	var shippingOpacity = document.getElementById("shipping_opacity");
609	var shippingShadow = document.getElementById("shipping_shadow");
610	var shippingPage = document.getElementById("shipping_page");
611
612	shippingOpacity.style.display = "none";		 
613	shippingShadow.style.display = "none";		  
614	shippingPage.src = "";
615}
616
617function optionImageSelect(formName, idx, optionId, newValueId)
618{
619	var itemsForm = document.forms[formName];
620	var viewType = itemsForm.type.value;
621	var productData = getProductData(itemsForm, idx);
622	var optionValues = productData["options"][optionId]["values"];
623	var valueData = productData["options"][optionId]["values"][newValueId];
624	var valueTitle = valueData["value"];
625	var imageSmall = valueData["image_small"];
626	var imageLarge = valueData["image_large"];
627	var imageSuper = valueData["image_super"];
628	var mainImage = (viewType == "details") ? imageLarge : imageSmall;
629	if (mainImage != "") {
630		rolloverImage('option'+newValueId, mainImage, 'image_'+idx, 'super_link_'+idx, imageSuper);
631	}
632	var oldValueId = itemsForm.elements["property"+idx+"_"+optionId].value; // get old value to allow deselect value
633	for (keyId in optionValues) {
634		var imageObj = document.getElementById("option_image"+idx+"_"+keyId);
635		if (keyId == newValueId && keyId != oldValueId) {
636			imageObj.className = 'imageSelected';
637		} else {
638			imageObj.className = 'imageSelect';
639		}
640	}
641	// save id and value title
642	var oldValueId = itemsForm.elements["property"+idx+"_"+optionId].value; // get old value to allow deselect value
643	if (newValueId == oldValueId) {
644		itemsForm.elements["property"+idx+"_"+optionId].value = "";
645	} else {
646		itemsForm.elements["property"+idx+"_"+optionId].value = newValueId;
647	}
648	var valueObj = document.getElementById("optionValue"+idx+"_"+optionId);
649	if (valueObj) {
650		if (newValueId == oldValueId) {
651			valueObj.innerHTML = "";
652		} else {
653			valueObj.innerHTML = valueTitle;
654		}
655	}
656	// property was changed
657	changeProperty(formName, idx);
658}
659
660
661function optionImageShow(formName, idx, optionId, newValueId)
662{
663	var itemsForm = document.forms[formName];
664	var viewType = itemsForm.type.value;
665	var productData = getProductData(itemsForm, idx);
666	try {
667		var optionValues = productData["options"][optionId]["values"];
668		var valueData = productData["options"][optionId]["values"][newValueId];
669		var imageSmall = (typeof valueData["image_small"] === "undefined") ? "" : valueData["image_small"];
670		var imageLarge = (typeof valueData["image_large"] === "undefined") ? "" : valueData["image_large"];
671		var imageSuper = (typeof valueData["image_super"] === "undefined") ? "" : valueData["image_super"];
672		var mainImage = (viewType == "details") ? imageLarge : imageSmall;
673		if (mainImage != "") {
674			rolloverImage('option'+newValueId, mainImage, 'image_'+idx, 'super_link_'+idx, imageSuper);
675		}
676	} catch (e) {}
677}
678
679function optionImagesToggle(idx, optionId)
680{
681
682	var toggleImage = document.getElementById("toggleImage"+idx+"_"+optionId);
683	var imagesBlock = document.getElementById("optionImages"+idx+"_"+optionId);
684	var optionBlock = document.getElementById("pr"+idx+"_"+optionId);
685	if (imagesBlock.className == "optionImages") {
686		toggleImage.src = "images/icons/close.png";
687		imagesBlock.className = "optionImagesOpen";
688		optionBlock.style.border = "1px solid #656565";
689	} else {
690		toggleImage.src = "images/icons/arrow-down.png";
691		imagesBlock.className = "optionImages";
692		optionBlock.style.border = "none";
693	}
694
695}
696
697function changeProperty(formName, idx)
698{
699	var itemsForm = document.forms[formName];
700
701	var selectedOptions = new Array();
702	var priceControl = "";
703	var htmlControl = false;
704	var itemId = itemsForm.elements["item_id"+idx].value;;
705	var taxPercent = 0;
706	var productData = getProductData(itemsForm, idx);
707	var params = productData; // todo: change to productData
708	var taxNote = params["tax_note"];
709	var pointsBase = params["base_points_price"];
710	var prIDs = params["properties_ids"];
711	var formId = params["form_id"];
712	var stockLevel = getParamValue(params, "sl", "int");
713	var useStockLevel = getParamValue(params, "use_sl", "int")
714	var inStock = getParamValue(params, "in_sm", "txt");
715	var outStock = getParamValue(params, "out_sm", "txt")
716
717	if (itemsForm.elements["tax_percent"+idx] && itemsForm.elements["tax_percent"+idx].value != "") {
718		taxPercent = parseFloat(itemsForm.elements["tax_percent"+idx].value);
719		if (isNaN(taxPercent)) { taxPercent = 0; }
720	}
721
722	if (itemId != "" && document.getElementById) {
723		priceControl = document.getElementById("sales_price" + idx);
724		if (!priceControl) {
725			priceControl = document.getElementById("price" + idx);
726		}
727	} 
728	var pointsPriceControl = document.getElementById("points_price" + idx);
729
730	// check what options were selected and what options is active
731	var returnedValues = checkOptions(itemsForm, idx);
732	var selectedOptions = returnedValues[0];
733	var activeOptions = returnedValues[1];
734	// calculate price for selected options
735	var totalAdditionalPrice = calculateOptionsPrice(itemsForm, idx, selectedOptions);
736
737	// check stock levels for options
738	var optionUseStock = 0; var optionStockLevel = 0; 
739	for (prID in selectedOptions) {
740		if (itemsForm.elements["property_control"+idx+"_" + prID]) { // check if it is property control
741			var prControl = itemsForm.elements["property_control"+idx+"_" + prID].value;
742			if (prControl == "LISTBOX" || prControl == "RADIOBUTTON") {
743				optionUseStock = getOptionValue(itemsForm, "use_sl_" + selectedOptions[prID]);
744				if (optionUseStock == 1) {
745					optionStockLevel = getOptionValue(itemsForm, "sl_" + selectedOptions[prID]);
746					if (useStockLevel == 0 || stockLevel > optionStockLevel) {
747						stockLevel = optionStockLevel;
748						useStockLevel = 1;
749					}
750				}
751			} else if (prControl == "CHECKBOXLIST" || prControl == "TEXTBOXLIST") {
752				var values = selectedOptions[prID];
753				for (valueId in values) {
754					optionUseStock = getOptionValue(itemsForm, "use_sl_" + valueId);
755					if (optionUseStock == 1) {
756						optionStockLevel = getOptionValue(itemsForm, "sl_" + valueId);
757						if (useStockLevel == 0 || stockLevel > optionStockLevel) {
758							stockLevel = optionStockLevel;
759							useStockLevel = 1;
760						}
761					}
762				}   
763			}
764		}
765	}
766	// end options stock levels
767
768	// change stock level and stock message
769	var obj = document.getElementById("sl" + idx);
770	var blockObj = document.getElementById("block_sl" + idx);
771	if (obj) {
772		if (useStockLevel == 1) {
773			obj.innerHTML = stockLevel;
774			if (blockObj) { blockObj.style.display = "block"; }
775		} else {
776			obj.innerHTML = "";
777			if (blockObj) { blockObj.style.display = "none"; }
778		}
779	}
780	obj = document.getElementById("sm" + idx);
781	blockObj = document.getElementById("block_sm" + idx);
782	if (obj) {
783		var stockMessage = "";
784		if (useStockLevel == 0 || stockLevel > 0) {
785			stockMessage = inStock;
786		} else {
787			stockMessage = outStock;
788		}
789		obj.innerHTML = stockMessage;
790		if (blockObj) { 
791			if (stockMessage == "") {
792				blockObj.style.display = "none";
793			} else {
794				blockObj.style.display = "block"; 
795			}
796		}
797	}
798
799	// hide or show property blocks
800	for (prID in activeOptions) {
801		if (itemsForm.elements["property_control" + idx + "_" + prID]) { // check if it is property control
802			var propertyBlock = document.getElementById("pr" + idx + "_" + prID);
803			if (propertyBlock) { // custom HTML code in table view may not have it
804				if (activeOptions[prID]) {
805					propertyBlock.style.display = "block";			  
806				} else {
807					propertyBlock.style.display = "none";			   
808				}
809			}
810		}
811	}
812
813	// show hide image for subcomponents and update main image if it was set for option
814	for (prID in activeOptions) {
815		if (itemsForm.elements["property_control"+idx+"_" + prID]) { // check if it is property control
816			var prControl = itemsForm.elements["property_control"+idx+"_" + prID].value;
817			if (activeOptions[prID] && (prControl == "LISTBOX" || prControl == "RADIOBUTTON")) {
818				var prValue = selectedOptions[prID];
819
820				optionImageShow(formName, idx, prID, prValue); // check main image for update
821	  
822				var objId = formId + "_" + prID; // id for current product option
823				if (prValue != "") {
824					var image_button = document.getElementById("option_image_action"+idx+"_" + prID);
825					if (!image_button) {
826						var image_button	   = document.createElement('a');			   
827						image_button.id		= "option_image_action"+idx+"_" + prID;
828						image_button.href	  = "#";
829						image_button.onclick   = popupImage;
830						image_button.style.display = "none";
831						image_button.innerHTML = "<img src='images/icons/view_page.gif' alt='View' border='0'/>";
832						var propertyObj = document.getElementById("pr"+idx+"_" + prID);
833						if (propertyObj) { propertyObj.appendChild(image_button); }
834					}			   
835					if (itemsForm.elements["option_image"+idx+"_" + prValue]) {
836						var image = itemsForm.elements["option_image"+idx+"_" + prValue].value;
837						if (itemsForm.elements["option_image_action"+idx+"_" + prValue]) {
838							image_button.onclick = (itemsForm.elements["option_image_action"+idx+"_" + prValue].onclick);
839						}				   
840						image_button.style.display = "inline";
841						image_button.href  = image;
842						image_button.title = itemsForm.elements["property"+idx+"_" + prID].options[itemsForm.elements["property"+idx+"_" + prID].selectedIndex].text;
843					} else {
844						image_button.style.display = "none";
845					}
846				} else {
847					var image_button = document.getElementById("option_image_action"+idx+"_" + prID);
848					if (image_button) {
849						image_button.style.display = "none";
850					}
851				}
852			}
853		}
854	}
855
856	var basePrice = 0;
857	if (params["pe"] == "1") {
858		// get base price from textbox control when price could be edit
859		if (itemsForm.elements["price"+idx]) {
860			basePrice = itemsForm.elements["price"+idx].value;
861			basePrice = basePrice / params["crate"];
862		}
863	} else {
864		basePrice = params["base_price"]; 
865	}
866	var baseTax = 0;
867	// check product quantity
868	var quantity = 1;
869	if (itemsForm.elements["quantity"+idx]) {
870		if (itemsForm.elements["quantity"+idx].selectedIndex) {
871			quantity = parseInt(itemsForm.elements["quantity"+idx].options[itemsForm.elements["quantity"+idx].selectedIndex].value);
872		} else {
873			quantity = parseInt(itemsForm.elements["quantity"+idx].value);
874		}
875		if (isNaN(quantity)) { quantity = 1; } 
876	}
877	var isQuantityPrice = false;
878	if(params["quantity_price"]) { 
879		var prices = params["quantity_price"]; 
880		if (prices != "") {
881			prices = prices.split(",");
882			for (var p = 0; p < prices.length; p = p + 5) {
883				var minQuantity = parseInt(prices[p]);
884				var maxQuantity = parseInt(prices[p + 1]);
885				if (quantity >= minQuantity && quantity <= maxQuantity) {
886					isQuantityPrice = true;
887					basePrice = parseFloat(prices[p + 2]);
888					baseTax = parseFloat(prices[p + 3]);
889					var propertiesDiscount = parseFloat(prices[p + 4]);
890					if (propertiesDiscount > 0) {
891						totalAdditionalPrice -= (Math.round(totalAdditionalPrice * propertiesDiscount) / 100);
892					}
893					break;
894				}
895			}
896		}
897	}
898	
899	var price = basePrice + totalAdditionalPrice;
900	var taxAmount = 0; var productPrice = 0; var taxPrice = 0; var priceExcl = 0;
901	if (params["tax_prices_type"] == 1) {
902		// price already includes tax
903		if (isQuantityPrice) {
904			taxPrice = Math.round((price) * 100) / 100; 
905			// calculate options tax
906			var optionsTax = (Math.round(totalAdditionalPrice * 100) - Math.round(totalAdditionalPrice * 10000 / ( 100 + taxPercent))) / 100; 
907			taxAmount = baseTax + optionsTax; 
908		} else {
909			taxPrice = Math.round((price + params["comp_price"]) * 100) / 100; 
910			taxAmount = (Math.round(price * 100) - Math.round(price * 10000 / ( 100 + taxPercent))) / 100; 
911		}
912		if (isQuantityPrice) {
913			productPrice = Math.round((price - taxAmount) * 100) / 100;
914		} else {
915			productPrice = Math.round((price - taxAmount + params["comp_price"] - params["comp_tax"]) * 100) / 100;
916		}
917		priceExcl = productPrice;
918	} else {
919		if (isQuantityPrice) {
920			// calculate options tax
921			var optionsTax = Math.round(totalAdditionalPrice * taxPercent) / 100; 
922			taxAmount = baseTax + optionsTax; 
923			productPrice = Math.round((price) * 100) / 100;
924			taxPrice = Math.round((productPrice + taxAmount) * 100) / 100; 
925		} else {
926			taxAmount = Math.round(price * taxPercent) / 100; 
927			productPrice = Math.round((price + params["comp_price"]) * 100) / 100;
928			taxPrice = Math.round((productPrice + taxAmount + params["comp_tax"]) * 100) / 100; 
929		}
930		priceExcl = productPrice;
931	}
932
933	if (params["show_prices"] == 2) {
934		productPrice = taxPrice;
935		taxPrice = priceExcl;
936	} else if (params["show_prices"] == 3) {
937		productPrice = taxPrice;
938	}
939
940	if (priceControl) {
941		if (params["pe"] == "1") {
942			// if user can edit price do nothing
943		} else {
944			if (params["zero_price_type"] != 0 && productPrice == 0) {
945				if (params["zero_price_type"] == 1) { params["zero_price_message"] = ""; }
946				priceControl.innerHTML = params["zero_price_message"];
947			} else {
948				priceControl.innerHTML = params["cleft"] + formatNumber(productPrice * params["crate"], params["cdecimals"], params["cpoint"], params["cseparator"]) + params["cright"];
949			}
950			priceBlockControl = document.getElementById("price_block"+idx);
951			if (priceBlockControl) {
952				if (params["zero_price_type"] == 1 && productPrice == 0) {
953					priceBlockControl.style.display = "none";
954				} else {
955					priceBlockControl.style.display = "block";
956				}
957			}
958		}
959	}
960	taxPriceControl = document.getElementById("tax_price" + idx);
961	if (taxPriceControl) {
962		if (params["zero_price_type"] != 0 && taxPrice == 0) {
963			taxPriceControl.innerHTML = "";
964		} else {
965			if (taxNote != "") { taxNote = " " + taxNote; }
966			taxPriceControl.innerHTML = "(" + params["cleft"] + formatNumber(taxPrice * params["crate"], params["cdecimals"], params["cpoint"], params["cseparator"]) + params["cright"] + taxNote + ")";
967		}
968	}
969	if (pointsPriceControl) {
970		var pointsPrice = 0;
971		if (params["pe"] == "1") {
972			pointsPrice = (basePrice + totalAdditionalPrice) * params["points_rate"];
973		} else {
974			pointsPrice = pointsBase + (totalAdditionalPrice * params["points_rate"]);
975		}
976		pointsPriceControl.innerHTML = formatNumber(pointsPrice, params["points_decimals"]);
977	}
978
979}
980
981function checkOptions(itemsForm, idx)
982{
983	var params = getProductData(itemsForm, idx);
984	var prIDs = params["properties_ids"];
985	var selectedOptions = new Array();
986	var activeOptions = new Array();
987	var returnValues = new Array();
988
989	// first check of all selected options if properties available for the product block
990	if (prIDs && prIDs != "") {
991		var properties = prIDs.split(",");
992		for ( var i = 0; i < properties.length; i++) {
993			var prID = properties[i];
994			var prValue = ""; 
995			if (itemsForm.elements["property_control"+idx+"_" + prID]){  //P
996				var prControl = itemsForm.elements["property_control"+idx+"_" + prID].value;
997			}
998
999			if (prControl == "LISTBOX") {
1000				prValue = itemsForm.elements["property"+idx+"_" + prID].options[itemsForm.elements["property"+idx+"_" + prID].selectedIndex].value;
1001				if (prValue != "") {
1002					selectedOptions[prID] = prValue;
1003				}
1004			} else if (prControl == "RADIOBUTTON") {
1005				var radioControl = itemsForm.elements["property"+idx+"_" + prID];
1006				if (radioControl) { // check if there any active values for radio button available
1007					if (radioControl.length) {
1008						for ( var ri = 0; ri < radioControl.length; ri++) {
1009							if (radioControl[ri].checked) {
1010								prValue = radioControl[ri].value;
1011								break;
1012							}
1013						}
1014					} else {
1015						if (radioControl.checked) {
1016							prValue = radioControl.value;
1017						}
1018					}
1019				}
1020				if (prValue != "") {
1021					selectedOptions[prID] = prValue;
1022				}
1023			} else if (prControl == "CHECKBOXLIST") {
1024				if (itemsForm.elements["property_total"+idx+"_" + prID]) {
1025					var totalOptions = parseInt(itemsForm.elements["property_total"+idx+"_" + prID].value);
1026					for ( var ci = 1; ci <= totalOptions; ci++) {
1027						if (itemsForm.elements["property"+idx+"_" + prID + "_" + ci].checked) {
1028							var checkedValue = itemsForm.elements["property"+idx+"_" + prID + "_" + ci].value;
1029							if (!selectedOptions[prID]) {
1030								selectedOptions[prID] = new Array();
1031							}
1032							selectedOptions[prID][checkedValue] = 1;
1033						}
1034					}
1035				} 
1036			} else if (prControl == "TEXTBOXLIST") {
1037				if (itemsForm.elements["property_total"+idx+"_" + prID]) {
1038					var totalOptions = parseInt(itemsForm.elements["property_total"+idx+"_" + prID].value);
1039					for ( var ci = 1; ci <= totalOptions; ci++) {
1040						if (itemsForm.elements["property"+idx+"_" + prID + "_" + ci].value != "") {
1041							var valueId = itemsForm.elements["property_value"+idx+"_" + prID + "_" + ci].value;
1042							var valueText = itemsForm.elements["property"+idx+"_" + prID + "_" + ci].value;
1043							if (!selectedOptions[prID]) {
1044								selectedOptions[prID] = new Array();
1045							}
1046							selectedOptions[prID][valueId] = valueText;
1047						}
1048					}
1049				} 
1050			} else if (prControl == "LABEL"){
1051				// get from hidden control
1052				if (itemsForm.elements["property"+idx+"_" + prID]) {
1053					prValue = itemsForm.elements["property"+idx+"_" + prID].value;
1054					if (prValue != "") {
1055						selectedOptions[prID] = prValue;
1056					}
1057				}
1058			} else if (prControl == "WIDTH_HEIGHT"){
1059				var widthValue = itemsForm.elements["property_width"+idx+"_" + prID].value;
1060				var heightValue = itemsForm.elements["property_height"+idx+"_" + prID].value;
1061				if (widthValue != "" && heightValue != "") {
1062					selectedOptions[prID] = new Array(); 
1063					selectedOptions[prID]["width"] = widthValue;
1064					selectedOptions[prID]["height"] = heightValue;
1065				}
1066			} else {
1067				// check if property exists on page
1068				prValue = (itemsForm.elements["property"+idx+"_" + prID]) ? itemsForm.elements["property"+idx+"_" + prID].value : "";
1069				if (prValue != "") {
1070					selectedOptions[prID] = prValue;
1071				}
1072			}
1073		}
1074	}
1075
1076	// second check for active options and correct selected options if necessary
1077	if (prIDs && prIDs != "") {
1078		do {
1079			// save how many selected options we have at start
1080			var startSelectedNumber = selectedOptions.length;
1081			// check availability of parent options	 
1082			var properties = prIDs.split(",");
1083			for ( var i = 0; i < properties.length; i++) {
1084				var prID = properties[i];
1085				var prControl = itemsForm.elements["property_control"+idx+"_" + prID].value;
1086				if (itemsForm.elements["property_parent_id"+idx+"_" + prID]){ //P
1087					var parentPropertyId = itemsForm.elements["property_parent_id"+idx+"_" + prID].value;
1088				}			   
1089				if (itemsForm.elements["property_parent_value_id"+idx+"_" + prID]){ //P
1090					var parentValueId = itemsForm.elements["property_parent_value_id"+idx+"_" + prID].value;
1091				}			   
1092				var showProperty = true;
1093				if (parentPropertyId != "") {
1094					if (!selectedOptions[parentPropertyId]) {
1095						showProperty = false;
1096					} else if (parentValueId != "") {
1097						// check parent control
1098						var parentControl = itemsForm.elements["property_control"+idx+"_" + parentPropertyId].value;
1099						// for multi-listing we need to different check of selected value then for single control
1100						if ((parentControl == "CHECKBOXLIST" || parentControl == "TEXTBOXLIST") && !selectedOptions[parentPropertyId][parentValueId]) {
1101							showProperty = false;
1102						} else if (parentControl != "CHECKBOXLIST" && parentControl != "TEXTBOXLIST" && selectedOptions[parentPropertyId] != parentValueId) {
1103							showProperty = false;
1104						}
1105					}
1106				}
1107				activeOptions[prID] = showProperty;
1108				if (!showProperty) {
1109					// delete from selected
1110					if (selectedOptions[prID]) {
1111						delete selectedOptions[prID];
1112					}
1113	  
1114					// clear all options
1115					var prControl = itemsForm.elements["property_control"+idx+"_" + prID].value;
1116					if (prControl == "LISTBOX") {
1117						var selectedIndex = itemsForm.elements["property"+idx+"_" + prID].selectedIndex;
1118						if (selectedIndex > 0) {
1119							itemsForm.elements["property"+idx+"_" + prID].options[0].selected = true;
1120						}
1121					} else if (prControl == "RADIOBUTTON") {
1122						var radioControl = itemsForm.elements["property"+idx+"_" + prID];
1123						if (radioControl) { // check if there any active values for radio button available
1124							if (radioControl.length) {
1125								for ( var ri = 0; ri < radioControl.length; ri++) {
1126									radioControl[ri].checked = false;
1127								}
1128							} else {
1129								radioControl.checked = false;
1130							}
1131						}	  
1132					} else if (prControl == "CHECKBOXLIST") {
1133						var totalOptions = parseInt(itemsForm.elements["property_total"+idx+"_" + prID].value);
1134						for ( var ci = 1; ci <= totalOptions; ci++) {
1135							itemsForm.elements["property"+idx+"_" + prID + "_" + ci].checked = false;
1136						}
1137					} else if (prControl == "TEXTBOXLIST") {
1138						var totalOptions = parseInt(itemsForm.elements["property_total"+idx+"_" + prID].value);
1139						for ( var ci = 1; ci <= totalOptions; ci++) {
1140							// don't erase user or default text in textbox controls
1141							//itemsForm.elements["property"+idx+"_" + prID + "_" + ci].value = "";
1142						}
1143					} else if (prControl == "TEXTBOX" || prControl == "TEXTAREA") {
1144						// don't erase user or default text in textbox controls
1145						//itemsForm.elements["property"+idx+"_" + prID].value = "";
1146					} else if (prControl == "WIDTH_HEIGHT") {
1147					}
1148				}
1149			}
1150		} while (startSelectedNumber != selectedOptions.length);
1151	}
1152
1153	returnValues[0] = selectedOptions;
1154	returnValues[1] = activeOptions;
1155
1156	return returnValues;
1157}
1158
1159function calculateOptionsPrice(itemsForm, idx, selectedOptions)
1160{
1161	var productData = getProductData(itemsForm, idx);
1162	var params = productData; // todo: change to productData
1163	var propertiesPrice = 0;
1164	var prPrice = 0;
1165	for (var prID in selectedOptions) {
1166		if (itemsForm.elements["property_control"+idx+"_" + prID]) { // check if it is property control
1167			prPrice = calculateOptionPrice(itemsForm, idx, selectedOptions, prID, false);
1168			productData["options"][prID]["price"] = prPrice;
1169			propertiesPrice += prPrice;
1170		}
1171	}   
1172
1173	// check if we need to update some option prices
1174	var optionsData = productData["options"];
1175	var nameDelimiter = productData["name_delimiter"];
1176	var positivePriceRight = productData["positive_price_right"];
1177	var positivePriceLeft = productData["positive_price_left"];
1178	var negativePriceRight = productData["negative_price_right"];
1179	var negativePriceLeft = productData["negative_price_left"];
1180	for (var prID in optionsData) {
1181		var optionData = optionsData[prID];
1182		var controlType = optionData["control_type"];
1183		var percentagePriceType = optionData["percentage_price_type"];
1184		var percentagePropertyId = optionData["percentage_property_id"];
1185		var parentPrice = 0;
1186		if (productData["options"][percentagePropertyId] && productData["options"][percentagePropertyId]["price"]) {
1187			parentPrice = productData["options"][percentagePropertyId]["price"];
1188		}
1189		if (percentagePriceType == 2 && percentagePropertyId != "") {
1190			var optionValues = optionData["values"];
1191			if (controlType == "LISTBOX") {
1192				var listObj = itemsForm.elements["property"+idx+"_" + prID];
1193				for (var l = 0; l < listObj.options.length; l++) {	
1194					var listVal = listObj.options[l].value;
1195					if (listVal && optionValues[listVal]) {
1196						var valueDesc = optionValues[listVal]["desc"];
1197						var valuePercentage = parseFloat(optionValues[listVal]["percentage_price"]);			
1198						if (isNaN(valuePercentage)) { valuePercentage = 0; }
1199						if (valuePercentage != 0) {
1200							var valuePrice = Math.round(parentPrice * valuePercentage) / 100;
1201							if (valuePrice > 0) {
1202								listObj.options[l].text = valueDesc+" "+positivePriceRight+currencyFormat(valuePrice, productData["currency"])+positivePriceLeft;
1203							} else if (valuePrice < 0) {
1204								listObj.options[l].text = valueDesc+" "+negativePriceRight+currencyFormat(valuePrice, productData["currency"])+negativePriceLeft;
1205							} else {
1206								listObj.options[l].text = valueDesc;
1207							}
1208						}
1209					}
1210				}
1211			}
1212		}
1213	}
1214	return propertiesPrice;
1215}
1216
1217
1218function calculateOptionPrice(itemsForm, idx, selectedOptions, prID, subPrice)
1219{
1220	var productData = getProductData(itemsForm, idx);
1221	var params = productData; // todo: change to productData
1222	var optionData = productData["options"][prID];
1223	var optionValues = optionData["values"];
1224
1225	// check if we need to get parent option price
1226	var parentPrice = 0;
1227	var percentagePriceType = optionData["percentage_price_type"];
1228	var percentagePropertyId = optionData["percentage_property_id"];
1229	if (percentagePriceType == 2 && percentagePropertyId != "" && !subPrice) {
1230		parentPrice = calculateOptionPrice(itemsForm, idx, selectedOptions, percentagePropertyId, true);
1231	}
1232
1233	// start calculation
1234	var totalPrice = 0; var valueId; var valuePrice;
1235	var usedControls = 0; var controlText = ""; var freeLetters = 0;
1236	var priceType = parseInt(optionData["property_price_type"]);
1237	var priceAmount = parseFloat(optionData["property_price"]);
1238	if (isNaN(priceAmount)) { priceAmount = 0; }
1239	var freePriceType = parseInt(optionData["free_price_type"]);
1240	var freePriceAmount = optionData["free_price_amount"];
1241	var freeControls = 0;
1242	if (freePriceType == 1) {
1243		freePriceAmount = parseFloat(freePriceAmount);
1244	} else {
1245		freePriceAmount = parseInt(freePriceAmount);
1246	}
1247	if (isNaN(freePriceAmount)) { freePriceAmount = 0; }
1248	if (freePriceType == 2) {
1249		freeControls = freePriceAmount;
1250	} else if (freePriceType == 3 || freePriceType == 4) {
1251		freeLetters = freePriceAmount;
1252	}
1253	
1254	var prControl = optionData["control_type"];
1255	if (prControl == "LISTBOX" || prControl == "RADIOBUTTON") {
1256		valueId = selectedOptions[prID];
1257		usedControls++;
1258		//prPrice = getOptionPrice(itemsForm, valueId);
1259		prPrice = getOptionPrice(productData, prID, valueId); 
1260
1261		if (percentagePriceType == 2 && parentPrice != 0 && optionValues[valueId]) {
1262			var valuePercentage = parseFloat(optionValues[valueId]["percentage_price"]);			
1263			if (isNaN(valuePercentage)) { valuePercentage = 0; }
1264			totalPrice += Math.round(parentPrice * valuePercentage) / 100;
1265		}
1266		totalPrice += prPrice;
1267	} else if (prControl == "CHECKBOXLIST" || prControl == "TEXTBOXLIST") {
1268		var values = selectedOptions[prID];
1269		for (valueId in values) {
1270			usedControls++;
1271			//prPrice = getOptionPrice(itemsForm, valueId);
1272			prPrice = getOptionPrice(productData, prID, valueId); 
1273			totalPrice += prPrice;
1274			if (prControl == "TEXTBOXLIST") {
1275				controlText += selectedOptions[prID][valueId];
1276				if (freeControls >= usedControls) {
1277					if (priceType == 3) {
1278						freeLetters = controlText.length;
1279					} else if (priceType == 4) {
1280						freeLetters = controlText.replace(/[\n\r\t\s]/g, "").length;
1281					}
1282				}
1283			}
1284		}   
1285	} else if (prControl == "WIDTH_HEIGHT") {
1286		usedControls++;
1287		var prices = optionData["prices"]; 
1288		var selectedWidth = parseFloat(selectedOptions[prID]["width"]);
1289		var selectedHeight = parseFloat(selectedOptions[prID]["height"]);
1290		var minWidth; var maxWidth; var minHeight; var maxHeight;
1291		for (var curWidth in prices) {
1292			if (curWidth > selectedWidth || curWidth == selectedWidth) {
1293				for (var curHeight in prices[curWidth]) {
1294					if (curHeight > selectedHeight || curHeight == selectedHeight) {
1295						totalPrice += parseFloat(prices[curWidth][curHeight]);
1296						break;
1297					}
1298				}
1299				break;
1300			}
1301		}
1302	} else {
1303		usedControls++;
1304		if (prControl == "TEXTAREA" || prControl == "TEXTBOX") {
1305			controlText = selectedOptions[prID];
1306			if (freeControls >= usedControls) {
1307				if (priceType == 3) {
1308					freeLetters = controlText.length;
1309				} else if (priceType == 4) {
1310					freeLetters = controlText.replace(/[\n\r\t\s]/g, "").length;
1311				}
1312			}
1313		}
1314	}
1315	if (priceType == 1) {
1316		totalPrice += priceAmount;
1317	} else if (priceType == 2) {
1318		if (usedControls > freeControls) {
1319			totalPrice += (priceAmount * (usedControls - freeControls));
1320		}
1321	} else if (priceType == 3) {
1322		var textLength = controlText.length;
1323		if (textLength > freeLetters) {
1324			totalPrice += (priceAmount * (textLength - freeLetters));
1325		}
1326	} else if (priceType == 4) {
1327		var textLength = controlText.replace(/[\n\r\t\s]/g, "").length;
1328		if (textLength > freeLetters) {
1329			totalPrice += (priceAmount * (textLength - freeLetters));
1330		}
1331	}
1332	if (freePriceType == 1) {
1333		totalPrice -= freePriceAmount;
1334	}
1335	// end of calculation
1336
1337	return totalPrice;
1338}
1339function changeQuantity(formName, itemIndex)
1340{
1341	changeProperty(formName, itemIndex);
1342}
1343
1344function productsWin(pagename)
1345{
1346	var productsWin = window.open (pagename, 'productsWin', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=800,height=600');
1347	productsWin.focus();
1348}
1349
1350function properyImageUpload(uploadUrl)
1351{
1352	var uploadWin = window.open (uploadUrl, 'uploadWin', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=800,height=600');
1353	uploadWin.focus();
1354}
1355
1356function openPreviewWin(previewUrl, width, height)
1357{
1358	var previewWin = window.open (previewUrl, 'previewWin', 'left=0,top=0,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height);
1359	previewWin.focus();
1360	return false;
1361}
1362
1363function getOptionPrice(productData, prID, valueId)
1364{
1365	var optionPrice = 0;
1366	try {
1367		optionPrice = parseFloat(productData["options"][prID]["values"][valueId]["price"]);
1368	} catch (e) {}
1369	if (isNaN(optionPrice)) { optionPrice = 0; }
1370	return optionPrice;
1371}
1372
1373function getOptionValue(itemForm, valueName)
1374{
1375	var optionPrice = 0;
1376	if (valueName != "") {
1377		if(itemForm.elements[valueName]) {
1378			optionPrice = parseInt(itemForm.elements[valueName].value);
1379			if(isNaN(optionPrice)) {
1380				optionPrice = 0;
1381			}
1382		}
1383	}
1384	return optionPrice;
1385}
1386
1387function formatNumber(numberValue, decimals, decimalPoint, thousandsSeparator)
1388{
1389	if (decimals == undefined) {
1390		decimals = 0;
1391	}
1392	if (thousandsSeparator == undefined) {
1393		thousandsSeparator = ",";
1394	}
1395
1396	var numberParts = "";
1397	var roundValue = 1;
1398	for (var d = 0; d < decimals; d++) {
1399		roundValue *= 10;
1400	}
1401	numberValue = Math.round(numberValue * roundValue) / roundValue;
1402	var numberSign = "";
1403	if (numberValue < 0) {
1404		numberSign = "-";
1405		numberValue = Math.abs(numberValue);
1406	} 
1407
1408	var numberText = new String(numberValue);
1409	var numberParts = numberText.split(".");
1410	var beforeDecimal = numberParts[0];
1411	var afterDecimal = "";
1412	numberText = "";
1413	if (numberParts.length == 2) {
1414		afterDecimal = numberParts[1];
1415	}
1416	while (beforeDecimal.length > 0) {
1417		if (beforeDecimal.length > 3) {
1418			numberText = thousandsSeparator + beforeDecimal.substring(beforeDecimal.length - 3, beforeDecimal.length) + numberText;
1419			beforeDecimal = beforeDecimal.substring(0, beforeDecimal.length - 3);
1420		} else {
1421			numberText = beforeDecimal + numberText;
1422			beforeDecimal = "";
1423		}
1424	}
1425	if (decimals > 0) {
1426		while (afterDecimal.length < decimals) {
1427			afterDecimal += "0";
1428		}
1429		if (decimalPoint == undefined) {
1430			decimalPoint = ".";
1431		}
1432		numberText += decimalPoint + afterDecimal;
1433	}
1434	numberText = numberSign + numberText;
1435
1436	return numberText;
1437}
1438
1439function currencyFormat(numberValue, currency)
1440{
1441	if (!currency) { currency = {}; }
1442	if (!currency.left) { currency.left = ""; }
1443	if (!currency.right) { currency.right = ""; }
1444	var formatted = currency["left"] + formatNumber(numberValue*currency["rate"], currency["decimals"], currency["point"], currency["separator"]) + currency["right"];
1445	return formatted;
1446}
1447
1448function getParamValue(params, paramName, paramType)
1449{
1450	var paramValue = "";
1451	if (params[paramName]) {
1452		paramValue = params[paramName];
1453	}
1454	if (paramType == "int") {
1455		paramValue = parseInt(paramValue);
1456		if(isNaN(paramValue)) { paramValue = 0; }
1457	} else if (paramType == "float") {
1458		paramValue = parseFloat(paramValue);
1459		if(isNaN(paramValue)) { paramValue = 0; }
1460	}
1461	return paramValue;
1462}
1463
1464
1465function getProductData(itemsForm, idx)
1466{
1467	var productData = null;
1468	if (itemsForm.elements["item"+idx] && itemsForm.elements["item"+idx].hasAttribute("data-product")) {
1469		productData = itemsForm.elements["item"+idx].getAttribute("data-product");
1470	} else if (itemsForm.elements["item_id"+idx] && itemsForm.elements["item_id"+idx].hasAttribute("data-product")) {
1471		productData = itemsForm.elements["item_id"+idx].getAttribute("data-product");
1472	} else if (itemsForm.elements["product_data"+idx]) {
1473		productData = itemsForm.elements["product_data"+idx].value;
1474	}
1475	if (productData) {
1476		try {
1477			productData = JSON.parse(productData);
1478		} catch(e) {
1479			alert(e + "\n" + productData); 
1480		}	
1481	}
1482	// check some parameters
1483	var checkParams = {"base_price": 0, "crate": 1, "pe": 0, "zero_product_action": 1,
1484		"zero_price_type": 0, "show_prices": 1, "tax_prices_type": 0, "points_rate": 1,
1485		"points_decimals": 0, "points_decimals": 0, "comp_price": 0, "comp_tax": 0,
1486		"base_points_price": 0, "base_reward_points": 0, "base_reward_credits": 0};
1487	for (paramName in checkParams) {
1488		productData[paramName] = parseFloat(productData[paramName]);
1489		if (isNaN(productData[paramName]) || productData[paramName] === null) { productData[paramName] = checkParams[paramName]; }
1490	}
1491	for (paramName in productData) {
1492		if (productData[paramName] === null) { productData[paramName] = ""; }
1493	}
1494
1495	return productData;
1496}
1497
1498function saveInputValue(obj)
1499{
1500	obj.setAttribute("data-value", obj.value);
1501}
1502
1503function checkInputLength(obj, maxLength, limitType)
1504{
1505	var savePos = obj.selectionStart;
1506	var objText = obj.value;
1507	var calcText = (limitType == 3 || limitType == 4) ? objText.replace(/[\n\r\t\s]/g, "") : objText;
1508	if (calcText.length > 0 && calcText.length > maxLength) {
1509		obj.value = obj.getAttribute("data-value");
1510		if (obj.setSelectionRange) {
1511			obj.setSelectionRange(savePos-1, savePos-1);
1512		}
1513	} else {
1514		saveInputValue(obj);
1515	}
1516}
1517
1518function checkMaxLength(e, obj, maxLength, limitType)
1519{
1520	var key;
1521	if (window.event) {
1522		key = window.event.keyCode; //IE
1523	} else {
1524		key = e.which; //Firefox
1525	}
1526	var objText = obj.value;
1527	var selectedText = "";
1528  if (obj.selectionEnd) {
1529	selectedText = objText.substring(obj.selectionStart, obj.selectionEnd);
1530  } else if (document.selection && document.selection.createRange) {
1531	selectedText = document.selection.createRange().text;
1532  } 
1533	if (limitType == 3 || limitType == 4) {
1534		selectedText = selectedText.replace(/[\n\r\t\s]/g, "");
1535	}
1536	if (selectedText.length > 0) {
1537		return true;
1538	}
1539	if (key == 0 || key == 8 || key == 9 || key == 16 || key == 17 || key == 35 || key == 36 || key == 37 || key == 39 || key == 46 || key == 116) {
1540		return true;
1541	}
1542
1543	if (limitType == 3 || limitType == 4) {
1544		objText = objText.replace(/[\n\r\t\s]/g, "");
1545	}
1546  return (objText.length < maxLength);
1547}
1548
1549function checkBoxesMaxLength(e, obj, formName, idx, prID, maxLength, limitType)
1550{
1551	var itemsForm = document.forms[formName];
1552
1553	var key;
1554	if (window.event) {
1555		key = window.event.keyCode; //IE
1556	} else {
1557		key = e.which; //Firefox
1558	}
1559
1560	var objText = obj.value;
1561	var selectedText = "";
1562	var selectedText = "";
1563  if (obj.selectionEnd) {
1564	selectedText = objText.substring(obj.selectionStart, obj.selectionEnd);
1565  } else if (document.selection && document.selection.createRange) {
1566	selectedText = document.selection.createRange().text;
1567  } 
1568	if (limitType == 3 || limitType == 4) {
1569		selectedText = selectedText.replace(/[\n\r\t\s]/g, "");
1570	}
1571	if (selectedText.length > 0) {
1572		return true;
1573	}
1574
1575	if (key == 0 || key == 8 || key == 9 || key == 16 || key == 17 || key == 35 || key == 36 || key == 37 || key == 39 || key == 46 || key == 116) {
1576		return true;
1577	}
1578
1579	var totalOptions = parseInt(itemsForm.elements["property_total"+idx+"_" + prID].value);
1580	var totalLength = 0;
1581	for ( var ci = 1; ci <= totalOptions; ci++) {
1582		if (itemsForm.elements["property"+idx+"_" + prID+ "_" + ci].value != "") {
1583			var valueText = itemsForm.elements["property"+idx+"_" + prID+ "_" + ci].value;
1584			if (limitType == 3 || limitType == 4) {
1585				valueText = valueText.replace(/[\n\r\t\s]/g, "");
1586			}
1587			totalLength += valueText.length;
1588		}
1589	}
1590  return (totalLength < maxLength);
1591}
1592
1593function moveSpecialOffer(e)
1594{
1595	var mousePos = getMousePos(e);
1596	var pageSize = getPageSize();
1597	var scrollSize = getScroll();
1598
1599	var popObj = document.getElementById("popupBlock");
1600	if (popObj) {		   
1601		popObj.style.display = "block";
1602		var blockWidth = popObj.offsetWidth;
1603		var blockHeight = popObj.offsetHeight;
1604		// get default position
1605		var posX = mousePos[0] + 30;
1606		var posY = mousePos[1] - blockHeight/2;
1607		// check better position 
1608		if (posY < scrollSize[1]) {
1609			posY = scrollSize[1];
1610		} else if (posY + blockHeight > pageSize[1] + scrollSize[1]) {
1611			posY -= (posY + blockHeight - pageSize[1] - scrollSize[1]);
1612		} 
1613		if (posX > pageSize[0] / 2) {
1614			posX = mousePos[0] - blockWidth - 30;
1615		}
1616		popObj.style.left = posX + "px";
1617		popObj.style.top  = posY + "px";
1618	}
1619}
1620
1621function popupSpecialOffer(objName, displayValue)
1622{
1623	var scrollSize = getScroll();
1624	var itemObj = document.getElementById(objName);
1625	var popObj = document.getElementById("popupBlock");
1626	var soObj = document.getElementById("soPopupBox");
1627	if (displayValue == "block") {
1628		// delete popup block if it was initialized before
1629		var divTag = document.getElementById("popupBlock");
1630		if (divTag) {
1631			document.body.removeChild(divTag);
1632		}
1633
1634		divTag = document.createElement("div");
1635		divTag.id = "popupBlock";
1636		divTag.className = itemObj.className;
1637		divTag.style.zIndex = "999";
1638		divTag.style.position = "absolute";
1639		divTag.style.left = "10px";
1640		divTag.style.top  = "10px";
1641		divTag.innerHTML = itemObj.innerHTML;
1642		document.body.insertBefore(divTag, document.body.firstChild);
1643	} else {
1644		var popupObj = document.getElementById("popupBlock");
1645		if (popupObj) {
1646			document.body.removeChild(popupObj);
1647		}
1648	}
1649}
1650
1651function loadCategories(pbId, categoryId)
1652{
1653	var catObjName = "c_" + pbId + "_" + categoryId;
1654	var scObjName = "sc_" + pbId + "_" + categoryId;
1655	var scObj = document.getElementById(scObjName);
1656	if (scObj) {
1657		var largeRegExp = /large/i;
1658		var imgObj = document.getElementById("img_" + pbId + "_" + categoryId);
1659
1660		if (scObj.style.display == "none") {
1661			scObj.style.display = "block";
1662			if (imgObj) { 
1663				if (imgObj.src.match(largeRegExp)) {
1664					imgObj.src = "images/icons/minus_large.png"; 
1665				} else {
1666					imgObj.src = "images/icons/minus.gif"; 
1667				}
1668			}
1669		} else {
1670			scObj.style.display = "none";
1671			if (imgObj) { 
1672				if (imgObj.src.match(largeRegExp)) {
1673					imgObj.src = "images/icons/plus_large.png"; 
1674				} else {
1675					imgObj.src = "images/icons/plus.gif"; 
1676				}
1677			}
1678		}
1679	} else {
1680		var url = "block.php?pb_id="+encodeURIComponent(pbId)+"&ajax=1&category_id="+encodeURIComponent(categoryId);
1681		var params = new Array(pbId, categoryId);
1682		vaSpin(catObjName); // show loading progress
1683		callAjax(url, categoriesLoaded, params);
1684	}
1685}
1686
1687function categoriesLoaded(categoriesHTML, params)
1688{
1689	var pbId = params[0];
1690	var categoryId = params[1];
1691	var catObjName = "c_" + pbId + "_" + categoryId;
1692	var catObj= document.getElementById(catObjName);
1693	vaStopSpin(catObjName);
1694	catObj.innerHTML += categoriesHTML;
1695	var imgObj = document.getElementById("img_" + pbId + "_" + categoryId);
1696	if (imgObj) { 
1697		var regExp = /large/i;
1698		if (imgObj.src.match(regExp)) {
1699			imgObj.src = "images/icons/minus_large.png"; 
1700		} else {
1701			imgObj.src = "images/icons/minus.gif"; 
1702		}
1703	}
1704}
1705
1706function safeJsonParse(formName, paramName)
1707{
1708	var formObj = document.forms[formName];
1709	var jsonText = (formObj.elements[paramName]) ? formObj.elements[paramName].value : "";
1710	var jsonData = new Array();
1711	try {
1712		jsonData = JSON.parse(jsonText);
1713	} catch (e) {}
1714	return jsonData;
1715}
1716
1717window.viartData = window.viartData||{};window.viartData["scripts"]=window.viartData["scripts"]||{};window.viartData["scripts"]["shopping"]={"load":1};
1718document.currentScript.parentNode.removeChild(document.currentScript);

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.