
html="";
inclusions=new Array();
rates=new Array();

days=0;
function mm() {
}

// 
function drawRates(x,fr,data) {
	html = "<table cellpadding=0 cellspacing=0 border=0><tr><td id=s4><a href='index.cgi?info=" + x + "'>" + fr + "</a></td>";
	tmp = new Array();
	tmp = data.split("^");
	for (i=0; i!=tmp.length; i++) {
		html+="<td id=s4><a href='index.cgi?info=" + x + "'>" + tmp[i] + "</a></td>";
	}
	html+="</tr></table>";

	document.getElementById("r_"+x).innerHTML=html;
}

dayNames=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
dayNamesShort=new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
monthNames=new Array("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC");

// hotel admin rate editor row
bigHTML="";
function dRE(rm,iDay,iDate,r,a,i,s,h) {

	iDateF=iDate.substr(6,2) + " " + monthNames[iDate.substr(4,2)*1-1] + ", " + iDate.substr(0,4);
	dayName = dayNames[iDay];
	if (iDay==0 || iDay==5 || iDay==6) {
		dayName = "<b>" + dayName + "</b>";
	}

	html="<tr>";
	html+= "<td id=eh>" + dayName + "<br>" + iDateF + "</td>";
	html+= "<td><input type=text size=4 maxlength=9 name='r_" + rm + "_" + iDate + "' value='" + r + "'></td>";
	html+= "<td><textarea cols=60 rows=2 name='i_" + rm + "_" + iDate + "' style='height:35px'>" + i + "</textarea></td>";
	html+= "<td><input type=text size=3 maxlength=5 name='a_" + rm + "_" + iDate + "' value='" + a + "'></td>";
	html+= "<td align=center><input type=button class=button value='COPY' id='bb" + iDate + "' onClick='copyRatesOne(this,"+iDate+","+rm+")'></td>";
	html+= "<td align=center><input type=button class=button value='COPY' id='b" + iDate + "' onClick='copyRates(this,"+iDate+","+rm+")'></td>";
	html+= "<td>" + s + "</td>";
	html+= "<td><input type=checkbox name='ss_" + rm + "_" + iDate + "' value=1 onClick=\"document.form001.a_" + rm + "_" + iDate + ".value=0\"></td>";
	checked="";
	if (h==1) { checked = " checked" }
//	html+= "<td><input type=checkbox name='h_" + rm + "_" + iDate + "' value=1" + checked + "></td>";
	html+= "</tr>";
	html+= "<input type=hidden name='s_" + rm + "_" + iDate + "' value=" + s + ">";
document.write(html);
//	bigHTML+=html;
}

// hotel admin rate editor header
function editorRow() {
	bigHTML="";
	bigHTML += "<tr style='background:#DDDDDD'>";
	bigHTML += "<td><br><b>Day</b><br><br></td>";
	bigHTML += "<td><b>Rate</b></td>";
	bigHTML += "<td><b>Inclusions</b></td>";
	bigHTML += "<td><b>Allotment</b></td>";
	bigHTML += "<td><b>Copy/Paste</b></td>";
	bigHTML += "<td nowrap><b>Copy (Range)</b></td>";
	bigHTML += "<td><b>Sold</b></td>";
	bigHTML += "<td><b>Stop</b></td>";
//	bigHTML += "<td><b>Hot</b></td>";
	bigHTML += "</tr>";
	document.write(bigHTML);
}

copying1=0;
function copyRatesOne(obj,theDate,rm) {
	theForm=document.form001.elements;
	x=theForm.length;
	if (copying1==0) {
		copyDate=theDate;
		obj.style.background='#66AADD';
		for (i=0; i!=x; i++) {
			if (theForm[i].id=="bb"+theDate) {
				copyRate=theForm[i-3].value;
				copyInc=theForm[i-2].value;
				copyAllot=theForm[i-1].value;
				copyStop=theForm[i+2].checked;
				copying1=1;
				break;
			}
		}

		for (i=0; i!=x; i++) {
			if (theForm[i].id!="bb"+theDate) {
				if (theForm[i].id.indexOf("bb")!=-1) {
//					theForm[i].value="PASTE";
					theForm[i].style.background="red";
				}
			}
		}

		alert("Click the red buttons to insert the copied values into dates.\nClick the light blue button when finished.");
	}
	else if (copying1==1) { // go back to normal because original button was clicked again
		if (obj.id=="bb"+copyDate) {
			obj.style.background="#0066CC";
			for (i=0; i!=x; i++) {
				if (theForm[i].style.background=="red") {
					theForm[i].style.background="#0066CC";
//					theForm[i].value="COPY";
				}
			}
			copying1=0;
			return false;
		}
		else {
			for (i=0; i!=x; i++) {
				if (theForm[i].id=="bb"+theDate) {
					theForm[i-3].value=copyRate;
					theForm[i-2].value=copyInc;
					theForm[i-1].value=copyAllot;
					theForm[i+2].checked=copyStop;
					break;
				}
			}
		}
	}
}

copying=0;
function copyRates(obj,theDate,rm) {
	obj.style.background='#66AADD';
	if (copying==0) {
		copyDate1=theDate+"";
		copyDate2="";
		copying=1;
		alert("You have selected this date to copy.\nNow select an end date by clicking on its COPY button.");
	}
	else if (copying==1) {
		copying=2;
		copyDate2=theDate+"";

		niceDate1=copyDate1.substr(6,2) + " " + monthNames[parseInt(copyDate1.substr(4,2))-1] + ", " + copyDate1.substr(0,4);
		niceDate2=copyDate2.substr(6,2) + " " + monthNames[parseInt(copyDate2.substr(4,2))-1] + ", " + copyDate2.substr(0,4);

		if (confirm("You have now selected an end date.\nPlease confirm this date range (" + niceDate1 + " to " + niceDate2 + ") is correct or click Cancel to abort the copy process.")==false) {
			copying=0;
			document.getElementById("b"+copyDate1).style.background="#0066CC";
			document.getElementById("b"+copyDate2).style.background="#0066CC";
		}
		else {
			finish=0;
			for (i=0; i!=document.form001.elements.length; i++) {
				if (document.form001.elements[i].name==("r_"+rm+"_"+copyDate1)) {
					copyRate=document.form001.elements[i].value;
					copyInc=document.form001.elements[i+1].value;
					copyAllot=document.form001.elements[i+2].value;
					copyAllot=document.form001.elements[i+2].value;
					copyStop=document.form001.elements[i+4].checked;
					copying=3;
				}
				else {
					if (copying==3) {
						if (document.form001.elements[i].name.indexOf("r_")!=-1) {
							document.form001.elements[i].value=copyRate;
						}
						else if (document.form001.elements[i].name.indexOf("i_")!=-1) {
							document.form001.elements[i].value=copyInc;
						}
						else if (document.form001.elements[i].name.indexOf("a_")!=-1) {
							document.form001.elements[i].value=copyAllot;
						}
						else if (document.form001.elements[i].name.indexOf("ss_")!=-1) {
							document.form001.elements[i].checked=copyStop;
						}
					}
				}

				if (finish==1) { break }

				if (document.form001.elements[i].name==("r_"+rm+"_"+copyDate2)) {
					document.getElementById("b"+copyDate1).style.background="#0066CC";
					document.getElementById("b"+copyDate2).style.background="#0066CC";
					finish=1;
				}
			}
			copying=0;
		}
	}
}


