var reEmail=/^[0-9a-zA-Z_\.-]+\@[0-9a-zA-Z_\.-]+\.[0-9a-zA-Z_\.-]+$/
function checkEmail(obj){
 	if(!reEmail.test(obj.value))
	{
		alert("Please enter a valid email address.");
		obj.focus();
		return false;
	}
	return true;
}


function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
//		   alert("Invalid E-mail ID")
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
//		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
//		    alert("Invalid E-mail ID")
		    return false
		}
		 if (str.indexOf(at,(lat+1))!=-1){
//		    alert("Invalid E-mail ID")
		    return false
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
//		    alert("Invalid E-mail ID")
		    return false
		 }
		 if (str.indexOf(dot,(lat+2))==-1){
//		    alert("Invalid E-mail ID")
		    return false
		 }
		 if (str.indexOf(" ")!=-1){
//		    alert("Invalid E-mail ID")
		    return false
		 }
 		 return true					
	}


function leftrim(x) {
	var str = x.value;
	while(str.charAt(0) == ' ' || str.charAt(0) == '?' || str.charAt(0) == '+' || str.charAt(0) == '-' || str.charAt(0) == ',') {
		str = str.substr(1,str.length-1)
	}
	return str;
}

function selchoice(obj,selvalue) {
	for(i=0;i<=obj.options.length-1;i++) {
		if(obj.options[i].value == selvalue) {
			obj.options[i].selected = true;
			break;
		}
	}
	return true;
}

function isFloat(aStr)
{
	var i_val="0123456789";
	var index;
	for(index=0;index < aStr.length; index++)
	{
		if(i_val.indexOf(aStr.charAt(index))<0)
			return false;
	}
	return true;	
}	


function checkDate1(dd,mm,yy) {
 var myDayStr = document.CheckDate.formDate.value;
var myMonthStr = document.CheckDate.formMonth.value;
var myYearStr = document.CheckDate.formYear.value;
var myDateStr = myDayStr + ' ' + myMonthStr + ' ' + myYearStr;

/* Using form values, create a new date object
which looks like "Wed Jan 1 00:00:00 EST 1975". */
var myDate = new Date( myDateStr );

// Convert the date to a string so we can parse it.
var myDate_string = myDate.toGMTString();

/* Split the string at every space and put the values into an array so,
using the previous example, the first element in the array is "Wed", the
second element is "Jan", the third element is "1", etc. */
var myDate_array = myDate_string.split( ' ' );

/* If we entered "Feb 31, 1975" in the form, the "new Date()" function
converts the value to "Mar 3, 1975". Therefore, we compare the month
in the array with the month we entered into the form. If they match,
then the date is valid, otherwise, the date is NOT valid. */
if ( myDate_array[2] != myMonthStr ) {
  alert( 'I\'m sorry, but "' + myDateStr + '" is NOT a valid date.' );
} else {
  alert( 'Congratulations! "' + myDateStr + '" IS a valid date.' );
}
 
}







 



var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

function checkDate(dd,mm,yy)
{
	var day = parseInt(dd);
	var month = parseInt(mm);
	var year = parseInt(yy);

	if (!day || !month || !year)
		return false;

	if (year/4 == parseInt(year/4))
		monthLength[1] = 29;

	if (day > monthLength[month-1])
		return false;

	monthLength[1] = 28;

	var now = new Date();
	now = now.getTime(); //NN3

	var sdd = parseInt(dd);
	var smm = parseInt(mm);
	var syy = parseInt(yy);

	var sdateToCheck = new Date();
	sdateToCheck.setYear(syy);
	sdateToCheck.setMonth(smm-1);
	sdateToCheck.setDate(sdd);
	var scheckDate = sdateToCheck.getTime();
	var futureDate = (now <= scheckDate);
	if (futureDate==false) 
	{
		return false;
	}
	return true;
}


function start_end_date(sdd,smm,syy,edd,emm,eyy) {
	var now = new Date();
	now = now.getTime(); //NN3
	var sdd = parseInt(sdd);
	var smm = parseInt(smm);
	var syy = parseInt(syy);
	var edd = parseInt(edd);
	var emm = parseInt(emm);
	var eyy = parseInt(eyy);

	var sdateToCheck = new Date();
	sdateToCheck.setYear(syy);
	sdateToCheck.setMonth(smm-1);
	sdateToCheck.setDate(sdd);
	var scheckDate = sdateToCheck.getTime();

//	var edateToCheck = new Date();
//	edateToCheck.setYear(eyy);
//	edateToCheck.setMonth(emm-1);
//	edateToCheck.setDate(edd);
//	var echeckDate = sdateToCheck.getTime();

//    var futureDate = (sdateToCheck > edateToCheck);
//	var pastDate = (now > scheckDate);
	var futureDate = (now <= scheckDate);
	
//	alert(sdateToCheck);
//    alert(edateToCheck);
	alert("Future:"+futureDate);
//	alert("Past:"+pastDate);
    alert("Date is Correct");
	return futureDate;
}