var status = false;
function CheckDecision(){
	if (document.OForm.cbxSame.checked){
		status=true;
		document.OForm.txtLastNameS.value= document.OForm.txtLName.value;
		document.OForm.txtFirstNameS.value= document.OForm.txtFName.value;
		document.OForm.txtAddress1S.value= document.OForm.txtAddress1.value;
		document.OForm.txtAddress2S.value= document.OForm.txtAddress2.value;
		document.OForm.txtCityS.value= document.OForm.txtCity.value;
		document.OForm.txtStateS.value= document.OForm.txtState.value;
		document.OForm.drpStateS.value= document.OForm.drpState.value;
		document.OForm.txtZipS.value= document.OForm.txtZip.value;
		document.OForm.CountryS.value= document.OForm.Country.value;
		document.OForm.txtPhoneS.value= document.OForm.txtPhone.value;
		document.OForm.txtEmailS.value= document.OForm.txtEmail.value;		
	}
	else{
		status=false;
	}

	if(document.OForm.Country.value!='United States'){
		document.OForm.txtState.style.visibility="visible";
		document.OForm.txtState.style.display="block";

		document.OForm.drpState.style.visibility="hidden";
		document.OForm.drpState.style.display="none";
	}
	else{
		document.OForm.drpState.style.visibility="visible";
		document.OForm.drpState.style.display="block";

		document.OForm.txtState.style.visibility="hidden";
		document.OForm.txtState.style.display="none";
	}

	if(document.OForm.CountryS.value!='United States'){
		document.OForm.txtStateS.style.visibility="visible";
		document.OForm.txtStateS.style.display="block";

		document.OForm.drpStateS.style.visibility="hidden";
		document.OForm.drpStateS.style.display="none";
	}
	else{
		document.OForm.drpStateS.style.visibility="visible";
		document.OForm.drpStateS.style.display="block";

		document.OForm.txtStateS.style.visibility="hidden";
		document.OForm.txtStateS.style.display="none";
	}

	MakeReadOnlys();
	SumIt();
}
function MakeReadOnlys(){
	document.OForm.txtLastNameS.readOnly= status;
	document.OForm.txtFirstNameS.readOnly= status;
	document.OForm.txtAddress1S.readOnly= status;
	document.OForm.txtAddress2S.readOnly= status;
	document.OForm.txtCityS.readOnly= status;
	document.OForm.txtStateS.readOnly= status;
	document.OForm.txtZipS.readOnly= status;
	document.OForm.CountryS.disabled = status;
	document.OForm.txtPhoneS.readOnly= status;
	document.OForm.txtEmailS.readOnly=status;
}


