/*
*Function to Display the "Loading.." Animated Gif when switching page results
*
*
*
*/
function getPageResults(currentpage, pagesize){

	
	//Retrieve the Div containing the image
	var loadingImage = document.getElementById("systemWorking");
	
	//If div exists show the image
	if(loadingImage){

	    loadingImage.style.display = "";
	}
	
	//Call the page results
	if(BrowserCheck.ie || BrowserCheck.ns)
	{
		var t = setTimeout("getPageResults2(" + currentpage + "," +  pagesize + ")", 250);
	}
	else
	{
		getPageResults2(currentpage,pagesize);
	}
}


/*
* Function to Handle building the table for the results when using paging
* 
*
*
*/
function getPageResults2(currentpage, pagesize){
	
	
	//try{
	
	//Clear out the Results table and Remove all Pois from the Map
	document.getElementById("divMQResults").innerHTML = "";
	document.getElementById("divMQPages").innerHTML = "";
	
	mqTileMap.removeAllShapes();
	
	//Clear out the mLocations Poi Collection - this collection stores what is currently displayed on the map
	mLocations = new MQA.ShapeCollection();
	
	//Build the Results table
	var html = "";
	
	//Pull out the locations by the Paging
	var location;
	var start = (parseInt(currentpage)-1) * parseInt(pagesize);
	var end = start + parseInt(pagesize);
	var resultend;
	
	//Variables for building the results table
	var tr, td, th, img, a, b, distance, time, img;
	var spacer;
				
	var rowItt = 0;
	var cellItt = 0;
	
	var tbl = document.createElement("table");
	
	tbl.className = "tbl"
	tbl.cellSpacing = 0;
	tbl.cellPadding = 0;
	tbl.border = 0;
	tbl.width = "100%";

	
	
	
	for(var i = start; i < locCollection.getSize() && i < end; i++){
	
		resultend = i;
		
		var num;
		
		
		
		location = locCollection.getAt(i);
		
		if(location.getNearby())
		{
			num = (parseInt(location.getId()) - 1) + ""; 
			
		}
		else
		{
			num = location.getId();
			
		}
		
	
		tr = tbl.insertRow(rowItt++);
		cellItt = 0;
		tr.style.height = "15px";
		if(location.getNearby() == true && i == 0)
		{
			tr.className = "resultstablerowhighlight";
		}
		else
		{
			tr.className = "resultstablerow";
		}
		tr.id = "tr1_" + location.getId();

		td = tr.insertCell(cellItt++);
		td.onmouseover = onPoiMouseover;
		td.onmouseout = onPoiMouseout;
		td.id = "td1_" + location.getId();
		
		var temp = location.checkedFlag;
		
		var cbx = DOMFunctions.createInputElementCheckBox("checkbox", "choice" , location.getId(), temp);
	
		td.appendChild(cbx);
		td.appendChild(DOMFunctions.createInputElement("hidden", location.getId() + "_name" , location.getName()));
		td.appendChild(DOMFunctions.createInputElement("hidden", location.getId() + "_street" , location.getAddress()));
		td.appendChild(DOMFunctions.createInputElement("hidden", location.getId() + "_city" , location.getCity()));
		td.appendChild(DOMFunctions.createInputElement("hidden", location.getId() + "_state" , location.getStateProvince()));
		td.appendChild(DOMFunctions.createInputElement("hidden", location.getId() + "_country" , location.getCountry()));
		td.appendChild(DOMFunctions.createInputElement("hidden", location.getId() + "_post" , location.getPostalCode()));
		td.appendChild(DOMFunctions.createInputElement("hidden", location.getId() + "_lat" , location.getLatLng().getLatitude()));
		td.appendChild(DOMFunctions.createInputElement("hidden", location.getId() + "_long" , location.getLatLng().getLongitude()));
		td.appendChild(DOMFunctions.createInputElement("hidden", location.getId() + "_phone" , location.getPhone()));
		
		
		td = tr.insertCell(cellItt++);
		td.onmouseover = onPoiMouseover;
		td.onmouseout = onPoiMouseout;
		td.onclick = onPoiClick;
		td.id = "td2_" + location.getId();
		
		img = document.createElement("img");
		img.onmouseover = onPoiMouseover;
		img.onmouseout = onPoiMouseout;
		img.src = "/img/mq_icons/" + num + ".gif";
		
		img.id = "i_"+ location.getId();
		td.appendChild(img);
		
		
		td = tr.insertCell(cellItt++);
		td.onmouseover = onPoiMouseover;
		td.onmouseout = onPoiMouseout;
		td.onclick = onPoiClick;
		td.id = "td3_" + location.getId();
		
		
		//Build links for clicking on the Title to open the infowindow
		a = document.createElement("a");
		a.id = "a_" + location.getId();
		a.onclick = onPoiClick;
		a.onmouseover = onPoiMouseover;
		a.onmouseout = onPoiMouseout;
		a.href = "javascript:openInfoWindow(" + location.getId() + ");";
		a.appendChild(document.createTextNode(location.getName()));		
		td.appendChild(a);
		
		if(showdist == 1){
			td.appendChild(document.createTextNode(" (" + location.getDistance() + " mi.)")); 
		}
			
		tr = tbl.insertRow(rowItt++);
		cellItt = 0;
		tr.style.height = "15px";
		if(location.getNearby() == true && i == 0)
		{
			tr.className = "resultstablerowhighlight";
		}
		else
		{
			tr.className = "resultstablerow";
		}
		tr.id = "tr2_" + location.getId();
		
		td = tr.insertCell(cellItt++);
		td.onmouseover = onPoiMouseover;
		td.onmouseout = onPoiMouseout;
		td.onclick = onPoiClick;
		td.id = "td4_" + location.getId();
		td.appendChild(document.createTextNode(" ")); 
		
		td = tr.insertCell(cellItt++);
		td.onmouseover = onPoiMouseover;
		td.onmouseout = onPoiMouseout;
		td.onclick = onPoiClick;
		td.id = "td5_" + location.getId();
		td.appendChild(document.createTextNode(" ")); 
		
		
		td = tr.insertCell(cellItt++);
		td.onmouseover = onPoiMouseover;
		td.onmouseout = onPoiMouseout;
		td.onclick = onPoiClick;
		td.id = "td6_" + location.getId();
		td.appendChild(document.createTextNode(" " + location.getAddress() + ", " + location.getCity() + ", " + location.getStateProvince() + " " + location.getPostalCode())); 

		tr = tbl.insertRow(rowItt++);
		cellItt = 0;
		tr.style.height = "15px";
		if(location.getNearby() == true && i == 0)
		{
			tr.className = "resultstablerowhighlight";
		}
		else
		{
			tr.className = "resultstablerow";
		}
		tr.id = "tr3_" + location.getId();
		
		td = tr.insertCell(cellItt++);
		td.onmouseover = onPoiMouseover;
		td.onmouseout = onPoiMouseout;
		td.onclick = onPoiClick;
		td.style.borderBottom = "1px solid #000000";
		td.id = "td7_" + location.getId();
		
		img = document.createElement("img");
		img.src = "/img/MISC/transparent.gif"
		img.id = "img_"+ location.getId();
		td.appendChild(img);
		
		
		td = tr.insertCell(cellItt++);
		td.onmouseover = onPoiMouseover;
		td.onmouseout = onPoiMouseout;
		td.onclick = onPoiClick;
		td.style.borderBottom = "1px solid #000000";
		td.id = "td8_" + location.getId();
		
		img = document.createElement("img");
		img.src = "/img/MISC/transparent.gif"
		img.id = "img_"+ location.getId();
		td.appendChild(img);
		
		
		td = tr.insertCell(cellItt++);
		td.onmouseover = onPoiMouseover;
		td.onmouseout = onPoiMouseout;
		td.onclick = onPoiClick;
		td.style.borderBottom = "1px solid #000000";
		td.id = "td9_" + location.getId();
		td.appendChild(document.createTextNode(" " + location.getPhone() + " ")); 


		if(location.getTarating())
		{
			
			img = document.createElement("img");
			img.style.align="top";
			img.style.height="12";
			img.style.width="71";
			img.src = location.getTarating();
			img.id = "img_"+ location.getId();
			td.appendChild(img);

		}
		else if(location.getGreenopia())
		{

			if(location.getGreenopia() == 1)
			{
				img = document.createElement("img");
				img.id = "img_"+ location.getId();
				img.src = "/img/greenopia/leaf_award_small_1.png";
				td.appendChild(img);	
			}
			else if(location.getGreenopia() == 2)
			{
				img = document.createElement("img");
				img.id = "img_"+ location.getId();
				img.src = "/img/greenopia/leaf_award_small_2.png";
				td.appendChild(img);	
			}
			else if(location.getGreenopia() == 3)
			{
				img = document.createElement("img");
				img.id = "img_"+ location.getId();
				img.src = "/img/greenopia/leaf_award_small_3.png";
				td.appendChild(img);	
			}
			else if(location.getGreenopia() == 4)
			{
				img = document.createElement("img");
				img.id = "img_"+ location.getId();
				img.src = "/img/greenopia/leaf_award_small_4.png";
				td.appendChild(img);	
			}
			else
			{
				img = document.createElement("img");
				img.src = "/img/MISC/transparent.gif"
				img.id = "img_"+ location.getId();
				td.appendChild(img);
			}
																						
		}
		else
		{
		
			img = document.createElement("img");
			img.src = "/img/MISC/transparent.gif"
			img.id = "img_"+ location.getId();
			td.appendChild(img);
		}

		mLocations.add(location);
	}
	
	
	//Add listeners to the Locations For Single POint Declutter
	//if(mLocations.getSize() > 11 && mLocations.getSize() <= 21){
	//	for(var n = 0; n < mLocations.getSize(); n++){					
	//		MQEventManager.addListener(mLocations.getAt(n), "mousedown", addpointdec);
	//	}
	//}
	
	if(poiorigin){
		//Add the origin to the map
		mLocations.add(poiorigin);
	}
	
	if(poidestination){
		
		mLocations.add(poidestination);
	}
	
	
	//Add the pois to the Map from the new collection
	//mqTileMap.replacePois(mLocations); 
	
	mLocations.setName("pois");
				
	mqTileMap.replaceShapeCollection(mLocations, 'pois');
	
	
	var html;
	var newhtml;
	var npoi;
	
	//Loop through the current displayed poicollection and replace the html in the infowindow popup based on the checked flag
	for(var i = 0; i < mLocations.getSize(); i++)
	{
		if(mLocations.getAt(i).checkedFlag == true){
			npoi = mqTileMap.getPoiByKey(mLocations.getAt(i).getValue('key'));
			html = new String(npoi.getValue('infoContentHTML'));
			newhtml = html.replace("Select", "Unselect");
			npoi.setValue('infoContentHTML',(newhtml));		
		}
	}
	
	//Perform a Best Fit on the Map
	//mqTileMap.bestFit(false);

	mqTileMap.zoomToRect(mLocations.getBoundingRect());
	
	//Save the original state of the map for the revert functionality
	mqTileMap.saveState();
	
	//Save the center location of the map 
	centerll = mqTileMap.getCenter();

	//Set the results table into the div
	var parent = document.getElementById("divMQResults");
	parent.appendChild(tbl);
	
	
	//Build the Div that Contains the paging links
	if(locCollection.getSize() > pagesize){
		
		tbl = document.createElement("table");
		tbl.className = "tbl"
		tbl.cellSpacing = 0;
		tbl.cellPadding = 0;
		tbl.border = 0;
		tbl.width = "100%";
		
		rowItt = 0;

		var pages = Math.ceil(locCollection.getSize() / pagesize);
		
		if(pages * pagesize > MaxSearchResults){
			pages = Math.ceil(MaxSearchResults / pagesize);
		}
		
		tr = tbl.insertRow(rowItt++);
		cellItt = 0;

		td = tr.insertCell(cellItt++);
		td.appendChild(document.createTextNode(" " + (start+1) + "  -  " + (resultend + 1) + " of " + locCollection.getSize() + "   "));
		
		if(currentpage > 1 ){
			a = document.createElement("a");
			a.href = "javascript:getPageResults(" + (currentpage -1) + ", " + pagesize + ");"
			a.appendChild(document.createTextNode(" <<Previous "));
			td.appendChild(a);
	
			/*a = document.createElement("a");
			a.href = "javascript:getPageResults(" + (currentpage -1) + ");"
			a.appendChild(document.createTextNode("<"));
			td.appendChild(a);*/
		}
		
		for (var i=0; i < pages; i ++){
			if(currentpage == i+1){
				
				td.appendChild(document.createTextNode(" "));
				b = document.createElement("b");
				b.appendChild(document.createTextNode(i+1));
				td.appendChild(b);		
				td.appendChild(document.createTextNode(" "));
			}
			else {
				td.appendChild(document.createTextNode(" "));
				a = document.createElement("a");
				a.href = "javascript:getPageResults(" + (i+1) + ", " + pagesize + ");"
				a.appendChild(document.createTextNode((i+1)));
				td.appendChild(a);		
				td.appendChild(document.createTextNode(" "));
			}
		}
		
		if(currentpage < pages  ){
			/*a = document.createElement("a");
			a.href = "javascript:getPageResults(" + (currentpage + 1) + ");"
			a.appendChild(document.createTextNode(">"));
			td.appendChild(a);*/
			
			a = document.createElement("a");
			a.href = "javascript:getPageResults(" + (currentpage + 1) + ", " + pagesize + ");"
			a.appendChild(document.createTextNode(" Next>>"));
			td.appendChild(a);
		}
	
	}
	
		var parentpage = document.getElementById("divMQPages");
		parentpage.appendChild(tbl);
		
		//Reset the check all box
		document.getElementById("checkall").checked = false;
		
		
		//Retrieve the loading image
		var loadingImage = document.getElementById("systemWorking");

		//Hide the loading image once changes are complete
		if(loadingImage){
		    loadingImage.style.display = "none";
		}

}


