// used for new user
function verifyNewUser()
{
	if (document.newuser.acfname.value.length == 0)
	{
	 alert("Please enter the user's first name.");
	 document.newuser.acfname.focus();
	 return false;
	}
	if (document.newuser.aclname.value.length == 0)
	{
	 alert("Please enter the user's last name.");
	 document.newuser.aclname.focus();
	 return false;
	}
	if (document.newuser.acemail.value.length == 0)
	{
	 alert("Please enter the user's email.");
	 document.newuser.acemail.focus();
	 return false;
	}
}
// used for contact us
function verify() 
{
	if (document.ContactUs.fname.value.length == 0)
	{
	 alert("Please enter your first name.");
	 document.ContactUs.fname.focus();
	 return false;
	}
	if (document.ContactUs.lname.value.length == 0)
	{
	 alert("Please enter your last name.");
	 document.ContactUs.lname.focus();
	 return false;
	}
	if (document.ContactUs.email.value.length == 0)
	{
	 alert("Please enter your email.");
	 document.ContactUs.email.focus();
	 return false;
	}
	if (document.ContactUs.comments.value.length == 0)
	{
	 alert("Please enter your message.");
	 document.ContactUs.comments.focus();
	 return false;
	}
}
//used for Time Extension
function checkTE()
{	
	if (document.newTimeExtension.comments.value.length == 0)
	{
	 alert("Please enter your comments.");
	 document.newTimeExtension.comments.focus();
	 return false;
	}
	if (document.newTimeExtension.totalfunds.value.length == 0)
	{
	 alert("Please enter your amount of funds to be used.");
	 document.newTimeExtension.totalfunds.focus();
	 return false;
	}
	if (validateAmount(document.newTimeExtension.totalfunds) == false)
	{
		return false;
	}
	if (checkDate(document.newTimeExtension.revisedenddate) == false)
	{
		return false;
	}
}

  //validation for the MM/DD/YYYY  format for the entered date
  function checkDate(passDate)
  {
    var passDateValue = passDate.value;
   
    if (passDateValue.length > 0)
    {
      if (isDate(passDateValue) == false)
      {
         passDate.focus();
         return false;  
      }
    }
  }
  
//Begin date validation 
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1000;
var maxYear=9999;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) 
{
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function DaysArray1(n) 
{
	for (var i = 1; i <= 12; i++) {
		k = 31
		if (n==4 || n==6 || n==9 || n==11) {k = 30}
		if (n==2) {k = 29}
   } 
   return k
}

function isDate(dtStr)
{
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(pos1+1,pos2)
    var strMonth=dtStr.substring(0,pos1)
    var strYear=dtStr.substring(pos2+1)

    strYr=strYear
    
	if (strDay.charAt(0)=="0" && strDay.length>1)
    {
     strDay=strDay.substring(1);
    } 
	
    if (strMonth.charAt(0)=="0" && strMonth.length>1) 
    {
      strMonth=strMonth.substring(1);
    }  
	
    for (var i = 1; i <= 3; i++) 
    {
		if (strYr.charAt(0)=="0" && strYr.length>1)
        {
         strYr=strYr.substring(1);
        } 
	}
	
    month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
    
	if (pos1==-1 || pos2==-1)
    {
		alert("Please review the date entered.\n \n Date Format is MM/DD/YYYY."); 
				return false
	}
    
	if (strMonth.length<1 || month<1 || month>12)
    {
		alert("Please review the date entered.\n \n Date Format is MM/DD/YYYY."); 
				return false
	}
    
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > DaysArray1(month))
    {
		alert("Please review the date entered.\n \n Date Format is MM/DD/YYYY."); 
				return false
	}
    
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		alert("Please review the date entered.\n \n Date Format is MM/DD/YYYY."); 
				return false
	}
	
    if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
    {
		alert("Please review the date entered.\n \n Date Format is MM/DD/YYYY."); 
				return false
	}
 return true
}
//End date validation 

function Checkchars(this_field) 
{ 
     var char_count = this_field.value.length; 
     var fullStr = this_field.value + " "; 
     var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi; 
     var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, ""); 
     var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi; 
     var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " "); 
     var splitString = cleanedStr.split(" "); 
     var word_count = splitString.length -1; 

     var good ="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ~`!$@#%^&*()_-+=[]{}<>|/:';?.,"; 
     var good = good + '"'; 
     return true; 
} 


//generic function for the Email validation
    function isEmailAddr(email)
    {
	  var result = false
      var theStr = new String(email)
      var index = theStr.indexOf("@");
      if (index > 0)
      {
        var pindex = theStr.indexOf(".",index);
          if ((pindex > index+1) && (theStr.length > pindex+1))
         	result = true;
      }
      return result;
    }
	
