// JavaScript Document

	// function to sum gift allocations and alert user is sum of allocations is greater than total gift
	function updateHP() {
		// get form values as numbers
		if (document.dcf1.gift_amount) {
			_tga = new Number(document.dcf1.gift_amount.value);
			_tga.toFixed(2);
		}
		else {
			_tga = new Number(0);
		}
		if (document.dcf1.alloc_priorities) {
			_hp  = new Number(document.dcf1.alloc_priorities.value);
			_hp.toFixed(2);
		}
		else {
			_hp = new Number(0);
		}
		
		if (document.dcf1.alloc_faculty) {
		 	_fac = new Number(document.dcf1.alloc_faculty.value);
			_fac.toFixed(2);
		}
		else {
			_fac = new Number(0);
		}
		if (document.dcf1.alloc_arts) {
			_art = new Number(document.dcf1.alloc_arts.value);
			_art.toFixed(2);
		}
		else {
			_art = new Number(0);
		}
		if (document.dcf1.alloc_athletics) {
			_ath = new Number(document.dcf1.alloc_athletics.value);
			_ath.toFixed(2);
		}
		else {
			_ath = new Number(0);		
		}
		if (document.dcf1.alloc_aid) {		
			_aid = new Number(document.dcf1.alloc_aid.value);
			_aid.toFixed(2);
		}
		else {
			_aid = new Number(0);
		}
		if (document.dcf1.alloc_student_progs) {
			_sp  = new Number(document.dcf1.alloc_student_progs.value);
			_sp.toFixed(2);
		}
		else {
			_sp  = new Number(0);
		}
		if (document.dcf1.alloc_tech) {
			_tec = new Number(document.dcf1.alloc_tech.value);
			_tec.toFixed(2);
		}
		else {
			_tec = new Number(0);
		}
		if (document.dcf1.alloc_campus) {
			_cmp = new Number(document.dcf1.alloc_campus.value);
			_cmp.toFixed(2);
		}
		else {
			_cmp = new Number(0);
		}
		if (document.dcf1.alloc_culture_comm) {
			_cult = new Number(document.dcf1.alloc_culture_comm.value);
			_cult.toFixed(2);
		}
		else {
			_cult = new Number(0);
		}
		// declare some variabels to use internally
		_sumall = new Number(0);
		_diff = new Number(0);
		// sum allocations
		_sumall = (_fac + _art + _ath + _aid + _sp + _tec + _cmp + _cult);
		//_sumall = (_fac + _ath + _aid + _cult);
		// difference of total gift amount and sum of allocations
		_diff = (_tga - _sumall);
		// multiply by -1 so we can display a positive number in alert if _sumall > _tga
		_invdiff = _diff * -1; 
	
		// check if alloactions are grreater than total gift amount
		if (_diff < 0 ) {
			// send form focus to gift amount
			document.dcf1.gift_amount.focus();
			// display alert						
			alert('The sum of your allocations is greater than your Total Gift Amount by $' + _invdiff +'.\nPlease update your Total Gift Amount');						
		}
		else {
			// update form data
			document.dcf1.gift_amount.value = _tga.toFixed(2);
			document.dcf1.alloc_priorities.value = _diff.toFixed(2);
		}
	}

	function checkGiftVal(val, fieldName) {
		_myVal = new Number(val);
		// make sure entered numbers are all positive and only 2 digits after the decimal
		if (isNaN(_myVal)) {
				alert('You have entered an non-numeric value. Please correct your entry and try again.\n\nDo not use commas.  For example, enter ten thousand as 10000');
				document.dcf1[fieldName].value = '';
				document.dcf1[fieldName].focus();
				document.dcf1[fieldName].select();			
			}
		else if (_myVal<0 ) {
				alert('You have entered an number less than zero. Please correct your entry and try again.');
				document.dcf1[fieldName].value = '';
				document.dcf1[fieldName].focus();
				document.dcf1[fieldName].select();
				//return false;
		}
		else {
				document.dcf1[fieldName].value = _myVal.toFixed(2);				
			}
	}


	// function to throw alert if Honorary / Memory allocation is greater than total gift amount
	
	function checkHonMemVal(val, fieldName) {
		_myVal = new Number(val);
		_tga   = new Number(document.dcf1.gift_amount.value);
		
		// make sure entered numbers are all positive and only 2 digits after the decimal
		if (_myVal>_tga) {
				alert('You have allocated more for an Honorary / Memorial Gift than your Total Gift Amount. Please correct your entry and try again.');
				document.dcf1[fieldName].value = '';
				document.dcf1[fieldName].focus();
				document.dcf1[fieldName].select();			
			}
		else {
				document.dcf1[fieldName].value = _myVal.toFixed(2);
			}
				
	}


	// fucntion to submit form when user ckicks link in breadcrumb
	// used to save form data to the session scope
	
	function linkSubmit ( submitVal )
		{
		  document.dcf2.prev.value = submitVal ;
		  document.dcf2.prev.submit() ;
		}