/*
* Function to Handle building the table for the results when using paging
* 
*
*
*/
function getPageResults3(currentpage, pagesize){
	
	//try{
	
	//Clear out the Results table and Remove all Pois from the Map
	document.getElementById("divMQResults").innerHTML = "";
	document.getElementById("divMQPages").innerHTML = "";
	
	mqTileMap.removeAllShapes();
	
	//Clear out the mLocations Poi Collection - this collection stores what is currently displayed on the map
	mLocations = new MQA.ShapeCollection();
	
	//Build the Results table
	var html = "";
	
	//Pull out the locations by the Paging
	var location;
	var start = (parseInt(currentpage)-1) * parseInt(pagesize);
	var end = start + parseInt(pagesize);
	var resultend;
	
	//Variables for building the results table
	var tr, td, th, img, a, b, distance, time, img;
	var spacer;
				
	var rowItt = 0;
	var cellItt = 0;
	
	var tbl = document.createElement("table");
	
	tbl.className = "tbl"
	tbl.cellSpacing = 0;
	tbl.cellPadding = 0;
	tbl.border = 0;
	tbl.width = "100%";

	
	for(var i = start; i < locCollection.getSize() && i < end; i++){
	
		resultend = i;
		
		location = locCollection.getAt(i);
		
	
		tr = tbl.insertRow(rowItt++);
		cellItt = 0;
		tr.style.height = "15px";
		tr.className = "resultstablerow";
		tr.id = "tr1_" + location.getId();

		//td = tr.insertCell(cellItt++);
		//td.onmouseover = onPoiMouseover;
		//td.onmouseout = onPoiMouseout;
		//td.id = "td1_" + location.getId();
		
		//var temp = location.checkedFlag;
		
		//var cbx = DOMFunctions.createInputElementCheckBox("checkbox", "choice" , location.getId(), temp);
	
		//td.appendChild(cbx);
		//td.appendChild(DOMFunctions.createInputElement("hidden", location.getId() + "_name" , location.getName()));
		//td.appendChild(DOMFunctions.createInputElement("hidden", location.getId() + "_street" , location.getAddress()));
		//td.appendChild(DOMFunctions.createInputElement("hidden", location.getId() + "_city" , location.getCity()));
		//td.appendChild(DOMFunctions.createInputElement("hidden", location.getId() + "_state" , location.getStateProvince()));
		//td.appendChild(DOMFunctions.createInputElement("hidden", location.getId() + "_country" , location.getCountry()));
		//td.appendChild(DOMFunctions.createInputElement("hidden", location.getId() + "_post" , location.getPostalCode()));
		//td.appendChild(DOMFunctions.createInputElement("hidden", location.getId() + "_lat" , location.getLatLng().getLatitude()));
		//td.appendChild(DOMFunctions.createInputElement("hidden", location.getId() + "_long" , location.getLatLng().getLongitude()));
		//td.appendChild(DOMFunctions.createInputElement("hidden", location.getId() + "_phone" , location.getPhone()));
		
		
		td = tr.insertCell(cellItt++);
		td.onmouseover = onPoiMouseover;
		td.onmouseout = onPoiMouseout;
		//td.onclick = onPoiClick;
		td.id = "td2_" + location.getId();
		
		img = document.createElement("img");
		img.onmouseover = onPoiMouseover;
		img.onmouseout = onPoiMouseout;
		img.src = "/img/mq_icons/" + location.getId() + ".gif";
		img.id = "i_"+ location.getId();
		td.appendChild(img);
		
		
		td = tr.insertCell(cellItt++);
		td.onmouseover = onPoiMouseover;
		td.onmouseout = onPoiMouseout;
		//td.onclick = onPoiClick;
		td.id = "td3_" + location.getId();
		
		
		//Build links for clicking on the Title to open the infowindow
		a = document.createElement("a");
		a.id = "a_" + location.getId();
		//a.onclick = onPoiClick;
		a.onmouseover = onPoiMouseover;
		a.onmouseout = onPoiMouseout;
		a.href = "javascript:openInfoWindow(" + location.getId() + ");";
		a.appendChild(document.createTextNode(location.getName()));		
		td.appendChild(a);
		
		if(showdist == 1){
			td.appendChild(document.createTextNode(" (" + location.getDistance() + " mi.)")); 
		}
			
		tr = tbl.insertRow(rowItt++);
		cellItt = 0;
		tr.style.height = "15px";
		tr.className = "resultstablerow";
		tr.id = "tr2_" + location.getId();
		
		td = tr.insertCell(cellItt++);
		td.onmouseover = onPoiMouseover;
		td.onmouseout = onPoiMouseout;
		//td.onclick = onPoiClick;
		td.id = "td4_" + location.getId();
		td.appendChild(document.createTextNode(" ")); 
		
		//td = tr.insertCell(cellItt++);
		//td.onmouseover = onPoiMouseover;
		//td.onmouseout = onPoiMouseout;
		//td.onclick = onPoiClick;
		//td.id = "td5_" + location.getId();
		//td.appendChild(document.createTextNode(" ")); 
		
		
		td = tr.insertCell(cellItt++);
		td.onmouseover = onPoiMouseover;
		td.onmouseout = onPoiMouseout;
		//td.onclick = onPoiClick;
		td.id = "td6_" + location.getId();
		td.appendChild(document.createTextNode(" " + location.getAddress() + ", " + location.getCity() + ", " + location.getStateProvince() + " " + location.getPostalCode())); 

		tr = tbl.insertRow(rowItt++);
		cellItt = 0;
		tr.style.height = "15px";

		tr.className = "resultstablerow";
		
		tr.id = "tr3_" + location.getId();
		
		td = tr.insertCell(cellItt++);
		td.onmouseover = onPoiMouseover;
		td.onmouseout = onPoiMouseout;
		//td.onclick = onPoiClick;
		td.style.borderBottom = "1px solid #000000";
		td.id = "td7_" + location.getId();
		
		img = document.createElement("img");
		img.src = "/img/MISC/transparent.gif"
		img.id = "img_"+ location.getId();
		td.appendChild(img);
		
		
		//td = tr.insertCell(cellItt++);
		//td.onmouseover = onPoiMouseover;
		//td.onmouseout = onPoiMouseout;
		//td.onclick = onPoiClick;
		//td.style.borderBottom = "1px solid #000000";
		//td.id = "td8_" + location.getId();
		
		//img = document.createElement("img");
		//img.src = "/img/MISC/transparent.gif"
		//img.id = "img_"+ location.getId();
		//td.appendChild(img);
		
		
		td = tr.insertCell(cellItt++);
		td.onmouseover = onPoiMouseover;
		td.onmouseout = onPoiMouseout;
		//td.onclick = onPoiClick;
		td.style.borderBottom = "1px solid #000000";
		td.id = "td9_" + location.getId();
		td.appendChild(document.createTextNode(" " + location.getPhone() + " ")); 
		
		if(location.getTarating())
		{
			
			img = document.createElement("img");
			img.style.align="top";
			img.style.height="12";
			img.style.width="71";
			img.src = location.getTarating();
			img.id = "img_"+ location.getId();
			td.appendChild(img);

		}
		else if(location.getGreenopia())
		{
			
			img = document.createElement("img");
			img.id = "img_"+ location.getId();
			
			
			if( location.getGreenopia == 1)
			{
				img = document.createElement("img");
				img.id = "img_"+ location.getId();
				img.src = "<img src='/img/greenopia/leaf_award_small_1.png' />";
				td.appendChild(img);	
			}
			else if(location.getGreenopia == 2)
			{
				img = document.createElement("img");
				img.id = "img_"+ location.getId();
				img.src = "<img src='/img/greenopia/leaf_award_small_2.png' />";
				td.appendChild(img);	
			}
			else if(location.getGreenopia == 4)
			{
				img = document.createElement("img");
				img.id = "img_"+ location.getId();
				img.src = "<img src='/img/greenopia/leaf_award_small_3.png' />";
				td.appendChild(img);	
			}
			else if(location.getGreenopia == 4)
			{
				img = document.createElement("img");
				img.id = "img_"+ location.getId();
				img.src = "<img src='/img/greenopia/leaf_award_small_4.png' />";
				td.appendChild(img);	
			}
			else
			{
				img = document.createElement("img");
				img.src = "/img/MISC/transparent.gif"
				img.id = "img_"+ location.getId();
				td.appendChild(img);
			}
																						
		}
		else
		{
		
			img = document.createElement("img");
			img.src = "/img/MISC/transparent.gif"
			img.id = "img_"+ location.getId();
			td.appendChild(img);
		}
		
		


		mLocations.add(location);
	}
	
	
	//Add listeners to the Locations For Single POint Declutter
	//if(mLocations.getSize() > 11 && mLocations.getSize() <= 21){
	//	for(var n = 0; n < mLocations.getSize(); n++){					
	//		MQEventManager.addListener(mLocations.getAt(n), "mousedown", addpointdec);
	//	}
	//}
	
	if(poiorigin){
		//Add the origin to the map
		mLocations.add(poiorigin);
	}
	
	if(poidestination){
		
		mLocations.add(poidestination);
	}
	
	
	//Add the pois to the Map from the new collection
	//mqTileMap.replacePois(mLocations); 
	
	mLocations.setName("pois");
				
	mqTileMap.replaceShapeCollection(mLocations, 'pois');
	
	
	var html;
	var newhtml;
	var npoi;
	
	//Loop through the current displayed poicollection and replace the html in the infowindow popup based on the checked flag
	/*for(var i = 0; i < mLocations.getSize(); i++)
	{
		if(mLocations.getAt(i).checkedFlag == true){
			npoi = mqTileMap.getPoiByKey(mLocations.getAt(i).getValue('key'));
			html = new String(npoi.getValue('infoContentHTML'));
			newhtml = html.replace("Select", "Unselect");
			npoi.setValue('infoContentHTML',(newhtml));		
		}
	}*/
	
	//Perform a Best Fit on the Map
	//mqTileMap.bestFit(false);

	mqTileMap.zoomToRect(mLocations.getBoundingRect());
	
	//Save the original state of the map for the revert functionality
	mqTileMap.saveState();
	
	//Save the center location of the map 
	centerll = mqTileMap.getCenter();

	//Set the results table into the div
	var parent = document.getElementById("divMQResults");
	parent.appendChild(tbl);
	
	
	//Build the Div that Contains the paging links
	if(locCollection.getSize() > pagesize){
		
		tbl = document.createElement("table");
		tbl.className = "tbl"
		tbl.cellSpacing = 0;
		tbl.cellPadding = 0;
		tbl.border = 0;
		tbl.width = "100%";
		
		rowItt = 0;

		var pages = Math.ceil(locCollection.getSize() / pagesize);
		
		if(pages * pagesize > MaxSearchResults){
			pages = Math.ceil(MaxSearchResults / pagesize);
		}
		
		tr = tbl.insertRow(rowItt++);
		cellItt = 0;

		td = tr.insertCell(cellItt++);
		td.appendChild(document.createTextNode(" " + (start+1) + "  -  " + (resultend + 1) + " of " + locCollection.getSize() + "   "));
		
		if(currentpage > 1 ){
			a = document.createElement("a");
			a.href = "javascript:getPageResults3(" + (currentpage -1) + ", " + pagesize + ");"
			a.appendChild(document.createTextNode(" <<Previous "));
			td.appendChild(a);
	
			/*a = document.createElement("a");
			a.href = "javascript:getPageResults(" + (currentpage -1) + ");"
			a.appendChild(document.createTextNode("<"));
			td.appendChild(a);*/
		}
		
		for (var i=0; i < pages; i ++){
			if(currentpage == i+1){
				
				td.appendChild(document.createTextNode(" "));
				b = document.createElement("b");
				b.appendChild(document.createTextNode(i+1));
				td.appendChild(b);		
				td.appendChild(document.createTextNode(" "));
			}
			else {
				td.appendChild(document.createTextNode(" "));
				a = document.createElement("a");
				a.href = "javascript:getPageResults3(" + (i+1) + ", " + pagesize + ");"
				a.appendChild(document.createTextNode((i+1)));
				td.appendChild(a);		
				td.appendChild(document.createTextNode(" "));
			}
		}
		
		if(currentpage < pages  ){
			/*a = document.createElement("a");
			a.href = "javascript:getPageResults(" + (currentpage + 1) + ");"
			a.appendChild(document.createTextNode(">"));
			td.appendChild(a);*/
			
			a = document.createElement("a");
			a.href = "javascript:getPageResults3(" + (currentpage + 1) + ", " + pagesize + ");"
			a.appendChild(document.createTextNode(" Next>>"));
			td.appendChild(a);
		}
	
	}
	
		var parentpage = document.getElementById("divMQPages");
		parentpage.appendChild(tbl);
		
		//Reset the check all box
		//document.getElementById("checkall").checked = false;
		
		
		//Retrieve the loading image
		var loadingImage = document.getElementById("systemWorking");

		//Hide the loading image once changes are complete
		if(loadingImage){
		    loadingImage.style.display = "none";
		}

}




