﻿// JScript File

/*

// when user clicks enter the continue button will be clicked
function EnterKeySubmit() {

	if( event.keyCode == 13 ) { 
		document.getElementById('btnContinue').click(); 
		event.returnValue = false; 
	}	
	
}

// client side validation for a checkbox
function ValidateCheckBox(oScr, args) {
   args.IsValid = document.getElementById('chkAgree').value;
}	


 // client side validation for a ssn
function ValidateSSN(oScr, args) {

   var ssn;
   
   alert(oScr)
   
   //validates that the system date is in mmddyyyy format				
   ssn = document.getElementById(oScr.controltovalidate).value;
	
   if( ssn.length != 9) {
      args.IsValid = false;
      return;
   }
	
   if( isNaN(ssn) ) {
      args.IsValid = false;
      return;
   }
        	
   args.IsValid = true;
	
}

*/

// this is used to validate a users password 
function ValidatePassword(oScr, args) {

   var UPPER_LETTERS="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var LOWER_LETTERS="abcdefghijklmnopqrstuvwxyz";
   var NUMBERS = "0123456789"

   var bHasLower = false;
   var bHasNumeric = false;
   var bHasUpper = false;
   var password;
   var ch;
   var j;

   password = document.getElementById(oScr.controltovalidate).value  ;             
   
   if ( password.length < 8 ) {args.IsValid = false; return; }
   if ( password.length > 15 ) {args.IsValid = false; return; }
   
   //check for 1 letter and 1 number         
   for(j=0; j<password.length; j++) {
     // call isAlpha recursively for each character

     ch = password.substring(j,j+1);
     if ( UPPER_LETTERS.indexOf(ch) > -1 ) bHasUpper = true;
     if ( LOWER_LETTERS.indexOf(ch) > -1 ) bHasLower = true;
     if ( NUMBERS.indexOf(ch) > -1 ) bHasNumeric = true;           
     
   }
   
   args.IsValid = ( bHasUpper && bHasNumeric && bHasLower )        
   
}



/*

function Back() {   
   history.go(-1);
}

*/

/* validates that a borrower is in the credit union */
/* TMS 14047 */

 function ValidateCreditUnionMember(lenderID) {

      var isCreditUnion = false;
      var isChaseLoan = false;
      
      lenderID=lenderID.substr(0,6)
      
//      if( lenderID == '817854')
//         isCreditUnion = true;
//      else 
      //if (lenderID == '806870')
        // isCreditUnion = true; else 
       // if (lenderID == '818553')
        // isCreditUnion = true;
      //else if (lenderID == '834108')
        // isCreditUnion = true;
//      else if (lenderID == '820323')
//         isCreditUnion = true;
//      else if (lenderID == '826781')
//         isCreditUnion = true;    
      if (lenderID == '805147')
         isChaseLoan = true; 
      else if (lenderID == '834091')
         isChaseLoan = true;  
     // else if (lenderID == '834352')
      //   isCreditUnion = true;
         
    //  if( isCreditUnion ) {
     //    alert('You must be a member of this credit union to get a loan.')
     // }  
      
      
       if( isChaseLoan ) {
         alert('Chase may sell your loan to another lender, but your borrower benefits will not be affected by the sale. For further information, please go to http://www.Chasestudentloans.com/saledisclosure.')
      }  
      
   }
   
   
   /* Validates Address so there is no instance of PO BOX in any form or variation. */
   
   function ValidatePermAddress(oScr, args) {
            
      var AddRegex = /([P,p][.]{0,1}\s*[O,o][.]{0,1}\s*[B,b][o,O][x,X])|([P,p][O,o][S,s][T,t]\s*[O,o][F,f][F,f][I,i][C,c][E,e]\s*[B,b][O,o][X,x])|([N,n]\/[A,a])/;
      var Add;
            
      Add = document.getElementById(oScr.controltovalidate).value;
            
      if (Add.match(AddRegex)) {
         args.IsValid = false;
         return;
      }
      else {
		   args.IsValid = true;
		   return;
		}    
            
   }
   
   /* Validates Reference Address so there is no instance of N/A in any form or variation. */
   
   function ValidateRefAddress(oScr, args) {
            
      var AddRegex = /([N,n]\/[A,a])|^([N,n][A,a])$/;
      var Add;
            
      Add = document.getElementById(oScr.controltovalidate).value;
            
      if (Add.match(AddRegex)) {
         args.IsValid = false;
         return;
      }
      else {
		   args.IsValid = true;
		   return;
		}    
            
   }
   
   function showHideClick(obj,div) 
    {

        var elem = document.getElementById(div);
   
            if (elem.style.display == "none") 
            {
                    elem.style.display = ""; // show the div
                    //obj.src = "../../images/menuArrowLeft.gif"; // change the image

                      
            } 
            else if(elem.style.display != "none")
            {            
                    elem.style.display = "none"; // show the div   
                    //obj.src = "../../images/menuArrow.gif"; // change the image
   
            }


    }
   
      