$(document).ready(function() {
    blankTarget();
    $("a.fancybox").fancybox({
        'zoomSpeedIn': 300,
        'zoomSpeedOut': 300,
        'overlayShow': true,
        'hideOnContentClick': false
    });

    $("a.fancybox_iframe").fancybox({
        'zoomSpeedIn': 300,
        'zoomSpeedOut': 300,
        'overlayShow': true,
        'width': 450,
        'height': 150,
        'autoScale' : false,
        'hideOnContentClick': false,
        'type': 'iframe'
    });

    $(".kosarba").fancybox({
        'autoScale' : true,
    	'type' : 'ajax',
        'titleShow' : false,
        'href' : '_kosar.php',
        'overlayOpacity' : 0.4,
		'overlayColor' : '#000',
        'hideOnContentClick': false,
    });
});

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, false, 'html', target_id, "$( target ).val("+ def +")");
}

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";
        }
    }
}

function kosarba(id)
{
    var data = 'id=' + $("#kiszereles_" + id).val() + '&darab=' + $("#darab_" + id).val();

    $.ajax({
        url: "_kosarba.php",
        type: "POST",
        data: data,
        cache: false,
        async: false,
        success: function (response) {
            $("#kosar_tartalma .right").load("_lablec_kosar.php");
            $("#darab_" + id).val('');
        }
    });
}

function ar(k, id)
{
    var data = 'k=' + k;

    $.ajax({
        url: "_ar.php",
        type: "POST",
        data: data,
        cache: false,
        complete: function(xhr) {
            $("#ar_" + id).html(xhr.responseText);
        }
    });
}

function kedvezmeny()
{
    if($('#debitcode').val() != '') {
        $('#telepules').attr("disabled", "disabled");
        $('#iskola_id').attr("disabled", "disabled");
    }
    else {
        $('#telepules').removeAttr("disabled");
        $('#iskola_id').removeAttr("disabled");
    }
}

function iskola()
{
    if($('#iskola_id').val() != 0) {
        $('#debitcode').attr("disabled", "disabled");
    }
    else {
        $('#debitcode').removeAttr("disabled");
    }
}
