// JavaScript Document
/* script created by TravelChaCha
					 culture holidays
					 junior programmer
					 Dated 29 july 2007
script to validate check in and check out dates
	1. first check in date should be greater then current date
	2. check out date should be greater than check in date
	3. check out date should not be greater than 30 days from check in dates
arguments are id's of check in month, year, day and check out month,year and day
*/
function chkDate(iDD,iMM,iYY,oDD,oMM,oYY){
		var inDD=document.getElementById(iDD);
		var inMM=document.getElementById(iMM);
		var inYY=document.getElementById(iYY);
				
		var outDD=document.getElementById(oDD);
		var outMM=document.getElementById(oMM);
		var outYY=document.getElementById(oYY)	;	
		// myDate is global Variable
		//var myDate=new Date();
		//calculating date diff b/w chk in and chk out dates in miliseconds
		var diffMili=Date.UTC(outYY.value,outMM.value,outDD.value,0,0,0)-Date.UTC(inYY.value,inMM.value,inDD.value,0,0,0);
		//calculating diff in days between chk in and chk out days
		var diffDays=diffMili/1000/60/60/24;
		//calculating date diff between check in and Current date
		var inDateDiff=Date.UTC(inYY.value,inMM.value,inDD.value,0,0,0)-Date.UTC(myDate.getFullYear(),myDate.getMonth(),myDate.getDate(),0,0,0);
		var inDateDiff=(inDateDiff/1000/60/60/24)-inDD.length;
		if(inDateDiff<=0){
			alert("\'Check In\' Date Should Be Greater Than Today's Date");
			return false;
		}
		else{
			if(diffDays<=0){
				alert("\'Check Out\' Date Should Be Greater Than \'Check In Date\'");
				return false;
			}
			if(diffDays>=30){
				alert("You Can Only Book Hotel For 30 Days");
				return false;
			}
			if(diffDays<30){
				if(chkRoom() && CityValidate())
				return true;
				else
				return false;
			}			
		}
	}
	
	function chkRoom(){
		var Room2Adult=document.getElementById("Room2Adult");
		var Room3Adult=document.getElementById("Room3Adult");
		var Rooms=document.getElementById('Rooms');
		if(Rooms.value==2 && Room2Adult.value==0){
				alert("Adults In Room Sholud Be Greater Than 0");
				return false;
			}
		if((Rooms.value==3 && Room3Adult.value==0) || (Rooms.value==3 && Room2Adult.value==0)){
				alert("Adults In Room Sholud Be Greater Than 0");
				return false;
			}
		else
			return true;
		}
		
	function CityValidate(){
			var otherCity=document.getElementById("otherCity");
			//fm is form and element 8 is other radio button
			fm=document.getElementById("RHform");
			if(fm.city[8].checked && otherCity.selectedIndex==0){
				alert("Select City First");
				otherCity.focus();
				return false;
			}
			else
			return true;
		}