function refine_search_link_click()
{

	var var_link_div = $("refine_search_link_div");
	var var_form_div = $("advanced_search_form_div");

	var_link_div.style.display = "none";
	var_form_div.style.display = "block";

	return false;
}

function advanced_search_populate_regions_dropdown_from_server(originalRequest)
{
		
	Try.these(
			function () 
			{				
				
				var jsonObject = eval('(' + originalRequest.responseText + ')');				
				
				
				document.getElementById("region_id").options[0] = new Option("", "-1");
				document.getElementById("region_id").options.length  = 1;
				
				for(var i=0; i<jsonObject["object_data"].length; i++)
				{
					if(jsonObject["object_data"][i]["user_id"]!='')
					{
						 document.getElementById("region_id").options[i+1] = new Option(jsonObject["object_data"][i]["region"], jsonObject["object_data"][i]["region_id"]);
					}
				}								
				
			
				document.getElementById("region_id").disabled = false;	
			}//function ()	
	)
	
}



function advanced_search_populate_regions_dropdown()

{
	
	
	var var_country_id = document.advanced_search_form.country_id.value;
	
	if(var_country_id > 0)
	{
		var url = "actions.php";
		var pars = "action_list=ajax_get_regions_list&country_id="+var_country_id;


		document.getElementById("region_id").options[0] = new Option("Loading...", "0");
		document.getElementById("region_id").selectedIndex = 0;
		document.getElementById("region_id").disabled = true;
		
		var myAjax = new Ajax.Request( url,

												{
													
												  method: 'get',
												  parameters: pars,
												  onComplete: advanced_search_populate_regions_dropdown_from_server
												  
												}

									);	
	}
	else
	{
		advanced_search_populate_country_dropdown();
	}




}


function advanced_search_populate_country_dropdown_from_server(originalRequest)
{
		
	Try.these(
			function () 
			{				
				
				var jsonObject = eval('(' + originalRequest.responseText + ')');				
				
				var var_country_id = document.advanced_search_form.country_id;
				var var_region_id = $("region_id");

				var_region_id.options[0] = new Option("", "-1");
				var_region_id.options.length  = 1;

				var_country_id.options[0] = new Option("", "-1");
				var_country_id.options.length  = 1;

				
				for(var i=0; i<jsonObject["countries_array"].length; i++)
				{
					if(jsonObject["countries_array"][i]["country"]!='')
					{
						 var_country_id.options[i+1] = new Option(jsonObject["countries_array"][i]["country"], jsonObject["countries_array"][i]["country_id"]);
					}
				}								

				
				for(var i=0; i<jsonObject["regions_array"].length; i++)
				{
					if(jsonObject["regions_array"][i]["region"]!='')
					{
						 var_region_id.options[i+1] = new Option(jsonObject["regions_array"][i]["region"], jsonObject["regions_array"][i]["region_id"]);
					}
				}								
				
			
				var_region_id.disabled = false;	
				var_country_id.disabled = false;	
			}//function ()	
	)
	
}

function advanced_search_populate_country_dropdown()

{
	
	
	destination_id = document.getElementById("destination_id").value;
	
	var url = "actions.php";
	var pars = "action_list=ajax_get_countries_regions_list&destination_id="+destination_id;


	var var_country_id = document.advanced_search_form.country_id;
	var var_region_id = $("region_id");

	var_country_id.options[0] = new Option("Loading...", "0");
	var_country_id.selectedIndex = 0;
	var_country_id.disabled = true;

	var_region_id.options[0] = new Option("Loading...", "0");
	var_region_id.selectedIndex = 0;
	var_region_id.disabled = true;

		
	var myAjax = new Ajax.Request( url,

											{
												
											  method: 'get',
											  parameters: pars,
											  onComplete: advanced_search_populate_country_dropdown_from_server
											  
											}

								);	



}

function check_contact_form()
{
	var var_email = $("email");
	var var_message = $("message");


	if(!validate_email(var_email, "Please enter your (valid) email address"))
	{
		return false;
	}

	
	if(isEmpty(var_message))
	{
		alert("Please enter your message");
		return false;
	}
	

	return true;
}

function clear_phone_fields(field)
{

	switch(field.name)
	{
		case "area_code":
				if(field.value == "area code")
					field.value = "";
			break;
		case "phone_number":
				if(field.value == "phone number")
					field.value = "";
			 break;
		case "extension":
				if(field.value == "extension")
					field.value = "";
			break;
	}


}

function change_description_display()
{
	var short_description_var = $("short_description_div");
	var full_description = $("full_description");


	short_description_var.style.display = "none";
	full_description.style.display = "block";

	return false;
}

