	function showSelectedTabAsSelected(selectedTabID)
	{
		//show the tab as selected
		var tabIndex = 0;
		var currentTabID = "tab" + tabIndex;

		while(document.getElementById(currentTabID) != null)
		{
				if(currentTabID == selectedTabID)
				{ 
					document.getElementById("tab" + tabIndex).className = "selected";
				}
				else
				{
					document.getElementById("tab" + tabIndex).className = "";			
				}
				tabIndex = tabIndex + 1;
				currentTabID = "tab" + tabIndex;
		}	
	}

	// AJAX update call
	function ajaxStartTabRefresh(airplanesEngineFK, selectedTabID)
	{ 
		

	   if(window.location.href.toLowerCase().indexOf("planesforsale.php") >= 0)
	   {
   	        //show the tab as selected
	   		showSelectedTabAsSelected(selectedTabID);
	   
			var tabBodyObject = document.getElementById("mainContentBody");
			
			//show a loading message while the ajax data asych call is running
			if(tabBodyObject != null)
			{
				tabBodyObject.innerHTML = "<span style=\"font: bold 30px Verdana; padding: 30px;\">Loading..." + "<img src=\"images/loading.gif\" alt=\"\" style=\"border: 0;\" /></span>";
			}
			
	                            //this is a time stamp that can be used to determine weather to refresh the content
	                            //it is used on the planes for sale page to force the content to be updated on an
	                           //AJAX refresh call rather than displaying cached data
	                           var TimeStamp = "<?php echo date('dMyGis')?>";
	
			//the timestamp post variable that is passed is used to avoid IE from cacheing the results, which forces it to update the plane list
			//since the variable is defined in this script server side using PHP before the page load it will stay the same once a user is on the page
			//this allows us to take advantage of the cacheing if the user clicks on a tab and then later (without a postback)
			//clicks on the same tab.  The next time the user comes to the page, however, the variable is updated so he
			//is sure to see the updated list of aircraft and not a cached list
			var cObj = YAHOO.util.Connect.asyncRequest('GET', 'planesforsaleAJAX.php?engine=' + airplanesEngineFK + "&timestamp=" + TimeStamp, {
				success: function (response) {
					//AJAX worked, so make the call to update the tab data
					document.getElementById('mainContentBody').innerHTML = response.responseText;
					
					//this would help with client side history, as it shows up in the address bar but not server side
					window.location.hash = "#" + airplanesEngineFK + "/" + selectedTabID;
				},
				failure: function (response) {
					//if AJAX did not work, we will do an old fashion redirect
					window.location = 'planesforsale.php?engine=' + airplanesEngineFK;
				}
			});	
		}
		else
		{
					//we are not yet on the planesforsale.php page, we will do an old fashion redirect
					window.location = 'planesforsale.php?engine=' + airplanesEngineFK;
		}
	
	}
	
	function UpdateBasedOnHashOnPageLoad()
	{
	   if(window.location.href.toLowerCase().indexOf("planesforsale.php") >= 0 && window.location.href.toLowerCase().indexOf("engine=") >= 0)
	   {
	         var selectedEngine = window.location.href.substring(window.location.href.toLowerCase().indexOf("engine=") + 7, window.location.href.length);

			 //this uses the history kept with the hash in the URL to ensure that bookmarking and the back button
			 //work as expected
			 selectedEngine = selectedEngine.substring(0,1);

			 var currentEngine = selectedEngine;
	
			 //get the hash from the URL
			 var hashUrl = window.location.hash;
			 //get rid of the number sign at the begining
			 hashUrl = hashUrl.replace("#", "");

			 if ((hashUrl!= null) && (hashUrl != ""))
			 {
			 	var hashSplit = hashUrl.split("/");
			 	
			 	if((hashSplit[0] != null) && (hashSplit[0] > 0) && (hashSplit[1] != null) && (hashSplit[1] != ""))
			 	{
			 		var hashEngine = hashSplit[0];
			 		var selectedTab = hashSplit[1];
	 		
			 		//if the engine type specified by the hash is not the same one
			 		//that was displayed on this page load, we need to reload
			 		//based on the engine specified by the hash
					if(hashEngine != currentEngine)
					{
						ajaxStartTabRefresh(hashEngine, selectedTab);
					}
					else
					{
			   	        //show the tab as selected
				   		showSelectedTabAsSelected("tab"+ currentEngine);
					}
					
				}
				else
				{
		   	        //show the tab as selected
			   		showSelectedTabAsSelected("tab"+ currentEngine);
				}
				
	
			 }
			 else
			 {

	   	        //show the tab as selected
		   		showSelectedTabAsSelected("tab"+ currentEngine);
			 }
			 
		 }
	}
