var isFirstShowing=false;
var const_debugMode10=0;
	//debug functions only
	function jgAlert(inString){
		var regExp=/¬/g;
		inString=inString.replace(regExp,lR());
		alert(inString);
	}
	function lR(nRet){//016 adds  Line-Return(s)
		var rC=String.fromCharCode(10);
		var tS = rC;
		if(arguments.length==0){nRet=1}
		while (nRet>1){
			tS += rC;
			nRet = nRet-1;
		}
		return tS;
	}
	
	
	
	//javascript functions for operating page (eventually into js file that is linked only if php has javascript switch set
	var debugMode10=0;
	var maxLinesPerView=4;//try 10 later
	var glob_linesPerView=0;
	var glob_PageMode_0MonthPerView_1NumberPerView=0;
	var glob_avail0edit1=0;
	var jgc_lastNoTopBorderCellIfSameAsPrev=3;
	var cellNameMonth="cellMonthShort";
	//var bookMode1form0none=1;
	//alert("909: bookMode1form0none="+bookMode1form0none);
	var captionString="";
	var nRows;
	/*var firstRunIndexToShow=0;
	var lastRunIndexToShow=12;	
	var currentFirstIndexShowing;
	var currentLastIndexShowing;*/
	var glob_currentPageID=-1;
	var glob_pageID_min=-1;
	var glob_pageID_firstPageWithAvailability=-1;
	var glob_pageID_max=-1;
	var glob_buttonsAtTop=true;
	
	var dayStringFormat01=0;//0=short, 1=full 
	var indexOnCurrentPage;
	var currentRowID;
	var ignoreClicks=false;
	var verbose=false;
	var monthStringFormat01=0;//0=short, 1=full

	//mons=new Array ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	var rowClass=1;
	var page = new Array();
	
	if ((navigator.appName == 'Microsoft Internet ')||(navigator.appName == 'Microsoft Internet Explorer')){
		//var classNameUpAbit="upabit";
		var glob_class_sup="supIE";
	} else {
		//var classNameUpAbit="upabitmore";
		var glob_class_sup="supFF";
	}
	//var glob_defaultString="&nbsp;";
	var glob_defaultString="<span class='glob_class_sup'>&nbsp;</span>";
	mainTableStruc=new Array();
	/*mainTableStruc[0]=new colStruc(0,false,true,"Arrive DOW and Date","dateCellShort1","Left");
	mainTableStruc[1]=new colStruc(1,true,true,"Arrive Month",cellNameMonthCell);
	mainTableStruc[2]=new colStruc(2,true,true,"Arrive Year","yearCell");
	mainTableStruc[3]=new colStruc(3,true,true,"Duration","cellNights","Left");//was col5
	mainTableStruc[4]=new colStruc(4,true,true,"Depart DOW and Date","dateCellShort2","Left");
	mainTableStruc[5]=new colStruc(5,true,true,"Depart Month",cellNameMonthCell);
	mainTableStruc[6]=new colStruc(6,true,true,"Depart Year","yearCell","Right");
	*/
	
	addCol(false,true,"Arrive DOW and Date","cellDate","Left");//was dateCellShort1
	addCol(true,true,"Arrive Month",cellNameMonth);
	addCol(true,true,"Arrive Year","cellYear");
	addCol(true,true,"Duration","cellNightsAvail","Left");
	addCol(true,true,"Depart DOW and Date","cellDate","Left");//was dateCellShort2
	addCol(true,true,"Depart Month",cellNameMonth);
	addCol(true,true,"Depart Year","cellYear","Right");

	if (bookMode1form0none==1){
		addCol(false,false,"Price","cellPriceList","");
		addCol(false,false,"Booking","cellButton","Right");
		var classStringPrice="cellPriceList";
		var classStringButton="cellButton border_RightVisible";
	} else {
		addCol(false,false,"Price","cellPriceList","Right");
		var classStringPrice="cellPriceList border_RightVisible";
	}
	var colCount=mainTableStruc.length;
	//alert("901 colCount set to "+colCount);
	function addCol(silentLeft, silentRight, colDesc, cellClass, borderDesc){
		if (arguments.length<5){
			var borderDesc = "";
		}
		var newIndex=mainTableStruc.length;
		mainTableStruc[newIndex]=new colStruc(newIndex,silentLeft, silentRight, colDesc, cellClass, borderDesc);
	}
	
	function setPriceCellAvail(currentCellIndex,thisRun){
		if (true){
			var tS="<span class='"+glob_class_sup+"'>£</span>"+"&nbsp;<span class='"+glob_class_sup+"_correctionForNormal'>"+thisRun.price+"</span>";
		} else {
			var tS="£ "+thisRun.price;
		}
		thisRun.cellInnerHTML[currentCellIndex]= tS;
		thisRun.cellClassString[currentCellIndex]=lTrim(stringCellBorderClasses(thisRun,currentCellIndex));
	}
	function setBookNowCell(currentCellIndex,thisRun){
		var ref="c"+"-"+offeringLongID+"-"+thisRun.arriveADN+"-"+thisRun.nights + "-"+thisRun.price;
		var tS="<div class='cellButtonIEcorrection'>";//for IE which adds spurious spacing 
		tS += "<input class='bookButton' type='submit' name='" + ref+"' id='" + ref + "' value='BOOK THIS'>";
		tS+="</div>";
		thisRun.cellInnerHTML[currentCellIndex]= tS;
		thisRun.cellClassString[currentCellIndex]=lTrim(stringCellBorderClasses(thisRun,currentCellIndex));
	}
	
	
	function pageStruc(pageID){
		this.pageID=pageID;
		this.firstRunIndex=0;
		this.lineCount=0;
		this.showPrevFirst=!(pageID==glob_pageID_min);
		this.showNextLast=!(pageID==glob_pageID_max);
		var thisMonthZB=pageID % 12;
		var thisYear=(pageID-thisMonthZB)/12;
		this.headerString=obMonthList[1][aV(thisMonthZB,1)]+" " +thisYear;
		if (glob_PageMode_0MonthPerView_1NumberPerView==0){
			if (monthText[pageID]){
				this.subheadString=monthText[pageID];
			} else {
				this.subheadString="";
			}
		}
	}

	function stringCellBorderClasses(thisRun,colIndex){
		return stringCellClass_Avail(colIndex,thisRun.isSameAsPrev,true,false);
	}
	function stringCellClass_Avail(colIndex,isSameAsPrev, showInternalBorders, setTopDividerOff){
		if (arguments.length<3){
			var showInternalBorders=true;
		}
		if (arguments.length<4){
			var setTopDividerOff=false;
		}
		//version for availability table
		
		//alert("16 thisRun.runIndex="+thisRun.runIndex +" - colIndex="+colIndex);
		var thisClassName=mainTableStruc[colIndex].cellClassName;
		//thisClassName+=" clearBottom ";

		//TOP
		if (setTopDividerOff||((isSameAsPrev)&&(mainTableStruc[colIndex].noTopBorderIfSameAsPrev))){//first 4 cols need empty top border if same as prev and not dirty
			//allert("writing clearTopNoDivider for a="+a);
			thisClassName+=" clearTopNoDivider "
		} else {
			thisClassName+=" dividerTopLine ";
		}
		if (colIndex==0||(colIndex==(mainTableStruc.length-1))){
			var showBorders=true;
		} else {
			var showBorders=showInternalBorders;
		}
		//LEFT
		if (showBorders && mainTableStruc[colIndex].hasLeftBorder){
			thisClassName+=" borderLeft ";
		} else {
			//if (!mainTableStruc[colIndex].silentLeft){
				thisClassName+=" clearLeft ";
			//}
		}
		
		//RIGHT
		if (showBorders && mainTableStruc[colIndex].hasRightBorder){
			thisClassName+=" borderRight ";
		} else {
			//if (!mainTableStruc[colIndex].silentRight){
				thisClassName+=" clearRight ";
			//}
		}
		return thisClassName;
	}
	

	
	
	
	
	
	function monthID(thisADN){
		//returns numeric month-number to allow calculation of no of months between two ADNs]
		var thisDate=ADNtoDate(thisADN);
		return monthIDforDate(thisDate);
	}
	function monthIDforDate(thisDate){
		return (thisDate.getFullYear()*12)+thisDate.getMonth();
	}
	function setPageNumbers(){
		//alert("881 - setPageNumbers");
		var prevPageID=-1;
		var runsThisValue=0;
		var maxRunsSoFar=0;
		var thisMonthID;
		var prevRunMonthID=-1;
		if (debugMode){
			alert("1536: glob_PageMode_0MonthPerView_1NumberPerView="+glob_PageMode_0MonthPerView_1NumberPerView);
		}
		if (glob_PageMode_0MonthPerView_1NumberPerView==0){
			//loop through the run array
			//find highest no of runs per month - will use this as row count for each month
			//at the same time, finish the detail of the entry in page array
			var thisDate;
			
			var prevYear;
			
			var tS="MonthIDs"+lR();
			if (debugMode){
				alert("1531: setPageNumbers: run.length="+run.length);
			}
			for (var a=0; a<run.length; a++){
				thisMonthID=monthID(run[a].arriveADN);
				run[a].monthID=thisMonthID;
				run[a].pageID=thisMonthID;
				if (debugMode){
					tS+="run["+a+"].monthID="+thisMonthID+lR();;
				}
			}
			if (debugMode){
				alert("955: "+tS);
			}
			//now create the month-per-page array
			
			//glob_pageID_min=run[0].monthID;
			var thisDate = new Date();
			glob_pageID_min=monthIDforDate(thisDate);//minimum pageID is for the current month
													 //if no availability in that month, it will show "No availability" (rather than not offer that month at all)
			glob_pageID_max=run[run.length-1].monthID;
			//alert("creating pages from "+glob_pageID_min+" to "+ glob_pageID_max+" inclusive");
			for (thisMonthID=glob_pageID_min; thisMonthID<=glob_pageID_max; thisMonthID++){
				page[thisMonthID]=new pageStruc(thisMonthID);
			}	
			prevRunMonthID=-1;
			glob_pageID_firstPageWithAvailability=99999;
			for (var a=0; a<run.length; a++){
				if (run[a].monthID<glob_pageID_min){
					//do nothing - month has passed
				} else {
					if (glob_pageID_firstPageWithAvailability>run[a].monthID){
						glob_pageID_firstPageWithAvailability=run[a].monthID;
						if (debugMode){
							alert("1532: glob_pageID_firstPageWithAvailability set to "+run[a].monthID+" a="+a);
						}
					}
					if (run[a].monthID==prevRunMonthID){
						//subsequent entry in a month
						runsThisValue++;
						page[run[a].monthID].lineCount++;
						//alert("thisDate="+thisDate+" - increase runsThisValue - to "+runsThisValue);
					} else {
						
						//first entry in a month
						runsThisValue=1;//moved up two lines so that it counts in maxRunsSoFar
						//moved down outside IF: maxRunsSoFar=jgMax(maxRunsSoFar,runsThisValue);
						
						var thisMonthID=run[a].monthID;
						if (debugMode){
							alert("1538 maxRunsSoFar="+maxRunsSoFar+lR()+"thisMonthID="+thisMonthID+lR()+"PAGES:"+lR()+debugListPages());
						}
						page[thisMonthID].lineCount=1;
						page[thisMonthID].firstRunIndex=run[a].runIndex
						//alert("thisDate="+thisDate+" - new month"+lR()+"runsThisValue="+runsThisValue+lR()+"maxRunsSoFar="+maxRunsSoFar);
						prevRunMonthID=thisMonthID;
					}
					maxRunsSoFar=jgMax(maxRunsSoFar,runsThisValue);//JG 280308
					run[a].rowIndex=page[thisMonthID].lineCount-1;
				}
			}
			glob_linesPerView=maxRunsSoFar;
			//alert("883: glob_linesPerView="+glob_linesPerView);
		} else {
			//loop through the run array and find highest no of runs per arriveADN - will HIGHER of this and normal limit as row count for each month
			var prevADN=0;
			var thisADN=0;
			for (var a=0; a<run.length; a++){
				if (run[a].arriveADN==prevADN){
					runsThisValue++;
				} else {
					maxRunsSoFar=jgMax(maxRunsSoFar,runsThisValue);
					runsThisValue=0;
					prevADN=run[a].arriveADN;
				}
			}
			glob_linesPerView=jgMax(maxLinesPerView,maxRunsSoFar);
			alert("884: maxRunsSoFar="+maxRunsSoFar+lR()+"maxLinesPerView="+maxLinesPerView+lR()+"glob_linesPerView="+glob_linesPerView);
			//number-per-page is fixed: now do the page allocations 
			//var rS="";
			for (var runIndex=0; runIndex<run.length; runIndex++){
				startNewPage=false;
				//for number-per-view, need to check that all the entries with this arriveADN will fit on page (or start new page for all of them)
				if (runIndex==0){
					startNewPage=true;
				} else {
					var linesThisPageIfShowThisADNOnThisPage=aV(page[glob_currentPageID].lineCount,1);
					for (var b=aV(runIndex,1); b<run.length; b++){
						if (run[b].arriveADN==run[runIndex].arriveADN){//looped entry is same arriveADN as the run we are choosing a page for
							linesThisPageIfShowThisADNOnThisPage++;
						} else {
							break;
						}
					}
					startNewPage=(linesThisPageIfShowThisADNOnThisPage>glob_linesPerView);
					/*if (startNewPage){
						alert("runIndex="+runIndex+lR()+"new page because linesThisPageIfShowThisADNOnThisPage="+linesThisPageIfShowThisADNOnThisPage);
					}*/
				}
				if (startNewPage){
					glob_currentPageID++;
					page[glob_currentPageID]=new pageStruc(glob_currentPageID);
					page[glob_currentPageID].firstRunIndex=runIndex;
				}
				page[glob_currentPageID].lineCount++;
				run[runIndex].pageID=glob_currentPageID;
				run[runIndex].rowIndex=page[glob_currentPageID].lineCount;
				//alert("882: set run["+runIndex+"].rowIndex=page["+glob_currentPageID+"].lineCount, which is "+run[runIndex].rowIndex
				//rS+="runIndex="+runIndex+": "+glob_currentPageID+lR();
				if (runIndex==(nRows-1)){//this is the last row
					page[glob_currentPageID].showNextLast=false;
				}
			}
		}
		//alert(rS);
		//glob_pageID_min=0;
		glob_pageID_max = page.length-1;
		//glob_pageID_firstPageWithAvailability = run[0].pageID;
		glob_currentPageID = glob_pageID_firstPageWithAvailability;//page showing first available dates
		//alert("setting glob_pageID_firstPageWithAvailability to "+glob_pageID_firstPageWithAvailability);
	}
	function debugListPages(){
		var tS="";
		for (pageIndex in page){
			tS+="*"+pageIndex+" ";
		}
		return tS
	}
	function loadFirstPage(){
		if (debugMode){
			alert("910 loadFirstPage - glob_pageID_firstPageWithAvailability="+glob_pageID_firstPageWithAvailability);
		}
		makePage(glob_pageID_firstPageWithAvailability);
	}
	function writeEmptyCellRow(tBody,isFirst,isLast,cellText,addDividerBlank){
		if (arguments.length<5){
			addDividerBlank=true;
		}
		var tr = tBody.insertRow(tBody.rows.length);
		//setThisAttribute(tr,"class","cellEmpty");
		setThisAttribute(tr, "id","blankRow");
		var newcell=tr.insertCell(-1); //insert new cell to end of row
		newcell.colSpan=colCount;
		if (isLast){
			thisClassName="cellEmptyLastRow dividerBottom";
		} else {
			thisClassName="cellEmptyNotLastRow ";
		}
		if (isFirst){
			thisClassName+=" dividerTopLine ";
		} else {
			if (addDividerBlank){
				//thisClassName+=" dividerBlank ";
				thisClassName+=" dividerTop_SpacerOnly ";
			}
		}
		thisClassName+=" border_LeftVisible border_RightVisible ";
		setThisAttribute(newcell,"class",thisClassName)
		//newcell.className = thisClassName;
		if ((arguments.length>3)&&(cellText.length>0)){
			newcell.innerHTML=cellText;
		} else {
			newcell.innerHTML="&nbsp;";
		}
	}
	
	function makePage(newPageIndex){
		if (debugMode){
			alert("newPageIndex="+newPageIndex);
		}
		//show debug only for first month
		var debugThisFunction=((newPageIndex==glob_pageID_firstPageWithAvailability) && true && debugMode);
		if (debugMode){
			alert("1540a: debugThisFunction="+debugThisFunction);
		}
		if (newPageIndex %2 ==1){
			rowClass=2;
		} else {
			rowClass=1;
		}
		
		var thisPage=page[newPageIndex];
		if (glob_PageMode_0MonthPerView_1NumberPerView==0){
			if (debugThisFunction){
				alert2("911 thisPage.pageID="+thisPage.pageID);
			}
			var thisHeaderString="<div class='monthYear'>"+thisPage.headerString+"</div>";
			var thisSubheadString=thisPage.subheadString;
			if (thisSubheadString.length>0){
				thisHeaderString+="<div class='monthSubHead'>"+thisSubheadString+"</div>";
			}
			gObj("monthYearHeader").innerHTML=thisHeaderString;
		}
		var tBody=gObj("mainTableBody");
		while (tBody.rows.length>0) {//deletes all rows of a table
			tBody.deleteRow(0);
		}
		//alert("tBody.rows.length="+tBody.rows.length);
		
		var startIndex=thisPage.firstRunIndex;
		var thisLastIndex=aV(startIndex,glob_linesPerView)-1;
		var paddingFalse_dummyRowTrue=false;
		var blankRowAboveSorryMessage = true;
		var drawBlankBoxForPartEmptyMonths = true;//if false, empty cells are blank - if true, they are boxed en masse
		var isFirstPaddedRow=true;
		var firstRowIndex=0;
		if (debugThisFunction){
			alert2("890 in makePage with newPageIndex="+newPageIndex+lR()+"startIndex="+startIndex+lR()+"thisLastIndex="+thisLastIndex+lR()+"glob_linesPerView="+glob_linesPerView);
		}
		if (thisPage.lineCount==0){
			if (blankRowAboveSorryMessage){
				if (debugThisFunction){
					alert2("918: blankRowAboveSorryMessage");
				}
				createRow(tBody,0,0,false,false,true,debugThisFunction);
				firstRowIndex++;
				startIndex++;
			}
			writeEmptyCellRow(tBody, !blankRowAboveSorryMessage,(thisRunIndex==thisLastIndex), "Sorry - we have no availability starting in "+thisPage.headerString,true);
			firstRowIndex++;
			for (var thisRowIndex=firstRowIndex; thisRowIndex<glob_linesPerView-1; thisRowIndex++){
				if (debugThisFunction){
					alert2("912: creating interim row with thisRowIndex="+thisRowIndex+lR()+"thisRunIndex set to -1");
				}
				createRow(tBody,thisRowIndex,-1,false,false,true,debugThisFunction);//interim rows
			}
			if (debugThisFunction){
				alert2("913: creating final row with thisRowIndex="+thisRowIndex);
			}
			createRow(tBody,glob_linesPerView-1,-1,true,false,true,debugThisFunction);//final row
		} else {
			for (var thisRowIndex=0; thisRowIndex<glob_linesPerView; thisRowIndex++){
				var thisRunIndex= aV(thisPage.firstRunIndex, thisRowIndex);
			//for (var thisRunIndex=startIndex; thisRunIndex<=thisLastIndex; thisRunIndex++){
				/*if (thisRunIndex>40){*/
					//alert("in loop with thisRunIndex="+thisRunIndex+lR()+"thisLastIndex="+thisLastIndex+lR()+"thisPage.lineCount="+thisPage.lineCount);
				/*}*/
				if ((thisRunIndex<run.length) && (thisRunIndex<aV(startIndex,thisPage.lineCount))){
					//this is an active row
					//var isLastActiveRow=thisRunIndex==(aV(startIndex,thisPage.lineCount)-1)
					//alert("904:thisRunIndex="+thisRunIndex+lR()+"thisPage.lineCount="+thisPage.lineCount+lR()+"startIndex="+startIndex+lR()+"isLastActiveRow="+isLastActiveRow);
					var isLastRow=(thisRowIndex==(glob_linesPerView-1));
					useBottomBorder=(isLastRow) ;
					//alert("899a: active row");
					if (debugThisFunction){
						alert2("914: creating ACTIVE row with thisRowIndex="+thisRowIndex+lR()+"thisRunIndex="+thisRunIndex);
					}
					createRow(tBody,thisRowIndex,thisRunIndex,useBottomBorder,true,false,debugThisFunction);
				} else {
					//padding row
					//if (drawBlankBoxForPartEmptyMonths){
					//alert("899b: padding row");
					if (paddingFalse_dummyRowTrue){
						if (debugThisFunction){
							alert2("915: creating DUMMY row with thisRowIndex="+thisRowIndex);
						}
						createRow(tBody,thisRowIndex,-1,(thisRowIndex==glob_linesPerView-1),false,(thisRowIndex>thisPage.lineCount),debugThisFunction);//do not add dividerBlank for first row after last available row
					} else {
						if (debugThisFunction){
							alert2("919: writeEmptyCellRow with thisRowIndex="+thisRowIndex);
						}
						writeEmptyCellRow(tBody,isFirstPaddedRow,thisRowIndex==glob_linesPerView-1);
					}
					isFirstPaddedRow=false;
				}
			}
		}
		setFooterButtons(newPageIndex);
	}
	function setButton(buttonName,imgName,isEnabled){
		gObj(buttonName).className=buttonName+" bn"+isEnabled;
		if (isEnabled){
			gObj("img_"+imgName).src=imgName+".png";
		} else {
			gObj("img_"+imgName).src=imgName+"Grey.png";
		}
	}
	
	function setFooterButtons(pageIndex){
		setButton("bnFirst","start",page[pageIndex].showPrevFirst);
		setButton("bnPrev","back",page[pageIndex].showPrevFirst);
		setButton("bnNext","next",page[pageIndex].showNextLast);
		setButton("bnLast","last",page[pageIndex].showNextLast);
		
		/*gObj("bnFirst").className="bnFirst bn"+page[pageIndex].showPrevFirst;
		gObj("bnPrev").className="bnPrev bn"+page[pageIndex].showPrevFirst;
		gObj("bnNext").className="bnNext bn"+page[pageIndex].showNextLast;
		gObj("bnLast").className="bnLast bn"+page[pageIndex].showNextLast;*/
	}
	function ADNdateBit(thisADN,formatName){
		//"D" 3-letter day
		//"j" numeric date, no leading zero
		//"M" 3-letter month
		//"Y" 4-figure year
		var thisDate=ADNtoDate(thisADN);
		if (formatName=="Y"){
			return thisDate.getFullYear();
		}
		if (formatName=="M"){
			return obMonthList[0][aV(thisDate.getMonth(),1)];
		}
		if (formatName=="D"){
			return dayName[0][thisDate.getDay()];
		}
		if (formatName=="j"){
			return thisDate.getDate();
		}
		//shouldn't get here
		return "Format~"+formatName+"~ not coded";
	}
	
	function createCell(tr,thisCellIndex,ihString,cnString,idString,csString){
		//adds new cell. ihString compulsory - others optional (but must have cnString if using csString etc)
		var newcell=tr.insertCell(thisCellIndex); //insert new cell to end of row//was -1
		newcell.innerHTML=ihString;
		//alert("cell count="+tr.cells.length);
		if ((arguments.length>3 && cnString.length>0)){
			if (thisCellIndex>-1){
				//alert(cnString);
				newcell.className=cnString;
			}
		}
		if ((arguments.length>4 && idString.length>0)){
			newcell.id=idString;
		}
		if ((arguments.length>5 && csString.length>0)){
			newcell.colSpan=csString;
		}
	}

	function createRow(tBody,rowIndex,runIndex,useBottomBorder,fillCell, setTopDividerOff, debugThisFunction){
		if (arguments.length<7){
			var debugThisFunction=false;
		}
		
		if (arguments.length<6){
			addDividerBlank=false;
		}
		var varClassDividerFirst;
		var varClassDitto;
		var varClassDividerBottom;
		var thisRun=run[runIndex];
		var tS="";
		//var defaultString="1<sup>1</sup>";
		if (debugThisFunction){
			alert2("907 rowIndex="+rowIndex+lR()+"runIndex="+runIndex+lR()+"fillCell="+fillCell);
		}
		var tr = tBody.insertRow(tBody.rows.length);
		
		if (fillCell){
			var departADN=thisRun.arriveADN+thisRun.nights;
			//tS += pAlert("rowClass=" + rowClass);
			if (thisRun.isSameAsPrev10==1){
				varClassDividerFirst=" dividerTop_SpacerOnly ";
				varClassDitto=" ditto" + rowClass + " ";
			} else {
				varClassDividerFirst=" dividerTopLine ";
				varClassDitto="";
				if (rowClass==1){
					rowClass=2;
				} else {
					rowClass=1;
				}
			}
			thisRun.currentRowClass=rowClass;
		}

		if (fillCell){
			if (debugThisFunction){
				alert2("916: runIndex="+runIndex+lR()+"rowIndex="+rowIndex);
			}
			setCellsAndRepaint_TableRow(runIndex,rowIndex,useBottomBorder,false, "createRow")
		} else {
			if (debugThisFunction){
				alert2("920 calling fillTableRowWithEmptyCells: rowIndex="+rowIndex);
			}
			fillTableRowWithEmptyCells(rowIndex, setTopDividerOff,useBottomBorder);
		}
	}
	
	function fillTableRowWithEmptyCells(thisRowIndex, setTopDividerOff,useBottomBorder){
		var tBod=gObj("mainTableBody");
		if (tBod.rows.length>thisRowIndex){
			tBod.deleteRow(thisRowIndex);
		} 
		var tr = tBod.insertRow(thisRowIndex);
		if (thisRunIndex=tBod.rows.length-1){
			//last row
			//allert("814: LAST ROW"+lR()+"date="+thisRun.dateString+lR()+debug_stringRunTableList());
		}
		setThisAttribute(tr, "id","blank"+thisRowIndex);
		//setThisAttribute(tr, "class","cellEmpty");
		//alert("907:set blank"+thisRowIndex);
		for (var a=0; a<mainTableStruc.length; a++){
			var td=tr.insertCell(a);
			//var thisClassString=stringCellClass_Avail(a,false);//- fallback: worked in old version, but slow
			//var thisClassString="";
			//var thisClassString=mainTableStruc[a].cellClassName;
			var thisClassString=stringCellClass_Avail(a,false,false,setTopDividerOff);
			/*if (a==0){
				thisClassString+=" border_LeftVisible "
			}
			if (a==mainTableStruc.length-1){
				thisClassString+=" border_RightVisible "
			}*/
			/*if (addDividerBlank){
				thisClassString+=" dividerBlank ";
			}*/
			if (useBottomBorder){
				thisClassString+=" dividerBottom ";
			}
			td.innerHTML =glob_defaultString;
			setThisAttribute(td,"class",thisClassString);
		}
	}
	function buttonRowString(){
		var hasNext=page[glob_pageID_min].showNextLast;
		var useTRTD=false;
		
		if (useTRTD){
			var cols1=3;
			var cols2=4;
			if (colCount==9){
				var cols2=5;
				var cols3=1;
			} else {
				var cols3=1;
				var cols2=4;
				var cols3=1;
			}
		}
		//alert("842: colCount+"+colCount);
		var tS="<div class='brs'><!--start of buttonRowString-->"
		if (useTRTD){
			tS+="<tr><td class='monthYearHeader' colspan='"+cols1+"'>\n";
		}
		tS+="<div class='floatLeft'>\n";
			//FIRST button
			tS+="<button type='button' class='bnFirst bnFalse' id='bnFirst' onClick='singleClick(1);' onDblclick='doubleClick(1)' >\n";
			tS+="<img id ='img_start' src='start.png' width='38' height ='26' alt='First page'><br />START</button>\n";
			//PREV button
			tS+="<button type='button' class='bnPrev bnFalse' id='bnPrev'  onClick='singleClick(2);' onDblclick='doubleClick(2)' >\n";
			tS+="<img id ='img_back' src='back.png' width='38' height ='26' alt='Previous page'><br />BACK</button>\n";
		tS+="</div>\n";
		if (useTRTD){
			tS+="</td><td colspan='"+cols2+"' class='monthYearHeader' id='monthYearHeader'>&nbsp;</td>\n";
			tS+="<td class='monthYearHeader' colspan='"+cols3+"'>\n";
		} else {
			//SEE LATER tS+="<div class='monthYearHeader' id='monthYearHeader'>&nbsp;</div>";
		}
		tS+="<div class='floatRight'>\n";
			//NEXT button
			tS+="<button type='button' class='bnNext bn"+hasNext+"' id='bnNext'  onClick='singleClick(3);' onDblclick='doubleClick(3)' >\n";
			tS+="<img id ='img_next' src='next.png' width='38' height ='26' alt='Next page'><br />NEXT</button>\n";
			//END button
			tS+="<button type='button' class='bnLast bn"+hasNext+"' id='bnLast' onClick='singleClick(4);' onDblclick='doubleClick(4)' >\n";
			tS+="<img id ='img_last' src='last.png' width='38' height ='26' alt='Last page'><br />END</button>\n";
		tS+="</div>\n";
		if (useTRTD){
			tS+="</td>\n";
			tS+="</tr>\n";
		} else {
			tS+="<div class='monthYearHeader' id='monthYearHeader'>&nbsp;</div>\n";
			tS+="<div class='clear'></div>\n";
		}
		tS+="</div><!--end of brs-->";
		return tS;
	}
	function tableFooterString(){
		//alert("page min is "+glob_pageID_min+" page length = "+page.length);
		
		var tS="<tfoot>\n";
		
		if (true){//extras
			tS+="<tr>\n";
			tS+="<td class='extras' colspan='"+colCount+"'>\n";
			var bottomString="";
			if (includedText.length>0){
				bottomString+=includedText;
				var spacer="<br />\n";
			} else {
				var spacer="";
			}
			if (extrasText.length>0){
				bottomString+=spacer+"Extra charges: "+extrasText;
			}
			if ((glob_paypalInTable) && (glob_paypalInTable)){
				tS+=HTM_acceptPaypal(bottomString);
			} else {
				tS+=bottomString;
			}
			tS+="</td>\n";
			tS+="</tr>\n";
		}
		if (!glob_buttonsAtTop){
			tS+=buttonRowString();
		}
	
		tS+="<tr>\n";
		tS+="<td colspan='"+colCount+"' class='fiveHigh'>&nbsp;</td>\n";
		tS+="</tr>\n";<!--dummy row because Firefox mangles the mouseover zone on bottom row of table-->
		tS+="</tfoot>\n";
		tS+="</table>\n";
		tS+="</form>\n";
		return tS;
	}
	
	
	function doubleClick(whichButton){
		//alert("doubleClick");
		if ((navigator.appName == 'Microsoft Internet Explorer')||(navigator.appName == 'Microsoft Internet Explorer')){
			singleClick(whichButton);
		} 
	}
	function singleClick(whichButton){
		//alert("singleClick");
		if (!ignoreClicks){
			ignoreClicks=true;
			var nowDate=new Date();
			if (debugMode){
				writeLog("singleClick with whichButton="+whichButton+" at "+nowDate);
			}
			switch(whichButton){
				case 1://first
					glob_currentPageID = glob_pageID_min;
					break
				case 2://prev
					if (glob_currentPageID>glob_pageID_min){
						glob_currentPageID--;
					}
					break
				case 3://next
					if (glob_currentPageID<glob_pageID_max){
						glob_currentPageID++;
					}
					break
				case 4://last
					glob_currentPageID = glob_pageID_max;
					break
				default: 
					alert("unexpected value for whichButton = "+whichButton);
			}
			if (debugMode){
				alert2("908: glob_currentPageID set to "+glob_currentPageID);
			}
			makePage(glob_currentPageID);
			ignoreClicks=false;
		}
	}
	/*function loadFirst(){
		if (!ignoreClicks){
			ignoreClicks=true;
			writeLog("loadFirst");
			glob_currentPageID=glob_pageID_min;
			makePage(glob_currentPageID);
			ignoreClicks=false;
		}
	}
		function loadNext(){
		if (!ignoreClicks){
			ignoreClicks=true;
			writeLog("loadNext");
			if (glob_currentPageID<glob_pageID_max){
				glob_currentPageID++;
				makePage(glob_currentPageID);
			}
			ignoreClicks=false;
		}
	}
	function loadPrev(){
		if (!ignoreClicks){
			ignoreClicks=true;
			writeLog("loadPrev");
			if (glob_currentPageID>glob_pageID_min){
				glob_currentPageID--;
				makePage(glob_currentPageID);
			} 
			//else {
			//	alert("glob_currentPageID="+glob_currentPageID+" - not going back");
			//}
			ignoreClicks=false;
		}
	}
	function loadLast(){
		
		if (!ignoreClicks){
			ignoreClicks=true;
			writeLog("loadLast");
			glob_currentPageID=glob_pageID_max;
			makePage(glob_currentPageID);
			ignoreClicks=false;
		}
	}
	*/
	
	//~~~~~~~~~~~~~~~DEBUG ONLY ~~~~~~~~~
	function writeRunParam(thisRun,paramName){
		eval("var tV=thisRun."+paramName+";");
		return "<td>"+paramName+"<br>"+tV+"</td>";
	}
	function entryCell(propValue, isHighlighted){
		if ((arguments.length==2) && isHighlighted){
			var classString=" class='debugContrast' ";
		} else{
			if (propValue==true){
				var classString=" class='isTrue' ";
			} else {
				if (propValue==false){
					var classString=" class='isFalse' ";
				} else {
					var classString="";
				}
			}
		}
		return "<td "+classString+">"+propValue+"</td>";
	}