//US Phone validation
function isValidUSphone(arg) {	
	var number;
	var n;
	var msg = "Y";
	if(arg != "") {		
	//alert("The length is" + arg.length);
		if(arg.length == 13) {
				if (arg.charAt(0) != '(' && arg.charAt(4) != ')' && arg.charAt(8) != '-' ){
						alert("Please use this format (***)***-**** for phone number.");
						return false;
				}		
				number = arg.substr(1,3) + arg.substr(5,3) + arg.substr(9,4);			
				if (number.length != 10){
					alert("Invalid US phone number.");
					return false;
				}
		}		
		else if(arg.length == 12) {
				if (arg.charAt(3) == '-' && arg.charAt(7) == '-') {
					msg="N"
				}
				else if(arg.charAt(3) == '.' && arg.charAt(7) == '.') {
					msg="N";
				}
				else if(arg.charAt(3) == ' ' && arg.charAt(7) == ' ') {
					msg="N";
				}
				
				if(msg == 'Y') {
					alert("Invalid phone format.");
					return false;
				}					
				number = arg.substr(0,3) + arg.substr(4,3) + arg.substr(8,4);			
				if (number.length != 10){
					alert("Invalid US phone number.");
					return false;
				}
		}
		else if(arg.length == 10) {
			number=arg;
		}
		else{
			alert("Invalid US phone number. Please use the format (***)***-****.");
			 return false;
		}
		for (var i=0; i < number.length; i++){
			n = number.charAt(i);
			if (isNaN(parseInt(n))){
			   alert("Invalid US phone number.");
			   return false;
			}
		}	
	return true;
	}
}	


//to validate whether the entered nummber is numeric or not	
 function validateNumber(this_field)
  {
         var char_count = this_field.value.length;

         var fullStr = this_field.value + " ";
         var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
         var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
         var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
         var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
         var splitString = cleanedStr.split(" ");
         var word_count = splitString.length -1;
       
        var good="0123456789"
       
        for (var i = 0; i < this_field.value.length; i++)
        {
            if (good.indexOf(this_field.value.charAt(i)) == -1) 
            {
               if ((this_field.value.charCodeAt(i) != 13) && (this_field.value.charCodeAt(i) != 10) && (this_field.value.charCodeAt(i) != 92))
                {
                   alert("Please enter a valid number. Special characters or alphabetic characters are not allowed")
                   this_field.focus();
				   this_field.value = "";
                   return false;
                }    
            }    
        } 
   }     
  //validation function end	
	
//validation function to check whether the user is entering a valid amount or not
  function validateAmount(this_field)
  {
         var char_count = this_field.value.length;

         var fullStr = this_field.value + " ";
         var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
         var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
         var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
         var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
         var splitString = cleanedStr.split(" ");
         var word_count = splitString.length -1;
       
        var good="0123456789."
       
        for (var i = 0; i < this_field.value.length; i++)
        {
            if (good.indexOf(this_field.value.charAt(i)) == -1) 
            {
               if ((this_field.value.charCodeAt(i) != 13) && (this_field.value.charCodeAt(i) != 10) && (this_field.value.charCodeAt(i) != 92))
                {
                   alert("Please enter a valid amount. Special characters or alphabetic characters are not allowed")
                   this_field.focus();
                   return false;
                }    
            }    
        } 
   }     
  //validation function end	
  
