////////////////////////////////////////////////////////////////////////////////////////////////////////
function loadSite(){


//update alias
outputAlias("", siteAlias, listingTypeId, siteStorenum);

//remove all previous broker info, output new list 
removeChildren(document.getElementById("emailIcon"));
removeChildren(document.getElementById("email"));
removeChildren(document.getElementById("brokerphone"));
outputAllBrokers(brokerList, null);

//remove list of lots, output new list
removeChildren(document.getElementById("lots"));
outputAllLots(null);

//update additional information
outputInfo("", siteInfo);

//remove previous list of categories, output new list
//removeChildren(document.getElementById("catTitle"));
removeChildren(document.getElementById("category"));
outputAllCategories(categoryList);

getSiteIntroImage();
loadMediaPanel(1,null);
currLotid = null;

}

////////////////////////////////////////////////////////////////////////////////////////////////////////
function loadpage(){
	
	//document.images["picframe"].width = 420;
	//document.images["picframe"].height = 300;
	
	outputAddress();

	document.images["logo"].src = logoPath;
	
	var type = document.createTextNode(listingType);
	document.getElementById("listingtype").appendChild(type);
	
	//alert(demoYear);
	if(demoYear != undefined){
		
		writeDemoFile(demoYear, demoMapFileName);
		
		if(demoMile != undefined){
			writeDemoMiles(demoMile);	
		}
	}
	//alert("skipped demos");
	//if only one lot and site is not lowes listing display lot first
	if(listingTypeId != 1){
		
		lotCount = lot.length;
		if(lotCount < 2){
			displayLot(null);
			return;
		}
		
	}
	
	//alert("did not exit");
	
	outputAlias(null, siteAlias, listingTypeId, siteStorenum);
	outputInfo(null, siteInfo);

	//load default image
	getSiteIntroImage();

	loadMediaPanel(1,null);
	
	outputAllBrokers(brokerList, null);

	outputAllCategories(categoryList);
		
	outputAllLots(null);

	
}


/////////////////////////////////////////////////////////////////////////////////////////////
function displayLot(element){

if(element != null){
	lotIndex = parseInt(element.id);
	//alert("Parse int - "+lotIndex);
}
else{
	lotIndex = 0;	
}

currLotid = lot[lotIndex][0];
outputAlias(lot[lotIndex][1], siteAlias, listingTypeId, siteStorenum);
outputInfo(lot[lotIndex][9], siteInfo);

//remove list of brokers, output new list
removeChildren(document.getElementById("emailIcon"));
removeChildren(document.getElementById("email"));
removeChildren(document.getElementById("brokerphone"));
outputAllBrokers(lotBroker[lotIndex], lotIndex);

//output lot list
removeChildren(document.getElementById("lots"));
outputAllLots(lotIndex);

//output category list
removeChildren(document.getElementById("category"));
outputAllCategories(lotCategory[lotIndex]);

//get intro image for initial display
getLotIntroImage(lotIndex);
loadMediaPanel(2, lotIndex);

}

