function isEmpty(field)
{
   if (field.value.length == 0) return true;
   for (var i = 0; i = field.value.length; ++i)
   {
      var ch = field.value.charAt(i);
      if (ch != " " && ch != "\t" && ch != "\r" && ch != "\n") return false;
   }
   return true;
}
function deblank(field)
{
    var val = "";
    var x = 0;
    var y = field.value.length;
    while (x < y)
    {
        var ch = field.value.charAt(x);
        if (ch > " ") val = val + ch;
        x = x + 1;
    }
    field.value = val;
}
function isNumeric(field)
{
   deblank(field);
   if (field.value.length == 0) return false;
   var i = 0;
   var x = field.value.length;
   while (i < x)
   {
      var ch = field.value.charAt(i);
      if (ch < "0" || ch > "9") return false;
      i++;
   }
   return true;
}

function anyRadioButton()
{
        //radio buttons - eight buttons
        for (i=0; i < 8; i++)
        {
            if(document.confirm.amount[i].checked) return true;
        }
        return false;          
}

function checkforDonation()
{
        if (anyRadioButton()) return true;  
        if (! (isEmpty(document.confirm.otheramount))) return true;  
        if (! (isEmpty(document.confirm.pledgeamount))) return true;  
        alert ("Please select or enter a donation amount.") ;
        document.confirm.otheramount.focus();
        return false;
}


function validateDonation()
{	
    if (! (checkforDonation())) return false;
    if (! (isEmpty(document.confirm.otheramount)))
    {   
        if (! (isNumeric(document.confirm.otheramount)))
        {
            alert("Amount must be whole dollars. Please reenter");
            document.confirm.otheramount.focus();
            document.confirm.otheramount.select();
            return false;
        }
    }
    if (! (isEmpty(document.confirm.pledgeamount)))
    {
        if (! (isNumeric(document.confirm.pledgeamount)))
        {
            alert("Amount must be whole dollars. Please reenter");
            document.confirm.pledgeamount.focus();
            document.confirm.pledgeamount.select();
            return false;
        }
        if (document.confirm.pledgeinterval.selectedIndex < 1) 
        {
            alert("Please select a donation frequency.")
            document.confirm.pledgeinterval.focus();
            return false;
        }
    }
    return true;
}    

