function checkDonation(pFrm) {
    if (trim(pFrm.donationAmount.value) == "" ||
        isNaN(pFrm.donationAmount.value)) {
        alert("Please enter a numerical amount that you would like to donate to Framework Housing Agency.");
        pFrm.donationAmount.focus();
        return false;
    } else if (parseFloat(pFrm.donationAmount.value) < 1.5) {
        alert("Sorry but due to bank charges the minimum donation we can accept is \xA31.50");
        pFrm.donationAmount.focus();
        return false;
    }
    if (notValidEmail(pFrm.email.value)) {
        alert("Please enter a valid email address");
        pFrm.email.focus();
        return false;
    }
    pFrm.amount.value = pFrm.donationAmount.value;
    pFrm.CM_donationAmount.value = pFrm.donationAmount.value;
    pFrm.CM_email.value = pFrm.email.value;
    pFrm.CM_name.value = pFrm.name.value;
   /* if (pFrm.CM_taxCredits.checked) {
        pFrm.action = "framework_donations_gift_aid.asp";
    }*/
    return true;
}

function checkGiftAidDonation(pFrm) {
    if (trim(pFrm.name.value) == "") {
        alert("Please enter your full name.");
        pFrm.name.focus();
        return false;
    }
    if (trim(pFrm.address.value) == "") {
        alert("Please enter your address.");
        pFrm.address.focus();
        return false;
    }
    if (trim(pFrm.postcode.value) == "") {
        alert("Please enter your postcode.");
        pFrm.postcode.focus();
        return false;
    }
    pFrm.CM_title.value = pFrm.title.value;
    pFrm.CM_address.value = pFrm.address.value;
    pFrm.CM_postcode.value = pFrm.postcode.value;
    return true;
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
}

function notValidEmail(pString){
var dotpos=pString.indexOf('.');
var atpos=pString.indexOf('@');
	if(atpos == -1 || (pString=="") || (pString==" ") || (pString.length < 6)){
		return true;
	}
	else if(dotpos + 1 == atpos){
		return true;
	}
	else{
		var emailterm=pString.substring(atpos, (pString.length));
		if(emailterm.indexOf('.')==-1 || emailterm.length < 2){
			return true;}
		else return false;
	}

}
