function trim(f)
{
/*  This function trims leading and trailing spaces
  from the value of the input argument */
     x = f.value;
     while (x.substring(0,1) == ' ') x = x.substring(1);
     while (x.substring(x.length-1,x.length) == ' ') x = x.substring(0,x.length-1);
     f.value = x
 }

function TMLsub()
{    trim(document.TML.lastname_in);
     trim(document.TML.firstname_in);
     lnamein = document.TML.lastname_in.value.toUpperCase();
     fnamein = document.TML.firstname_in.value.toUpperCase();
     if (lnamein.length < 2 &&
         fnamein.length < 2 )
       {alert("Name arguments must be at least 2 characters.")}
     else
       { if (lnamein.length == 0)
           {var x = "%"}
         else
          {var x = lnamein};
         if (fnamein.length > 0)
         {x = x + "," + fnamein};
         for (i=0; i < x.length; i++)
           {if (x.substring(i,i+1) == '*')
              {
               x = x.substring(0,i) + '%' + x.substring(i+1,99)
              }
            };
         document.TML.lastname.value = x;
         document.TML.query_arg.value = x;
         document.TML.submit();
        };
}
function posttrim(f)
/*  This function trims trailing spaces from the value of the input argument */
{
   if ( f.value.length > 0 )
    {
       var i = f.value.length;
         {while((f.value.substring(i - 1, i) == " ") && (i > 0) )
          { i = i - 1 }
         };
       f.value = f.value.substring(0,i);
    };
}

function pretrim(f)
/* This function trims leading spaces from the value of the input argument */
{
   if ( f.value.length > 0 )
    {
       var j = f.value.length + 1;
       var i = 0;
         {while((f.value.substring(i, i + 1) == " ") && (i < f.value.length ) )
          { i = i + 1 }
         };
       f.value = f.value.substring(i,j);
    };
}

function lengthed(f, fname, min, max)
/* this function checks the length of the value of argument f, issues an alert if
it is not between min and max, inclusive, and returns a value of FALSE if this is the case.
The fname argument supplies a text string for the name of the variable, and is used only
in the alert message */
   {  var returnVal = false
     {  if (f.value.length > max)
            {alert(fname + " is limited to " + max + " characters.  Your entry is " +
             f.value.length + " characters.")
            }
       else if
          (f.value.length < min)
            {alert(fname + " must be at least " + min + " characters.  Your entry is " +
             f.value.length + " characters.")
            }
       else returnVal = true }
       return returnVal
}
function embedcheck(f)
{
   if (f.value.indexOf(",") > -1)
      {if (f.value.charAt(f.value.indexOf(",") + 1) == ' ')
        { f.value = f.value.substring(0,f.value.indexOf(",") + 1) +
         f.value.substring(f.value.indexOf(",") + 2,99);
        };
      };
   var alpha_count = 0;
   f.value = f.value.toUpperCase();
   for (var i = 0; i < f.value.length; i++)
      { if (f.value.substring(i,i+1) >= "A" && f.value.substring(i,i+1) <= "Z")
         {alpha_count = alpha_count + 1
         };
      };
   if (alpha_count < 2)
     {alert("Name search argument must contain at least two alpha characters.");
      returnVal = false;
     }
   else
     {
      returnVal = true;
     };

   return returnVal;
}
function editform()
{    
	trim(document.searchform.lastname_in);
	trim(document.searchform.firstname_in);
	     if (document.searchform.lastname_in.value.length >1 ||
         document.searchform.firstname_in.value.length >1  )
       		{
			if (document.searchform.lastname_in.value == "Last name" ||
				document.searchform.lastname_in.value.length == 0)/*{
				document.searchform.lastname_in.value = "";
			}
		if (document.searchform.lastname_in.value.length == 0)*/{
			var x = "%";}
		else{
			var x = document.searchform.lastname_in.value;}		

			if (document.searchform.firstname_in.value != "First" &
				document.searchform.firstname_in.value.length > 0){
				/*document.searchform.firstname_in.value = "";
			}
						
			if (document.searchform.firstname_in.value.length > 0){*/
				x = x + "," + document.searchform.firstname_in.value;}	
			document.searchform.lastname.value = x;
/*      if  (lengthed(document.searchform.lastname,"Name Search Argument",2,39)
            && embedcheck(document.searchform.lastname) )
         {*/
           for (i=0; i < document.searchform.lastname.value.length; i++)
              {if ((document.searchform.lastname.value.substring(i,i+1) == "*" ) ||
                    (document.searchform.lastname.value.substring(i,i+1) == "'"  ) )
                 {
                  document.searchform.lastname.value =
                  document.searchform.lastname.value.substring(0,i) + '%' +
                  document.searchform.lastname.value.substring(i+1,99)
                  }
               };
           document.searchform.lastname.value =
           document.searchform.lastname.value.toUpperCase();
           document.searchform.query_arg.value =
           document.searchform.lastname.value;
           if (Math.random()<= -1) {
             document.searchform.action="http://lookup.wellsfargo.com/asp/emps001.asp";
             }
           return true;
         }
      else
         { 
		 alert("Name arguments must be at least 2 characters.");
		 document.searchform.lastname_in.focus();
           return false;
         }
}