/*
* Function to handle the mouseover event on a poi and table result
* Pre-Condtion: The event must exist.
* Post-Condition: The appropriate action is taken based on the object that triggered the event. 
*
* @param        e - a javascript event 
* @author       Seisan Consulting   2-16-2006 
*/
function onPoiMouseover(e){

	var poiid = false;
	var poi = null;
	
		
	if(this.getKey){
	
		//retrieve the correct table rows from the results table based on the key of the poi that triggered the event
		poiid = this.getKey();
		
		
		
		//Each Address block is made up of three table rows
		var tr1 = document.getElementById("tr1_" + poiid);
		var tr2 = document.getElementById("tr2_" + poiid);
		var tr3 = document.getElementById("tr3_" + poiid);
		var tr4 = document.getElementById("tr4_" + poiid);
		
		
		//Switch the class names of the table rows to the class for the highlighted table row
		if(tr1.className.indexOf("_over") == -1){
			tr1.className = tr1.className + "_over";
		}
		if(tr2.className.indexOf("_over") == -1){
			tr2.className = tr2.className + "_over";
		}
		if(tr3.className.indexOf("_over") == -1){
			tr3.className = tr3.className + "_over";
		}
		
		if(tr4)
		{
			if(tr4.className.indexOf("_over") == -1)
			{
				tr4.className = tr4.className + "_over";
			}
		}
		
		
		
		
		if(!this.supressscroll){	
			//scroll to the search result on the table
			scrollToSearchResult(poiid);
		}
		this.supressscroll = false;
	
		//if(!BrowserCheck.ie)
		//{
			//Change to the highlighted icon
			//poi = mqTileMap.getPoiByKey(poiid);
			
			//Set the Correct Image for the result number
			//if(poiid >= 99)
			//	poi.getIcon().setImage("/img/mq_icons/blue_icons/" + poiid + ".gif", 21, 16, false, false);
			//else
			//	poi.getIcon().setImage("/img/mq_icons/blue_icons/" + poiid + ".gif", 16, 16, false, false);
			//	
			//poi.getIcon().getElement().style.zIndex = 9;
		//}
	}
	else {
		
		//A mouseover on the result table has triggered the event
		
		//Retrieve the number from the cell id
		var obj = DOMFunctions.getEventCurrentTarget(e);
		poiid =  obj.id;

		
		//alert("Tr id who threw this event " + poiid);
		
		poiid = poiid.substring(poiid.lastIndexOf("_")+1);
		
		
		
		//Retrieve the poi based on the key read from the table row that triggered the event
		try
		{
			poi = mqTileMap.getPoiByKey(poiid);
	
			if(poi != null){

				//Create a mouseover event and send it to the matching poi on the map to have the poi show the infowindow
				var event = new Object();
				event.type ="mouseover";
				poi.supressscroll = true;
				poi.onMouseOver(event);
			}
		}
		catch(exc)
		{
			
		}
	}
	
	
	
}

