
function Validator(theForm)
{

	if (document.login.loginid.value == "")
	{
		alert("Please enter Registration ID!");
		document.login.loginid.focus();
		return (false);
	}

  if((document.login.loginid.value.indexOf("select")!=-1)|| (document.login.loginid.value.indexOf("insert")!=-1)||(document.login.loginid.value.indexOf("delete")!=-1)||(document.login.loginid.value.indexOf("drop")!=-1)||(document.login.loginid.value.indexOf("XP_")!=-1)||(document.login.loginid.value.indexOf("shutdown")!=-1)||(document.login.loginid.value.indexOf("--")!=-1)||(document.login.loginid.value.indexOf("update")!=-1) )
  {
   alert("Registration ID is not Valid");
   document.login.loginid.focus();
   return false;
  }
  	
       var objToTest = document.login.loginid;
	   
	alertMessage = "Registeration ID must have 10 char length";
 	if(objToTest.value.length > 10 || objToTest.value.length < 10)
	{    
	    
	   
		return displayAlertMessage(objToTest,alertMessage);
		
	}
	
	var okString = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_,.";
	var checkStr = document.login.loginid.value;
	allValid=checkString(okString,checkStr)
	if (!allValid)
	{
		alert("Invalid LoginID");
		document.login.loginid.focus();
		return (false);
	}

	allvalid=true;
   for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
       if (checkStr.charAt(i) == "-" )
       	   if (checkStr.charAt(i+1) == "-" )
	   		{ 	alert("Registration ID is not Valid");
				document.login.loginid.focus();
				return(false);
			}
  }
  
 if (!allValid)
  {
    alert("Please enter only letter, digit, whitespace and \"-,.\" characters in the \"Title\" field.");
    document.login.loginid.focus();
    return (false);
  }
if (document.login.password.value == "")
{
		alert("Please Enter Password");
		document.login.password.focus();
		return (false);
}

  if((document.login.password.value.indexOf("select")!=-1)|| (document.login.password.value.indexOf("insert")!=-1)||(document.login.password.value.indexOf("delete")!=-1)||(document.login.password.value.indexOf("XP_")!=-1)||(document.login.password.value.indexOf("drop")!=-1)||(document.login.password.value.indexOf("shutdown")!=-1)||(document.login.password.value.indexOf("--")!=-1)||(document.login.password.value.indexOf("update")!=-1)||(document.login.password.value.indexOf("'")!=-1))
  {
   alert("Not a valid password");
   document.login.password.focus();
   return false;
  }

	var objToTest = document.login.password;
	alertMessage = "Password should have 8 to 10 characters.";
 	if(objToTest.value.length < 8){
		return displayAlertMessage(objToTest,alertMessage);
	}
	return (true);
}  //end of Validator function

function displayAlertMessage(objToTest,alertMessage) {
	
	alert(alertMessage);
	
	objToTest.focus();
	return false;
}

function checkString(okString,checkStr)
{
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < okString.length;  j++)
      if (ch == okString.charAt(j))
        break;
    if (j == okString.length)
    {
      allValid = false;
      break;
    }
  }
  return (allValid);
}
function validateLength(objToTest,value,operator){
   alert(objToTest.value.length);
	var flag = false;
	switch(operator){
		case '<':
				if (objToTest.value.length < value)
					flag = true;
					break;
		case '>':
				if (objToTest.value.length > value)
					flag = true;
					break;
		case '=':
				if (objToTest.value.length = value)
					flag = true;
					break;
	}
	return flag;
}

