function isEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[1-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

/*Check to see if js is enabled*/
function cc(){
 /* check for a cookie */
  if (document.cookie == ""){
	/*change jsenabled field value to false */
    document.form1.jsenabled.value ="false"  
  } else {
    document.form1.jsenabled.value ="true"
  }
}


function formValidator(){
	var txtFirstName = document.getElementById('txtFirstName');
	var txtLastName = document.getElementById('txtLastName');
	var txtEmail = document.getElementById('txtEmail');
	var txtPhone = document.getElementById('txtPhone');
	var txtPrevInstitution = document.getElementById('txtPrevInstitution');
	var txtPrevDegree = document.getElementById('txtPrevDegree');
	var txtPrevMajor = document.getElementById('txtPrevMajor');
	var txtUiucDegree = document.getElementById('txtUiucDegree');
	var txtProgramAdmitted = document.getElementById('txtProgramAdmitted');
	var listAssistantshipName = document.getElementById('listAssistantshipName');
	
	if(isEmpty(txtFirstName, "First name is a required field.")){
		if(isEmpty(txtLastName, "Last name is a required field.")){
			if(emailValidator(txtEmail, "Please enter a valid email address.")){
				if(isEmpty(txtPhone, "Please enter a valid phone number.")){
					if(isEmpty(txtPrevInstitution, "Previous institution is a required field.")){
						if(isEmpty(txtPrevDegree, "Previous degree is a required field.")){	   
							if(isEmpty(txtPrevMajor, "Previous major is a required field.")){	   
								if(isEmpty(txtUiucDegree, "Degree to be obtained from UIUC is a required field.")){	   
									if(isEmpty(txtProgramAdmitted, "Program admitted to is a required field.")){	   
											return true;
									}
								}
							}
						}
					}
				}
			}
		}
	}
			
	return false;
	
}
