
$(document).ready(
	function() {

	switchRooms('#FindHotel_NoOfRooms');

	if($(".tool_tip").tooltip)
		$(".tool_tip").tooltip();

		$(window).unload(
			function(){
				if($.unblockUI)
					$.unblockUI();
			}
		);

	if($("#NameToFind").autocomplete)
		$("#NameToFind").autocomplete(
			'/utils/autocomplete/hotel/',
			{
				delay:10,
				minChars:2,
				matchSubset:1,
				matchContains:1,
				cacheLength:1,
				onItemSelect:selectItem,
				onFindValue:findValue,
				formatItem:formatItem,
				autoFill:false,
				lineSeparator: ';'
			}
		);

		setTimeout("show_notice()", 2000);
		setTimeout("show_notice1()", 4000);

		$("#commentform").hide();
		$("#commentform1").hide();
		$("#loading_win").hide();
		$("#loading_win1").hide();
		$("#thank_you").hide();
		$("#thank_you1").hide();
		$("#closeform").hide();
		$("#closeform1").hide();
	}

);
        
function show_success()
{
	$("#loading_win").hide();
	$("#commentform").hide();
	$("#closeform").hide();
	$("#thank_you").show();
}

function show_success1()
{
	$("#loading_win1").hide();
	$("#commentform1").hide();
	$("#closeform1").hide();
	$("#thank_you1").show();
}

function togglelink()
{
	$("#addcomment").toggle();
	$("#closeform").toggle();
	$("#commentform").toggle();
}


function togglelink1()
{
	$("#addcomment1").toggle();
	$("#closeform1").toggle();
	$("#commentform1").toggle();
}

function show_notice()
{
	$("#notice_div_1").css("display", "block").fadeIn("slow");
}

function hide_notice()
{
	$("#notice_div_1").css("display", "none");
	$("#notice_div_1").fadeOut("slow");
}

function show_notice1()
{
	$("#notice_div_2").css("display", "block");
	$("#notice_div_2").fadeIn("slow");
}

function hide_notice1()
{
	$("#notice_div_2").css("display", "none");
	$("#notice_div_2").fadeOut("slow");
}

function findValue(li) {
	if( li == null ) return;

	if( !!li.extra ) var sValue = li.extra[0];

	else var sValue = li.selectValue;
}

function selectItem(li) {
	findValue(li);
}

function formatItem(row, i) {
	if(row[1] == '-1')
	{
		return '<span style="color: #888">' + row[0] + '</span>'
	}
	else
	{
		return '<span>' + row[0] + '</span>';
	}
}

function changelocation(svalue, controller, action, returnto, i)
{
	var cvalue = svalue.value;
	var cur;

	if(cvalue == 1)
		cur = 'USD';
	else cur = 'EUR';

	var c = controller;
	var a = action;
	window.location = '/utils/set_currency/?code='+cur+'&returnto=' + escape(returnto);
}

function switchRooms(o)
{
	RoomNo = $(o).val();

	for(i = 5; i > RoomNo; i--)
	{
		$('#room-' + i).hide().find('input').val('');
		$('#room-child-' + i).hide();
	}

	for(i = 1; i <= RoomNo; i++)
	{
		$('#room-' + i).show();
		showChildOpts(i);
	}
}

function showChildOpts(o)
{
	var noofchildren = parseInt($("select[name='FindHotel[Rooms][" + o + "][Children]']").val());

	if(noofchildren > 0)
	{
		$('#room-child-' + o).show();

		$('#room-child-' + o)
			.find('div.child-age:gt('+(noofchildren-1)+')').hide()
			.end()
			.find('div.child-age:lt('+(noofchildren)+')').show();
	}
	else
	{
		$('#room-child-' + o).hide();
	}
}

$(document).ready(
	function ()
	{
		if($.unblockUI)
			$.unblockUI();

		var advanced_pos = $("#advanced").attr("class");

		if( advanced_pos == "display_none" ) {
			$("#simpleinscription").hide();
		}
		else {
			$("#advancedinscription").hide();
		}
	}
);

function togglesform(hiddenvalue)
{
	$("#simpleinscription").toggle();
	$("#advancedinscription").toggle();
	$("#advanced").toggle();

	if(hiddenvalue == 0)
	{
		//change value for searchtype = advanced
		$("#searchtype").val("advanced");
	}
	else $("#searchtype").val("");
}

$(document).ready(
	function() {
		var img1 = new Image();
		img1.src = '/images/searchpage/loaditem.gif';

		var img2 = new Image();
		img2.src = '/images/searchpage/tps_bg_search.jpg';

		var img3 = new Image();
		img3.src = '/images/searchpage/tpslogo.jpg';

//		$("#FindHotel").validationAideEnable(null, {summaryFieldMessageFormat: "##MESSAGE##", beforeSubmit: showSearchIndicator});
		
		$('#linkreset').click( 
			function(){
				$('#FindHotel').clearForm();
				$('#FindHotel_NoOfRooms').val(1);
				$("select[name='emptyselect']").val(1);
				$("select[name='FindHotel[CityDistrict]']").val(-1);
				
				for(i = 1; i <= 5; i++){
					$("select[name='FindHotel[Rooms]["+i+"][Adults]']").val(2);
					$("select[name='FindHotel[Rooms]["+i+"][Children]']").val(0);
					$("select[name='FindHotel[Rooms]["+i+"][ChildAge][1]']").val(0);
					$("select[name='FindHotel[Rooms]["+i+"][ChildAge][2]']").val(0);
				}
				
				$('#FindHotel_NoOfRooms').change();
				
				return false;
			}
		);
	}
);

function check()
{
	var d1 = $('#FindHotel_ArrivalDate').val();
	var d2 = $('#FindHotel_DepartureDate').val();

	d1 = d1.split('/');
	d2 = d2.split('/');

	if(d1.length < 3 || d2.length < 3)
		return;

	if(d1[2] < d2[2])
		return true;

	if(d1[2] == d2[2])
	{
		if(d1[1] < d2[1])
			return true;

		if(d1[1] == d2[1])
		{
			return d1[0] < d2[0];
		}
	}
}

function changetab()
{
	document.getElementById('hoteltabs').tabber.tabShow(2);
}

function WindowOpen()
{
	window.open('/new/window_open_best_price_guarantee','new','width=450,height=575,toolbar=0,menubar=0,scrollbars=1,location=0,resizable=0');

	return false;
}

function WindowOpenThaute()
{
	window.open('https://seal.thawte.com/thawtesplash?form_file=fdf/thawtesplash.fdf&dn=SECURE.TURKEYTPS.COM&lang=en','new','width=550,height=575,toolbar=0,menubar=0,scrollbars=1,location=0,resizable=0');

	return false;
}

var_show = 1;
function js_showavailability(id_show){
	if(id_show == 1) {
		$('#findCheckAvailability').show();
		var_show = 0;
	}
	else {
		$('#findCheckAvailability').hide();
		var_show = 1;
	}
}

function swap_in( id )
{
    $( "#ce_" + id + "" ).addClass("events_img_sub_menu_selected");
}

function swap_out( id )
{
    $( "#ce_" + id + "" ).removeClass("events_img_sub_menu_selected");
}
