
function checkForHungRequests()
{
	
	if(bItem2Running)
	{
	
		bItem2Running = false;
		doAjaxUpdate(2);
	}
	if(bItem3Running)
	{
		
		bItem3Running = false;
		doAjaxUpdate(3);
	}
	if(bItem4Running)
	{
		
		bItem4Running = false;
		doAjaxUpdate(4);
	}
	if(bItem5Running)
	{
		
		bItem4Running = false;
		doAjaxUpdate(5);
	}
	
	
}


function trackThemeBehaviour(nTrackingElementId,sTrackingValue)
{
	nThemeTrackingStepCounter = nThemeTrackingStepCounter +1;

	new Ajax.Request(sAjaxUrl,
	{
		method:'post',
		parameters:
		{
			action: "trackUser",
			sSession: sClientSession,
			nSupplierID: nSupplierID,
			nTrackingElementId: nTrackingElementId,
			nTrackingStep: nThemeTrackingStepCounter,
			sTrackingValue: sTrackingValue,
				
			uniqueValue: makeUniqueValue()
		}
		,
		onSuccess: function(transport)
		{
			// Success
				var response = transport.responseText || "no response text";
		}
		}
		);
	}
	
	
	function doAjaxUpdate(actionID)
	{
		
		
		
		setTimeout("checkForHungRequests()",5000);
		
		switch(actionID)
		{
			case 1:
			action = "getThemes";
			updateElement = "theme_select_container";
			
			if(nThemeStep == 1)
			{
				$('theme_quick_search_button').disabled = true;
				$('theme_quick_search_button').hide();
			}
			else
			{
				$('theme_search_button').disabled = true;
				$('theme_search_button').hide();
			}
			bItem1Running = true;
			break;
			
			case 2:
			action = "getDestinationCountries";
			updateElement = "destination_country_select_container";
			if(nThemeStep == 1)
			{
				$('theme_quick_search_button').disabled = true;
				$('theme_quick_search_button').hide();
			}
			else
			{
				$('theme_search_button').disabled = true;
				$('theme_search_button').hide();
			}
			bItem2Running = true;
			break;
			
			case 3:
			action = "getMonthYears";
			updateElement = "departure_month_select_container";
			if(nThemeStep == 1)
			{
				$('theme_quick_search_button').disabled = true;
				$('theme_quick_search_button').hide();
			}
			else
			{
				$('theme_search_button').disabled = true;
				$('theme_search_button').hide();
			}
			bItem3Running = true;
			break;
			
			case 4:
			action = "getDepartureAreas";
			updateElement = "departure_area_select_container";
			if(nThemeStep == 1)
			{
				$('theme_quick_search_button').disabled = true;
				$('theme_quick_search_button').hide();
			}
			else
			{
				$('theme_search_button').disabled = true;
				$('theme_search_button').hide();
			}
			bItem4Running = true;
			break;
			
			case 5:
			action = "getDurations";
			updateElement = "duration_select_container";
			if(nThemeStep == 1)
			{
				$('theme_quick_search_button').disabled = true;
				$('theme_quick_search_button').hide();
			}
			else
			{
				$('theme_search_button').disabled = true;
				$('theme_search_button').hide();
			}
			bItem5Running = true;
			break;
			
			
			default:
			{
				alert("no action found");
				action = "";
				updateElement = "";
			}	
		}
		
		new Ajax.Request(sAjaxUrl, 
		{ 
			method:'post', 
			parameters: 
			{
				action: action,
				nSupplierID: nSupplierID,
				nCategoryID: $('nCategoryID').value,
				sCountryID: $('sCountryID').value,
				sMonthYear: $('sMonthYear').value,
				sDepartureAreaID: $('sDepartureAreaID').value,
				nDurationID: $('nDurationID').value,
				nThemeStep:nThemeStep,
				
				uniqueValue: makeUniqueValue()
			},
			onLoading: function()
			{
				switch(actionID)
				{
					case 1:
						$(updateElement).update('<select id="nCategoryID" class="select_box" disabled="true" ><option value="-1">'+sTokenCategorySearching+'</option></select>');
					
					break;
					case 2:
						$('destination_country_select_container').update('<select id="sCountryID" class="select_box" disabled="true" ><option value="-1">'+sTokenCategorySearching+'</option></select>');
						$('departure_month_select_container').update('<select id="sMonthYear" class="select_box" disabled="true" ><option value="0,0">'+sTokenCategorySearching+'</option></select>');
						$('departure_area_select_container').update('<select id="sDepartureAreaID" class="select_box" disabled="true"><option value="-1">'+sTokenCategorySearching+'</option></select>');
						$('duration_select_container').update('<select id="nDurationID" class="select_box" disabled="true" ><option value="-1">'+sTokenCategorySearching+'</option></select>');
					
										
					break;
					case 3:
						$('departure_month_select_container').update('<select id="sMonthYear" class="select_box" disabled="true" ><option value="0,0">'+sTokenCategorySearching+'</option></select>');
						$('departure_area_select_container').update('<select id="sDepartureAreaID" class="select_box" disabled="true"><option value="-1">'+sTokenCategorySearching+'</option></select>');
						$('duration_select_container').update('<select id="nDurationID" class="select_box" disabled="true" ><option value="-1">'+sTokenCategorySearching+'</option></select>');
							break;
					case 4:
						$('departure_area_select_container').update('<select id="sDepartureAreaID" class="select_box" disabled="true" ><option value="-1">'+sTokenCategorySearching+'</option></select>');
						$('duration_select_container').update('<select id="nDurationID" class="select_box" disabled="true" ><option value="-1">'+sTokenCategorySearching+'</option></select>');
						break;
					case 5:
						$(updateElement).update('<select id="nDurationID" class="select_box" disabled="true" ><option value="-1">'+sTokenCategorySearching+'</option></select>');
					break;
				}
				
				
			}
			,
			onSuccess: function(transport) 
			{ 
				// Success
				var response = transport.responseText || "no response text"; 
				
				/*
				if(updateElement != "")
				{
					$(updateElement).update(response);
				}
				*/
				switch(actionID)
				{
					case 1:
					/*doAjaxUpdate(2);*/
					break; 
					 case 2:
					/*doAjaxUpdate(3);*/
					
					var splitArray = response.split("[TM_SPLIT]", 4)
					$('destination_country_select_container').update(splitArray[0]);
					$('departure_month_select_container').update(splitArray[1]);
					$('departure_area_select_container').update(splitArray[2]);
					$('duration_select_container').update(splitArray[3]);
					bItem2Running = false;
					
					
					
					
					break; 
					case 3:
					/*doAjaxUpdate(4);*/
					
						var splitArray = response.split("[TM_SPLIT]", 3)
				
					$('departure_month_select_container').update(splitArray[0]);
					$('departure_area_select_container').update(splitArray[1]);
					$('duration_select_container').update(splitArray[2]);
					bItem3Running = false;
					break; 
					case 4:
					/*doAjaxUpdate(5);*/
					
					var splitArray = response.split("[TM_SPLIT]", 2)
					$('departure_area_select_container').update(splitArray[0]);
					$('duration_select_container').update(splitArray[1]);
				
					bItem4Running = false;
					break;
					case 5:
					
					$('duration_select_container').update(response);
					
					if(nThemeStep == 1)
					{
						
						$('theme_quick_search_button').disabled = false;
						$('theme_quick_search_button').show();
					}
					else
					{
						$('theme_search_button').disabled = false;
						$('theme_search_button').show();
					}
					
					bItem5Running = false;
					break;
					
					default:
					{
						
					}
					
					
				}
				if(nThemeStep == 1)
					{
						
						$('theme_quick_search_button').disabled = false;
						$('theme_quick_search_button').show();
					}
					else
					{
						$('theme_search_button').disabled = false;
						$('theme_search_button').show();
					}
				
			}
			}
		);
		
		
		
	}
	
	
	function trackThemeBehaviour(nTrackingElementId,sTrackingValue)
	{
		nThemeTrackingStepCounter = nThemeTrackingStepCounter +1;
		new Ajax.Request(sAjaxUrl,
			{
				method:'post',
				parameters:
				{
					action: "trackUser",
					sSession: sClientSession,
					nSupplierID: nSupplierID,
					nTrackingElementId: nTrackingElementId,
					nTrackingStep: nThemeTrackingStepCounter,
					sTrackingValue: sTrackingValue,
					uniqueValue: makeUniqueValue()
				}
				,
				onSuccess: function(transport)
				{
					// Success
					var response = transport.responseText || "no response text";
				}
			}
		);
	}
	
	
	function changeOrderBy()
	{
		$('nOrderBy_bottom').selectedIndex = $('nOrderBy').selectedIndex;
	}
		
	function changeOrderBy_bottom()
	{
		$('nOrderBy').selectedIndex = $('nOrderBy_bottom').selectedIndex;
	}
		
	// display none check
	function toggleInfoBox(theId,obj)
	{
		if(document.getElementById('more_info_active_'+theId).style.display  == 'block')
		{
			document.getElementById('more_info_active_'+theId).style.display = 'none';
			document.getElementById('more_info_inactive_'+theId).style.display = 'block';
			document.getElementById('show_hide_more_info_button_'+theId).className="show_more_info_button";
			document.getElementById('fact_box_'+theId).style.display = 'none';
			obj.innerHTML= "";
		}
		else
		{
			document.getElementById('more_info_inactive_'+theId).style.display = 'none';
			document.getElementById('more_info_active_'+theId).style.display = 'block';
			document.getElementById('show_hide_more_info_button_'+theId).className="hide_more_info_button";
			document.getElementById('fact_box_'+theId).style.display = 'block';
			document.getElementById('show_hide_more_info_button_'+theId).focus();
			obj.innerHTML= "";
		}
	}

	function closeElements(theId)
	{
		document.getElementById('show_hide_more_info_button_'+theId).className="show_more_info_button";
	}

	function generateElements(theId)
	{
		document.getElementById('more_info_active_'+theId).style.display = 'block';
		document.getElementById('show_hide_more_info_button_'+theId).className="hide_more_info_button";
		document.getElementById('show_hide_more_info_button_'+theId).onClick = closeElements('+theId+');
		document.getElementById('more_info_inactive_'+theId).style.display = 'none';
	}
	
