
function prepare_ajax_get_estimate()
{
	setQtyField();
		if (userState != '' && userZipcode != '' && userCity != '') 
		{
			document.getElementById('s_state').value = userState;
			document.getElementById('s_city').value = userCity;
			var sel = document.getElementById('s_stateX');
			var opts = sel.options;
			for (var i in opts)
			{
				if (opts[i].value == userState)
				{
					document.getElementById('s_stateX').selectedIndex = i;
					break;
				}
			}
			document.getElementById('s_city').value = userCity;
		}	
}
	function ajax_get_estimate() 
	{
		if(userState == ''){if ($('input[name=s_state]').val() != '') userState = $('input[name=s_state]').val();}
		if(userZipcode == ''){ if ($('input[name=s_zipcode]').val() != '') userZipcode = $('input[name=s_zipcode]').val();}
		if(userCity == ''){	if ($('input[name=s_city]').val() != '')	userCity = $('input[name=s_city]').val();}
		
		
		if (userState == '' || userZipcode == '' || userCity == '') 
		{
			$('#ajaxQuickShipEstimateTxt').html('Please insure you have entered all the required information');	
			return false;
		}
		if ($('#check1').checked == false && $('#check2').checked == false)
		{
			$('#ajaxQuickShipEstimateTxt').html('Please select what you would like the estimate for!');	
			return false;
		}
		
		
		var data = new Object(); 
		  data.s_country = 'US'; 
		  data.s_state = userState; 
		  data.s_zipcode = userZipcode; 
		  data.s_city = userCity; 
		  data.s_address = userAddress;
		  data.check1 = $('#check1')[0].checked;
		  data.check2 = $('#check2')[0].checked;
		  data.check2val = $('#check2').val();
		  data.check2qty = $('#curProdQty').val();
		  var dataString = $.toJSON(data);
		  $('#btnAjaxShip').val('Getting Estimate...');
		  $('#btnAjaxShip').attr('disabled','disabled');
		$.post('/ajax_ship_estimate.php',{ajaxdata: dataString},
				function(res){
					var obj = $.evalJSON(res);
					if (!obj.USPS || !obj.UPS )
					{
						$('#ajaxQuickShipEstimateTxt').html('There was an error processing your request.');	
					}
					else
					{
						$('#ajaxQuickShipEstimateTxt').html( obj.USPS.method + ' = $' + obj.USPS.rate + '<br/><br/>' + obj.UPS.method + ' = $' + obj.UPS.rate + '<br/><br/> <span style="color:red; font-weight:bold;">These rates are only estimates, final shipping costs will be determined at checkout.</span>');
					}
							  $('#btnAjaxShip').val('Get Estimate');
							  $('#btnAjaxShip').attr('disabled','');
			return false;
			});
	}
	function setQtyField()
	{
		if ($('#product_avail').length != 0)
		{
			$('#curProdQty').val($('#product_avail').val());
		}
			
			var bool = true;
		if (document.getElementById('check2').checked == true) 
		{	
			$('#curProd').show('fast');
			bool = false;
		}


		if(bool)	$('#curProd').hide();
		
		
	}