//called from /pages/public/ssi/scripts/myghLogin.js
/*
function stripZeros(unstrippedUserId) {
  var pattern = new RegExp(/^([0\s]+)/);
  var userId;
  var bAgent = navigator.userAgent;
  var bVersion = parseInt(navigator.appVersion);
  var bFullVersion = parseFloat(navigator.appVersion);
  var bName = navigator.appName;
  var bPlatform = navigator.platform;
  
  if (window.RegExp) { // be sure browser supports regular expressions
    
    if (((bPlatform.indexOf('Mac') == '-1') && (bName == 'Microsoft Internet Explorer')) || ((bName == 'Netscape') && (bVersion >= '5'))) { // check brower version and if not msie/mac or netscape 4 or below, then strip the leading zeros and spaces

      if (unstrippedUserId.match(pattern) != null) { // strip zeros and spaces when they exist at the beginning of the string
        var stuffToStrip = unstrippedUserId.match(pattern);
          userId = unstrippedUserId.substring(stuffToStrip[0].length, unstrippedUserId.length);
      }
      
      else { // otherwise pass the string to the userId field
        userId = unstrippedUserId;
      }
    }
    
    else { // due to bugs, if the browser is mac/msie then let user know that zeros and spaces are not allowed at the beginning of the userId
      userId = elseAlert(unstrippedUserId);
    }
  }

  else { // browsers that don't support regular expressions do this
    userId = elseAlert(unstrippedUserId); // let user know that zeros and spaces are not allowed at the beginning of the userId
  }
  return userId;
}
*/

function stripZeros(userId)
{
//alert("Inside stripZeros, userId = |" + userId + "|");
  if (userId == null)
  {
    //do nothing
  }
  else if (userId.charAt(0) != "0" && userId.charAt(0) != " ")
  {
    // return userId;
  }
  else
  {
    var charsToDelete = 0;
    var currentChar;
    var stopStripping = false;
    
    for (x = 0; stopStripping == false; x++)
    {
      currentChar = userId.charAt(x);
      
//alert("CurrentChar = " + currentChar);

      if (currentChar == "0" || currentChar == " ")
      {
        charsToDelete++;
//alert("Chars to delete = " + charsToDelete);
      }
      else
      {
        stopStripping = true;
      }
    }
      
    userId = userId.substring(charsToDelete);
       
  }
  return stripTrailingSpaces(userId);
}


function stripTrailingSpaces(userId)
{
//alert("Inside stripTrailingSpaces, userId = |" + userId + "|");

	var stringLength = userId.length;
	var startPoint;
	
	if( (userId == null) || (stringLength == 0) )
	{
		// do nothing
	}
	else 
	{
//alert("UserId length = " + stringLength);

	    var charsToDelete = 0;
	    var currentCharacter;
    	    var stopStripping = false;
    	    
	 for (x = stringLength -1 ; stopStripping == false; x--)
	 {
		currentCharacter = userId.charAt(x);
		
//alert("CurrentChar = |" + currentCharacter + "|");

		 if( (currentCharacter == "") || (currentCharacter == " "))
		 {
			charsToDelete++;
			
//alert("Chars to delete = " + charsToDelete);

		 }
		 else
		 {
			stopStripping = true;
		 }
   	 }
   	 startPoint = stringLength - charsToDelete;
//alert("startPoint = " + startPoint);
   	 userId = userId.substring(0, startPoint);
   	 
//alert("at end of stripLeadingSpaces, userId = |" + userId + "|");

   	 
   	}
	 return userId;	
}





function elseAlert(unstrippedUserId) {
  var userId = '0'; //set to 0 for flag as not to submit form
  if (unstrippedUserId.charAt(0) == ('0' | ' ')) { // let user know that zeros and spaces are not allowed at the beginning of the userId
    alert('When entering your member ID or Web access number, please omit any spaces or zeroes at the beginning of the number. For example, if your number is 00012345, enter it as 12345.');
  }
  else { // otherwise pass the string to the userId field
    userId = unstrippedUserId;
  }
  return userId;
}
