
//Functions for the right menu images
var html1 = "<a href=\"http://www.gardenbuildingsdirect.co.uk/Garden-Furniture\" id=\"RightCrossBanner\" rel=\"nofollow\"><img src=\"/assets/images/upsell-banners/furniture.jpg\" alt=\"Garden Furniture Now Available\" /></a>";
var html2 = "<a href=\"http://www.gardenbuildingsdirect.co.uk/Barbecues\" id=\"RightCrossBanner\" rel=\"nofollow\"><img src=\"/assets/images/upsell-banners/barbecues.jpg\" alt=\"Barbecues Now Available\" /></a>";
var html3 = "<a href=\"http://www.gardenbuildingsdirect.co.uk/Outdoor-toys\" id=\"RightCrossBanner\" rel=\"nofollow\"><img src=\"/assets/images/upsell-banners/outdoor-toys.jpg\" alt=\"Outdoor Toys Now Available\" /></a>";

var altCrossRotate = Math.floor((Math.random()*3)+1);
function rotateCrossBanner() {	
	if (altCrossRotate==1) {
		$("#linking").html(html1);
	} 
	else if (altCrossRotate==2) {
		$("#linking").html(html2);
	}
	else if (altCrossRotate==3) {
		$("#linking").html(html3);
	}
}

$(document).ready(function(){
	//For the right menu images
	rotateCrossBanner();
    //hide right menu if window is too small
    hideShowRhCol();
});
$(window).resize(function() {
    hideShowRhCol();
});
function hideShowRhCol() {
    //hide the right hand menu if the window is too small for it
    if ($(window).width() < 1090) {
        $("#rh-col2").hide();
    }
    else {
        $("#rh-col2").show();            
    }
}

function showSalesLinePopup() {
    triggerMacBox({
        boxID: "SalesLineInformation",
        width: 300,
        ajaxUrl: "/hoursinfo.aspx"
    });
}


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();
    
    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 name = $("#aqName").val();
    var email = $("#aqEmail").val();
    var telephone = $("#aqTelephone").val();
    var question = $("#aqQuestion").val();
    
    var url = "/submitQuestionForm.aspx";
    var data = "type=ajax&productid=" + productid + "&aqName=" + name + "&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");
            }
        }
    });
}