function isValidDate(dateStr) {

// Checks for the following valid date formats:

// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY

// Also separates date into month, day, and year variables



var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;



// To require a 4 digit year entry, use this line instead:

// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;



var matchArray = dateStr.match(datePat); // is the format ok?

if (matchArray == null) {

alert("Date is not in a valid format.")

return false;

}

month = matchArray[1]; // parse date into variables

day = matchArray[3];

year = matchArray[4];

if (month < 1 || month > 12) { // check month range

alert("Month must be between 1 and 12.");

return false;

}

if (day < 1 || day > 31) {

alert("Day must be between 1 and 31.");

return false;

}

if ((month==4 || month==6 || month==9 || month==11) && day==31) {

alert("Month "+month+" doesn't have 31 days!")

return false

}

if (month == 2) { // check for february 29th

var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));

if (day>29 || (day==29 && !isleap)) {

alert("February " + year + " doesn't have " + day + " days!");

return false;

   }

}

return true;  // date is valid

}

//  End -->







// TO REMOVE LEADING AND TRAILING SPACES OF A GIVEN STRING

// will return a string after removing trailing and leading spaces from the string.

function trimSpaces(strValue) 

{

	var intNoOfCharctrs = strValue.length;

	var strLspace = "";	

	var strTrimmed="";

	strLspace=strValue;

	while (strLspace.charAt(0)==" ")

	{

		strLspace=strLspace.substring(1,intNoOfCharctrs);

	}

	strTrimmed=trimTrailingSpaces(strLspace);

	return strTrimmed;

}//end of trimSpaces() method



function trimTrailingSpaces(aValue) 

{

	var bValue=reverse(aValue); //pass the value to Reverse method

	var strValue = "";

	var retValue="";

	var intNoOfCharctrs = bValue.length;

	strValue=bValue;

	while (strValue.charAt(0)==" ")//checks whether the charceter is space

	{

		strValue=strValue.substring(1,intNoOfCharctrs);

	}

	strValue=reverse(strValue);

	return strValue;

}//end of trimTrailingSpaces() method



//Internally called in TrimTrailingSpaces, for reversing the String

function reverse(aValue)

{

	var intIndex;

	var strValue="";

	var intNoOfCharctrs = aValue.length;

	for (intIndex = 0; intIndex <=  intNoOfCharctrs; intIndex++)

	strValue = aValue.substring(intIndex, intIndex+1) + strValue;

	return strValue;//reverse the field value and send to again trailing space method

}//end of reverse() method



// METHOD FOR URLENCODING FOR A GIVEN VALUE

// this will return a urlencoded string for space and ampersand

function urlencode(s)

{

	var result = "";

	for(i=0;i<s.length;i++)

	{

		if(s.charAt(i) == " " )

		{

			result += "+";

		}

        else if(s.charAt(i) == "&")

		{

		    result +="%26"

		}

	    else

		{

			result += s.charAt(i);

		}

	}

	return result;

}

// end of urlencode() method



// METHOD FOR CHECKING THE EXISTANCE OF ANY SPECIAL CHARACTERS IN A STRING

// this will return false if any of the special characters are present in the string else returns true.

function checkSplChar(name){

 var splchar=new Array('/','*','%','-','!','@','#','$','%','^','&','+','|','=','{','}','[',']','<','>','\'','\"','\\','\,','.',';',':','~','`','(',')','?');



       for(i=0;i < name.length;i++)

          {

              for(j=0;j < splchar.length;j++)

                {

                    if(name.charAt(i)==splchar[j])

                       {

                           return false;

                        }

                }

          }

		  return true; 

}

// end of checkSplChar() method.



// METHOD FOR CHECKING THE EXISTANCE OF SELECTED SPECIAL CHARACTERS IN A STRING

// this will return false if any of the special characters are present in the string else returns true.

function checkSplChar_Few(name){

 var splchar=new Array('/','*','!','#','$','&','{','}','[',']','<','>','\'','\"',';',':','(',')','?','`');



       for(i=0;i < name.length;i++)

          {

              for(j=0;j < splchar.length;j++)

                {

                    if(name.charAt(i)==splchar[j])

                       {

                           return false;

                        }

                }

          }

		  return true; 

}

// end of checkSplChar_Few() method.



// METHOD FOR CHECKING THE EXISTANCE OF ANY SPECIAL CHARACTERS AND NUMBERS IN A STRING

// this will return false if any of the special characters and numbers are present in the string else returns true.

function checkSplChar_Num(name){

 var splchar=new Array('0','1','2','3','4','5','6','7','8','9','/','*','%','-','!','@','#','$','%','^','&','+','|','=','{','}','[',']','<','>','\'','\"','\\','\,','.',';',':','~','`','(',')','?');



       for(i=0;i < name.length;i++)

          {

              for(j=0;j < splchar.length;j++)

                {

                    if(name.charAt(i)==splchar[j])

                       {

                           return false;

                        }

                }

          }

		  return true; 

}

// end of checkSplChar_Num() method.



// METHOD FOR CHECKING THE BLANK SPACES IN A GIVEN STRING

// this will return false if any blank space exists else returns true.

function checkBlank(name){

	for(i=0;i < name.length;i++)

	{

		if(name.charAt(i) == " " )

		{

			return false;

		}

	}

	return true;

}

// END OF checkBlank() method.	



//VALIDATE EMAIL ADDRESS.......

function isEmail(email) 

{

  if ((email.indexOf('@', 0) == -1) || email.indexOf('.') == -1) 

  {

    return false;

  }

 else { return true; }

}









// to change the color of a row

function setPointer(theRow, thePointerColor)

{

    if (thePointerColor == '' || typeof(theRow.style) == 'undefined') {

        return false;

    }

    if (typeof(document.getElementsByTagName) != 'undefined') {

        var theCells = theRow.getElementsByTagName('td');

    }

    else if (typeof(theRow.cells) != 'undefined') {

        var theCells = theRow.cells;

    }

    else {

        return false;

    }



    var rowCellsCnt  = theCells.length;

    for (var c = 0; c < rowCellsCnt; c++) {

        theCells[c].style.backgroundColor = thePointerColor;

    }



    return true;

} // end of the 'setPointer()' function





// Check the value is in Numeric or not

	function IsNumeric(str)	

	 {

	 	var no=true,i,s1;	

		var Chr = "0123456789._-";

		for (i = 0; i < str.length ; i++)

      	{ 

      		s1= str.charAt(i); 

      		if (Chr.indexOf(s1) == -1) 

         	{

         		no = false;

         	}

      	}

		if(no==false)

		{

			return false;

		}

		else

		{

			return true;

		}

	 }

	 



