<!--

function validate(form) {
  
    var result;
    var msg = new Array(50);
    var message = "";
    var i = 2;     // indicator of the current message; 0,1 - for the header 
        
    //// Designation 
     if (form.desg.options[form.desg.selectedIndex].value == "" && form.other_desg.value == "") 
        msg[i++] = "Select fund"; 
     if (form.desg.options[form.desg.selectedIndex].value == "" && form.other_desg.value != "") 
        msg[i++] = "Select Other fund from the drop down menu."; 
     if (form.desg.options[form.desg2.selectedIndex].value == "" && form.other_desg2.value != "") 
        msg[i++] = "Select Other fund from the drop down menu."; 
		
	if (form.desg.options[form.desg.selectedIndex].value != "other" && form.other_desg.value != "") 
        msg[i++] = "You cannot select a regular fund while specifying Other fund in the text box";  
	if (form.desg2.options[form.desg2.selectedIndex].value != "other" && form.other_desg2.value != "") 
        msg[i++] = "You cannot select a regular fund while specifying Other fund in the text box";  
				
	if (form.desg.options[form.desg.selectedIndex].value == "other" && form.other_desg.value == "") 
        msg[i++] = "Other fund";                        
    if (form.amount.options[form.amount.selectedIndex].value == "other" && form.other_amount.value == "") 
        msg[i++] = "Other gift amount";
    if (form.desg2.options[form.desg2.selectedIndex].value == "other" && form.other_desg2.value == "") 
        msg[i++] = "Second other fund";
    if (form.amount2.options[form.amount2.selectedIndex].value == "other" && form.other_amount2.value == "") 
        msg[i++] = "Second other gift amount";
      
    // no designation with valid amount   
    if ((form.desg2.selectedIndex == 0 && trimString(form.other_desg2.value) == "") &&
        (form.amount2.selectedIndex != 0 || trimString(form.other_amount2.value) != "" )) {
        msg[i++] = "Another gift";
    }
                
    // designation without amount
    if ((form.desg2.selectedIndex != 0 || trimString(form.other_desg2.value) != "") &&   
        (form.amount2.selectedIndex == 0 && trimString(form.other_amount2.value) == "" )) {
        msg[i++] = "Another gift";
    } 

    // valid amount                
    if (isValidStr(form.other_amount.value, "money") == false) 
        msg[i++] = "Other gift amount";
    
    if (isValidStr(form.other_amount2.value, "money") == false)
        msg[i++] = "Second other gift amount";                
    
               
    if ((form.gift_type[0].checked == true ||   
        form.gift_type[1].checked == true ||   
        form.gift_type[2].checked == true) &&
        (form.person.value == "" || form.person.value == "Please enter name here")) {
        msg[i++] = "Name for honor/memory/behalf";
    }

    if (form.matching_gifts[0].checked == true) { // donor's company
        if (form.company.value == "")
            msg[i++] = "Matching gift company name";
    } else if (form.matching_gifts[1].checked == true) { // spouse's company               
        if (form.spouse_company.value == "")
            msg[i++] = "Matching gift spouse company name";
    } else if (form.matching_gifts[2].checked == true) { // both
        if (form.company.value == "")
            msg[i++] = "Matching gift company name";
        if (form.spouse_company.value == "")
            msg[i++] = "Matching gift spouse company name";
    }        
             
   
    //// generate error messages
    if (i > 2) {
        msg[0] = "Reminder: please review the following field(s).";
        msg[1] = "-------------------------------------------------";
        for (var j = 0; j < i; j++) message += msg[j] + "\n";   
        alert(message);
        result = false;
		form.action = "";
    }
	else
        form.action = "https://advdev.usmd.edu/onlineEvent/credit_card.cfm";
    //else {
        cleanUp(form);            
    //    result = true; 
   // }

    return result;
}

function cleanUp(form) {

    var str, amount;
    var i,k;
    var c;        
    


    if (form.gift_type[3].checked == true) {
        form.person.value = "";
    }
            
    if (form.matching_gifts[0].checked == false &&
        form.matching_gifts[1].checked == false &&
        form.matching_gifts[2].checked == false) {
        form.company.value = "";
        form.spouse_company.value = ""; 
    }
        
    
        
    //// address 
    if (form.home_country.value.toUpperCase() != "US" && 
        form.home_country.value.toUpperCase() != "USA") {
        form.home_state.value = "";
    }        
    if (form.busn_country.value.toUpperCase() != "US" && 
        form.busn_country.value.toUpperCase() != "USA") {
        form.busn_state.value = "";
    }  
              
}

function isValidStr(str, type) {
       
    var lookup;
    var result;
    
    str = trimString(str);   // remove leading and trailing spaces       
    if (str == "") return true;
    
    if (type == "phone") {
        lookup = "0123456789";
    }
    else if (type == "foreign_phone") {
        lookup = "0123456789- ";
    }    
    else if (type == "zip") {
        lookup = "0123456789-";
    }    
    else if (type == "year") {    
        if (str.length != 2 && str.length != 4)
            return false;
        else    
            lookup = "0123456789";                       
    }
    else if (type == "card") {   
        lookup = "0123456789- ";
    }
    else if (type == "money") {                      
        lookup = "0123456789.,";
    }
    
    return charFound(str,lookup);     
}

function charFound(str, lookup) {
    for (var i=0; i < str.length; i++) {
        if (lookup.indexOf(str.charAt(i)) == -1)  // not found
            return false;
    }
    return true;
}

function trimString(str) {
  while (str.charAt(0) == ' ')
    str = str.substring(1);
    
  while (str.charAt(str.length - 1) == ' ')
    str = str.substring(0, str.length - 1);
    
  return str;
}
    
function giftType(type) {
    
    if (type == "none") {       
        document.giving_form.person.value = "";    
        document.giving_form.person.disabled = true;                      
    }    
    else {   
        document.giving_form.person.disabled = false;
        document.giving_form.person.value = "Please enter name here";
    } 
}

function matchingGift(company) {
    if (company == "none") {
        document.giving_form.company.value = "";
        document.giving_form.spouse_company.value = "";
    }
}     
   

       
//-->
