function ajax(url, data, async, type, target, readyfunction)
{
    if(typeof async == 'undefined')
    {
        async = true;
    }

    if(typeof type == 'undefined')
    {
        type = 'html';
    }

    $.ajax({
		type: "POST",
		url: url,
		data: data,
        dataType: type,
        async: async,
		complete: function(xhr) {
		    if(typeof target == 'undefined' && xhr.responseText != '')
            {
                //alert(xhr.responseText);
            }
            else if(typeof target != 'undefined')
            {
                $( target ).html( xhr.responseText );
                if(typeof readyfunction != 'undefined')
                {
                    eval(readyfunction);
                }
            }
		}
	});
}

function reload(file, val, table, target_id, def)
{
    var fk = $(val).attr('id');
    var selected = $(val).val();

    var d = '';
    d += 'fk=' + fk;
    d += '&selected=' + selected;
    d += '&table=' + table;
    d += '&def=' + def;

    ajax(file, d, true, 'html', target_id, "$( target ).val("+ def +")");
}

function reloadCsomag(def)
{
    var d = 'tipus=' + $('input[name=tipus]:checked').val();

    ajax('_csomagselect.php', d, false, 'html', '#csomag', "$('#csomag').val("+ def +")");

    ar();
}

function ar()
{
    var d = '';
    d += 'csomag=' + $('#csomag').val();
    d += '&gep=' + $('#gepek').val();
    d += '&telepites=' + $('#telepites').val();

    ajax('_ar.php', d, false, 'script');

    document.getElementById('fizetendo').innerHTML = fizetendo;
}
