
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){
	// Check that current character is number.
	var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}


function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   }
   return this
}


function is_dd_mon_yyyy(dtStr,label,fieldname){

var dtCh= "-";
var minYear=1900;
var maxYear=2100;


	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var month=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	//if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
        //month=parseInt(strMonth)
	//alert(month);

	var intMonth = 0;
	if(month != null)
		month=month.toUpperCase();
	 switch (month) {
	case "JAN":
	intMonth = 1;
	break;
case "FEB":
intMonth = 2;
break;
case "MAR":
intMonth = 3;
break;
case "APR":
intMonth = 4;
break;
case "MAY":
intMonth = 5;
break;
case "JUN":
intMonth = 6;
break;
case "JUL":
intMonth = 7;
break;
case "AUG":
intMonth = 8;
break;
case "SEP":
intMonth = 9;
break;
case "OCT":
intMonth = 10;
break;
case "NOV":
intMonth = 11;
break;
case "DEC":
intMonth = 12;
break;
      	}
        day=parseInt(strDay)
	year=parseInt(strYr)
	var full_year ="200"+ strYr;
	var current_date = new Date();
//	alert(full_year)
//	alert(intMonth-1);
//	alert(day);


	var selected_date = new Date(full_year, intMonth-1, day);

	var current_date = new Date();

	if (pos1==-1 || pos2==-1){
	//	add_err(label+":"+"The date format should be : dd-mon-yyyy")
		add_err(label+ localize("DATE_FORMAT_MON"),fieldname)
	}

	if (month != "JAN" && month != "FEB" && month != "MAR" && month != "APR" && month != "MAY" && month != "JUN" &&
month != "JUL" && month != "AUG" && month != "SEP" && month != "OCT" && month != "NOV" && month != "DEC") {
		add_err(label+":"+localize("VALID_MONTH"),fieldname);
	}
        if (day <= 0 || day > 31){
		add_err(label+":"+localize("ENTER_DAY"),fieldname);
	}
        if ((month=="Feb" && day>daysInFebruary(year)) || day > daysInMonth[intMonth]){
		add_err(label+":"+localize("THERE_ARE_NOT")+""+ day+localize("DAYS_IN_THIS_MONTH"),fieldname );
	}
	if (strYear.length != 4 || isInteger(strYear) == false){
		add_err(label+":"+localize("ENTER_4_DIGIT_YEAR"),fieldname);
	}
        if (isInteger(strDay) == false){
		add_err(label+":"+localize("ENTER_2_DIGIT_DATE"),fieldname);
	}
}

