// JavaScript Document

function swap_ship_location(){
        var us_shipping = document.getElementById("us_shipping");
        var country_shipping = document.getElementById("country_shipping");
        var domestic = document.getElementById("Domestic");
        if(domestic.checked == true)
        {
                us_shipping.style.display = "inline";
                country_shipping.style.display = "none";
        }
        else
        {
                us_shipping.style.display = "none";
                country_shipping.style.display = "inline";
        }
}


function update_total()
{
		var choose_shipping = document.getElementById("choose_shipping");
		var sub_total = document.getElementById("sub_total");
		var shipping_price = document.getElementById("shipping_price");
		var grand_total = document.getElementById("grand_total");
		if(document.getElementById("tax"))
			var tax = parseFloat(document.getElementById("tax").innerHTML);
		else
			var tax = 0;
		if(document.getElementById("ship_index"))
		{
			var ship_index = document.getElementById("ship_index");
			ship_index.value = choose_shipping.selectedIndex;
		}
				
		shipping_price.innerHTML = '$' + choose_shipping.options[choose_shipping.selectedIndex].value;
		grand_total.innerHTML = addCommas((parseFloat(choose_shipping.options[choose_shipping.selectedIndex].value) + parseFloat(remove_Commas(sub_total.innerHTML)) + tax).toFixed(2));
		
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function remove_Commas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /,/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx,'');
	}
	return x1 + x2;
}