/*-----------------------------------------------------------------------
Created by: KD
Created date: 25-sep-06
File description: Admin Form in Administration
Special instructions-notes:Java script Validation
Tables used:None
Stored procedures:None
Triggers used:None
-----------------------------------------------------------------------*/

function ValidateLogin(theForm)
{
	var errMesg = "";
	var displayMesg = "Please provide valid value for\n";
	
	var loginName = theForm.username.value = theForm.username.value.toLowerCase();
		
 	var Q = ""; // this block determines lifespan of Q
	
	if(theForm.username.value == "Username"){
		alert("Please provide valid username");
		return false;
	}
	if(theForm.password.value == "Password"){
		alert("Please provide valid password");
		return false;
	}
	
	if(theForm.username.value == ""){
		errMesg +="Login Id\n";
	}
	
/*	if(theForm.password.value != ""){
		if(!isCharsInBag(theForm.username.value, "abcdefghijklmnopqrstuvwxyz0123456789.-_")){
			errMesg += "Login Id has invalid characters\n";
		}
	}
*/	
	if(theForm.username.value != ""){	
		if(loginName.length < 3){
			errMesg += "Login Id must be 3 or more characters.\n" ;
		}else{
			var count;
			for (count=0; count < loginName.length; count++){
				if (loginName.charAt(count) == "_"){
					if (loginName.charAt(count+1) == "_"){
						errMesg += "Login Id may not contain more than one consecutive underscore.\n";
					}
				}
			}
		}
	}

	if(theForm.password.value == ""){
		errMesg +="Password\n";
	}

	if(theForm.password.value != ""){
		if(theForm.password.value.length < 5){
			errMesg += "Password must be at least 5 characters.\n";
		}
	}	

	if (errMesg == ""){
		return true;
	}else{
		displayMe = displayMesg+errMesg;
		alert(displayMe);
		return false;					
	}
}
