// this formats the results into currency

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function isNotNum(str) {
   var numStr = "0123456789"
   for (i=0; i <= str.length-1; i++) {
      if (numStr.indexOf(str.charAt(i)) == -1) return true;
   }
   return false;
}

function isNotDollar(str) {
   var numStr = "0123456789."
   for (i=0; i <= str.length-1; i++) {
      if (numStr.indexOf(str.charAt(i)) == -1) return true;
   }
   return false;
}

function calculate_total() {
	//VERIFY DATA FIRST
	errMsg ='';
	if (isNotDollar(document.f.amt1.value)) { errMsg = 'Please enter a dollar amount.' };
	/*
	if (isNotNum(document.f.qty1.value)) { errMsg = 'Number of people attending must be a number.' };
	if (isNotNum(document.f.qty2.value)) { errMsg = 'Number of people attending must be a number.' };
	*/
	
	if (errMsg != '') {
		showPayPal('errMsgDiv','goToPayPal',1);
		}
	else {
			
		if (document.f.amt1.value == '') {document.f.amt1.value = '0.00'};
		/*
		if (document.f.qty1.value == '') {document.f.qty1.value = 0};
		if (document.f.qty2.value == '') {document.f.qty2.value = 0};
		*/
		
		document.f.amount.value = formatCurrency(eval(document.f.amt1.value));
		
		//checkAndHide('goToPayPal','reCalculate');

		showPayPal('goToPayPal','errMsgDiv',0);
	};

	

	
}



/*
function checkAndHide(id,id2) {
	obj = document.getElementById(id);
	obj2 = document.getElementById(id2);
	if (obj.style.display != "none"){
	obj.style.display = "none";
	obj2.style.display = "";
	}
	else {
	obj.style.display = "";
	obj2.style.display = "none";
	}
}
*/

function showPayPal(id,id2,param) {
	//param 1 to determine mode
	obj = document.getElementById(id);
	obj2 = document.getElementById(id2);
	if (param == 1) {
	//There was an error
		obj.style.display = "";
		obj2.style.display = "none";
		document.getElementById('errorMessageText').innerHTML = errMsg;

	}
	else {
	//There is no error
		obj.style.display = "";
		obj2.style.display = "none";
	}
}