function SetText(obj,text){
	if(document.all){
		obj.innerText = text;
	}
	else{
		obj.textContent = text;
	}
}
function GetText(obj){
	if(document.all){
		return obj.innerText;
	}
	else{
		return obj.textContent;
	}
}
function SumIt(){
	//book
	var Quantity = document.getElementById("txtNumber");
	var discount = document.getElementById("lblDiscount");
	//audio
	var Quantity2 = document.getElementById("txtNumber2");
	var discount2 = document.getElementById("lblDiscount2");
	var discount3 = document.getElementById("lblDiscount3");

	var TotalAmount = document.getElementById("TotalAmount");
	var TaxAmount = document.getElementById("TaxAmount");
	var ShippingAmount = document.getElementById("ShippingAmount");
	//var CopiesAmount = document.getElementById("CopiesAmount");
	//var CopiesAmount2 = document.getElementById("CopiesAmount2");
	var ShippingNote = document.getElementById("ShippingNote");
	var TaxNote = document.getElementById("TaxNote");
	//var cbxMAResident = document.getElementById("cbxMAResident");

	var hBooksCost = document.getElementById("hBooksCost");
	var hTaxCost = document.getElementById("hTaxCost");
	var hShippingCost = document.getElementById("hShippingCost");
	var hTotalCost = document.getElementById("hTotalCost");	
	var hCallSupport = document.getElementById("hCallSupport");	
	var hTotalCopies = document.getElementById("hTotalCopies");

	var TotalCopies = document.getElementById("TotalCopies");	
	var TotalBooksAmount = document.getElementById("TotalBooksAmount");		

	TaxNote.innerText='';
	ShippingNote.innerText='';		
	
	var PerCopyCost = 1;
	var PerCopyCost2 = 0;
	var ShippingCost = 1;
	var q = 0;
	var q2 = 0;
	var tax = 0;
	var TotalQuantity = 0; 
	var CallSupport = false;

	SetText(TotalAmount,"");	
	SetText(TotalBooksAmount,"");
	SetText(discount,"");		
	SetText(discount2,"");
	SetText(discount3,"");
//	SetText(CopiesAmount,"");		
//	SetText(CopiesAmount2,"");		
	SetText(TotalBooksAmount,"");		
	SetText(TotalCopies,"");
	SetText(TaxAmount,"");
	SetText(ShippingAmount,"");
	SetText(ShippingNote,"");

	hBooksCost.value = "";
	hTaxCost.value = "";
	hShippingCost.value = "";
	hTotalCost.value = "";
	hCallSupport.value = false;
	hTotalCopies.value="";

	if( !isNaN(Quantity.value) )
	{
		q = parseInt(Quantity.value);
		if(q>0){
			TotalQuantity = q;
		}
		else{
			TotalQuantity = 0;
		}
	}
	else{
		SetText(discount,"Invalid amount.");
		TotalQuantity = 0;
	}

	if( !isNaN(Quantity2.value) )
	{
		q2 = parseInt(Quantity2.value);		
		if(q2>0){
			TotalQuantity += q2;
		}
	}
	else{
		SetText(discount2,"Invalid amount.");
		TotalQuantity += 0;
	}

	if(TotalQuantity!=null && TotalQuantity >0){

		var totalcost=0;

		if(TotalQuantity==1){
			PerCopyCost = 14.95;
		}
		else if(TotalQuantity==2){
			PerCopyCost = 13.46;
			SetText(discount3,"2 copies @ 10% Discount: $13.46 each");
		}
		else if(TotalQuantity<6){
			PerCopyCost = 12.70;
			SetText(discount3,TotalQuantity + " copies @ 15% Discount: $12.70 each");
		}
		else if(TotalQuantity>5 && TotalQuantity<20){
			PerCopyCost = 11.96;
			SetText(discount3,TotalQuantity + " copies @ 20% Discount: $11.96 each");
		}
		else if(TotalQuantity>19){
			PerCopyCost = 11.96;
			PerCopyCost = 0;
			CallSupport = true;
			hCallSupport.value = "true";
			//SetText(discount3,"Please call for pricing/discount details.");
		}

		//books totals have already been added together now.
		SetText(TotalCopies,TotalQuantity);

		if(!CallSupport){
			totalcost = TotalQuantity * PerCopyCost;	
			SetText(TotalBooksAmount, "$" + totalcost.toFixed(2));			
		}

		if(document.OForm.CountryS.value!='United States'){
			ShippingCost = 0;
			SetText(ShippingAmount,"**Shipping could not added for non US orders");
			SetText(ShippingNote," * Shipping has not been included");
			CallSupport = true;
			hCallSupport.value = "true";
		}else{
			if(document.OForm.drpStateS.value=='MA'){
				var tax = totalcost * .05;
				//alert("totalcost " + totalcost + "*.05= "+ totalcost * .05);
				SetText(TaxNote," MA 5% Tax");
				SetText(TaxAmount,"$" + tax.toFixed(2));
				totalcost += tax;
				hTaxCost.value = GetText(TaxAmount);
			}
		}

		if( TotalQuantity>0 && TotalQuantity<4 ){
			ShippingCost = 5;
			SetText(ShippingAmount,"$5.00");
		}
		else if(TotalQuantity<11){
			ShippingCost = 7;
			SetText(ShippingAmount,"$7.00");
		}
		else if( TotalQuantity > 10 ){
			ShippingCost = 0;			
			//SetText(ShippingAmount,"USA  10+ copies:  please call for USA shipping/handling fee.");
			SetText(ShippingNote," * Shipping has not been included");
			CallSupport = true;
			hCallSupport.value = "true";
		}

		if(!CallSupport){
			totalcost+=ShippingCost;
			SetText(TotalAmount,"$"+ totalcost.toFixed(2));
		}
		else{
			SetText(TotalAmount,"Please call for pricing/discount details.");
			SetText(ShippingAmount,"");
			SetText(discount3,"");
			//SetText(ShippingNote,"");
			hTaxCost.value = "";
		}
	}
	else{
		SetText(TotalAmount,"");
	}

	hBooksCost.value = GetText(TotalBooksAmount);

	hTotalCopies.value = TotalQuantity + " &nbsp;&nbsp; " + GetText(discount3);

	hTaxCost.value = GetText(TaxAmount) + " &nbsp;&nbsp; " + GetText(TaxNote) ;

	hShippingCost.value = GetText(ShippingAmount) + " &nbsp;&nbsp; " + GetText(ShippingNote);

	hTotalCost.value = GetText(TotalAmount);


return false;




}
