// JavaScript Document

	var map;	//globals, used in Google Map
	var oldmap1; var oldmap2; var oldmap3; var oldmap4; var oldmap5; var oldmap6; var oldmap7; var oldmap8; var oldmap9;
	 
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("LincolnPlaces"));
        map.setCenter(new GLatLng(38.9,-88.2), 5);
	  	//map.setMapType must be after map.setCenter
		map.setMapType(G_SATELLITE_MAP);
		map.addControl(new GLargeMapControl());					<!-- zoom control -->
		map.addControl(new GMapTypeControl());
		<!-- type (Satellite, Terrain etc.) control -->
		map.enableDoubleClickZoom();
    	//map.enableScrollWheelZoom();
	  	//small map at the corner
 		map.addControl(new GOverviewMapControl()); 

		//arrays of checkboxes, general and old maps
		var boxes = new Array("box1", "box2", "box3", "box4", "box5");
		var mapboxes = new Array("mbox1", "mbox2", "mbox3", "mbox4", "mbox5", "mbox6", "mbox7", "mbox8", "mbox9");

		// Create a base icon for all of our markers that specifies the
        // shadow, icon dimensions, etc.
        var baseIcon = new GIcon();
        baseIcon.shadow = "img/markers/shadow50.png";
        baseIcon.iconSize = new GSize(34, 34);
        baseIcon.shadowSize = new GSize(37, 34);
        baseIcon.iconAnchor = new GPoint(9, 34);
        baseIcon.infoWindowAnchor = new GPoint(9, 2);
        baseIcon.infoShadowAnchor = new GPoint(18, 25);

		//check boxes are loaded unchecked
		for (k = 0; k < boxes.length; k++) {
			document.getElementById(boxes[k]).checked = false ;
		}
		for (k = 0; k < mapboxes.length; k++) {
			document.getElementById(mapboxes[k]).checked = false ;
		}
		
		//the first example, recommendation letter: two markers, Dakota territory map, trajectory
		function toggle_box1(){
			if (document.getElementById("box1").checked == true) {				
				// ground overlay
				//toggle_mbox1();
						
				var green_dMarker = new GIcon(baseIcon);
    			green_dMarker.image = "img/markers/green.png";
				var green_dMarker_dot = new GIcon(baseIcon);
    			green_dMarker_dot.image = "img/markers/green-dot.png";
				var dicons = [];			//array of icons
				dicons[0] = green_dMarker_dot;				
				dicons[1] = green_dMarker;

       			var dboundaries = new GLatLngBounds(new GLatLng(41.987,-106.038), new GLatLng(49.71,-95.898));
        		var doldmap = new GGroundOverlay("img/Dacota_territory_1870.png", dboundaries);
				map.addOverlay(doldmap);
				
				var FortRandallLat = 43.049808;
				var FortRandallLng = -98.553235;
				var WashingtonLat = 38.897612; 
				var WashingtonLng = -77.036583;
			
	    		var dpolyOptions = {geodesic:true};
        		var dpolyline = new GPolyline([
        		new GLatLng(FortRandallLat,FortRandallLng),
        		new GLatLng(WashingtonLat,WashingtonLng)
        		], "#00ff00", 2, 1, dpolyOptions);
        		map.addOverlay(dpolyline);
	
				function createDemoMarker(dpoint,dhtml,icontype) {							<!-- Creates a marker at the given point with the given number label -->
					var dmarker = new GMarker(dpoint,dicons[icontype]);
					GEvent.addListener(dmarker, "click", function() {
					dmarker.openInfoWindowHtml(dhtml);
					});
					return dmarker;
				}
				var dmarkers = new Array();
				var dpoint = new GLatLng(FortRandallLat,FortRandallLng);			
				var dhtml = '<span style="font-size:small;">October 26, 1862, Letter to President Abraham Lincoln<br /> to name Francis H. Cooper Lieutenant in the US Army.<br /><a href="http://isda.ncsa.uiuc.edu/lpapers/edit_doc.html" target="_new">[static]</a>, pages: <a href="http://isda.ncsa.uiuc.edu/lpapers/index.php?page_ID=236867&num=01-02-03" target="_new">[3]</a></span>'; 
				dmarkers[0] = createDemoMarker (dpoint,dhtml,1);
				map.addOverlay(dmarkers[0]);					<!-- Add 1 marker to the map at LatLng position, if centered make the center the same LatLng -->
		
				dpoint = new GLatLng(WashingtonLat,WashingtonLng);			
				dhtml = 'Washington, D.C. <br />26<sup>th</sup> October, 1862<br /><a href="http://isda.ncsa.uiuc.edu/lpapers/index.php?page_ID=236867&num=01-02-03" target="_new">[3]</a>'; 
				dmarkers[1] = createDemoMarker (dpoint,dhtml,0);
				map.addOverlay(dmarkers[1]);					<!-- Add 1 marker to the map at LatLng position, if centered make the center the same LatLng -->
				GEvent.trigger(dmarkers[1], "click");
			}
			else {
				clearAll();
				//check boxes are loaded unchecked
				for (k = 0; k < boxes.length; k++) {
					document.getElementById(boxes[k]).checked = false ;
				}
				for (k = 0; k < mapboxes.length; k++) {
					document.getElementById(mapboxes[k]).checked = false ;
				}

			}
		}

		function toggle_box2() {
			if (document.getElementById("box2").checked == true) {
				map.setCenter(new GLatLng(39.7500, -84.1833));
				// this variable will collect all the info which will eventually be placed in the side_bar
 				
				var dplace = "";
    
      			// arrays to hold copies of the markers and html used by the side_bar because the function closure trick doesnt work there
      			var pgmarkers = [];	//new Array()
      			var phtmls = [];
      			var count = 0;
				
			    // A function to create the marker and set up the event window
      			function createPlaceMarker(ppoint,pname,phtml) {
        			var pmarker = new GMarker(ppoint);
        			GEvent.addListener(pmarker, "click", function() {
          				pmarker.openInfoWindowHtml(phtml);
        				});
        			// save the info we need to use later for the side_bar
        			pgmarkers[count] = pmarker;
        			phtmls[count] = phtml;
        			// add a line to the side_bar html
        			dplace += '<span style="font-size:x-small"><a href="javascript:pmyclick(' + count + ')">' + pname + '</a> | </span>';
        			count++;
        			return pmarker;
				}
      			// This function picks up the click and opens the corresponding info window
      			function pmyclick(count) {
        		gmarkers[count].openInfoWindowHtml(phtmls[count]);
      			}
				// Download the data in data.xml and load it on the map. 
				GDownloadUrl("placesAll.xml", function(data, responseCode) {
  					// To ensure against HTTP errors that result in null or bad data always check status code is equal to 200 before processing the data
  					if(responseCode == 200) {
    					var pxml = GXml.parse(data);
    					var pmarkers = pxml.documentElement.getElementsByTagName("marker");
    					for (var ppi = 0; ppi < pmarkers.length; ppi++) {
							//obtain the attribues of each marker
      						var ppoint = new GLatLng(parseFloat(pmarkers[ppi].getAttribute("lat")),parseFloat(pmarkers[ppi].getAttribute("lng")));
             				var phtml = pmarkers[ppi].getAttribute("label"); 
            				var plabel = pmarkers[ppi].getAttribute("label");		
		    				var picontype = parseInt(pmarkers[ppi].getAttribute("icontype"));

							//places without LatLng should have icontype=0
							if(picontype != 0){ 
             					map.addOverlay(createPlaceMarker(ppoint,plabel,phtml));   						
 							}
   						}
 						
						//construct the text
						dplace = '<p style="margin: 5px; padding: 0">' + dplace + '</p>';
         				// put the assembled text into the side_bar div
          				document.getElementById("side_bar").innerHTML = dplace;
   					} 
					else if(responseCode == -1) {
    					alert("Data request timed out. Please try later.");
					} else { 
    					alert("Request resulted in error. Check XML file is retrievable.");
  					}
				});

			}
			else {
				clearAll();
		//check boxes are loaded unchecked
		for (k = 0; k < boxes.length; k++) {
			document.getElementById(boxes[k]).checked = false ;
		}
		for (k = 0; k < mapboxes.length; k++) {
			document.getElementById(mapboxes[k]).checked = false ;
		}
			}		
		}

		function toggle_box3() {
			if (document.getElementById("box3").checked == true) {
				map.setCenter(new GLatLng(39.7500, -84.1833), 6);

				var blue_hMarker_dot = new GIcon(baseIcon);
    			blue_hMarker_dot.image = "img/markers/blue-dot.png";

				//map.setZoom(6); 
				var hLat = new Array("37.531818","37.598337","38.120278","39.804446","39.871112","39.978916","39.801524","39.800704","39.800084","39.783250","38.886726","38.897612","38.941694");
				var hLng = new Array("-85.737337","-85.652826","-86.996944","-89.098949","-89.744053","-89.843037","-89.649556","-89.651302","-89.650683","-89.650370","-77.004673","-77.036583","-77.011766");
				if (hLat.length == hLng.length) {
					for (hh = 0; hh < hLat.length; hh++) {
						var ab = new GLatLng(hLat[hh],hLng[hh]);
						map.addOverlay(new GMarker(ab,blue_hMarker_dot));
					}
				}
				else {
					alert ("Mismatch in Lat nad Lng numbers"); 
				}
			}
			else {
				clearAll();
						//check boxes are loaded unchecked
		for (k = 0; k < boxes.length; k++) {
			document.getElementById(boxes[k]).checked = false ;
		}
		for (k = 0; k < mapboxes.length; k++) {
			document.getElementById(mapboxes[k]).checked = false ;
		}

			}		
		}

		function toggle_mbox4() {
			if (document.getElementById("mbox4").checked == true) {
				map.setCenter(new GLatLng(38.897612,-77.036583), 12);
				var boundaries = new GLatLngBounds(new GLatLng(38.8595,-77.07115), new GLatLng(38.9205,-76.9695));
        		oldmap4 = new GGroundOverlay("img/Washington_1852.png", boundaries);
				map.addOverlay(oldmap4);
			}
			else {
				map.removeOverlay(oldmap4);
				map.setCenter(new GLatLng(38.9,-88.2), 5);
			}  
		}

		function toggle_mbox5() {
			if (document.getElementById("mbox5").checked == true) {
				var boundaries = new GLatLngBounds(new GLatLng(38.29,-77.97), new GLatLng(39.50,-76.94));
        		oldmap5 = new GGroundOverlay("img/Holle_1861.jpg", boundaries);
				map.addOverlay(oldmap5);
			}
			else {
				map.removeOverlay(oldmap5); 
			}  
		}

		function toggle_mbox6() {
			if (document.getElementById("mbox6").checked == true) {
				map.setCenter(new GLatLng(38.897612,-77.036583), 13);
				var boundaries = new GLatLngBounds(new GLatLng(38.8595,-77.07115), new GLatLng(38.9205,-76.9695));
        		oldmap6 = new GGroundOverlay("img/Mitchell_1861.png", boundaries);
				map.addOverlay(oldmap6);
			}
			else {
				map.removeOverlay(oldmap6);
				map.setCenter(new GLatLng(38.9,-88.2), 5);
			}  
		}

		function toggle_mbox7() {
			if (document.getElementById("mbox7").checked == true) {
				map.setCenter(new GLatLng(38.9,-88.2), 3);
				var boundaries = new GLatLngBounds(new GLatLng(21.40,-132.2), new GLatLng(55.22,-62.8));
        		oldmap7 = new GGroundOverlay("img/USAcivilBigRefStitch2.png", boundaries);
				map.addOverlay(oldmap7);
			}
			else {
				map.removeOverlay(oldmap7); 
			}  
		}

		function toggle_mbox8() {
			// old map overlay if the checkboc is checked
			if (document.getElementById("mbox8").checked == true) {
        		var boundaries = new GLatLngBounds(new GLatLng(41.987,-106.038), new GLatLng(49.71,-95.898));
        		oldmap8 = new GGroundOverlay("img/Dacota_territory_1870.png", boundaries);
				map.addOverlay(oldmap8);
			}
			else {
				map.removeOverlay(oldmap8); 
			}  
		}

		function toggle_mbox9() {
			if (document.getElementById("mbox9").checked == true) {
				var boundaries = new GLatLngBounds(new GLatLng(37,-91.57), new GLatLng(42.54,-87.5));
        		oldmap9 = new GGroundOverlay("img/illhist.png", boundaries);
				map.addOverlay(oldmap9);
			}
			else {
				map.removeOverlay(oldmap9); 
			}  
		} 


	}
    else {
      	alert("Sorry, the Google Maps API is not compatible with this browser");
    }

	// this variable will collect the html which will eventually be placed in the side_bar
	var side_bar_html = "";
    
	// arrays to hold copies of the markers and html used by the side_bar
	var gmarkers = [];
	var htmls = [];
	var i = 0;

	//function createIcon(colour) {	
	//	var smallicon = new GIcon(baseIcon);
	//	smallicon.image = "img/markers/" + colour[0] + ".png";
	//	var smallicon_dot = new GIcon(baseIcon);
	//	smallicon_dot.image = "img/markers/" + colour[0] + "-dot.png";
	//	var icons = [];
	//	icons[0] = smallicon;				
	//	icons[1] = smallicon_dot; 
	//	return icons;
	//}


