/* 
###########################################
	e]O      eYe Openers design
	 ~

		http://eYeOpeners.info
	Send e-mail to "web.development" at the above domain


	Custom JavaScript API 
	Prepared for 

	Nova Institute
	http://novainstitute.org/.net               	  	

		Site Design & Programming
	Copyright MMIX eYe Openers design

	- All Rights Reserved -
###########################################
*/

/*###############

elem=id | numb=total books ordered per elem
Alerts visitor/orderer that 5 or more books need to be bulk ordered through Nova's phone number.

###############
*/
function totals(elem,numb){
var current=document.all.subtotal.value;

if(numb>=5){
	if(confirm("You have requested " +numb+ " copies.\r\rPlease contact Nova Institute for bulk quantity discounts of over 4 copies per book.\r\r\t\tYou may phone 301 946 2099,\r\r\t\tor send an E-mail.\r\r\t\tOK:\tReturn to form and restart order [Address not affected].\r\r\t\tCANCEL:\tE-mail Nova Institute now.")){

/* 
YOU CAN FIX THIS PERHAPS BY MAKING  '' A VALUE OF ZERO
		eval("document.all."+elem+".value=''")
*/
		document.all.ntc.value=0;
		document.all.uwe.value=0;
		document.all.chh.value=0;
		document.all.chp.value=0;
		document.all.subtotal.value=0;
		document.all.tax.value=0;
		document.all.shiphand.value=0;
		document.all.total.value=0}
	else{
		document.all.ntc.value=0;
		document.all.uwe.value=0;
		document.all.chh.value=0;
		document.all.chp.value=0;
		document.all.subtotal.value=0;
		document.all.tax.value=0;
		document.all.shiphand.value=0;
		document.all.total.value=0;
		location.href='mailto:bulk.orders@novainstitute.org?subject=Bulk%20Order.'}}

else if(elem=='ntc'){
	if(numb=='0'){
		document.all.subtotal.value="0.00"}
	if(numb=='1'){
		document.all.subtotal.value=parseFloat(current)+15.00;
		tax();
		shiphand();
		total()}
	else if(numb=='2'){
		document.all.subtotal.value=parseFloat(current)+30.00;
		tax();
		shiphand();
		total()}
	else if(numb=='3'){
		document.all.subtotal.value=parseFloat(current)+45.00;
		tax();
		shiphand();
		total()}
	else if(numb=='4'){
		document.all.subtotal.value=parseFloat(current)+60.00;
		tax();
		shiphand();
		total()}
	else if(numb==''){
		numb='0'}
	}
else if(elem=='uwe' || elem=='chh'){
	if(numb=='0'){
		document.all.subtotal.value="0.00"}
	if(numb=='1'){
		document.all.subtotal.value=parseFloat(current)+19.95;
		tax();
		shiphand();
		total()}
	else if(numb=='2'){
		document.all.subtotal.value=parseFloat(current)+39.90;
		tax();
		shiphand();
		total()}
	else if(numb=='3'){
		document.all.subtotal.value=parseFloat(current)+59.85;
		tax();
		shiphand();
		total()}
	else if(numb=='4'){
		document.all.subtotal.value=parseFloat(current)+79.80;
		tax();
		shiphand();
		total()}
	else if(numb==''){
		numb='0'}
	}
else if(elem=='chp'){
	if(numb=='0'){
		document.all.subtotal.value="0.00"}
	if(numb=='1'){
		document.all.subtotal.value=parseFloat(current)+8.95;
		tax();
		shiphand();
		total()}
	else if(numb=='2'){
		document.all.subtotal.value=parseFloat(current)+17.90;
		tax();
		shiphand();
		total()}
	else if(numb=='3'){
		document.all.subtotal.value=parseFloat(current)+26.85;
		tax();
		shiphand();
		total()}
	else if(numb=='4'){
		document.all.subtotal.value=parseFloat(current)+35.80;
		tax();
		shiphand();
		total()}
	else if(numb==''){
		numb='0'}}}

