function trackCharterBehaviour(nTrackingElementId,sTrackingValue)
{
	nCharterTrackingStepCounter = nCharterTrackingStepCounter +1;
	
		
	new Ajax.Request(sAjaxUrl, 
		{ 
			method:'post', 
			parameters: 
			{
				action: "trackUser",
				sSession: sClientSession,
				nSupplierID: nSupplierID,
				nTrackingElementId: nTrackingElementId,
				nTrackingStep: nCharterTrackingStepCounter,
				sTrackingValue: sTrackingValue,
				uniqueValue: makeUniqueValue()
			}
			,
			onSuccess: function(transport) 
			{ 
				// Success
					var response = transport.responseText || "no response text"; 
				
			}
		}
	);
}

function checkForHungRequests()
{
	if(bRunningFullRequest)
	{
		bRunningFullRequest = 0;
		if(bItem1Running)
		{
			/*alert("1 running");*/
			bItem1Running = false;
			doAjaxUpdate(1);
		}
		if(bItem2Running)
		{
			/*alert("2 running");*/
			bItem2Running = false;
			doAjaxUpdate(1);
		}
		if(bItem3Running)
		{
			/*alert("3 running");*/
			bItem3Running = false;
			doAjaxUpdate(1);
		}
		if(bItem4Running)
		{
			/*alert("4 running");*/
			bItem4Running = false;
			doAjaxUpdate(1);
		}
		
		
	}
	
}


function doAjaxUpdate(actionID)
{
	var action = "";
	var updateElement = "";
	
	switch(actionID)
	{
		case 1:
		action = "getDestinationDropDown";
		updateElement = "destination_select_container";
		if(nCharterStep == 1)
		{
			$('charter_quick_search_button').disabled = true;
			$('charter_quick_search_button').hide();
		}
		else if(nCharterStep == 2)
		{
			$('filter_search_button').disabled = true;
			$('filter_search_button').hide();
		}
		
		
		bItem1Running = true;
		
		break;
			
		case 2:
		action = "getAreaDropDown";
		updateElement = "area_select_container";
		if(nCharterStep == 1)
		{
			$('charter_quick_search_button').disabled = true;
			$('charter_quick_search_button').hide();
		}
		else if(nCharterStep == 2)
		{
			$('filter_search_button').disabled = true;
			$('filter_search_button').hide();
		}
		bItem2Running = true;
		break;
		
		case 3:
		action = "getDurationDropDown";
		updateElement = "duration_select_container";
		if(nCharterStep == 1)
		{
			$('charter_quick_search_button').disabled = true;
			$('charter_quick_search_button').hide();
		}
		else if(nCharterStep == 2)
		{
			$('filter_search_button').disabled = true;
			$('filter_search_button').hide();
		}
		bItem3Running = true;
		break;
		
		case 4:
		action = "getSpecificationsDropDown";
		updateElement = "specification_select_container";
		if(nCharterStep == 1)
		{
			$('charter_quick_search_button').disabled = true;
			$('charter_quick_search_button').hide();
		}
		else if(nCharterStep == 2)
		{
			$('filter_search_button').disabled = true;
			$('filter_search_button').hide();
		}
		bItem4Running = true;
		break;
		/*
		case 5:
		action = "getDurations";
		updateElement = "destination_select_container";
		$('charter_quick_search_button').disabled = true;
		$('charter_quick_search_button').hide();
		break;
		*/
		
		default:
		{
			alert("no action found");
			action = "";
			updateElement = "";
		}	
	}
	
	if (actionID == 1 && bRunningFullRequest) {
		
		/*alert('full request is running - please wait');*/
		/*setTimeout("checkForHungRequests()",5000);*/
	}
	else 
	{
		if (actionID == 1)
		{
			/*bRunningFullRequest = 1;*/
			setTimeout("checkForHungRequests()",5000);
		}
		new Ajax.Request(sAjaxUrl, {
			method: 'post',
			parameters: {
				action: action,
				nSupplierID: nSupplierID,
				sDepartureID: $('departure_code').value,
				sDestinationID: $('destination_code').value,
				sAreaId: $("area_code").value,
				dDepartureDate: $("departure_date").value,
				nflexDays: $("flex_days").value,
				nDuration: $("nDuration").value,
				nSpecification: $("nSpecification").value,
				nCharterStep: nCharterStep,
				
				uniqueValue: makeUniqueValue()
			},
			onLoading: function(){
				switch (actionID) {
					case 1:
						$(updateElement).update(getDestionationOnLoading);
						$('area_select_container').update(getAreasOnLoading);
						$('duration_select_container').update(getDurationsOnLoading);
						$('specification_select_container').update(getSpecificationsOnLoading);
						break;
					case 2:
						$(updateElement).update(getAreasOnLoading);
						$('duration_select_container').update(getDurationsOnLoading);
						$('specification_select_container').update(getSpecificationsOnLoading);
						break;
					case 3:
						$(updateElement).update(getDurationsOnLoading);
						$('specification_select_container').update(getSpecificationsOnLoading);
						break;
					case 4:
						$(updateElement).update(getSpecificationsOnLoading);
						break;
				}
			},
			onSuccess: function(transport){
				// Success
				var response = transport.responseText || "no response text";
				
			/*	if (updateElement != "") {
					$(updateElement).update(response);
				}*/
				
				
				
				switch (actionID) {
					case 1:
						/*doAjaxUpdate(2);*/
						bItem1Running = false;
						
							var splitArray = response.split("[TM_SPLIT]", 4)
							$('destination_select_container').update(splitArray[0]);
							$('area_select_container').update(splitArray[1]);
							$('duration_select_container').update(splitArray[2]);
							$('specification_select_container').update(splitArray[3]);
				
						
						
						break;
						
						
					case 2:
						/*doAjaxUpdate(3);*/
						bItem2Running = false;
						
							var splitArray = response.split("[TM_SPLIT]", 3)
						
							$('area_select_container').update(splitArray[0]);
							$('duration_select_container').update(splitArray[1]);
							$('specification_select_container').update(splitArray[2]);
				
				
						
						break;
					case 3:
						/*doAjaxUpdate(4);*/
						bItem3Running = false;
						var splitArray = response.split("[TM_SPLIT]", 2)
						$('duration_select_container').update(splitArray[0]);
						$('specification_select_container').update(splitArray[1]);
				
				
						break;
					case 4:
						
						$('specification_select_container').update(response);
										
						bItem4Running = false;
						bRunningFullRequest = 0;
						break;
					default:
						{
						
						}
				}
				
				if(nCharterStep == 1)
				{
					$('charter_quick_search_button').disabled = false;
					$('charter_quick_search_button').show();
				}
				else if(nCharterStep == 2)
				{
					$('filter_search_button').disabled = false;
					$('filter_search_button').show();
				}
				
			}
		});
	}
}	
	