/*
* Function to handle the mouseout event on a poi and table result
* Pre-Condtion: The event must exist.
* Post-Condition: The appropriate action is taken based on the object that triggered the event. 
*
* @param        e - a javascript event 
* @author       Seisan Consulting   2-16-2006 
*/
function onPoiMouseout(e){

	
	//If the key is defined then a Poi has triggered this event
	var poiid = false;
	var poi = null;
	
	//If the key is defined then a Poi has triggered this event
	//var infowindow = mqTileMap.getInfoWindow();
	
	if(this.getKey){
	
		//retrieve the correct table rows from the results table based on the key of the poi that triggered the event
		poiid = this.getKey();
		
		//Each Address block is made up of three table rows
		var tr1 = document.getElementById("tr1_" + poiid);
		var tr2 = document.getElementById("tr2_" + poiid);
		var tr3 = document.getElementById("tr3_" + poiid);
		var tr4 = document.getElementById("tr4_" + poiid);
		
		//Switch the class names of the table rows to the class for the non-highlighted table row
		var cn = tr1.className;
		if(cn.indexOf("_over") > -1){
			cn = cn.substring(0,cn.indexOf("_over"));
			tr1.className = cn;
		}
		var cn = tr2.className;
		if(cn.indexOf("_over") > -1){
			cn = cn.substring(0,cn.indexOf("_over"));
			tr2.className = cn;
		}
		var cn = tr3.className;
		if(cn.indexOf("_over") > -1){
			cn = cn.substring(0,cn.indexOf("_over"));
			tr3.className = cn;
		}
		
	
		if(tr4)
		{
			var cn = tr4.className;
			if(cn.indexOf("_over") > -1){
				cn = cn.substring(0,cn.indexOf("_over"));
				tr4.className = cn;
			}
		}

		
		//if(!BrowserCheck.ie)
		//{
			//Un-Highlight the Icon By Changing the color of the icon back to yellow
		//	poi = mqTileMap.getPoiByKey(poiid);
			
		//	if(poiid >= 99)
		//		poi.getIcon().setImage("/img/mq_icons/" + poiid + ".gif", 21, 16, false, false);
		//	else
		//		poi.getIcon().setImage("/img/mq_icons/" + poiid + ".gif", 16, 16, false, false);
				
		//	poi.getIcon().getElement().style.zIndex = 9;
		//}

	}
	else {
	
		//if(!infowindow.isHidden()){
		//		infowindow.hide();
		//}
	
		//The result on the result table has triggered the event
		var obj = DOMFunctions.getEventCurrentTarget(e);
		poiid =  obj.id;
		
		//alert("Tr id who threw this event " + poiid);
		
		poiid = poiid.substring(poiid.lastIndexOf("_")+1);
		//Retrieve the poi based on the key read from the table row that triggered the event
		
		try{
			poi = mqTileMap.getPoiByKey(poiid);
		
			if(poi != null){
				//Create a mouseover event and send it to the matching poi on the map to have the poi show the infowindow
				var event = new Object();
				event.type ="mouseout";
				poi.onMouseOut(event);
			}
		}
		catch(exc){}
	}
	
}

