function date_valid_new(myField,myd,mym,myy,dmsg,maxy,miny,maxm,minm,maxd,mind)
{
   today = new Date();
 thisDay = parseInt(today.getDate());
 year_now =parseInt(today.getYear());
  if(navigator.appName=="Netscape"){year_now+=1900};
 month_now=parseInt(today.getMonth())+1;

  if((maxy=="")||(isNaN(maxy))){ maxy=year_now }
  else{ maxy=parseInt(maxy) }   

  if((miny=="")||(isNaN(miny))){ miny="1900";   miny=parseInt(miny) }
  else{ miny=parseInt(miny) }

  if((maxm=="")||(isNaN(maxm))){   maxm=month_now; }
  else{maxm=parseInt(maxm);}  

  if((minm=="")||(isNaN(minm))){   minm="01";   minm=parseInt(minm); }
  else{minm=parseInt(minm);}

  if((maxd=="")||(isNaN(maxd))){   maxd=thisDay; }
  else{maxd=parseInt(maxd);}  

  if((mind=="")||(isNaN(mind))){   mind="01";   mind=parseInt(mind); }
  else{mind=parseInt(mind);}

   if(parseInt(myy)>maxy || parseInt(myy)<miny){
   alert("You Must Enter The Year for "+dmsg+" Between "+miny+" and "+maxy+"\n please provide date correctly");
   myField.focus();
   return false;
   }
      
  if(mym>12){
  alert("we think you can not enter an abnormal month for "+dmsg+"\n please provide date correctly");
  myField.focus();
  return false;
  }

  if(myd>31){
  alert("we think you can not enter an abnormal day for "+dmsg+"\n please provide date correctly");
  myField.focus();
  return false;
  }
 

 year_b=parseInt(myy);

 monthDays = new Array(); 
 monthDays=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
 
 if(((year_b % 4 == 0) && (year_b % 100 != 0)) || (year_b % 400 == 0)) monthDays[1] = 29;


  if(parseInt(myd) > monthDays[parseInt(mym)-1])
  {
   alert("You have Entred an invalid day for the month mentioned for "+dmsg+" \n please provide date correctly");
   myField.focus();
   return false;
  }

//    alert(myy+"   "+mym+"   "+myd+"\n "+year_now+"   "+month_now+"   "+thisDay)
//    alert("we think you may not bo born in the future"+"\n please provide date correctly");


 if(parseInt(myy) > maxy) { dis_msg_new(myField,myd,mym,myy,dmsg,maxy,miny,maxm,minm,maxd,mind); return false; }
 if((parseInt(myy) == maxy)&&(parseInt(mym) > maxm)){ dis_msg_new(myField,myd,mym,myy,dmsg,maxy,miny,maxm,minm,maxd,mind); return false; }
 if((parseInt(myy) == maxy)&&(parseInt(mym) == maxm)&&(parseInt(myd) > maxd)){ dis_msg_new(myField,myd,mym,myy,dmsg,maxy,miny,maxm,minm,maxd,mind); return false; }
 if(parseInt(myy) < miny) { dis_msg_new(myField,myd,mym,myy,dmsg,maxy,miny,maxm,minm,maxd,mind); return false; }
 if((parseInt(myy) == miny)&&(parseInt(mym) < minm)){ dis_msg_new(myField,myd,mym,myy,dmsg,maxy,miny,maxm,minm,maxd,mind); return false; }
 if((parseInt(myy) == miny)&&(parseInt(mym) == minm)&&(parseInt(myd) < mind)){ dis_msg_new(myField,myd,mym,myy,dmsg,maxy,miny,maxm,minm,maxd,mind); return false; }

return true;
}

function dis_msg_new(myField,myd,mym,myy,dmsg,maxy,miny,maxm,minm,maxd,mind){

var ent_val="Entered "+dmsg+" is "+myd+"/"+mym+"/"+myy
alert(" "+dmsg+" Must Be "+"\n Between "+mind+"/"+minm+"/"+miny+"\n And "+maxd+"/"+maxm+"/"+maxy+"\n "+ent_val+"\n"+"\n please provide date correctly");
myd=""
mym=""
myy=""
myField.focus();
}

function datevaltrim(obj)
{
  var txt=obj.value;
  if((txt!="")||(txt!=null))
  {
   while(txt.charAt(txt.length-1) == " "||txt.charAt(txt.length-1) == ".")
   {
    txt=txt.substring(0,txt.length-1);
   }
    while(txt.charAt(0) == " "||txt.charAt(0) == ".")
   {
    txt=txt.substring(1,txt.length);
   }
  }
 obj.value=txt;
 return txt;
}
