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(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('_reloadselect.php', d, true, 'html', target_id, "$( target ).val("+ def +")");
}

function rendeles(id, e)
{
    var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;

	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}

    $('#popup_div').css({left:posx, top:posy});

    var darab = 1;

    var d = '';
    d += '&id=' + id;
    d += '&darab=' + darab;

    ajax('_rendeles.php', d, true, 'html', '#kosar_tartalma', "$('#popup_div').show().fadeOut(1500)");
}

function doSomething(e) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;

	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}

    alert(posx);
}


function reloadCaptcha(id)
{
	document.getElementById('captcha_'+id).src = 'img/captcha.php?id='+id+'&'+Math.random();
}

function blankTarget()
{
    if(!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for(var i=0; i<anchors.length; i++)
    {
        var anchor = anchors[i];
        anchor.tabindex = i;
        if(anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
        {
            anchor.target = "_blank";
        }
    }
}

$(document).ready(function() {
	blankTarget();
});