// track mouse poistion for inclusion
var IE = document.all?true:false

if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;

var tempX = 0
var tempY = 0

function getMouseXY(e) {
	if (IE) {
		tempX = event.clientX + document.body.scrollLeft
		tempY = event.clientY + document.body.scrollTop
	} else {
		tempX = e.pageX
		tempY = e.pageY
	}  
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0}  
	return true
}

// show inclusion popup
function si(x) {
	if (x!=null) {
		if (x=='') { x="Not available for this date." }
		if (x=='X') { x="No inclusions listed." }
		document.getElementById("incDiv").innerHTML=x;
		if (tempX<200) { tempX=200 }
		document.getElementById("incDiv").style.left=tempX-200;
		document.getElementById("incDiv").style.top=tempY+15;
//				document.getElementById("calendar").style.display='none';
		document.getElementById("incDiv").style.display='';
	}
	else {
		document.getElementById("incDiv").style.display='none';
	}
}




// search and info dates headers
counterP=0;
function pH() {
	styling="";
	img="/sbr4/rt_bg_nc.png";
	if (counterP==0) {
		img="/sbr4/rt_bg.png";
	}
	html+="<tr style='background:url(/sbr4/rt_bg_nc.png)'><td colspan=3 style='background:url(" + img + "); padding:8px'><b>" + headerText + "</b></td><td align=right style='padding:0px'>";
	html+="<table cellpadding=0 cellspacing=0 border=0><tr><td id=s4 style='background:url(/sbr4/rt_bg_nc.png); border-left:1px solid #DDDDDD'><b>Full<br>Rate</b></td>";
	styling="";
	for (pi=0; pi!=headerDates.length; pi++) {
		tmpP = new Array();
		tmpP = headerDates[pi].split("-");
		img="/sbr4/rbg.png";
		if (pi==(headerDates.length-1) && counterP==0) {
			img="/sbr4/rbg_c.png";
		}
		html += "<td style='border-left:1px solid gold; background:url("+img+")' id=s4h" + styling + "><b>" + dayNamesShort[tmpP[0]] + "</b><br>" + tmpP[1] + "/" + tmpP[2] + "</td>";
	}
	html+="</tr></table>";
	html+="</td></tr>";
	counterP++;
}

hotelTypes=new Array("Hotel/Motel","Serviced Apartment","Private Hotel/B&B/Guest House","Self-contained Cottage/Cabin","Holiday apartment/Condo/Villa","Resort");

