///scripts for conference calculations

function calculate_conference(number,type) {
	var sub_Total;
	sub_Total = document.conference_registration.amount.value;
	if (type == "team") {
		if (number == "yes") {
			sub_Total = sub_Total - 25;
			}
		if (number == "no") {
			if (sub_Total == 485) {
				sub_Total = 510;
			} else {
				sub_Total = 560;
			}
			//sub_Total = sub_Total + 25.00;
			}
		}
		
	if (type == "conf") {
		if (number == "yes") {
			sub_Total = sub_Total - 50;
			}
		if (number == "no") {
			if (sub_Total == 485) {
				sub_Total = 535;
			} else {
				sub_Total = 560;
			}

			}
		}
		
		
		
	if (type == "schol") {
		
		if (number == "yes") {
			sub_Total = sub_Total - 250;
			}
		
		if (number == "no") {

			if (sub_Total == 235) {
				sub_Total = 485;
				} else {
					if (sub_Total == 285) {
					sub_Total = 535;
					} else {
						if (sub_Total == 260) {
						sub_Total = 510;
						} else {
							sub_Total = 560;
						}
					}
				}
			}


		}
		
		
		
		

	//alert(sub_Total);	
	//Pad the shipping cost with the right number of decimals
	sub_Total = Math.round(sub_Total*100)/100;
	var tmpRate = sub_Total.toString();
	var decimal_location = tmpRate.indexOf('.');
	var rate_length = tmpRate.length;

	if (decimal_location == -1) { //begin no decimal
		tmpRate = tmpRate + '.00';
	}// end no decimals
	else { //check for one decimal
		if (rate_length - (decimal_location+1) == 1) { //begin one decimal
			tmpRate = tmpRate + '0';
		}// end one decimal
	} // end check for one decimal

	sub_Total = tmpRate.toString();
	document.conference_registration.total.value = sub_Total;
	document.conference_registration.amount.value = sub_Total;
}


function job_company() {
	var job, company;
	job = document.conference_registration.job.value;
	company = document.conference_registration.school.value;
	document.conference_registration.os0.value = job + ", " + company;
}



// scripts for SOC purchasing

function calculate_subtotal() {
	var Book_Number = document.soc_purchase.quantity.value;
	var sub_Total;
	if (Book_Number < 5) {
		sub_Total = 16.00 * Book_Number;
		document.soc_purchase.amount.value = 16.00;
	}
	else {
		sub_Total = 15.00 * Book_Number;
		document.soc_purchase.amount.value = 15.00;
		}
	document.soc_purchase.booktotal.value = pad_decimals(sub_Total);
}

function pad_decimals(startval) {
	//Pad the shipping cost with the right number of decimals
	result = Math.round(startval*100)/100;
	var tmpRate = result.toString();
	var decimal_location = tmpRate.indexOf('.');
	var rate_length = tmpRate.length;
	if (decimal_location == -1) { //begin no decimal
		tmpRate = tmpRate + '.00';
	}// end no decimals
	else { //check for one decimal
		if (rate_length - (decimal_location+1) == 1) { //begin one decimal
			tmpRate = tmpRate + '0';
		}// end one decimal
	} // end check for one decimal
	return tmpRate.toString();
}


function calculate_subtotal_combo() {
	var Book_Number = document.soc_combo_purchase.quantity.value;
	var sub_Total;
	var book_cost;
	if (Book_Number < 5) {
		book_cost = 27.00;
	}
	else {
		 book_cost = 26.00;
		}
	document.soc_combo_purchase.amount.value = book_cost;
	document.soc_combo_purchase.booktotal.value = pad_decimals(book_cost*Book_Number);
}