//Begin validation for editProjectInfo.cfm
 function validateProjectInfo()
 {
	if (document.editProjectInfo.work_street.value.length == 0)
   {
      alert("Please enter the street address");
	  document.editProjectInfo.work_street.focus();
	  return false;
	}
	if (document.editProjectInfo.work_city.value.length == 0)
	{
	   alert("Please enter a valid city");
	   document.editProjectInfo.work_city.focus();
	   return false;
	 }
  
	if (document.editProjectInfo.work_postal_code.value.length == 0  && document.editProjectInfo.work_state.value > 0)
   {
      alert("Please enter a valid postal code");
	  document.editProjectInfo.work_postal_code.focus();
	  return false;
   }
	else if(document.editProjectInfo.work_postal_code.value != "") {
		//no edit for foreign countries
		if(document.editProjectInfo.work_state.value > 0) {
			var good="0123456789 -"
			for (var i = 0; i < document.editProjectInfo.work_postal_code.value.length; i++) {
				if (good.indexOf(document.editProjectInfo.work_postal_code.value.charAt(i)) == -1) {
					alert("Please enter numbers in the zip code.")
					document.editProjectInfo.work_postal_code.focus();
					return false;
				}    
			}
		}
	}
	
	if(document.editProjectInfo.phone.value.length == 0) {
		alert("Please enter a valid phone number");
	  	document.editProjectInfo.phone.focus();
	  	return false;
	}
   	 if (document.editProjectInfo.work_country.value == 221 
	&& document.editProjectInfo.work_state.selectedIndex == 0)
	{
	   alert("Please select a valid state");
	   document.editProjectInfo.work_country.focus();
	   return false;
	 }
   	 if (document.editProjectInfo.work_country.selectedIndex == 0)
	{
	   alert("Please select a valid country");
	   document.editProjectInfo.work_country.focus();
	   return false;
	 }
	if (document.editProjectInfo.project_title.value.length == 0)
	{
	   alert("Please enter a project title.");
	   document.editProjectInfo.project_title.focus();
	   return false;
	 }
   	 if (document.editProjectInfo.worldarea.selectedIndex == 0)
	{
	   alert("Please select a world area");
	   document.editProjectInfo.work_country.focus();
	   return false;
	 }
   if (document.editProjectInfo.list_partner.value.length > 200)
	{
		alert("List agreement Partners is limited to 200 characters. Please re-enter");
		document.editProjectInfo.list_partner.focus();
		return false;
	}
	
	if ((document.editProjectInfo.prog_key.value == 3) || (document.editProjectInfo.prog_key.value == 4) ||
	   (document.editProjectInfo.prog_key.value == 5) || (document.editProjectInfo.prog_key.value == 6) ||
	   (document.editProjectInfo.prog_key.value == 7) || (document.editProjectInfo.prog_key.value == 8) || 
	   (document.editProjectInfo.prog_key.value == 9) || (document.editProjectInfo.prog_key.value == 10) || 
	   (document.editProjectInfo.prog_key.value == 13)) {		   

   if (document.editProjectInfo.abstractnarr.value.length == 0)
	{
		alert("Please enter your abstract.");
		document.editProjectInfo.abstractnarr.focus();
		return false;
	}

        // if the user enters only the blanks in the abstract
        var whiteSpace = 0;
        
        for (i=0; i < document.editProjectInfo.abstractnarr.value.length; i++)
        {
           if (document.editProjectInfo.abstractnarr.value.charCodeAt(i) == 32)
           {
              whiteSpace = whiteSpace + 1;
           } 
        }

        if (document.editProjectInfo.abstractnarr.value.length == whiteSpace)
        {
		alert("Please enter the abstract.");
		document.editProjectInfo.abstractnarr.focus();
          return false;
        }

	if (document.editProjectInfo.prog_key.value != 6  && document.editProjectInfo.prog_key.value != 7)
	{
		var Selected_any = false;
		var objSelect = document.editProjectInfo.lang;
		for (var i=1; i<objSelect.length; i++) {	
    		if (objSelect.options[i].selected) {
				Selected_any = true;
			}
  		}
  		if (!Selected_any) {
	  	alert("Please select Languages");
	  	document.editProjectInfo.lang.focus();
	  	return false;
  		}
	}
		var Selected_yes = false;
		var objSelect = document.editProjectInfo.projCountry;
		for (var i=1; i<objSelect.length; i++) {	
    		if (objSelect.options[i].selected) {
				Selected_yes = true;
			}
  		}
  		if (!Selected_yes) {
	  	alert("Please select Countries");
	  	document.editProjectInfo.projCountry.focus();
	  	return false;
  		}		
	}
	if ((document.editProjectInfo.prog_key.value == 3) || (document.editProjectInfo.prog_key.value == 5) || 
		(document.editProjectInfo.prog_key.value == 6) || (document.editProjectInfo.prog_key.value == 8) || 
		(document.editProjectInfo.prog_key.value == 9)) {
		var Selected_any = false;
  		var objSelect = document.editProjectInfo.disc;
  		for (var i=1; i<objSelect.length; i++) {	
    		if (objSelect.options[i].selected) {
				Selected_any = true;
			}
  		}
  		if (!Selected_any) {
	  	alert("Please select Disciplines");
	  	document.editProjectInfo.disc.focus();
	  	return false;
  		}		 
	}	

  if ((document.editProjectInfo.prog_key.value > 2) && (document.editProjectInfo.prog_key.value != 14) && (document.editProjectInfo.prog_key.value != 11)) {
  	var Selected_any = false;
  	var objSelect = document.editProjectInfo.subject;
  	for (var i=1; i<objSelect.length; i++) {	
    	if (objSelect.options[i].selected) {
			Selected_any = true;
		}
  	}
  	if (!Selected_any) {
	  alert("Please select Subject Areas");
	  document.editProjectInfo.subject.focus();
	  return false;
  	}
  }


}	  //End validation for editProjectInfo.cfm	 

//Begin validation for updateUserAccount.cfm
	
function validateUpdateUser()
{
if ((document.updateUser.currPassword.value.length == 0) ||(document.updateUser.currPassword.value ==' '))
    {
      alert("Please enter your current password");
	  document.updateUser.currPassword.focus();
	  return false;
	 }

 if (document.updateUser.newPassword.value.length < 6)
 {
     alert("New password must be at least six characters long");
	    document.updateUser.newPassword.focus();
	    return false;
 }
    
 if ((document.updateUser.newPassword.value) != (document.updateUser.conPassword.value))
 {
   alert("The new password and confirmation don't match.  Please re-enter.");
   document.updateUser.newPassword.focus();
   return false;
 }

}
//End of validation for updateUserAccount.cfm	   

