/*   Error Messages    */
var invalidUserName = "Please enter a valid Username.",
	invalidPassword = "Please enter a valid Password.",
	emptyUserName   = "Please enter a Username.",
	emptyPassword   = "Please enter a Password.";

function setFocus(fieldName)
{
	document.getElementById(fieldName).select();
	document.getElementById(fieldName).focus();
}

function checkForRegExp(fieldValue)
{
	var myRegExp = /[^a-z0-9]/i;
	
	if(myRegExp.test(fieldValue))
	{
		return false;
	}
	return true;
}

function validateInput()
{
	document.getElementById("btnSignIn").disabled = true;

	document.frmLogin.login.value = document.frmLogin.login.value.trim();
	document.frmLogin.password.value = document.frmLogin.password.value.trim();
	
	var login = document.frmLogin.login;
	var password = document.frmLogin.password;

	if (login.value == "")
	{
		alert(emptyUserName);
		setFocus("txtLogin");
		document.getElementById("btnSignIn").disabled = false;
		return false;
	} 

	with(login)
	{
		if(!checkForRegExp(value))
		{
			alert(invalidUserName);
			setFocus("txtLogin");
			document.getElementById("btnSignIn").disabled = false;
			return false;
		}
	}

	<!-- Validation for password -->
	if(password.value == "")
	{
		alert(emptyPassword);
		setFocus("txtPassword");
		document.getElementById("btnSignIn").disabled = false;
		return false;
	}

	with(password)
	{
		if(!checkForRegExp(value))
		{
			alert(invalidPassword);
			setFocus("txtPassword");
			document.getElementById("btnSignIn").disabled = false;
			return false;
		}
	}
	document.frmLogin.submit();
}

// A trim function for 
String.prototype.trim = function ()
{
	// skip leading and trailing whitespace
	// and return everything in between
	var x=this;
//		x=x.replace(/^\s*(.*)/, "$1");
//		x=x.replace(/(.*?)\s*$/, "$1");
//		return x;

	var SPACE = 32;
	var trimedString = "";	
	var exactVal = this;
	var start = 0;
	var end = 0;

	// index of first character other than space
	for (i=0; i<exactVal.length; i++)
	if(!(exactVal.charCodeAt(i) == SPACE))
	{
		start = i;
		break;
	}

	// index of last character other than space
	for (i=exactVal.length-1; i>0; i--)
		if (!(exactVal.charCodeAt(i) == SPACE))
		{
			end = i;
			break;
		}

	// Extract The string free from starting spaces and ending spaces but not space in between.
	for (i=start; i<=end; i++)
		trimedString = trimedString+ exactVal.charAt(i);

	// now exact value becomes the trimed string
	exactVal  = trimedString;
	return exactVal;
}