/*
* Function to handle the mouseover event on a poi and table result
* Pre-Condtion: The event must exist.
* Post-Condition: The appropriate action is taken based on the object that triggered the event. 
*
* @param        e - a javascript event 
* @author       Seisan Consulting   2-16-2006 
*/
function onPoiMouseoverCorridor(e){
	
	var poiid = false;
	var poi = null;
	
	//If the key is defined then a Poi has triggered this event
	var infowindow = mqTileMap.getInfoWindow();
		
	if(this.getKey){
	
		//retrieve the correct table rows from the results table based on the key of the poi that triggered the event
		poiid = this.getKey();
		
		//Each Address block is made up of three table rows
		var tr1 = document.getElementById("tr1_" + poiid);
		var tr2 = document.getElementById("tr2_" + poiid);
		var tr3 = document.getElementById("tr3_" + poiid);
		
		//Switch the class names of the table rows to the class for the highlighted table row
		if(tr1.className.indexOf("_over") == -1){
			tr1.className = tr1.className + "_over";
		}
		if(tr2.className.indexOf("_over") == -1){
			tr2.className = tr2.className + "_over";
		}
		if(tr3.className.indexOf("_over") == -1){
			tr3.className = tr3.className + "_over";
		}
		
		if(!this.supressscroll){	
			//scroll to the search result on the table
			scrollToSearchResult(poiid);
		}
		this.supressscroll = false;
	
		//Change to the highlighted icon
		poi = mqTileMap.getPoiByKey(poiid);
		
		if(poiid = 0)
		{
			//alert("start icon");
		}
		else if(poiid = routeResults )
		{
			//alert("end icon");
		}
		else
		{
			//if(!BrowserCheck.ie)
			//{
			//	//Set the Correct Image for the result number
			//	if(poiid >= 99)
				//	poi.getIcon().setImage("/img/mq_icons/blue_icons/" + poiid + ".gif", 21, 16, true, false);
			//	else
			//		poi.getIcon().setImage("/img/mq_icons/blue_icons/" + poiid + ".gif", 16, 16, true, false);
				
			//	poi.getIcon().getElement().style.zIndex = 9;
			//}
		}
	}
	else {
	
		//A mouseover on the result table has triggered the event
		//if(!infowindow.isHidden()){
		//	infowindow.hide();
		//}
		
		//Retrieve the number from the cell id
		var obj = DOMFunctions.getEventCurrentTarget(e);
		poiid =  obj.id;
		poiid = poiid.substring(poiid.lastIndexOf("_")+1);
		
		//Retrieve the poi based on the key read from the table row that triggered the event
		poi = mqTileMap.getPoiByKey(poiid);
	
		if(poi != null){

			//Create a mouseover event and send it to the matching poi on the map to have the poi show the infowindow
			var event = new Object();
			event.type ="mouseover";
			poi.supressscroll = true;
			poi.onMouseOver(event);
		}
	}
	
}