/*function isArray(a){
	return(a.constructor.toString().indexOf("Array") != -1);
}*/

function isArray(v) {
	return v && typeof v === 'object' && typeof v.length === 'number' && !(v.propertyIsEnumerable('length'));
}

function arrayListString(thisArray){
	var tS="";
	for (element in thisArray){
		if (isArray(thisArray[element])){
			tS+=element+"-><br>"+arrayListString(thisArray[element]);
		} else {
			tS+="*"+element+"=";
			if (thisArray[element]==true){
				tS+="<span class='isTrue'>";
				var closeSpan=true;
			} else {
				if (thisArray[element]==false){
					tS+="<span class='isFalse'>";
					var closeSpan=true;
				} else {
					var closeSpan=false;
				}
			}
			tS+=thisArray[element];
			if (closeSpan){
				tS+="</span>";
			}
			tS+="<br>";
		}
	}
	return tS;
}
	
	
	
/*function listRun(arrayRef, repeatHeaderCount,colCountBeforeRepeatingCol0){
	//repeatHeaderCount=2;repaint header row every x rows
	//colCountBeforeRepeatingCol0=6; repeat column 0 every y columns
	if (arrayRef==1){
		var thisArray=run;
	}
	if (arrayRef==2){
		var thisArray=page;
	}
	alert("array length="+thisArray.length);
	var headerRow="<tr>";
	var a=0;
	for (element in thisArray){
		for (property in thisArray[element]){
			//run through first row to get name each of attributes
			if (a==0){
				var headerProperty=property;
			}
			if (a % colCountBeforeRepeatingCol0==0){
				headerRow+="<td class='debugContrast'>";
				headerRow+=headerProperty;
				headerRow+="</td>";
			}
			if (a>0){ 
				headerRow+="<td class='debugContrast'>";
				headerRow+=property;
				headerRow+="</td>";
			}
			a++;
		}
		break;//only interested in first element, as others will have same structure
	}
	headerRow+="</tr>";
	//allert("headerRow="+headerRow);
	var tS="<table border='1'>";
	//for (var a=0; a<thisArray.length; a++){
	for (a in thisArray){
		if (a % repeatHeaderCount == 0){
			tS+=headerRow;
		}
		tS+="<tr>";
		var b=0;
		for (property in thisArray[a]){
			if (b==0){
				var colZeroString=entryCell(thisArray[a][property],true);
			}
			if (b % colCountBeforeRepeatingCol0==0){
				tS+=colZeroString;
			}
			if (b>0){
				//if (isArray(thisArray[a])){
					if (isArray(thisArray[a][property])){
						tS+="<td>"+arrayListString(thisArray[a][property])+"</td>";
					} else {
						tS+=entryCell(thisArray[a][property]);
					}
				//} else {
				//tS+=entryCell(thisArray[a]);
				//}
			}
			b++;
		}
		tS+="</tr>"
	}
	tS+="</table>";
	gObj("debug"+arrayRef).innerHTML=tS;
}*/

