//
// Common functions available to every page in the Estuary Estates website.
//


// Opens a new window for the Google map link on property-details.html
// Called in populatePropertyDetails() function below.

function OpenWindow(theURL, winName, features) {
	window.open(theURL, winName, features);
}




function swapImage(imgPath) {
	var x = document.getElementById("mainImage");
	x.src = imgPath;
}




function getSearchAsArray() {
	var theResults = new Array()
	var input = unescape(location.search.substr(1))
	if (input) {
		var srchArray = input.split("&")
		var tempArray = new Array()
		for (var i = 0; i < srchArray.length; i++) {
			tempArray = srchArray[i].split("=")
			var varForKeyForArray = "'" + tempArray[0] + "'";
			theResults[varForKeyForArray] = tempArray[1]
		}
	}
	return theResults
}



var inComeSelectedArea = "allareas";
var inComechkInclude = "false";
var propDetailsId = "";

function setVariables() {

	var srchArray = getSearchAsArray();
	
	if (location.search) {
		if (srchArray["'chkInclude'"]) { inComechkInclude = srchArray["'chkInclude'"]; }
		if (srchArray["'selectedArea'"]) { inComeSelectedArea = srchArray["'selectedArea'"]; }
		if (srchArray["'propID'"]) { propDetailsId = srchArray["'propID'"]; }
	}
}
setVariables();



function swopAmpersands() {
	var str = new String(inComeSelectedArea);
	str = str.replace(/and/g, "&");
	inComeSelectedArea = str;
}
swopAmpersands();






//////////////// these four function vary in the staff system


/// handle data from the live-properties.js and live-users.js files



function addProperty(propID, theNewArray) {
	if ( typeof(arP) != "undefined" ) {
		arP.push(theNewArray);
	}
}
function adjustPropertiesArray(propID, theNewArray) {
	if ( typeof(arP) != "undefined" ) {
		for (var i = 0; i < arP.length; i++) {
			if ( arP[i][0] == propID ) {
				arP[i] = theNewArray;
			}
		}
	}
}




// called at top of all pages to ensure correct arP creation

function validateData() {
	var itemsInP = arP.length;
	///////////////////////////////////////////////////////////////////////////////////////////////////// to do
	

	for (var i = 0; i < arP.length; i++ ) { 
		if (typeof arP[i][20] != 'undefined' && arP[i][20] != "") {
			itemsInP -= 1;
		}

	}
	if (itemsInP > 0) {
		alert("error");
	}
	else {
		// do nothing
	}
}










// called on all pages to create the search dd list

function BuildSearchDdList() {
	var arrayOfSearchPlaces = new Array();
	var searchAreas = new String();
	var arTemp = new Array();
	//var arTemp = new Array();
	
	// go through aP and create a new Array of live search areas
	for (var i = 0; i < arP.length; i++) {

		if (arP[i][15] == "Yes" && arP[i][22] == "Live") {	// 15 = display on website; 22 = preview or live

			arrayOfSearchPlaces.push(arP[i][17]);

			//arTemp = arP[i][17].split(","); 			// separate multiple search areas
			//for (var j = 0; j < arTemp.length; j++) {
			//	arrayOfSearchPlaces.push(arTemp[j]);
			//}
		}
	}

	// dedupe array and sort alphabet
	var dedupedarrayOfSearchPlaces = new Array();
	var lastPlaceName = "";
	arrayOfSearchPlaces.sort(); 
	for (var i = 0; i < arrayOfSearchPlaces.length; i++ ) { 
		if ( arrayOfSearchPlaces[i] != lastPlaceName ) {
			dedupedarrayOfSearchPlaces.push(arrayOfSearchPlaces[i]);
		}
		lastPlaceName = arrayOfSearchPlaces[i];
	}

	// create html to be returned
	var htmlToReturn = "";			      		
	htmlToReturn += '<select name="searchArea" id="searchArea">';
	htmlToReturn += '<option value="allareas">Select an area...</option>';
	for (var i = 0; i < dedupedarrayOfSearchPlaces.length; i++ ) { 
		if (inComeSelectedArea == dedupedarrayOfSearchPlaces[i]) {
			htmlToReturn += '<option value="' + dedupedarrayOfSearchPlaces[i] + '" selected>' + dedupedarrayOfSearchPlaces[i] + '</option>';
		}
		else {
			htmlToReturn += '<option value="' + dedupedarrayOfSearchPlaces[i] + '">' + dedupedarrayOfSearchPlaces[i] + '</option>';
		}
	}   		
	htmlToReturn += '</select>';

	htmlToReturn += '&nbsp;&nbsp;&nbsp;&nbsp;<label id="lblInclude">Include surrounding area?</label>&nbsp;<input id="chkInclude" name="chkInclude" type="checkbox" class="checkbox"';
	if (inComechkInclude == "true") {
		htmlToReturn += ' checked="checked" ';		
	}
	htmlToReturn += ' />';
	return htmlToReturn;

}

