
// For time-dependent fees
// requires .php extension

function determinePrice(form, earlyFee, cutoff, lateFee, n) {
n = n - 1; //allows numbering in form to start at 1 instead of 0
var totalInBox = form.Total.value;
totalInBox = form.Total.value.substring(2, form.Total.value.length);
var costMe = 0;
var checkNumber = form.costitem; //trying to get an ID number assocated with respective checkbox so script can go through 'if' statement
var Checkboxes=eval("form.costitem");

var currenttime = form.time.value; //from nameless hidden field in form preamble
var currentDate = new Date(currenttime);

var cutoff = new Date(cutoff);

	if (currentDate.getTime() > cutoff.getTime() && Checkboxes[n].checked == true){ //if today is after cutoff date
	costMe = lateFee;
//	alert( 'ALatefee: ' + costMe); 
	} 
	if (currentDate.getTime() < cutoff.getTime() && Checkboxes[n].checked == true){ //if today is before cutoff date
	costMe = earlyFee;
//	alert( 'BEarlyfee: ' + costMe); 
	} 
	if (currentDate.getTime() > cutoff.getTime() && Checkboxes[n].checked == false){ //if today is after cutoff date
	costMe = lateFee * -1;
//	alert( 'CLatefee: -' + costMe); 
	} 
	if (currentDate.getTime() < cutoff.getTime() && Checkboxes[n].checked == false){ //if today is before cutoff date
//	alert('before date'); 
	costMe = earlyFee * -1;
//	alert( 'DEarlyfee: -' + costMe); 
	} 
if (form.Total.value == ""){
	form.Total.value = 0;
}
var TotalCost = eval(totalInBox) + eval(costMe);
totalInBox = TotalCost
form.Total.value = '$ ' + totalInBox;
form.costitem[n].value = '$ ' + costMe;


}

//    var divs = document.getElementsByTagName("div"); // get array of all divs



// For normal fees
// HTML: <input type="anything" cost="any whole number" name="anything" value="anything" onClick="count(this.form)"
// must be a 'checked' element to be counted
// 
// Total box:  <input type="text" id="Total" name="Total Cost" value="$ 0" readonly="true" style="width:40px;" />

function count(form) {
var costMe = 0;
var costArray = new Array;
var j=0;
for (i=0;i<form.elements.length;i++) {
	if (form.elements[i].getAttribute('cost') && form.elements[i].checked == true ){
	costArray[j] = (form.elements[i].getAttribute('cost'));
	j++
	}
}
//alert( 'costarray[0]:' + costArray[0]);
for (k=0;k<costArray.length;k++){
	costMe = eval(costMe)+eval(costArray[k]);	
}
	var totalCost = eval(costMe) + 20;
	form.Total.value = '$ ' + totalCost;
}



function discountCount(form) { //for scholarships, speakers, etc.  Used on /sisg
	var costMe = 0;
	var totalCost;
	var costArray = new Array;
	//var discountAmount = 0; 
	var checkOK = "0123456789"; //error checking for # only field
	var allValid = true; //error checking for # only field
	var h=0;
	
	for (i=0;i<form.elements.length;i++) {
		if (form.elements[i].getAttribute('cost') && form.elements[i].checked == true ){
			costArray[h] = (form.elements[i].getAttribute('cost'));
			h++ 
		}
	}
	for (k=0;k<costArray.length;k++){
		costMe = eval(costMe)+eval(costArray[k]);	
	}

	for (i = 0;  i < document.getElementById('discount').value.length;  i++){
		ch = document.getElementById('discount').value.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length){
			allValid = false;
			break;
		}
	}
	if (!allValid){
		alert("Please use numbers only.");
		document.getElementById('discount').value = document.getElementById('discount').value.substring(0,document.getElementById('discount').value.length-1);
		document.getElementById('discount').focus();
		//return (false);
	}
	else {
		if (document.getElementById('discount').value == ""){
			discount=0;
		}
		else{
			discount = eval(document.getElementById('discount').value);
		}
		totalCost = eval(costMe) - eval(discount);
		if (totalCost == 135){
			totalCost = 35;	
		}
		form.Total.value = '$ ' + totalCost;		
		
	}
}