//Begin validation for validateTAR when user clicks save inctar.cfm
function validateTAR()
{
 if (document.Tar.partic_nbr.value.length == 0 || document.Tar.partic_nbr.value < 1)
  {
    alert("Please enter the number of participants.");
    document.Tar.partic_nbr.focus();
    return false;
  }  
  var good="0123456789"
  for (var i = 0; i < document.Tar.partic_nbr.value.length; i++)
     {
        if (good.indexOf(document.Tar.partic_nbr.value.charAt(i)) == -1) 
        {
          alert("Number of participants must be numeric.")
          document.Tar.funds_expended.focus();
          return false
          break;
        }    
     }
	if (document.Tar.participant_name.value.length == 0)
	{
		 alert("Please enter the participant name(s)");
		 document.Tar.participant_name.focus();
		 return false;
	}

	if (document.Tar.participant_name.value.length > 500)
	{
	  alert("The Participants names are limited to 500 characters.");
	  document.Tar.participant_name.focus();
	  return false;
	}
	if (document.Tar.travel_explanation.value.length > 2000)
	{
	  alert("Please limit the purpose of travel explanation to 2000 characters.");
	  document.Tar.travel_explanation.focus();
	  return false;
	}
if (document.Tar.funds_expended_explanation.value.length > 2000)
{
  alert("Please limit the Explanation of Funds Extended to 2000 characters.");
  document.Tar.funds_expended_explanation.focus();
  return false;
}

  if (checkDate(eval("document.Tar.leaving_date")) == false)
  {
    eval("document.Tar.leaving_date.focus()");
	return false;
  } 
  if (checkDate(eval("document.Tar.return_date")) == false)
  {
    eval("document.Tar.return_date.focus()");
	return false;
  }  

	if (document.Tar.tar_approval_comment.value.length > 1000)
	{
	  alert("Please limit the Comments to 1000 characters.");
	  document.Tar.tar_approval_comment.focus();
	  return false;
	}

  var good="0123456789"
  for (var i = 0; i < document.Tar.funds_expended.value.length; i++)
     {
        if (good.indexOf(document.Tar.funds_expended.value.charAt(i)) == -1) 
        {
          alert("Please enter whole numbers only in the funds to be expended.")
          document.Tar.funds_expended.focus();
          return false;
        }    
     }
}