function tableHeaderString(captionString1){
	var tS="<form id='userForm' action='http://www.winster.org/CottageNetwork/booking.php' method='post' >\n";
	tS+= "<table id='dateTable' cellpadding='0' border='"+debugMode10+"' cellspacing='0' summary='This table lists dates when the accommodation is available' >\n";
	
	if (glob_buttonsAtTop){
		captionString1+=buttonRowString();
	} else {
		captionString1+="<!-- glob_buttonsAtTop="+glob_buttonsAtTop+" -->\n";
	}
	tS+=captionString1;
	tS+="</caption>";
	tS += "<thead>";
		tS += "<tr>\n";
			tS += "<th scope='col' class='colHeader' colspan='3'>Arrival Date</th>\n";
			tS += "<th scope='col' class='colHeader'>Stay</th>\n";
			tS += "<th scope='col' class='colHeader' colspan='3'>Finish Date</th>\n";
			tS += "<th scope='col' class='colHeader'>&nbsp;</th>\n";//Price
			if (bookMode1form0none==1){
				tS += "<th scope='col' class='colHeader'>&nbsp;</th>\n";//Button
			}
		tS += "</tr>";
		tS += "<tr class='hiddentr'>\n";
			//tS += "<th scope='col' class='colSubHeader'>Day</th>";
			tS += "<th scope='col' class='colSubHeader'>Date</th>\n";
			tS += "<th scope='col' class='colSubHeader'>Month</th>\n";
			tS += "<th scope='col' class='colSubHeader'>Year</th>\n";
			tS += "<th scope='col' class='colSubHeader'>Duration</th>\n";
			//tS += "<th></th>";
			//tS += "<th scope='col' class='colSubHeader'>Day</th>";
			tS += "<th scope='col' class='colSubHeader'>Date</th>\n";
			tS += "<th scope='col' class='colSubHeader'>Month</th>\n";
			tS += "<th scope='col' class='colSubHeader'>Year</th>\n";
			tS += "<th scope='col' class='colSubHeader'>Price</th>\n";
			if (bookMode1form0none==1){
				tS += "<th scope='col' class='colSubHeader'>Action</th>\n";
			}
		tS += "</tr>\n";
	tS += "</thead>\n";
	tS += "<tbody id='mainTableBody'>\n";
	return tS;
}
function alert2(msg){
	//writeLog(msg);
	alert(msg);
}
function writeLog(msg){
	if (debugMode){
		gObj("log").value+=lR()+msg;
	}
}

