//Function for sliding the single payement and monthly payment donation
function checkOption(){
	document.donateForm.AMOUNT.value = '';
	if(document.donateForm.donationType[0].checked){
	   	document.donateForm.monthly_AMOUNT.value = '';
		document.getElementById('onetimedonation').style.display="block";	
		
	   	document.getElementById('monthlypaymentplan').style.display= 'none';
	}
	else if(document.donateForm.donationType[1].checked){
		document.donateForm.total_AMOUNT.value = '';
		
		document.getElementById('monthlypaymentplan').style.display = 'block';
	   	document.getElementById('onetimedonation').style.display= 'none';

	}	
}
//Function to validate the form
function validateForm(){
	var fund 				= document.donateForm.FUND.value; 
 	var listing				= document.donateForm.LISTING.value; 
 	var matching 			= document.donateForm.MATCHING.value;
	var Description			= document.donateForm.DESCRIPTION;
	var Comment1			= document.donateForm.COMMENT1;
	var Comment2			= document.donateForm.COMMENT2;
	var oneTimedonation		= document.donateForm.donationType[0].checked;
	var monthlyDonation		= document.donateForm.donationType[1].checked;
	var additionalComments	= '';
	
	var digit=/^\d{0,9}$/;
	
	
	
	if(oneTimedonation == false && monthlyDonation == false){
		alert("Please, Select the Donation Type");
		return false;
	}
	
	//Validate for single payment donation
	if(oneTimedonation == true){
	 	if(document.donateForm.total_AMOUNT.value == '' || document.donateForm.total_AMOUNT.value == 0){
			alert("Please, Enter the Single Donation Amount");
			return false;
		}
		else if(!digit.test(document.donateForm.total_AMOUNT.value)){
			alert("Please, Enter the Amount in Digits");
			return false;
		}
	
		document.donateForm.AMOUNT.value = document.donateForm.total_AMOUNT.value;
	}
	
	//Validat for monthly payment donation
	if(monthlyDonation == true){
		var Monthlyamount 	= document.donateForm.monthly_AMOUNT.value;
		var monthTotal 		= document.donateForm.months.value;
		var totalMAMOUNT	= document.donateForm.total_MAMOUNT;
		
		if(monthTotal == '' || monthTotal == 0){
			alert("Please, Enter the Number of Month");
			return false;
		}
		
	 	if(Monthlyamount == '' || Monthlyamount == 0){
			alert("Please, Enter the Monthly Donation Amount");
			return false;
		}
		
		totalMAMOUNT.value	= Monthlyamount * monthTotal;
		
		additionalComments  = '; This is a Recurring monthly donation and the "Number of months = ' + monthTotal + ' and the total donation amount = $' + totalMAMOUNT.value + '"';
		document.donateForm.AMOUNT.value = Monthlyamount;

	}
	
	if (listing == ''  || listing == null) listing = 'NONE';
	if (matching == '' || matching == null) matching = 'NONE';
	
	Description.value	= 'Donation for: ' + fund + '; Donor listed as: ' + listing + '; Donation matched by: ' + matching + additionalComments; 
	Comment1.value	= 'FUND = ' + fund; 
	Comment2.value	= 'LISTING = ' + listing +', MATCHING = ' + matching;
	//alert(Description.value);
	//alert(Comment1);
	//alert(Comment2);
	return true;
}

//Function to check the single payment donation 
/*
function checkAmount() {
	var nAmount = document.donateForm.total_AMOUNT.value
	if (nAmount <100) {
		alert ('Any single contribution cannot be under $100. You must donate at least $100 per credit card charge in order to use this online donation form.');
		document.donateForm.total_AMOUNT.value = 0;
	}
}*/

function isPositiveInteger(val){
      if(val==null){return false;}
      if (val.length==0){return false;}
      for (var i = 0; i < val.length; i++) {
            var ch = val.charAt(i)
            if (ch < "0" || ch > "9") {
            return false
            }
      }
      return true;
}

function checkMonthlyAmount() {
	var nMonthlyAmount 	= document.donateForm.monthly_AMOUNT.value;
	var monthTotal 		= document.donateForm.months.value;
	
	if(nMonthlyAmount != '' && isPositiveInteger(nMonthlyAmount) == false){
		alert("Please, Enter the Monthly amount in Numeric");
		return false;
	}
	if(monthTotal != '' && isPositiveInteger(monthTotal) == false){
		alert("Please, Enter the Total months in Numeric");
		return false;
	}
	
	if (nMonthlyAmount < 50) {
		alert ('Any single contribution cannot be under $50. You must donate at least $50 per credit card charge in order to use this online donation form to set up a monthly payment plan. Would you perhaps like to make your entire donation over a shorter period of time or in a single payment?');	
		document.donateForm.monthly_AMOUNT.value = 0;
		document.donateForm.total_MAMOUNT.value	 = 0;  
		return false;
	}
	else{
		mAmount = document.donateForm.monthly_AMOUNT.value;
		Month	= document.donateForm.months.value;
		document.donateForm.total_MAMOUNT.value	= mAmount * Month;		
	}
}