//var temp = {colour_name: {}};
//temp["colour_name"] = ["darkgreen", "orange", "blue", "red", "brown", "green", "lightblue", "pink", "purple", "yellow"];
//var models = temp.colour_name;
//	var icons = [];

//for (cc = 0; cc < models.length; cc += 1) {
//	var tmpMarker = new GIcon(G_DEFAULT_ICON);
//    tmpMarker.image = "img/markers/" + models[cc] + "-dot.png";
//	icons[cc] = tmpMarker;
//}

  		//(x[i]; 
	//}
	//var colour_name = new Array("darkgreen","orange","blue","red","brown","green","lightblue","lightblue","pink","purple","yellow");

	// Create some custom icons     	
	var orange_Marker = new GIcon(baseIcon);
   	orange_Marker.image = "img/markers/orange-dot.png";
	var blue_Marker = new GIcon(baseIcon);
   	blue_Marker.image = "img/markers/blue-dot.png";
	var red_Marker = new GIcon(baseIcon);
   	red_Marker.image = "img/markers/red-dot.png";
	var green_Marker = new GIcon(baseIcon);
	green_Marker.image = "img/markers/green-dot.png";
	var lightblue_Marker = new GIcon(baseIcon);
	lightblue_Marker.image = "img/markers/lightblue-dot.png";
	var pink_Marker = new GIcon(baseIcon);
    pink_Marker.image = "img/markers/pink-dot.png";
	var purple_Marker = new GIcon(baseIcon);
    purple_Marker.image = "img/markers/purple-dot.png";
	var yellow_Marker = new GIcon(baseIcon);
    yellow_Marker.image = "img/markers/yellow-dot.png";

	//An array of GIcons, to make the selection easier
	var icons = [];
	icons[0] = pink_Marker;					// icontype=7 
	icons[1] = orange_Marker;				// icontype=1
	icons[2] = blue_Marker;					// icontype=2
	icons[3] = red_Marker;					// icontype=3
	icons[4] = green_Marker;				// icontype=5
	icons[5] = lightblue_Marker;			// icontype=6
	icons[6] = purple_Marker;				// icontype=8
	icons[7] = yellow_Marker;				// icontype=9

    // A function to create the marker and set up the event window

