var bad_entry=false;
var total_hour=0;
var total_point=0;

function set_cursor()
{
  document.VITA.first_name.focus();
}


function is_empty(checkVal)  
{
    if (checkVal=="") return true;
    else return false;
}

function req_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.last_name.value=="") 
    {	alert("Enter your last name, please!");theForm.last_name.focus();return false; }
 else if (theForm.address1.value=="") 
    {	alert("Enter your address, please!");theForm.address1.focus();return false; } 
 else if (theForm.city.value=="") 
    {	alert("Enter your city, please!");theForm.city.focus();return false; } 
 else if (theForm.state.selectedIndex==0) 
    {	alert("Select your state, please!");theForm.state.focus();return false; } 
 else if (theForm.zip.value=="") 
    {	alert("Enter your zip code, please!");theForm.zip.focus();return false; } 
 else if (theForm.phone1.value=="") 
    {	alert("Enter your area code, please!");theForm.phone1.focus();return false; } 
 else if (theForm.phone2.value=="") 
    {	alert("Enter your phone, please!");theForm.phone2.focus();return false; } 
 else if (theForm.phone3.value=="") 
    {	alert("Enter your phone, please!");theForm.phone3.focus();return false; } 
 else if (theForm.email.value=="") 
    {	alert("Enter your email, please!");theForm.email.focus();return false; } 
 else if (theForm.program.selectedIndex==0) 
    {	alert("Select your program of interest, please!");theForm.program.focus();return false; } 
 else if (theForm.status.selectedIndex==0) 
    {	alert("Select your status, please!");theForm.status.focus();return false; } 
 else if (theForm.meetWith[0].checked && theForm.meetTime.value=="") 
    {	alert("Enter your meet time, please!");theForm.meetTime.focus();return false; } 
 else if (theForm.meetWith[0].checked && theForm.beforeAfter.selectedIndex==0) 
    {	alert("Select your prefered tour time, please!");theForm.beforeAfter.focus();return false; } 
 else if (theForm.meetWith[1].checked && theForm.date1.value=="") 
    {	alert("Enter at least one of your desired date/time, please!");theForm.date1.focus();return false; } 
return true;
}

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_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;
}

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 toggle_meetTime(theForm)
{
	if (theForm.meetWith[0].checked)
	{
	  theForm.meetTime.disabled = false;
	  theForm.beforeAfter.disabled = false;
	  theForm.date1.value = "";
	  theForm.date2.value = "";
	  theForm.date3.value = "";
	  theForm.date1.disabled = true;
	  theForm.date2.disabled = true;
	  theForm.date3.disabled = true;
	  theForm.meetTime.focus();
	 }
	 else
	 {
	  theForm.meetTime.value = "";
	  theForm.beforeAfter.selectedIndex =0;
	  theForm.beforeAfter.disabled = true;
	  theForm.meetTime.disabled = true;
	  theForm.date1.disabled = false;
	  theForm.date2.disabled = false;
	  theForm.date3.disabled = false;
//	  theForm.date1.focus();
	}
}

