var DateOffset		= 7;
var DateDifference	= 1;
var NoYears			= 4;
var CurrDday 		= new Date();
var CurrMonth		= CurrDday.getMonth();
var CurrDate		= CurrDday.getDate();
var CurrYear		= CurrDday.getFullYear();

var InDay 			= new Date();
var InDay			= new Date(InDay.setDate(InDay.getDate()+DateOffset));
var InMonth			= InDay.getMonth();
var InDate			= InDay.getDate();
var InYear			= InDay.getFullYear();

var OutDay 			= InDay;
var OutDay			= new Date(OutDay.setDate(OutDay.getDate()+DateDifference));
var OutMonth		= OutDay.getMonth();
var OutDate			= OutDay.getDate();
var OutYear			= OutDay.getFullYear();
var nav				= navigator.appName;
var WeekDays		= new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
var FORM="";var INM="";var IND="";var INY="";var OUTM="";var OUTD="";var OUTY="";var NON="";
var rSource="W";

function Init(frm,inm,ind,iny,outm,outd,outy,non){
FORM=frm;INM=inm;IND=ind;INY=iny;OUTM=outm;OUTD=outd;OUTY=outy;NON=non;
FillYears();
}

function FillYears(){
	with(document.forms[FORM]){
		for (a=0; a<=NoYears; a++){
		if (a!=NoYears){elements[INY].options[a]= new Option(InYear+a,InYear+a);}
		elements[OUTY].options[a]= new Option(InYear+a,InYear+a);
		}
	}
	LoadDefaultDates();
}

function LoadDefaultDates(){
	with (document.forms[FORM]){
	elements[INY].options[InYear-InYear].selected=true;
	elements[OUTY].options[OutYear-InYear].selected=true;
	elements[INM].options[InMonth].selected=true;
	elements[OUTM].options[OutMonth].selected=true;
	setMonthDays(IND,InMonth,InYear);
	setMonthDays(OUTD,OutMonth,OutYear);
	elements[IND].options[InDate-1].selected=true;
	elements[OUTD].options[OutDate-1].selected=true;
	elements[NON].options[DateDifference-1].selected=true;
	}
	document.images["iday"].src="images/dd"+returnDay('IN')+".gif";
	document.images["oday"].src="images/dd"+returnDay('OUT')+".gif";
}

function setMonthDays(objname,mm,yy){
	with (document.forms[FORM]){
		currIndex=elements[objname].selectedIndex;
		elements[objname].options.length=0;
		for (a=1; a<=getMaxDays(mm,yy); a++){
		elements[objname].options[a-1] = (a<10)? new Option("0"+a+"","0"+a+"") : new Option(a,a)
		}
		if (elements[objname].options.length<(currIndex+1)){
		elements[objname].selectedIndex=elements[objname].options.length-1;
		}else{
		elements[objname].selectedIndex=currIndex;
		}
	}
}


function returnDay(val){
	iiy=document.forms[FORM].elements[eval(""+val+"Y")].options[document.forms[FORM].elements[eval(""+val+"Y")].selectedIndex].value;
	iim=document.forms[FORM].elements[eval(""+val+"M")].options[document.forms[FORM].elements[eval(""+val+"M")].selectedIndex].value;
	iid=document.forms[FORM].elements[eval(""+val+"D")].options[document.forms[FORM].elements[eval(""+val+"D")].selectedIndex].value;
	tmpDate1=new Date(iiy,iim,iid);
	return tmpDate1.getDay();
}


function retDay(dd,mm,yy){
tempOptDate= new Date(yy,mm,dd,0,0,0,0);
return WeekDays[tempOptDate.getDay()]

}

function getMaxDays(mm,yy){
mxCount=0;
	if (mm==1 && yy%4==0){
	mxCount=29; }else if (mm==1){
	mxCount=28; }else if (mm==0 || mm==2 || mm==4 || mm==6 || mm==7 || mm==9 || mm==11){
	mxCount=31;	}else{ mxCount=30;}
return mxCount;
}

function countNoDays(inM,inD,inY,outM,outD,outY){
selDays=1;
	if (inY==outY){
		if (inM==outM){
		selDays=outD-inD;
			if (selDays<1){selDays=-1;}
		}else{
			if (inM>outM){
			selDays=-1;
			}else{
				selDays=(getMaxDays(inM,inY)-inD)+outD;
				for (a=0; a<(outM-inM-1); a++){
				selDays=selDays+getMaxDays(inM+1+a,inY);
				}
			}
		}
	}else{
		if (outY>inY){
			selDays=(getMaxDays(inM,inY)-inD)+outD;
			for (k=inM+1; k<=11; k++){
				selDays=selDays+getMaxDays(k,inY);
			}
			for (k=0; k<(outY-inY-1); k++){
				selDays=selDays+getDaysOfYear(inY+1+k);
			}
			for (k=0; k<outM; k++){
				selDays=selDays+getMaxDays(k,outY);
			}
			
		}else{
		selDays=-1;
		}
	}
	return selDays;
}