function newsearch() {
  if (editform()) {
    document.searchform.submit();
  }
}

/*function newsearch()
{     	trim(document.searchform.lastname_in);
	trim(document.searchform.firstname_in);
		if (lengthed(document.searchform.lastname_in, "lastname", 2, 39)){
	     if (document.searchform.lastname_in.value.length >1 ||
         document.searchform.firstname_in.value.length >1  )
       		{
		if (document.searchform.lastname_in.value.length == 0){
			var x = "%";}
		else{
			var x = document.searchform.lastname_in.value;}			
			if (document.searchform.firstname_in.value.length > 0){
				x = x + "," + document.searchform.firstname_in.value;}	
			document.searchform.lastname.value = x;

           for (i=0; i < document.searchform.lastname.value.length; i++)
              {if ((document.searchform.lastname.value.substring(i,i+1) == "*" ) ||
                    (document.searchform.lastname.value.substring(i,i+1) == "'"  ) )
                 {
                  document.searchform.lastname.value =
                  document.searchform.lastname.value.substring(0,i) + '%' +
                  document.searchform.lastname.value.substring(i+1,99)
                  }
               };
           document.searchform.lastname.value =
           document.searchform.lastname.value.toUpperCase();
           document.searchform.query_arg.value =
           document.searchform.lastname.value;
             document.searchform.submit()
       }
      else
       {document.searchform.lastname_in.focus()
       }; 
	   }
}*/

function soundex()
{ if (editform())
   {
    var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var codes = " 123 12  22455 12623 1 2 2";
    var code_1 = "";
    var code_2 = "";
    var lname = document.searchform.lastname.value;
    if (lname.indexOf(",") >= 0)
      {lname = lname.substring(0,lname.indexOf(","));
       document.searchform.lastname.value = lname;
      };
    var soundex_key = lname.charAt(0);
    for (var i = 1; i < lname.length; i++)
      { if  (!(lname.charAt(i) == " ") && !(lname.charAt(i) == lname.charAt(i - 1)))
          { code_1 = codes.charAt(chars.indexOf(lname.charAt(i)));
            code_2 = codes.charAt(chars.indexOf(lname.charAt(i - 1)));
            if ( !(code_1 == " ")  && !(code_1 == code_2) )
              { soundex_key = soundex_key + code_1 }
          }
      };
    soundex_key = soundex_key + "0000";
    soundex_key = soundex_key.substring(0,4);
    document.soundexform.lastname.value =
       document.searchform.lastname.value;
    document.soundexform.lname_soundex.value =
         soundex_key;
    document.soundexform.submit();
    };
}
function pressenter()
{
    if (editform())
      {return true
      }
    else
      { return false
      };
}

function checkbrowser()
{
  document.searchform.lastname.focus();
  if (navigator.appVersion.substring(0,1) < "4")
    {alert("***OBSOLETE BROWSER WARNING***" +
           "\n\nYour browser, " +
           navigator.appName + " " + navigator.appVersion +
           ", is obsolete." +
           "\n\nPlease contact your PC support representative to obtain an upgrade.")
     return false
    }
   else
    { return true
    };

}
function emailhelp()
{ windowx=window.open('empshe1.htm','windowx','dependent=yes,alwaysRaised=yes,scrollbars=yes,Width=600,Height=400')
}

function sethtx()
{  
   document.searchform.htx_member.value = "emps001.htx";
   var i = document.searchform.lastname.value.indexOf("''");
   if (i > -1)
     {document.searchform.lastname.value = document.searchform.lastname.value.substring(0,i) + "'" + document.searchform.lastname.value.substring(i + 2,document.searchform.lastname.value.length + 1);
      document.searchform.query_arg.value = document.searchform.lastname.value;};
   document.searchform.lastname.focus(); 
}

var FocusNeeded = true; // set a global flag
var isNS6 = navigator.userAgent.toLowerCase().indexOf("gecko") == -1 ? false : true;
    
function showIt() {
	// Set the focus to the 1st screen field
        if (FocusNeeded) {
         
         
            if (window.location.hash.indexOf("#Enroll") > -1) {
                document.searchform.lastname_in.focus();
            } else {
                document.searchform.lastname_in.focus();
            }
         
        }
}

// Used to trigger the form submit when user hits Enter while in the destination field.  
// See last line of code in ind_footer file or compiled source for how function is called.
function entrevous(keypressed) {
    // The Document Object Model event we need is only available in Javascript 1.2, MSIE4+ and NS4+
	// This functions is the onKeyPress event handler for the destination field
	var key;        
	// Test	of MSIE DOM without all that parsing of the agent string
	// NN and MSIE use different DOMs
	if (isNS6) {
	  // Navigator 6
	  key=keypressed.keyCode;
	} else if  (document.all) {
	  // MSIE 4,5
	    key=window.event.keyCode;
	} else {
	  // Navigator 4, could also test for object document.layers
	    key=keypressed.which;
	};
		      
	// Check each key pressed for character code 13 (carriage return), AND
	// then SUBMIT the form for the user
	if (key==13) {
	newsearch();

	}
    
}
function loadit(){
showIt();
}