
function ltrim (s) // Krish
{
	for (i=0; i<s.length; i++)
		if ( s.charAt(i) != ' '  && s.charAt(i) != '\n'	&&
		     s.charAt(i) != '\t' && s.charAt(i) != '\b' &&
		     s.charAt(i) != '\r' && s.charAt(i) != '\f' )
			break;
	s = s.substring (i);
	return (s);
}

function validateTextField (theField, fieldLabel, shouldTrim, emptyCheck, minLength, maxLength, checkOK, OKString)
{
	fieldNameString = ' "' + fieldLabel + '" ';
	if (shouldTrim)
		theField.value = ltrim (theField.value);

	if (emptyCheck && theField.value == "")
	{
	alert("Please enter a value for the" + fieldNameString + "field.");
	theField.focus();
	return (false);
	}

	if (emptyCheck && minLength > 0 && theField.value.length < minLength)
	{
		alert("Please enter at least " + minLength + " characters in the" + fieldNameString + "field.");
		theField.focus();
		return (false);
	}

	if (maxLength > 0 && theField.value.length > maxLength)
	{
		alert("Please enter at most " + maxLength + " characters in the " + fieldNameString + "field.");
		theField.focus();
		return (false);
	}

	checkOK = ltrim(checkOK);
	if (checkOK != "")
	{
		var checkStr = theField.value;
		var allValid = true;
		for (i = 0;  i < checkStr.length;  i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;  j < checkOK.length;  j++)
				if (ch == checkOK.charAt(j))
					break;
			if (j == checkOK.length)
			{
				 allValid = false;
				 break;
			}
		}

		if (!allValid)
		{
	alert("Please enter only " + OKString + " in the" + fieldNameString + "field.");
			theField.focus();
			return (false);
		}
	}

	return true;
}

// called onSubmit of form
function validatemmc (theForm)
{
  var dateToday = new Date();
  var dateGiven = new Date();
  var str;


 if ( ! validateTextField (theForm.uname, "User Name", true, true, 5, 15, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-", "Characters, Digits"))
		return false;

  if ( ! validateTextField (theForm.pword, "Password", true, true, 5, 15, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-", "Characters, Digits"))
		return false;

  return (true);
}

function validatemmc2 (theForm)
{
  var dateToday = new Date();
  var dateGiven = new Date();
  var str;


 //if ( ! validateTextField (theForm.uname, "User Name", true, true, 15, 15, "0123456789", "Digits"))
	//	return false;

 // if ( ! validateTextField (theForm.pword, "Password", true, true, 15, 15, "0123456789", "Digits"))
	//	return false;

  return (true);
}


function mmcValidreg (theForm)
{
  var dateToday = new Date();
  var dateGiven = new Date();
  var str;


 if ( ! validateTextField (theForm.name, "Name", true, true, 5, 50, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_- .", "Characters, Digits"))
		return false;

  if ( ! validateTextField (theForm.address, "Address", true, true, 5, 200, "", "Characters, Digits"))
		return false;

 if ( ! validateTextField (theForm.emailid, "EMail", true, true, 5, 100,
 "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-@.", "digits,alphabets,hyphen,@ and underscore"))
 return false;

    if (! isEmail (theForm.emailid.value))
    {
        alert("Please enter a valid EMail address in the \"E-Mail\" field.");
        theForm.emailid.focus();
        return (false);
   }

   if((theForm.username.value=="")||(theForm.username.value =="0")){
	alert("Please Enter Username") ;
	theForm.username.value="";
	theForm.username.focus();
	return false;
   }
   if((theForm.password.value=="")||(theForm.password.value =="0")){
	alert("Please Enter password") ;
	theForm.password.value="";
	theForm.password.focus();
	return false;
   }
   if(theForm.username.value==theForm.password.value){
	alert("Both User name and Password are same.Please Try again") ;
	theForm.password.value="";
	theForm.password.focus();
	return false;
   }


 //if ( ! validateTextField (theForm.username, "User Name", true, true, 15, 15, "0123456789", "Digits"))
	//	return false;

 // if ( ! validateTextField (theForm.password, "Password", true, true, 15, 15, "0123456789", "Digits"))
	//	return false;

  return (true);
}



function mmcValidation()
{
	var i;

	if ( ! validatemmc(document.forms[0]) )
	  return false ;
	return document.forms[0].action; 
}

function mmcValidation2()
{
	var i;

	if ( ! validatemmc2(document.forms[0]) )
	  return false ;
	return document.forms[0].action; 
}
