$(document).ready(function () { $('#btnGetShippingQuote').click(getQuote); });

function getQuote()
{
    $("#shipQuoteSuccess").hide();
    $("#shipQuoteFailure").hide();

    var to = "" + $("#shipToZip").val();
    var from = sq_FromZip; // Defined by the containing page template
    
    if (!to.match(/^\s*\d{5}(\-\d{4})?\s*$/))
    {
        $("#shipQuoteValidation").show();
        return;
    }
    else
        $("#shipQuoteValidation").hide();

    $('#btnGetShippingQuote').val('Please wait...').attr('disabled', true);
    $.ajax({
        url: "lib/shipquote.php?from=" + from + "&to=" + to,
        cache: false,
        dataType: "json",
        success: getQuote_Success,
        error: getQuote_Failure
    });
}

function getQuote_Success(data, textStatus)
{
    if (data == null || data.result == null || !data.result.success)
    {
        getQuote_Failure(null, null, null);
        return;
    }

    var subCatCode = 79;
    var uShipUrl = "http://www.uship.com/priceestimator/?r=721166&logo=http://www.supercardirect.com/system/modules/main/user/templates/supercar/images/supercardir_img.gif&s=" + subCatCode + "&z1=" + data.result.fromZip + "&z2=" + data.result.toZip;
  
    if (typeof sq_Title !="undefined" && sq_Title != null && sq_Title != "") // sq_Title is defined by the containing page template
        uShipUrl += "&t=" + sq_Title;
    if (typeof sq_ImageUrl != "undefined" && sq_ImageUrl != null && sq_ImageUrl != "") // sq_ImageUrl is defined by the containing php script
        uShipUrl += "&iurl=" + sq_ImageUrl;
    if (typeof sq_Make != "undefined" && sq_Make != null && sq_Make != "") // sq_Make is defined by the containing php script
        uShipUrl += "&make=" + sq_Make;
    if (typeof sq_Model != "undefined" && sq_Model != null && sq_Model != "") // sq_Model is defined by the containing php script
        uShipUrl += "&model=" + sq_Model;
    if (typeof sq_Year != "undefined" && sq_Year != null && sq_Year != "") // sq_Year is defined by the containing php script
        uShipUrl += "&year=" + sq_Year;
           
    $('#btnGetShippingQuote').val('Get Quote').attr('disabled', false);
    $('#shipQuote').text("$" + data.result.quote);
    $('#shipQuoteUrl').attr("href", encodeURI(uShipUrl));
//    $('#shipQuoteUrl').attr("href", encodeURI(data.result.url));
    $('#shipQuoteSuccess').fadeIn();
}

var ee;

function getQuote_Failure(XMLHttpRequest, textStatus, errorThrown)
{
    $('#btnGetShippingQuote').val('Get Quote').attr('disabled', false);
    $('#shipQuoteFailure').fadeIn();
}
