// JavaScript Document
function checkDate(day, month, year)
{
	if(day.substring(0, 1)==0)
		day=day.substring(1, day.length);
	if(month.substring(0, 1)==0)
		month=month.substring(1, month.length);
	// since jan equals one and not zero, hence thirteen elements in the array.
	var no_of_days_in_month = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31)
	if (month >= 1 && month <= 12 && day >=  1 && day <= 31 && year >= 0)
	{
		//Handling february, special case.
		if (month == 2)
		{
			if ( (year%4==0 && year%100 != 0) || year%400 == 0 )
					no_of_days_in_month[month]=29
		}

		if (day >= 1 && day <= no_of_days_in_month[month])
		{
			return true;
		}
		else
		{
			return false;
		}

	}
	else
	{
			return false;
	}
}

function isInteger(iNumber){
	var i;

	for (i=0;i<iNumber.length;i++)
	{
		var c = iNumber.charAt(i);

		if (!isDigit(c))
		{
			return false;
		}
	}

	return true;
}

function isDigit(c)
{
         return ((c >= "0") && (c <= "9"))
}

function trim(inputString) {
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") {
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") {
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) {
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
   }
   return retValue;
}

function isValidName(name){
	return name.search(/[^a-zA-Z\.\s\']/) == -1 ;
}

function isValidEmail(email){
	return email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1;
}
function isValidPhone(phone){
	return isInteger(phone);
}
