	$(document).ready(function () {
		atmp = window.location.pathname.split('/');
		if ( atmp == "order.php"){
			updateIt(0);
			$("input[name='quanity']").text(0);
		}

	$(":checkbox").click(function() {
		//alert("click");
		if($(this).attr("name") == "StoB") {
			var tmp = $("input[name^='s']");
			tmp.push($("select[name='sState']").get(0));
			tmp.push($("select[name='sCountry']").get(0));
			var chkd = $(":checkbox").get(0)
			chkd = chkd.checked;	
			jQuery.each(tmp, function() {
				nm = $(this).attr("name").substr(1);
				bnm = 'b'+nm; shnm = 's'+nm;
				if(chkd) {
					if($(this).attr("type") == 'text') {
						$("input[name='"+bnm+"']").val($("input[name="+shnm+"]").val());
					} else {
						$("select[name='"+bnm+"']").
							attr("selectedIndex", 
							$("select[name='"+shnm+"']").attr("selectedIndex"));
							$("#id_bState").trigger('change');
					}
				} 
			});
			}
		});
		

	
	$("input[name='quanity']").change (function(){
		updateIt($("input[name='quanity']").val());
	});
	$("input[name='quanity']").blur (function(){
		updateIt($("input[name='quanity']").val());
	});
	$("input[name='quanity']").select (function(){
		updateIt($("input[name='quanity']").val());
	});
		
	});
	
	function updateIt(unit) {
		cCost = unit*cost;
		cCost = cCost.toFixed(2)
		$("#stotal").html("$"+cCost);
		subtotal = cCost;
		tsandh = (unit*sandh).toFixed(2);
		$("#sh").html("$"+tsandh);
		total = (unit*cost)+(unit*sandh)+ttax;
		$("#total").html("$"+total.toFixed(2));
	
	}

	var bill = new Object();
	var ship = new Object();
	var card = new Object();
	
	function doIt() {
		abill = $("input[name^='s'],select[name^='b'],input[name='email']");
		aship = $("input[name^='b'],select[name^='s']");
		acard = $("input[name^='c'],select[name^='c']");
		jQuery.each(abill, function (){
			bill[$(this).attr('name')] = $(this).val();	
		});
		jQuery.each(aship, function (){
			ship[$(this).attr('name')] = $(this).val();	
		});
		jQuery.each(acard, function (){
			card[$(this).attr('name')] = $(this).val();	
		});
	}
	
	
	function buyNow(type){
		switch (type) {
			case "paypal":
				//var target = "https://www.sandbox.paypal.com/cgi-bin/webscr";
				var target = "https://www.paypal.com/cgi-bin/webscr";
				var cInputs = {"cmd":"_xclick",
					"business":"promotiondenied@qwestoffice.net",
					"currency_code":"USD",
					"item_name":"Promotion: Denied"
					};
				break;
			case "email":
				if(window.location.hostname == 'uriel') {
					var target = "./info.php";	
				} else {
					var target = "https://barakael.thegreate-scape.net/~josephwh/info.php";
				}
				
				var cInputs= {};
				break;
		}
		if($("select[name='bState']").val() == "CO") {
			tax = 7.4;
		} else {
			tax = 0;
		}
		ppLink = document.createElement("form");
		ppLink.action = target;
		ppLink.method="post";
		cInputs["item_name"] = "Promotion: Denied";
		cInputs["quantity"] =$("input[name='quanity']").val();
		cInputs["amount"] = cost;
		cInputs["shipping"] = sandh;
		cInputs["shipping2"] = sandh;
		cInputs["tax_rate"] = tax;

		for(var inp in cInputs) {
		    var myInput = document.createElement("input") ;
		    myInput.type="hidden";
		    myInput.setAttribute("name", inp) ;
		    myInput.setAttribute("value", cInputs[inp]);
		    ppLink.appendChild(myInput);
		}
		document.body.appendChild(ppLink);
		ppLink.submit();
		document.body.removeChild(ppLink);
	}