function getDaysOfYear(yy){
	if (yy%4==0){
	return 366;
	}else{
	return 365;
	}
}

function setCheckOut(){
	with (document.forms[FORM]){
	setMonthDays(IND,elements[INM].options[elements[INM].selectedIndex].value,elements[INY].options[elements[INY].selectedIndex].value);
	tempCheckIn = new Date(elements[INY].options[elements[INY].selectedIndex].value,elements[INM].options[elements[INM].selectedIndex].value,elements[IND].options[elements[IND].selectedIndex].value,0,0,0,0);
	tempCheckOut = new Date(tempCheckIn.setDate(tempCheckIn.getDate()+Number(elements[NON].options[elements[NON].selectedIndex].value)));
	elements[OUTY].selectedIndex = tempCheckOut.getFullYear()-InYear;
	elements[OUTM].selectedIndex = tempCheckOut.getMonth();
	setMonthDays(OUTD,tempCheckOut.getMonth(),tempCheckOut.getFullYear());
	elements[OUTD].selectedIndex = tempCheckOut.getDate()-1;
	}
	document.images["iday"].src="images/dd"+returnDay('IN')+".gif";
	document.images["oday"].src="images/dd"+returnDay('OUT')+".gif";
}

function setNights(){
	with (document.forms[FORM]){
	setMonthDays(OUTD,elements[OUTM].options[elements[OUTM].selectedIndex].value,elements[OUTY].options[elements[OUTY].selectedIndex].value);
	inM=Number(elements[INM].options[elements[INM].selectedIndex].value);
	inD=Number(elements[IND].options[elements[IND].selectedIndex].value);
	inY=Number(elements[INY].options[elements[INY].selectedIndex].value);
	outM=Number(elements[OUTM].options[elements[OUTM].selectedIndex].value);
	outD=Number(elements[OUTD].options[elements[OUTD].selectedIndex].value);
	outY=Number(elements[OUTY].options[elements[OUTY].selectedIndex].value);
	noDays=countNoDays(inM,inD,inY,outM,outD,outY);
		if (noDays!=-1 && noDays<=elements[NON].options.length){
			elements[NON].selectedIndex=noDays-1;
		}
	}
	document.images["iday"].src="images/dd"+returnDay('IN')+".gif";
	document.images["oday"].src="images/dd"+returnDay('OUT')+".gif";
}

