// JavaScript Document
var total=0;
var subtotal=0;
var shipping=0;

var c1=2995;
var c2=1895;
var c3=1695;
var c4=1995;
var c5=399;

var p;
var total2=0;
var sh=0;

function DblToStr(number,decimals) {
	var newString;// The new rounded number
	decimals = Number(decimals);
	if (decimals < 1) {
		newString = (Math.round(number)).toString();
	} else {
		var numString = number.toString();
		if (numString.lastIndexOf(".") == -1) {// If there is no decimal point
			numString += ".";// give it one at the end
		}
		var cutoff = numString.lastIndexOf(".") + decimals;// The point at which to truncate the number
		var d1 = Number(numString.substring(cutoff,cutoff+1));// The value of the last decimal place that we'll end up with
		var d2 = Number(numString.substring(cutoff+1,cutoff+2));// The next decimal, after the last one we want
		if (d2 >= 5) {// Do we need to round up at all? If not, the string will just be truncated
			if (d1 == 9 && cutoff > 0) {// If the last digit is 9, find a new cutoff point
				while (cutoff > 0 && (d1 == 9 || isNaN(d1))) {
					if (d1 != ".") {
						cutoff -= 1;
						d1 = Number(numString.substring(cutoff,cutoff+1));
					} else {
						cutoff -= 1;
					}
				}
			}
			d1 += 1;
		} 
		newString = numString.substring(0,cutoff) + d1.toString();
	}
	if (newString.lastIndexOf(".") == -1) {// Do this again, to the new string
		newString += ".";
	}
	var decs = (newString.substring(newString.lastIndexOf(".")+1)).length;
	for(var i=0;i<decimals-decs;i++) newString += "0";
	//var newNumber = Number(newString);// make it a number

	return newString;
}

function count() {

total=0;
subtotal=0;
shipping=0;
total2=0;
sh=0;

document.forms.BB_BuyButtonForm.item_name_1.value = '';

if (document.forms.buyform.p1.checked  == true) {
	subtotal += c1;
	sh += 1;
	p = (c1)/100;
	document.getElementById('d1').innerHTML='$'+p;
	document.forms.BB_BuyButtonForm.item_name_1.value = document.forms.BB_BuyButtonForm.item_name_1.value + 'Social Networking Deluxe Pack';
} else {
	document.getElementById('d1').innerHTML='-';
}


if (document.forms.buyform.p2.checked  == true) {
	subtotal += c2;
	sh += 1;
	p = (c2)/100;
	document.getElementById('d2').innerHTML='$'+p;
	document.forms.BB_BuyButtonForm.item_name_1.value = document.forms.BB_BuyButtonForm.item_name_1.value + 'Social Networking Paperback';
} else {
	document.getElementById('d2').innerHTML='-';
}

if (document.forms.buyform.p3.checked  == true) {
	subtotal += c3;
	p = (c3)/100;
	document.getElementById('d3').innerHTML='$'+p;
	document.forms.BB_BuyButtonForm.item_name_1.value = document.forms.BB_BuyButtonForm.item_name_1.value + 'Social Networking Ebook';
} else {
	document.getElementById('d3').innerHTML='-';
}

if (document.forms.buyform.p4.checked  == true) {
	subtotal += c4;
	p = (c4)/100;
	document.getElementById('d4').innerHTML='$'+p;
	document.forms.BB_BuyButtonForm.item_name_1.value = document.forms.BB_BuyButtonForm.item_name_1.value + 'Social Networking Videos; ';
} else {
	document.getElementById('d4').innerHTML='-';}

if (document.forms.buyform.p5.checked  == true) {
	subtotal += c5;
	p = (c5)/100;
	document.getElementById('d5').innerHTML='$'+p;
	document.forms.BB_BuyButtonForm.item_name_1.value = document.forms.BB_BuyButtonForm.item_name_1.value + 'Shipping Upgrade';
} else {
	document.getElementById('d5').innerHTML='-';
}

if (sh == 1) {shipping = 315;}
if (sh >= 2) {shipping = 315;}
if (sh >= 3) {shipping = 315;}


subtotal = DblToStr(subtotal / 100, 2);
shipping = DblToStr(shipping / 100, 2);
if (shipping == 0) {document.getElementById('ship').innerHTML='-';} else {document.getElementById('ship').innerHTML='$'+shipping;}
if (subtotal == 0) {document.getElementById('stot').innerHTML='-';} else {document.getElementById('stot').innerHTML='$'+subtotal;}

document.forms.BB_BuyButtonForm.item_price_1.value = subtotal;
document.forms.BB_BuyButtonForm.ship_method_price_1.value = shipping;

subtotal = Number(subtotal) * 100;
shipping = Number(shipping) * 100;

total = subtotal + shipping;

if (total == 0) {document.getElementById('tot').innerHTML='-';} else {p = DblToStr(Math.round(total)/100, 2); document.getElementById('tot').innerHTML='$'+p; } 
total2=total;

}
