function calculate_shippingRates(products_weight, zip_code) {
	x_calculate_shippingRates(products_weight, zip_code, calculate_shippingRates_cb);		
}

function calculate_shippingRates_cb(output) {	
	var decoded_output = output.replace(/^:/, "");
	var shipping_info = JSON.parse(decoded_output); //encode the string
	
	if (validate_attr()){
		var weightCalc = document.frm_poster.total_weight.value;
		var weighZipCode = document.frm_poster.zip_code.value;
		
		if(weightCalc && weighZipCode) {
			html_output = '<br />';
			html_output += '<table align="center" bgcolor="#FFFFFF" border="0" cellspacing="0" cellpadding="10" width="100%">\n';
			html_output += '	<tr>\n';
			html_output += '		<td>\n';
			html_output += '			<table align="center" border="0" bgcolor="#FFFFFF" cellspacing="0" cellpadding="0" width="90%">\n';
			html_output += '			<tr>\n';
			html_output += '				<td colspan="3" style="font-size:11px; text-align:center; color:#666666;"><strong>Shipping Rates '+shipping_info[1]['module'].replace('United Parcel Service','')+'</strong></td>\n';
			html_output += '			</tr>\n';
			html_output += '			<tr>\n';
			html_output += '				<td colspan="3">&nbsp;</td>\n';
			html_output += '			</tr>\n';
			html_output += '			<tr>\n';
			html_output += '				<td width="82%" style="font-size:11px; color:#666666;">'+shipping_info[1]['methods'][6]['title']+'</td>\n';
			html_output += '				<td width="2%" style="font-size:11px; color:#666666;">$</td>\n';
			
			
			// Uncomment this if Geound Shipping is not free
			//html_output += '				<td width="16%" style="font-size:11px; color:#666666; text-align:right;">'+shipping_info[1]['methods'][6]['cost']+'</td>\n';
			
			// Free Ground Shipping
			html_output += '				<td width="16%" style="font-size:11px; color:#666666; text-align:right;">0.00</td>\n';
			
			
			html_output += '			</tr>\n';
			html_output += '			<tr>\n';
			html_output += '				<td style="font-size:11px; color:#666666;">'+shipping_info[1]['methods'][3]['title']+'</td>\n';
			html_output += '				<td style="font-size:11px; color:#666666;">$</td>\n';
			html_output += '				<td style="font-size:11px; color:#666666; text-align:right;">'+shipping_info[1]['methods'][3]['cost']+'</td>\n';
			html_output += '			</tr>\n';
			html_output += '			<tr>\n';
			html_output += '				<td style="font-size:11px; color:#666666;">'+shipping_info[1]['methods'][1]['title']+'</td>\n';
			html_output += '				<td style="font-size:11px; color:#666666;">$</td>\n';
			html_output += '				<td style="font-size:11px; color:#666666; text-align:right;">'+shipping_info[1]['methods'][1]['cost']+'</td>\n';
			html_output += '			</tr>\n';
			html_output += '			<tr>\n';
			html_output += '				<td colspan="3">&nbsp;</td>\n';
			html_output += '			</tr>\n';
			html_output += '			<tr>\n';
			html_output += '				<td style="font-size:11px; color:#666666;">Store Pickup</td>\n';
			html_output += '				<td style="font-size:11px; color:#666666;">$</td>\n';
			html_output += '				<td style="font-size:11px; color:#666666; text-align:right;">'+shipping_info[0]['methods'][0]['cost']+'</td>\n';
			html_output += '			</tr>\n';
			html_output += '			</table>\n';
			html_output += '		</td>\n';
			html_output += '	</tr>\n';
			html_output += '</table>\n';


			
			
			document.getElementById('result_shippingRates').innerHTML = html_output;
		} else {
			alert('Please enter a zipcode to calculate the shipping rate.');
		}
	
	} else {
		alert('Please select a product before calculating the shipping rate.');
	}
	
}

	function validate_attr() {
	
		frm = document.frm_poster;
		
		quantity = frm.quantity.value;
		area = frm.area.value;
		total_weight = frm.total_weight.value;
		
		if(quantity == 0 || area == 0 || total_weight == 0) {
			return false;
		} else {
			return true;
		}
		
		
	
	
	}

