function dateRangeValidation(){ return dateValidation(0, 's', 'e') } function dateValidation(formIndex, sind, eind){ var flagvalid = false syear = document.forms[formIndex].elements[sind+"Year"].value smonth = document.forms[formIndex].elements[sind+"Month"].options[document.forms[formIndex].elements[sind+"Month"].selectedIndex].value sday = document.forms[formIndex].elements[sind+"Day"].options[document.forms[formIndex].elements[sind+"Day"].selectedIndex].value shour = document.forms[formIndex].elements[sind+"Hour"].options[document.forms[formIndex].elements[sind+"Hour"].selectedIndex].value sminute = document.forms[formIndex].elements[sind+"Minute"].options[document.forms[formIndex].elements[sind+"Minute"].selectedIndex].value var sDate = null; if(document.forms[formIndex].elements[sind+"Second"] != null) { ssecond= document.forms[formIndex].elements[sind+"Second"].options[document.forms[formIndex].elements[sind+"Second"].selectedIndex].value sDate = new Date(syear,(smonth-1),sday,shour, sminute,ssecond); }else { sDate = new Date(syear,(smonth-1),sday,shour, sminute); } eyear=document.forms[formIndex].elements[eind+"Year"].value emonth=document.forms[formIndex].elements[eind+"Month"].options[document.forms[formIndex].elements[eind+"Month"].selectedIndex].value eday=document.forms[formIndex].elements[eind+"Day"].options[document.forms[formIndex].elements[eind+"Day"].selectedIndex].value ehour=document.forms[formIndex].elements[eind+"Hour"].options[document.forms[formIndex].elements[eind+"Hour"].selectedIndex].value eminute=document.forms[formIndex].elements[eind+"Minute"].options[document.forms[formIndex].elements[eind+"Minute"].selectedIndex].value var eDate = null; if(document.forms[formIndex].elements[eind+"Second"] != null) { esecond=document.forms[formIndex].elements[eind+"Second"].options[document.forms[formIndex].elements[eind+"Second"].selectedIndex].value eDate = new Date(eyear, (emonth-1),eday, ehour, eminute,esecond); }else { eDate = new Date(eyear, (emonth-1),eday, ehour, eminute); } flagvalid = checkYear(syear) if(!flagvalid){ alert("Please input start year in the format \"YYYY\" and must be a number") return flagvalid } if(flagvalid){ flagvalid = checkYear(eyear) if(!flagvalid){ alert("Please input end year in the format \"YYYY\" and must be a number") return flagvalid } } if(flagvalid){ if( (checkDate(syear, smonth, sday, 'Start')) && (checkDate(eyear,emonth, eday, 'End')) ){ flagvalid = true }else { flagvalid = false return flagvalid } } var checkDaysDiffrence; if (typeof document.forms[formIndex].elements["checkDaysDiffrence"] != 'undefined'){ checkDaysDiffrence= document.forms[formIndex].elements["checkDaysDiffrence"].value; } var diffDays = parseInt((eDate - sDate) / (1000 * 60 * 60 * 24), 10); if(flagvalid){ var difference = eDate - sDate if(parseFloat(difference) > 0) flagvalid = true else { if(difference == 0){ alert("Both Start date and End date are equal. \nPlease correct") alert(difference) }else { alert("End date is before Start date \nPlease correct") } flagvalid = false } if(checkDaysDiffrence){ if(diffDays >= checkDaysDiffrence){ flagvalid = false alert("Days diffrence more then "+checkDaysDiffrence+" days"); } } } return flagvalid } function checkYear(year){ var yearFlag = true; if(year.length!=4){ yearFlag = false; }else{ for(var i=0; i '9'){ yearFlag = false; } } } return yearFlag; } function checkDate(syear, smonth, sday, period){ var period_text; if(period == 'Start') { period_text = 'Start' } else if (period == 'DSSR') { period_text = 'DSSR' } else if (period == 'TPDR') { period_text = 'TPDR' } else if (period == 'Mailbox fee start') { period_text = 'Mailbox fee start' }else { period_text ='End' } leapYear = (((syear % 4 == 0) && (syear % 100 != 0)) || (syear % 400 == 0)) ? true : false; flag = true if((smonth >12)||(smonth < 1)) { alert(period_text + " month out of range."); flag = false return flag; } if((( sday > (no = !leapYear ? 28 : 29))||(sday <1)) && (smonth == 2)) { alert(period_text +" day out of range"); flag = false return flag; } if(((smonth==1)||(smonth==3)||(smonth==5)||(smonth==7)||(smonth==8)||(smonth==10)||(smonth==12))&&((sday>31)||(sday<1))) { alert(period_text +" day out of range"); flag = false return flag; } if(((smonth==4)||(smonth==6)||(smonth==9)||(smonth==11))&&((sday>30)||(sday<1))) { alert(period_text +" day out of range"); flag = false return flag; } return flag } function checkElement(){ for(i = 0; i 12)||(smonth < 1)) { alert(" Month out of range."); flag = false return flag; } if((( sday > (no = !leapYear ? 28 : 29))||(sday <1)) && (smonth == 2)) { alert( "Day out of range"); flag = false return flag; } if(((smonth==1)||(smonth==3)||(smonth==5)||(smonth==7)||(smonth==8)||(smonth==10)||(smonth==12))&&((sday>31)||(sday<1))) { alert(" Day out of range"); flag = false return flag; } if(((smonth==4)||(smonth==6)||(smonth==9)||(smonth==11))&&((sday>30)||(sday<1))) { alert(" Day out of range"); flag = false return flag; } return flag } //end