function villa_to_wishlist(checkbox, villa_id, villa_wishlist_status)
{

	var action_list = "";

	if(checkbox.checked == true)
	{
		action_list = "add_villa_to_wishlist";
	}
	else
	{
		action_list = "remove_villa_from_wishlist";
	}


	var url = "actions.php";


	var pars = "action_list="+action_list+"&villa_id="+villa_id;
	
	var myAjax = new Ajax.Request( url,

											{
												
											  method: 'get',
											  parameters: pars,
											  onComplete: the_villa_to_wishlist_result
											  
											}

								);	

	return false;
}

function single_villa_to_wishlist(villa_id)
{

	var action_list = "add_villa_to_wishlist";



	var url = "actions.php";


	var pars = "action_list="+action_list+"&villa_id="+villa_id;

	var myAjax = new Ajax.Request( url,

											{
												
											  method: 'get',
											  parameters: pars,
											  onComplete: the_villa_to_wishlist_result
											  
											}

								);	

	return false;
}


function the_villa_to_wishlist_result(originalRequest)
{

	
		Try.these(
			function () {				
			
					var jsonObject = eval('(' + originalRequest.responseText + ')');		

					alert(jsonObject["html_content"][0]);

					
				
			}//function ()			
			
			
	);	
	
}


function change_subcategory(subcategory_type)
{
	
	var subcategory_var = $(subcategory);

	var url = "actions.php";
	var pars = "action_list=get_subcategory_url&subcategory_type="+subcategory_type+"&subcategory="+subcategory_var.value;


	var myAjax = new Ajax.Request( url,

											{
												
											  method: 'get',
											  parameters: pars,
											  onComplete: change_subcategory_from_server
											  
											}

								);			
										 										 
	return false;						

}


function change_subcategory_from_server(originalRequest)
{

	Try.these(
			function () {				
			
					var jsonObject = eval('(' + originalRequest.responseText + ')')
					
					if(jsonObject.length > 0)
					{
						window.location = jsonObject;
					}
					
				
			}//function ()			
		)

}


function populate_description_container()
{
	
	var short_description_div_var = $("short_description_div");		
	var description_div_var = $("description_div");	


	short_description_div_var.style.display = "none";
	description_div_var.style.display = "block";
	
										 										 
	return false;									 	
}




function check_villa_send_form()
{

	var name = $("name");
	var friend_name = $("friend_name");

	var email = $("email");
	var friend_email = $("friend_email");
	

	if(isEmpty(name))
	{
		alert("Please enter your name");
		return false;
	}

	if(isEmpty(friend_name))
	{
		alert("Please enter your friend's name");
		return false;
	}


	if(!validate_email(email, "Please enter your email address"))
	{
		return false;
	}
	

	if(!validate_email(friend_email, "Please enter your friend's email address"))
	{
		return false;
	}


	return true;
}


function check_reservation_request()
{

	var first_name = $("first_name");
	var last_name = $("last_name");

	var area_code = $("area_code");
	var phone_number = $("phone_number");
	var extension = $("extension");

	var email = $("email");

	var country = $("country");


	var checkin_year = $("checkin_year");
	var checkin_month = $("checkin_month");

	var checkout_year = $("checkout_year");
	var checkout_month = $("checkout_month");

	

	if(isEmpty(first_name))
	{
		alert("Please enter the first name");
		return false;
	}
	if(isEmpty(last_name))
	{
		alert("Please enter the last name");
		return false;
	}


	if(isEmpty(area_code))
	{
		alert("Please enter the area code");
		return false;
	}
	
	if(isEmpty(phone_number))
	{
		alert("Please enter the phone number");
		return false;
	}

	/*
	if(!isNumeric(area_code.value) || !isNumeric(phone_number.value))
	{
		alert("Please enter a valid phone number");
		return false;
	}
	*/

	if(country.value <= 0)
	{
		alert("Please select your country");
		return false;
	}

	if(!validate_email(email, "Please enter a valid email address"))
	{
		return false;
	}
	
	/*
	var current_date = new Date();
	var current_month = current_date.getMonth();

	
	if(checkin_month.value > 0 || checkin_year.value > 0)
	{
		if(current_month > checkin_month.value-1)
		{
			alert("Please enter a valid checkin date");
			return false;
		}
	}


	if(checkout_month.value > 0 || checkout_year.value > 0)
	{
		if(current_month > checkout_month.value-1)
		{
			alert("Please enter a valid checkout date");
			return false;
		}
	}
	*/

	return true;
}

function check_agent_reservation_request()
{

	var email_address = $("email_address");

	if(!validate_email(email_address, "Please enter a valid email address"))
	{
		return false;
	}

	return true;
}

function isNumeric(value) {
  if (value == null || !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
  return true;
}
