$(document).ready(function() {

		$('a.big_search').click(function() { //show/hide extended search

			if($('#extended_search').css('display') == 'none'){
			   $('#extended_search').show();
			} else {
			   $('#extended_search').hide();
			}

		});

		//about room types
	    $('a.minus').live('click', function() { // when you click the remove link (room_types)
	    	if ($('#room_type_3').length > 0){
				$('#room_type_3').remove();
			}
			else if($('#room_type_2').length > 0) {
				$('#room_type_2').remove();
				$('a.plus').show();
			}

		});

		$('a.plus').live('click',function() {// when you click the add link
			var MainSection = $(this).parent().parent();
			if ($('#room_type_2').length == 0  ){
				room_type_2.appendTo(MainSection);

			}
			else if($('#room_type_3').length == 0) {
				room_type_3.appendTo(MainSection);
				$(this).hide();
			}

		});

	});


function ValidateHotelSearchForm( form )
{
	var Destination	=	form.inputString;
	if(Destination.value.length < 1 )
	{
		alert( gTLNG_DATA["input_destination"] );
		Destination.focus();
		return false;
	}

	var CheckIn		=	form.tbDateFrom;
	var CheckOut	=	form.tbDateTo;

	if ( CheckIn.value.length > 0 || CheckOut.value.length > 0 ) {

		if (isDate(CheckIn.value)==false)
		{

			alert( gTLNG_DATA["input_start_date"] );
			CheckIn.focus();
			return false;
		}

		if (isDate(CheckOut.value)==false)
		{
			alert( gTLNG_DATA["input_end_date"] );
			CheckOut.focus();
			return false;
		}

		if (compareDates(CheckIn.value, CheckOut.value) >= 0)
		{
			alert( gTLNG_DATA["input_valid_dates"] );
			CheckIn.focus();
			return false;
		}

		/*
		var RoomCnt	=	form.sCount1;

		if ( RoomCnt.selectedIndex < 1)
		{
			alert("Моля изберете брой стаи");
			RoomCnt.focus();
			return false;
		}
		*/

		var AdultsCnt	=	form.sAdults1;
		if (0 > RoomCnt.selectedIndex)
		{
			alert( gTLNG_DATA["input_valid_adults"] );
			AdultsCnt.focus();
			return false;
		}
	}


    return true;
}


// Validate for hotel info with date
function ValidateHotelInfoSearchForm( form )
{
	var Destination	=	form.inputString;
	if( Destination != undefined && Destination.value.length < 1 )
	{
		alert( gTLNG_DATA["input_destination"] );
		Destination.focus();
		return false;
	}

	var CheckIn	 =	form.tbDateFrom;
	var CheckOut =	form.tbDateTo;

	if ( CheckIn.value.length == 0 || CheckOut.value.length == 0 ) {
		alert( gTLNG_DATA["input_valid_dates"] );
		return false;
	}


	if (isDate(CheckIn.value)==false)
	{

		alert( gTLNG_DATA["input_start_date"] );
		CheckIn.focus();
		return false;
	}

	if (isDate(CheckOut.value)==false)
	{
		alert( gTLNG_DATA["input_end_date"] );
		CheckOut.focus();
		return false;
	}

	if (compareDates(CheckIn.value, CheckOut.value) >= 0)
	{
		alert( gTLNG_DATA["input_valid_dates"] );
		CheckIn.focus();
		return false;
	}

	var RoomCnt	=	form.sCount1;
	if ( parseInt(RoomCnt.value) < 1)
	{
		alert("Моля изберете брой стаи");
		RoomCnt.focus();
		return false;
	}

	var AdultsCnt	=	form.sAdults1;
	if (0 > AdultsCnt.selectedIndex)
	{
		alert( gTLNG_DATA["input_valid_adults"] );
		AdultsCnt.focus();
		return false;
	}


    return true;
}





function isDate(str_date)
{
	return (str_date.match(/(0[1-9]|[12][0-9]|3[01])-(0[1-9]|1[012])-(19|20)[0-9][0-9]/) == null) ? false : true;
}

function compareDates(str_date_a, str_date_b)
{
	array_date_a = str_date_a.split('-');
	array_date_b = str_date_b.split('-');

	year_a = array_date_a.pop();
	year_b = array_date_b.pop();

	month_a = array_date_a.pop();
	month_b = array_date_b.pop();

	day_a = array_date_a.pop();
	day_b = array_date_b.pop();

	if (year_a == year_b)
	{
		if (month_a == month_b)
		{
			if (day_a == day_b)
				return 0;
			else
			{
				if (day_a < day_b)
					return -1;
				else
					return 1;
			}
		}
		else
		{
			if (month_a < month_b)
				return -1;
			else
				return 1;
		}
	}
	else
	{
		if (year_a < year_b)
			return -1;
		else
			return 1;
	}
}

function validate_form( form )
{

	var Username	=	form.user;
	if(Username.value.length==0)
    {
        alert ( gTLNG_DATA["fill_in_username"] );
        Username.focus();
        return false;
    }

    var Password	=	form.pass;
	if(Password.value.length==0)
    {
        alert ( gTLNG_DATA["fill_in_password"] );
        Password.focus();
        return false;
    }

    return true;
}

function validate_log_to_res_form( form )
{

	var Username	=	form.OurRefNum;
	if(Username.value.length==0)
    {
        alert ( gTLNG_DATA["fill_in_reservation_number"] );
        Username.focus();
        return false;
    }

    var Password	=	form.UserPassword;
	if(Password.value.length==0)
    {
        alert ( gTLNG_DATA["fill_in_password"] );
        Password.focus();
        return false;
    }

    return true;
}

function show_rooms(form) {

	var s_room_type_count1	=	form.sCount1;
	var s_room_type_count2	=	form.sCount2;
	var s_room_type_count3	=	form.sCount3;

	var div2 = document.getElementById("rooms_2");
	var div3 = document.getElementById("rooms_3");

	/*
	if (s_room_type_count1.selectedIndex < 1 ) {

		s_room_type_count2.selectedIndex = 0;
		div2.style.display = 'none';
	}
	else {
		div2.style.display = 'block';
	}
	*/
	div2.style.display = 'block';

	if (s_room_type_count2.selectedIndex < 1 ) {

		s_room_type_count3.selectedIndex = 0;
		div3.style.display = 'none';
	}
	else {
		div3.style.display = 'block';
	}
}

function show_ages(form, type){

	try {

		var form;
		var type;
	  	var children 	= 	document.forms[form].elements['sChildren'+type];


		var age1	=	document.getElementById("sChAges"+type+1);
		var age2	=	document.getElementById("sChAges"+type+2);

		if (children.value == 0){
			age1.style.display = 'none';
			age2.style.display = 'none';
		}

		if (children.value == 1){
			age1.style.display = 'block';
			age2.style.display = 'none';
			age1.focus()
		}

		if (children.value == 2){
			age1.style.display = 'block';
			age1.focus()
			age2.style.display = 'block';
		}



	  } catch (e) {
	  	//alert("Oops! Something bad just happened. Calling 911...");
	  	return false;
	  }

	  return true;
}