// called by on submit of search form on all pages

function showPropertiesPage(theForm) {
	var str = new String(theForm.searchArea.value);
	str = str.replace(/&/g, "and")
	var urlToGoTo = 'property-for-sale-north-cornwall.html?selectedArea=' + str + '&chkInclude=' + theForm.chkInclude.checked;
	location.href = urlToGoTo;
}










//"New Polzeath", "Polzeath", "Port Isaac", "Rock", "St Minver/Tredrizzick", "St Moritz", "Trebetherick", "Trelights", "Surrounding Areas"
//"NewPolzeath", "Polzeath", "PortIsaac", "Rock", "StMinverTredrizzick", "StMoritz", "Trebetherick", "Trelights", "SurroundingAreas"

//////  when naming use dropdown value with spaces and ampersands removed

var arrayNewPolzeath = new Array("Polzeath", "Rock", "Roserrow", "Trebetherick", "St Minver & Tredrizzick", "St Moritz");
var arrayPolzeath = new Array("New Polzeath", "Rock", "Roserrow", "Trebetherick", "St Minver & Tredrizzick", "St Moritz");
var arrayTrebetherick = new Array("New Polzeath", "Polzeath", "Rock", "Roserrow", "St Minver & Tredrizzick", "St Moritz");
var arrayRock = new Array("New Polzeath", "Polzeath", "Roserrow", "Trebetherick", "St Minver & Tredrizzick", "St Moritz");
var arrayStMoritz = new Array("New Polzeath", "Rock", "Roserrow", "Trebetherick", "St Minver & Tredrizzick");
var arrayRoserrow = new Array("New Polzeath", "Rock", "Trebetherick", "St Minver & Tredrizzick", "St Moritz");

var arrayPortIsaac = new Array("St Minver & Tredrizzick", "Trelights", "Surrounding Areas");
var arrayStMinverTredrizzick = new Array("New Polzeath", "Polzeath", "Port Isaac", "Rock", "Trelights", "Surrounding Areas");
var arrayTrelights = new Array("Port Isaac", "St Minver & Tredrizzick", "Surrounding Areas");
var arraySurroundingAreas = new Array("Port Isaac", "St Minver & Tredrizzick", "Trelights");




// conditionally creates the list of properties on property-for-sale-north-cornwall.html

