var nav=navigator.appName;
var myindate = new Date();
var myoutdate = new Date();
myoutdate = new Date(myoutdate.setDate(myoutdate.getDate()+1));
var inmm 	= myindate.getMonth();
var indd 	= myindate.getDate();
var inyy 	= myindate.getFullYear();
var outmm = myoutdate.getMonth();
var outdd = myoutdate.getDate();
var outyy = myoutdate.getFullYear();
var dayimagepath="http://www.secure-atlanticcity.com/ACExperts/Img/en/";

function set_default_date(){
document.frm1.cmbCheckInYear.options.length=0;

for (a=0; a<5; a++){
with (document.frm1){
if (a!=4){
cmbCheckInYear.options[a]= new Option(inyy+a,inyy+a);
}
}
}

with (document.frm1){
cmbNoOfAdults.selectedIndex=1;
cmbCheckInMonth.selectedIndex		=	inmm;
cmbCheckInYear.selectedIndex			= inyy-inyy;
cmbCheckOutMonth.value	= outmm;
cmbCheckOutYear.value		= outyy;
cmbNoOfNights.selectedIndex				=	0;
}
document.images["inday"].src=""+dayimagepath+"/dd"+(myindate.getDay())+".gif";
setMonthDays("In");
document.frm1.cmbCheckInDate.selectedIndex			= indd-1;
document.frm1.cmbCheckOutDate.value		= outdd;

}

function setCheckOut(){
tmpInDate = new Date(document.frm1.cmbCheckInYear.options[document.frm1.cmbCheckInYear.selectedIndex].value,document.frm1.cmbCheckInMonth.options[document.frm1.cmbCheckInMonth.selectedIndex].value,document.frm1.cmbCheckInDate.options[document.frm1.cmbCheckInDate.selectedIndex].value,0,0,0,0);
document.images["inday"].src=""+dayimagepath+"/dd"+(tmpInDate.getDay())+".gif";
noDays = Number(document.frm1.cmbNoOfNights.options[document.frm1.cmbNoOfNights.selectedIndex].value);
tmpOutDate = new Date(tmpInDate.setDate(tmpInDate.getDate()+noDays));
document.frm1.cmbCheckOutMonth.value	= tmpOutDate.getMonth();
document.frm1.cmbCheckOutYear.value		= tmpOutDate.getFullYear();
document.frm1.cmbCheckOutDate.value		= tmpOutDate.getDate();
}

function setNights(){
tmpInDate = new Date(document.frm1.cmbCheckInYear.options[document.frm1.cmbCheckInYear.selectedIndex].value,document.frm1.cmbCheckInMonth.options[document.frm1.cmbCheckInMonth.selectedIndex].value,document.frm1.cmbCheckInDate.options[document.frm1.cmbCheckInDate.selectedIndex].value,0,0,0,0);
tmpOutDate = new Date(document.frm1.cmbCheckOutYear.value,document.frm1.cmbCheckOutMonth.value,document.frm1.cmbCheckOutDate.value,0,0,0,0);
dateDifference = get_deference(tmpInDate,tmpOutDate);
if (dateDifference<1 || dateDifference>15){
return;
}
if (dateDifference>0){
document.frm1.cmbNoOfNights.selectedIndex = dateDifference-1;
}
}

function maxdate(mm,yy){
if (mm==1){
if(yy%4==0){return 29;}else{return 28;}
}else if (mm==0 || mm==2 || mm==4 || mm==6 || mm==7 || mm==9 || mm==11){
return 31;
}else{
return 30;
}
}

function setMonthDays(name){
tmpmm	= document.frm1.elements["cmbCheck"+name+"Month"].options[document.frm1.elements["cmbCheck"+name+"Month"].selectedIndex].value;
tmpyy	= document.frm1.elements["cmbCheck"+name+"Year"].options[document.frm1.elements["cmbCheck"+name+"Year"].selectedIndex].value;
maxdays = maxdate(tmpmm,tmpyy);
selectedInd=document.frm1.elements["cmbCheck"+name+"Date"].selectedIndex; 
document.frm1.elements["cmbCheck"+name+"Date"].options.length=28;
toAdd=maxdays-28;
for (a=0; a<toAdd; a++){
document.frm1.elements["cmbCheck"+name+"Date"].options[document.frm1.elements["cmbCheck"+name+"Date"].options.length] = new Option(29+a,29+a);
}
new_lnth=document.frm1.elements["cmbCheck"+name+"Date"].options.length;
if (new_lnth<selectedInd+1){
document.frm1.elements["cmbCheck"+name+"Date"].selectedIndex=document.frm1.elements["cmbCheck"+name+"Date"].options.length-1;
}else{
document.frm1.elements["cmbCheck"+name+"Date"].selectedIndex=selectedInd;
}
}

function checkValues(affcode){
tmpInDate = new Date(document.frm1.cmbCheckInYear.options[document.frm1.cmbCheckInYear.selectedIndex].value,document.frm1.cmbCheckInMonth.options[document.frm1.cmbCheckInMonth.selectedIndex].value,document.frm1.cmbCheckInDate.options[document.frm1.cmbCheckInDate.selectedIndex].value,0,0,0,0);
tmpOutDate = new Date(document.frm1.cmbCheckOutYear.value,document.frm1.cmbCheckOutMonth.value,document.frm1.cmbCheckOutDate.value,0,0,0,0);
dateDifference = get_deference(tmpInDate,tmpOutDate);

noNights = document.frm1.cmbNoOfNights.options[document.frm1.cmbNoOfNights.selectedIndex].value;
today = new Date();
if ((today-tmpInDate)>86400000){
alert("Check in date can not be less than the system date");
set_default_date();
return;
}

if (dateDifference>15 || dateDifference<1){
alert("Number of night(s) can not be grater than "+document.frm1.cmbNoOfNights.options.length+" or less than 1.\r\nPlease select again ...");
set_default_date();
return;
}else{
document.frm1.cmbNoOfNights.selectedIndex=dateDifference-1;
}

noOfRooms = document.frm1.cmbNoOfRooms.selectedIndex+1;
noOfAdults = document.frm1.cmbNoOfAdults.selectedIndex+1;

if(noOfRooms>noOfAdults){
alert("Please enter the Total number of adults Combined for all rooms!");
return;
}

if (affcode!=''){
document.frm1.afftCode.value=""+affcode+"";
}
document.frm1.selCity.value="%";
docdom=""+document.domain+"";
document.frm1.AffiliateMainPage.value=""+document.location+"";
document.frm1.action = "http://www.secure-atlanticcity.com/servlet/ACExperts.ResevationSearch";
document.frm1.submit();
}

function get_deference(ind,oud){
ind_d = ind.getDate();
ind_m = ind.getMonth();
ind_y = ind.getYear();
oud_d = oud.getDate();
oud_m = oud.getMonth();
oud_y = oud.getYear();
ret_val=0;
		if (ind_y==oud_y){
				if (ind_m==oud_m){
				ret_val=oud_d-ind_d;
				}else{
				ret_val=(maxdate(ind_m,ind_y)-ind_d)+oud_d
				}
		}else{
				if (ind_m==11 && oud_m==0){
				ret_val=(maxdate(ind_m,ind_y)-ind_d)+oud_d
				}
		}
return ret_val;
}
