function val_date(dd,curr_date_flag,dft_value,set_focus) {
// pass in dft_value to default field to when . entered, if not passed current date is used
 	if (dd.className == 'error') {
		dd.className = '';
	}
 	if (dd.className == 'errorrequiredfield') {
		dd.className = 'requiredfield';
	}

  if (isblank(dd.value))
    return true;

  if (set_focus && set_focus != null)
  	var w_set_focus = set_focus;
  else
    var w_set_focus = 'Y';

   now = new Date() ;
   var d = dd.value;
   d = d.replace(/ /g,'');
   d = d.replace(/\//g,'-');
   var w_year = now.getYear();
   var w_dow = now.getDay();
   w_year = w_year.toString();
   if (w_year.length == 4)	
	  w_year = w_year.substring(2,4);

   var w_pivot = 50;
		
	if (d.substr(0,1) == ".") {
		if (dft_value && dft_value != null) {
		  d = dft_value.substr(4,2) + '-' + dft_value.substr(6,2) + '-' + dft_value.substr(2,2);
		}
		else {
		 var w_days_away = d.substr(1,d.length-1)
		 var w_day = now.getDate();
		 w_day = w_day + w_days_away;
	 	 if ((w_day * 1) <10)
	   		w_day = '0' + w_day;
	 	 var w_mon = now.getMonth() + 1;
	 	 if ((w_mon * 1) <10)
	   		w_mon = '0' + w_mon;
    	 d = w_mon + '-' +  w_day + '-'  + w_year;
	   	}	
	}
	else if (d.toUpperCase() == "M"
		|| d.toUpperCase() == "T" 
		|| d.toUpperCase() == "W" 
		|| d.toUpperCase() == "TH" 
		|| d.toUpperCase() == "F" 
		|| d.toUpperCase() == "S" 
		|| d.toUpperCase() == "SU" 
		)
		{
		   var w_day;
		   if (d.toUpperCase() == "M")
		   	  w_day = 1;
		   else if (d.toUpperCase() == "T")
		   	  w_day = 2;
		   else if (d.toUpperCase() == "W")
		   	  w_day = 3;
		   else if (d.toUpperCase() == "TH")
		   	  w_day = 4;
		   else if (d.toUpperCase() == "F")
		   	  w_day = 5;
		   else if (d.toUpperCase() == "S")
		   	  w_day = 6;
		   else if (d.toUpperCase() == "SU")
		   	  w_day = 0;
			  
		   	w_add_days = w_day - w_dow;
			if (w_add_days <= 0)
				w_add_days = w_add_days + (7 - 0);
			 var w_day = now.getDate();
			 w_day = w_day + (w_add_days - 0);
	 		 if ((w_day * 1) <10)
	   			w_day = '0' + w_day;
	 		 var w_mon = now.getMonth();
	 		 if ((w_mon * 1) <10)
	   			w_mon = '0' + w_mon;
			 var w_day_date = new Date('20'+w_year,w_mon,w_day);
   	         var w_year = w_day_date.getYear();
		     w_year = w_year.toString();
			 if (w_year.length == 4)
			 	w_year = w_year.substring(2,4);
			 var w_day = w_day_date.getDate();
	 	 	if ((w_day * 1) <10)
	   			w_day = '0' + w_day;
	 	 	var w_mon = w_day_date.getMonth() + 1;
		 	 if ((w_mon * 1) <10)
		   		w_mon = '0' + w_mon;
    		 d = w_mon + '-' +  w_day + '-'  + w_year;
	}
	else if (d.length == 1 || d.length == 2){
		var w_current_day = now.getDate();
		if (wayne_checkinteger(d)) {
		 	w_yr = w_year;
			if(d - 0 < w_current_day - 0){
			 	 var w_mon = now.getMonth() + 2;
				 if(w_mon - 0 > 12){
				 	w_mon = '01';
				 	w_yr = w_year + 1 - 0;
				 }
			}
			else{
			 	 var w_mon = now.getMonth() + 1;
			}	
		}
		else{
			alert('invalid date');
			if(w_set_focus == 'Y')
				dd.focus();
			return;
		}
		// check if single digit day of month enterd
	 	 if ((w_mon * 1) <10)
	   		w_mon = '0' + w_mon;
	 	 if ((d * 1) <10 && d.length == 1)
	   		d = '0' + d;
    	 d = w_mon + '-' + d + '-'  + w_yr;
	}

    if (d.length == 0)
        return true;
	
	if (d.length == 4 && d.indexOf('-') == -1) {
		d = d + w_year;
	}
	if (d.length < 5) {
		alert('invalid date');
		if(w_set_focus == 'Y')
			dd.focus();
		return;
	}
	if (d.length == 5 && d.indexOf('-') == -1) {
	  d = '0' + d;
	}

	if (d.length <= 5 && d.indexOf('-') != -1 && d.indexOf('-') == d.lastIndexOf('-')) {
		d = d + '-' + w_year;
	}

	if (d.length == 6 && d.indexOf('-') == -1 && d.indexOf('/') == -1) {
		l_month = d.substr(0,2);
		l_day = d.substr(2,2);
		l_year = d.substr(4,2);
	}
	else {
		isplit = d.indexOf('-');
		if (isplit == -1 || isplit == d.length) {
			isplit = d.indexOf('/');
	    	if (isplit == -1 || isplit == d.length) {
				alert('invalid date');
				if(w_set_focus == 'Y')
					dd.focus();
				return;
			}
			else {
				l_delim = '/';
			}
	    }
		else {
			l_delim = '-';}
	
	    l_month = d.substring(0, isplit);
		isplit = d.indexOf(l_delim, isplit + 1);
	
		if (isplit == -1 || (isplit + 1 ) == d.length) {
			alert('invalid date');
			if(w_set_focus == 'Y')
				dd.focus();
			return;
		}
	
	    l_day = d.substring((l_month.length + 1), isplit);
		l_year = d.substring(isplit + 1);
	}
	if (l_month.length == 1)
	  l_month = '0' + l_month;
	if (l_day.length == 1)
	  l_day = '0' + l_day;
	if (l_year.length == 1)
	  l_year = '0' + l_year;
	if (l_year.length == 4)
		l_year = l_year.substr(2,2);
	
	if (!wayne_checkinteger(l_month)) {//check month
		alert('invalid month');
		if(w_set_focus == 'Y')
			dd.focus();
		return;
	}
	else
	if (!wayne_checkrange(l_month, 1, 12)) { //check month
		alert('invalid month');
		if(w_set_focus == 'Y')
			dd.focus();
		return;}
	else
	if (!wayne_checkinteger(l_year)) { //check year
		alert('invalid year');
		if(w_set_focus == 'Y')
			dd.focus();
		return;}
	else
	if (!wayne_checkrange(l_year, 0, 99)) { //check year
		alert('invalid year');
		if(w_set_focus == 'Y')
			dd.focus();
		return;}
	else
	if (!wayne_checkinteger(l_day)) { //check day
		alert('invalid day');
		if(w_set_focus == 'Y')
			dd.focus();
		return;}
	else
	if (!wayne_checkday(l_year, l_month, l_day)) { // check day
		alert('invalid day');
		if(w_set_focus == 'Y')
			dd.focus();
		return;}
	else
	    d = l_month + '-' + l_day + '-' + l_year;

	if (curr_date_flag) {
	  if (curr_date_flag == 'Y') {
		if ((l_year * 1) < (w_pivot * 1))
		  w_century = '20';
		else
		  w_century = '19';
		  
	    entered_date = new Date(w_century + l_year,l_month - 1,l_day,23,59,59,999);
        if (entered_date < now) {
		  alert('Date cannot be less than todays date - ' + now.toLocaleString());
		  if(w_set_focus == 'Y')
  			dd.focus();
		  return;
		}
	  }	  
   	
	}
	
	dd.value =  l_month + '-' + l_day + '-' + l_year;
	return true;
}