function submitData(AFFCode){
with (document.forms[FORM]){
	inM=Number(elements[INM].options[elements[INM].selectedIndex].value);
	inD=Number(elements[IND].options[elements[IND].selectedIndex].value);
	inY=Number(elements[INY].options[elements[INY].selectedIndex].value);
	outM=Number(elements[OUTM].options[elements[OUTM].selectedIndex].value);
	outD=Number(elements[OUTD].options[elements[OUTD].selectedIndex].value);
	outY=Number(elements[OUTY].options[elements[OUTY].selectedIndex].value);
	selInday = new Date(inY,inM,inD,0,0,0,0);
	
	noDays=countNoDays(inM,inD,inY,outM,outD,outY);

		if (noDays==-1){
		alert('Check Out Date should be greater than Check In Date     ');
		FillYears();
		}else if (noDays>elements[NON].options.length){
			if (noDays>elements[NON].options.length && noDays<31){
			alert('You can not book '+noDays+' days.\r\n\r\nNumber of days should be maximum of '+elements[NON].options.length+'       ');
			FillYears();
			}else if (noDays>30 && noDays<365){
			alert('You have selected more than '+(Math.ceil(noDays/31)-1)+' month(s).\r\n\r\nNumber of days should be maximum of '+elements[NON].options.length+'       ');
			FillYears();
			}else if (noDays>364){
			alert('You have selected more than '+(Math.ceil(noDays/365)-1)+' year(s).\r\n\r\nNumber of days should be maximum of '+elements[NON].options.length+'       ');
			FillYears();
			}
		}else{
			chk=false;
			if (CurrDday.getFullYear()<selInday.getFullYear()){
			chk=false;
			}else	if (CurrDday.getMonth()<selInday.getMonth()){
			chk=false;
			}else if (CurrDday.getDate()>selInday.getDate()){
			chk=true;
			}	
			if (chk){
			alert('Check In Date should be grater than or equal to current date    ');
			FillYears();
			}else{
			if (navigator.appName.indexOf("Microsoft")>-1 || navigator.userAgent.indexOf("Netscape/7")>-1){
			showWait("searchImg");
			}
MURL="http://www.londonhotelsavings.com/servlet/LondonHotelSavings.ResevationSearch?"+
"&afCd="+document.frm1.afftCode.value+"&afTy="+document.frm1.afftType.value+"&NoRm="+document.frm1.cmbNoOfRooms.options[document.frm1.cmbNoOfRooms.selectedIndex].value+""+
"&NoAd="+document.frm1.cmbNoOfAdults.options[document.frm1.cmbNoOfAdults.selectedIndex].value+"&NoCh="+document.frm1.cmbNoChi.value+""+
"&NoNgt="+document.frm1.cmbNoOfNights.options[document.frm1.cmbNoOfNights.selectedIndex].value+""+
"&mPrD=All&InDt="+document.frm1.cmbCheckInDate.options[document.frm1.cmbCheckInDate.selectedIndex].value+"&InMn="+document.frm1.cmbCheckInMonth.options[document.frm1.cmbCheckInMonth.selectedIndex].value+""+
"&InYr="+document.frm1.cmbCheckInYear.options[document.frm1.cmbCheckInYear.selectedIndex].value+"&OtDt="+document.frm1.cmbCheckOutDate.options[document.frm1.cmbCheckOutDate.selectedIndex].value+""+
"&OtMn="+document.frm1.cmbCheckOutMonth.options[document.frm1.cmbCheckOutMonth.selectedIndex].value+"&OtYr="+document.frm1.cmbCheckOutYear.options[document.frm1.cmbCheckOutYear.selectedIndex].value+""+
"&htCd="+escape(document.frm1.hotelCode.value)+"&amty="+escape(document.frm1.selAmenity.value)+"&mxPv="+document.frm1.maxpPrevalue.value+"&LcD="+escape(document.frm1.cmbLocationDesc.value)+""+
"&Loc="+escape(document.frm1.selLocation.value)+"&rtyD="+document.frm1.cmbRoomTypeDesc.value+"&rmty="+escape(document.frm1.HidRoomType.value)+"&rSc="+rSource+"&vInf="+escape(document.frm1.visitorInfo.value)+""+
"&GrD="+escape(document.frm1.cmbGroupDesc.value)+"&grp="+escape(document.frm1.selGroup.value)+"&GrD="+escape(document.frm1.cmbAmenityDesc.value)+"&catg="+escape(document.frm1.selCategory.value)+""+
"&language=en&country=US&browser=IE";
/*			MURL="http://www.londonhotelsavings.com/servlet/LondonHotelSavings.ResevationSearch?param=SEARCH&AffiliateMainPage="+document.frm1.AffiliateMainPage.value+""+
"&afftCode="+document.frm1.afftCode.value+"&afftType="+document.frm1.afftType.value+"&cmbNoOfRooms="+document.frm1.cmbNoOfRooms.options[document.frm1.cmbNoOfRooms.selectedIndex].value+""+
"&cmbNoOfAdults="+document.frm1.cmbNoOfAdults.options[document.frm1.cmbNoOfAdults.selectedIndex].value+"&cmbNoChi="+document.frm1.cmbNoChi.value+""+
"&cmbNoOfNights="+document.frm1.cmbNoOfNights.options[document.frm1.cmbNoOfNights.selectedIndex].value+"&hidNbHood=-&hidTravelerType=-&startPriceRange=0&endPriceRange=999999"+
"&maxpPrevalueDesc=All&cmbCheckInDate="+document.frm1.cmbCheckInDate.options[document.frm1.cmbCheckInDate.selectedIndex].value+"&cmbCheckInMonth="+document.frm1.cmbCheckInMonth.options[document.frm1.cmbCheckInMonth.selectedIndex].value+""+
"&cmbCheckInYear="+document.frm1.cmbCheckInYear.options[document.frm1.cmbCheckInYear.selectedIndex].value+"&cmbCheckOutDate="+document.frm1.cmbCheckOutDate.options[document.frm1.cmbCheckOutDate.selectedIndex].value+""+
"&cmbCheckOutMonth="+document.frm1.cmbCheckOutMonth.options[document.frm1.cmbCheckOutMonth.selectedIndex].value+"&cmbCheckOutYear="+document.frm1.cmbCheckOutYear.options[document.frm1.cmbCheckOutYear.selectedIndex].value+""+
"&hotelCode="+escape(document.frm1.hotelCode.value)+"&selAmenity="+escape(document.frm1.selAmenity.value)+"&selDiscount1=N&selDiscount2=N&maxpPrevalue="+document.frm1.maxpPrevalue.value+"&selLocationDesc="+escape(document.frm1.cmbLocationDesc.value)+""+
"&selLocation="+escape(document.frm1.selLocation.value)+"&engineType=RES&HidRoomTypeDesc="+document.frm1.cmbRoomTypeDesc.value+"&HidRoomType="+escape(document.frm1.HidRoomType.value)+"&rSource="+rSource+"&visitorInfo="+escape(document.frm1.visitorInfo.value)+""+
"&selGroupDesc="+escape(document.frm1.cmbGroupDesc.value)+"&selGroup="+escape(document.frm1.selGroup.value)+"&selCategoryDesc="+escape(document.frm1.cmbAmenityDesc.value)+"&selCategory="+escape(document.frm1.selCategory.value)+""+
"&language=en&country=US&browser=IE";*/
top.location=MURL;
			}
		}
	}
}

 

