﻿function CompareDate(fld1,fld2) 
            {             	
            if (Page_ClientValidate() == true)
            {	
	            var success = true; 
	            var mo,day,yy,testDate;
            	
	            var re = new RegExp("^((31(?! (Feb|Apr|Jun|Sep|Nov)))|((30|29)(?! Feb))|(29(?= Feb (((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|		[2468][048]|[3579][26])00)))))|(0?[1-9])|1\\d|2[0-8])-(Jan|Feb|Mar|May|Apr|Jul|Jun|Aug|Oct|Sep|Nov|Dec)-((1[6-9]|[2-9]\\d)\\d{2})$"); 

	            var m=re.test(fld1.value); 
	            var m1=re.test(fld2.value);  
            	
	            var PickDate =CheckDateFormat(fld1);
	            var DropDate =CheckDateFormat(fld2);
            	
	            if (DropDate < PickDate)
	            {
		            alert("Selected Date(s) Are Not Valid, Drop-Off Date must be greater than Pick-Up Date."); 
		            return false;
	            }        	
	            
            	
            return true;
            }
            }


   
        function getMonth(val)
            {
	            var monthArray = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","JAN","FEB","MAR","APR","MAY","JUN","JUL",		"AUG","SEP","OCT","NOV","DEC");
	            for (var i=0; i<monthArray.length; i++) 
	            {
		            if (monthArray[i] == val) 
		            {
			            return(i);
		            } 
	            }
	            return(-1);
            }

        function CheckDateFormat(dt1)
            {
                var success = true; 
                var mo, day, yy, testDate; 
                var val = dt1.value; 
                var re = new RegExp("[0-9]{1,2}[/-][A-Z,a-z]{3}[/-][0-9]{4}", "g");
                if (re.test(val)) 
                { 
                    var delimChar = (val.indexOf("/") != -1) ? "/" : "-"; 
                    var delim1 = val.indexOf(delimChar); 
                    var delim2 = val.lastIndexOf(delimChar); 
                    day = parseInt(val.substring(0,delim1),10); 
                    mo = getMonth(val.substring(delim1+1,delim2),10); 
                    yy = parseInt(val.substring(delim2+1),10); 
                    testDate = new Date(yy,mo,day); 		
                }
                else 
                { 
                    alert("Incorrect date format.  Enter as DD-MON-YYYY or DD/MON/YYYY."); 
                    success = false; 
                } 
            	
                if (success)
                  return testDate;
                else 
                  return false;

            }    