//Begin validation for validateTARToIEPS inctar.cfm
function validateTARToIEPS()
{
 if (document.Tar.partic_nbr.value.length == 0 || document.Tar.partic_nbr.value < 1)
  {
    alert("Please enter the number of participants.");
    document.Tar.partic_nbr.focus();
    return false;
  }  
  var good="0123456789"
  for (var i = 0; i < document.Tar.partic_nbr.value.length; i++)
     {
        if (good.indexOf(document.Tar.partic_nbr.value.charAt(i)) == -1) 
        {
          alert("Number of participants must be numeric.")
          document.Tar.partic_nbr.focus();
          return false
          break;
        }    
     }

if (document.Tar.participant_name.value.length == 0)
{
	 alert("Please enter the participant name(s)");
	 document.Tar.participant_name.focus();
	 return false;
}

if (document.Tar.participant_name.value.length > 500)
{
  alert("The Participants names are limited to 500 characters.");
  document.Tar.participant_name.focus();
  return false;
}

if (document.Tar.currentprogram.value != 'AORC' && document.Tar.currentprogram.value != 'GPA') 
{
  if ((document.Tar.travel_to_from_us[0].checked == false) && (document.Tar.travel_to_from_us[1].checked == false))
  {
    alert("Please select Travel To/From US.");
    document.Tar.travel_to_from_us[0].focus();
    return false;
  }
  if ((document.Tar.travel_to_from_us[0].checked == true) && (document.Tar.in_country.checked == true))
  {
    alert("If Traveling to the US, In-country travel cannot be selected.");
    document.Tar.in_country.focus();
    return false;
  }
  if ((document.Tar.in_country.checked == false) && (document.Tar.international_travel.checked == false) && (document.Tar.currentprogram.value != 'GPA'))
  {
    alert("Please select either In-Country or International Travel or both.");
    document.Tar.in_country.focus();
    return false;
  }
}

if (document.Tar.currentprogram.value != 'GPA') 
{
  if(document.Tar.type.options[document.Tar.type.selectedIndex].value == "") {  
    alert("Please select the Type of Participant.");
    document.Tar.type.focus();
    return false;
  }
}

if (document.Tar.currentprogram.value == 'FLAS'){
	if ((document.Tar.type.options[document.Tar.type.selectedIndex].value == 9) && (document.Tar.POApprove[0].checked != true)) {
		alert("The student's overseas program request must be approved by an IEPS program officer before a TAR can be submitted for the student.");
		document.Tar.POApprove[0].focus();
		return false;
	}
}

if(document.Tar.purpose.options[document.Tar.purpose.selectedIndex].value == "")
  {
    alert("Please select the Purpose of Travel.");
    document.Tar.purpose.focus();
    return false;
  }

if (document.Tar.travel_explanation.value == "")
  {
    alert("Please provide a brief explanation of the purpose of travel.");
    document.Tar.travel_explanation.focus();
    return false;
  }  

if (document.Tar.travel_explanation.value.length > 2000)
{
  alert("Please limit the purpose of travel explanation to 2000 characters.");
  document.Tar.travel_explanation.focus();
  return false;
}

 var cSelect = 0;
 for (Count = 0; Count < document.Tar.country_key.length; Count++)
   {
    if ((document.Tar.country_key[Count].selectedIndex))
    {
     cSelect = 1;
     }
   }
 if (cSelect == 0)
 {
  alert("Please select the country");
  document.Tar.country_key[0].focus();
  return false;
 } 

if (document.Tar.funds_expended.value.length == 0)
  {
    alert("Please enter the funds to be expended.");
    document.Tar.funds_expended.focus();
    return false;
  }  
//  if (document.Tar.funds_expended_explanation.value == "")
//  {
//    alert("Please provide a brief explanation of the funds expended.");
//    document.Tar.funds_expended_explanation.focus();
//    return false;
//  } 

  var good="0123456789"
  for (var i = 0; i < document.Tar.funds_expended.value.length; i++)
     {
        if (good.indexOf(document.Tar.funds_expended.value.charAt(i)) == -1) 
        {
          alert("Please enter whole numbers only in the funds to be expended.")
          document.Tar.funds_expended.focus();
          return false;
        }    
     }
  
if (document.Tar.funds_expended_explanation.value.length > 2000)
{
  alert("Please limit the Explanation of Funds Extended to 2000 characters.");
  document.Tar.funds_expended_explanation.focus();
  return false;
}

  if (document.Tar.leaving_date.value == "")
  {
    alert("Please enter the departure date.");
    document.Tar.leaving_date.focus();
    return false;
  }
  if (checkDate(eval("document.Tar.leaving_date")) == false)
  {
    eval("document.Tar.leaving_date.focus()");
	return false;
  } 
  if (document.Tar.return_date.value == "")
  {
    alert("Please enter the return date.");
    document.Tar.return_date.focus();
    return false;
  }
  if (checkDate(eval("document.Tar.return_date")) == false)
  {
    eval("document.Tar.return_date.focus()");
	return false;
  }  
  var leavingDate = new Date(eval("document.Tar.leaving_date.value"));
  var returningDate = new Date(eval("document.Tar.return_date.value"));
  if (leavingDate.valueOf() > returningDate.valueOf())
  { 
    alert("Date of leaving must be before the date of returning.");
    document.Tar.leaving_date.focus();
    return false;
  }

if (document.Tar.tar_approval_comment.value.length > 1000)
{
  alert("Please limit the Comments to 1000 characters.");
  document.Tar.tar_approval_comment.focus();
  return false;
}


	if ((document.Tar.FlyAmerica[0].checked != true) && (document.Tar.FlyAmerica[1].checked != true))
	{
	  alert("The travel request must either comply with the Fly America Act or the grant funds being used for overseas costs, excluding international travel.");
	  document.Tar.FlyAmerica[0].focus();
	  return false;
	}

  if ((document.Tar.currentprogram.value == 'GPA' || document.Tar.international_travel.checked == true) && (document.Tar.depart_date_1.value == "") && (document.Tar.retdepart_date_1.value == "") && (document.Tar.FlyAmerica[1].checked != true))
  {
     alert("For international travel, at least one leg of departure or return itinerary must be provided.");
     document.Tar.depart_date_1.focus();
     return false;
  }   
     
  //validation for Departure Itinerary
  for (i=1; i<=6; i++)
  {
	 if ((eval("document.Tar.depart_date_" + i + ".value.length") > 0)
		||(eval("document.Tar.depart_city_" + i + ".value.length") > 0)
		||(eval("document.Tar.depart_st_" + i + ".value.length") > 0)
		||(eval("document.Tar.arr_date_" + i + ".value.length") > 0)
		||(eval("document.Tar.arr_city_" + i + ".value.length") > 0)
		||(eval("document.Tar.arr_st_" + i + ".value.length") > 0)
		||(eval("document.Tar.airline" + i + ".value.length") > 0))
   {
    if (checkDate(eval("document.Tar.depart_date_" + i)) == false)
    {
      eval("document.Tar.depart_date_" + i + ".focus()");
	return false;
    }
    if (eval("document.Tar.depart_city_" + i + ".value") == "")
    {
     alert("Please enter the city of departure for Departure Itinerary in record " + i)
     eval("document.Tar.depart_city_" + i + ".focus()");
    return false;   
    }
    if (eval("document.Tar.depart_st_" + i + ".value") == "")
    {
     alert("Please enter the state or country of departure for Departure Itinerary in record " + i)
     eval("document.Tar.depart_st_" + i + ".focus()");
    return false;   
    }   
    if (eval("document.Tar.arr_date_" + i + ".value") == "")
      {
         alert("Please enter the arrival date for Departure Itinerary in record " + i);
         eval("document.Tar.arr_date_" + i + ".focus()");
         return false;
      } 
    if (checkDate(eval("document.Tar.arr_date_" + i)) == false)
    {
      eval("document.Tar.arr_date_" + i + ".focus()");
      return false;
    }
    
  //validate if departure date is less than the arrival date (less one for international date line)
    var depDate = new Date(eval("document.Tar.depart_date_" + i + ".value"));
    var arrDate = new Date(eval("document.Tar.arr_date_" + i + ".value"));
    var depPrev = new Date(depDate.getTime() - 86400000 ); 

    if (arrDate.valueOf() < depPrev.valueOf())
    {
     alert("Arrival date must be after the departure date. Please re-enter.");
     eval("document.Tar.arr_date_" + i + ".focus();");
     return false; 
    }
    if (eval("document.Tar.arr_city_" + i + ".value") == "")
    {
     alert("Please enter the city of arrival for Departure Itinerary in record " + i)
     eval("document.Tar.arr_city_" + i + ".focus()");
     return false;   
     }
    if (eval("document.Tar.arr_st_" + i + ".value") == "")
    {
     alert("Please enter the state or country of arrival for Departure Itinerary in record " + i)
     eval("document.Tar.arr_st_" + i + ".focus()");
     return false;   
     }
     if (eval("document.Tar.airline" + i + ".value") == "")
     {
      alert("Please enter the departure airline and flight number in record " + i);
      eval("document.Tar.airline" + i + ".focus();");
      return false;
     }
   }   // if depart date entered
  } // for loop


 
  //validation for Return Itinerary 
  for (i=1; i<=6; i++)
  {
	 if ((eval("document.Tar.retdepart_date_" + i + ".value.length") > 0)
		||(eval("document.Tar.retdepart_city_" + i + ".value.length") > 0)
		||(eval("document.Tar.retdepart_st_" + i + ".value.length") > 0)
		||(eval("document.Tar.retarr_date_" + i + ".value.length") > 0)
		||(eval("document.Tar.retarr_city_" + i + ".value.length") > 0)
		||(eval("document.Tar.retarr_st_" + i + ".value.length") > 0)
		||(eval("document.Tar.retairline" + i + ".value.length") > 0))
   {	  
    if (checkDate(eval("document.Tar.retdepart_date_" + i)) == false)
    {
      eval("document.Tar.retdepart_date_" + i + ".focus()");
	return false;
    }
   if (eval("document.Tar.retdepart_city_" + i + ".value") == "")
    {
     alert("Please enter the city of departure for Return Itinerary in record " + i)
     eval("document.Tar.retdepart_city_" + i + ".focus()");
    return false;   
    }
    if (eval("document.Tar.retdepart_st_" + i + ".value") == "")
    {
     alert("Please enter the state or country of departure for Return Itinerary in record " + i)
     eval("document.Tar.retdepart_st_" + i + ".focus()");
    return false;   
    }   
    if (eval("document.Tar.retarr_date_" + i + ".value") == "")
      {
         alert("Please enter the arrival date for Return Itinerary in record " + i);
         eval("document.Tar.retarr_date_" + i + ".focus()");
         return false;
      } 
    if (checkDate(eval("document.Tar.retarr_date_" + i)) == false)
    {
      eval("document.Tar.retarr_date_" + i + ".focus()");
      return false;
    }
    
    //validate if departure date is less than the arrival date
    var depDate = new Date(eval("document.Tar.retdepart_date_" + i + ".value"));
    var arrDate = new Date(eval("document.Tar.retarr_date_" + i + ".value"));
    var depPrev = new Date(depDate.getTime() - 86400000 ); 

    if (arrDate.valueOf() < depPrev.valueOf())
    {
     alert("Arrival date must be after the departure date. Please re-enter.");
     eval("document.Tar.retarr_date_" + i + ".focus();");
     return false; 
    }
    if (eval("document.Tar.retarr_city_" + i + ".value") == "")
    {
     alert("Please enter the city of arrival for Return Itinerary in record " + i)
     eval("document.Tar.retarr_city_" + i + ".focus()");
     return false;   
     }
    if (eval("document.Tar.retarr_st_" + i + ".value") == "")
    {
     alert("Please enter the state or country of arrival for Return Itinerary in record " + i)
     eval("document.Tar.retarr_st_" + i + ".focus()");
     return false;   
     }
     if (eval("document.Tar.retairline" + i + ".value") == "")
     {
      alert("Please enter the return airline and flight number in record " + i);
      eval("document.Tar.retairline" + i + ".focus();");
      return false;
     }
   }   // if depart date entered
  } // for loop
  

}
//End of  validation for validateTARToIEPS() 