function calculate_shipping() { //v1.0
	var Book_Number = document.soc_purchase.quantity.value;
	var base_rate;	
	var ShipCountry = document.soc_purchase.shipcountry.value;
	var MediaBaseRate = 3.50; //2010 Base rate: 2.38 + .39 per lb
	var SinglePriority = 5.00; //2010 Base rate: 4.90 
	var BulkPriority = 11.00; //2010 Base rate: 10.70
	var IntAir = 14.00; //2010 Base (single priority - any international): 13.45
	var IntBulk = 44.00;
	
	switch (ShipCountry) {
		case 'none': //no valid shipping was chosen
			base_rate = 0;
			document.soc_purchase.custom.value = "Shipping Method: None Chosen";
			document.soc_purchase.buy.disabled = true;
		break;
		
		case 'book': //Media Rate Shipping
		    base_rate = (MediaBaseRate + (Book_Number-1)*(.75));	
			document.soc_purchase.custom.value = "Shipping Method: Domestic Media";
   			document.soc_purchase.buy.disabled = false;
		break;
		
		case 'priority': //Priority Rate Shipping
		document.soc_purchase.custom.value = "Shipping Method: Domestic Priority";
		document.soc_purchase.buy.disabled = false;
		if (Book_Number < 3) { //begin 1 book
			base_rate = SinglePriority;
			} // end 1 book
		else { //begin > 1 book
			if (Book_Number < 14) { //begin 2-10 books
				base_rate = BulkPriority ;
			} // end 2-10 books
			else { //begin > 10 books
				if (Book_Number == 14) { //begin 11 books
					base_rate = BulkPriority +SinglePriority;
				} //end 11 books
				else { //begin > 11 books
					if (Book_Number > 14) {//begin 12-30 books
						if (Book_Number == 27 ) { //begin 21 books
							base_rate = 2*BulkPriority + SinglePriority;
							} //end 21 books
							else { //begin 12-20 or 22-30 books
								if (Book_Number > 27) { //begin 22-30 books
									base_rate = 3*BulkPriority;
								} //end 22-30 books
								else { //begin 12-20 books
									base_rate = 2*BulkPriority;
								} //end 12-20 books
							} //end 12-20 or 22-30 books
					} //end 12-30 books
				} //end > 11 books
			}//end > 10 books
		} //end > 1 book
		
		//add handling fee
		base_rate = base_rate + (Book_Number) * .5;
		
		break;
		case 'air': //airmail international shippping
			document.soc_purchase.custom.value = "Shipping Method: International Airmail";
   			document.soc_purchase.buy.disabled = false;


		//determine the groups of 7 books that are required for bulk processing
		bulk_rate = (Book_Number/7|0)*IntBulk;
		
		//calculate the shipping for the other books that are not bulk
		switch (Book_Number%7) {
			case 0:
			case 1:
			case 2:
		  		indiv_rate = IntAir;
		  		break;
		 	case 3:
			case 4:
				indiv_rate = 2*IntAir;
				break;
			case 5:
			case 6:
				indiv_rate = 3*IntAir;
				break;
				
		}

		//calculate the base rate
		switch (Book_Number/7|0){
		case 0:
			base_rate = indiv_rate;
			break;
		case 1:
			base_rate = IntBulk;
			break;
		case 2:
			base_rate = indiv_rate + IntBulk;
			break;
		case 3:
			base_rate = 2*IntBulk;
			break;
		case 4:
			base_rate = 2*IntBulk + indiv_rate;
			break;
		}

		//add handling fee
		base_rate = base_rate + (Book_Number) * .5;

		break;
	}
	
	if (base_rate == 0)
	
	{
	document.soc_purchase.shipping.value = base_rate;
	document.soc_purchase.total.value = 0;
		
	}else{
	
	document.soc_purchase.shipping.value = pad_decimals(base_rate);
	
	//Update the total
	var booktotal = document.soc_purchase.booktotal.value;
	var subTotal = parseFloat(base_rate) + parseFloat(booktotal);
	document.soc_purchase.total.value = pad_decimals(subTotal);
	
	}//end base_rate = 0
}
//-->

