
function Validator(theForm)
{

	if (theForm.loginid.value == "")
	{
		alert("Please enter Registration ID!");
		theForm.loginid.focus();
		return (false);
	}

  if((theForm.loginid.value.indexOf("select")!=-1)|| (theForm.loginid.value.indexOf("insert")!=-1)||(theForm.loginid.value.indexOf("delete")!=-1)||(theForm.loginid.value.indexOf("drop")!=-1)||(theForm.loginid.value.indexOf("XP_")!=-1)||(theForm.loginid.value.indexOf("shutdown")!=-1)||(theForm.loginid.value.indexOf("--")!=-1)||(theForm.loginid.value.indexOf("update")!=-1) )
  {
   alert("Registration ID is not Valid");
   theForm.loginid.focus();
   return false;
  }
  	
       var objToTest = theForm.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 = theForm.loginid.value;
	allValid=checkString(okString,checkStr)
	if (!allValid)
	{
		alert("Invalid LoginID");
		theForm.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");
				theForm.loginid.focus();
				return(false);
			}
  }
  
 if (!allValid)
  {
    alert("Please enter only letter, digit, whitespace and \"-,.\" characters in the \"Title\" field.");
    theForm.loginid.focus();
    return (false);
  }
if (theForm.password.value == "")
{
		alert("Please Enter Password");
		theForm.password.focus();
		return (false);
}

  if((theForm.password.value.indexOf("select")!=-1)|| (theForm.password.value.indexOf("insert")!=-1)||(theForm.password.value.indexOf("delete")!=-1)||(theForm.password.value.indexOf("XP_")!=-1)||(theForm.password.value.indexOf("drop")!=-1)||(theForm.password.value.indexOf("shutdown")!=-1)||(theForm.password.value.indexOf("--")!=-1)||(theForm.password.value.indexOf("update")!=-1)||(theForm.password.value.indexOf("'")!=-1))
  {
   alert("Not a valid password");
   theForm.password.focus();
   return false;
  }

	var objToTest = theForm.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;
}