function populatePropertyList() {
	
	var newHTML = "";

	newHTML += '<table id="tblSurroundingArea" class="propertySummary" cellspacing="10" width="100%">';

	// order by price
	arP.sort(compareShelf4);



	if (inComeSelectedArea != "allareas") {

	    /// properties in the area specified
	    /// properties in the area specified
	    /// properties in the area specified
	    /// properties in the area specified
	    /// properties in the area specified

	    var tempHTML = "";
	    tempHTML += '	<tr>';
	    tempHTML += '		<td colspan="6">';
	    tempHTML += '			<div class="propsectionheader">These are the properties available in the area you selected:</div>';
	    tempHTML += '		</td>';
	    tempHTML += '	</tr>';


	


	    var propSec1Counter = 0;
	    for (var i = 0; i < arP.length; i++) {
	    	if (arP[i][17] == inComeSelectedArea && arP[i][15] == "Yes" && arP[i][22] == "Live") { // if search area found (in list) and display on website = Yes
	            var bedText = " Bedroom"
	            if (arP[i][2] != "1") { bedText = " Bedrooms"; }

	            tempHTML += '	<tr>';
	            tempHTML += '		<td rowspan="2"><a href="property-details.html?propID=' + arP[i][0] + '"><img id="' + arP[i][0] + '" src="images/prop-sm/' + arP[i][0] + '.jpg" onerror="useLargeInstead(\'' + arP[i][0] + '\')" alt="Property for Sale in North Cornwall" width="100px" height="75px"/></a>';
	            tempHTML += '		</td>';
	            tempHTML += '		<td class="doNotJustify"><b>' + arP[i][20] + '</b></td>';
	            tempHTML += '		<td>&pound;' + CommaFormatted(arP[i][4]) + '</td>';
	            tempHTML += '		<td>' + arP[i][2] + bedText + '</td>';
	            tempHTML += '		<td>' + arP[i][16] + '</td>';
	            tempHTML += '		<td><a class="hiddenForPrinting" href="property-details.html?propID=' + arP[i][0] + '">Full&nbsp;Details</a></td>';
	            tempHTML += '	</tr>';
	            tempHTML += '	<tr>';
	            tempHTML += '		<td colspan="5">' + switchOddCharsBackForHTML(arP[i][11]) + '</td>';
	            tempHTML += '	</tr>';
	            tempHTML += '	<tr>';
	            tempHTML += '		<td colspan="6">';
	            tempHTML += '			<div class="lineThin"></div>';
	            tempHTML += '		</td>';
	            tempHTML += '	</tr>';
	            propSec1Counter++;

	        }
	    }
	    if (propSec1Counter > 0) {
	        newHTML += tempHTML;
	    }




	    // properties in nearby areas
	    // properties in nearby areas
	    // properties in nearby areas
	    // properties in nearby areas
	    // properties in nearby areas

	       //"New Polzeath", "Polzeath", "Port Isaac", "Rock", "Roserrow", "St Minver/Tredrizzick", "St Moritz", "Trebetherick", "Trelights", "Surrounding Areas"
	       //"NewPolzeath", "Polzeath", "PortIsaac", "Rock", "Roserrow", "StMinverTredrizzick", "StMoritz", "Trebetherick", "Trelights", "SurroundingAreas"

	    

	    if (inComeSelectedArea == "New Polzeath") { var arrayOfCloseByAreas = arrayNewPolzeath; }
	    else if (inComeSelectedArea == "Polzeath") { var arrayOfCloseByAreas = arrayPolzeath; }
	    else if (inComeSelectedArea == "Port Isaac") { var arrayOfCloseByAreas = arrayPortIsaac; }
	    else if (inComeSelectedArea == "Rock") { var arrayOfCloseByAreas = arrayRock; }
	    else if (inComeSelectedArea == "Roserrow") { var arrayOfCloseByAreas = arrayRoserrow; }
	    else if (inComeSelectedArea == "St Moritz") { var arrayOfCloseByAreas = arrayStMoritz; }
	    else if (inComeSelectedArea == "St Minver & Tredrizzick") { var arrayOfCloseByAreas = arrayStMinverTredrizzick; }
	    else if (inComeSelectedArea == "Trebetherick") { var arrayOfCloseByAreas = arrayTrebetherick; }
	    else if (inComeSelectedArea == "Trelights") { var arrayOfCloseByAreas = arrayTrelights; }
	    else if (inComeSelectedArea == "Surrounding Areas") { var arrayOfCloseByAreas = arraySurroundingAreas; }
	    else {
	        var arrayOfCloseByAreas = new Array();
	    }

	    
	    tempHTML = ""; // reset

	    tempHTML += '	<tr>';
	    tempHTML += '		<td colspan="6">';
	    tempHTML += '			<div class="propsectionheader">These properties are not in the area you specified, but are nearby:</div>';
	    tempHTML += '		</td>';
	    tempHTML += '	</tr>';


	    var propSec2Counter = 0;
	    for (var i = 0; i < arP.length; i++) {
	    	var adjacentArea = "No";

	        for (var j = 0; j < arrayOfCloseByAreas.length; j++) {
				if (arP[i][17] == arrayOfCloseByAreas[j]) {
	            	adjacentArea = "Yes";
	            }
	        }
	        
			if (arP[i][17] != inComeSelectedArea && arP[i][15] == "Yes"  && arP[i][22] == "Live" && adjacentArea == "Yes") {
	            var bedText = " Bedroom"
	            if (arP[i][2] != "1") { bedText = " Bedrooms"; }

	            tempHTML += '	<tr>';
	            tempHTML += '		<td rowspan="2"><a href="property-details.html?propID=' + arP[i][0] + '"><img id="' + arP[i][0] + '" src="images/prop-sm/' + arP[i][0] + '.jpg" onerror="useLargeInstead(\'' + arP[i][0] + '\')" alt="Property for Sale in North Cornwall" width="100px" height="75px"/></a>';
	            tempHTML += '		</td>';
	            tempHTML += '		<td class="doNotJustify"><b>' + arP[i][20] + '</b></td>';
	            tempHTML += '		<td>&pound;' + CommaFormatted(arP[i][4]) + '</td>';
	            tempHTML += '		<td>' + arP[i][2] + bedText + '</td>';
	            tempHTML += '		<td>' + arP[i][16] + '</td>';
	            tempHTML += '		<td><a class="hiddenForPrinting" href="property-details.html?propID=' + arP[i][0] + '">Full&nbsp;Details</a></td>';
	            tempHTML += '	</tr>';
	            tempHTML += '	<tr>';
	            tempHTML += '		<td colspan="5">' + switchOddCharsBackForHTML(arP[i][11]) + '</td>';
	            tempHTML += '	</tr>';
	            tempHTML += '	<tr>';
	            tempHTML += '		<td colspan="6">';
	            tempHTML += '			<div class="lineThin"></div>';
	            tempHTML += '		</td>';
	            tempHTML += '	</tr>';
	            propSec2Counter++;
	        }
	    }
	    if (propSec2Counter > 0) {
	        newHTML += tempHTML;
	    }





	    // left over properties
	    // left over properties
	    // left over properties
	    // left over properties
	    // left over properties




	    if (inComechkInclude == "true") {   // display properties in surrounding areas (which actually means include all the remaining properties).

	        tempHTML = ""; // reset

	        tempHTML += '	<tr>';
	        tempHTML += '		<td colspan="6">';
	        tempHTML += '			<div class="propsectionheader">You may also be interested in these properties:</div>';
	        tempHTML += '		</td>';
	        tempHTML += '	</tr>';

	        var propSec3Counter = 0;
	        for (var i = 0; i < arP.length; i++) {
	            var adjacentArea = "No";
	            for (var j = 0; j < arrayOfCloseByAreas.length; j++) {
	                if (arrayOfCloseByAreas[j] == arP[i][17]) {
	                    adjacentArea = "Yes";
	                }
	            }
	            if (arP[i][17] != inComeSelectedArea && arP[i][15] == "Yes"  && arP[i][22] == "Live" && adjacentArea == "No") {
                    
	                var bedText = " Bedroom"
	                if (arP[i][2] != "1") { bedText = " Bedrooms"; }

	                tempHTML += '	<tr>';
	                tempHTML += '		<td rowspan="2"><a href="property-details.html?propID=' + arP[i][0] + '"><img id="' + arP[i][0] + '" src="images/prop-sm/' + arP[i][0] + '.jpg" onerror="useLargeInstead(\'' + arP[i][0] + '\')" alt="Property for Sale in North Cornwall" width="100px" height="75px"/></a>';
	                tempHTML += '		</td>';
	                tempHTML += '		<td class="doNotJustify"><b>' + arP[i][20] + '</b></td>';
	                tempHTML += '		<td>&pound;' + CommaFormatted(arP[i][4]) + '</td>';
	                tempHTML += '		<td>' + arP[i][2] + bedText + '</td>';
	                tempHTML += '		<td>' + arP[i][16] + '</td>';
	                tempHTML += '		<td><a class="hiddenForPrinting" href="property-details.html?propID=' + arP[i][0] + '">Full&nbsp;Details</a></td>';
	                tempHTML += '	</tr>';
	                tempHTML += '	<tr>';
	                tempHTML += '		<td colspan="5">' + switchOddCharsBackForHTML(arP[i][11]) + '</td>';
	                tempHTML += '	</tr>';
	                tempHTML += '	<tr>';
	                tempHTML += '		<td colspan="6">';
	                tempHTML += '			<div class="lineThin"></div>';
	                tempHTML += '		</td>';
	                tempHTML += '	</tr>';
	                propSec3Counter++;
	            }
	        }
	    }
	    if (propSec3Counter > 0) {
	        newHTML += tempHTML;
	    }
		
		var NoPropsDisplayed = false;
		if (propSec1Counter == 0 && propSec2Counter == 0 && propSec3Counter == 0){
			NoPropsDisplayed = true;
		}
	}


	else if (inComeSelectedArea == "allareas" ||  NoPropsDisplayed == true) {
		// NoPropsDisplayed is a safety net to avoid a blank screen.

	    tempHTML = ""; // reset

	    var propSec4Counter = 0;
	    for (var i = 0; i < arP.length; i++) {
	        if (arP[i][15] == "Yes" && arP[i][22] == "Live") {

	            var bedText = " Bedroom"
	            if (arP[i][2] != "1") { bedText = " Bedrooms"; }

				tempHTML += '	<tr>';
				tempHTML += '		<td rowspan="2"><a href="property-details.html?propID=' + arP[i][0] + '"><img id="' + arP[i][0] + '" src="images/prop-sm/' + arP[i][0] + '.jpg" onerror="useLargeInstead(\'' + arP[i][0] + '\')" alt="Property for Sale in North Cornwall" width="100px" height="75px"/></a>';
				tempHTML += '		</td>';
				tempHTML += '		<td class="doNotJustify"><b>' + arP[i][20] + '</b></td>';
				tempHTML += '		<td>&pound;' + CommaFormatted(arP[i][4]) + '</td>';
				tempHTML += '		<td>' + arP[i][2] + bedText + '</td>';
				tempHTML += '		<td>' + arP[i][16] + '</td>';
				tempHTML += '		<td><a class="hiddenForPrinting" href="property-details.html?propID=' + arP[i][0] + '">Full&nbsp;Details</a></td>';
				tempHTML += '	</tr>';
				tempHTML += '	<tr>';
				tempHTML += '		<td colspan="5">' + switchOddCharsBackForHTML(arP[i][11]) + '</td>';
				tempHTML += '	</tr>';
				tempHTML += '	<tr>';
				tempHTML += '		<td colspan="6">';
				tempHTML += '			<div class="lineThin"></div>';
				tempHTML += '		</td>';
				tempHTML += '	</tr>';
				propSec4Counter++;

	        }
	    }

	    if (propSec4Counter > 0) {
	        newHTML += tempHTML;
	    }

	}


	newHTML += '</table>';
	document.getElementById("listofprops").innerHTML = newHTML;

}