// added publications here - use for common publications.cfm in /includes dir
function validatePublications()
{
   if (validateNumber(document.publications.pub_val1) == false)
   {     return false;   }
   if (validateNumber(document.publications.pub_val2) == false)
   {     return false;   }
   if (validateNumber(document.publications.pub_val3) == false)
   {     return false;   }
   if (validateNumber(document.publications.pub_val4) == false)
   {     return false;   }
   if (validateNumber(document.publications.pub_val5) == false)
   {     return false;   }
   if (validateNumber(document.publications.pub_val6) == false)
   {     return false;   }
   if (validateNumber(document.publications.pub_val7) == false)
   {     return false;   }
   if (validateNumber(document.publications.pub_val8) == false)
   {     return false;   }
   if (validateNumber(document.publications.oth_pub_val1) == false)
   {     return false;   }
   if (validateNumber(document.publications.oth_pub_val2) == false)
   {     return false;   }
   if (validateNumber(document.publications.oth_pub_val3) == false)
   {     return false;   }
   	 
   var char_count = document.publications.comments.value.length;
  if (char_count > 2000) 
	 {
	  alert("Comment is limited to 2000 characters. Please re-enter.");
	  document.publications.comments.focus();
	  return false;
	}
}		

function validateTravelto()
{
   if (document.TraveltoUS.type.selectedIndex == 0)
   {
        alert("Please select the Type of Participant.");
        document.TraveltoUS.type.focus();
        return false;
   }
   if (document.TraveltoUS.destination.selectedIndex == 0)
   {
        alert("Please select the Country Traveling from.");
        document.TraveltoUS.type.focus();
        return false;
   }
   if (validateNumber(document.TraveltoUS.funds_expended) == false)
   {     return false;   }
   if (validateNumber(document.TraveltoUS.inst_contrib) == false)
   {     return false;   }
   if (validateNumber(document.TraveltoUS.per_contrib) == false)
   {     return false;   }
   if (validateNumber(document.TraveltoUS.other_contrib) == false)
   {     return false;   }
if (document.TraveltoUS.funds_expended.value == "") 
   {	document.TraveltoUS.funds_expended.value=0;   }
if (document.TraveltoUS.inst_contrib.value == "") 
   {	document.TraveltoUS.inst_contrib.value=0;   }
if (document.TraveltoUS.per_contrib.value == "") 
   { document.TraveltoUS.per_contrib.value=0;   }
if (document.TraveltoUS.other_contrib.value == "") 
   { document.TraveltoUS.other_contrib.value=0;   }


}
function validateTravelFrom()
{
   if (document.TravelFromUS.type.selectedIndex == 0 && document.TravelFromUS.destination.selectedIndex == 0
     && document.TravelFromUS.purpose.selectedIndex == 0 && document.TravelFromUS.discipline.selectedIndex == 0
     && document.TravelFromUS.other_dest.value == '' && document.TravelFromUS.other_purpose.value == '')
  {
        return true;
   }

   if (document.TravelFromUS.type.selectedIndex == 0)
   {
        alert("Please select the Type of Participant.");
        document.TravelFromUS.type.focus();
        return false;
   }
   
   if ((document.TravelFromUS.destination.selectedIndex == 0) && (document.TravelFromUS.other_dest.value == ''))
   {
        alert("Please select the country of destination or enter the country in the Other field");
        document.TravelFromUS.destination.focus();
        return false;
   }
   
   if ((document.TravelFromUS.purpose.selectedIndex == 0) && (document.TravelFromUS.other_purpose.value == ''))
   {
        alert("Please select the Purpose of Travel");
        document.TravelFromUS.purpose.focus();
        return false;
   }

   if (validateNumber(document.TravelFromUS.funds_expended) == false)
   {     return false;   }
   if (validateNumber(document.TravelFromUS.inst_contrib) == false)
   {     return false;   }
   if (validateNumber(document.TravelFromUS.per_contrib) == false)
   {     return false;   }
   if (validateNumber(document.TravelFromUS.other_contrib) == false)
   {     return false;   }
if (document.TravelFromUS.funds_expended.value == "") 
   {	document.TravelFromUS.funds_expended.value=0;   }
if (document.TravelFromUS.inst_contrib.value == "") 
   {	document.TravelFromUS.inst_contrib.value=0;   }
if (document.TravelFromUS.per_contrib.value == "") 
   { document.TravelFromUS.per_contrib.value=0;   }
if (document.TravelFromUS.other_contrib.value == "") 
   { document.TravelFromUS.other_contrib.value=0;   }

 } //end of validations for TravelFromUS.cfm
 
 
 //call this function for onBlur event for 2 or 4 columns budget page
