					function GetElement(obj) {
						if (document.getElementById) return document.getElementById(obj);
						else if (document.all) return document.all[obj];
						else return document.layers[obj];
					}
					function open_popup( url ) {
						var hwin;
				              hwin = window.open( url, '', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=620,height=460');
					}
					function open_popup2( url ) {
						var hwin;
				              hwin = window.open( url, '', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=460,height=580');
				              return false;
					}
					function popup_image( url, w, h ) {
						var hwin;
				              hwin = window.open( '', '', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=auto,resizable=1,width='+(w+20)+',height='+(h+20));
				              hwin.document.write('<html><head><title></title></head><body>');
				              hwin.document.write('<a href="javascript:window.close();"><img src="'+url+'" width="'+w+'" height="'+h+'" alt="Закрыть окно" border="0"/></a>');
				              hwin.document.write('</body></html>');
				              hwin.document.close();
					}
					function popup_image2( url, w, h ) {
						var hwin;
				              hwin = window.open( '', '', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=auto,resizable=1,width='+(w+20)+',height='+(h+20));
				              hwin.document.write('<html><head><title>Фото</title></head><body>');
				              hwin.document.write('<a href="javascript:window.close();"><img src="'+url+'" alt="Закрыть окно" border="0"/></a>');
				              hwin.document.write('</body></html>');
				              hwin.document.close();
					}
					//
					function submit_form(f) {
						if (f.onsubmit) {
							if (f.onsubmit())
								f.submit();
						}
						else
							f.submit();
					}
					
					// cache images
					var cachedImages = new Array();
					// cachedImages[0] = new Image(); cachedImages[0].src = "/images/m_shop.jpg";
					function l(im, i) {
						if (document.images)
							document.images[im].src = cachedImages[i].src;
					}
					
					// ITEM OBJECT
					function ShopItem() {
						this.variant_id = null;
						this.price = null;
						this.va = new Array();	// variant_attributes
						this.vv = new Array();	// variant_values
					}
					

			function shop_submit(form_id) {
				var foundItem = shop_item(form_id);
				if (foundItem != null) {
					document.forms[form_id].variant_id.value = foundItem.variant_id;
					document.forms[form_id].submit();
				}
				else
					alert("Извините, но такой опции нет в наличии");
				return false;
			}
			function shop_update(form_id) {
				var foundItem = shop_item(form_id);
				var price;
				if (foundItem != null) {
					price = foundItem.price;
					if (foundItem.price_new != foundItem.price)
						price = "<strike>"+price+"</strike><br/>Новая цена: "+foundItem.price_new;

					sku = foundItem.sku;
					document.forms[form_id].variant_id.value = foundItem.variant_id;
				}
				else {
					price = "нет в наличии";
					sku = " --- ";
				}
				var p = document.getElementById('price_'+form_id);
				if (p)
					p.innerHTML = price;
				p = document.getElementById('sku_'+form_id);
				if (p)
					p.innerHTML = sku;
			}
			function shop_force(form_id) {
				var items = eval('variants_'+form_id);
				if (items.length == 0)
					return;
				var item = items[0];
				var f = document.forms[form_id];
				// thru whole form
				for(var i = 0; i < f.length; i++) {
					if (f.elements[i].type == "select-one") {
						var el = f.elements[i];
						// thru variant options
						var b = false;
						for(var k = 0; k < item.vv.length; k++) {
							if (item.va[k] == el.name) {
								var val = item.vv[k];
								// thru select options
								for(var z = 0; z < el.options.length; z++) {
									if (el.options[z].value == val) {
										el.options[z].selected = true;
										b = true;
										break;
									}
								}
								if (b)
									break;
							}
						}
					}
				}
			}
			function shop_item(form_id) {
				var a =  eval('variants_'+form_id);
				var f = document.forms[form_id];
				var va = new Array();
				var vv = new Array();
				for(var i = 0; i < f.length; i++)
					if (f.elements[i].type == "select-one") {
						if (f.elements[i].selectedIndex >= 0) {
							va[va.length] = f.elements[i].name;
							vv[vv.length] = f.elements[i].options[f.elements[i].selectedIndex].value;
						}
					}
				var foundItem = null;
				for(var i = 0; i < a.length; i++)
					if (compareItems(a[i], va, vv)) {
						foundItem = a[i];
						return foundItem;
						break;
					}
				return foundItem;
			}
			function compareItems(item, va, vv) {
				var result = true;
				if (va.length != item.va.length)
					return false;
				for(var i = 0; i < va.length; i++) {
					for(var z = 0; z < item.va.length; z++)
						if (va[i] == item.va[z]) {
							if (vv[i] != item.vv[z])
								return false;
							break;
						}
				}
				return true;
			}
