
function isValidDate(dateArg){
	var return_str = "";

	var intArg = parseInt(dateArg.replace(/\//g,''),10);
	var slash1 = dateArg.indexOf('/');
	var slash2 = dateArg.indexOf('/',slash1+1);
	
	var strMM   = dateArg.substring(0,slash1);
	var strDD   = dateArg.substring(slash1+1,slash2);
	var strYYYY = dateArg.substring(slash2+1);

	var intMonth = parseInt(strMM,10);
	var intDay   = parseInt(strDD,10);
	var intYear  = parseInt(strYYYY,10);
	
	if (slash1 > -1 && slash2 > -1){
		if (strMM.length<1 || intMonth<1 || intMonth>12){
			return_str = "Please enter a valid month";
		}
		if (strDD.length<1 || intDay<1 || intDay>31 || intDay>Date.getDaysInMonth(intYear,intMonth-1)){
			return_str = "Please enter a valid day";
		}
		if (strYYYY.length != 4 || intYear==0 || intYear<1970 || intYear>2100){
			return_str = "Please enter a valid 4 digit year between " + 1970 + " and " + 2100;
		}
		if (dateArg.indexOf('/',slash2+1) != -1 || (intArg>0 && intArg<100000000) == false){
			return_str = "Please enter a valid date";
		}
	}
	else {
		return_str = "The date format should be : mm/dd/yyyy";
	}

	return return_str;
}

Date.isLeapYear=function(year){
	return(((year%4===0)&&(year%100!==0))||(year%400===0));
};
Date.getDaysInMonth=function(year,month){
	return[31,(Date.isLeapYear(year)?29:28),31,30,31,30,31,31,30,31,30,31][month];
};
Date.prototype.getDaysInMonth=function(){
	return Date.getDaysInMonth(this.getFullYear(),this.getMonth());
};
Date.prototype.addMonths=function(value){
	this.setDate(this.getDate());
	this.setMonth(this.getMonth() + value);
	this.setDate(Math.min(this.getDate(),this.getDaysInMonth()));
	return this;
};		
		
