// -----------------------------------------------------------------------------------------
// functions
// -----------------------------------------------------------------------------------------
function initiateAdvencedSearch()
{
	var objDiv = document.getElementById('Div_Advanced');
	var objTextBox = document.getElementById('TextBox_Title');
	
	for (var i = 0; i < document.forms[0].elements.length; i++)
	{
		if (document.forms[0].elements[i].type == "checkbox") 
		{
			if((document.forms[0].elements[i].checked) 
			&& (document.forms[0].elements[i].id != "Checkboxlist_Themes_0")
			&& (document.forms[0].elements[i].id != "rm"))
			{
				objDiv.style.display = '';
				break;
			}
		}
	}
	
	if (objTextBox.value !="") objDiv.style.display = '';
}

// switch displaying ADVANCED SEARCHING OPTIONS
function Display_AdvancedSearch()
{
	var objDiv = document.getElementById("Div_Advanced");
	objDiv.style.display = (objDiv.style.display == '') ? 'none' : '';
}

function DisableValidator(strIdValidator)
{
	var objValidator = document.getElementById(strIdValidator);
	if (objValidator)
		objValidator.enabled = false;
}

function EnableValidator(strIdValidator)
{
	var objValidator = document.getElementById(strIdValidator);
	if (objValidator)
		objValidator.enabled = true;
}

function SynchronizeByArrivalDate()
{
	if (!objArrivalDate || !objDepartureDate || !objDuration)
		return false; 
	
	if (objArrivalDate.value != "")
	{
		// verify that objArrivalDate.value is a date
		if (isDate(objArrivalDate.value))
		{
			if (objDuration.value != "")
			{
				// verify that duration is an Int
				if (isInt(objDuration.value))
				{
					var intDuration = parseInt(objDuration.value,10);
					if (intDuration > 0)
					{
						var strDate = AddDays(objArrivalDate.value, intDuration - 1);
						objDepartureDate.value = strDate;
						
						return true; // departure date synchronized
					}
					else 
						return false; // nothing todo
				}
				else
					return false; // wrong format (duration)
			}
			else
			{
				if (objDepartureDate.value != "")
				{
					// verify that objDepartureDate.value is a date
					if (isDate(objDepartureDate.value))
					{
						var intDuration = GetDays(objArrivalDate.value, objDepartureDate.value);
						intDuration += 1; 
						objDuration.value = intDuration;
					}
					else
						return false; // wrong format (departure date)
				}
				else
					return false; // nothing todo
			}
		}
		else
			return false; // wrong format (arrival date)
	}
	else
		return false; // nothing todo
}

function SynchronizeByDepartureDate()
{
	if (!objArrivalDate || !objDepartureDate || !objDuration)
		return false; 
		
	if (objDepartureDate.value != "")
	{
		// verify that objDepartureDate.value is a date
		if (isDate(objDepartureDate.value))
		{
			if (objArrivalDate.value != "")
			{
				// verify that objArrivalDate.value is a date
				if (isDate(objArrivalDate.value))
				{
					var intDuration = GetDays(objArrivalDate.value, objDepartureDate.value);
					intDuration += 1; 
					objDuration.value = intDuration;
					
					return true; // duration synchronized
				}
				else
					return false; // wrong format (arrival date)
			}
			else
				return false; // nothing todo
		}
		else
			return false; // wrong format (departure date)				
	}
	else
		return false; // nothing todo
}

function SynchronizeByDuration()
{
	if (!objArrivalDate || !objDepartureDate || !objDuration)
		return false; 

	if (objDuration.value != "")
	{
		// verify that duration is an Int
		if (isInt(objDuration.value))
		{
			if (objArrivalDate.value != "")
			{
				// verify that objArrivalDate.value is a date
				if (isDate(objArrivalDate.value))
				{
					var intDuration = parseInt(objDuration.value, 10);
					if (intDuration > 0)
					{
						var strDate = AddDays(objArrivalDate.value, intDuration - 1);
						objDepartureDate.value = strDate;
				
						return true; // departure date synchronized
					}
					else 
						return false; // nothing todo
				}
				else 
					return false; // wrong format (arrival date)
			}
			else
				return false; // nothing todo
		}
		else
			return false; // wrong format (duration)
	
	}
	else
		return false; // nothing todo
}

