// JavaScript Document
function req_Validator(theForm){	
	if (theForm.start_term.value=="")
		{ alert("Please select your start term!");theForm.start_term.focus();return false; }
	else if (theForm.program1.value=="") 
		{ alert("Enter at least one program of interest, please!");theForm.program1.focus();return false; } 
	else 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.country.value=="") 
        { alert("Select your country, please!");theForm.country.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 name, please!");theForm.city.focus();return false; } 
	else if (theForm.country.value=="USA" && theForm.us_state.value=="") 
        { alert("Select your state name, please!");theForm.us_state.focus();return false; } 
	else if (theForm.country.value!="USA" && theForm.province.value=="") 
        { alert("Enter your province name, please!");theForm.us_state.focus();return false; } 
	else if (theForm.zip_code.value=="") 
        { alert("Enter your zip code, please!");theForm.zip_code.focus();return false; } 
	else if (theForm.email.value=="") 
        { alert("Enter your email, please!");theForm.email.focus();return false; }
	else if (!theForm.gender[0].checked &&!theForm.gender[1].checked) 
        { alert("Select your gender, please!");theForm.gender[0].focus();return false; }	
	else if (theForm.age.value=="") 
        { alert("Select your age range, please!");theForm.age.focus();return false; } 
	//else if (theForm.phone.value=="") 
      //  { alert("Enter your  phone number, please!");theForm.phone.focus();return false; }
	else if (theForm.how_hear1.value=="") 
        { alert("Please let us know how you learned about us!");theForm.how_hear1.focus();return false; }
	else if (theForm.gpa.value=="")
		{ alert("Enter your grades, please!"); theForm.gpa.focus(); return false; }
	else if (theForm.country.value!="USA" && ((!theForm.iBT[0].checked &&!theForm.iBT[1].checked)&&(!theForm.TOEFL[0].checked&&!theForm.TOEFL[1].checked)&&(!theForm.IELTS[0].checked&&!theForm.IELTS[1].checked)))
		{ alert("Please enter your English assessment scores!"); theForm.iBT[0].focus(); return false; }
	
		
	if(theForm.campus_tour[0].checked)
	{
		theForm.action ="tour.asp";
		theForm.target="_self";
		return true;
	}
	else if(theForm.campus_tour[1].checked)
	{	
		theForm.action ="https://grad.towson.edu/servlet/reqinfoTour";
		theForm.target="_self";
		return true;
	}
	
}


function Checked(box)
{
  if(box.checked)
   {
      return true;
   }
  else
   {
   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;
}
function is_length3(checkVal)
{
  
	if(checkVal.length == 3)
	return true;
	else return false;
	
}

function is_length4(checkVal)
{
  
	if(checkVal.length == 4)
	return true;
	else return false;
	
}

function is_gpanumber(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 toggle(theForm)
{
	if (theForm.country.value == "USA")
	{
	  theForm.province.disabled = true;
	  theForm.us_phone1.disabled = false;
	  theForm.us_phone2.disabled = false;
	  theForm.us_phone3.disabled = false;
	  theForm.intl_phone.disabled = true;
	  document.getElementById('state').style.display="";
	  document.getElementById('English').style.visibility='hidden';
	 }
	 else
	 {
		theForm.province.disabled = false;
		theForm.intl_phone.disabled = false;
		theForm.us_phone1.disabled = true;
		theForm.us_phone2.disabled = true;
		theForm.us_phone3.disabled = true;
		document.getElementById('state').style.display='none';
		document.getElementById('English').style.visibility='visible';
		theForm.armed_forces.disabled = true;
	  	theForm.military_branch.disabled = true;
	 }
}		//end of toggle


function toggleTexBox(theForm)
{
	if (theForm.contact_you[0].checked)
		theForm.questions.disabled = false;
	else
		theForm.questions.disabled = true;
}

function toggleMili(theForm)
{
	if (theForm.armed_forces[0].checked)
		theForm.military_branch.disabled = false;
	else
		theForm.military_branch.disabled = 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 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;
}



