function stripCharsNotInBag (s)

{   var i;
    var returnString = "";
	var bag  = "_.-#@0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\" ";
    // Search through string's characters one by one.
    // If character is in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }

    return returnString;
}


function stripCharsNotInBagpass(s)

{   var i;
    var returnString = "";
	var bag  = "_.-#@~!@#$%^&*()_+{}|[]\<>?/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\" ";
    // Search through string's characters one by one.
    // If character is in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }

    return returnString;
}



function stripCharsInBag (s)
{   
	var i;
    var returnString = "";
    var bag  = "'\",' '";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
   
  
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}


function stripCharsInBagspace (s)

{   var i;
    var returnString = "";
    var bag  = " ";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
   
  
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

function validateUserName(userName)
{
	if(!(userName.length >=1 && userName.length <=10))
	{
		alert(s_username_length_not_in_range);
		return false;
	}
	return true;
}

function validateUserPass(passWord)
{
	if(!(passWord.length >=5 && passWord.length <=8))
	{
		alert(s_password_length_not_in_range);
		return false;
	}
	return true;
}

function getFormatedUserId(userName)
{
	//if only for student type
	if (GetuserType(userName)=='s')
	{
		var ch = userName.charAt(0);
		if(isAlphabetic(ch)== true){
			userName = userName.substr(1,userName.length-1);
			var ch = userName.charAt(userName.length-1);
			if(isAlphabetic(ch)== true){
				userName = userName.substr(0,userName.length-1);
				userName = '1' + userName;
			}else{
				userName = '1' + userName;
			}
		}else{
			// this will be in this form 012345678 , add 1 at the begining
			userName = '1' + userName;
		}		
	}
	return userName;
}

function GetuserType(userName)
{
	var usertype='';
	var ch0 = userName.charAt(0);
	var ch1 = userName.charAt(1);
	
	if( (isAlphabetic(ch0) && isNumeric(ch1)) || isNumeric(userName)){
		usertype = 's';
	}else if(userName=='gmatadmin'){
		usertype = 'a';
	}else if(userName=='londonms'){
		usertype = 'p';
	}else{
		usertype = 't';
	}
	return usertype;
	
}

function isAlphabetic(str)
// returns true if str is alphabetic
// that is only A-Z a-z or space
// returns false otherwise
// returns false if empty
{
  var len= str.length;
  if (len==0)
    return false;
  //else
  var p=0;
  var ok= true;
  var ch= "";
  while (ok && p<len)
  {
    ch= str.charAt(p);
    if (('A'<=ch && ch<='Z')||('a'<=ch && ch<='z'))
      p++;
    else
      ok= false;
  }
  return ok;
}

function isNumeric(str)
// returns true if str is numeric
// that is it contains only the digits 0-9
// returns false otherwise
// returns false if empty
{
  var len= str.length;
  if (len==0)
    return false;
  //else
  var p=0;
  var ok= true;
  var ch= "";
  while (ok && p<len)
  {
    ch= str.charAt(p);
    if ('0'<=ch && ch<='9')
      p++;
    else
      ok= false;
  }
  return ok;
}