function fillTotal(colNum)
{ //alert (colNum);
  var totalColVal;
  var inDirCostVal;
  var tempBudgetVal;
  var tempinDirCostVal;
  var tempTotalDirCost;
  var tempTotalIndirCost;
  
for (col = 1; col <= colNum; col++) //2 or 4 columns
{
   totalColVal = 0;
   tempTotalDirCost = 0;
   tempTotalIndirCost = 0;
   
  for (row = 1; row < 8; row++) // 8 rows 
  {		
  		tempBudgetVal = 0;
		//set to 0 if it's blank
	 if (eval("document.frmBudget.budget_value" + row + "_" + col + ".value") == "")
	    {
	    eval("document.frmBudget.budget_value" + row + "_" + col + ".value = 0");
	    }
	else
	{
		//check for numeric numbers without decimals
   	   tempBudgetVal = parseInt(eval("document.frmBudget.budget_value" + row + "_" + col + ".value"));
	   
	    if (eval("document.frmBudget.budget_value" + row + "_" + col + ".value") != tempBudgetVal)
	   {     
        	alert("Budget values must be numeric without decimals.");
			eval("document.frmBudget.budget_value" + row + "_" + col + ".value = ''");
			eval("document.frmBudget.budget_value" + row + "_" + col + ".focus()");
	  	return false;
	   }   
	   
	   eval("document.frmBudget.budget_value" + row + "_" + col + ".value =" + tempBudgetVal);
	}
 
	//set Total Direct Costs
       totalColVal = totalColVal + tempBudgetVal;
       eval("document.frmBudget.budget_value8_" + col + ".value =" + totalColVal);
  }  
  
   //check Total Indirect Costs
   if (eval("document.frmBudget.budget_value9_" + col + ".value") == "")
	    {
	    eval("document.frmBudget.budget_value9_" + col + ".value = 0");
	    }
  else 
  {
      tempinDirCostVal = parseInt(eval("document.frmBudget.budget_value9_" + col + ".value"));
	   
	   if (eval("document.frmBudget.budget_value9_" + col + ".value") != tempinDirCostVal )
	   {
		   	alert("Budget values must be numeric without decimals.");
	 	      tempinDirCostVal = 0;
			eval("document.frmBudget.budget_value9_" + col + ".value = ''");
		  	eval("document.frmBudget.budget_value9_" + col + ".focus()");
		return false;
	   }
	   
	   //Indirect Costs value may not exceed 8% of direct costs.
	  inDirCostVal = totalColVal*0.08;
	  
//	   if (eval("document.frmBudget.budget_value9_" + col + ".value") > inDirCostVal)
//	  {
//		  alert("Indirect Costs value may not exceed 8% of direct costs.");
//		  eval("document.frmBudget.budget_value9_" + col + ".value = ''");
//		  eval("document.frmBudget.budget_value9_" + col + ".focus()");
//	  	return false;
//	  }
	   
	eval("document.frmBudget.budget_value9_" + col + ".value =" + tempinDirCostVal);
  }//end of row loop
  
  //set Total Budget
   tempTotalDirCost = parseInt(eval("document.frmBudget.budget_value8_" + col + ".value"));
   tempTotalIndirCost = parseInt(eval("document.frmBudget.budget_value9_" + col + ".value"));
   if (document.frmBudget.matchingBudget.value == 0)
   {
  	eval("document.frmBudget.budget_value10_" + col + ".value =" + tempTotalDirCost + "+" + tempTotalIndirCost);
   }
  if (document.frmBudget.matchingBudget.value == 1)
  {
	if (eval("document.frmBudget.budget_value10_" + col + ".value") == "")
	{
	    tempTrain = 0;
	}
	else
	{
	   tempTrain = parseInt(eval("document.frmBudget.budget_value10_" + col + ".value"));
	   if (eval("document.frmBudget.budget_value10_" + col + ".value") != tempTrain )
	   {
		   	alert("Budget values must be numeric without decimals.");
			tempTrain = 0;
			eval("document.frmBudget.budget_value10_" + col + ".value = ''");
		  	eval("document.frmBudget.budget_value10_" + col + ".focus()");
		return false;
	   }
	}
  	eval("document.frmBudget.budget_value11_" + col + ".value =" + tempTotalDirCost + "+" + tempTotalIndirCost + "+" + tempTrain);
  	eval("document.frmBudget.budget_value11_" + col + ".value =" + tempTotalDirCost + "+" + tempTotalIndirCost + "+" + tempTrain);
  }
} // end loop

//calculate percentage
if (document.frmBudget.matchingBudget.value == 1)
{
  if (document.frmBudget.budget_value11_1.value > 0 || document.frmBudget.budget_value11_2.value > 0)
  {
	document.frmBudget.percentage_1.value = Math.round(document.frmBudget.budget_value11_1.value*100 / (parseInt(eval("document.frmBudget.budget_value11_1.value"))+parseInt(eval("document.frmBudget.budget_value11_2.value"))));
	document.frmBudget.percentage_2.value = 100 - document.frmBudget.percentage_1.value;
  }
  if (colNum == 4)
  {
	if (document.frmBudget.budget_value11_3.value > 0 || document.frmBudget.budget_value11_4.value > 0)
	{
	document.frmBudget.percentage_3.value = Math.round(document.frmBudget.budget_value11_3.value*100 / (parseInt(eval("document.frmBudget.budget_value11_3.value"))+parseInt(eval("document.frmBudget.budget_value11_4.value"))));
	document.frmBudget.percentage_4.value = 100 - document.frmBudget.percentage_3.value;
	}
  }
}
}


