﻿function date_diff(f) {

	//ISO 8601 Gregorian Days Difference Demo (http://www.merlyn.demon.co.uk/js-date1.htm)
	var diffr=Math.round((new Date(f.ReservationBtn$C_txtendt.value.replace(/-/g, '/'))-new Date(f.ReservationBtn$C_txtstdt.value.replace(/-/g, '/')))/864e5);
	return diffr;
}
function check_Reservastion_form(f) {

	var j=k=xflag=0;
	var tchk=bchk="";
	var A_on=new Array();
	var A_room=new Array();
	var A_per=new Array();
    f = document.book_room_res
	if(f.ReservationBtn$C_txtstdt.value == '')
	{
	    alert("Please Select Check In Date");
	    f.ReservationBtn$C_txtstdt.focus();
	    return false
	}
	if(f.ReservationBtn$C_txtendt.value == '')
	{
	    alert("Please Select Check Out Date");
	    f.ReservationBtn$C_txtendt.focus();
	    return false
	}
	
				var tmpdt;
				var curdte=new Date();
				var curday=curdte.getDate();
				var curmth=curdte.getMonth()+1;
				var curyer=curdte.getYear();
				tmpdt=curyer.toString();
				if (tmpdt.substring(0,1)=="1") { //this is only required for linux server
					curyer+=1900;
				}
				var nxtyer=curyer+1;
				if (parseInt(curday)<10) {
					curday=""+"0"+""+curday;
				}
				if (parseInt(curmth)<10) {
					curmth=""+"0"+""+curmth;
				}
				var yrmtdy=curyer.toString()+curmth.toString()+curday.toString();
				var seldt=nxtyer+"0930";

				
					//yyyymmdd format
										    
					var stdt=f.ReservationBtn$C_txtstdt.value.substring(6)+f.ReservationBtn$C_txtstdt.value.substring(0,2)+f.ReservationBtn$C_txtstdt.value.substring(5,3);
					var endt=f.ReservationBtn$C_txtendt.value.substring(6)+f.ReservationBtn$C_txtendt.value.substring(0,2)+f.ReservationBtn$C_txtendt.value.substring(5,3);
					
					if (date_diff(f)==0) {
						alert("Check-In and Check-Out Date cannot be same");
						return false;
					} else if (date_diff(f)<0) {
						alert("Check-Out date is less than Check-In date");
						return false;
					} else if (parseInt(stdt)<=parseInt(yrmtdy) || parseInt(endt)<=parseInt(yrmtdy)) {
						alert("Booking date should be greater than current date");
						return false;
					} else if (parseInt(endt)>parseInt(seldt)) { //should not be more than next year's last day of september
						alert("Ending date should not be more than September 30, "+nxtyer);
						return false;
					}
		return true;
		
}