function debugString(){
	var tS="<p><a href='Javascript:listRun(1,6,6);'>LIST RUN STRUCTURE</a>";
	tS+="<br><div "+idName("debug1")+">DEBUG INFO COMING HERE</div></p>";
	tS+="<p><a href='Javascript:listRun(2,15,6);'>LIST PAGE STRUCTURE</a>";
	tS+="<br><div "+idName("debug2")+">DEBUG INFO COMING HERE</div></p>";
	tS+="<form><textarea rows='20' cols='60' id='log'>LOG:</textarea></form>";
	tS+="<br><div "+idName("debug3")+">DEBUG INFO COMING HERE</div>";
	tS+="<br><a href='Javascript:listRun(3,5,6);'>LIST COLUMN STRUCTURE</a></p>";
	tS+="<p><a href='Javascript:showTableWidth();'>SHOW TABLE WIDTH</a></p>";
	return tS;
}
function writeDebugArea(){
	d(debugString());
}
function setHTML(idName,codeString,outerTagString){
	if ((navigator.appName == 'Microsoft Internet Explorer')&& false){
		gObj(idName).outerHTML="<" +outerTagString+" id='"+idName+">"+codeString+"</"+outerTagString+">";
		//alert("IE - code ends"+codeString.substring(codeString.length-20));
	} else {
		gObj(idName).innerHTML=codeString;
		//alert("FF/Opera - code ends"+codeString.substring(codeString.length-20));
	}
}
function countRuns(){
	var nRuns=0;
	for (var thisRunIndex in run){
		nRuns++;
	}
	return nRuns;
}
function writeData(){
	if (false){
		alert("832 writeData called");
		return;
	}
	
	var captionString1="";
	captionString1 += "<caption>AVAILABLE DATES";
	//captionString += "<br />for "+offeringName+", "+offeringLocation+"<br />\n";
	captionString1 += "<span class='update'> last updated on "+lastUpdatedString+"</span>\n";
	//captionString += "<div class='monthYearHeader' id='monthYearHeader'>&nbsp;</div>\n";
	//var captionString2 = "</caption>\n";
	//alert("nRows="+nRows);
	if (const_debugMode10==1){
		alert("1537: const_debugMode10="+const_debugMode10+lR()+"about to run setPageNumbers");
	}
	
	var showTable=true;//default
	if (countRuns()>0){
		setPageNumbers();
		if (page.length==0){
			showTable==false;
		} else {
			var tS=tableHeaderString(captionString1);
			tS+=tableFooterString();
			if (const_debugMode10==1){
				tS+=debugString();
				//alert("917a writing debugString");
			} else {
				//tS+="<p><a href='Javascript:showTableWidth();'>stw</a></p>";
				//alert("917b NOT writing debugString");
			}
			//alert("833: tS="+tS);
			setHTML('availText',tS, 'div');
			glob_tBod=gObj("dateTable",true);
			tS="";//default
			if (bookMode1form0none==1){
				if (contactPhonePublic.length>0){
					tS="To make a booking, click on the button beside your chosen dates - or call us on "+contactPhonePublic;
				} 
			} else {
				var emailLinkString="<a href='mailto: "+contactEmail+"'>email us</a>";
				if (contactPhonePublic.length>0){
					tS="To book, please call us on "+contactPhonePublic+" or "+emailLinkString;
				} else {
					tS="To book, please "+emailLinkString;
				}
			}
			if ((acceptsPaypal&& !glob_paypalInTable)){
				tS+=HTM_acceptPaypal();
			}
			setHTML('bookingInstrucs',tS, 'p');
			loadFirstPage();
		}
	} 
	if (!showTable){
		setHTML('availText',"Sorry - this system does not currently have any details of availability.", 'div');
		if (contactPhonePublic.length>0){
			tS="Instead, please call us on "+contactPhonePublic;
		} else {
			tS="";
		}
		setHTML('bookingInstrucs',tS, 'p');
	}
	setPageWidth();
	
}
function HTM_acceptPaypal(extraText){
	var tS="<div style='float:right; padding-right: 6px; padding-top: 6px; padding-bottom: 6px'>";
		tS+="<a href='#'' onclick='javascript:explainPayPal();'>";
			tS+="<img  src='http://www.cottageNetwork.com/paypal.gif' border='0' alt='Solution Graphics'>";
		tS+="</a>";
	tS+="</div>";
	//tS+="<div style=''>";
	tS+=extraText+"<br><br>Once we have accepted your booking, you can pay us with<br> any major Credit Card or Debit Card or a PayPal account";
	//tS+="</div>";
	tS+="<div style='clear: both;'></div>";
	
	return tS;
}