// validate comments field for 2 columns budget page
function validateBudget()
{
  if (document.frmBudget.carryover_from.value.length == 0)
  {
    alert("Total amount carried over is required.");
    document.frmBudget.carryover_from.focus();
    return false;
  }  
  if (document.frmBudget.carryover_to.value.length == 0)
  {
    alert("Total amount to be carried over is required.");
    document.frmBudget.carryover_to.focus();
    return false;
  }  

 tempNum = parseInt(document.frmBudget.carryover_from.value);
	
	  if (document.frmBudget.carryover_from.value != tempNum)
	  {
	    alert("Total amount carried over must be numeric without a decimal.");
	    document.frmBudget.carryover_from.focus();
	    return false;
	  }  

 tempNum = parseInt(document.frmBudget.carryover_to.value);
	
	  if (document.frmBudget.carryover_to.value != tempNum)
	  {
	    alert("Total amount to be carried over must be numeric without a decimal.");
	    document.frmBudget.carryover_to.focus();
	    return false;
	  }  

//attachment is required
   if (document.frmBudget.attachment.value.length == 0 && document.frmBudget.old_attach.value.length == 0)
   {
     alert("Please click the Browse... button and select your budget attachment.");
     document.frmBudget.attachment.focus();
     return false;     
   }
   if (document.frmBudget.comments.value.length > 1000)
   {
     alert("The comment is limited to 1000 characters and spaces.");
     document.frmBudget.comments.focus();
     return false;     
   }
}