function tax(){
var subtotal=document.all.subtotal.value;
if(document.all.State.value=='MD' || document.all.State.value=='md' || document.all.State.value=='Md' || document.all.State.value=='mD'){
	document.all.tax.value=subtotal*.05;
	total()}}

function shiphand(){
var ntcAmt=document.all.ntc.value;
var uweAmt=document.all.uwe.value;
var chhAmt=document.all.chh.value;
var chpAmt=document.all.chp.value;
var totalAmt=parseInt(ntcAmt)+parseInt(uweAmt)+parseInt(chhAmt)+parseInt(chpAmt);

if(
ntcAmt!=0 || uweAmt!=0 || chhAmt!=0 || chpAmt!=0 || ntcAmt!='' || uweAmt!='' || chhAmt!='' || chpAmt!=''){
		if(totalAmt==1){
			document.all.shiphand.value="3.00"}
		else if(totalAmt==2){
			document.all.shiphand.value="4.00"}
		else if(totalAmt>=3){
			document.all.shiphand.value=totalAmt+".00"}}}

function total(){
var sub=document.all.subtotal.value;
var tax=document.all.tax.value;
var shp=document.all.shiphand.value;
var total=parseFloat(sub)+parseFloat(tax)+parseFloat(shp);

if(sub!=''){
	document.all.total.value=total}}


//Clear all order (Step 2) fields if clicking on a previously entered amount to prevent addition problems.

function clearOrder(elem){
if(document.all.Name.value=='' || 
document.all.City.value=='' ||
document.all.State.value=='' ||
document.all.Zip.value=='' ||
document.all.Country.value=='' ||
document.all.Phone.value=='' ||
document.all.email.value==''){
	document.all.Name.focus();
	alert("Please begin with or complete Step 1 above.");
	document.all.Name.focus();}

else if(elem!=0){
	if(confirm("You are changing an amount. The form will clear to start over [Address will remain].\r\r\t\tOK:\tClear order entries to start again.\r\r\t\tCANCEL:\tDo not clear and return to form as is.")){
		document.all.ntc.value=0;
		document.all.uwe.value=0;
		document.all.chh.value=0;
		document.all.chp.value=0;
		document.all.subtotal.value=0;
		document.all.tax.value=0;
		document.all.shiphand.value=0;
		document.all.total.value=0}}}

/*
Clear 0s before sending so notification email doesn't include non-ordered books.

function clear0s(){
if(document.all.ntc.value=0 || document.all.uwe.value=0 || document.all.chh.value=0 || document.all.chp.value=0){
	document.all.ntc.value='';
	document.all.uwe.value='';
	document.all.chh.value='';
	document.all.chp.value=''}}

*/

/*
############
1. Round decimal to two digits 
2. Add digit to rendering .5 as .50
3. http://www.willmaster.com/possibilities/archives/wmp20030218001.shtml
//Call using
//var result = CurrencyFormatted(number)
############
*/

function currencyFormat(amount){
alert("Hi! From Program.");
var i=parseFloat(amount);
if(isNaN(i)){
	i=0.00}
var minus='';
if(i<0){
	minus='-'}
i=Math.abs(i);
i=parseInt((i+.005)*100);
i=i/100;
s=new String(i);
if(s.indexOf('.')<0){
	s+='.00'}
if(s.indexOf('.')==(s.length-2)){
	s+='0'}
s=minus+s;
return s}

/*
###########################################
	e]O      eYe Openers design
	 ~

		http://eYeOpeners.info
	Send e-mail to "web.development" at the above domain


	Custom JavaScript API
	Prepared for 

	Nova Institute
	http://novainstitute.org/.net               	  	

		Site Design & Programming
	Copyright MMIX eYe Openers design

	- All Rights Reserved -
###########################################
*/
