// WhitefaceLakePlacidInfo.com/tripPlanner dhtml functions, see dhtml.css for affected DIV objects 
var tabbedLayerArray = new Array();
//add Strings of the div objects we want tabbed
tabbedLayerArray.push("'tips'");
tabbedLayerArray.push("'tp'");
tabbedLayerArray.push("'searchResults'");

function closeAllTabs()
{
	for(var i=0;i < tabbedLayerArray.length;i++)
	{
		document.getElementById(eval(tabbedLayerArray[i])).style.visibility = "hidden";
		document.getElementById(eval(tabbedLayerArray[i])).style.display = "none";
	}
	
	//update the actual tabs so they are closed
	/*document.getElementById("tpTab").className = "closedTab";
	document.getElementById("tipsTab").className = "closedTab";
	document.getElementById("searchTab").className = "closedTab";*/
	document.getElementById("tpTab").src = "i/mapImages/bt-tp.gif";
	document.getElementById("searchTab").src = "i/mapImages/bt-search.gif";
	document.getElementById("tipsTab").src = "i/mapImages/bt-tips.gif";
}

function openTabById(idstring)
{
	
		
	closeAllTabs();
	map.closeInfoWindow();
	hideAllMarkers();
	
	
	switch(idstring)
	{
		case "tp":
			
			document.getElementById("tp").style.visibility = "visible";
			document.getElementById("tp").style.display = "block";
			//document.getElementById("tpTab").className = "openTab";
			document.getElementById("tpTab").src = "i/mapImages/bt-tp-on.gif";
			
			//map the TP items
			mapTPMarkers();
			
			break;
	
		case "tips":
			document.getElementById("tips").style.visibility = "visible";
			document.getElementById("tips").style.display = "block";
			//document.getElementById("tipsTab").className = "openTab";
			document.getElementById("tipsTab").src = "i/mapImages/bt-tips-on.gif";
			break;

		case "searchResults":
			document.getElementById("searchResults").style.visibility = "visible";
			document.getElementById("searchResults").style.display = "block";
			//document.getElementById("searchTab").className = "openTab";
			document.getElementById("searchTab").src = "i/mapImages/bt-search-on.gif";
			
			showSearchResultMarkers();

			break;
	}
	
	
	
}

function viewingTP()
{
	if(document.getElementById("tp").style.visibility == "visible")
	{
		return true;
	}
	else return false;
}



/********* trip planner DIV update functions, called from Add and Remove functions (tripplanner.js) *************/
function updateTripPlanner()
{

	  var xmlHttp;
	  try
		{    // Firefox, Opera 8.0+, Safari    
				xmlHttp=new XMLHttpRequest();    }
	  	catch (e)
		{    // Internet Explorer    
			try
		  	{      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      }
			catch (e)
		  	{
				try
				{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
		  		catch (e)
				{
					//no AJAX support, so just refresh the browser
					document.location = 'googleMap.cfm';
				}
			}
		}
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				//update the text
				if(!hasTripPlannerItems())//there are no items left, so reset the welcome text
				{
					document.getElementById("tp").innerHTML="Welcome to the Lake Placid / Essex County Trip Planner!<p>You can view your trip planner items at any time by opening up this tab. Once you\'re finished, click the \"Print Trip Planner\" button to print your personalized trip planner.";
				}
				else
				{
					//clear the current markers
					removeTPMarkers();
					map.closeInfoWindow();
					
					
					
					//update the trip planner using the newly built method from loadTripPlanner.cfm
					var funcIndex = xmlHttp.responseText.indexOf("{");
					var funcEnd = xmlHttp.responseText.indexOf("}",funcIndex);
					
					var theCodeToRun = xmlHttp.responseText.substring(funcIndex+1,funcEnd-1);

					

					eval(theCodeToRun);
					
					document.getElementById("tp").innerHTML=xmlHttp.responseText;

				}
				//if the TP is visible, update IT
				if( viewingTP() )
				{
					mapTPMarkers();
				}
			}
		}
		var queryURL = 'CFHandlers/loadTripPlanner.cfm';
		xmlHttp.open("GET",queryURL,true);
		xmlHttp.send(null);	
}


function loadSubCats(maincat)
{
	//reset the sub cat id value to an empty string
	updateSubCatID("");

	  var xmlHttp;
	  try
		{    // Firefox, Opera 8.0+, Safari    
				xmlHttp=new XMLHttpRequest();    }
	  	catch (e)
		{    // Internet Explorer    
			try
		  	{      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      }
			catch (e)
		  	{
				try
				{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
		  		catch (e)
				{
					//no AJAX support, so just refresh the browser with the new main cat, which will auto load the subcats
					document.location = 'googleMap.cfm?searchCategory='+maincat;
				}
			}
		}
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				document.getElementById("subCats").innerHTML=xmlHttp.responseText;
			}
		}
		var queryURL = 'CFHandlers/loadSubCats.cfm?maincat='+maincat;
		xmlHttp.open("GET",queryURL,true);
		xmlHttp.send(null);	
}


function updateSubCatID(ID)
{
	document.getElementById("subCatID").value = ID;
}