/*
* Function to handle the mouseout event on a poi and table result
* Pre-Condtion: The event must exist.
* Post-Condition: The appropriate action is taken based on the object that triggered the event. 
*
* @param        e - a javascript event 
* @author       Seisan Consulting   2-16-2006 
*/
function onPoiMouseoutCorridor(e){
	
	//If the key is defined then a Poi has triggered this event
	var poiid = false;
	var poi = null;
	if(this.getKey){
	
		//retrieve the correct table rows from the results table based on the key of the poi that triggered the event
		poiid = this.getKey();
		
		//Each Address block is made up of three table rows
		var tr1 = document.getElementById("tr1_" + poiid);
		var tr2 = document.getElementById("tr2_" + poiid);
		var tr3 = document.getElementById("tr3_" + poiid);
		
		//Switch the class names of the table rows to the class for the non-highlighted table row
		var cn = tr1.className;
		if(cn.indexOf("_over") > -1){
			cn = cn.substring(0,cn.indexOf("_over"));
			tr1.className = cn;
		}
		var cn = tr2.className;
		if(cn.indexOf("_over") > -1){
			cn = cn.substring(0,cn.indexOf("_over"));
			tr2.className = cn;
		}
		var cn = tr3.className;
		if(cn.indexOf("_over") > -1){
			cn = cn.substring(0,cn.indexOf("_over"));
			tr3.className = cn;
		}
		
		//Un-Highlight the Icon By Changing the color of the icon back to yellow
		poi = mqTileMap.getPoiByKey(poiid);
		
		if(poiid = 0)
		{
			//poi.getIcon().setImage("/img/mq_icons/start.gif", 21, 16, true, false);
		}
		else if(poiid = routeResults)
		{
			//poi.getIcon().setImage("/img/mq_icons/end.gif", 21, 16, true, false);
		}
		else
		{
			//if(!BrowserCheck.ie)
			//{	
			//	if(poiid >= 99)
			//		poi.getIcon().setImage("/img/mq_icons/" + poiid + ".gif", 21, 16, true, false);
			//	else
			//		poi.getIcon().setImage("/img/mq_icons/" + poiid + ".gif", 16, 16, true, false);
			//		
			//	poi.getIcon().getElement().style.zIndex = 9;
			//}
		}
	}
	else {
	
		//The result on the result table has triggered the event
		var obj = DOMFunctions.getEventCurrentTarget(e);
		poiid =  obj.id;
		poiid = poiid.substring(poiid.lastIndexOf("_")+1);
		//Retrieve the poi based on the key read from the table row that triggered the event
		
		poi = mqTileMap.getPoiByKey(poiid);
		
		if(poi != null){
			//Create a mouseover event and send it to the matching poi on the map to have the poi show the infowindow
			var event = new Object();
			event.type ="mouseout";
			poi.onMouseOut(event);
		}
	}
	
}


/*
* Function to handle the mouseover event on a poi and table result
* Pre-Condtion: The event must exist.
* Post-Condition: The appropriate action is taken based on the object that triggered the event. 
*
* @param        e - a javascript event 
* @author       Seisan Consulting   2-16-2006 
*/
function onPoiMouseoverFav(e){
	
	
	var poiid = false;
	var poi = null;
	
	//Retrieve the number from the cell id
	var obj = DOMFunctions.getEventCurrentTarget(e);
	poiid =  obj.id;
	poiid = poiid.substring(poiid.lastIndexOf("_")+1);
	
	//Each Address block is made up of three table rows
	var tr1 = document.getElementById("tr1_" + poiid);
	
	//Switch the class names of the table rows to the class for the highlighted table row
	if(tr1.className.indexOf("_over") == -1){
		tr1.className = tr1.className + "_over";
	}
}

/*
* Function to handle the mouseout event on a poi and table result
* Pre-Condtion: The event must exist.
* Post-Condition: The appropriate action is taken based on the object that triggered the event. 
*
* @param        e - a javascript event 
* @author       Seisan Consulting   2-16-2006 
*/
function onPoiMouseoutFav(e){

	
	//If the key is defined then a Poi has triggered this event
	var poiid = false;
	var poi = null;
	
	
	//The result on the result table has triggered the event
	var obj = DOMFunctions.getEventCurrentTarget(e);
	poiid =  obj.id;
	poiid = poiid.substring(poiid.lastIndexOf("_")+1);
	
	
	//Each Address block is made up of three table rows
	var tr1 = document.getElementById("tr1_" + poiid);
	
	//Switch the class names of the table rows to the class for the non-highlighted table row
	var cn = tr1.className;
	if(cn.indexOf("_over") > -1){
		cn = cn.substring(0,cn.indexOf("_over"));
		tr1.className = cn;
	}

}