// search results rate result
function sR(sortKey,index,hotel,rating,fr,r,i,l,t,ll,sr,rt) {
//alert(i);
	rates=new Array();
	rates=r.split("-");
	incs=new Array();
	incs=i.split("^");
	if (window.location.href.indexOf('localhost')!=-1) {
		link = "index.cgi?info=" + index + "&da=" + days + "&we=" + we;
	}
	else {
		hotelName=hotel;
		hotelName = hotelName.replace(/ /g,"-");
		hotelName = hotelName.replace(/'/g,"");
		hotelName = hotelName.replace(/"/g,"");
		hotelName = hotelName.replace(/&/g,"");
		link = "/hotel/" + hotelName.toLowerCase() + "/" + index + "/" + days + "/" + we;
	}

	if (sr==0) {
		ratingG = "stars_" + rating + ".png";
		ratingT="rated " + rating+" stars";
	}
	else {
		ratingG = "circle_" + rating + ".png";
		ratingT="rated " + rating + " (self rated)";
	}

	html+="<tr onmouseover=\"this.style.background='#DFDFF0'\" onmouseout=\"this.style.background='#F0F2F5'\"><td colspan=2 style='border-left:1px solid #D9AD00; border-bottom:1px solid #DDDDDD; padding-left:8px; width:100%'>";
	html+="<a href='" + link + "' onmouseover='si(\"" + l + "<br>(" + hotelTypes[t] + ")\")' onmouseout='si()' style='font-size:11px'>" + hotel + "</a><br>";
	html+="<a href='javascript:showList(1," + index + ")'><img src='/sbr4/compare.png' border=0 title='click to add this hotel to your comparison list'></a>";
	html+= "<img src='/sbr4/" + ratingG + "' alt='" + ratingT + "'>";
	html+="</td><td align=right nowrap style='padding-right:8px; border-bottom:1px solid #DDDDDD'><a href='" + link + "'><img src='/sbr4/button_next.png' border=0 alt='next - view hotel info and book now '></a></td><td align=right>";
	html+="<table cellpadding=0 cellspacing=0 border=0 width=690 id=rt><tr>";
	html+= "<td id=s4 style='border-bottom:1px solid #DADADA' onmouseover='si(\"<b>Full rates for room types:</b><br>" + rt + "\")' onmouseout='si()'>" + parseInt(fr) + "</td>";
	for (i=0; i!=14; i++) {
		link1="<a href='" + link +"'>";link2="</a>";
		if (rates[i]==0) { rates[i]="SOLD"; link1=''; link2=''; inc='' }
		else {
			inc=incs[i];
			if (inc != "X") {
				if (!isNaN(inc)) {
					inc=incs[inc];
				}
			}
		}
		styling="";
		if (rates[i] != 0 && inc!="X") { styling="background:#94C2Ed" }
		if (rates[i] == "SOLD") { styling="background:url(/sbr4/sold.png)"; rates[i]="&nbsp;" }
		if (i==13) { styling+="; border-right:1px solid #D9AD00;" }
		html+="<td id=s4 onmouseover='si(\"" + inc + "\")' onmouseout=\"si()\" style='border-bottom:1px solid #DADADA; border-left:1px solid #DADADA; " + styling + "'>" + link1 + rates[i] + link2 + "</td>";
	}
	html+="</tr></table>";
	html+="</td></tr>";
}

// info page rates result
function iR(index,room,desc,info,fr,r,i) {
	rates=new Array();
	rates=r.split("-");
	incs=new Array();
	incs=i.split("^");
	if (window.location.href.indexOf("localhost")!=-1) {
		link = "index.cgi?book=" + index + "&da=" + days +"&we="+we;
	}
	else {
		link = "https://www.standbyrates.com.au/index.cgi?book=" + index + "&da=" + days +"&we="+we;
	}
	html+="<tr onmouseover=\"this.style.background='#DFDFF0'\" onmouseout=\"this.style.background='#F0F2F5'\"><td colspan=2 style='background:white; border-left:1px solid #D9AD00; xborder-bottom:1px solid #DDDDDD; padding-left:8px; width:100%'><a href='" + link + "'><font size=2><b>" + room + "</b></font></a></td><td align=right nowrap style='background:white; padding-right:8px'><a href='" + link + "'><img src='/sbr4/button_book_now.png' border=0 alt='book now'></a></td><td align=right>";
	html+="<table cellpadding=0 cellspacing=0 border=0 width=690 id=rt><tr>";
	html+= "<td id=s4 style='border-bottom:1px solid #DADADA; border-left:1px solid #DADADA'>" + parseInt(fr) + "</td>";
	for (i=0; i!=14; i++) {
		link1="<a href='" + link +"'>";link2="</a>";
		if (rates[i]==0) { rates[i]="SOLD"; link1=''; link2=''; inc='' }
		else {
			inc=incs[i];
			if (inc != "X") {
				if (!isNaN(inc)) {
					inc=incs[inc];
				}
			}
		}
		styling="";
		if (rates[i] != 0 && inc!="X") { styling="background:#94C2Ed" }
		if (rates[i] == "SOLD") { styling="background:url(/sbr4/sold.png)"; rates[i]="&nbsp;" }
		if (i==13) { styling+="; border-right:1px solid #D9AD00;" }
		html+="<td id=s4 onmouseover='si(\"" + inc + "\")' onmouseout=\"si()\" style='border-bottom:1px solid #DADADA; border-left:1px solid #DADADA; " + styling + "'>" + link1 + rates[i] + link2 + "</td>";
	}
	html+="</tr></table>";
	html+="</td></tr>";
	html+="<tr><td colspan=4 style='background:white; border-left:1px solid #D9AD00; border-right:1px solid #D9AD00; border-bottom:1px solid #DDDDDD; padding-left:8px'><!--<div style='float:right; padding:6px'><a href='" + secureLink + "index.cgi?offer=" + index + "'><img src='/sbr4/button_make_an_offer.png' border=0 alt='Make an Offer'></a></div>--><font size=1>Description: " + desc + "<br>" + info + "</font><br></td></tr>";
	html+="<tr><td colspan=10 style='border-left:1px solid #D9AD00; border-right:1px solid #D9AD00; background:white; height:8px; padding:0px'><font size=1>&nbsp;</font></td></tr>";
	html+="<tr><td colspan=10 style='background:#AAAAAA; height:1px; padding:0px'></td></tr>";
}

// booking dates rates
function bR(index,room,desc,info,fr,r,i,remain) {
	rates=new Array();
	rates=r.split("-");
	incs=new Array();
	incs=i.split("^");
	remain2=new Array();
	remain2=remain.split("^");
//	link = "index.cgi?book=" + index;
	html+="<tr>";
	for (i=0; i!=28; i++) {
//		link1="<a href='" + link +"'>";link2="</a>";
		if (rates[i]==0) { rates[i]="SOLD"; inc='' }
		else {
			inc=incs[i];
			if (inc != "X") {
				if (!isNaN(inc)) {
					inc=incs[inc];
				}
			}
		}
		styling="";
		if (rates[i] != 0 && inc!="X") { styling="background:#94C2Ed" }
		if (rates[i] == "SOLD") { styling="background:url(/sbr4/sold.png); background-position:center"; rates[i]="&nbsp;" }
		if (i==27) { styling+="; border-right:1px solid #D9AD00;" }
		else if (i==0) { styling+="; border-left:1px solid #D9AD00;" }
		else { styling+="; border-left:1px solid #DDDDDD" }
		if (rates[i]!="&nbsp;") {
			theRate=Math.ceil(rates[i]*(1-(commission*0.01)));
		}
		else {
			theRate="";
		}
		html+="<td id=b4 onmouseover='si(\"" + inc + "\")' onmouseout=\"si()\" style='border-bottom:1px solid #DADADA; border-left:1px solid #DADADA; " + styling + "'>" + theRate + "</td>";
	}

	html+="</tr>";
	html+="<tr>";
	for (pi=0; pi!=headerDates.length; pi++) {
		tmpP = new Array();
		tmpP = headerDates[pi].split("-");
		if (pi==0) { styling="border-left:1px solid gold" }
		else if (pi==27) { styling="border-right:1px solid gold" }
		else { styling="border-left:1px solid #DDDDDD" }
		theName = tmpP[3] + tmpP[2] + tmpP[1];
		inc=incs[pi]=inc=incs[pi].replace(/"/g,"");
		inc=incs[pi]=inc=incs[pi].replace(/'/g,"");
		checked="";
		for (i=0; i!=bookingDates.length; i++) {
			tmp = new Array();
			tmp = bookingDates[i].split("^");
			if (tmp[0]==theName) {
				checked=" checked";
				break;
			}
		}
		if (rates[pi]=="&nbsp;") {
			html += "<td id=cb style='" + styling + "; border-bottom:1px solid gold'>&minus;</td>";
		}
		else {
//			theRate=theRate=Math.ceil(rates[pi]*(1-(commission*0.01)));
			theRate=rates[pi];
			html += "<td id=cb style='" + styling + "; border-bottom:1px solid gold'><input type=checkbox name='" + theName + "' value=1 onClick=\"addDate(this.name,'" + incs[pi] + "',"+theRate+","+tmpP[0]+","+remain2[pi] + ")\" "+ checked + "></td>";
		}

	}
	html+="</tr>";
}

// booking dates table header
function bpH() {
	styling="";
	img="/sbr4/rt_bg_nc.png";
	if (counterP==0) {
		img="/sbr4/rt_bg.png";
	}
	html+="<tr>";
	for (pi=0; pi!=headerDates.length; pi++) {
		tmpP = new Array();
		tmpP = headerDates[pi].split("-");
		styling = "border-left:1px solid gold; background:url(/sbr4/rbg.png)";
		if (pi==0) {
			styling = "background:url(/sbr4/rbg_cl_bk.png); background-position:top left; background-repeat:no-repeat";
		}
		else if (pi==(headerDates.length-1)) {
			styling = "border-left:1px solid gold; background:url(/sbr4/rbg_cr_bk.png); background-position:top right; background-repeat:no-repeat";
		}
//styling="";
		html += "<td style='" + styling + "' id=b4h><font size=1><b>" + dayNamesShort[tmpP[0]] + "</b></font><br>" + parseInt(tmpP[1]*1) + "<br><font size=1>" + months2[parseInt(tmpP[2]*1)-1] + "</font></td>";
	}
	html+="</tr>";
	counterP++;
}


var xmlhttp;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
	xmlhttp = new ActiveXObject( 'Msxml2.XMLHTTP' );
} catch (e) {
	try {
		xmlhttp = new ActiveXObject( 'Microsoft.XMLHTTP' );
		} catch (E) {
		xmlhttp = false;
	}
}
@else
	if (
	!xmlhttp && document.createElement ) {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp = false;
	}
}@end @*/

if ( !xmlhttp && document.createElement ) {
	xmlhttp = new XMLHttpRequest();
}

// next / prev 14 buttons pressed - search and info screens
we=0;
function moveRates(d) {
	document.getElementById('srr').innerHTML="<img src='/sbr4/loading.gif'>";

	if (d!=-1) {
		days+=d;
	}
	else {
		we=1;
	}

	if (window.location.href.indexOf("localhost")!=-1) {
		url2 = "http://localhost/cgi-bin/sbr4/index.cgi?" + command + "&d=" + days + "&we=" + we + "&loc=" + country + "^" + city + "^" + loc + "&k=" + escape(keywords) + "&sort="+searchMode+"&sl="+shortList+"&ga="+gaCookie+"&popup=1";
	}
	else {
		url2 = "http://www.standbyrates.com.au/index.cgi?" + command + "&d=" + days + "&we=" + we + "&loc=" + country + "^" + city + "^" + loc + "&k=" + escape(keywords) + "&sort="+searchMode+"&sl="+shortList+"&ga="+gaCookie+"&popup=1";
	}
//alert(url2);
	var now = new Date(), txt, url = url2;
//document.write(url2);return false;
	if( url ) {
		xmlhttp.open( 'GET', url, true );
		xmlhttp.onreadystatechange = function() {
			if ( xmlhttp.readyState===4 ) {
				txt = xmlhttp.responseText;
//alert(txt);
				tmp = new Array();
				tmp = txt.split("{");
//if (searchMode!=-1) {
//	tmp=tmp.sort();
//}
				headerDates=new Array();
				tmp[0]=tmp[0].replace(/'/g,"");
				headerDates=tmp[0].split("^");
				counter=0;
				counterP=0;
//alert(tmp[1]);
				html="";
				for (i=1; i!=tmp.length-1; i++) {
					if (counter==0) {
						pH();
					}
					if (tmp[i]!="") {
						tmp2=new Array();
						tmp2=tmp[i].split("}");
						if (command=="search") {
							sR(tmp2[0],tmp2[1],tmp2[2],tmp2[3],tmp2[4],tmp2[5],tmp2[6],tmp2[7],tmp2[8],tmp2[9],tmp2[10],tmp2[11]);
						}
						else {
							iR(tmp2[0],tmp2[1],tmp2[2],tmp2[3],tmp2[4],tmp2[5],tmp2[6]);
						}
					}
					counter++;
					if (counter==10) { counter=0 }
				}
				html="<table width=100% cellpadding=0 cellspacing=0 border=0 bgcolor=#F0F2F5 id=srt>" + html + "<tr><td colspan=3 style='border:none; height:10px; background:#D9AD00 url(/sbr4/blc.png) no-repeat bottom left'><br></td><td style='border:none; background:#D9AD00 url(/sbr4/brc.png) no-repeat bottom right'></td></tr></table>";
				document.getElementById('srr').innerHTML=html; html="";
			} 
		}
		xmlhttp.send( null );
	}
}

// next / prev 14 buttons pressed - booking screen
function moveRatesB(d,room) {
	document.getElementById('srr').innerHTML="<img src='/sbr4/loading.gif'>";

	if (d!=-1) {
		days+=d;
	}
	else {
		we=1;
	}

	if (window.location.href.indexOf("localhost")!=-1) {
		url2 = "http://localhost/cgi-bin/sbr4/index.cgi?" + command + "=" + room + "&d=" + days + "&we=" + we + "&loc=" + country + "^" + city + "^" + loc + "&popup=1";
	}
	else {
		url2 = "http://www.standbyrates.com.au/index.cgi?" + command + "=" + room + "&d=" + days + "&we=" + we + "&loc=" + country + "^" + city + "^" + loc + "&popup=1";
	}

	var now = new Date(), txt, url = url2;
//document.write(url2);return false;
	if( url ) {
		xmlhttp.open( 'GET', url, true );
		xmlhttp.onreadystatechange = function() {
			if ( xmlhttp.readyState===4 ) {
				txt = xmlhttp.responseText;
				tmp = new Array();
				tmp = txt.split("{");
				headerDates=new Array();
				tmp[0]=tmp[0].replace(/'/g,"");
				headerDates=tmp[0].split("^");
				counter=0;
				counterP=0;
				html="";
				bpH();
				if (tmp[1]!="") {
					tmp2=new Array();
					tmp2=tmp[1].split("}");
					bR(tmp2[0],tmp2[1],tmp2[2],tmp2[3],tmp2[4],tmp2[5],tmp2[6],tmp2[7]);
				}
				html="<table width=100% cellpadding=0 cellspacing=0 border=0>" + html + "</table>";
				document.getElementById('srr').innerHTML=html; html="";
			} 
		}
		xmlhttp.send( null );
	}
}

// build calendars
calendarMade=0;
cDays=new Array("S","M","T","W","T","F","S");
cDays3=new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
months=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
months2=new Array("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC");
cDays2=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
function chooseDate() {

	if (calendarMade==0) {

		calStart = new Date();
		month = calStart.getMonth();
		curCal=month;
		year = calStart.getFullYear();
		mm=month;
		html = "<table cellpadding=4 cellspacing=0 border=0>";
		if (command!="offer") {
			html += "<tr><td colspan=12 bgcolor=white style='border:1px solid black' align=center><font size=1><b>PICK YOUR START DATE</b></font></td></tr><tr valign=top>";
		}

		for (i=month; i!=(month+13); i++ ) {

			if (mm==12) { mm=0; year++ }

			today = new Date();
			calStart = new Date(year,mm,1);

			if (year%4 == 0) {
				if (year%100 != 0) {
					cDays2[1]=29;
				}
				else {
					if (year%400 == 0) {
						cDays2[1]=29;
					}
				}
			}

			startDay=calStart.getDay();

			html += "<td width=200 height=150 id=mc" + i + " align=center style='border:1px solid black; display:none; background:#DADADA'><font size=1><b>" + months[mm].toUpperCase() + " " + year + "</font></b><br><table cellpadding=2 cellspacing=1 border=0><tr><td bgcolor=white><a href='#' onClick='moveCal(-1);return false'><img src='/sbr4/calendar_left.gif' border=0 alt='previous month'></a></td>";
			for (ii=0; ii!=7; ii++ ) {
				html += "<td align=center bgcolor=white>" + cDays[ii] + "</td>";
			}
			html += "<td bgcolor=white><a href='#' onClick='moveCal(1);return false'><img src='/sbr4/calendar_right.gif' border=0 alt='next month'></a></td></tr>";

			counter=0;
			html+="<tr><td bgcolor=white>&nbsp;</td>";
			leading=0;
			for (ii=0; ii!=startDay; ii++) {
				html += "<td bgcolor=white>&nbsp;</td>";
				counter++;
				leading++;
			}
			for (ii=0; ii!=cDays2[mm]; ii++) {
				if (counter==0 && leading!=0) { html+="<tr><td bgcolor=white>&nbsp;</td>" }
				if (command=="offer") {
					html += "<td align=center bgcolor=#F0F0F0 onmouseover=\"this.style.background='white'\" onmouseout=\"this.style.background='#F0F0F0'\" style='cursor:pointer' onClick='changed=1;setOfferCheckin(" + year + "," + (mm+1) + "," + ii + "," + counter + ")'>" + (ii+1) + "</td>";
				}
				else {
					html += "<td align=center bgcolor=#F0F0F0 onmouseover=\"this.style.background='white'\" onmouseout=\"this.style.background='#F0F0F0'\" style='cursor:pointer' onClick='getDays(" + year + "," + (mm+1) + "," + ii + "," + counter + ")'>" + (ii+1) + "</td>";
				}
				counter++;
				if (counter==7) { counter=0; html+="<td bgcolor=white>&nbsp;</td></tr>"; leading=1 }
			}

			if (counter!=0) {
				for (ii=0; ii!=7-counter; ii++) {
					html += "<td bgcolor=white>&nbsp;</td>";
				}
				html+="<td bgcolor=white>&nbsp;</td>";
			}
			html+="</tr></table>";

			html+="</td>";
			mm++;
		}

		if (window.location.href.indexOf("offer")==-1) {
			html += "</tr><tr><td colspan=12 bgcolor=white style='border:1px solid black'><p align=center><a href='' onClick=\"document.getElementById('calendar').style.display='none'; return false\"><FONT SIZE=1><b>CLOSE CALENDAR</b></font></a></p></td></tr></table>";
		}
	}

	if (command=="offer") {
		document.getElementById("calendar2").innerHTML=html;
	}
	else {
		document.getElementById("calendar").innerHTML=html;
		document.getElementById("calendar").style.display='';
	}

	if (window.location.href.indexOf("search")!=-1) {
		document.getElementById("calendar").style.left=tempX-250;
		document.getElementById("calendar").style.top=tempY-100;
	}
	else {
		document.getElementById("calendar").style.left=tempX;
		document.getElementById("calendar").style.top=tempY-100;
	}
	document.getElementById("mc" + month).style.display='';
}

// move the calendar month
function moveCal(x) {
	calStart = new Date();
	month = calStart.getMonth();
	if ((curCal+x) < month) { return false }
	if ((curCal+x) > (month+12)) { return false }
	for (i=month; i!=(month+13); i++) {
		document.getElementById("mc" + i).style.display='none';
	}
	curCal+=x;
	document.getElementById("mc" + curCal).style.display='';
}

// get days between two dates
selYear=0;
selMonth=0;
selDate=0;
daysAhead=0;
command="";
function getDays(y,m,d,dd) {

	var current_date = new Date()
	current_date.setHours(0)
	current_date.setMinutes(0)

	var new_years_date = new Date()
	new_years_date.setYear(y)
	new_years_date.setMonth(m-1)
	new_years_date.setDate(d+1)
	new_years_date.setHours(0)
	new_years_date.setMinutes(0)

	// Call the days_between function
	plusDays=days_between(current_date, new_years_date);
	if (plusDays<0) {
		alert("You must select a day in the next 365 days.");
		plusDays=0;
	}

	selYear=y;
	selMonth=m;
	selDate=d+1;

	calStart = new Date();
	month = current_date.getMonth()+1;
	year = current_date.getFullYear();
	date = current_date.getDate();
	one = (365*year) + parseInt(year/4) - parseInt(year/100) + parseInt(year/400) + date + parseInt((153*month+8)/5);
	two = (365*selYear) + parseInt(selYear/4) - parseInt(selYear/100) + parseInt(selYear/400) + selDate + parseInt((153*selMonth+8)/5);

	if (command=="search" || command.indexOf("info=")!=-1) {
		days=0;
		moveRates(plusDays);
	}
	else {
		document.getElementById("theDate").innerHTML=cDays3[dd] + " " + selDate + " " + months[selMonth-1] + " " + selYear;
		daysAhead=plusDays;
	}
	document.getElementById("calendar").style.display='none';
}

// booking screen select date function
extraGuests=0;
bookingDates=new Array();
function addDate(ddd,inc,rate,wday,remain) {
	if (ddd!=-1) {
		add=-1;
		if (bookingDates.length!=0) {
			for (i=0; i!=bookingDates.length; i++) {
				tmp = new Array();
				tmp = bookingDates[i].split("^");
				if (tmp[0]==ddd) {
					add=i;
				}
			}
		}

		if (add==-1) {
			bookingDates[bookingDates.length]=ddd+"^"+inc+"^"+rate+"^"+wday+"^"+remain+"^"+1;
		}
		else {
			bookingDates.splice(add,1);
		}

		bookingDates=bookingDates.sort();
	}

	if (bookingDates.length!=0) {
		totalRooms=0;
		total=0;
		totalO=0;
		total2=0;
		adjustedTotal=0;
		html="<table width=99% cellpadding=4 cellspacing=0 border=0 id=btt><tr valign=bottom style='background:#CCCCCC'><td align=center width=75 nowrap><b>Date</b></td><td width=75 nowrap align=center><b>Rate</b></td><td width=75 nowrap><b># Rooms</b></td><td width=100%><b>Inclusions</b></td></tr>";
		bookingString="";
		for (i=0; i!=bookingDates.length; i++) {
			tmp = new Array();
			tmp = bookingDates[i].split("^");
//			theRate=Math.ceil(tmp[2]*(1-(commission*0.01)));;
//			theRate=Math.ceil(tmp[2]*(1-(commission*0.01)));
			theRate=tmp[2];
			adjustedRate=Math.ceil(tmp[2]*(1-(commission*0.01)));
			html+="<tr style='background:white'><td align=center>" + cDays3[tmp[3]*1] + "<br>" + tmp[0].substr(6,2) + "<br>" + months2[(tmp[0].substr(4,2)*1)-1] + "</td><td align=center>" + symbol + adjustedRate + "</td><td><select name='q_"+i+"' onChange='addQty(this," + tmp[2] + ","+i+")'>";
			for (ii=0; ii!=tmp[4]; ii++) {
				selected="";
				if (tmp[5]==(ii+1)) { selected=" selected" }
				html+="<option value=" + (ii+1) + selected + ">" + (ii+1);
			}
			if (tmp[1] == "X") { tmp[1] = "No inclusions." }
			html+="</select></td><td width=100%>" + tmp[1] + "</td></tr>";
			total+=tmp[2]*tmp[5];
			totalRooms+=tmp[5]*1;
			adjustedTotal+=adjustedRate*tmp[5];
			total2+=tmp[2]*1;
			bookingString+=tmp[0]+"}"+adjustedRate+"}"+tmp[2]+"}"+tmp[1]+"}"+tmp[5]+"{";
		}
		extraGuestsT=(totalRooms*extraGuests)*guestsCost;

		html+="<tr style='background:#FAFAFA'><td colspan=2>&nbsp;</td><td colspan=2>";
		if (guestsMax==0 || guestsCost==0) {
			html+="Extra guests cannot be accommodated in this room.";
		}
		else {
			html+="<select name=bookingGuestsExtra onChange='extraGuests=this.selectedIndex; addDate(-1)'>";
			for (i=0; i!=guestsMax+1; i++) {
				selected="";
				if (extraGuests==i) { selected=" selected" }
				html+="<option value="+i+selected+">"+i;
			}
			html+="</select>";
			html+=" extra guests at <b>" + symbol + guestsCost.toFixed(2) + "</b> each per night. This room allows a maximum of <b>" + guestsMax + "</b> extra guest(s).";
		}

//window.status=totalO;
//		adjustedTotal=total2;
		if (depositPerc==1) {
			payableToHotel = Math.ceil(adjustedTotal*depositPerc);
		}
		else {
			payableToHotel = total*depositPerc;
		}
//alert(payableToHotel);
//		deposit = ( adjustedTotal - payableToHotel);
//		deposit = adjustedTotal * (0.01*commission);
//		deposit = total*0.1;
//		deposit=Math.ceil(deposit*(commission*0.1));
		deposit = adjustedTotal - payableToHotel;
		payableToHotel += extraGuestsT*depositPerc;
		if (depositPerc!=1) {
			deposit+=(extraGuestsT*0.1);
		}
		adjustedTotal+=extraGuestsT;

//		newTotal = (deposit+bookingFee+payableToHotel).toFixed(2);

		document.form001.iG1.value=bookingString;
		document.form001.bookingExtraGuests.value=extraGuests;

		document.form001.bookingTotal.value=adjustedTotal.toFixed(2);
		document.form001.bookingCommission.value=commission;
		document.form001.bookingBookingFee.value=bookingFee.toFixed(2);
		document.form001.bookingDeposit.value=deposit.toFixed(2);
		document.form001.bookingPayable.value=payableToHotel.toFixed(2);

		html+="</td></tr>";
		html+="<tr style='background:#EAEAEA'><td>&nbsp;</td><td align=center><b>" + symbol + "<span id=theTotal>" + adjustedTotal.toFixed(2) + "</span></b></td><td colspan=2><b>Accommodation Total (Standby Rate)</b></td></tr>";
		html+="<tr style='background:#EAEAEA'><td>&nbsp;</td><td align=center>" + symbol + "<span id=theDeposit>" + deposit.toFixed(2) + "</span></td><td colspan=2><b><!--" + (10-commission) + "% -->Deposit</b></td></tr>";
		html+="<tr style='background:#EAEAEA'><td>&nbsp;</td><td align=center>" + symbol + bookingFee.toFixed(2) + "</td><td colspan=2><b>Booking Fee</b></td></tr>";
		html+="<tr style='background:#EAEAEA'><td>&nbsp;</td><td align=center><font color=red><b>" + symbol + "<span id=thePayable>" + (deposit+bookingFee).toFixed(2) + "</span></b></font></td><td colspan=2><font color=red><b>Payable Now</b> (non-refundable)</font></td></tr>";
		html+="<tr style='background:#EAEAEA'><td>&nbsp;</td><td align=center><b>" + symbol + "<span id=theBalance>" + payableToHotel.toFixed(2) + "</span></b></td><td colspan=2><b>Balance Payable to Hotel</b></td></tr>";
		html+="</table>";
	}
	else {
		html="";
		document.form001.iG1.value="";
	}

	document.getElementById('bd').innerHTML=html;
}

// adjust qty of selected booking date
function addQty(obj,rate,element) {
	qty = obj.options[obj.selectedIndex].value*1;
	tmp = new Array();
	tmp = bookingDates[element].split("^");
	bookingDates[element]=tmp[0]+"^"+tmp[1]+"^"+tmp[2]+"^"+tmp[3]+"^"+tmp[4]+"^"+qty;
	addDate(-1);
}

y1=0;m1=0;d1=0;w1=0;
y2=0;m2=0;d2=0;w2=0;

// find the check-in date of an offer
plusDays=0;
function setOfferCheckin(y,m,d,dd) {

	var current_date = new Date()
	current_date.setHours(0)
	current_date.setMinutes(0)

	var new_years_date = new Date()
	new_years_date.setYear(y)
	new_years_date.setMonth(m-1)
	new_years_date.setDate(d+1)
	new_years_date.setHours(0)
	new_years_date.setMinutes(0)

	// Call the days_between function
	plusDays=days_between(current_date, new_years_date);
	if (plusDays<0) {
		alert("You must select a day in the next 365 days.");
		plusDays=0;
	}
}

// calculate the days between two dates
function days_between(date1, date2) {

    // The number of milliseconds in one day
    var ONE_DAY = 1000 * 60 * 60 * 24

    // Convert both dates to milliseconds
    var date1_ms = date1.getTime()
    var date2_ms = date2.getTime()

	return Math.round( (date2_ms-date1_ms)/ONE_DAY);

}

// draw selected nights for the offer screen
nights=0;
changed=0;
enteredRates=new Array();
function doOfferDates() {
	nights=document.form001.offerNights.selectedIndex;

	myDate=new Date();
	myDate.setDate(myDate.getDate()+(plusDays));
	m = myDate.getMonth()+1;
	y = myDate.getFullYear();
	d = myDate.getDate();
	w = myDate.getDay();

	myDate=new Date();
	myDate.setDate(myDate.getDate()+(nights+plusDays));
	m2 = myDate.getMonth()+1;
	y2 = myDate.getFullYear();
	d2 = myDate.getDate();
	w2 = myDate.getDay();

//	if (wdayO!="") {
		document.getElementById("dateSpan").innerHTML=cDays3[w] + " " + (d) + " " + months[m-1] + ", " + y;
//	}
	if (nights!=0 && plusDays>-1) {
		document.getElementById("dateSpan2").innerHTML="<b>Checkout:</b> " + cDays3[w2] + " " + d2 + " " + months[m2-1] + ", " + y2;
		if (changed==1) {
			changed=0;
			html="<table cellpadding=4 cellspacing=0 border=0 id=rows width=490><tr><td align=center><b>Date</b></td><td><b>My Offer</b></td><td><b>Standard Inclusions</b></td></tr>";
			bookingDates=new Array();
			enteredRates2=new Array();
			counter=0;
			for (i=0; i!=(plusDays+nights); i++) {
				if (i>=plusDays) {
					myDate=new Date();
					myDate.setDate(myDate.getDate()+(i));
					selMonthO = myDate.getMonth()+1;
					selYearO = myDate.getFullYear();
					selDateO = myDate.getDate();
					selWdayO = myDate.getDay();
					incDetails = new Array();
					incDetails = offerIncs2[selWdayO].split("}");
//					if (enteredRates[i]==null) { enteredRates[i]="" }
					html+="<tr valign=top><td align=right width=150 nowrap>" + cDays3[selWdayO] + " " + selDateO + " " + months[selMonthO-1] + ", " + selYearO + " \$</td><td width=1% nowrap><input type=text name='r_"+i+"' size=9 maxlength=9 onKeyUp='enteredRates["+counter+"]=this.value' value='" + enteredRates[counter] + "'></td><td>" + incDetails[2] + "</td></tr>";
					bookingDates[bookingDates.length] = selDateO+"}"+selMonthO+"}"+selYearO + "}" + incDetails[2];
					counter++;
				}
			}
			html+="<tr valign=top><td align=right><font color=red><b>My Total Offer</b></font></td><td width=1% nowrap>\$<span id=offerTotal></span></td><td>&nbsp;</td></tr>";
			html+="<tr valign=top><td align=right><b>10% Deposit</b></td><td width=1% nowrap>\$<span id=offerDeposit></span></td><td>&nbsp;</td></tr>";
			html+="<tr valign=top><td align=right><b>Booking Fee</b></td><td width=1% nowrap>\$<span id=offerBookingFee></span></td><td>&nbsp;</td></tr>";
			html+="<tr valign=top><td align=right><b>Total</b></td><td width=1% nowrap>\$<span id=offerGrandTotal></span></td><td>&nbsp;</td></tr>";
			html+="<tr valign=top><td align=right><font color=red><b>Balance Payable to Hotel</b></font></td><td width=1% nowrap>\$<span id=offerPayable></span></td><td>&nbsp;</td></tr>";
			html+="</table><br><b>Enter whole dollar amounts only.</b><br>";
			document.getElementById("rates").innerHTML=html;
		}

		data="";
		for (i=0; i!=bookingDates.length; i++) {
			data+=bookingDates[i]+"{";
		}
		document.form001.iG7.value=data;
		data="";
		for (i=0; i!=enteredRates.length; i++) {
			if (enteredRates[i]==null) {
				data+=0+"{";
			}
			else {
				data+=enteredRates[i]+"{";
			}
		}
		document.form001.iG6.value=data;

	}
	else {
		document.getElementById("dateSpan2").innerHTML="";
		document.getElementById("rates").innerHTML="<b>To Begin:</b> Please select the start date and number of nights on the left.";
	}

	theTotal=0;
	obj = document.form001;
	for (i=0; i!=obj.elements.length; i++) {
		if (obj.elements[i].name.indexOf("r_")!=-1) {
			if (isNaN(obj.elements[i].value*1)) {
				obj.elements[i].value="";
			}
			if (obj.elements.value*1==0) {
				obj.elements.value="";
			}
			theTotal+=obj.elements[i].value*1;
		}
	}

	if (document.getElementById("offerTotal")) {
		deposit = (theTotal*0.1).toFixed(2);
		document.getElementById("offerTotal").innerHTML=theTotal.toFixed(2);
		document.getElementById("offerDeposit").innerHTML=deposit;
		document.getElementById("offerBookingFee").innerHTML=bookingFee.toFixed(2);
		document.getElementById("offerGrandTotal").innerHTML=((bookingFee*1)+(deposit*1)).toFixed(2);
		document.getElementById("offerPayable").innerHTML=(theTotal-deposit).toFixed(2);
	}

}

// validate booking fields
function checkFields() {

	if (!document.form001.terms.checked) {
		alert("You must agree to the Terms and Conditions by ticking the I Agree checkbox.");
		return false;
	}

	if (bookingDates.length<minStay) {
		alert("This room type requires a minimum stay of " + minStay + " night(s).");
		return false;
	}

	if (document.form001.iG1.value.length==0) {
		alert("You must select at least one date for your booking.");
		return false;
	}

	fields=new Array("Firstname","Lastname","Email","Email2","Phone","ETA");
	for (i=0; i!=fields.length; i++) {
		obj = eval("document.form001.booking" + fields[i]);
		if (obj.value.length==0) {
			alert("Please complete all the mandatory fields before proceeding.");
			return false;
		}
	}

	if (document.form001.iG2.value.length==0 || document.form001.iG3.value.length==0) {
		alert("Please complete your payment details before proceeding.");
		return false;
	}

	if (document.form001.iG4.selectedIndex==0 || document.form001.iG5.selectedIndex==0) {
		alert("Please complete your payment details before proceeding.");
		return false;
	}

//	if (document.form001.bookingGuestsAdult.selectedIndex==0) {
//		alert("Please complete all the mandatory fields before proceeding.");
//		return false;
//	}

	if (document.form001.bookingEmail.value.indexOf("@")==-1 || document.form001.bookingEmail.value.indexOf(".")==-1) {
		alert("Please ensure you enter a valid Email Address.");
		return false;
	}

	if (window.location.href.indexOf("localhost")==-1) {
		if (document.form001.bookingEmail.value!=document.form001.bookingEmail2.value) {
			alert("Your second entered Email Address does not match your first.");
			return false;
		}
	}

	if (isNaN(document.form001.iG3.value) || document.form001.iG3.value.length<14) {
		alert("You must enter your numerical credit card number.");
		return false;
	}

	if (isNaN(document.form001.bookingCode.value) || document.form001.bookingCode.value.length!=3) {
		alert("You must enter your credit card's numerical 3 digit CVC number.");
		return false;
	}

	if (document.form001.bookingAdults.selectedIndex==0 && document.form001.bookingChildren.selectedIndex==0) {
		alert("You must select at least 1 Adult.");
		return false;
	}

	clickedButton=1;
	return true;
}
clickedButton=0;


// validate offer fields
function checkOfferFields() {

	fields = new Array();
	fields = document.form001.iG6.value.split("{");
	cTotal=0;
	for (ci=0; ci!=fields.length; ci++) {
		if (fields[ci]!=null) {
			cTotal+=fields[ci];
		}
	}
	if (cTotal==0) {
		alert("You must enter your offered rates for the nights.");
		return false;
	}

	if (document.form001.offerNights.selectedIndex==0) {
		alert("You must select at least one night for your offer.");
		return false;
	}

	if (document.form001.offerAdults.selectedIndex==0) {
		alert("You must select the number of Adults.");
		return false;
	}

	fields=new Array("Firstname","Lastname","Email","Email2","Phone","ETA");
	for (ci=0; ci!=fields.length; ci++) {
		obj = eval("document.form001.offer" + fields[ci]);
		if (obj.value.length==0) {
			alert("Please complete all the mandatory fields before proceeding.");
			return false;
		}
	}

	if (document.form001.iG2.value.length==0 || document.form001.iG3.value.length==0) {
		alert("Please complete your payment details before proceeding.");
		return false;
	}

	if (document.form001.iG4.selectedIndex==0 || document.form001.iG5.selectedIndex==0) {
		alert("Please complete your payment details before proceeding.");
		return false;
	}

	if (document.form001.offerEmail.value.indexOf("@")==-1 || document.form001.offerEmail.value.indexOf(".")==-1) {
		alert("Please ensure you enter a valid Email Address.");
		return false;
	}

	if (document.form001.offerEmail.value!=document.form001.offerEmail2.value) {
		alert("Your second entered Email Address does not match your first.");
		return false;
	}

	if (isNaN(document.form001.iG3.value) || document.form001.iG3.value.length<14) {
		alert("You must enter your numerical credit card number.");
		return false;
	}

	if (document.form001.agree.checked==false) {
		alert("You must read the Terms and Conditions, then tick the I Agree checkbox before proceeding.");
		return false;
	}

	if (isNaN(document.form001.offerCVC.value) || document.form001.offerCVC.value.length!=3) {
		alert("You must enter your credit card's numerical 3 digit CVC number.");
		return false;
	}

// check entered rates

	return true;
}


function watchCounter() {
	totalC=0;
	countered=0;
	ok=0;
	for (i=0; i!=nights; i++) {
		if (document.form001("a_" + i).selectedIndex==1) {
			ok=1;
		}
	}

	if (ok==1) {
		if (document.form001.offerResponse[0].checked) {
			document.form001.offerResponse[1].checked=true;
		}
		document.getElementById("counterLabel").style.display="";
		document.getElementById("counterTotal").style.display="";
		document.getElementById("counterTotalCommission").style.display="";
		document.getElementById("counterTotalNett").style.display="";
	}
	else {
		document.getElementById("counterLabel").style.display="none";
		document.getElementById("counterTotal").style.display="none";
		document.getElementById("counterTotalCommission").style.display="none";
		document.getElementById("counterTotalNett").style.display="none";
	}

	for (i=0; i!=nights; i++) {
		totalC+=document.form001("r_" + i).value*1;
	}
	document.getElementById("counterTotal").innerHTML=symbol + totalC.toFixed(2);
	document.getElementById("counterTotalCommission").innerHTML=symbol + (totalC*0.1).toFixed(2);
	document.getElementById("counterTotalNett").innerHTML=symbol + (totalC*0.9).toFixed(2);

	if (maxRooms>1) {
		for (i=0; i!=maxRooms; i++) {
			if (document.form001.offerRoom[i].checked && document.form001.offerRoom[i].value!=theRoom && document.form001.offerResponse[0].checked) {
				document.form001.offerResponse[2].checked=true;
			}
		}

		if (document.form001.offerResponse[0].checked) {
			for (i=0; i!=nights; i++) {
				document.form001("r_" + i).value=rates[i];
			}
		}
	}

}

function resetOffer() {
	countered=0;
	for (i=0; i!=document.form001.elements.length; i++) {
		if (document.form001.elements[i].name.indexOf("a_")!=-1) {
			if (document.form001.elements[i].selectedIndex==1) {
				countered++;
			}
		}
	}

	if (countered==0) {
		document.form001.offerResponse[0].checked=true;
	}
}

// validate hotel's response
function checkOfferFields2() {
	if (document.form001.offerResponse[1].checked || document.form001.offerResponse[2].checked) {
		for (i=0; i!=nights; i++) {
			if ((document.form001("r_" + i).value*1)==0) {
				alert("Please ensure you have entered a rate for each night you have countered.");
				return false;
			}
		}
	}

	if (document.form001.offerResponse[0].checked) {
		return confirm("You have selected to accept the customer's offer.\n\nBy proceeding, you are confirming the booking of the customer's selected nights and requests.\n\nThe customer will pay a 10% deposit to StandbyRates now and the remainder will be paid on arrival to the hotel.");
	}

	return true;
}

searchMode=-1;
// re-sort the search results
function sortSearch(mode) {
	searchMode=mode;
	moveRates(daysAhead);
}

shortList="";
function showList(mode,index) {
	if (mode==1) {
		shortList+=index+"^";
		document.getElementById('goList').style.display='';
		document.getElementById('goListBack').style.display='none';
		alert("The selected hotel has been added to your comparison shortlist.\n\nClick 'View Shortlist Comparison' when finished selecting your hotels.2");
	}
	else if (mode==2) {
		searchMode=mode;
		moveRates(daysAhead);
		document.getElementById('goList').style.display='none';
		document.getElementById('goListBack').style.display='';
	}
	else if (mode==3) {
		shortList="";
		searchMode=mode;
		moveRates(daysAhead);
		document.getElementById('goList').style.display='none';
		document.getElementById('goListBack').style.display='none';
	}
}

gaCookie="";

currentMM="";
function flip2(mode,x,side) {

	if (currentMM==x+""+side) {
		return false;
	}

	if (mode==0) {
		for (var i=1; i!=4; i++) {
			document.getElementById("mm"+side+""+x+""+i).className="mmTabL" + i;
		}
	}
	else {
		for (var i=1; i!=4; i++) {
			document.getElementById("mm"+side+""+x+""+i).className="mmTabL" + i + "u";
		}
	}
}

