var nav=navigator.appName;
var nav=navigator.appName;
var myindate = new Date(2010,1,27,0,0,0,0);
var myoutdate=new Date(2010,1,28,0,0,0,0);
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="images";
function set_default_date(){
document.frm1.cmbCheckInYear.options.length=0;
document.frm1.cmbCheckOutYear.options.length=0;
for (a=0; a<1; a++){
with (document.frm1){
if (a!=4){
cmbCheckInYear.options[a]= new Option(inyy+a,inyy+a);
}
cmbCheckOutYear.options[a]= new Option(inyy+a,inyy+a);
}
}

with (document.frm1){
cmbNoOfAdults.selectedIndex=1;
cmbCheckInMonth.selectedIndex		=	inmm;
cmbCheckInYear.selectedIndex			= inyy-inyy;
cmbCheckOutMonth.selectedIndex	= outmm;
cmbCheckOutYear.selectedIndex		= outyy-inyy;
cmbNoOfNights.selectedIndex				=	0;
}
//document.images["inday"].src=""+dayimagepath+"/dd"+(myindate.getDay())+".gif";
set_image('in')
//document.images["outday"].src=""+dayimagepath+"/dd"+(myoutdate.getDay())+".gif";
set_image('out')
setMonthDays("In");
setMonthDays("Out");
document.frm1.cmbCheckInDate.selectedIndex			= indd-1;
document.frm1.cmbCheckOutDate.selectedIndex		= outdd-1;
}

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";
set_image('in')
noDays = Number(document.frm1.cmbNoOfNights.options[document.frm1.cmbNoOfNights.selectedIndex].value);
tmpOutDate = new Date(tmpInDate.setDate(tmpInDate.getDate()+noDays));
document.frm1.cmbCheckOutMonth.selectedIndex	= tmpOutDate.getMonth();
document.frm1.cmbCheckOutYear.selectedIndex		= tmpOutDate.getFullYear()-inyy;
setMonthDays("Out");
document.frm1.cmbCheckOutDate.selectedIndex		= tmpOutDate.getDate()-1;
//document.images["outday"].src=""+dayimagepath+"/dd"+(tmpOutDate.getDay())+".gif";
set_image('out')
}

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.options[document.frm1.cmbCheckOutYear.selectedIndex].value,document.frm1.cmbCheckOutMonth.options[document.frm1.cmbCheckOutMonth.selectedIndex].value,document.frm1.cmbCheckOutDate.options[document.frm1.cmbCheckOutDate.selectedIndex].value,0,0,0,0);
dateDifference = get_deference(tmpInDate,tmpOutDate);
//document.images["outday"].src=""+dayimagepath+"/dd"+(tmpOutDate.getDay())+".gif";
set_image('in')
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.options[document.frm1.cmbCheckOutYear.selectedIndex].value,document.frm1.cmbCheckOutMonth.options[document.frm1.cmbCheckOutMonth.selectedIndex].value,document.frm1.cmbCheckOutDate.options[document.frm1.cmbCheckOutDate.selectedIndex].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("Number of adults is greater then the maximum no of adults for the rooms selected!");
return;
}

//document.frm1.selCity.value="%";

var chk=chkRange();

if (!chk){
document.getElementById("chkMsg").style.display="block";
//alert("please select dates between 28th February 2009 to 09th March 2009");
//document.write();
return;
}else{

document.getElementById("chkMsg").style.display="none";
}

document.frm1.selCity.value="%";
document.frm1.AffiliateMainPage.value = ""+document.location+"";
document.frm1.action = "http://www4.secure-reservation.com/servlet/ACG.ResevationSearch";
op_win();
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;
}

var sWith=screen.width;
var toadd= 0;
if (sWith>800){
toadd = (sWith-800)/2;
}

function op_win(){
document.getElementById("progress").style.left=parseInt(document.getElementById("progress").style.left)+toadd;
document.getElementById("progress").style.visibility="visible";
}

function progress(){
document.getElementById("progress").style.visibility="hidden";
}


var brwag=navigator.userAgent;


function ret2digit(val){
if (val.length<2){return "0"+val+"";}else{return ""+val+"";}
}
function chkRange(){
var chkOK=true;
var inDT=Number(""+ret2digit(document.frm1.cmbCheckInYear.options[document.frm1.cmbCheckInYear.selectedIndex].value)+""+ret2digit(document.frm1.cmbCheckInMonth.options[document.frm1.cmbCheckInMonth.selectedIndex].value)+""+ret2digit(document.frm1.cmbCheckInDate.options[document.frm1.cmbCheckInDate.selectedIndex].value)+"");
var ouDT=Number(""+ret2digit(document.frm1.cmbCheckOutYear.options[document.frm1.cmbCheckOutYear.selectedIndex].value)+""+ret2digit(document.frm1.cmbCheckOutMonth.options[document.frm1.cmbCheckOutMonth.selectedIndex].value)+""+ret2digit(document.frm1.cmbCheckOutDate.options[document.frm1.cmbCheckOutDate.selectedIndex].value)+"");
if (inDT<20100207 && inDT>20100126 && ouDT<20100208 && ouDT>20100127){
chkOK=true;
}else{
chkOK=false;
}
return chkOK;
}




function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function set_image(para){
if (para=="in"){
day = new Date(Number(document.frm1.cmbCheckInYear.options[document.frm1.cmbCheckInYear.selectedIndex].value),Number(document.frm1.cmbCheckInMonth.options[document.frm1.cmbCheckInMonth.selectedIndex].value),Number(document.frm1.cmbCheckInDate.options[document.frm1.cmbCheckInDate.selectedIndex].value));
document.images["inday"].src="http://www4.secure-reservation.com/ACG/dd"+day.getDay()+".gif"
}else{
day = new Date(Number(document.frm1.cmbCheckOutYear.options[document.frm1.cmbCheckOutYear.selectedIndex].value),Number(document.frm1.cmbCheckOutMonth.options[document.frm1.cmbCheckOutMonth.selectedIndex].value),document.frm1.cmbCheckOutDate.options[document.frm1.cmbCheckOutDate.selectedIndex].value);
document.images["outday"].src="http://www4.secure-reservation.com/ACG/dd"+day.getDay()+".gif"
}
}

//-->