/*
* Function to scroll the results table to the location of the id passed. 
* Pre-Condtion: The key != null
*
* @param        key - a poi id key
* @author       Seisan Consulting   2-16-2006 
*/
function scrollToSearchResult(key){
	
	//Retrieve the div containing the results listing
	var div = document.getElementById("divMQResults");
	var div2 = document.getElementById("divMQResults2");
	
	if(div){
	
		//get the height value of the current contents of the div
		var height = div.scrollHeight;
	
		//Add up the height of a single address block made up of 3 table rows
		var tr1 = document.getElementById("tr1_" + key);
		var tr2 = document.getElementById("tr2_" + key);
		var tr3 = document.getElementById("tr3_" + key);
		
		var distance = parseInt(tr1.style.height) + parseInt(tr2.style.height) + parseInt(tr3.style.height);
		
		//distance = (height/perPageResultNumber);
		
		var result;
		
		for(var i = 0; i < mLocations.getSize(); i++)
		{
			if (mLocations.getAt(i).getKey() == key)
			{
				result = (i);
			}
		}

		var amount;
	
		if(poidestination && poiorigin){
			amount = ((result-2) * distance) - 50;
		}else if((poiorigin && !poidestination) || (!poiorigin && poidestination)){
			amount = ((result-1) * distance) - 50;
		}else if(!poiorigin && ! poidestination){
			amount = ((result+1) * distance) - 50;
		}else{
			amount = (result * distance) - 50;
		}

		if(amount <= 50){
			div.scrollTop =  0;
		}else{
			div.scrollTop = amount;
			
		}
	
	}
	
	if(div2){
	
		//get the height value of the current contents of the div
		var height = div2.scrollHeight;
	
		//Add up the height of a single address block made up of 3 table rows
		var tr1 = document.getElementById("tr1_" + key);
		var tr2 = document.getElementById("tr2_" + key);
		var tr3 = document.getElementById("tr3_" + key);
		
		var distance = parseInt(tr1.style.height) + parseInt(tr2.style.height) + parseInt(tr3.style.height);
		
		//distance = (height/perPageResultNumber);
		
		var result;
		
		for(var i = 0; i < mLocations.getSize(); i++)
		{
			if (mLocations.getAt(i).getKey() == key)
			{
				result = (i);
			}
		}
			
		var amount;
	
		if(poidestination && poiorigin){
			amount = ((result-2) * distance) - 50;
		}else if((poiorigin && !poidestination) || (!poiorigin && poidestination)){
			amount = ((result-1) * distance) - 50;
		}else if(!poiorigin && ! poidestination){
			amount = ((result+1) * distance) - 50;
		}else{
			amount = (result * distance) - 50;
		}
		
		if(amount <= 50){
			div2.scrollTop =  0;
		}else{
			div2.scrollTop = amount;
			
		}
	}
}



/*
* Function to handle the click event on a poi and table result
* Pre-Condtion: The event must exist.
* Post-Condition: The appropriate action is taken based on the object that triggered the event. 
*
* @param        e - a javascript event 
* @author       Seisan Consulting   2-16-2006 
*/
var ignoreTd = false;

function onPoiClick(e){
	
	var poiid = false;
	
	var obj = DOMFunctions.getEventCurrentTarget(e);
	
	poiid =  obj.id;

	var fullid =  obj.id;
	
		
	if(poiid.substring(0,1) != "a"){
		
		//Check to see the browser Internet Explorer Handles the Event bubbling differently than firefox
		if(BrowserCheck.ie)
		{
			
			if(ignoreTd)
			{
				ignoreTd = false;
			}

				poiid = poiid.substring(poiid.lastIndexOf("_")+1);
				
				var temp = document.getElementById(poiid);
				
				
				if(fullid.length > 3){
	
					if(temp.checked == true){
						document.getElementById(poiid).checked = false;
	
					}else{
						document.getElementById(poiid).checked = true;
					}
				}
				
				
				//Loop through the Location Collection and find the Location object with the matching Key and change the checked flag approriately
				
				var html;
				var newhtml;
				var poi;
				
				if(locCollection)
				{
					
				
					for(var i = 0; i < locCollection.getSize(); i++)
					{
						if(locCollection.getAt(i).getKey() == poiid)
						{
							if(locCollection.getAt(i).checkedFlag == true)
							{
								//Uncheck the Box
								locCollection.getAt(i).checkedFlag = false;
								//Change the text in the infowindow popup to select
								poi = mqTileMap.getPoiByKey(poiid);
								html = new String(poi.getValue('infoContentHTML'));
								newhtml = html.replace("Unselect", "Select");
								poi.setValue('infoContentHTML',(newhtml));
							}
							else
							{
								//Check the box
								locCollection.getAt(i).checkedFlag = true;
								//Change the text in the infowindow popup to unselect
								poi = mqTileMap.getPoiByKey(poiid);
								html = new String(poi.getValue('infoContentHTML'));
								newhtml = html.replace("Select", "Unselect");
								poi.setValue('infoContentHTML', (newhtml));
							}
						}
					}
				}
				else
				{
	
					
					for(var i = 0; i < mLocations.getSize(); i++)
					{
						if(mLocations.getAt(i).getKey() == poiid)
						{
						
							if(temp.checked == true)
							{
								
								//Change the text in the infowindow popup to select
								poi = mqTileMap.getPoiByKey(poiid);
								html = new String(poi.getValue('infoContentHTML'));
								newhtml = html.replace("Select", "Unselect");
								poi.setValue('infoContentHTML',(newhtml));
							}
							else
							{
								
								//Change the text in the infowindow popup to unselect
								poi = mqTileMap.getPoiByKey(poiid);
								html = new String(poi.getValue('infoContentHTML'));
								newhtml = html.replace("Unselect", "Select");
								poi.setValue('infoContentHTML',(newhtml));
							}
						}
					}
				}
					
			//}
		}else{
		
			if(ignoreTd)
			{
				ignoreTd = false;
			}
			else{
			
				
				poiid = poiid.substring(poiid.lastIndexOf("_")+1);
				
				var temp = document.getElementById(poiid);
				
				
				if(fullid.length > 3){
	
					if(temp.checked == true){
						document.getElementById(poiid).checked = false;
	
					}else{
						document.getElementById(poiid).checked = true;
					}
				}
				
				
				//Loop through the Location Collection and find the Location object with the matching Key and change the checked flag approriately
				
				var html;
				var newhtml;
				var poi;
				
				if(locCollection)
				{
					
				
					for(var i = 0; i < locCollection.getSize(); i++)
					{
						if(locCollection.getAt(i).getKey() == poiid)
						{
							if(locCollection.getAt(i).checkedFlag == true)
							{
								//Uncheck the Box
								locCollection.getAt(i).checkedFlag = false;
								//Change the text in the infowindow popup to select
								poi = mqTileMap.getPoiByKey(poiid);
								html = new String(poi.getValue('infoContentHTML'));
								newhtml = html.replace("Unselect", "Select");
								poi.setValue('infoContentHTML', (newhtml));
							}
							else
							{
								//Check the box
								locCollection.getAt(i).checkedFlag = true;
								//Change the text in the infowindow popup to unselect
								poi = mqTileMap.getPoiByKey(poiid);
								html = new String(poi.getValue('infoContentHTML'));
								newhtml = html.replace("Select", "Unselect");
								poi.setValue('infoContentHTML', (newhtml));
							}
						}
					}
				}
				else
				{
	
					
					for(var i = 0; i < mLocations.getSize(); i++)
					{
						if(mLocations.getAt(i).getKey() == poiid)
						{
						
							if(temp.checked == true)
							{
								
								//Change the text in the infowindow popup to select
								poi = mqTileMap.getPoiByKey(poiid);
								html = new String(poi.getValue('infoContentHTML'));
								newhtml = html.replace("Select", "Unselect");
								poi.setValue('infoContentHTML', (newhtml));
							}
							else
							{
								
								//Change the text in the infowindow popup to unselect
								poi = mqTileMap.getPoiByKey(poiid);
								html = new String(poi.getValue('infoContentHTML'));
								newhtml = html.replace("Unselect", "Select");
								poi.setValue('infoContentHTML', (newhtml));
							}
						}
					}
				}
					
			}
		
		}
		
	}
	else {
	
		ignoreTd = true;
	}
	
	
}

