
function myDateSelecter(id,nn) {  
    IDmonth =id+'month'
	IDday   =id+'day'
	IDyear  =id+'year'
	if (isNaN(nn)||(nn==''))     { nn=0 }	
	SelectedMonth = parseInt(document.getElementById(IDmonth).value)
	SelectedDay   = parseInt(document.getElementById(IDday).value) + parseInt(nn)
	SelectedYear  = parseInt(document.getElementById(IDyear).value)
	SelectedDate  = new Date(SelectedYear,SelectedMonth,SelectedDay)
	return (SelectedDate);
}
function myDateInsert(dt,id) {  
    IDmonth =id+'month'
	IDday   =id+'day'
	IDyear  =id+'year'
	document.getElementById(IDmonth).value = parseInt(dt.getMonth())
	document.getElementById(IDday).value   = parseInt(dt.getDate())
	document.getElementById(IDyear).value  = parseInt(dt.getFullYear())
}


function CheckIn(d){ //Shift Checkout date 2 days forward when elected 
	CheckInDate = myDateSelecter('CI',0)                       
	Today = new Date()	
	addDay = d 		
	if (CheckInDate<Today) { alert ("Sorry, the check in date can't be earlier than today."); 
		myDateInsert(Today,'CI',0)                             
		CheckOutDate= myDateSelecter('CI',addDay)	         
		myDateInsert(CheckOutDate,'CO')
	}
	else { 
		newCheckOutDate = myDateSelecter('CI',addDay);
		myDateInsert(newCheckOutDate,'CO')
	}
} 
function CheckOut(d){ //Alert if CheckOut<=CheckInDate
	CheckOutDate  = myDateSelecter('CO',0)  
 	Today = new Date()
	if (CheckOutDate<=Today) { alert("Sorry, the check out date should be later than today.")
		myDateInsert(Today,'CI',0)           
		CheckOutDate = myDateSelecter('CI',d); 
		myDateInsert(CheckOutDate,'CO')
	}
	else {
	    CheckInDate  = myDateSelecter('CI',0)
	    if (CheckOutDate<=CheckInDate) { 
            alert("Sorry, the check out date should be later than check in date.");
			addDay = d
            newCheckOutDate  = myDateSelecter('CI',addDay) 
            myDateInsert(newCheckOutDate,'CO')
		}
	}
} 
//-------------------------------------------


