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;
		var shippingTypes = ["Ground","2nd Day Air","Next Day Air"];

		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';
			
			for (var i=shipping_info[1]['methods'].length-1; i>(-1); i--) {  
				for ( var j=0; j<shippingTypes.length; j++) {
					if(shippingTypes[j]==shipping_info[1]['methods'][i]['title']) {
						if(shipping_info[1]['methods'][i]['title']=='Ground') {
			html_output += '				<tr>\n';
			html_output += '					<td style="font-size:11px; color:#666666;">'+shipping_info[1]['methods'][i]['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;">0.00</td>\n';
			html_output += '				</tr>\n';
						} else {
			html_output += '				<tr>\n';
			html_output += '					<td style="font-size:11px; color:#666666;">'+shipping_info[1]['methods'][i]['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'][i]['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;
		}
		
		
	
	
	}