//-->
function calculate_shipping_combo() { //v1.0
	var Book_Number = document.soc_combo_purchase.quantity.value;
	var base_rate;	
	var ShipCountry = document.soc_combo_purchase.shipcountry.value;
	var MediaBaseRate = 3.50; //2010 Base rate: 2.38 + .39 per lb
	var SinglePriority = 5.00; //2010 Base rate: 4.90 
	var BulkPriority = 11.00; //2010 Base rate: 10.70
	var IntAir = 14.00; //2010 Base (single priority - any international): 13.45
	var IntBulk = 44.00;
		
	var double_book_number = Book_Number * 2;
	
	switch (ShipCountry) {
		case 'none': //no valid shipping was chosen
			base_rate = 0;
			document.soc_combo_purchase.custom.value = "Shipping Method: None Chosen";
			document.soc_combo_purchase.buy.disabled = true;
		break;

		case 'book': //Media Rate Shipping
		    base_rate = (MediaBaseRate + (Book_Number-1)*(.75));	
			document.soc_combo_purchase.custom.value = "Shipping Method: Domestic Media";
			document.soc_combo_purchase.buy.disabled = false;

		break;
		
		case 'priority': //Priority Rate Shipping
		document.soc_combo_purchase.custom.value = "Shipping Method: Domestic Priority";
			document.soc_combo_purchase.buy.disabled = false;

		if (double_book_number < 3) { //begin 1 book
			base_rate = SinglePriority;
			} // end 1 book
		else { //begin > 1 book
			if (double_book_number < 14) { //begin 2-10 books
				base_rate = BulkPriority ;
			} // end 2-10 books
			else { //begin > 10 books
				if (double_book_number == 14) { //begin 11 books
					base_rate = BulkPriority +SinglePriority;
				} //end 11 books
				else { //begin > 11 books
					if (double_book_number > 14) {//begin 12-30 books
						if (double_book_number == 27 ) { //begin 21 books
							base_rate = 2*BulkPriority + SinglePriority;
							} //end 21 books
							else { //begin 12-20 or 22-30 books
								if (double_book_number > 27) { //begin 22-30 books
									if (double_book_number > 56) { //begin more than 28 books
										base_rate = 4*BulkPriority;
									} else {
										base_rate = 3*BulkPriority;
									}
								} //end 22-30 books
								else { //begin 12-20 books
									base_rate = 2*BulkPriority;
								} //end 12-20 books
							} //end 12-20 or 22-30 books
					} //end 12-30 books
				} //end > 11 books
			}//end > 10 books
		} //end > 1 book
		
		//add handling fee
		base_rate = base_rate + (double_book_number) * .25;

		
		break;
		case 'air': //airmail international shippping
			document.soc_combo_purchase.custom.value = "Shipping Method: International Airmail";
			document.soc_combo_purchase.buy.disabled = false;


		//determine the groups of 7 books that are required for bulk processing
		bulk_rate = (Book_Number/4|0)*IntBulk;
		
		//calculate the shipping for the other books that are not bulk
		switch (Book_Number%4) {
			case 0:
			case 1:
				indiv_rate = IntAir;
				break;
			case 2:
		  		indiv_rate = 2*IntAir;
		  		break;
		 	case 3:
				indiv_rate = 3*IntAir;
				break;
				
		}

		//calculate the base rate
		switch (Book_Number/4|0){
		case 0:
			base_rate = indiv_rate;
			break;
		case 1:
			base_rate = IntBulk;
			break;
		case 2:
			base_rate = indiv_rate + IntBulk;
			break;
		case 3:
			base_rate = 2*IntBulk;
			break;
		case 4:
			base_rate = 2*IntBulk + indiv_rate;
			break;
		case 5:
			base_rate = 3*IntBulk;
			break;
		case 6:
			base_rate = 3*IntBulk + indiv_rate;
			break;
		case 7:
			base_rate = 4*IntBulk;
			break;
		}

		//add handling fee
		base_rate = base_rate + (Book_Number) * .5;

		break;
	}
	
	document.soc_combo_purchase.shipping.value = pad_decimals(base_rate);
	
	//Update the total
	var booktotal = document.soc_combo_purchase.booktotal.value;
	var subTotal = parseFloat(base_rate) + parseFloat(booktotal);

	document.soc_combo_purchase.total.value = pad_decimals(subTotal);
}

//called by the Tucson DVD order page
function calculate_total() {
	var Book_Number = document.dvd.quantity.value;
	var ShipCountry = document.dvd.shipcountry.value;
	var sub_Total;
	var base_rate;

	if (ShipCountry == 'us') {
		base_rate = 45.00;
		} else {
		base_rate = 50.00;
	}

	sub_Total = base_rate * Book_Number;
	document.dvd.amount.value = base_rate;
	document.dvd.total.value = pad_decimals(sub_Total);
	document.dvd.buy.disabled = false;
}


// email address hider
function emailName(emailFront,emailBack) {
	return emailFront + "@" + emailBack;
}

function sendEmail(emailFront,emailBack) {
	return "<A HREF='mailto:" + emailFront + "@" + emailBack + "'>";
}



//  popup window
var popupwin=0;
function popup() {
	if(popupwin) { popupwin.close(); }
	popupwin = open('', 'popupwin', 'scrollbars=yes,resizable=yes,width=600,height=500');
}


