function resetForm() {
    document.myForm.reset()	
}

function updateTotal() {

    var numChecked = 0
    var total = 0
		 
    if (document.myForm.allPass.checked) {
        if (document.myForm.student[0].checked) {
	    total = 40
        }
	else {
  	    total = 80
	}	
    }
    
    else {	
    if (document.myForm.wsSat.checked) {
	numChecked++
    }
    if (document.myForm.wsSun.checked) {
	numChecked++
    }

    if (document.myForm.student[0].checked) {
	switch (numChecked) {
	  case 1:
	    total = 20
	    break
	  case 2:
	    total = 35
	    break
          default:
	    total = 0
	}
	if (document.myForm.milongaPass[0].checked) {
	    total = total + 10	
    	}		
	if (document.myForm.wsMon.checked) {
	    total = total + 10	
    	}		
    }
    else {
	switch (numChecked) {
	  case 1:
	    total = 40
	    break
	  case 2:
	    total = 60
	    break
           default:
	    total = 0
	}
	if (document.myForm.milongaPass[0].checked) {
	    total = total + 20	
    	}		
	if (document.myForm.wsMon.checked) {
	    total = total + 20	
    	}		
    }
    }

    document.myForm.totalDisplay.value = "$" + total
    document.myForm.total.value = document.myForm.totalDisplay.value
}		


function validateForm() {

    var formOK = false

    //check for empty strings
    if (checkString(document.myForm.firstName, "First Name") &&
	checkString(document.myForm.lastName, "Last Name") &&
	checkString(document.myForm.city, "City") &&	
	checkString(document.myForm.state, "State")) {
	formOK = true
    }	
    else {
        return false
    }
    
    //check for nothing checked
    if (document.myForm.allPass.checked ||
	document.myForm.milongaPass[0].checked ||
	document.myForm.wsSat.checked ||
  	document.myForm.wsSun.checked ||
	document.myForm.wsMon.checked) {
        formOK = true
    }
    else {
        formOK = false
	alert("You have not registered for any workshops or milongas. Please select one now.")
	document.myForm.allPass.focus()
 	return false
    }

    //check for allPass checked with other options
    if (document.myForm.allPass.checked &&
        (document.myForm.wsSat.checked || 
 	 document.myForm.wsSun.checked ||
	 document.myForm.wsMon.checked ||      	
 	 document.myForm.milongaPass[0].checked)) {
         formOK = false
	 alert("You cannot register for both the All-Inclusive Pass and individual workshops/milongas. Please modify your selection.")
	 document.myForm.allPass.focus()
 	 return false
    }	
    else {
  	formOK = true
    }	

    if (formOK) {
        document.myForm.submit()
    }
}





// Notify user that required field theField is empty.
// String s describes expected contents of theField.value.
// Put focus in theField and return false.
function warnEmpty (theField, s) {   
    var mPrefix = "You did not enter a value into the "	
    var mSuffix = " field. This is a required field. Please enter it now."

    theField.focus()
    alert(mPrefix + s + mSuffix)
    return false
}


function checkString(theField, s)
{   
    //if ((emptyOK == true) && (isEmpty(theField.value))) 
    //	return true;
    if (isWhitespace(theField.value)) 
       return warnEmpty(theField, s);
    else return true;
}


// Returns true if string s is empty or 
// whitespace characters only.
function isWhitespace (s) {   
    var i;
    var whitespace = " \t\n\r";	

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++) {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

// Check whether string s is empty.
function isEmpty(s) {   
    return ((s == null) || (s.length == 0))
}





