//********************* Remove spaces at the beginning & at the end *********************
function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 

//********************* Input must in 'A' - 'Z' or 1 - 9 *********************
function checkChar(theString)
{
	len=theString.length;
	chars="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	for(i=0; i<len; i++)
	{
		if (chars.indexOf(theString.charAt(i))<0)
   		{
   			return false;
		}
	}
return true;
}

var whitespace = " \t\n\r";

function isEmpty(s) {   
	return ((s == null) || (s.length == 0))
}

function isWhitespace (s) {   
	var i;

    if (isEmpty(s)) 
		return true;
    for (i = 0; i < s.length; i++) {   
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) 
			return false;
    }
    return true;
}

function charInString (c, s) {   
	for (i = 0; i < s.length; i++) {   
		if (s.charAt(i) == c) 
			return true;
    }
    return false
}

function stripInitialWhitespace (s) {   
	var i = 0;

    while ((i < s.length) && charInString (s.charAt(i), whitespace))
       i++;
    
    return s.substring (i, s.length);
}

function isEmail (s) {   
	if (isEmpty(s)) {
		return false;
	}

    if (isWhitespace(s)) {
		return false;
	}
    
    var i = 1;
    var sLength = s.length;

    while ((i < sLength) && (s.charAt(i) != "@")) { 
		i++;
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) {
		return false;
    } else 
		i += 2;

    while ((i < sLength) && (s.charAt(i) != ".")) { 
		i++;
    }

    if ((i >= sLength - 1) || (s.charAt(i) != ".")) {
		return false;
    } else 
		return true;
}

function checklogin(theString)
{
	len=theString.length;
	chars="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_";
	for(i=0; i<len; i++)
	{
		if (chars.indexOf(theString.charAt(i))<0)
   		{
   			return false;
		}
	}
return true;
}