var bad_entry=false;
var total_hour=0;
var total_point=0;

function set_cursor()
{
  document.assistantship.first_name.focus();
}


function is_empty(checkVal)  
{
    if (checkVal=="") return true;
    else return false;
}

function App_Validator(theForm)
{
  var wrong=false;
  if (theForm.first_name.value=="") 
    {	alert("Enter your first name, please!");theForm.first_name.focus();return false; }
 /*
  else if (theForm.ssn1.value=="") 
    {	alert("Enter your ssn, please!");theForm.ssn1.focus();return false; } 
 else if (theForm.ssn2.value=="") 
    {	alert("Enter your ssn, please!");theForm.ssn2.focus();return false; } 
 else if (theForm.ssn3.value=="") 
    {	alert("Enter your ssn, please!");theForm.ssn3.focus();return false; } 
*/
 else if (theForm.last_name.value=="")
 	{	alert("Enter your last name, please!");theForm.last_name.focus();return false;	}
 else if (theForm.program.value=="") 
    {	alert("Enter your program of intent, please!");theForm.program.focus();return false; }
 else if ( (!(theForm.admin[0].checked))&& (!(theForm.admin[1].checked)) ) 
   {	alert("Select one statement, please!");return false; } 
 else if (theForm.date1.value=="") 
    {	alert("Enter the month of expected graduation date, please!");theForm.date1.focus();return false; } 
 else if (theForm.date2.value=="") 
    {	alert("Enter the day of expected graduation date, please!");theForm.date2.focus();return false; } 
 else if (theForm.date3.value=="") 
    {	alert("Enter the year of expected graduation date, please!");theForm.date3.focus();return false; } 
 /*
  else if (theForm.phone.value=="") 
    {	alert("Enter your phone, please!");theForm.phone.focus();return false; }
 else if(!emailCheck(theForm.email.value))
  { theForm.email.value='';theForm.email.focus();return false; } 
*/
 else if (theForm.email.value=="") 
    {	alert("Enter your E-mail address, please!");theForm.email.focus();return false; } 
 else if ( (!(theForm.department[0].checked))&& (!(theForm.department[1].checked)) ) 
   {	alert("Are you interested outside your department?");return false; } 
  else if ( theForm.summer.value=="" && theForm.fall.value=="" &&  theForm.fall.value=="") 
   {	alert("Fill up one semester at least, please!");return false; } 
  else if ( (!(theForm.hours_10.checked))&& (!(theForm.hours_20.checked)) ) 
   {	alert("Choose the number of hours, please!");return false; } 
}

function emailCheck (emailStr) {

 var emailPat=/^(.+)@(.+)$/;
 var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
 var validChars="\[^\\s" + specialChars + "\]";
 var quotedUser="(\"[^\"]*\")";
 var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
 var atom=validChars + '+';
 var word="(" + atom + "|" + quotedUser + ")";
 var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
 var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
 var matchArray=emailStr.match(emailPat);
 if (matchArray==null) { 
	alert("Please enter a correct e-mail address");
	return false;
	}
var user=matchArray[1];
var domain=matchArray[2];
if (user.match(userPat)==null) {   
    alert("The username of the e-mail doesn't seem to be valid.");
    return false;
}
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {  
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address of the e-mail is invalid!");
		return false;
	    }
    }
}
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name of the e-mail doesn't seem to be valid.")
    return false
}

var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<1 ){
   alert("Please enter a valid e-mail domain name.")
   return false
}
if (len<2) {   var errStr="the e-mail address is missing a hostname!"
   alert(errStr)
   return false
}
return true;
}

function is_letter(checkVal)
{
    var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-'. ";
    var allValid = true;
    for (i = 0;  i < checkVal.length;  i++)
     {
       ch = checkVal.charAt(i);
       for (j = 0;  j < checkOK.length;  j++)
         if (ch == checkOK.charAt(j)) break;
       if (j == checkOK.length)
          {
            allValid = false;
            break;
          }
     }
    	if (!allValid) return (false); 
    	else return true;
}


function is_onlyLetter(checkVal)
{
    	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    	var allValid = true;
    	for (i = 0;  i < checkVal.length;  i++)
    	{
       		ch = checkVal.charAt(i);
       		for (j = 0;  j < checkOK.length;  j++)
         		if (ch == checkOK.charAt(j)) break;
       		if (j == checkOK.length)
       		{
            		allValid = false;
            		break;
       		}
    	}
    	if (!allValid) return (false);
    	else return true;
}


function check_phone(checkVal)
{
    if (!is_number(checkVal))
	{
	  alert("only digits, () or - for phone number");
	  return false;
	}
}
function is_number(checkVal)
{
    var checkOK = "0123456789()- ";
    var allValid = true;
    for (i = 0;  i < checkVal.length;  i++)
     {
       ch = checkVal.charAt(i);
       for (j = 0;  j < checkOK.length;  j++)
         if (ch == checkOK.charAt(j)) break;
       if (j == checkOK.length)
          {
            allValid = false;
            break;
          }
     }
    if (!allValid) return false;
    else return true;
}