function popupphotos() {
	if(popupwin) { popupwin.close(); }
	popupwin = open('', 'popupwin', 'scrollbars=yes,resizable=yes,width=700,height=700');
}

//Scripts for habits purchasing

function calculate_subtotal_cards(number) {
	var Card_Number = document.card_purchase.quantity.value;
	var sub_Total;
	if (Card_Number < 7) {
		sub_Total = 10.00 * Card_Number;
		document.card_purchase.amount.value = 10.00;
	}
	else {

		if (Card_Number < 51) {
			sub_Total = 9.00 * Card_Number;
			document.card_purchase.amount.value = 9.00;
			}
			else {
				sub_Total = 8.00 * Card_Number;
				document.card_purchase.amount.value = 8.00;
			}
		}
	//Pad the shipping cost with the right number of decimals
	sub_Total = Math.round(sub_Total*100)/100;
	var tmpRate = sub_Total.toString();
	var decimal_location = tmpRate.indexOf('.');
	var rate_length = tmpRate.length;
	if (decimal_location == -1) { //begin no decimal
		tmpRate = tmpRate + '.00';
	}// end no decimals
	else { //check for one decimal
		if (rate_length - (decimal_location+1) == 1) { //begin one decimal
			tmpRate = tmpRate + '0';
		}// end one decimal
	} // end check for one decimal
	sub_Total = tmpRate.toString();

	document.card_purchase.cardtotal.value = sub_Total;
}

function calculate_subtotal_poster() {
	var Poster_Number = document.poster_purchase.quantity.value;
	var sub_Total;
	
	if (Poster_Number < 5) {
		sub_Total = 20.00 * Poster_Number;
		document.poster_purchase.amount.value = 20.00;
	}
	else {
		if (Poster_Number <16) {
			sub_Total = 18.00 * Poster_Number;
			document.poster_purchase.amount.value = 18.00;
			} else {
			sub_Total = 16.00 * Poster_Number;
			document.poster_purchase.amount.value = 16.00;
			}
		}
	//Pad the shipping cost with the right number of decimals
	sub_Total = Math.round(sub_Total*100)/100;
	var tmpRate = sub_Total.toString();
	var decimal_location = tmpRate.indexOf('.');
	var rate_length = tmpRate.length;
	if (decimal_location == -1) { //begin no decimal
		tmpRate = tmpRate + '.00';
	}// end no decimals
	else { //check for one decimal
		if (rate_length - (decimal_location+1) == 1) { //begin one decimal
			tmpRate = tmpRate + '0';
		}// end one decimal
	} // end check for one decimal
	sub_Total = tmpRate.toString();
	document.poster_purchase.postertotal.value = sub_Total;
}

function calculate_shipping_cards(method) { //v1.0
	var Book_Number = document.card_purchase.quantity.value;
	var Base_Price = document.card_purchase.cardtotal.value;
	var base_rate;	
	var shipcards = document.card_purchase.shipcards.value;

	switch (shipcards) {
		case 'none': //no valid shipping was chosen
			base_rate = 0;
			document.card_purchase.custom.value = "Shipping Method: None Chosen";
			document.card_purchase.buy.disabled = true;

			document.card_purchase.shipping.value = base_rate;
			document.card_purchase.total.value = 0;

		break;
		
		case 'domestic': //Domestic Shipping
		    base_rate = 0;	
			document.card_purchase.custom.value = "Shipping Method: Domestic";
   			document.card_purchase.buy.disabled = false;

			document.card_purchase.shipping.value = '0.00';
			document.card_purchase.total.value = Base_Price;			

		break;
		
		case 'international': //International Shipping
		document.card_purchase.custom.value = "Shipping Method: International";
		document.card_purchase.buy.disabled = false;

		if (Book_Number < 7) { //begin 1-6 cards
			base_rate = 13.45;
			} // end 1 book
		else { //> 6 books
			if (Book_Number < 13) { //begin 7-12 books
				base_rate = 26.90;
			} // end 7-12 books
			else { //begin > 12 books
				if (Book_Number <51) { //begin 13-50 books
					base_rate = 43.45;
				} // end 13-50 books
					else { //begin 51-80
						base_rate = 55.95;
					}
				}
			}					
					
		
		//Pad the shipping cost with the right number of decimals
	tmpRate = base_rate.toString();
	var decimal_location = tmpRate.indexOf('.');
	var rate_length = tmpRate.length;
	if (decimal_location == -1) { //begin no decimal
		tmpRate = tmpRate + '.00';
	}// end no decimals
	else { //check for one decimal
		if (rate_length - (decimal_location+1) == 1) { //begin one decimal
			tmpRate = tmpRate + '0';
		}// end one decimal
	} // end check for one decimal
	base_rate = tmpRate.toString();
	document.card_purchase.shipping.value = base_rate;
	
	//Update the total
	var cardtotal = document.card_purchase.cardtotal.value;
	var subTotal = parseFloat(base_rate) + parseFloat(cardtotal);
	//Pad the shipping cost with the right number of decimals

	subTotal = Math.round(subTotal*100)/100;
	var tmpRate = subTotal.toString();
	var decimal_location = tmpRate.indexOf('.');
	var rate_length = tmpRate.length;
	if (decimal_location == -1) { //begin no decimal
		tmpRate = tmpRate + '.00';
	}// end no decimals
	else { //check for one decimal
		if (rate_length - (decimal_location+1) == 1) { //begin one decimal
			tmpRate = tmpRate + '0';
		}// end one decimal
	} // end check for one decimal
	subTotal = tmpRate.toString();
	document.card_purchase.total.value = subTotal;
		
		break;
	}
	
}