function LoadCal(DateType,monthField,dayField,yearField,formName){
dayval=Number(document.forms[formName].elements[dayField].options[document.forms[formName].elements[dayField].selectedIndex].value);
monthval=Number(document.forms[formName].elements[monthField].options[document.forms[formName].elements[monthField].selectedIndex].value);
yearval=Number(document.forms[formName].elements[yearField].options[document.forms[formName].elements[yearField].selectedIndex].value);
window.open("loadDatesIndex.asp?DateType="+DateType+"&formName="+formName+"&DayField="+dayField+"&day="+dayval+"&MonthField="+monthField+"&month="+(Number(monthval)+1)+"&YearField="+yearField+"&year="+yearval+"","calwin","width=235,height=190,top=280,left=100,location=0,status=0");
}

var stp1msg1="Please wait one moment ...";
var stp1msg2="We are checking and retrieving the rates and availability of our hotels";
var dtext;var height11=70;var height12=46;var width11=155;var width12=90;var width21=210;var width22=195;var height21=40;var height22=36;
function getmsg(val){
dtext="<div id='progress' name='progress' style='position:absolute; visibility: hidden; width:"+eval("width2"+val+"")+"px; height:75px; left: 300px; top: 480px;'>"+
"<table width='"+eval("width2"+val+"")+"' height='"+eval("height1"+val+"")+"' cellspacing='0' bgcolor='#000099'><tr><td><table width='100%' height='"+(eval("height1"+val+"")-4)+"' cellspacing='0' bgcolor='#FFFFFF'><tr>"+
"<td align='center'><table width='"+(eval("width2"+val+"")-20)+"'  height='"+eval("height2"+val+"")+"' align='center' cellspacing='0'>";
if (navigator.appName=="Netscape" && navigator.userAgent.indexOf("Netscape/7")==-1){
dtext=dtext+"<tr><td align='center'><b><font color='#000090' face='Arial, Helvetica, sans-serif' style='font-size:12px;'>"+eval("stp"+val+"msg1")+"</font></b></td></tr>";
}else if (navigator.appName=="Netscape" && navigator.userAgent.indexOf("Netscape/7")>-1){
dtext=dtext+"<tr><td align='center'><span style='overflow: hidden;	width: "+eval("width1"+val+"")+"px;	position: relative;'><blink><span style='font-family: Arial, Helvetica, sans-serif;	font-size: 12px;	color: #000090;	font-weight: bold;'>"+eval("stp"+val+"msg1")+"</span></blink></span></td></tr>";
}else{dtext=dtext+"<tr><td align='center'><span style='overflow: hidden;	width: "+eval("width1"+val+"")+"px;	position: relative;'><marquee align='middle' behavior='alternate' scrollamount='400' scrolldelay='180' width='400'><span style='font-family: Arial, Helvetica, sans-serif;	font-size: 12px;	color: #000090;	font-weight: bold;'>"+eval("stp"+val+"msg1")+"</span></marquee></span></td></tr>";}
dtext=dtext+"<tr><td><span style='font-family: Arial, Helvetica, sans-serif;	font-size: 11px;	color: #000090;	text-align: justify;'>";
dtext=dtext+eval("stp"+val+"msg2")+"</span></td></tr></table></td></tr></table></td></tr></table></div>";
if (navigator.appName.indexOf("Microsoft")>-1 || navigator.userAgent.indexOf("Netscape/7")>-1){
document.write(dtext);
}
}

getmsg(1);



function showWait(imgName){
imgtop=0;
imgleft=0;
if(navigator.userAgent.indexOf("Netscape/7")>-1){
imgtop=document.getElementById(imgName).y;
imgleft=document.getElementById(imgName).x;
document.getElementById('progress').style.left=imgleft-90;
document.getElementById('progress').style.top=imgtop+35;
document.getElementById('progress').style.visibility="visible";

}else if (navigator.userAgent.indexOf("MSIE")>-1){
cNode = document.images[imgName]
while(cNode.tagName!='BODY'){ 
imgtop+=cNode.offsetTop; 
imgleft+=cNode.offsetLeft; 
cNode=cNode.offsetParent; 
}
document.all['progress'].style.left=imgleft-90;
document.all['progress'].style.top=imgtop+35;
document.all['progress'].style.visibility="visible";
}
}