// shopping javacript function confirmBuy(itemForm) { var prMessage = "Please specify {property_name} for {product_name}."; var prIDs = ""; if(itemForm.properties) { prIDs = itemForm.properties.value; } if (prIDs != "") { var properties = prIDs.split(","); var productName = itemForm.elements["item_name"].value; for ( var i = 0; i < properties.length; i++) { var prID = properties[i]; var prRequired = itemForm.elements["property_required_" + prID].value; if(prRequired == 1) { var prValue = ""; var prControl = itemForm.elements["property_control_" + prID].value; if (prControl == "LISTBOX") { prValue = itemForm.elements["property_" + prID].options[itemForm.elements["property_" + prID].selectedIndex].value; } else if (prControl == "RADIOBUTTON") { var radioControl = itemForm.elements["property_" + prID]; if (radioControl.length) { for ( var ri = 0; ri < radioControl.length; ri++) { if (radioControl[ri].checked) { prValue = radioControl[ri].value; break; } } } else { if (radioControl.checked) { prValue = radioControl.value; } } } else if (prControl == "CHECKBOXLIST") { if (itemForm.elements["property_total_" + prID]) { var totalOptions = parseInt(itemForm.elements["property_total_" + prID].value); for ( var ci = 1; ci <= totalOptions; ci++) { if (itemForm.elements["property_" + prID + "_" + ci].checked) { prValue = 1; break; } } } } else { prValue = itemForm.elements["property_" + prID].value; } if(prValue == "") { var propertyName = itemForm.elements["property_name_" + prID].value; prMessage = prMessage.replace("\{property_name\}", propertyName); prMessage = prMessage.replace("\{product_name\}", productName); alert(prMessage); if (prControl != "RADIOBUTTON" && prControl != "CHECKBOXLIST") { itemForm.elements["property_" + prID].focus(); } return false; } } } } return true; } function changeProperty(itemForm) { var priceControl = ""; var htmlControl = false; var prIDs = ""; var itemId = ""; var priceEdit = 0; var taxPercent = 0; var taxPrices = 1; var priceClass=""; if (itemForm.pe) { priceEdit = itemForm.pe.value; if (priceEdit == "1") { return; } } if (itemForm.tax_percent && itemForm.tax_percent.value != "") { taxPercent = parseFloat(itemForm.tax_percent.value); if (isNaN(taxPercent)) { taxPercent = 0; } } if (itemForm.tax_prices && itemForm.tax_prices.value != "") { taxPrices = parseFloat(itemForm.tax_prices.value); if (isNaN(taxPrices)) { taxPrices = 1; } } if (itemForm.add_id) { itemId = itemForm.add_id.value; } else if (itemForm.item_id) { itemId = itemForm.item_id.value; } if (itemForm.price_class) { priceClass = itemForm.price_class; } if (itemForm.sales_price) { priceControl = itemForm.sales_price; } else if (itemForm.price) { priceControl = itemForm.price; } else if (itemId != "" && document.getElementById) { htmlControl = true; priceControl = document.getElementById("sales_price_" + itemId); if (!priceControl) { priceControl = document.getElementById("price_" + itemId); } } var totalAdditionalPrice = 0; var totalAdditionalPriceTaxed = 0; if(itemForm.properties) { prIDs = itemForm.properties.value; } if(prIDs != "") { var properties = prIDs.split(","); for ( var i = 0; i < properties.length; i++) { var prID = properties[i]; var prValue = ""; var additionalPrice = 0; var additionalPriceTaxed = 0; var prControl = itemForm.elements["property_control_" + prID].value; if (prControl == "LISTBOX") { prValue = itemForm.elements["property_" + prID].options[itemForm.elements["property_" + prID].selectedIndex].value; } else if (prControl == "RADIOBUTTON") { var radioControl = itemForm.elements["property_" + prID]; if (radioControl.length) { for ( var ri = 0; ri < radioControl.length; ri++) { if (radioControl[ri].checked) { prValue = radioControl[ri].value; break; } } } else { if (radioControl.checked) { prValue = radioControl.value; } } } else if (prControl == "CHECKBOXLIST") { if (itemForm.elements["property_total_" + prID]) { var totalOptions = parseInt(itemForm.elements["property_total_" + prID].value); for ( var ci = 1; ci <= totalOptions; ci++) { if (itemForm.elements["property_" + prID + "_" + ci].checked) { var checkedValue = itemForm.elements["property_" + prID + "_" + ci].value; if (itemForm.elements["option_price_" + checkedValue]) { // UNiX create change in item_properties.php line 325 if(taxPrices!=2){ var checkedPrice = parseFloat(itemForm.elements["option_price_" + checkedValue].value); }else{ var checkedPrice = parseFloat(itemForm.elements["option_price_" + checkedValue].value); var checkedPricetax = parseFloat(itemForm.elements["option_taxed_" + checkedValue].value); } if(!isNaN(checkedPrice) && checkedPrice!= 0) { additionalPrice += parseFloat(checkedPrice); } if(!isNaN(checkedPricetax) && checkedPricetax!= 0) { additionalPriceTaxed += parseFloat(checkedPricetax); } } } } } } if (prValue != "") { if(itemForm.elements["option_price_" + prValue]) { var optionPrice = itemForm.elements["option_price_" + prValue].value; var option_taxed= parseFloat(itemForm.elements["option_taxed_" + prValue].value); if(optionPrice != "") { additionalPrice = parseFloat(optionPrice); } } } if(!isNaN(additionalPrice) && additionalPrice != 0) { totalAdditionalPrice += additionalPrice; } if(!isNaN(additionalPriceTaxed) && additionalPriceTaxed != 0) { totalAdditionalPriceTaxed += additionalPriceTaxed; } } } if(priceControl && itemForm.base_price) { var cl = ""; var cr = ""; var basePrice = parseFloat(itemForm.base_price.value); if (itemForm.cl) { cl = itemForm.cl.value; } if (itemForm.cr) { cr = itemForm.cr.value; } var compPrice = 0; var compTax = 0; if (itemForm.comp_price && itemForm.comp_price.value != "") { compPrice = parseFloat(itemForm.comp_price.value); } if (itemForm.comp_tax && itemForm.comp_tax.value != "") { compTax = parseFloat(itemForm.comp_tax.value); } // check product quantity var quantity = 1; if (itemForm.quantity) { if (itemForm.quantity.selectedIndex) { quantity = parseInt(itemForm.quantity.options[itemForm.quantity.selectedIndex].value); } else { quantity = parseInt(itemForm.quantity.value); } if (isNaN(quantity)) { quantity = 1; } } if(itemForm.quantity_price) { var prices = itemForm.quantity_price.value; if (prices != "") { prices = prices.split(","); for (var p = 0; p < prices.length; p = p + 4) { var minQuantity = parseInt(prices[p]); var maxQuantity = parseInt(prices[p + 1]); if (quantity >= minQuantity && quantity <= maxQuantity) { basePrice = parseFloat(prices[p + 2]); var propertiesDiscount = parseFloat(prices[p + 3]); if (propertiesDiscount > 0) { totalAdditionalPrice -= (Math.round(totalAdditionalPrice * propertiesDiscount) / 100); } break; } } } } // UNiX Create taxless for with out VAT var taxless_price = parseFloat(itemForm.taxless_price.value); if (taxPrices == 2) { var price = taxless_price + totalAdditionalPrice; }else{ var price = basePrice + totalAdditionalPrice; } var taxAmount = (Math.round(price * taxPercent) / 100); var productPrice = price + compPrice; var taxPrice = Math.round((productPrice + taxAmount + compTax) * 100) / 100; if (taxPrices == 2) { if(option_taxed!=null){ productPrice = (basePrice + compPrice + option_taxed); if(totalAdditionalPrice==0 && priceClass.value=="realprice"){ productPrice = taxPrice; }else if(priceClass.value=="realprice"){ productPrice = taxPrice; }else{ } }else{ if(totalAdditionalPrice!=null && priceClass.value=="ourprice"){ productPrice = basePrice; }else if(priceClass.value=="realprice"){ productPrice = taxPrice; }else{ productPrice = basePrice; } } taxPrice = price + compPrice; } else if (taxPrices == 3) { productPrice = taxPrice; } if (htmlControl) { priceControl.innerHTML = cl + formatNumber(productPrice) + cr; } else { priceControl.value = cl + formatNumber(productPrice) + cr; } taxPriceControl = document.getElementById("tax_price_" + itemId); if (taxPriceControl) { taxPriceControl.innerHTML = cl + formatNumber(taxPrice) + cr; } } } function changeQuantity(itemForm) { changeProperty(itemForm); } function properyImageUpload(uploadUrl) { var uploadWin = window.open (uploadUrl, 'uploadWin', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=400,height=300'); uploadWin.focus(); } function openPreviewWin(previewUrl, width, height) { 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); previewWin.focus(); return false; } function openSuperImage(imageUrl, width, height) { var scrollbars = "no"; // add margins to image size if (width > 0 && height > 0) { width += 30; height += 30; } // check available sizes var availableHeight = window.screen.availHeight - 60; var availableWidth = window.screen.availWidth - 20; if (isNaN(availableHeight)) { availableHeight = 520; } if (isNaN(availableWidth)) { availableWidth = 760; } if (height > availableHeight || height == 0) { height = availableHeight; scrollbars = "yes"; } if (width > availableWidth || width == 0) { width = availableWidth; scrollbars = "yes"; } var superImageWin = window.open (imageUrl, 'superImageWin', 'left=0,top=0,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=' + scrollbars + ',resizable=yes,width=' + width + ',height=' + height); superImageWin.focus(); return false; } function setFilePath(filepath, filetype, controlName, formId) { if(filepath != "" && controlName != "" && formId != "") { var formName = "form_" + formId; document.forms[formName].elements[controlName].value = filepath; document.forms[formName].elements[controlName].focus(); } } function formatNumber(numberValue) { var numberParts = ""; var numberText = new String(numberValue); if(numberText.indexOf(".") == -1) { numberText += ".00"; } else if (numberText.indexOf(".") == (numberText.length - 2)) { numberText += "0"; } else { var numberParts = numberText.split("."); if(numberParts[1].length > 2) { numberText = numberParts[0] + "." + numberParts[1].substring(0, 2); } } var numberLength = numberText.length; if (numberLength >= 10) { numberText = numberText.substring(0, numberLength-9)+","+numberText.substring(numberLength-9, numberLength-6)+","+numberText.substring(numberLength-6, numberLength); } else if (numberLength >= 7) { numberText = numberText.substring(0, numberLength-6)+","+numberText.substring(numberLength-6, numberLength); } return numberText; }