// Copyright © 2001 by Apple Computer, Inc., All Rights Reserved.


function checkWholeForm() {
	var thisForm = document.getElementById("theForm");
    var why = "";
	why += checkName(thisForm.name.value);
	why += checkEmail(thisForm.email.value);
	why += checkStreet(thisForm.street.value);
	why += checkCity(thisForm.city.value);
	why += checkState(thisForm.state.value);
	why += checkZip(thisForm.zipcode.value);
	why += checkContact(thisForm.emergency_contact.value);
	why += checkRelationship(thisForm.emergency_relationship.value);
    why += checkPhone(thisForm.emergency_phone.value);
	why += checkYoga(thisForm.yoga_experience.selectedIndex);
	why += checkMeditation(thisForm.meditation_experience.selectedIndex);
	why += checkMethod(thisForm.method.value);
    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "Please enter your email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}


// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) {
var error = "";
if (strng == "") {
   error = "Please fill in the emergency contact number.\n";
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The emergency contact number contains illegal characters.";
  
    }
    if (!(stripped.length == 10)) {
        error = "The emergency contact number is the wrong length. Make sure you included an area code.\n";
    } 
return error;
}    


// non-empty textbox

function checkName(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please fill in your name.\n"
  }
return error;     
}

function checkStreet(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please fill in your street address.\n"
  }
return error;     
}

function checkCity(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please fill in your city.\n"
  }
return error;     
}

function checkState(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please fill in your state or province.\n"
  }
return error;     
}

function checkZip(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please fill in your zip code.\n"
  }
return error;     
}

function checkContact(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please fill in the emergency contact.\n"
  }
return error;     
}

function checkRelationship(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please fill in the emergency contact relationship.\n"
  }
return error;     
}

function checkMethod(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please tell us how you learned about the retreat.\n"
  }
return error;     
}


// drop down



function checkYoga(choice) {
    var error = "";
    if (choice == 0) {
       error = "Please select your yoga experience from the drop-down list.\n";
    }    
return error;
} 

function checkMeditation(choice) {
    var error = "";
    if (choice == 0) {
       error = "Please select your meditation experience from the drop-down list.\n";
    }    
return error;
} 