﻿function clearSearch(searchBox) {
    if (searchBox.value == "Search...") searchBox.value = "";
}
function search(qid) { window.location = '/app/search.aspx?q=' + document.getElementById(qid).value + '&page=1'; return false; }
function setCommandSupressDefault(strCommandName, strCommandValue, strConfirm) { var bConfirm; if (strConfirm != null && strConfirm != "") { bConfirm = confirm(strConfirm); } else { bConfirm = true; } if (bConfirm == true) { document.getElementById("command_name").value = strCommandName; document.getElementById("command_value").value = strCommandValue; document.getElementById("aspnetForm").submit(); } return bConfirm; }
function setCommand(strCommandName, strCommandValue, strConfirm) { var bConfirm; if (strConfirm != null && strConfirm != "") { bConfirm = confirm(strConfirm); } else { bConfirm = true; } if (bConfirm == true) { document.getElementById("command_name").value = strCommandName; document.getElementById("command_value").value = strCommandValue; } return bConfirm; }

var tabSelector = { links: null, tabs: null, init: function(linksID, tabsID) { var linksBox = document.getElementById(linksID); var tabsBox = document.getElementById(tabsID); links = linksBox.getElementsByTagName("A"); tabs = tabsBox.getElementsByTagName("DIV"); }, showTab: function(linkI, tabI) { for (i = 0; i < links.length; i++) { if (i == linkI) { links[i].className = 'on'; tabs[i].className = 'on'; } else { links[i].className = 'off'; tabs[i].className = 'off'; } } return false; } }

function createCustomiseAndBuy() {

    //  this builds the functionality for the customise options on the
    //  product page. The price is recalculated on each option
    //  change and retrieved via web service.

    //  call the update when select boxes are changed.
    $(".options select").change(function() {
        updateCustomiseAndBuy();
    });

}


//  the updateCustomiseAndBuy function is called whenenever a user changes an option 
//  in the customise and buy panel.
function updateCustomiseAndBuy() {
    var product = $(".customiseandbuy").find("input:first").val();
    var options = "";

    //  show calculating message.
    $("span.totalprice").html("...");

    //  get options.
    $(".options select").each(function() {
        options = options + $(this).val() + " , ";
    });
    if (options.length > 0) options = options.substr(0, options.length - 3);
    //  build the JSON string.
    var JSON = "{" +
               " Product_ID : " + product + " , " +
               " ProductOptions : [ " + options + " ] " +
               "}";

    //  call the web service passing the product and options
    //  and then update the price.
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/Assets/Seagull/WebServices/Seagull.asmx/CustomiseAndBuy",
        data: JSON,
        dataType: "json",
        success: function(response) {
            var oResponse = eval("(" + response.d + ")");

            //  Update prices.
            $("span.totalprice").html(oResponse.DataTwo);

        },
        error: function(response) {

            //  if an error has occured display for debugging purposes.
            alert(response.responseText);
        }
    });
}