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
}


//function to check the validity of expirty month not less than
//current month when the expiry year is the same of current year.
//it receives three values - expiry year (as number in four digits eg. 1999)
//expiry month as (first three letters of month) and the field name.
//by C.MANI MARAN
function CardExpiry (year, month, theField)
 {
          var curdate = new Date();
          var curmm = curdate.getMonth();
          var curyy = curdate.getYear();
          if (curyy <= 99) {
             curyy = curyy + 1900;
          }
          if (month == "Jan")
             { var curmonth = 0 }
          if (month == "Feb")
             { var curmonth = 1 }
          if (month == "Mar")
             { var curmonth = 2 }
          if (month == "Apr")
             { var curmonth = 3 }
          if (month == "May")
             { var curmonth = 4 }
          if (month == "Jun")
             { var curmonth = 5 }
          if (month == "Jul" )
             { var curmonth = 6 }
          if (month == "Aug")
             { var curmonth = 7 }
          if (month == "Sep")
             { var curmonth = 8 }
          if (month == "Oct")
             { var curmonth = 9 }
          if (month == "Nov")
             { var curmonth = 10 }
          if (month == "Dec")
             { var curmonth = 11 }
         if ((curyy == year) && (curmonth < curmm)) {
            alert ("Invalid Credit Card Expiry Date");
            theField.focus();
           return false;
         }
return true;
 }


function futureDate(year1, theField)
 {
   var curdate = new Date();
   var curyear = curdate.getYear();
   if (curyear <= 99) {
      curyear = ((curyear + 1900) - 10)
   }
   if (year1 > curyear) {
      alert ("Date of Birth should be atleast 10 years less than current year");
      theField.focus();
      return false;
   }

  return true;
}



// called onClick of form
function validregsiter(theForm)
{
  var dateToday = new Date();
  var dateGiven = new Date();
  var str;
if (theForm.regno.value == "")
{
	alert("Enter regno");
	theForm.regno.focus();
return false;
		}
if (theForm.name.value == "")
{
alert("Enter your name");
	theForm.name.focus();
return false;


}
if ( ! validateTextField (theForm.regno, "Examination Register Number", true,
			true, 12, 12,
			"0123456789BDbdMDmd", "digits"))
		return false;
  /*
if ( ! validateTextField (theForm.name, "Name", true,
			true, 4, 50,
			"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_. ", "letters"))
		return false;



  if ( ! validateTextField (theForm.mobileno, "Mobile Number", true,
			false, 10, 12,
			"0123456789", "digits"))
		return false;

  
  if (theForm.mobileno.value != "")
	{
		if ( ! validateTextField (theForm.mobileno, "Mobile Number", true,true, 10, 12, "0123456789", "digits")) return false;
		if (theForm.city.value == "")
		{
			alert("Enter City Name");
			theForm.city.focus();
			return false;
		}
	}*/

  return (true);
}
