
var totalDonationAmount  = 0.0;
var donationAmounts = [];
var donationCategories = [];

var donationCountry = "";
var donationFirstName = "";
var donationLastName = "";
var donationAddress1 = "";
var donationAddress2 = "";
var donationCity = "";
var donationState = "";
var donationZip = "";

function UpdateDonationUser() {
	donationCountry = document.getElementById('donationCountryValue').value;
	donationFirstName = document.getElementById('donationFirstNameValue').value;
	donationLastName = document.getElementById('donationLastNameValue').value;
	donationAddress1 = document.getElementById('donationAddress1Value').value;
	donationAddress2 = document.getElementById('donationAddress2Value').value;
	donationCity = document.getElementById('donationCityValue').value;
	donationState = document.getElementById('donationStateValue').value;
	donationZip = document.getElementById('donationZipValue').value;
}


function CloseOtherPanels(currentPanel, totalPanels) {
	var i = 1;
	for(i = 1; i <= totalPanels; i++ ) {
		if( i != currentPanel )
			eval("if( CollapsiblePanel"+i+".contentIsOpen ) { CollapsiblePanel"+i+".close(); }");
	}
}


function UpdateDonations() {
	
	var inputs, i;
	var fundNames = "<h3>Funds Selected</h3><br/><table class='donationFloatingSummary' width='100%'>";
	totalDonationAmount = 0.0;
	
	inputs = document.getElementById('donateForm').elements;
	
	for (  var i = 0; i < inputs.length; i++ )
	{
		if ( inputs[i].name.substr(0,9) == 'donation-' ) {
			if( inputs[i].value != "" && inputs[i].value != null && isFinite(parseFloat(inputs[i].value)) ) {
				var bits = inputs[i].name.split('-');
				if( donationAmounts[bits[2]] == "" || donationAmounts[bits[2]] == null || !isFinite(parseFloat(donationAmounts[bits[2]])) ) {
					var objID = 'donation-'+bits[1]+'-'+bits[2];
					document.getElementById(objID).value = '';
				}
			}
		}
	} 
	
	for (  var i = 0; i < donationAmounts.length; i++ )
	{
		if( donationAmounts[i] != "" && donationAmounts[i] != null && isFinite(parseFloat(donationAmounts[i]))  ) {
			totalDonationAmount += parseFloat(donationAmounts[i]);
			var fundName = "<tr><td align='right' valign='top'><b>$"+ parseFloat(donationAmounts[i]).toFixed(2)+"</b></td>";
			fundName += "<td><b><a href='#"+i+"' onclick='eval(\"CollapsiblePanel"+donationCategories[i]+".open();\")'>" + document.getElementById('fundName-'+i).innerHTML + "</a></b> <a class='removeDonation' href='javascript:Do()' onclick='RemoveDonation("+donationCategories[i]+","+i+")'>(remove)</a></td>";
			//+ parseFloat(donationAmounts[i]).toFixed(2) + " "
			//<img style='cursor:pointer' align='absmiddle' src='./images/cross.png' title='Remove Donation of $" + parseFloat(donationAmounts[i]).toFixed(2) + "' onclick='RemoveDonation("+donationCategories[i]+","+i+")' />&nbsp;&nbsp;
			fundNames += fundName;
		}

	} 
	
	if( totalDonationAmount == 0.0 )
		fundNames += "<tr><td>Enter donations by expanding the fund boxes to the right.</td></tr>";
		
	fundNames += "</table>";
		
	document.getElementById('totalDonationAmount').innerHTML = "Total Donation $" + totalDonationAmount.toFixed(2);
	document.getElementById('donationFundSummary').innerHTML = fundNames;
}

function AddDonation(cat, fund) {
	var objID = 'donation-'+cat+'-'+fund;
	donationCategories[fund] = cat;
	donationAmounts[fund] = document.getElementById(objID).value;
	UpdateDonations();
}

function RemoveDonation(cat, fund) {
	var objID = 'donation-'+cat+'-'+fund;
	document.getElementById(objID).value = '';
	donationAmounts[fund] = "";
	UpdateDonations();
}