function calculate_shipping_poster() { //v1.0
	var Poster_Number = document.poster_purchase.quantity.value;
	var Base_Price = document.poster_purchase.postertotal.value;
	var base_rate;	
	var ShipPoster = document.poster_purchase.shipposter.value;

	switch (ShipPoster) {
		case 'none': //no valid shipping was chosen
			base_rate = 0;
			document.poster_purchase.custom.value = "Shipping Method: None Chosen";
			document.poster_purchase.buy.disabled = true;
			document.poster_purchase.shipping.value = base_rate;
			document.poster_purchase.total.value = 0;
		break;
		
		case 'domestic': //Domestic Shipping
		    base_rate = 0;	
			document.poster_purchase.custom.value = "Shipping Method: Domestic";
   			document.poster_purchase.buy.disabled = false;
			document.poster_purchase.shipping.value = '0.00';
			document.poster_purchase.total.value = Base_Price;			
		break;
		
		case 'international': //International Shipping
		document.poster_purchase.custom.value = "Shipping Method: International";
		document.poster_purchase.buy.disabled = false;
		
		if (Poster_Number < 7) { //begin 1-6 cards
			base_rate = 13.45;
			} // end 1 book
		else { //> 6 books
			if (Poster_Number < 13) { //begin 7-12 books
				base_rate = 26.90;
			} // end 7-12 books
			else { //begin > 12 books
				if (Poster_Number <51) { //begin 13-50 books
					base_rate = 43.45;
				} // end 13-50 books
					else { //begin 51-80
						base_rate = 55.95;
					}
				}
			}					
					
		
		//Pad the shipping cost with the right number of decimals
	tmpRate = base_rate.toString();
	var decimal_location = tmpRate.indexOf('.');
	var rate_length = tmpRate.length;
	if (decimal_location == -1) { //begin no decimal
		tmpRate = tmpRate + '.00';
	}// end no decimals
	else { //check for one decimal
		if (rate_length - (decimal_location+1) == 1) { //begin one decimal
			tmpRate = tmpRate + '0';
		}// end one decimal
	} // end check for one decimal
	base_rate = tmpRate.toString();
	document.poster_purchase.shipping.value = base_rate;
	
	//Update the total
	var postertotal = document.poster_purchase.postertotal.value;
	var subTotal = parseFloat(base_rate) + parseFloat(postertotal);
	//Pad the shipping cost with the right number of decimals

	subTotal = Math.round(subTotal*100)/100;
	var tmpRate = subTotal.toString();
	var decimal_location = tmpRate.indexOf('.');
	var rate_length = tmpRate.length;
	if (decimal_location == -1) { //begin no decimal
		tmpRate = tmpRate + '.00';
	}// end no decimals
	else { //check for one decimal
		if (rate_length - (decimal_location+1) == 1) { //begin one decimal
			tmpRate = tmpRate + '0';
		}// end one decimal
	} // end check for one decimal
	subTotal = tmpRate.toString();
	document.poster_purchase.total.value = subTotal;
		
		break;
	}



	}