/*
* Function to handle the click event on a poi and table result
* Pre-Condtion: The event must exist.
* Post-Condition: The appropriate action is taken based on the object that triggered the event. 
*
* @param        e - a javascript event 
* @author       Seisan Consulting   2-16-2006 
*/
ignoreTd = false;

function onPoiClickFav(e){
	
	var poiid = false;
	
	var obj = DOMFunctions.getEventCurrentTarget(e);
	
	poiid =  obj.id;

	var fullid =  obj.id;
		
	if(poiid.substring(0,1) != "a"){
		
		if(ignoreTd)
		{
			ignoreTd = false;
		}
		else{
		
			poiid = poiid.substring(poiid.lastIndexOf("_")+1);
			
			var temp = document.getElementById(poiid);
			
			
			if(fullid.length > 3){

				if(temp.checked == true){
					document.getElementById(poiid).checked = false;

				}else{
					document.getElementById(poiid).checked = true;
				}
			}
			
			
			//Loop through the Location Collection and find the Location object with the matching Key and change the checked flag approriately
			
			var html;
			var newhtml;
			var poi;
			
			if(locCollection)
			{
				
			
				for(var i = 0; i < locCollection.getSize(); i++)
				{
					if(locCollection.getAt(i).getKey() == poiid)
					{
						if(locCollection.getAt(i).checkedFlag == true)
						{
							//Uncheck the Box
							locCollection.getAt(i).checkedFlag = false;
							//alert("setting object to false");
							//Change the text in the infowindow popup to select
						}
						else
						{
							//Check the box
							locCollection.getAt(i).checkedFlag = true;
							//alert("Setting object to true");
							//Change the text in the infowindow popup to unselect
						}
					}
				}
			}
				
		}
		
	}
	else {
		ignoreTd = true;
	}
	
	
}


function clearAllCheckboxes()
{

	var cboxes = document.getElementsByName("choice");
	

	for(var i=0; i < cboxes.length; i++)
	{
		cboxes[i].checked = false;
		
	}
	
	try{
	
		var checkall = document.getElementById("checkall");
		
		checkall.checked = false;
	
	}catch(exc){}
	
	
}



function toggleCheckboxes(value)
{
	//var i = 1;
	
	var obj;
	
	//If there is an origin grab the second item in the array = first location
	//If no origin defined then grab the first position in the array = first location
	
	var t = mLocations.getAt(0).getKey();
	
	if(t){
	
		obj = mLocations.getAt(0);
	}
	else
	{
		if(poidestination)
		{
			//alert("Has a destination");
			obj = mLocations.getAt(2);
		}	
		else if(poiorigin){
			//alert("Has an origin");
			obj = mLocations.getAt(1);
		}
		else{
			//alert("No dest or origin plotted");
			obj = mLocations.getAt(0);
		}
	}
	
	var i = obj.getKey();

	
	var cb = document.getElementById(i);

	var npoi;
	var html;
	var newhtml;

	
	while(cb)
	{

		cb.checked = value;
		
		if(locCollection){
		
			locCollection.getAt(i-1).checkedFlag = value;
		}
		
		if(value == true)
		{
			npoi = mqTileMap.getPoiByKey(i);
			html = new String(npoi.getValue('infoContentHTML'));
			newhtml = html.replace("Select", "Unselect");
			npoi.setValue('infoContentHTML', (newhtml));		
		}
		else
		{
			npoi = mqTileMap.getPoiByKey(i);
			html = new String(npoi.getValue('infoContentHTML'));
			newhtml = html.replace("Unselect", "Select");
			npoi.setValue('infoContentHTML',(newhtml));
		}
		
		i++;
		
		cb = document.getElementById(i);

	}
	

}

function toggleCheckboxes2(form, checkboxName, value)
{
	if (form[checkboxName].length)
	{
		for (var i = 0; i < form[checkboxName].length; i++)
		{
			form[checkboxName][i].checked = value;
		}
	}
	else
	{
		form[checkboxName].checked = value;
	}
}



function check50CheckBoxes(form, checkboxName, value)
{
	if (form[checkboxName].length)
	{
		for (var i = 0; i <= 49; i++)
		{
			form[checkboxName][i].checked = value;
		}
	}
	else
	{
		form[checkboxName].checked = value;
	}
	
	if(locCollection)
	{
		for(var i=0; i <= 49; i++)
		{
			locCollection.getAt(i).checkedFlag = value;
		
		}
	}
	
}


function uncheckCheckboxes(form, checkboxName, value)
{
	if (!value) 
	{
		if (form[checkboxName].length)
		{
			for (var i = 0; i < form[checkboxName].length; i++)
			{
				form[checkboxName][i].checked = value;
			}
		}
		else
		{
			form[checkboxName].checked = value;
		}
	}
}

function confirmDelete() 
{
	return confirm('Are you sure you want to delete?');
}

function toggleVisibleOnEquals(id, x1, x2)
{	
	var el = document.getElementById(id);
	if (x1 == x2) 
	{
		el.style.visibility = "visible";		
	}
	else
	{
		el.style.visibility = "hidden";
	}
}	

function stateChange(stateOptionList, countryOptionList)
{
	var stateIndex = stateOptionList.selectedIndex
	var stateValue = stateOptionList[stateIndex].value;
	if (stateValue == "" && stateIndex != 0)
	{
		stateOptionList.selectedIndex = 0;
	}
	
	// the countryOptionList item is there in case we ever decide to 
	// automagically set the country based on the state selected
	if (stateValue != "")
	{
		var country_lookup = { "ab":2, "bc":2, "mb":2, "nb":2, "nl":2, "nt":2, "ns":2, "nu":2, "on":2, "pe":2, "qc":2, "sk":2, "yt":2, "pr":3 };
		var countryIndex = country_lookup[stateValue];
		if (countryIndex)
		{
			// alert("Canada");
			countryOptionList.selectedIndex = countryIndex;
		}
		else
		{
			// alert("United States");
			countryOptionList.selectedIndex = 1;
		}
	}

	// should this return something?
	return true;
}