// JavaScript Document

	jQuery.noConflict();
	
jQuery(document).ready(function()
{
	
//google.setOnLoadCallback(function() {

	
		jQuery("#spinner").bind("ajaxSend", function() {
		jQuery(this).show();
	}).bind("ajaxStop", function() {
		jQuery(this).hide();
	}).bind("ajaxError", function() {
		jQuery(this).hide();
	});


	var total = 0;
	
	function calcTotal()
	{
		
		//subtotal
		var currentTotal = jQuery("td.subTotal").text(); 
		currentTotal = currentTotal.replace('$', "").replace(',', "");
		
		//ship total
		
		var shiptotal1 = 0;
		
		shiptotal1 = jQuery("span.shiptotal").text();
		shiptotal1 = shiptotal1.replace('$', "");

		
		//tax total
		var taxTotal = jQuery('span.taxTotal').text();
		//alert (txTotal);
		if (taxTotal != ''){ 
		//alert('hi');
			taxTotal = taxTotal.replace('$', "");		
			var total1 ='$' + (parseFloat(shiptotal1) + parseFloat(currentTotal) + parseFloat(taxTotal)).toFixed(2); 
		
		} else {
		
			var total1 ='$' + (parseFloat(shiptotal1) + parseFloat(currentTotal)).toFixed(2); 
		}
		
		jQuery("strong.total").html("<strong>" + total1 + "</strong>");	
				
	}




	


//for shipping estimater 
var zip;

jQuery ("input[name='zip']").keypress(function(e) {

if (e.keyCode == 13){

		jQuery ("input#calclick").focus();
		zip = ship_est();
	
}else return e.keyCode;

});

	jQuery ('.error').hide();
	
	//jQuery("input[name='submit_ship_est']").click(ship_est());
	jQuery ("input#calclick").click(function(){ship_est()});
	

function ship_est(){	
	//jQuery("input[name='submit_ship_est']").live('click' , function()
	//{

		if (zip == jQuery("input[name='zip']").val()) return false; //if they put in the same zip as last time then dont do anything
		nocache = Math.random(); 
		jQuery ('.error').hide();
		
		jQuery ("div#error_wrap").animate({
					//backgroundColor: "#f9f9f9",
					borderTopColor: "#f9f9f9",
					borderBottomColor: "#f9f9f9",
					borderLeftColor: "#f9f9f9",
					borderRightColor: "#f9f9f9"
					}, 'fast' );
		
		
		zip = jQuery("input[name='zip']").val();
		
		
		if (zip == "") {
			//jQuery ("label#zip_error").show();
			
			jQuery ("label#zip_error").fadeIn("slow");
			jQuery ("div#error_wrap").animate({
								//backgroundColor: "#c86161",
								borderTopColor: "#eec5c5",
								borderBottomColor: "#eec5c5",
								borderLeftColor: "#eec5c5",
								borderRightColor: "#eec5c5"
								}, 100 );
			
			
			jQuery ("input#zip").focus();
			
			return false;
		}
		
		//alert (zip);
		jQuery('#shipest').load('administrator/components/com_virtuemart/classes/shipping/ajaxship.php?zip=' + zip + '&nocache=' + nocache + ' #shipestimates', function(){
			
			var shipest = jQuery ("#ship_select").val();

			if (shipest){
				jQuery("span.shiptotal").html('$' + shipest);
				calcTotal();
			}
			
	
		});

	return zip;		
		
	//});
	
} //end function ship_est
	
    jQuery ("#ship_select").live('change',function () {
    		  
		var shipest = jQuery (this).val();
		jQuery("span.shiptotal").html('$' + shipest);
    		
		calcTotal();
    
	});
		
        

	
}); //end dom ready
