var productImages = []; // Preloaded image. ID = 4450 productImages[4450] = new Image(); productImages[4450].src="/image/product/medium/artic_black_brnz-1.jpg"; productImages[4450].alt = "Spotters Artic Shiny Black with Copper Polarised Lenses"; // Preloaded image. ID = 1185 productImages[1185] = new Image(); productImages[1185].src="/image/product/medium/artic_2.jpg"; productImages[1185].alt = "Spotters Artic Demi Brown with Brown Glass Polarised lenses "; // Preloaded image. ID = 1200 productImages[1200] = new Image(); productImages[1200].src="/image/product/medium/artic_black_pen-1.jpg"; productImages[1200].alt = "Spotters Artic Shiny Black with Bronze Photochromic Glass Penetrator Polarised lenses"; // Preloaded image. ID = 4448 productImages[4448] = new Image(); productImages[4448].src="/image/product/medium/artic_black_gry-1.jpg"; productImages[4448].alt = "Spotters Artic Shiny Black with Grey Polarised Lenses"; // Preloaded image. ID = 4449 productImages[4449] = new Image(); productImages[4449].src="/image/product/medium/artic_black_brn-1.jpg"; productImages[4449].alt = "Spotters Artic Shiny Black with Brown Polarised Lenses"; // Preloaded image. ID = 2500 productImages[2500] = new Image(); productImages[2500].src="/image/product/medium/artic_black_bm.jpg"; productImages[2500].alt = "Spotters Artic Shiny Black with Blue Mirror on Brown Glass Polarised lenses"; // Preloaded image. ID = 4451 productImages[4451] = new Image(); productImages[4451].src="/image/product/medium/artic_black_platmirr-1.jpg"; productImages[4451].alt = "Spotters Artic Shiny Black with Glass Platinum Mirror Polarised Lenses"; // Preloaded image. ID = 4452 productImages[4452] = new Image(); productImages[4452].src="/image/product/medium/artic_black_emerald-1.jpg"; productImages[4452].alt = "Spotters Artic Shiny Black with CR39 Emerald Lenses"; // Preloaded image. ID = 4453 productImages[4453] = new Image(); productImages[4453].src="/image/product/medium/artic_black_yellow_photo-1.jpg"; productImages[4453].alt = "Spotters Artic Shiny Black with Glass Yellow Photochromic Polarised Lenses"; // Preloaded image. ID = 4454 productImages[4454] = new Image(); productImages[4454].src="/image/product/medium/artic_black_gold_mirror-1.jpg"; productImages[4454].alt = "Spotters Artic Shiny Black with Glass Gold Mirror Polarised Lenses"; var productData = []; var fromPrice = new Array(); var fromMemberPrice = new Array(); productData[5252] = [{16: 3059, 17: 1228}, {"price":289.50, "memberPrice":289.50, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":289.50, "stock":0, "imageId":4449} ]; fromPrice[5252] = 289.50; fromMemberPrice[5252] = 289.50; productData[5253] = [{16: 3059, 17: 1234}, {"price":199.50, "memberPrice":199.50, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":199.50, "stock":0, "imageId":4448} ]; fromPrice[5253] = 199.50; fromMemberPrice[5253] = 199.50; productData[5254] = [{16: 3059, 17: 1235}, {"price":199.50, "memberPrice":199.50, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":199.50, "stock":0, "imageId":4450} ]; fromPrice[5254] = 199.50; fromMemberPrice[5254] = 199.50; productData[5255] = [{16: 3059, 17: 2599}, {"price":289.50, "memberPrice":289.50, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":289.50, "stock":0, "imageId":4453} ]; fromPrice[5255] = 289.50; fromMemberPrice[5255] = 289.50; productData[5256] = [{16: 3059, 17: 3054}, {"price":199.50, "memberPrice":199.50, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":199.50, "stock":0, "imageId":4449} ]; fromPrice[5256] = 199.50; fromMemberPrice[5256] = 199.50; productData[5257] = [{16: 3059, 17: 3055}, {"price":289.50, "memberPrice":289.50, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":289.50, "stock":0, "imageId":4448} ]; fromPrice[5257] = 289.50; fromMemberPrice[5257] = 289.50; productData[5258] = [{16: 3059, 17: 3056}, {"price":289.50, "memberPrice":289.50, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":289.50, "stock":0, "imageId":1200} ]; fromPrice[5258] = 289.50; fromMemberPrice[5258] = 289.50; productData[5259] = [{16: 3059, 17: 3057}, {"price":289.50, "memberPrice":289.50, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":289.50, "stock":0, "imageId":2500} ]; fromPrice[5259] = 289.50; fromMemberPrice[5259] = 289.50; productData[5260] = [{16: 3059, 17: 3058}, {"price":289.50, "memberPrice":289.50, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":289.50, "stock":0, "imageId":4454} ]; fromPrice[5260] = 289.50; fromMemberPrice[5260] = 289.50; productData[5261] = [{16: 3059, 17: 3060}, {"price":289.50, "memberPrice":289.50, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":289.50, "stock":0, "imageId":4451} ]; fromPrice[5261] = 289.50; fromMemberPrice[5261] = 289.50; productData[5262] = [{16: 3059, 17: 3061}, {"price":199.50, "memberPrice":199.50, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":199.50, "stock":0, "imageId":4452} ]; fromPrice[5262] = 199.50; fromMemberPrice[5262] = 199.50; productData[5215] = [{16: 3062, 17: 1228}, {"price":289.50, "memberPrice":289.50, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":289.50, "stock":0, "imageId":1185} ]; fromPrice[5215] = 289.50; fromMemberPrice[5215] = 289.50; productData[5216] = [{16: 3062, 17: 1234}, {"price":199.50, "memberPrice":199.50, "exception":'TRUE', "isSpecial":'FALSE', "specialPrice":199.50, "stock":0, "imageId":0} ]; fromPrice[5216] = 199.50; fromMemberPrice[5216] = 199.50; productData[5217] = [{16: 3062, 17: 1235}, {"price":199.50, "memberPrice":199.50, "exception":'TRUE', "isSpecial":'FALSE', "specialPrice":199.50, "stock":0, "imageId":0} ]; fromPrice[5217] = 199.50; fromMemberPrice[5217] = 199.50; productData[5218] = [{16: 3062, 17: 2599}, {"price":289.50, "memberPrice":289.50, "exception":'TRUE', "isSpecial":'FALSE', "specialPrice":289.50, "stock":0, "imageId":0} ]; fromPrice[5218] = 289.50; fromMemberPrice[5218] = 289.50; productData[5219] = [{16: 3062, 17: 3054}, {"price":199.50, "memberPrice":199.50, "exception":'TRUE', "isSpecial":'FALSE', "specialPrice":199.50, "stock":0, "imageId":0} ]; fromPrice[5219] = 199.50; fromMemberPrice[5219] = 199.50; productData[5220] = [{16: 3062, 17: 3055}, {"price":289.50, "memberPrice":289.50, "exception":'TRUE', "isSpecial":'FALSE', "specialPrice":289.50, "stock":0, "imageId":0} ]; fromPrice[5220] = 289.50; fromMemberPrice[5220] = 289.50; productData[5221] = [{16: 3062, 17: 3056}, {"price":289.50, "memberPrice":289.50, "exception":'TRUE', "isSpecial":'FALSE', "specialPrice":289.50, "stock":0, "imageId":0} ]; fromPrice[5221] = 289.50; fromMemberPrice[5221] = 289.50; productData[5222] = [{16: 3062, 17: 3057}, {"price":289.50, "memberPrice":289.50, "exception":'TRUE', "isSpecial":'FALSE', "specialPrice":289.50, "stock":0, "imageId":0} ]; fromPrice[5222] = 289.50; fromMemberPrice[5222] = 289.50; productData[5223] = [{16: 3062, 17: 3058}, {"price":289.50, "memberPrice":289.50, "exception":'TRUE', "isSpecial":'FALSE', "specialPrice":289.50, "stock":0, "imageId":0} ]; fromPrice[5223] = 289.50; fromMemberPrice[5223] = 289.50; productData[5224] = [{16: 3062, 17: 3060}, {"price":289.50, "memberPrice":289.50, "exception":'TRUE', "isSpecial":'FALSE', "specialPrice":289.50, "stock":0, "imageId":0} ]; fromPrice[5224] = 289.50; fromMemberPrice[5224] = 289.50; productData[5225] = [{16: 3062, 17: 3061}, {"price":199.50, "memberPrice":199.50, "exception":'TRUE', "isSpecial":'FALSE', "specialPrice":199.50, "stock":0, "imageId":0} ]; fromPrice[5225] = 199.50; fromMemberPrice[5225] = 199.50; var attribSets = [16, 17]; // Find the variant selected. function findVariant() { found = false; // Found flag. variantIndex = 0; // The index of the found variant element. // This just scans for a match and if found it sets the flags and breaks. // If one mismatch is detected it just breaks the loop. for (variant in productData) // Loop through the variant array, called 'productData'. { for (set in attribSets) // Now loop through the sets. { // Get a refference to a attribute set select box. attrib = document.getElementById("attributes"+attribSets[set]); // Check to see if the value of that attribute select box is in the productData attribute array. if (productData[variant][0][attribSets[set]]==attrib.value) { found = true; } else { found = false; break; } } if (found==true) { variantIndex = variant; break; } } if (variantIndex!=0) { var data = productData[variantIndex][1]; data["var_id"] = variantIndex; return data; } else { return false; } } // This enables and disables the submit button. function submitButtonEnable(enabled) { if (enabled==false) { document.getElementById("submitButton").disabled = true; } else { document.getElementById("submitButton").disabled = false; } } function specialRowEnabled(enable) { if (enable==false) { document.getElementById("specialRow").style.display="none"; document.getElementById("memberPriceRow").style.display="block"; } else { document.getElementById("specialRow").style.display="block"; document.getElementById("memberPriceRow").style.display="none"; } } // Display stock indicator function displayStock() { // Don't show stock return true; // Get the selected variant. variant = findVariant(); if (variant["stock"] < 0) { stockString = "Made upon ordering"; } else if (variant["stock"] ==0) { stockString = "Out of stock"; } else if (variant["stock"] > 0) { stockString = "In stock & ready to ship"; } document.getElementById("stock").innerHTML = stockString; } // This is the function that gets called when the user changes the selection. function changeVariant() { var member = false; // Get the selected variant. variant = findVariant(); // Not a variant, show a from price and disable add to cart if(!variant) { var toprice = getToPrice(); var fromprice = getFromPrice(); if(toprice == fromprice) { document.getElementById("price").innerHTML = "RRP from AUD$ " + fromprice; } else { document.getElementById("price").innerHTML = "RRP from AUD$ " + fromprice + " to AUD$ " + toprice; } if(member) { document.getElementById("memberPrice").innerHTML = ""; } submitButtonEnable(false); specialRowEnabled(false); } // Check if it is an exception. else if (variant["exception"]=="FALSE") { // See if it is on special. if (variant["isSpecial"]=="TRUE") { // Display the special price with the old price with strike through font. document.getElementById("price").innerHTML = "RRP:  AUD$ " + variant["price"].toFixed(2) + ""; document.getElementById("specialPrice").innerHTML = variant["specialPrice"].toFixed(2) + getDiscountPercentage(variant["price"], variant["specialPrice"]); specialRowEnabled(true); } // Just show the normal price. else { if(member) { document.getElementById("price").innerHTML = "RRP:  AUD$ " + variant["price"].toFixed(2) + ""; } else { document.getElementById("price").innerHTML = "RRP:  AUD$ " + variant["price"].toFixed(2); } specialRowEnabled(false); } if(member) { document.getElementById("memberPrice").innerHTML = "Member's Price: AUD$ " + variant["memberPrice"].toFixed(2) + getDiscountPercentage(variant["price"], variant["memberPrice"]); } // Stock displayStock(); if (variant["imageId"]!=0) { // Swapping image was confusing the users //swapImage(variant["imageId"]); } submitButtonEnable(true); // Enable the submit button. } else { // Variant must be an exception so display some text and disable the submit button. document.getElementById("price").innerHTML = "Not Available"; document.getElementById("memberPrice").innerHTML = ""; submitButtonEnable(false); specialRowEnabled(false); } } function swapImage(image) { document.prodImageMain.src = productImages[image].src; document.getElementById("prodImageMainAlt").innerHTML = productImages[image].alt; } /** * Sort the prices for the product * @return lowest price */ function getFromPrice() { fromPrice.sort(function(a,b){return a - b}); return fromPrice[0].toFixed(2); } /** * Sort the prices for the product * @return highest price */ function getToPrice() { fromPrice.sort(function(a,b){return b - a}); return fromPrice[0].toFixed(2); } /** * Percentage off * @param price Original product price * @param specialPrice on special/sale price * @return Str Text string displaying percentage if percentage is greater than 0% */ function getDiscountPercentage(price, specialPrice) { var discount; // Make sure there is a difference in price if(price - specialPrice <= 0) { return ' (No Discount)'; } discount = ((price - specialPrice)/price)*100; discount = Math.round(discount); if(discount > 0) { return ' (' + discount + '% off)' } return ''; }