function vaidateForm(){

  var checkList = [0,1,2,3,4,5];
  for(i=0;i<checkList.length;++i){
    theValue = checkList[i];
    if(document.rasForm.elements[theValue].value == ""){
      alertMesseage(theValue);
      return(false);
    }
  }

  /*
  if(document.rasForm.state.value == ""){
      alert("Please Select A State");
      return(false);
  }
  */
  
  theValidZip = isZip(document.rasForm.zip.value);
  if(theValidZip == false){
    alert("Please Enter A Valid Zip Code '12345' or '12345-1234'");
    return(false);
  }

  theValidEmail = isEmail(document.rasForm.email.value);
  if(theValidEmail == false){
    alert("Please Enter A Valid Email Address");
    return(false);
  }
  
  theValidPhone = isPhoneNum(document.rasForm.phone.value);
  if(theValidPhone == false){
    alert("Please Enter A Valid Phone Number 'XXX-XXX-XXXX'");
    return(false);
  }
  
  return(true);
  
}

/////////////////////////////////////////////////////////////////////////////////

function isZip(theStr){
	var theStrLength = theStr.length;
	if((theStrLength == 5) || (theStrLength == 10)){
		if(theStrLength == 5){
			for(i=0;i<theStrLength;i++){
				 if ((theStr.charAt(i) < "0") || (theStr.charAt(i) > "9")) { return(false); }
			}			
		}else if(theStrLength == 10){
			var theDashChar = theStr.indexOf("-");
			if(theDashChar == -1){
				return(false);
			}
			for(i=0;i<theStrLength;i++){
				if(i != theDashChar){
					if ((theStr.charAt(i) < "0") || (theStr.charAt(i) > "9")) { return(false); }
				}
			}
		}
	}else{
		return(false);
	}
}

function isPhoneNum(theStr) {
  if(theStr.length != 12) { return(false); }
  if(theStr.charAt(3) != "-") && (theStr.charAt(7) != "-")) { return(false); }
  for(i=0;i<2;++i){
    if ((theStr.charAt(i) < "0") || (theStr.charAt(i) > "9")) { return false; }
  }
  for(i=4;i<6;++i){
    if ((theStr.charAt(i) < "0") || (theStr.charAt(i) > "9")) { return false; }
  }
  for(i=8;i<11;++i){
    if ((theStr.charAt(i) < "0") || (theStr.charAt(i) > "9")) { return false; }
  }
  return(true);
}


function isEmail(theStr) {
  return ((theStr != "") && (theStr.indexOf("@") != -1) && (theStr.indexOf(".") != -1));
}

  
function alertMesseage(theValue){
  switch(theValue){
    case(0):
      theMsg = "Please Enter Your Name"
      break;
    case(1):
      theMsg = "Please tell us your position."
      break;
    case(2):
      theMsg = "Please tell us the school you work for"
      break;
    case(3):
      theMsg = "Please Enter Your Address"
      break; 
    case(4):
      theMsg = "Please Enter Your City"
      break;
    case(6):
      theMsg = "Please Enter Your Zip"
      break;
  }
  alert(theMsg);
}
