$(document).ready(function()
    {
        //var cityParams = "&list=allcity";
        //if(currentCountry != '')
        //    cityParams = "&country="+currentCountry;
        /*$.ajax({
            type: "POST",
            url: "assets.php?page=" + currentPage + cityParams,
            dataType: "html",

            success: function (result)
            {
                $('#citySelect').html(result);
                $('#citySelect').val('');
                if(currentCity != '')
                {
                    $('#citySelect').val(currentCity);
                }
                /*    if (currentCountry != '' && currentCity != '')
                    {
                        $.ajax({
                            type: "POST",
                            url: "search.php?page=" + currentPage,
                            dataType: "html",
                            data: "country=" + currentCountry + "&city=" + currentCity,

                            success: function (result)
                            {
                                $('#siteContent').html(result);
                                if( ((currentMode == 'flight') || (currentMode == 'travel')) && (currentProvider != '') && (currentPrice != '') )
                                {
                                    showDetails(currentProvider,currentPrice);
                                }

                                if( (currentMode == 'booking') && (currentProvider != ''))
                                {
                                    showFlightFrame(currentProvider);
                                }
                            }
                        });
                    }
                }
		else
		{
			var rid = Math.floor(Math.random() * ($('#citySelect').children().length - 1)) + 1;
			$('#citySelect option').eq(rid).attr('selected', 'selected');
			setTimeout("$('#citySelect').change();",200);
		}
            }
        });*/

        /*$.ajax({
            type: "GET",
            url: "get_country_description.php?country="+currentCountry,
            dataType: "html",
	    data: "country=" + currentCountry,

            success: function (result)
            {
                $('#didYouKnowBox').html(result);
            }
        });*/
    });



function languageSelector_change (box)
{
        window.location = currentDir + '/lng/' + box.value + '/';
}



function countrySelect_change (box)
{
    $.ajax({
        type: "POST",
        url: "assets.php?page=" + currentPage,
        dataType: "html",
        data: "country=" + box.value,

        success: function (result)
        {
            $('#citySelect').html(result);
            //$('#citySelect').val('');
            $('#citySelect').get(0).selectedIndex = 0;
            //searchForm_redir();
        }
    });

    $.ajax({
        type: "POST",
        url: "get_country_description.php",
        dataType: "html",
        data: "country=" + box.value,

        success: function (result)
        {
            $('#didYouKnowBox').html(result);
        }
    });
}

function citySelect_change (box)
{
    $.ajax({
        type: "POST",
        url: "assets.php?page=" + currentPage,
        dataType: "text",
        data: "city=" + box.value,

        success: function (result)
        {
            $('#countrySelect').val(result);
            //searchForm_redir();
        }
    });
}

function searchForm_submit ()
{
    var country = $('#countrySelect').val();
    var city = $('#citySelect').val();

    if (country != '' && city != '')
    {
        $.ajax({
            type: "POST",
            url: "search.php?page=" + currentPage,
            dataType: "html",
            data: "country=" + country + "&city=" + city,

            success: function (result)
            {
                $('#siteContent').html(result);
            }
        });
    } else
{
        alert('Kérjük, válasszon Országot vagy Várost!');
    }
}

function searchForm_redir ()
{
    var country = $('#countrySelect').val();
    var city = $('#citySelect').val();

    if (country != '' && city != '')
    {
        window.location = dir + '/' + currentLink + '/' + country + '/' + city + '/';
    }
}

function signupForm_submit ()
{
    var first = $('#signupFirstname').val();
    var last = $('#signupLastname').val();
    var email = $('#signupEmail').val();
    var emailRegex = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

    if (first != '' && last != '' && email != '')
    {
        if (emailRegex.test(email) == false)
        {
            alert(currentValidmail);
        } else
{
            $.ajax({
                type: "POST",
                url: "signup.php",
                dataType: "html",
                data: "first_name=" + first + "&last_name=" + last + "&email=" + email,

                success: function (result)
                {
                    $('#signupForm').html(result);
                }
            });
        }
    } else
{
        alert(currentSignuperror);
    }
}



var wrapperOffset = 0;
var selectedTab = null;
var tabCount = 0;



function scrollTabs (d)
{
    var wrapper = document.getElementById('cityViewerTabs');

    switch (d)
    {
        case 'previous':
            wrapperOffset += 142;
            break;

        case 'next':
            wrapperOffset -= 142;
            break;
    }

    wrapperOffset = Math.max(wrapperOffset, (tabCount - 5) * -142);
    wrapperOffset = Math.min(wrapperOffset, 0);

    wrapper.style.left = String(wrapperOffset) + 'px';
}



function tab_click (t, id)
{
    if (selectedTab != null)
    {
        selectedTab.className = "tab";
    }

    selectedTab = t;
    selectedTab.className = "tab selected";

    $('.details-list').css('display', 'none');
    $('#tabContent_' + id).css('display', 'table');
}



function showDetails (provider,price)
{
    $.ajax({
        type: "GET",
        url: "get_post.php?page=" + currentPage + "&provider=" + provider + "&price=" + price + "&country=" + currentCountry + "&city=" + currentCity,
        dataType: "html",

        success: function (result)
        {
            $('#navigationContainer').html(result);
        }
    });
}



function showFlightFrame (target)
{
    $('#siteContent').html('<iframe src="http://www.amadeusepower.com/budapt/portals/budapt/flightfaresearch.aspx?Culture=' + currentCulture + '&External_FlightFareSearch_SearchType=Rountdrip&External_FlightFareSearch_From=BUD&External_FlightFareSearch_To=' + target + '&External_FlightFareSearch_PrefferedAirlines=QR&External_FlightFareSearch_DepartureTime=00:01&External_FlightFareSearch_ArrivalTime=00:01&External_FlightFareSearch_NumberOfAdults=1&External_FlightFareSearch_NumberOfChilds=0&External_FlightFareSearch_NumberOfInfants=0&External_FlightSearchTypeByProvider=AmadeusAndExtProviders&External_FlightFareSearch_FlightClass=0&External_Affiliate=www.bud.hu&IsExternalAccess=true"></iframe>');
}

function showFlightFrame2 (url)
{
    $('#siteContent').html('<iframe src="'+ url +'"></iframe>');
}