function compareShelf4(a, b) {
	return a[4] - b[4];
}




function useLargeInstead(propIDToUse) {
	var imgSrc = 'images/prop-lg/' + propIDToUse + '-01.jpg';
	document.getElementById(propIDToUse).onerror = "";
	document.getElementById(propIDToUse).src = imgSrc;
}

function hideThisImage(imgID) {
	document.getElementById(imgID).style.display = "none";
}




function populatePropertyDetails() {

	var newHTML = "";

	// propDetailsId set in setVariables()
	
	// find the property in the arP
	for (var i = 0; i < arP.length; i++) {
		if (arP[i][0] == propDetailsId) {
			

			var uniqueBitForString = "";
			var pageUrl = location.href;
			if (pageUrl.indexOf("uid") != -1) {
				uniqueBitForString = '?uid=' + uniqueID;
			}




			if (arP[i][22] == "Preview") {
				// if within staff system 
				if (pageUrl.indexOf("uid") != -1) {
					arP[i][22] = "Live";
					arP[i][15] = "Yes";
				}
			}

			

			if (arP[i][15] == "Yes"  && arP[i][22] == "Live" ) {
				// display online = Yes then show property

				var bedText = " Bedroom"
				if (arP[i][2] != "1") { bedText = " Bedrooms"; }
				
				
				
				
				
				
				if (arP[i][13] == "Sold") {
					soldHTML = '<div class="soldOverlay"></div>';
				}
				


				var soldHTML = "";

				switch (arP[i][13]) {
					case "Sold":
						soldHTML = '<div class="soldOverlay"></div>';
						break;
					case "Under Offer":
						soldHTML = '<div class="underofferOverlay"></div>';
						break;
					case "Sale Agreed":
						soldHTML = '<div class="saleagreedOverlay"></div>';
						break;
					case "Subject to Contract":
						soldHTML = '<div class="subjecttocontractOverlay"></div>';
						break;
				}


				newHTML += '			<div id="propDetails">';
				newHTML += '				Property ID:&nbsp;' + arP[i][0] + '&nbsp;&nbsp;&#124;&nbsp;&nbsp;';
				newHTML += '				<b>' + arP[i][20] + '</b>&nbsp;&nbsp;&#124;&nbsp;&nbsp;';
				newHTML += '				&pound;' + CommaFormatted(arP[i][4]) + '&nbsp;&nbsp;&#124;&nbsp;&nbsp;';
				newHTML += '				' + arP[i][2] + bedText + '&nbsp;&nbsp;&#124;&nbsp;&nbsp;';
				newHTML += '				' + arP[i][10];
				//newHTML += '				&nbsp;&nbsp;&#124;&nbsp;&nbsp;<a href="javascript:OpenWindow(\'http://maps.google.com/maps?q=' + arP[i][8] + ',' + arP[i][9] + '\',\'google-maps\',\'toolbar=1,location=1,status=1,menubar=1,scrollbars=1,resizable=1,top=10,left=10\')">View Map</a>';
				newHTML += '			</div>';
				
				newHTML += '			<div class="lineThin"></div>';
				newHTML += '			<div class="spacer"></div>';

				newHTML += '			<div id="imagesContainer">';
				newHTML += '				<img class="mainImg" id="mainImage" name="mainImage" src="images/prop-lg/' + arP[i][0] + '-01.jpg' + uniqueBitForString + '" width="337" height="253" border="0" alt="Property Image" onerror="hideThisImage(\'mainImage\')" />'
				newHTML += '				' + soldHTML;
				newHTML += '				<br />'
				newHTML += '				<a href="#" onclick="swapImage(\'images/prop-lg/' + arP[i][0] + '-01.jpg\',1);" onmouseover="swapImage(\'images/prop-lg/' + arP[i][0] + '-01.jpg' + uniqueBitForString + '\',1);">'
				newHTML += '				    <img id="smImg1" name="smImg1" class="propImageThumb" src="images/prop-lg/' + arP[i][0] + '-01.jpg' + uniqueBitForString + '" border="0" alt="Property Image" onerror="hideThisImage(\'smImg1\')" />'
				newHTML += '				</a>'
				newHTML += '				<a href="#" onclick = "swapImage(\'images/prop-lg/' + arP[i][0] + '-02.jpg\',1);" onmouseover="swapImage(\'images/prop-lg/' + arP[i][0] + '-02.jpg' + uniqueBitForString + '\',1);">'
				newHTML += '					<img id="smImg2" name="smImg2" class="propImageThumb" src="images/prop-lg/' + arP[i][0] + '-02.jpg' + uniqueBitForString + '" border="0" alt="Property Image"  onerror="hideThisImage(\'smImg2\')" />'
				newHTML += '				</a>'
				newHTML += '				<a href="#" onclick = "swapImage(\'images/prop-lg/' + arP[i][0] + '-03.jpg\',1);" onmouseover="swapImage(\'images/prop-lg/' + arP[i][0] + '-03.jpg' + uniqueBitForString + '\',1);">'
				newHTML += '					<img id="smImg3" name="smImg3" class="propImageThumb" src="images/prop-lg/' + arP[i][0] + '-03.jpg' + uniqueBitForString + '" border="0" alt="Property Image" onerror="hideThisImage(\'smImg3\')" />'
				newHTML += '				</a>'
				newHTML += '				<br />'
				newHTML += '				<a href="#" onclick = "swapImage(\'images/prop-lg/' + arP[i][0] + '-04.jpg\',1);" onmouseover="swapImage(\'images/prop-lg/' + arP[i][0] + '-04.jpg' + uniqueBitForString + '\',1);">'
				newHTML += '					<img id="smImg4" name="smImg4" class="propImageThumb" src="images/prop-lg/' + arP[i][0] + '-04.jpg' + uniqueBitForString + '" border="0" alt="Property Image" onerror="hideThisImage(\'smImg4\')" />'
				newHTML += '				</a>'
				newHTML += '				<a href="#" onclick = "swapImage(\'images/prop-lg/' + arP[i][0] + '-05.jpg\',1);" onmouseover="swapImage(\'images/prop-lg/' + arP[i][0] + '-05.jpg' + uniqueBitForString + '\',1);">'
				newHTML += '					<img id="smImg5" name="smImg5" class="propImageThumb" src="images/prop-lg/' + arP[i][0] + '-05.jpg' + uniqueBitForString + '" border="0" alt="Property Image" onerror="hideThisImage(\'smImg5\')" />'
				newHTML += '				</a>'
				newHTML += '				<a href="#" onclick = "swapImage(\'images/prop-lg/' + arP[i][0] + '-06.jpg\',1);" onmouseover="swapImage(\'images/prop-lg/' + arP[i][0] + '-06.jpg' + uniqueBitForString + '\',1);">'
				newHTML += '					<img id="smImg6" name="smImg6" class="propImageThumb" src="images/prop-lg/' + arP[i][0] + '-06.jpg' + uniqueBitForString + '" border="0" alt="Property Image" onerror="hideThisImage(\'smImg6\')" />'
				newHTML += '				</a>'				
				newHTML += '			</div>';
							
				newHTML += '			<div id="propText">';
				newHTML += '				' + switchOddCharsBackForHTML(arP[i][12]) + '';
				newHTML += '			</div>';
				
			}
			else if (arP[i][15] == "No" || arP[i][22] == "Preview"){
				// display online = No then show message
				newHTML = "<p>This property is not available to view online. Please return to the <a href=\"property-for-sale-north-cornwall.html?selectedArea=allareas&chkInclude=false\">property index</a> and select another property.</p>";
			}	
		}
	}
	
	document.getElementById("propdetails").innerHTML = newHTML;
}