///////////////////////////////////////////////////////////////////////////////////////////////
function outputAllLots(activeLot){

var cnt = lot.length;
//alert(cnt);
var strLot; 
var txtSpan;
var el_span;
var el_anchor_lot;
var el_anchor_site;

//no lots have been selected so site overview is assumed
if(activeLot == null){
	
	
	el_span = document.createElement("span");
	el_span.style.color = "#007961";
	//el_span.style.weight = "bold";
	el_span.style.cursor = "text";
	el_span.style.textDecoration = "none";

	txtSpan = document.createTextNode("Location Overview");	
	el_span.appendChild(txtSpan);
	
	//el_span.appendChild(txtSpan);
	document.getElementById("lots").appendChild(el_span);
	
	//insert a line break
	lineBreak = document.createElement("br");
	document.getElementById("lots").appendChild(lineBreak);
	//alert("Lot is Null");
	
}
//a lot has been selected change site overview propertis
else{
	//create and append a span element to element "lots"
	el_span = document.createElement("span");
	el_span.style.color = "#007961";
	el_span.style.cursor = "pointer";
	el_span.style.textDecoration = "underline";
	el_span.onclick = function() {loadSite();}
	
	txtSpan = document.createTextNode("Location Overview");
	el_span.appendChild(txtSpan);
	document.getElementById("lots").appendChild(el_span);
	
	lineBreak = document.createElement("br");
	document.getElementById("lots").appendChild(lineBreak);
	
}
///////////////// Loop through all lots and output to page
for(arrIndex=0; arrIndex<cnt; arrIndex++){
//alert(lot[arrIndex][11]);
	//alert("Lot count- "+cnt+" Lot arrIndex "+arrIndex);
	if(arrIndex == activeLot){
		
		//lot is flagged as being sold or leased, change font to red, also
		//deactivate link user is currently viewing this lot
		if(lot[arrIndex][10] == 1){
			//create and append a span element to element "lots"
			el_span = document.createElement("span");
			el_span.style.color = "#FF0000";
			el_span.style.cursor = "text";
			el_span.style.textDecoration = "none";
			el_span.setAttribute("id", arrIndex);
			//create a textnode and append to 			
			strLot = lot[arrIndex][4] +" "+ lot[arrIndex][6] + " " +lot[arrIndex][5];
			
			txtSpan = document.createTextNode(strLot);
			el_span.appendChild(txtSpan);
			
			document.getElementById("lots").appendChild(el_span);
			//insert a line break
			lineBreak = document.createElement("br");
			document.getElementById("lots").appendChild(lineBreak);
		}
		else{
			el_span = document.createElement("span");
			el_span.style.color = "#007961";
			el_span.style.cursor = "text";
			el_span.style.textDecoration = "none";
			el_span.setAttribute("id", arrIndex);
			//el_span.onclick = function() {loadSite();}
			
			if(lot[arrIndex][7] != ''){
				
				strLot = lot[arrIndex][4] +" "+ lot[arrIndex][6]+ " " +lot[arrIndex][5]+ " " +lot[arrIndex][7];
				
				if(lot[arrIndex][11] == 2){
					strLot = strLot + ' ac';
				}
				else{
					strLot = strLot + ' sf';
				}
			}
			else{
				strLot = lot[arrIndex][4] +" "+ lot[arrIndex][6]+ " " +lot[arrIndex][5];
			
			}
			
			txtSpan = document.createTextNode(strLot);
			el_span.appendChild(txtSpan);
			document.getElementById("lots").appendChild(el_span);
			
			
			lineBreak = document.createElement("br");
			document.getElementById("lots").appendChild(lineBreak);

		}
	}
	else{
		if(lot[arrIndex][10] == 1){
			
			el_span = document.createElement("span");
			el_span.style.color = "#FF0000";
			el_span.style.cursor = "pointer";
			el_span.style.textDecoration = "underline";
			el_span.setAttribute("id", arrIndex);
			
			strLot = lot[arrIndex][4] +" "+ lot[arrIndex][6]+ " " +lot[arrIndex][5];

			txtSpan = document.createTextNode(strLot);
			el_span.appendChild(txtSpan);
			document.getElementById("lots").appendChild(el_span);
			
			el_span.onclick = function() {displayLot(this);}
			
			lineBreak = document.createElement("br");
			document.getElementById("lots").appendChild(lineBreak);
		}
		else{
			
			el_span = document.createElement("span");
			el_span.style.color = "#007961";
			el_span.style.cursor = "pointer";
			el_span.style.textDecoration = "underline";
			el_span.setAttribute("id", arrIndex);
			//alert(el_span.getAttribute("id"));
			
			if(lot[arrIndex][7] != ''){
				
				strLot = lot[arrIndex][4] +" "+ lot[arrIndex][6]+ " " +lot[arrIndex][5]+ " " +lot[arrIndex][7];
				
				if(lot[arrIndex][11] == 2){
					strLot = strLot + ' ac';
				}
				else{
					strLot = strLot + ' sf';
				}
			}
			else{
				strLot = lot[arrIndex][4] +" "+ lot[arrIndex][6]+ " " +lot[arrIndex][5];
			}
			txtSpan = document.createTextNode(strLot);
			el_span.appendChild(txtSpan);
			document.getElementById("lots").appendChild(el_span);
			
			el_span.onclick = function() {displayLot(this);}
			
			lineBreak = document.createElement("br");
			document.getElementById("lots").appendChild(lineBreak);

		}
	}

}

}
////////////////////////////////////////////////////////////////////////////////////////////////////////
function l_loadsiteplans(lotIndex){
	
	activatePreviousLotMedia(lotIndex, currMedia);
	document.images["picframe"].src = l_siteplans[lotIndex][currIndex][4];
	document.getElementById("frameanchor").setAttribute("href",l_siteplans[lotIndex][currIndex][0]);
	document.getElementById("frameanchor").setAttribute("target", "_blank");
	document.getElementById("frameanchor").setAttribute("alt", l_siteplans[lotIndex][currIndex][1]);
	document.getElementById("frameanchor").setAttribute("title", l_siteplans[lotIndex][currIndex][1]);

	currMedia = 1;
	currMediaid = l_siteplans[lotIndex][currIndex][5];
	
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
function l_loadaerials(lotIndex){
	
	activatePreviousLotMedia(lotIndex, currMedia);
	document.images["picframe"].src = l_aerials[lotIndex][currIndex][4];
	document.getElementById("frameanchor").setAttribute("href",l_aerials[lotIndex][currIndex][0]);
	document.getElementById("frameanchor").setAttribute("target", "_blank");
	document.getElementById("frameanchor").setAttribute("alt", l_aerials[lotIndex][currIndex][1]);
	document.getElementById("frameanchor").setAttribute("title", l_aerials[lotIndex][currIndex][1]);

	currMedia = 2;
	currMediaid = l_aerials[lotIndex][currIndex][5];

}
////////////////////////////////////////////////////////////////////////////////////////////////////////
function l_loadphotos(lotIndex){
		
	activatePreviousLotMedia(lotIndex, currMedia);
	document.images["picframe"].src = l_photos[lotIndex][currIndex][4];
	document.getElementById("frameanchor").setAttribute("href",l_photos[lotIndex][currIndex][0]);
	document.getElementById("frameanchor").setAttribute("target", "_blank");
	document.getElementById("frameanchor").setAttribute("alt", l_photos[lotIndex][currIndex][1]);
	document.getElementById("frameanchor").setAttribute("title", l_photos[lotIndex][currIndex][1]);
	
	currMedia = 4;
	currMediaid = l_photos[lotIndex][currIndex][5];
}


////////////////////////////////////////////////////////////////////////////////////////////////////////
function s_loadsiteplans(){
	
	activatePreviousSiteMedia(currMedia);
	document.images["picframe"].src = s_siteSiteplans[currIndex][4];
	document.getElementById("frameanchor").setAttribute("href",s_siteSiteplans[currIndex][0]);
	document.getElementById("frameanchor").setAttribute("target", "_blank");
	document.getElementById("frameanchor").setAttribute("alt", s_siteSiteplans[currIndex][1]);
	document.getElementById("frameanchor").setAttribute("title",s_siteSiteplans[currIndex][1]);
	
	currMedia = 1;
	currMediaid = s_siteSiteplans[currIndex][5];
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////
function s_loadaerials(){

	activatePreviousSiteMedia(currMedia);
	document.images["picframe"].src = s_siteAerials[currIndex][4];
	document.getElementById("frameanchor").setAttribute("href",s_siteAerials[currIndex][0]);
	document.getElementById("frameanchor").setAttribute("target", "_blank");
	document.getElementById("frameanchor").setAttribute("alt", s_siteAerials[currIndex][1]);
	document.getElementById("frameanchor").setAttribute("title",s_siteAerials[currIndex][1]);
	
	currMedia = 2;
	currMediaid = s_siteAerials[currIndex][5];
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
function s_loadstreetmaps(){

	activatePreviousSiteMedia(currMedia);
	document.images["picframe"].src = s_siteStreetmaps[currIndex][4];
	document.getElementById("frameanchor").setAttribute("href",s_siteStreetmaps[currIndex][0]);
	document.getElementById("frameanchor").setAttribute("target", "_blank");
	document.getElementById("frameanchor").setAttribute("alt", s_siteStreetmaps[currIndex][1]);
	document.getElementById("frameanchor").setAttribute("title",s_siteStreetmaps[currIndex][1]);
	
	currMedia = 3;
	currMediaid = s_siteStreetmaps[currIndex][5];
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
function s_loadphotos(){
	
	activatePreviousSiteMedia(currMedia);
	document.images["picframe"].src = s_sitePhotos[currIndex][4];
	document.getElementById("frameanchor").setAttribute("href", s_sitePhotos[currIndex][0]);
	document.getElementById("frameanchor").setAttribute("target", "_blank");
	document.getElementById("frameanchor").setAttribute("alt", s_sitePhotos[currIndex][1]);
	document.getElementById("frameanchor").setAttribute("title",s_sitePhotos[currIndex][1]);

	currMedia = 4;
	currMediaid = s_sitePhotos[currIndex][5];
}

//////////////////////////////////////////////////////////////////////////////////////////////////
function writeDemoFile(year, file){

var str;	
	
if(year != undefined){
	
	str = year+" Demographics";
	var year = document.createTextNode(str);
	document.getElementById("demoyear").appendChild(year);
}

if(file != undefined){
	
	//create and add hyperlink
	var el_anchor = document.createElement("a");
	el_anchor.setAttribute("id", "demofile");
	el_anchor.setAttribute("href", file);
	el_anchor.setAttribute("target", "_blank");
	document.getElementById("demo").appendChild(el_anchor);
	
	//add text to hyperlink
	var txtDownload = document.createTextNode("Download Demos");
	document.getElementById("demofile").appendChild(txtDownload);

}
}

//////////////////////////////////////////////////////////////////////////////////////////////////
function writeDemoMiles(arrMile){

var strDemo;

//alert(arrMile[0][0]);
	
strDemo = "Pop-Project " + projectYear;
var demo = document.createTextNode(strDemo);
document.getElementById("popproheader").appendChild(demo);

strDemo = "Pop-Present " + presentYear;
var demo = document.createTextNode(strDemo);
document.getElementById("poppreheader").appendChild(demo);

strDemo = "Average HH Income";
var demo = document.createTextNode(strDemo);
document.getElementById("median").appendChild(demo);

strDemo = "Mile "+arrMile[0][0];
var demo = document.createTextNode(strDemo);
document.getElementById("mileone").appendChild(demo);

strDemo =  "Mile "+arrMile[1][0];
var demo = document.createTextNode(strDemo);
document.getElementById("miletwo").appendChild(demo);

strDemo = "Mile "+arrMile[2][0];
var demo = document.createTextNode(strDemo);
document.getElementById("milethree").appendChild(demo);

strDemo = arrMile[0][2];
var demo = document.createTextNode(strDemo);
document.getElementById("popFutureOne").appendChild(demo);

strDemo = arrMile[1][2];
var demo = document.createTextNode(strDemo);
document.getElementById("popFutureTwo").appendChild(demo);

strDemo = arrMile[2][2];
var demo = document.createTextNode(strDemo);
document.getElementById("popFutureThree").appendChild(demo);

strDemo = arrMile[0][1];
var demo = document.createTextNode(strDemo);
document.getElementById("popPresentOne").appendChild(demo);

strDemo = arrMile[1][1];
var demo = document.createTextNode(strDemo);
document.getElementById("popPresentTwo").appendChild(demo);

strDemo = arrMile[2][1];
var demo = document.createTextNode(strDemo);
document.getElementById("popPresentThree").appendChild(demo);

strDemo = "$ "+arrMile[0][3];
var demo = document.createTextNode(strDemo);
document.getElementById("medianOne").appendChild(demo);

strDemo = "$ "+arrMile[1][3];
var demo = document.createTextNode(strDemo);
document.getElementById("medianTwo").appendChild(demo);

strDemo = "$ "+arrMile[2][3];
var demo = document.createTextNode(strDemo);
document.getElementById("medianThree").appendChild(demo);

}
////////////////////////////////////////////////////////////////////////////////////////////////////
function removeChildren(parent){
//alert(parent);	
//alert(parent.hasChildNodes());

if(parent != null){
	if(parent.hasChildNodes()){
		//alert(parent.hasChildNodes());
		 while ( parent.childNodes.length >= 1 )
			{
					//alert(parent.childNodes[inc]);
				parent.removeChild( parent.firstChild );       
				//alert(parent.childNodes[inc]);
				
			} 
	}
}
}




/////////////////////////////////////////////////////////////////////////////////////////////////////
function outputAlias(lotAlias, siteAlias, listingTypeId, siteStorenum){

var alias;

if(siteAlias == ''){
	if(streetNum != ''){
		siteAlias = streetNum +" "+ street;		
	}
	else{
		if(crossStreet != ''){
			siteAlias = street +" & "+ crossStreet;
		}
		else{
			siteAlias = street;	
		}
	}
}
//alert(listingTypeId);
//alert(siteStorenum);

//lot index is set output lot alias if available
if((lotAlias) && (lotAlias !="")){
	
	//check for existing text node, if true then replace old text with new text
	if(document.getElementById("sitealias").hasChildNodes()){
		
		removeChildren(document.getElementById("sitealias"));
		alias = document.createTextNode(lotAlias);
		document.getElementById("sitealias").appendChild(alias);	
	}
	else{
		//alert(lotAlias);
		//no text nodes detected, create and append text node
		alias = document.createTextNode(lotAlias);
		//alert(txtAliasNode);
		document.getElementById("sitealias").appendChild(alias);
	}
}
//lot index not set, out put site alias
else{
	
	if(listingTypeId == 1){
		siteAlias = "#" + siteStorenum + " " + siteAlias;
	}
	
	if(document.getElementById("sitealias").hasChildNodes()){
		
		removeChildren(document.getElementById("sitealias"));
		alias = document.createTextNode(siteAlias);
		document.getElementById("sitealias").appendChild(alias);	
		
	}
	//text node does not exist, create new text node
	else{
		alias = document.createTextNode(siteAlias);
		document.getElementById("sitealias").appendChild(alias);
	}
	
}
}//end function
///////////////////////////////////////////////////////////////////////////////////////////////////////
function outputInfo(lotInfo, siteInfo){
var info;	

try{
	//lot index is set output lot info if available
	if((lotInfo) && (lotInfo !="")){
	
	//if(document.getElementById("info").hasChildNodes()){
		
		//removeChildren(document.getElementById("info"));
		document.getElementById("info").innerHTML = lotInfo;
		//info = document.createTextNode(siteInfo);
		//document.getElementById("info").appendChild(info);
	//}
	//else{
		//info = document.createTextNode(siteInfo);
		//document.getElementById("info").appendChild(info);
	//}
	
	
	//document.getElementById("info").innerHTML = lotInfo;
	}
	//lot index not set, out put site alias
	else{
		
		if((siteInfo) && (siteInfo != "")){
		
		/*if(document.getElementById("info").hasChildNodes()){
		
			removeChildren(document.getElementById("info"));
			*/
			document.getElementById("info").innerHTML = siteInfo;
			/*
			info = document.createTextNode(siteInfo);
			document.getElementById("info").appendChild(info);
		}
		else{
			info = document.createTextNode(siteInfo);
			document.getElementById("info").appendChild(info);
		}
	}
	else{
		document.getElementById("info").innerHTML = "&nbsp;";	
	*/
	}
}

}
	catch(err){
		document.getElementById("info").innerHTML = "Error: Displaying Info";
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////
function outputAllCategories(arrCategory){

var strCategory //contains text category listing
var currCategory;//loop incrementor
//alert(arrCategory);
var numCategories = arrCategory.length;

var newDiv = document.createElement("div");

newDiv.setAttribute("id", "catTitle");
newDiv.style.color = "#000000";
//newDiv.style.textAlign = "center";
newDiv.style.paddingBottom = "5px";
newDiv.style.textDecoration = "underline";

var title = document.createTextNode("Proposed Uses:");
newDiv.appendChild(title);
//var lineBreak = document.createElement("br");
document.getElementById("category").appendChild(newDiv);

//alert("number of categories"+numCategories);
for (currCategory=0; currCategory<numCategories; currCategory++){

	newDiv = document.createElement("div");
	newDiv.setAttribute("id", "catlist");
	newDiv.setAttribute("class","uses");
	newDiv.style.color = "#007961";
		
	strCategory = document.createTextNode(arrCategory[currCategory][1]);
	newDiv.appendChild(strCategory);
	
	document.getElementById("category").appendChild(newDiv);
}

}

/////////////////////////////////////////////////////////////////////////////
function outputAddress(){

var strAddress="";
var txtNode;
var googlelink = "http://maps.google.com/?q="+lat+"+"+lng;

	//txtNode = document.createTextNode(addrTxt);
	
	
	if(streetNum != ""){
		strAddress = streetNum +" "+street;
	}
	else{
		strAddress = street;
	}
	
	//insert text
	txtNode = document.createTextNode(strAddress);
	document.getElementById("address").appendChild(txtNode);
	
	
	if(crossStreet != ""){
		strAddress = " & "+crossStreet;
	
		//insert text
		txtNode = document.createTextNode(strAddress);
		document.getElementById("address").appendChild(txtNode);
		
	}		
		
	if(suiteNum != ""){
		
		//add break here
		var lineBreak = document.createElement("br");
		document.getElementById("address").appendChild(lineBreak);
		
		strAddress = "Suite Number "+suiteNum;
	
		//insert text
		txtNode = document.createTextNode(strAddress);
		document.getElementById("address").appendChild(txtNode);
		
	
	}
	
	//add break here
	var lineBreak = document.createElement("br");
	document.getElementById("address").appendChild(lineBreak);

strAddress = city + ", " +	state +" "+ zip;
	
	//insert text
	txtNode = document.createTextNode(strAddress);
	document.getElementById("address").appendChild(txtNode);
	
	var el_div = document.createElement("div");
	el_div.setAttribute("id", "divmap");
	document.getElementById("address").appendChild(el_div);
	
	//document.getElementById("address").appendChild(lineBreak);
	//alert(googlelink);
	var el_anchor = document.createElement("a");
	el_anchor.setAttribute("id", "maplink");
	el_anchor.setAttribute("href", googlelink);
	el_anchor.setAttribute("target", "_blank");
	document.getElementById("divmap").appendChild(el_anchor);
	document.getElementById("maplink").appendChild(document.createTextNode("Map"));
	

//alert(strAddress);
//return strAddress;
}


///////////////////////////////////////////////////////////////////////////////////////////////
function outputAllBrokers(arrBroker, lotIndex){

var currBroker;
var el_anchor_mailto;
var el_anchor_mailtoPic
var el_anchor_href;
var el_image;
var strBroker;
var brokername;
var brokerPhone;
var alttxt;
var el_anchor_broker;
var strBrokerName;
var el_div;
//display all brokers associated to overall site
if(lotIndex == null){
	
	var numBrokers = arrBroker.length;
	
	//loop through all brokers 
	for (currBroker=0; currBroker<numBrokers; currBroker++){
	
		/////////////// Output email link(pic) ////////////////////////////////
		
		//create anchor for email Icon
		el_anchor_mailtoPic = document.createElement("a");
		el_anchor_href = "mailto:"+ arrBroker[currBroker][4];
		el_anchor_mailtoPic.setAttribute("href", el_anchor_href);
		el_anchor_mailtoPic.setAttribute("id", "mailtoPic");
		
		//create image element
		el_image = document.createElement("img");
		el_image.setAttribute("id", "emailpic");
		alttxt = "Email " + arrBroker[currBroker][1];
		el_image.setAttribute("alt", alttxt);
		el_image.setAttribute("title", alttxt);
		el_image.setAttribute("border", "0");
		el_image.setAttribute("src", "../assets/Email.png");
		
		//append image(child) to mail anchor
		el_anchor_mailtoPic.appendChild(el_image);
		//append mail anchor(child) to div element
		el_div = document.createElement("div");
		el_div.appendChild(el_anchor_mailtoPic);
		
		//append children to element
		document.getElementById("emailIcon").appendChild(el_div);		
		
		/////////////// Output associate link(text) ////////////////////////////////
		
		//create anchor for email Name
		el_anchor_mailto = document.createElement("a");
		//el_anchor_href = "mailto:"+ arrBroker[currBroker][4];
		el_anchor_href = "Associate.php?brokerid=" + arrBroker[currBroker][0]
		el_anchor_mailto.setAttribute("href", el_anchor_href);
		el_anchor_mailto.setAttribute("id", "mailtoText");
		//create text node 
		strBrokerName = arrBroker[currBroker][1] +" "+ arrBroker[currBroker][2];
		brokername = document.createTextNode(strBrokerName);		
		//append textNode
		el_anchor_mailto.appendChild(brokername);
		//create civ element
		el_div = document.createElement("div");
		el_div.style.paddingBottom = "8px";
		
		//append anchor to div
		el_div.appendChild(el_anchor_mailto);
		
		//append children to element
		document.getElementById("email").appendChild(el_div);
		
		/////////////// Output Phone Number ////////////////////////////////
		strBrokerPhone = arrBroker[currBroker][3];
		//alert(arrBroker[currBroker][3])
		brokerPhone = document.createTextNode(strBrokerPhone);
		
		//create civ element
		el_div = document.createElement("div");
		el_div.style.paddingBottom = "5px";
		
		el_div.appendChild(brokerPhone);
		document.getElementById("brokerphone").appendChild(el_div);
		
	}
}

//display only brokers associated to selected lot
else{
	
	var numBrokers = arrBroker.length;
	
	//loop through all lot brokers 
	for (currBroker=0; currBroker<numBrokers; currBroker++){
		
		/////////////// Output email link(pic) ////////////////////////////////
		
		//create anchor for email Icon
		el_anchor_mailtoPic = document.createElement("a");
		el_anchor_href = "mailto:"+ arrBroker[currBroker][14];
		el_anchor_mailtoPic.setAttribute("href", el_anchor_href);
		el_anchor_mailtoPic.setAttribute("id", "mailtoPic");
		
		//create image element
		el_image = document.createElement("img");
		el_image.setAttribute("id", "emailpic");
		alttxt = "Email " + arrBroker[currBroker][1];
		el_image.setAttribute("alt", alttxt);
		el_image.setAttribute("title", alttxt);
		el_image.setAttribute("border", "0");
		el_image.setAttribute("src", "../assets/Email.png");
		
		//append image(child) to mail anchor
		el_anchor_mailtoPic.appendChild(el_image);
		//append mail anchor(child) to div element
		el_div = document.createElement("div");
		el_div.appendChild(el_anchor_mailtoPic);
		
		//append children to element
		document.getElementById("emailIcon").appendChild(el_div);		
		
		/////////////// Output email link(text) ////////////////////////////////
		
		//create anchor for email Name
		el_anchor_mailto = document.createElement("a");
		el_anchor_href = "Associate.php?brokerid="+ arrBroker[currBroker][0];
		el_anchor_mailto.setAttribute("href", el_anchor_href);
		el_anchor_mailto.setAttribute("id", "mailtoText");
		//create text node 
		strBrokerName = arrBroker[currBroker][1] +" "+ arrBroker[currBroker][2];
		brokername = document.createTextNode(strBrokerName);		
		//append textNode
		el_anchor_mailto.appendChild(brokername);
		//create civ element
		el_div = document.createElement("div");
		el_div.style.paddingBottom = "8px";
		
		//append anchor to div
		el_div.appendChild(el_anchor_mailto);
		
		//append children to element
		document.getElementById("email").appendChild(el_div);
		
		/////////////// Output Phone Number ////////////////////////////////
		strBrokerPhone = arrBroker[currBroker][9];
		brokerPhone = document.createTextNode(strBrokerPhone);
		
		//create civ element
		el_div = document.createElement("div");
		el_div.style.paddingBottom = "5px";
		
		el_div.appendChild(brokerPhone);
		document.getElementById("brokerphone").appendChild(el_div);
		
	}
}
}

//////////////////////////////////////////////////////////////////////////////////////////////////
function getLotIntroImage(lotIndex){
var image = "";
var thumb = "";
var alt = "";
var title = "";
var cnt = l_siteplans[lotIndex].length;
var inc;
var exitFlag = 0;

//start with site plans for introimage
for(inc=0; inc<cnt; inc++){

	if(l_siteplans[lotIndex][inc][3] == 1){
		image = l_siteplans[lotIndex][inc][0];
		thumb = l_siteplans[lotIndex][inc][4];
		alt = l_siteplans[lotIndex][inc][1];
		title = l_siteplans[lotIndex][inc][1];
		currMedia = 1;
		currMediaid = l_siteplans[lotIndex][inc][5];
		currIndex = inc;
		exitFlag = 1;
	} 	
}

//exit flag not set continue looking for default image to display
if(!exitFlag == 1){
	
	cnt = l_aerials[lotIndex].length;
	for(inc=0; inc<cnt; inc++){

		if(l_aerials[lotIndex][inc][3] == 1){
			image = l_aerials[lotIndex][inc][0];
			thumb = l_aerials[lotIndex][inc][4];
			alt = l_aerials[lotIndex][inc][1];
			title = l_aerials[lotIndex][inc][1];
			currMedia = 2;
			currMediaid = l_aerials[lotIndex][inc][5];
			currIndex = inc;
			exitFlag = 1;
		} 	
	}
}


if(!exitFlag == 1){
	
	cnt = l_photos[lotIndex].length;
	for(inc=0; inc<cnt; inc++){

		if(l_photos[lotIndex][inc][3] == 1){
			image = l_photos[lotIndex][inc][0];
			thumb = l_photos[lotIndex][inc][4];
			alt = l_photos[lotIndex][inc][1];
			title = l_photos[lotIndex][inc][1];
			currMedia = 4;
			currMediaid = l_photos[lotIndex][inc][5];
			currIndex = inc;
			exitFlag = 1;
		} 	
	}
}

//if no intro image found set one here, change order of media to change default
//introimage to set
if(!exitFlag == 1){
	cnt = l_photos[lotIndex].length;
	if(cnt > 0){
		image = l_photos[lotIndex][0][0];
		thumb = l_photos[lotIndex][0][4];
		alt = l_photos[lotIndex][0][1];
		title =l_photos[lotIndex][0][1];
		currMedia = 4;
		currMediaid = l_photos[lotIndex][0][5];
		currIndex = 0;
		exitFlag = 1;
	}
}

if(!exitFlag == 1){
	cnt = l_siteplans[lotIndex].length;
	if(cnt > 0){
		image = l_siteplans[lotIndex][0][0];
		thumb = l_siteplans[lotIndex][0][4];
		alt = l_siteplans[lotIndex][0][1];
		title = l_siteplans[lotIndex][0][1];
		currMedia = 1;
		currMediaid = l_siteplans[lotIndex][0][5];
		currIndex = 0;
		exitFlag = 1;
	}
}

if(!exitFlag == 1){
	cnt = l_aerials[lotIndex].length;
	if(cnt > 0){
		image = l_aerials[lotIndex][0][0];
		thumb = l_aerials[lotIndex][0][4];
		alt = l_aerials[lotIndex][0][1];
		title = l_aerials[lotIndex][0][1];
		currMedia = 2;
		currMediaid = l_aerials[lotIndex][0][5];
		currIndex = 0;
		exitFlag = 1;
	}
}

//load selected image into viewer
document.getElementById("frameanchor").setAttribute("target", "_blank");
document.getElementById("frameanchor").setAttribute("alt", alt);
document.getElementById("frameanchor").setAttribute("title",title);


if(thumb != ""){
	document.images["picframe"].src = thumb;
}
else{
	document.images["picframe"].src = noMedia;

}

if(image != ''){
	document.getElementById("frameanchor").setAttribute("href",image);
}
else{
	document.getElementById("frameanchor").setAttribute("href","#");	
}

}
////////////////////////////////////////////////////////////////////////////////////////////////////
function getSiteIntroImage(){
var image = "";
var thumb = "";
var alt = "";
var title = "";
var cnt = s_siteSiteplans.length;
var inc;
var exitFlag = 0;

//start with site plans for introimage
for(inc=0; inc<cnt; inc++){

	if(s_siteSiteplans[inc][3] == 1){
		
		image = s_siteSiteplans[inc][0];
		thumb = s_siteSiteplans[inc][4];
		alt = s_siteSiteplans[inc][1];
		title = s_siteSiteplans[inc][1];
		
		currMedia = 1;
		currMediaid = s_siteSiteplans[inc][5];
		currIndex = inc;
		exitFlag = 1;
	} 	
}

//exit flag not set continue looking for default image to display
if(!exitFlag == 1){
	
	cnt = s_siteAerials.length;
	for(inc=0; inc<cnt; inc++){

		if(s_siteAerials[inc][3] == 1){
			image = s_siteAerials[inc][0];
			thumb = s_siteAerials[inc][4];
			alt = s_siteAerials[inc][1];
			title = s_siteAerials[inc][1];
			currMedia = 2;
			currMediaid = s_siteAerials[inc][5];
			currIndex = inc;
			exitFlag = 1;
		} 	
	}
}

//exit flag not set continue looking for default image to display
if(!exitFlag == 1){
	
	cnt = s_siteStreetmaps.length;
	for(inc=0; inc<cnt; inc++){

		if(s_siteStreetmaps[inc][3] == 1){
			image = s_siteStreetmaps[inc][0];
			thumb = s_siteStreetmaps[inc][4];
			alt = s_siteStreetmaps[inc][1];
			title = s_siteStreetmaps[inc][1];
			currMedia = 3;
			currMediaid = s_siteStreetmaps[inc][5];
			currIndex = inc;
			exitFlag = 1;
		} 	
	}
}

if(!exitFlag == 1){
	
	cnt = s_sitePhotos.length;
	for(inc=0; inc<cnt; inc++){

		if(s_sitePhotos[inc][3] == 1){
			image = s_sitePhotos[inc][0];
			thumb = s_sitePhotos[inc][4];
			alt = s_sitePhotos[inc][1];
			title = s_sitePhotos[inc][1];
			currMedia = 4;
			currMediaid = s_sitePhotos[inc][5];
			currIndex = inc;
			exitFlag = 1;
		} 	
	}
}

//if no intro image found set one here, change order of media to change default
//introimage to set
if(!exitFlag == 1){
	cnt = s_siteSiteplans.length;
	if(cnt > 0){
		image = s_siteSiteplans[0][0];
		thumb = s_siteSiteplans[0][4];
		alt = s_siteSiteplans[0][1];
		title = s_siteSiteplans[0][1];
		currMedia = 1;
		currMediaid = s_siteSiteplans[0][5];
		currIndex = 0;
		exitFlag = 1;
	}
}

if(!exitFlag == 1){
	cnt = s_sitePhotos.length;
	if(cnt > 0){
		image = s_sitePhotos[0][0];
		thumb = s_sitePhotos[0][4];
		alt = s_sitePhotos[0][1];
		title = s_sitePhotos[0][1];
		currMedia = 4;
		currMediaid = s_sitePhotos[0][5];
		currIndex = 0;
		exitFlag = 1;
	}
}

if(!exitFlag == 1){
	cnt = s_siteAerials.length;
	if(cnt > 0){
		image = s_siteAerials[0][0];
		thumb = s_siteAerials[0][4];
		alt = s_siteAerials[0][1];
		title = s_siteAerials[0][1];
		currMedia = 2;
		currMediaid = s_siteAerials[0][5];
		currIndex = 0;
		exitFlag = 1;
	}
}

if(!exitFlag == 1){
	cnt = s_siteStreetmaps.length;
	if(cnt > 0){
		image = s_siteStreetmaps[0][0];
		thumb = s_siteStreetmaps[0][4];
		alt = s_siteStreetmaps[0][1];
		title = s_siteStreetmaps[0][1];
		currMedia = 3;
		currMediaid = s_siteStreetmaps[0][5];
		currIndex = 0;
		exitFlag = 1;
	}
}

//load selected image into viewer
document.getElementById("frameanchor").setAttribute("target", "_blank");
document.getElementById("frameanchor").setAttribute("alt", alt);
document.getElementById("frameanchor").setAttribute("title",title);

if(thumb != ""){
	document.images["picframe"].src = thumb;
}
else{
	document.images["picframe"].src = noMedia;
}

if(image != ''){
	document.getElementById("frameanchor").setAttribute("href",image);
}
else{
	document.getElementById("frameanchor").setAttribute("href","#");	
}

}


/////////////////////////////////////////////////////////////////////////////////////////////
function writeNavFooter(currMedia, lotIndex, mediaOwner){
//function writes out the html for the picframe navigation, in doing so
//it must determine if the currIndex if added to or subtracted from will
//exceed the array boundry

var backIndex=""; //current index position -1 
var forwardIndex=""; //current index position +1

//alert("writnav called");
if((currMedia > 0) && (currMedia < 5)){
	
	switch(mediaOwner){		
		case 1://site media	
			
			switch(currMedia){
				case 1://site siteplan
					var mediacnt = s_siteSiteplans.length;
					//alert("Siteplan media count- "+mediacnt);
					var owner = 1;
					break;
				case 2://site aerials
					var mediacnt = s_siteAerials.length;
					var owner = 1;
					break;
				case 3://site streetmaps
					var mediacnt = s_siteStreetmaps.length;
					var owner = 1;
					break;
				case 4://site photos
					var mediacnt = s_sitePhotos.length;	
					var owner = 1;
					break;
			}
		break;
		case 2:
			switch(currMedia){
				case 1://Lot siteplan
					var mediacnt = l_siteplans[lotIndex].length;
					//alert("Lot Siteplan media count- "+mediacnt);
					var owner = 2;
					break;
				case 2://Lot aerials
					var mediacnt = l_aerials[lotIndex].length;
					//alert("Lot aerial media count- "+mediacnt);
					var owner = 2;
					break;	
				case 4://Lot photos
					var mediacnt = l_photos[lotIndex].length;
					//alert("Lot Photo media count- "+mediacnt);
					var owner = 2;
					break;
			}
		break;	
	}		
}
else{//alert("error detecting media type");
}//place a default image here, instead of an elert
		
	//as long as index position is not 0, incrememnt backwards and enable navigation
	if(currIndex > 0){
		backIndex = currIndex-1;
		
		if(owner == 2){//media is from a lot output lotIndex value
			var strPrev = "<a class=\"navarrow\" href=\"#preview\" onclick=\"selectMedia("+owner+","+currMedia+","+ backIndex+","+lotIndex+");\">&lt;Prev&nbsp;</a>";
		}
		else{
			var strPrev = "<a class=\"navarrow\" href=\"#preview\" onclick=\"selectMedia("+owner+","+currMedia+","+ backIndex+",null);\">&lt;Prev&nbsp;</a>";
		}		
	}	
	else{
		var strPrev = "&lt;Prev&nbsp;";
		backIndex = currIndex;
	}
	
	//as long as index position is not equal to or greater than max array index, increment forward and enable navigation
	if(currIndex < mediacnt){
		forwardIndex = currIndex+1;
		
		if(forwardIndex < mediacnt){
			if(owner == 2){//media is from a lot output lotIndex value
				var strNext = "Image "+ forwardIndex + " of "+ mediacnt +"<a class=\"navarrow\" href=\"#preview\" onclick=\"selectMedia("+owner+","+currMedia+","+ forwardIndex+","+lotIndex+");\">&nbsp; Next</a>&gt;";
			}
			else{
				var strNext = "Image "+ forwardIndex + " of "+ mediacnt +"<a class=\"navarrow\" href=\"#preview\" onclick=\"selectMedia("+owner+","+currMedia+","+ forwardIndex+",null);\">&nbsp; Next</a>&gt;";	
			}
			
		}
		else{
			var strNext = "Image "+ forwardIndex + " of "+ mediacnt +" Next&gt;";
		}
	}
	else{
		var strNext = "Image "+ currIndex + " of "+ mediacnt +" Next&gt;";
		forwardIndex = currIndex;
	}			
	
	var strHtml = strPrev + strNext;		    		
	document.getElementById("imagnav").innerHTML = strHtml;
}

//function activateElement(){
//}

///////////////////////////////////////////////////////////////////////////////////////////////////////
function loadMediaPanel(mediaOwner, lotIndex){

switch(mediaOwner){
	
	case 1://site media
		clearNavHeader();
		writeSiteNavHeader();
		writeNavFooter(currMedia, null, mediaOwner);
		break;
	case 2://lot media
		clearNavHeader();
		writeLotNavHeader(lotIndex);
		writeNavFooter(currMedia, lotIndex, mediaOwner);
		break;
		
}	
}

//////////////////////////////////////////////////////////////////////////////////////////////////
function selectMedia(mediaOwner, currMedia, mediaIndex, lotIndex){
//function receives the current media type and the array index 
//position in which current media item should be outputted. i.e 
//filepath

//set global media index position
currIndex = mediaIndex;

switch(mediaOwner){
	
	case 1://site media
		switch(currMedia){
			case 1://site siteplan
			  s_loadsiteplans();
			  mediaClicked(document.getElementById("siteplan"));
			  writeNavFooter(currMedia, null, mediaOwner);
			  break;    
			case 2://site aerials
			  s_loadaerials();
			   mediaClicked(document.getElementById("aerial"));
			  writeNavFooter(currMedia, null, mediaOwner);
			  break;
			case 3://site streetmaps 
			  s_loadstreetmaps();
			  mediaClicked(document.getElementById("streetmap"));
			  writeNavFooter(currMedia, null, mediaOwner);
			  break;
			case 4://site photos 
			  s_loadphotos(); 
			  mediaClicked(document.getElementById("photo"));
			  writeNavFooter(currMedia, null, mediaOwner);
			  break;
		}
	break;
	case 2://lot media
		switch(currMedia){
			case 1://lot siteplan
			  l_loadsiteplans(lotIndex);
			  mediaClicked(document.getElementById("siteplan"));
			  writeNavFooter(currMedia, lotIndex, mediaOwner);
			  break;    
			case 2://lot aerials
			  l_loadaerials(lotIndex);
			  mediaClicked(document.getElementById("aerial"));			  
			  writeNavFooter(currMedia, lotIndex, mediaOwner);
			  break;
			case 4://site photos 
			  l_loadphotos(lotIndex); 
			  mediaClicked(document.getElementById("photo"));
			  writeNavFooter(currMedia, lotIndex, mediaOwner);
			  break;
		}
	break;

}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
function deactivateElement(el){
	el.onclick = null;
	el.style.cursor = "text";
	el.style.textDecoration = "none";
	el.style.color = "#C9C9C9";
	el.style.fontWeight = "normal";
	el.style.backgroundImage = "url(../assets/site-greenbar.gif)";
	el.style.borderWidth = "0 1px 1px 0";
}

////////////////////////////////////////////////////////////////////////////////////////////////////
function clearNavHeader(){

	deactivateElement(document.getElementById("siteplan"));
	deactivateElement(document.getElementById("aerial"));
	deactivateElement(document.getElementById("streetmap"));
	deactivateElement(document.getElementById("photo"));	
}

///////////////////////////////////////////////////////////////////////////////////////////////////
function mediaClicked(elm){

elm.onclick = null;
elm.style.cursor = "text";
elm.style.fontWeight = "normal";
elm.style.color = "#007961";
elm.style.textDecoration = "none";
elm.style.backgroundImage = "url(../assets/site-click-greenbar.gif)";
elm.style.borderWidth = "0 1px 0 0";	

}
////////////////////////////////////////////////////////////////////////////////////////////////////////
function mediaNotClicked(elm){

//elm.onclick = null;
elm.style.cursor = "pointer";
elm.style.fontWeight = "normal";
elm.style.color = "#007961";
elm.style.textDecoration = "none";
elm.style.backgroundImage = "url(../assets/site-greenbar.gif)";
elm.style.borderWidth = "0 1px 1px 0";	
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
function activatePreviousSiteMedia(media){

switch(media){
	case 1:
		el_td = document.getElementById("siteplan");
		mediaNotClicked(el_td);
		el_td.onclick = function() {selectMedia(1,1,0,null);}
		break;
	case 2:
		el_td = document.getElementById("aerial");
		mediaNotClicked(el_td);
		el_td.onclick = function() {selectMedia(1,2,0,null);}		
		break;
	case 3:
		el_td = document.getElementById("streetmap");
		mediaNotClicked(el_td);
		el_td.onclick = function() {selectMedia(1,3,0,null);}
		break;
	case 4:
		el_td = document.getElementById("photo");
		mediaNotClicked(el_td);
		el_td.onclick = function() {selectMedia(1,4,0,null);}
		break;

}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
function activatePreviousLotMedia(lotIndex, media){

switch(media){
	case 1:
		el_td = document.getElementById("siteplan");
		mediaNotClicked(el_td);
		el_td.onclick = function() {selectMedia(2,1,0,lotIndex);}	
		break;
	case 2:
		el_td = document.getElementById("aerial");
		mediaNotClicked(el_td);
		el_td.onclick = function() {selectMedia(2,2,0,lotIndex);}
		break;
	case 4:
		el_td = document.getElementById("photo");
		mediaNotClicked(el_td);
		el_td.onclick = function() {selectMedia(2,4,0,lotIndex);}
		break;

}
}


///////////////////////////////////////////////////////////////////////////////////////////////////
function writeSiteNavHeader(){	

var siteplancnt = s_siteSiteplans.length;
var aerialcnt = s_siteAerials.length;
//var streetmapcnt = 0//s_siteStreetmaps.length; turns off streetmaps
var streetmapcnt = s_siteStreetmaps.length;
var photocnt = s_sitePhotos.length;

//reset global media index variable, if not done switching from lot to lot has adverse affects
//if the user has incremented through the media
currIndex = 0;

//check to see if this media is present
var el_siteplan = document.getElementById("siteplan");

if(siteplancnt > 0){
	
	
	//if viewing media other than this media activate onclick event and add textnode if needed
	if(currMedia != 1){

			mediaNotClicked(el_siteplan);
			el_siteplan.onclick = function() {selectMedia(1,1,0,null);}

	}
	//viewing this media deactivate onclick event
	else{

			mediaClicked(el_siteplan);

	}
}
//there is no media of this type so deactivate onclick and handle text as needed
else{
		
		el_siteplan.onclick = null;
		el_siteplan.style.cursor = "text";

}

var el_aerial = document.getElementById("aerial");

if(aerialcnt > 0) {
	
	if(currMedia != 2){
		//if text node already exist then update onclick event

			mediaNotClicked(el_aerial);
			el_aerial.onclick = function() {selectMedia(1,2,0,null);}

	}
	//viewing this media check for text node, add if missing and deactivate onclick event
	else{

			mediaClicked(el_aerial);

	}
}
else{
	//alert(el_aerial.hasChildNodes());
		
		el_aerial.onclick = null;
		el_aerial.style.cursor = "text";

}

var el_streetmap = document.getElementById("streetmap");
	
if(streetmapcnt > 0){
	
	if(currMedia != 3){

			mediaNotClicked(el_streetmap);
			el_streetmap.onclick = function() {selectMedia(1,3,0,null);}

	}
	//viewing this media check for text node, add if missing and deactivate onclick event
	else{

			mediaClicked(el_streetmap);

	}
}
else{
		el_streetmap.onclick = null;
		el_streetmap.style.cursor = "text";

}


var el_photo = document.getElementById("photo");
	
if(photocnt > 0){
	
	if(currMedia != 4){
		//if text node already exist then update onclick event
			mediaNotClicked(el_photo);
			el_photo.onclick = function() {selectMedia(1,4,0,null);}

	}
	//viewing this media check for text node, add if missing and deactivate onclick event
	else{
		mediaClicked(el_photo);
	}
}
else{
		el_photo.onclick = null;
		el_photo.style.cursor = "text";

}

}
//////////////////////////////////////////////////////////////////////////////////////////////////
function writeLotNavHeader(lotIndex){

if((lotIndex != undefined) && (lotIndex != null)){
	//alert("In writeLotNavHeader function");
	var siteplancnt = l_siteplans[lotIndex].length;
	var aerialcnt = l_aerials[lotIndex].length;
	var photocnt = l_photos[lotIndex].length;
//	alert(photocnt);
	var el_siteplan = document.getElementById("siteplan");
	
	//check to see if this media is present
	if(siteplancnt > 0){
		
		//if viewing media other than this media activate onclick event and add textnode if needed
		if(currMedia != 1){
				mediaNotClicked(el_siteplan);
				el_siteplan.onclick = function() {selectMedia(2,1,0,lotIndex);}
				
		}
		//viewing this media check for text node, add if missing and deactivate onclick event
		else{
	
				mediaClicked(el_siteplan);
		}
	}
	//there is no media of this type so deactivate onclick and handle text as needed
	else{	
			el_siteplan.onclick = null;
			el_siteplan.style.cursor = "text";
	}
	
			
	var el_aerial = document.getElementById("aerial");
		
	if(aerialcnt > 0) {
		
		if(currMedia != 2){
				mediaNotClicked(el_aerial);
				el_aerial.onclick = function() {selectMedia(2,2,0,lotIndex);}
		}
		//viewing this media check for text node, add if missing and deactivate onclick event
		else{	
				mediaClicked(el_aerial);
		}
	}
	else{	
			el_aerial.onclick = null;
			el_aerial.style.cursor = "text";
	}
	
			
	var el_photo = document.getElementById("photo");
		
	if(photocnt > 0){

		if(currMedia != 4){
				mediaNotClicked(el_photo);
				el_photo.onclick = function() {selectMedia(2,4,0,lotIndex);}

		}
		//viewing this media check for text node, add if missing and deactivate onclick event
		else{	
				mediaClicked(el_photo);
				//alert("current media is photo");
		}
	}
	else{

			el_photo.onclick = null;
			el_photo.style.cursor = "text";
			//alert("no photos found");

	}
}
else{
	alert("Error lot index not defined");
}	

}

