function GetStockID(formID) // Returns the StockID for the selected form { var VariantIndex = document.forms['f' + formID].Variant.selectedIndex; return document.forms['f' + formID].Variant.options[VariantIndex].value; } function InStock(formID, StockID) // Determines whether an item is in stock { // Lookup value of hidden InStock field for this StockID if (document.forms['f' + formID]['InStock' + StockID].value == 'yes') { return true; } else { return false; } } function SiblingChange(formID) // Displays the correct Buy One or Out Of Stock button in the selected form // and changes the URL on the product image { var id id = "ProdPic" + formID; // Set the image's URL to a hidden form field value, so that the correct script is run if the // image is clicked. document.getElementById(id).href = document.forms['f' + formID]['VariantHref' + formID].value // Use function to return StockID var StockID = GetStockID(formID); if (StockID != 0) { // Use function to display correct button buyoutImage(formID, StockID) } } function buyoutImage(formID, StockID) // Display correct button for Buy One / Out of Stock { // Use function to see if item is in stock if (InStock(formID, StockID)) { // Item is in stock, so display Buy One document.images['buyout' + formID].src = "/Style/Grindstore/images/hd2002/buyone.gif"; document.images['buyout' + formID].alt = "click here to buy this item"; } else { // Item is out of stock, so display Notify document.images['buyout' + formID].src = "/Style/Grindstore/images/hd2002/outofstock.gif"; document.images['buyout' + formID].alt = "Notify me when there is some in stock"; } } function GoForth(formID, NewAddress) // Redirect to the correct page for more details or postcard { // Use function to return StockID var StockID = GetStockID(formID); if (StockID == 0) { // No item selected, so alert the user alert('Please select an entry from the drop-down list'); } else { try //Disable the Buy Now image's anchor or the BuyNow button, whilst the page submission is going on { if (document.all.BuyOneLink) { document.all.BuyOneLink.href = '#'; } if (document.forms['f' + formID].Variant) { document.forms['f' + formID].Variant.onclick = ''; } } catch(e) //Not found, do nothing { } finally //Continue { // Work out where to go window.location = '/' + NewAddress + '&stockid=' + StockID; } } } function GoForthReWrite(formID, NewAddress) // Redirect to the correct page for more details or postcard { // Use function to return StockID var StockID = GetStockID(formID); if (StockID == 0) { // No item selected, so alert the user alert('Please select an entry from the drop-down list'); } else { // Work out where to go window.location = NewAddress + '-stockid-' + StockID + '.html'; } } function GoSubmit(formID) // Either validate the form or pop up the Notify screen { // Use function to return StockID var StockID = GetStockID(formID); if (StockID == 0) { // No item selected, so alert the user alert('Please select an entry from the drop-down list'); } else { // Use function to see if item is in stock if (InStock(formID, StockID)) { // Item is in stock, so let the user buy one... // Update the hidden AddToCart field with the correct stockID document.forms['f' + formID]['AddToCart' + formID].value = StockID //Update the hidden Qty and MaxQty fields with the correct values document.forms['f' + formID]['Qty' + formID].value = 1 document.forms['f' + formID]['MaxQty' + formID].value = document.forms['f' + formID]['MaxQty' + StockID].value // Use the common validateFields function to submit the form validateFields('f' + formID, formID, StockID); } else { // Item is out of stock, so display Notify PopupNotify('/InStockNotify.asp?ID=' + StockID, 250, 300); } } } function GoSubmitShop(formID) // Validate the form { // Use function to return StockID var StockID = GetStockID(formID); if (StockID == 0) { // No item selected, so alert the user alert('Please select an entry from the drop-down list to'); } else { // Update the hidden AddToCart field with the correct stockID document.forms['f' + formID]['AddToCart' + formID].value = StockID; // Submit the form document.forms['f' + formID].submit(); } } function OpenWin(formID, StockID, CID) // Open popup window with passed StockID or StockID from the form { var Id = 0; //No form passed if (formID == 0) { //Use passed StockID Id = StockID; } else { //Use variant StockID from the form Id = GetStockID(formID); if (Id == 0) { // No item selected, so alert the user alert('Please select an entry from the drop-down list'); } } if (Id != 0) //Have an Id, so open the popup { var newWind = window.open("popup.asp?CID=" + CID + "&StockID=" + Id , "PopUp", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=370,height=530"); if (navigator.userAgent.substring(0,9) == "Mozilla/4") { newWind.focus(); } } } function GoSubmitShopPopUp(formID, StockID) // Validate the form and spoof posting to the opener window { var ID = 0; if (StockID == 0) { // Use function to return StockID ID = GetStockID(formID); } else { //use passed StockID ID = StockID; } if (ID == 0) { // No item selected, so alert the user alert('Please select an entry from the drop-down list'); } else { // Write the form contents to a querystring var strLocation = document.forms['f' + formID].action; strLocation = strLocation + '&CatID=' + document.forms['f' + formID].CID.value; strLocation = strLocation + '&CID=' + document.forms['f' + formID].CID.value; strLocation = strLocation + '&function=add'; strLocation = strLocation + '&recordCount=1'; strLocation = strLocation + '&AddToCart' + formID + '=' + ID; strLocation = strLocation + '&Qty' + formID + '=1'; // Spoof Submission of the form to the opener window window.opener.location = strLocation window.close() } } //Preload Images if (document.images) { imgbuyone = new Image(); imgoutofstock = new Image(); imgbuyone.src = "/images/buyone.gif"; imgoutofstock.src = "/images/outofstock.gif" }