//function createSmallMarker(point,icontype) {	
    //	var smallmarker = new GMarker(point,icons[icontype]);
	//	return smallmarker;
	//}	// end of createSmallMarker

    function createMarker(point,name,html,icontype,llog,doclink,doclinkLOC) {
   		var marker = new GMarker(point,icons[icontype]);
        	GEvent.addListener(marker, "click", function() {
          		marker.openInfoWindowHtml(html);
        	});
        	// save the info we need to use later for the side_bar
        	gmarkers[i] = marker;
        	htmls[i] = html;
			//creates table with headers
       		// add a line to the side_bar html columns
        	side_bar_html += '<tr><td><span style="font-size:x-small;">' + llog + '</span></td>'
			side_bar_html += '<td><span style="font-size:x-small;"><a href="javascript:myclick(' + i + ')">' + name + '</a></span></td>'
			side_bar_html += '<td style="text-align:center;"><span style="font-size:x-small;">' + doclinkLOC + '</span></td>';
			side_bar_html += '<td style="text-align:center;"><span style="font-size:x-small;">' + doclink + '</span></td></tr>';
        	i++;
        	return marker;
	}	// end of createMarker
 
    // This function picks up the click and opens the corresponding info window
    function myclick(i) { gmarkers[i].openInfoWindowHtml(htmls[i]); }

	function toggle_box4() {
		if (document.getElementById("box4").checked == true) {
			getquery(1);
		}
		else {
			clearAll(); 
		}  
	}
	
	function clearAll() {
		map.clearOverlays();
		//remember, side_bar is, hmm the bottom div
		side_bar_html = "";
		document.getElementById("side_bar").innerHTML = side_bar_html;
		for (k = 0; k < boxes.length; k++) {
			document.getElementById(boxes[k]).checked = false ;
		}
		for (k = 0; k < mapboxes.length; k++) {
			document.getElementById(mapboxes[k]).checked = false ;
		}
		map.setCenter(new GLatLng(38.9,-88.2), 5);
	}

	function createColour(colstr) {
		var length = colstr.length;
		var colour = [];
		switch (length) {
			case 4:
   				colour[0] = "pink"; colour[1] = "#EE4499"; colour[2] = 0;
   				//colour[0] = "darkgreen"; colour[1] = "#00BB00"; colour[2] = 0;
  				break;
			case 5:
   				colour[0] = "orange"; colour[1] = "#FF8800"; colour[2] = 1;
  				break;
			case 6:
   				colour[0] = "blue"; colour[1] = "#5588FF"; colour[2] = 2;
  				break;
			case 7:
   				colour[0] = "red"; colour[1] = "#FF6655"; colour[2] = 3;
  				break;
			case 8:
   				colour[0] = "orange"; colour[1] = "#FF8800"; colour[2] = 1;
   				//colour[0] = "brown"; colour[1] = "#CC9977"; colour[2] = 4;
  				break;
			case 9:
   				colour[0] = "green"; colour[1] = "#00FF33"; colour[2] = 4;
  				break;
			case 10:
   				colour[0] = "lightblue"; colour[1] = "#88DDDD"; colour[2] = 5;
  				break;
			case 11:
   				colour[0] = "lightblue"; colour[1] = "#88DDDD"; colour[2] = 5;
  				break;
			case 12:
   				colour[0] = "purple"; colour[1] = "#7755FF"; colour[2] = 6;
  				break;
			case 13:
   				colour[0] = "purple"; colour[1] = "#7755FF"; colour[2] = 6;
  				break;
			default:
   				colour[0] = "yellow"; colour[1] = "#FFFF55"; colour[2] = 7;
		}		
        return colour;
	}	// end of createIcon
					
 	// Create search request
	var pnum = 0;
	function getquery(pnum) {
 		//alert (pnum);
		var url = 'gebXML12.php';
		
		//example of selected documents - check table in MySQL
		if (document.getElementById("box4").checked == true) {
			url = 'gebXML12.php?year=all&month=all&day=all&type=all&place=all&demo=demo&page=' + pnum + '&sid=' + Math.random();
		}
		//form and page input
		else {
    		//Submits the search string and reads the data from XML/PHP/MySQL output	
			var values = document.ALform;
			
			url += '?year=' + values.year.value + '&month=' + values.month.value + '&day=' + values.day.value;
			url += '&type=' + values.type.value + '&place=' + values.place.value + '&page=' + pnum;
			url += '&sid=' + Math.random();
		}
		//url = 'gebXML2.php';			
		//alert (url);  
    	// Submits the search string and reads the data from XML/PHP/MySQL output	
    
		var request = GXmlHttp.create();
    	request.open("POST", url , true);
    	request.onreadystatechange = function() {
        	if (request.readyState == 4) {
        		var xmlDoc = request.responseXML;
				// alert (xmlDoc);
          		// obtain the array of markers (XML) and loop through it
          		var markers = xmlDoc.documentElement.getElementsByTagName("marker");
			
           		// obtain the array of pages (with only one child node - page)
 				var pages = xmlDoc.documentElement.getElementsByTagName("page")[0].childNodes[0].nodeValue;

				// obtain the error message (with only one child node - page)
 				var message = xmlDoc.documentElement.getElementsByTagName("message")[0].childNodes[0].nodeValue;
				//alert (message); 
						
				// empty the array of markers gmarkers = [] and reset the side_bar_html ;
				map.clearOverlays();  
				side_bar_html = "";

				for (var i = 0; i < markers.length; i++) {
					// obtain the attribues of each marker
					var docnumber = markers[i].getAttribute("doc_ID");
					var date = markers[i].getAttribute("date_XX");

					var place_LLog = markers[i].getAttribute("place_LLog");
					var state_LLog = markers[i].getAttribute("state_LLog");
					var lat1 = parseFloat(markers[i].getAttribute("Lat_LLog"));
					var lng1 = parseFloat(markers[i].getAttribute("Lng_LLog"));
					var point1 = new GLatLng(lat1,lng1);

					var from_place = markers[i].getAttribute("from_place");
					var from_state = markers[i].getAttribute("from_state");
					var lat2 = parseFloat(markers[i].getAttribute("from_Lat"));
					var lng2 = parseFloat(markers[i].getAttribute("from_Lng"));
					var point2 = new GLatLng(lat2,lng2);

					var to_place = markers[i].getAttribute("to_place");
					var to_state = markers[i].getAttribute("to_state");
					var lat3 = parseFloat(markers[i].getAttribute("to_Lat"));
					var lng3 = parseFloat(markers[i].getAttribute("to_Lng"));
					var point3 = new GLatLng(lat3,lng3);

					var docclass = markers[i].getAttribute("doc_class");
					var label = markers[i].getAttribute("doc_title");		

					//pages from ISDA
					var nopages = markers[i].getAttribute("pages_isda");
					//pages from the Library of Congress
					var nopagesLOC = markers[i].getAttribute("pages_loc");
					//end of the markers attributes

					//var html = markers[i].getAttribute("docPlace1"); 
					//var icontype = parseInt(markers[i].getAttribute("icontype"));
					var doc_num = markers[i].getAttribute("doc_num");
					//alert doc_num;
					//End of XML


					//this goes to the sidebar, we need to convert date to 1) lincoln page format and 2) to "nice" format (3rd July 1862), 
					//Lincoln Log link goes first, then the label, only the label fires the marker info window
					var dsplit = date.split("-");
					var dd = parseFloat(dsplit[2]);
					var mm = parseFloat(dsplit[1]);
					var yyyy = dsplit[0];
											 
					var dnames = "";
					
					if(isNaN(dd)) { dd = ""; }	//ss would be Nan otherwise, dnames is already = ""
					//check for XX in Day plus add superscript
					else if (dd == 1 || dd == 21 || dd ==31) { dnames = dd + '<sup>st</sup> '; }
					else if (dd == 2 || dd == 22) { dnames = dd + '<sup>nd</sup>'; }
					else if (dd == 3 || dd == 23) { dnames = dd + '<sup>rd</sup> '; }
					else { dnames = dd + '<sup>th</sup> '; }
				
					var mnames = new Array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
 					//check for XX in months, if yes sets 0 - empty string from the array
 					if(isNaN(mm)) { 
						mm = ""; 
						date = dnames + mnames[0] + ' ' + yyyy;
						}
					else { 
						date = dnames + mnames[mm] + ' ' + yyyy;
						mm += "/"
					}

					//continue in building sidebar with the document links
					var doclink = "";
					var doclinkLOC = "";
					var html =  date +'<br />' + place_LLog + ', ' + state_LLog + '<br />' + docclass;
					
					if (nopages > 0) {					
						//temporary hack with the old document names
						docnumber = doc_num;
						var listPages = "01";
						for (lp = 2; lp <= nopages; lp += 1) {
							if (lp < 10) {
								lpstr = "0" + lp;
							}
							else {
								lpstr = lp;
							}
							listPages = listPages + "-" + lpstr;
						}
						doclink = '<a href="http://isda.ncsa.uiuc.edu/lpapers/index.php?page_ID=' + docnumber + '&num=' + listPages +'" target="_new">[' + nopages +']</a>&nbsp;';
						//this appears in the marker info window
						html += '&nbsp;&nbsp;pages:' + doclink;
					}
					
					if (nopagesLOC > 0) { 
						doclinkLOC = '<a href="http://memory.loc.gov/ammem/alhtml/alser.html" target="_blank">[Y]</a>&nbsp;';
						html += '&nbsp;&nbsp;LOC:' + doclinkLOC;
					}						

					var llog = '<a href="http://www.thelincolnlog.org/view/' + yyyy + '/' + mm + dd + '" target="_blank">' + date + '</a>';
	

    	        	// create the marker
        	    	//var marker1 = createMarker(point1,label,html,icontype,llog,doclink);
					var colour = createColour(docclass);
					
        	    	var marker1 = createMarker(point1,label,html,colour[2],llog,doclink,doclinkLOC);
            		map.addOverlay(marker1);

					if (!isNaN(lat2) || !isNaN(lng2) || !isNaN(lat3) || !isNaN(lng3)) {
        	    	//	var marker2 = createSmallMarker(point2,1);
            		//	map.addOverlay(marker2);

        	    	//	var marker3 = createSmallMarker(point3,2);
            		//	map.addOverlay(marker3);

	    				var dpolyOptions = {geodesic:true};
        				var dpolyline = new GPolyline([point2,point3], colour[1], 2, 1, dpolyOptions);
        				map.addOverlay(dpolyline);				
					}

	          	}   //end of for loop through the array of markers
			
				//add pagination processed to the side_bar div					
				//pagination with 10 options [1] [2] ... etc., three cases 1) pages are less than 10, no first and last links 
				//2) more pages: 2a) the first ten, 2b) the last 10 or less and 2c) middle range with all 10 pages and all first, previous, [x1] [x2] ... [x10] next, last options

				//creates the [x1] [x2] ... pages
				function createPagination(countstr, pageNum, limitLow, limitHigh) {
					for ( var counter = limitLow; counter <= limitHigh ; counter++) {
						if (counter != pageNum) {
							countstr += "<a href='javascript:getquery(" + counter + ")'>[" + counter + "]</a>&nbsp;";
						}
						else {
							countstr += "[" + counter + "]&nbsp;";
						}
					}
					return (countstr);
  				}

				//pages = "1-10";//		from XML input, node <page>
				var psplit = pages.split("-");
				var pageNum = parseInt(psplit[0]);
				var last = parseInt(psplit[1]);
				var rows = parseInt(psplit[2]);
				var countstr = ""; 	
	
				var lastTenth = (10*Math.floor(last/10) + 1);
				//case 1, less than 10 pages
				if ( last <= 10 ) {
					countstr = createPagination(countstr, pageNum, 1 , last);			//function
				}
				// case 2, more than 10 pages
				else {
					//first ten pages, 2a
					if ( pageNum <= 10 ) {		
						countstr = createPagination(countstr, pageNum, 1, 10);			//function		
						countstr += "<a href='javascript:getquery(11)'>&gt;</a>&nbsp;";
						countstr += "<a href='javascript:getquery(" + last + ")'>&gt;&gt;</a>&nbsp;";
					}
					//last pages, 2b
					else if ( pageNum >= lastTenth ) {
						countstr += "<a href='javascript:getquery(1)'>&lt;&lt;</a>&nbsp;";
						var lastTenthPrev = lastTenth - 10;
						countstr += "<a href='javascript:getquery(" + lastTenthPrev + ")'>&lt;</a>&nbsp;";
						countstr = createPagination(countstr, pageNum, lastTenth, last);			//function
					}
					//middle, 2c
					else {
						//$countstr += "&nbsp;<a href='javascript:getquery(1)'>&lt;&lt;</a>&nbsp;";
						var pageTenth = (10*Math.floor(pageNum/10) + 1);
						var pageTenthPrev = pageTenth - 10;
						var pageTenthNext = pageTenth + 9;
						countstr += "<a href='javascript:getquery(1)'>&lt;&lt;</a>&nbsp;";
						countstr += "<a href='javascript:getquery(" + pageTenthPrev + ")'>&lt;</a>&nbsp;";			
						countstr = createPagination(countstr, pageNum, pageTenth, pageTenthNext);			//function
						pageTenthNext += 1;
						countstr += "<a href='javascript:getquery(" + pageTenthNext + ")'>&gt;</a>&nbsp;";
						countstr += "<a href='javascript:getquery(" + last + ")'>&gt;&gt;</a>&nbsp;";
					}
				}
				
				//message - total documents on pages 
				var total = "";
				//total = "&nbsp;" + pageNum + "/" + last + "(" + rows + ")";
				switch (last) {
					case 0:
  						total = "Sorry, no documents available";
  					break;
					case 1:
						if (rows == 1) {total = "total&nbsp;" + rows + "&nbsp;document on&nbsp;" + last + "&nbsp;page";}
						else {total = "total&nbsp;" + rows + "&nbsp;documents on&nbsp;" + last + "&nbsp;page";}
  					break;
					default:
  						total = "total:&nbsp;" + rows + "&nbsp;documents on&nbsp;" + last + "&nbsp;pages";
				}
				
				//construct the sidebar, the data are in the side_bar_html passed by the createMarker function
				side_bar_html = '<table class="tb-two" width="100%" cellspacing="0" style="margin: 0 10px 10px 10px"><tr><th width="15%"><span style="font-size:x-small;"><a href="http://www.thelincolnlog.org/view" target="_new">Lincoln Log</a></span></th><th><span style="font-size:x-small;">Lincoln Papers</span></th><th width="15%"><span style="font-size:x-small;"><a href="http://memory.loc.gov/ammem/alhtml/malhome.html" target="_new">Library of Congress</a></span></th><th width="15%"><span style="font-size:x-small;">Archives&nbsp;&nbsp;pages</span></th></tr>' + side_bar_html;
				side_bar_html += '</table>';   //end of the table created by the createMarker function
				side_bar_html = '<p style="margin: 5px; padding: 0">' + side_bar_html + '</p>';
				side_bar_html += '<p class="tx-center" style="margin: 0";><span style="font-size:small;">' + countstr + '</span><br /><span style="font-size:x-small;">' + total + '</span></p>';

          		// put the assembled side_bar_html contents into the side_bar div
          		document.getElementById("side_bar").innerHTML = side_bar_html;	
			
        	}	//end of if condition - request.readyState
		}	//end of request.onreadystatechange function
			
		request.send(null);

	}	//end of function getquery 
