
// For Foundation employee donation form
// custom script to check various fields
// G.C.  043004
// ==========================================================

//Function will return true if the value contains nothing/spaces/new lines/tabs
function isBlank(val) {
        if (val === null)
         {
           // return true;
		for (var i=0; i<val.length; i++) {
				var c = val.charAt(i);
				if ((c != ' ') && (c != '\n') && (c != '\t')){
					return false;
				}
		}
		return true;
	}
	
	if (val.length == 0){
		return true;
	}
}

function foundationEmployee_ck(theForm) {
    alert_msgs = new Array();
    var aryindex = 0;

    if (!theForm.Payroll[0].checked && !theForm.Payroll[1].checked) {
		alert_msgs[aryindex++] = "Please tell us how you wish your gift to be deducted from your paycheck.";
	}
	if (isBlank(theForm.Name.value)) {
		alert_msgs[aryindex++] = "Please tell us your name";
	}
	if (isBlank(theForm.Address.value)) {
		alert_msgs[aryindex++] = "Please tell us your address";
	}
	if (isBlank(theForm.City_state_zip.value)) {
		alert_msgs[aryindex++] = "Please tell us your city, state, and zip code";
	}
	if (isBlank(theForm.Email.value)) {
		alert_msgs[aryindex++] = "Please tell us your email address";
	}
	if (isBlank(theForm.Phone.value)) {
		alert_msgs[aryindex++] = "Please tell us your phone number";
	}

	var str = alert_msgs.join("\n");
	if (aryindex === 0) {
		return(true);
	} else {
		alert(str);
		return(false);
	}
}

function calculateTotal(theForm) {
	var greatestNeed = theForm.Greatest_need.value;
	var careFund = theForm.Care_fund.value;
	var desigination = theForm.Designation.value;
	var careFund2 = theForm.Care_fund2.value;
	var careFund3 = theForm.Care_fund3.value;
	var careFund4 = theForm.Care_fund4.value;
	var careFund42 = theForm.Care_fund42.value;
	var careFund5 = theForm.Care_fund5.value;
	var total = 0;

	if (!isBlank(greatestNeed)) {
		if (!isNaN(greatestNeed)) {
			total += parseFloat(greatestNeed);
		}
	}
	if (!isBlank(careFund)) {
		if (!isNaN(careFund)) {
			total += parseFloat(careFund);
		}
	}
	if (!isBlank(desigination)) {
		if (!isNaN(desigination)) {
			total += parseFloat(desigination);
		}
	}
	if (!isBlank(careFund2)) {
		if (!isNaN(careFund2)) {
			total += parseFloat(careFund2);
		}
	}
	if (!isBlank(careFund3)) {
		if (!isNaN(careFund3)) {
			total += parseFloat(careFund3);
		}
	}
	if (!isBlank(careFund4)) {
		if (!isNaN(careFund4)) {
			total += parseFloat(careFund4);
		}
	}
	if (!isBlank(careFund42)) {
		if (!isNaN(careFund42)) {
			total += parseFloat(careFund42);
		}
	}
	if (!isBlank(careFund5)) {
		if (!isNaN(careFund5)) {
			total += parseFloat(careFund5);
		}
	}

	theForm.Total_gift.value = (total);
}

// =========================================================================================
// End Function
