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 PKGdefault() {	 
    PKGinDays = parseInt(document.getElementById('PKGdiv1').innerHTML)
	if (!isNaN(PKGinDays)&&(PKGinDays!='')&&(PKGinDays!=0)) {
		CheckInDate = myDateSelecter('CI',0)  
		CheckOutDate = myDateSelecter('CI',PKGinDays)
		myDateInsert(CheckOutDate,'CO')
	}	
}
function PKGoption(d) { 
	optValue = document.getElementById('BedType').value
    var strLength = optValue.length;
	optPKlettr = optValue.substring(0,2)                          
	optPKID    = parseInt(optValue.substring(2,strLength))       
	if (optPKlettr=='pk') {                                      
	    NN = parseInt(document.getElementById('NofN'+optPKID).innerHTML) 
	    if (!isNaN(NN)&&(NN!='')&&(NN!=0)) 
		     { CheckOutDate = myDateSelecter('CI',NN)}           
		else { CheckOutDate = myDateSelecter('CI',d) }           
        myDateInsert(CheckOutDate,'CO')	
    }
}
function CheckIn(d){ //Shift Checkout date 2 days forward when elected 
	CheckInDate = myDateSelecter('CI',0)                       
	Today = new Date()	
	if (CheckInDate<Today) { alert ("Sorry, the check in date can't be earlier than today."); 
		myDateInsert(Today,'CI',0)                             
		CheckOutDate= myDateSelecter('CI',d)	         
		myDateInsert(CheckOutDate,'CO')
	}
	else { 
		newCheckOutDate = myDateSelecter('CI',d);
		myDateInsert(newCheckOutDate,'CO')
	}
} 
function CheckInPKG(d){ //Shift Checkout date 2 days forward when elected 
	CheckInDate = myDateSelecter('CI',0)                       
    PKGinDays = parseInt(document.getElementById('PKGdiv1').innerHTML)
	Today = new Date()	
	if (isNaN(PKGinDays)||(PKGinDays=='')||(PKGinDays==0)) { addDay = d }		
	else  { addDay = PKGinDays }	
	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.");
            PKGinDays = parseInt(document.getElementById('PKGdiv1').innerHTML)
	        if (isNaN(PKGinDays)||(PKGinDays=='')||(PKGinDays==0)) { addDay = d }	
	        else { addDay = PKGinDays }	
            newCheckOutDate  = myDateSelecter('CI',addDay) 
            myDateInsert(newCheckOutDate,'CO')
		}
	}
} 