/*****FEDWIRE SERVICES CONTINGENCY TESTS 
 *****Test Review Form validation script  - January 2003
*/
function clrtxt(fieldObject){
   fieldObject.value="";} 
function UnCheckRadio(radiobtn){
   var value = null;
   for (var i=0; i<radiobtn.length; i++){
       if (radiobtn[i].checked) {
	       radiobtn[i].checked=false;
           radiobtn[i].value=null;
        }
}
}
function getRadioValue(radiobtn){
   var value = null;
   for (var i=0; i<radiobtn.length; i++){
       if (radiobtn[i].checked) {
           value = radiobtn[i].value;}
        }
    return value;
} 
//****Start validating the form
function ValidateForm(theForm)
{var Flager = true
 var FlagerB = true
 var counter=0;
 var counterB=0;
 var counter1=0;
 var questions =""; 
 var questionsB ="";
 

 
if (theForm.InstitutionName.value == "Required")
  {
    alert("Please enter \"Institution Name\".");
    theForm.InstitutionName.focus();
    return (false);
  }

if (theForm.ABANumber.value == "Required")
  {
    alert("Please enter \"ABA Number\".");
    theForm.ABANumber.focus();
    return (false);
  }

if (theForm.ABANumber.value.length < 9)
  {
    alert("Please enter all nine digits of the \"ABA Number\".");
    theForm.ABANumber.focus();
    return (false);
  }

  var checkOK = "0123456789-";
  var checkStr = theForm.ABANumber.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  var multi= 0;
  var sumchek= 0;

  var checker=true;
  for (i = 0;  i < checkStr.length;  i++)
  {ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
     if (j == checkOK.length)
    {allValid = false;
      break;}
    allNum += ch;}
    if (!allValid)
    {alert("Only Numeric values are allowed in the \"ABA Number\" field.");
      theForm.ABANumber.focus();
      theForm.ABANumber.select();
      return (false);}
    if (allValid){
      for (i = 0;  i < 9;  i++)
      {if (i==0){
       ch = checkStr.charAt(0);
       multi=3*ch;
       sumchek=multi+sumchek;
       multi=0;}
       if (i==1){
       ch = checkStr.charAt(1);
       multi=7*ch;
       sumchek=multi+sumchek;
       multi=0;}
       if (i==2){
       ch = checkStr.charAt(2);
       multi=1*ch;
       sumchek=multi+sumchek;
       multi=0;}
       if (i==3){
       ch = checkStr.charAt(3);
       multi=3*ch;
       sumchek=multi+sumchek;
       multi=0;}
       if (i==4){
       ch = checkStr.charAt(4);
       multi=7*ch;
       sumchek=multi+sumchek;
       multi=0;}
       if (i==5){
       ch = checkStr.charAt(5);
       multi=1*ch;
       sumchek=multi+sumchek;
       multi=0;}
       if (i==6){
       ch = checkStr.charAt(6);
       multi=3*ch;
       sumchek=multi+sumchek;
       multi=0;}
       if (i==7){
       ch = checkStr.charAt(7);
       multi=7*ch;
       sumchek=multi+sumchek;
       multi=0;}
       if (i==8){
       ch = checkStr.charAt(8);
       multi=1*ch; 
       sumchek=multi+sumchek;
       sumchek=sumchek%10;      
       if(sumchek!=0)
          {
            allValid = false;
            alert("Invalid ABA Number.  Please Check the ABA Number you entered.")
            theForm.ABANumber.focus();
            theForm.ABANumber.select();
            return false}
      }
    }
}

 
if (theForm.ContactName.value == "Required")
  {
    alert("Please enter \"Contact Name\".");
    theForm.ContactName.focus();
    return (false);
  }
if (theForm.ContactPhone.value == "Required")
  {
    alert("Please enter  \"Contact Phone\".");
    theForm.ContactPhone.focus();
    return (false);
  }

   
if (theForm.FundsTested.checked) {counter1 = counter1+1;} 
if (theForm.SecuritiesTested.checked) {counter1 = counter1+1;}

if (counter1==0)      
  {
    alert("Please select at least one application type.");
	theForm.FundsTested.focus();
    return (false); 
  }
 
 if (getRadioValue(theForm.Question1A)==null)
    {
     questions +="*Question- 1A*";
     counter=counter+1;
     Flager=false; 	
     }else{
	  if ((getRadioValue(theForm.Question1A)=="No") && (theForm.Comments1A.value=="IF NO, PROVIDE COMMENTS"))
	  {alert("Question-1A - Please explain why you selected No.");
	   theForm.Comments1A.focus();
       return (false)}}
 if (getRadioValue(theForm.Question1B)==null)
    {
     questions +="*Question- 1B*";
     counter=counter+1;
     Flager=false; 	
     }else{
	  if ((getRadioValue(theForm.Question1B)=="No") && (theForm.Comments1B.value=="IF NO, PROVIDE COMMENTS"))
	  {alert("Question-1B - Please explain why you selected No.");
	   theForm.Comments1B.focus();
       return (false)}}
 if (getRadioValue(theForm.Question1C)==null)
    {
     questions +="*Question- 1C*";
     counter=counter+1;
     Flager=false; 	
     }else{
	  if ((getRadioValue(theForm.Question1C)=="No") && (theForm.Comments1C.value=="IF NO, PROVIDE COMMENTS"))
	  {alert("Question-1C - Please explain why you selected No.");
	   theForm.Comments1C.focus();
       return (false)}}
 if (getRadioValue(theForm.Question1D)==null)
    {
     questions +="*Question- 1D*";
     counter=counter+1;
     Flager=false; 	
     }else{
	  if ((getRadioValue(theForm.Question1D)=="No") && (theForm.Comments1D.value=="IF NO, PROVIDE COMMENTS"))
	  {alert("Question-1D - Please explain why you selected No.");
	   theForm.Comments1D.focus();
       return (false)}}
 if (getRadioValue(theForm.Question1E)==null)
    {
     questions +="*Question- 1E*";
     counter=counter+1;
     Flager=false; 	
     }else{
	  if ((getRadioValue(theForm.Question1E)=="No") && (theForm.Comments1E.value=="IF NO, PROVIDE COMMENTS"))
	  {alert("Question-1E - Please explain why you selected No.");
	   theForm.Comments1E.focus();
       return (false)}}
	 
 if (Flager==false && counter>1)
    {
      alert("Questions : "+questions+"   \"Yes\" OR \"No\" should be checked for these questions.");
	  return (false);
    }
  if (Flager==false && counter==1)
    {
      alert("Question : "+questions+"  A \"Yes\" OR \"No\" should be checked for this question.");
	  return (false);
    }
	 
 if (getRadioValue(theForm.Question2A)==null)
    {
     questionsB +="*2A*-";
     counterB=counterB+1;
     FlagerB=false; 	
     }else{
	  if ((getRadioValue(theForm.Question2A)=="Yes") && (theForm.Comments2A.value=="IF YES, PROVIDE COMMENTS"))
	  {alert("Question-2A - Please explain why you selected Yes.");
	   theForm.Comments2A.focus();
       return (false)}}
 if (getRadioValue(theForm.Question2B)==null)
    {
     questionsB +="*2B*-";
     counterB=counterB+1;
     FlagerB=false; 	
     }
	else{
	  if ((getRadioValue(theForm.Question2B)=="Yes") && (theForm.Comments2B.value=="IF YES OR NO, PROVIDE COMMENTS"))
	  {alert("Question-2B - Please explain why you selected Yes.");
	   theForm.Comments2B.focus();
       return (false)}
	  if ((getRadioValue(theForm.Question2B)=="No") && 
	  (theForm.Comments2B.value=="IF YES OR NO, PROVIDE COMMENTS"))
	  {alert("Question-2B - Please explain why you selected No.");
	   theForm.Comments2B.focus();
       return (false)
	  }
	}
 if (getRadioValue(theForm.Question2C)==null)
    {
     questionsB +="*2C*-";
     counterB=counterB+1;
     FlagerB=false; 	
     }else{
	  if ((getRadioValue(theForm.Question2C)=="Yes") && (theForm.Comments2C.value=="IF YES, PROVIDE COMMENTS"))
	  {alert("Question-2C - Please explain why you selected Yes.");
	   theForm.Comments2C.focus();
       return (false)}}


 if (FlagerB==false && counterB>1)
    {
      alert("Questions : "+questionsB+"   \"Yes\" OR \"No\" OR \"Not Applicable\" should be checked for these questions.");
	  return (false);
    }
  if (FlagerB==false && counterB==1)
    {
      alert("Question : "+questionsB+"  A \"Yes\" OR \"No\" OR \"Not Applicable\" should be checked for this question.");
	  return (false);
    }
	 
if (theForm.Comments1A.value == "IF NO, PROVIDE COMMENTS")
    {theForm.Comments1A.value="";}
if (theForm.Comments1B.value == "IF NO, PROVIDE COMMENTS")
    {theForm.Comments1B.value="";}
if (theForm.Comments1C.value == "IF NO, PROVIDE COMMENTS")
    {theForm.Comments1C.value="";}
if (theForm.Comments1D.value == "IF NO, PROVIDE COMMENTS")
    {theForm.Comments1D.value="";}
if (theForm.Comments1E.value == "IF NO, PROVIDE COMMENTS")
    {theForm.Comments1E.value="";}
if (theForm.Comments2A.value == "IF YES, PROVIDE COMMENTS")
    {theForm.Comments2A.value="";}
if (theForm.Comments2B.value == "IF YES OR NO, PROVIDE COMMENTS")
    {theForm.Comments2B.value="";}
if (theForm.Comments2C.value == "IF YES, PROVIDE COMMENTS")
    {theForm.Comments2C.value="";}
if (theForm.Suggestions.value == "ADDITIONAL COMMENTS")
    {theForm.Suggestions.value="";}

  
 return (true);
}

