$(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: "/shipquote/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)
	{
		//alert(data.result.failureReason);
		getQuote_Failure(null, null, null);
		return;
	}
	
    var subCatCode = 86;
    var uShipUrl = "http://www.uship.com/priceestimator/?r=452730&logo=http://www.atvquadswap.com/atv/site_atv/images/AtvQuadSwap_150pxW.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;
   		
	$('#btnGetShippingQuote').val('Get Quote').attr('disabled', false);
	$('#shipQuote').text("$" + data.result.quote)
	$('#shipQuoteUrl').attr("href", encodeURI(uShipUrl));
	$('#shipQuoteSuccess').fadeIn();
}
var ee;
function getQuote_Failure(XMLHttpRequest, textStatus, errorThrown)
{
	$('#btnGetShippingQuote').val('Get Quote').attr('disabled', false);
	$('#shipQuoteFailure').fadeIn();
}
