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) {

			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 += '<div id="radioShip0" class="ups_radio_highlight">\n';
							html_output += '	<div class="leftFloat" style="padding-top: 2px;">'+shipping_info[1]['methods'][i]['title']+'</div>\n';
							html_output += '	<div class="rightFloat" style="padding-top: 7px;"><b>$0.00</b></div>\n';
							html_output += '</div>\n';
						} else {
							html_output += '<div id="radioShip0" class="ups_radio">\n';
							html_output += '	<div class="leftFloat" style="padding-top: 2px;">'+shipping_info[1]['methods'][i]['title']+'</div>\n';
							html_output += '	<div class="rightFloat" style="padding-top: 7px;"><b>$'+shipping_info[1]['methods'][i]['cost']+'</b></div>\n';
							html_output += '</div>\n';
						}
					}
				}					
			}			
			
			document.getElementById('result_shippingRates').innerHTML = html_output;
			document.getElementById("zip_code").focus();
			
		} 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;
	}		

}