/*	
function getDestinations()
{

	new Ajax.Request(sAjaxUrl, 
	{ 
		method:'post', 
		parameters: 
		{
			action: "getDestinationDropDown",
			nSupplierID: nSupplierID,
			sDepartureID: $('departure_code').value,
			sDestinationID: $('destination_code').value,
			dDepartureDate: $("departure_date").value,
			nflexDays: $("flex_days").value,
			nCharterStep: 1,
			uniqueValue: makeUniqueValue()
		},
		onLoading: function()
		{
			$('charter_quick_search_button').disabled = true;
			$('destination_select_container').update(getDestionationOnLoading);
		 	$("destination_code").disabled=true;
			$("area_code").disabled=true;
		}
		,
		onSuccess: function(transport) 
		{ 
			// Success
			var response = transport.responseText || "no response text"; 
			$('destination_select_container').update(response);
		 	$("destination_code").disabled=false;
			$("area_code").disabled=false;
			if($("destination_code").value !=0)
			{
				$('charter_quick_search_button').disabled = false;
			}
			getAreas();
		}
	}
	);
}
		
		
function getAreas()
{
	$('status_text_container').update('');
	$('charter_quick_search_button').show();
	$("nSpecification").disabled=true;
	$("nDuration").disabled=true;	
	$("area_code").disabled=true;
	new Ajax.Request(sAjaxUrl, 
			{ 
				method:'post', 
				parameters: 
				{
					action: "getAreaDropDown",
					nSupplierID: nSupplierID,
					sDepartureID: $('departure_code').value,
					sDestinationID: $('destination_code').value,
					dDepartureDate: $("departure_date").value,
					sAreaId: $("area_code").value,
					nflexDays: $("flex_days").value,
					nCharterStep: 1,
					uniqueValue: makeUniqueValue()
				},
				onLoading: function()
				{
					$('area_select_container').update(getAreasOnLoading);
					$('charter_quick_search_button').disabled = true;
				}
				,
				onSuccess: function(transport) 
				{ 
					// Success
						var response = transport.responseText || "no response text"; 
						$('area_select_container').update(response);
						
						$("area_code").disabled=false;
						
						if($("area_code").value !=0)
						{
							$('charter_quick_search_button').disabled = false;
						}
						getDurations();
				 	
				}
				}
			);
		}
		
		
		
		function getDurations()
		{
			
			$("nDuration").disabled=true;	
			
			new Ajax.Request(sAjaxUrl, 
			{ 
				method:'post', 
				parameters: 
				{
					action: "getDurationDropDown",
					nSupplierID: nSupplierID,
					sDepartureID: $('departure_code').value,
					sDestinationID: $('destination_code').value,
					dDepartureDate: $("departure_date").value,
					sAreaId: $("area_code").value,
					nCharterStep: 1,
					nflexDays: $("flex_days").value,
					nDuration: $("nDuration").value,
					uniqueValue: makeUniqueValue()
				},
				onLoading: function()
				{
					$('duration_select_container').update(getDurationsOnLoading);
					$('charter_quick_search_button').disabled = true; 
				}
				,
				onSuccess: function(transport) 
				{ 
					// Success
						var response = transport.responseText || "no response text"; 
						$('duration_select_container').update(response);
						
						$("nDuration").disabled=false;
						if($("area_code").value !=0)
						{
							$('charter_quick_search_button').disabled = false;
						}
						getSpecifications(); 
				}
				}
			);
		}
		
		
		function getSpecifications()
		{
			
			$("nSpecification").disabled=true;
			
			
			new Ajax.Request(sAjaxUrl, 
			{ 
				method:'post', 
				parameters: 
				{
					action: "getSpecificationsDropDown",
					nSupplierID: nSupplierID,
					sDepartureID: $('departure_code').value,
					sDestinationID: $('destination_code').value,
					dDepartureDate: $("departure_date").value,
					sAreaId: $("area_code").value,
					nCharterStep: 1,
					nflexDays: $("flex_days").value,
					nSpecification: $("nSpecification").value,
					uniqueValue: makeUniqueValue()
				},
				onLoading: function()
				{
					$('specification_select_container').update(getSpecificationsOnLoading);
					$('charter_quick_search_button').disabled = true;
				}
				,
				onSuccess: function(transport) 
				{ 
					
						var response = transport.responseText || "no response text"; 
						$('specification_select_container').update(response);
						
						$("nSpecification").disabled=false;
						if($("area_code").value !=0)
						{
							$('charter_quick_search_button').disabled = false;
						}
						else
						{
							$('charter_quick_search_button').hide();
							$('status_text_container').update(statusText);
						}
				}
				}
			);
		}*/