function NumberOnly(evt) {
	
	/*if( !isFinite(obj.value) ) {
		var value = obj.value;
		
		obj.value = "";
		return false;
	}*/
	
	var charCode = (evt.which) ? evt.which : event.keyCode
	 if (charCode > 31 && (charCode < 48 || charCode > 57))
			return false;
	
	 return true;

	
	//UpdateDonations();
}

function OnEnter(evt, cat, fund) {
	var charCode = (evt.which) ? evt.which : event.keyCode;
	if( charCode === 13 ) 
		AddDonation(cat, fund);
}


function GoConfirm() {
	if( totalDonationAmount >= 1.0 ) {
		UpdateDonations(); 
		document.donateForm.submit();
	}
}


function EditAmount(cat, fund) {
	document.getElementById('updateButtonDiv').style.display = 'inline';
	document.getElementById('donateButtonDiv').innerHTML = '';
	document.getElementById('update-'+fund).innerHTML = '';
	document.getElementById('paypalTransferText').innerHTML = '';
	document.getElementById('paypalTransferText').style.display = 'none';
	document.getElementById('paybyCCdiv').style.display = 'none';
	document.getElementById('amount-'+fund).innerHTML = '';
	document.getElementById('editamount-'+cat+'-'+fund).style.display = '';
}

function EditTribute(fund) {
	document.getElementById('updateButtonDiv').style.display = 'inline';
	document.getElementById('donateButtonDiv').innerHTML = '';
	document.getElementById('paypalTransferText').innerHTML = '';
	document.getElementById('paypalTransferText').style.display = 'none';
	document.getElementById('paybyCCdiv').style.display = 'none';
	document.getElementById('tributelink-'+fund).style.display = 'none';
	//document.getElementById('canceltributelink-'+fund).style.display = '';
	document.getElementById('tributetextdiv-'+fund).style.display = '';
}

function EditFullTribute() {
	Hide('fullDonationTributeLink');
	Show('fullDonationTribute'); 	
	Hide('fullDonationTributeDiv');
	document.getElementById('updateButtonDiv').style.display = 'inline';
	document.getElementById('donateButtonDiv').innerHTML = '';
	document.getElementById('paypalTransferText').innerHTML = '';
	document.getElementById('paypalTransferText').style.display = 'none';
	document.getElementById('paybyCCdiv').style.display = 'none';
}


function RemoveAmount(cat, fund) {
	document.getElementById('txteditamount-'+cat+'-'+fund).value = '';
	document.updateForm.submit();
}



function UpdateDonationsOld() {
	
	var inputs, i;
	var fundNames = "<u>Funds Selected</u><br/><br/>";
	totalDonationAmount = 0.0;
	
	inputs = document.getElementById('donateForm').elements;
	
	for (  var i = 0; i < inputs.length; i++ )
	{
		if ( inputs[i].name.substr(0,9) == 'donation-' ) {
			if( inputs[i].value != "" && inputs[i].value != null && isFinite(parseFloat(inputs[i].value))  ) {
				var bits = inputs[i].name.split('-');
				totalDonationAmount += parseFloat(inputs[i].value);
				var fundName = "<div><img style='cursor:pointer' align='absmiddle' src='./images/cross.png' title='Remove Donation' onclick='RemoveDonation("+bits[1]+","+bits[2]+")' />&nbsp;&nbsp;" + document.getElementById('fundName-'+bits[2]).innerHTML + "</div>";
				fundNames += fundName;
			}
		}
	} 
	
	if( totalDonationAmount == 0.0 )
		fundNames += "None";
		
	document.getElementById('totalDonationAmount').innerHTML = "Total Donation $" + totalDonationAmount.toFixed(2);
	document.getElementById('donationFundSummary').innerHTML = fundNames;
}


function Show(id) {
	document.getElementById(id).style.display = '';
}

function Hide(id) {
	document.getElementById(id).style.display = 'none';
}

function Set(id, value) {
	document.getElementById(id).value = '';
}

function Do(){
	
}


