﻿function echeck(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var illegalChars="/[\(\)\<\>\,\;\:\\\/\"\[\]]/";
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){return false;}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){return false;}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){return false;}
	if (str.indexOf(at,(lat+1))!=-1){return false;}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){return false;}
	if (str.indexOf(dot,(lat+2))==-1){return false;}

	if (str.indexOf(" ")!=-1){return false;}
	return true;					
}

function checkdate(thedate) 
{
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{2,4})$/;
	var matchStartArray = thedate.match(datePat); 
	if(thedate != "")
	{
		if (matchStartArray == null) 	{
			//alert("Please enter date as either dd/mm/yyyy or dd-mm-yyyy.");
			return false;
		}	
		var sday = matchStartArray[1]; 
		var smonth = matchStartArray[3];
		var syear = matchStartArray[5];
	
		if (smonth < 1 || smonth > 12) 	{ // check month range
			//alert("Month must be between 1 and 12.");
			return false;
		}
	
		if (sday < 1 || sday > 31) { // check day range
			//alert("Day must be between 1 and 31.");
			return false;
		}
	
		if ((smonth==4 || smonth==6 || smonth==9 || smonth==11) && sday==31) { // check days in month range
			//alert("Month "+smonth+" doesn't have 31 days!")
			return false;
		}
	
		if (smonth == 2) { // check for february 29th
			var isleap = (syear % 4 == 0 && (syear % 100 != 0 || syear % 400 == 0));
			if (sday > 29 || (sday==29 && !isleap)) {
				//alert("February " + syear + " doesn't have " + sday + " days!");
				return false;
			}
		}
	return true;
	}
}