function Isddmmyyyy59
(theElement, theElementName) {
  var objRegExp = /^\d{1,2}(\-)\d{1,2}\1\d{4}$/

strValue = theElement.value

  if (strValue.length == 0 ) return true;

  //check to see if in correct format
  if(!objRegExp.test(strValue)){

	alert("Please enter a valid date in DD-MM-YYYY Format"); 
       theElement.focus(); 
       theElement.select();

    return false;} //doesn't match pattern, bad date
  else{
    var arrayDate = strValue.split(RegExp.$1); //split date into month, day, year
	var intDay = parseInt(arrayDate[0],10); 
	var intYear = parseInt(arrayDate[2],10);
	var intMonth = parseInt(arrayDate[1],10);
	
	//check for valid month
	if(intMonth > 12 || intMonth < 1) {
	alert("Please enter a valid date in DD-MM-YYYY Format"); 
       theElement.focus(); 
       theElement.select();
		return false;
	}
	
    //create a lookup for months not equal to Feb.
    var arrayLookup = { '1' : 31,'3' : 31, '4' : 30,'5' : 31,'6' : 30,'7' : 31,
                        '8' : 31,'9' : 30,'10' : 31,'11' : 30,'12' : 31}

    //check if month value and day value agree
    if(arrayLookup[intMonth] != null) {
      if(intDay <= arrayLookup[intMonth] && intDay != 0){return true;}
	else{	alert("Please enter a valid date in DD-MM-YYYY Format"); 
       	theElement.focus(); 
       	theElement.select();
		return false;} 

         //found in lookup table, good date
    }
	
    //check for February

if (intMonth == 2){
	var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
    if( ((booLeapYear && intDay <= 29) || (!booLeapYear && intDay <=28)) && intDay !=0)
      return true; //Feb. had valid number of days

	alert("Please enter a valid date in DD-MM-YYYY Format"); 
       theElement.focus(); 
       theElement.select();}  
return false; //any other values, bad date
}}
