function showSalesLinePopup() {
    triggerMacBox({
        boxID: "SalesLineInformation",
        width: 450,
        ajaxUrl: "/hoursinfo.aspx?date=" + new Date()
    });
}

function submitCallbackForm() {    
    //check the telephone number first... no point letting them ask for a callback if there's no number :-p
    var telephone1 = $("#cmb-telephone1").val();
    var telephone2 = $("#cmb-telephone2").val();
    if (telephone1.length == 0)
    {
        alert("Please enter a phone number in the 'Telephone 1' field");
        return;
    }
    var name = $("#cmb-name").val();
    var email = $("#cmb-email").val();
    var productid = $("#cmb-prodid").val();
    var reason = $("#cmb-reason option:selected").val();
    var time = $("#cmb-time option:selected").val();
    
    var url = "/submitCallbackForm.aspx";
    var data = "type=ajax&cmb-name=" + name + "&cmb-email=" + email + "&cmb-telephone1=" + telephone1 + "&cmb-telephone2=" + telephone2 + "&cmb-prodid=" + productid + "&cmb-reason=" + reason + "&cmb-time=" + time;
    var response = $.ajax(
    {
        type: "POST",
        url: url,
        data: data,
        complete: function(response)
        { 
            var rsp = response.responseText;
            if (rsp == "SUCCESS")
            {
                $(".cmbEntryForm").css("display", "none");
                $(".cmbSuccess").css("display", "block");
                $(".cmbError").css("display", "none");
            }
            else 
            {
                $(".cmbEntryForm").css("display", "none");
                $(".cmbSuccess").css("display", "none");
                $(".cmbError").css("display", "block");
            }
        }
    });
}

function submitPriceMatchForm()
{
    var name = $("#pmName").val();
    var email = $("#pmEmail").val();
    var telephone = $("#pmTelephone").val();
    var priceOption = $(".pmOption:checked").val();
    var priceFound = $("#pmPrice").val();
    var location = $("#pmLocation").val();
    var otherInfo = $("#pmOtherInfo").val();

    //verify the price to make sure it is actually a number
    var priceValidate = priceFound.replace(/&pound;/ig, "").replace(/£/ig, "");
    if (isNaN(priceValidate)) {
        //they can bob off!
        alert("Please enter a valid price in the format: 99.99");
        return;
    }
    
    var url = "/submitPriceBeaterForm.aspx";
    var data = "type=ajax&pmName=" + name + "&pmEmail=" + email + "&pmTelephone=" + telephone + "&pmOption=" + priceOption + "&pmPrice=" + priceFound + "&pmLocation=" + location + "&pmOtherInfo=" + otherInfo;
    var response = $.ajax(
    {
        type: "POST",
        url: url,
        data: data,
        complete: function(response)
        { 
            var rsp = response.responseText;
            if (rsp == "SUCCESS")
            {
                $(".pmEntryForm").css("display", "none");
                $(".pmSuccess").css("display", "block");
                $(".pmError").css("display", "none");
            }
            else 
            {
                $(".pmEntryForm").css("display", "none");
                $(".pmSuccess").css("display", "none");
                $(".pmError").css("display", "block");
            }
        }
    });
}

function submitAskAQuestionForm(productid)
{
    var firstname = $("#aqFirstname").val();
    var surname = $("#aqSurname").val();
    var email = $("#aqEmail").val();
    var telephone = $("#aqTelephone").val();
    var question = $("#aqQuestion").val();
    
    var url = "/submitQuestionForm.aspx";
    var data = "type=ajax&productid=" + productid + "&aqFirstname=" + firstname + "&aqSurname=" + surname + "&aqEmail=" + email + "&aqTelephone=" + telephone + "&aqQuestion=" + question;
    var response = $.ajax(
    {
        type: "POST",
        url: url,
        data: data,
        complete: function(response)
        { 
            var rsp = response.responseText;
            if (rsp == "SUCCESS")
            {
                $(".aqEntryForm").css("display", "none");
                $(".aqSuccess").css("display", "block");
                $(".aqError").css("display", "none");
            }
            else 
            {
                $(".aqEntryForm").css("display", "none");
                $(".aqSuccess").css("display", "none");
                $(".aqError").css("display", "block");
            }
        }
    });
}

function showMayDayDelivery2010Popup() {
    triggerMacBox({
        boxID: "MayDayDelivery2010",
        width: 500,
        ajaxUrl: "/MayDayDelivery2010/MayDayDelivery2010AJAX.aspx"
    });
}
function showDeliveryTimesEstPopup() {
    triggerMacBox({
        boxID: "DeliveryTimesEst",
        width: 400,
        ajaxUrl: "/CategoryPage/UserControls/delivery-times.aspx"
    });
}

///// RECOMMENDED PARASOLS LIGHTBOX /////
function showRecomendedParasolPopup() {
    triggerMacBox({
        boxID: "RecomendedParasol",
        width: 500,
        ajaxUrl: "/ProductPage/CustomProducts/RecomendParasols.aspx"
    });
}
///// RECOMMENDED CUSHIONS LIGHTBOX /////
function showRecomendedCushionsPopup() {
    triggerMacBox({
        boxID: "RecomendedCushions",
        width: 500,
        ajaxUrl: "/ProductPage/CustomProducts/RecomendCushions.aspx"
    });
}
///// INCLUDED PARASOLS LIGHTBOX /////
function showIncludedParasolPopup() {
    triggerMacBox({
        boxID: "IncludedParasol",
        width: 500,
        ajaxUrl: "/ProductPage/CustomProducts/IncludedParasols.aspx"
    });
}
///// INCLUDED CUSHIONS LIGHTBOX /////
function showIncludedCushionsPopup() {
    triggerMacBox({
        boxID: "IncludedCushions",
        width: 500,
        ajaxUrl: "/ProductPage/CustomProducts/IncludedCushions.aspx"
    });
}

$(document).ready(function() {
    //May Day Delivery 2010 links
    $(".MayDayDelivery2010Link").click(function(e) {
        e.preventDefault();
        showMayDayDelivery2010Popup();
    });
    $(".DeliveryTimesEstLink").click(function(e) {
        e.preventDefault();
        showDeliveryTimesEstPopup();
    });

    //Included items popups
    $(".IncludedCushionsLink").click(function(e) {
        e.preventDefault();
        showIncludedParasolPopup();
    });
    $(".IncludedParasolLink").click(function(e) {
        e.preventDefault();
        showIncludedParasolPopup();
    });
    $(".RecomendedCushionsLink").click(function(e) {
        e.preventDefault();
        showRecomendedParasolPopup();
    });
    $(".RecomendedParasolLink").click(function(e) {
        e.preventDefault();
        showRecomendedParasolPopup();
    });

    //if we're on a category page...
    var catContainer = $("#category-container");
    if ($(catContainer)[0] != null) {
        //...sort out the padding at the bottom for the absolute positioned description text
        var catOpeningText = ("#opening-text");
        $(catContainer).css("padding-bottom", $(catOpeningText).height() + 20);
    }
});
