var errorMsg = "";

//Clear Error Message
function clearMsg()
{
	errorMsg = "";
	hideMsg();
}

//Print Error Message in page
function printMsg(msg)
{
	var eMsg = document.getElementById('test');
        var sMsg = document.getElementById('error');        
        sMsg.innerHTML = "";
	eMsg.style.display = "";
	eMsg.innerHTML = "<p><font color=red>"+msg+"</font></p>";
	return;
}


function validateText(strValue, strField)
{
    if (strValue=="")
    {
        errorMsg = "Invalid UserID/Password";
        return false;
    }   

    for (var i=0; i<strValue.length; i++)
    {
        var valid = false;
        var str = strValue.substring(i,i+1);
        if (str >= "a" &&  str <= "z")
            valid = true;

        if (str >= "A" &&  str <= "Z")
            valid = true;

        if (str >= "0" &&  str <= "9")
            valid = true;
            
        if (!valid)
        {
            errorMsg = "Invalid UserID/Password";
            return false;
        }
    }
    return true;
}

//Clear Error Message in page
function hideMsg(){
	var eMsg = document.getElementById('test');
	eMsg.style.display = "none";
	eMsg.innerHTML = '';
	return;
}

//check if the error message need to be returned or not
function noError(){
	if ((errorMsg == "")||(errorMsg.length==0))
		return true;
	else{
		printMsg(errorMsg);
		return false;
	}
}

function validateForm(form)
{
    //clear the Error Message
    clearMsg();

    validateText(form.userid.value);
    validateText(form.password.value);

    //Email alert
    var ret = noError();
    return ret;
}