var reg_exp=/^[a-z][\w\.]*@[\w\.]+\.[a-z]{2,3}/i

function validate(current_form) {
    
    var missing_fields = new Array()
    var total_missing = 0
    
    for (counter = 0; counter < current_form.length; counter++) {
    
        if ((current_form[counter].type == "text" ||
            current_form[counter].type == "textarea" ||
            current_form[counter].type == "password") &&
            current_form[counter].mandatory) {
            
            if (its_empty(current_form[counter].value)) {
              
                missing_fields[total_missing] = current_form[counter]
                total_missing++
            }
        }
    }

 
    if (total_missing > 0) {
    
        var missing_message = "Sorry, you must complete the following " +
                              (total_missing == 1 ? " field:" : "fields:") +
                              "\n______________________________\n\n"
        
        for (counter = 0; counter < missing_fields.length; counter++) {
            missing_message += missing_fields[counter].name + "\n"
        }
    
        missing_message += "\n______________________________\n\n" +
                       "Please complete these fields and then resubmit the form."
        alert(missing_message)
        
        missing_fields[0].focus()
    }
    else {
          validate3(current_form)
    }
}

function its_empty(string_value) {

    if (string_value == "" || string_value == null) {
            return true
    }
    
        return false
}

function validate3(current_form) {

if(reg_exp.test(current_form.Email_address.value)) {
	display_data(current_form)
	return true
	}
	else {
	alert("Please enter a valid e-mail address.")
	return false
	}
}


function display_data(current_form) {
    
    var confirm_message = "Here's the data you have entered into the form:\n" 
+   "             To submit this data click 'OK' \n" +

                          "______________________________\n\n"
    
    for (var counter = 0; counter < current_form.length; counter++) {
    
        if (current_form[counter].type == "text" ||
            current_form[counter].type == "textarea") {
            
                confirm_message +=current_form[counter].name + " : " +
                                 current_form[counter].value + "\n"
        }


        else if (current_form[counter].type == "checkbox") {
        
            confirm_message +=current_form[counter].name + " : " +
                              current_form[counter].checked + "\n"
        }
        
      
               else if (current_form[counter].type == "select-one") {
        
                  confirm_message += current_form[counter].name + " : " +
            current_form[counter].options[current_form[counter].selectedIndex].text + "\n"
        }
        
              else if (current_form[counter].type == "select-multiple") {
        
                var chosen_ones = new Array()
            chosen_ones = get_selections(current_form[counter])
            
             if (chosen_ones.length > 0) {
                confirm_message += current_form[counter].name + " : "
                for (var counter2 = 0; counter2 < chosen_ones.length; counter2++) {
                    confirm_message += current_form[counter].options[chosen_ones[counter2]].text
                    if (counter2 < chosen_ones.length - 1) {
                        confirm_message += " + "
                    }
                }
            }
        }
    }
    
    confirm_message += "\n______________________________\n\n" +
                       "To alter or edit your data please click 'Cancel' and re-submit"
    
    var submit_ok = confirm(confirm_message)
   
if (submit_ok)  {
	document.forms[0].submit()
	}
	else {
	     return  false
	}
}

function get_selections(current_list) {

    var selected_array = new Array()
    var current_index = 0
    for (var counter = 0; counter < current_list.options.length; counter++) {
        if (current_list.options[counter].selected) {
            selected_array[current_index] = current_list.options[counter].index
            current_index++
        }
    }
    return selected_array
}