/*
** kosárba pakolás
*/

function incBasket(id) {
	$.ajax({
		url: '/'+_arg+'/store/inc/'+id,
		success: function(msg){
			if (msg) {
				$('#item_count_'+id).html(msg);		
				updateBasket();		
			}
		}
	});
}

function decBasket(id) {
	$.ajax({
		url: '/'+_arg+'/store/dec/'+id,
		success: function(msg){
			if (msg) {
				$('#item_count_'+id).html(msg);		
				updateBasket();		
			}
		}
	});
}

function searchNav( num ) {
	$('#searchLayer').slideToggle();
}

var box = 1;
var boxs = 1;
function changeObj( num, prefix ) {
    var open = '';

	switch (prefix) {
        case 'desc': open = box; box = num; break;
        case 'subitems': open = boxs; boxs = num; break;
    }

    if (!open) return false;

    $('#box-'+prefix+open).hide();
	$('#box-'+prefix+num).show();
	$('#link-'+prefix+open).removeClass("active");
	$('#link-'+prefix+num).addClass("active");

}

$(document).ready(function(){
    $("#dsearch").click(function () {
        $("#detailed-search").slideToggle();
    });

    //basketDown();
});

function change(id) {
$(document).ready(function(){
        $(".answer").hide();
        $("#box"+id).toggle();
        $(".question").css({'font-weight' : 'normal'});
        $("#link"+id).css({'font-weight' : 'bold'});
});
}

var boxz = 1;
function changeCat( num ) {
	$("#boxz"+num).toggle();

    boxz = num;
}

function setStoreShop(el) {
	$.ajax({
		url: '/'+_arg+'/system/setstoreshop/'+el.value+'/',
        success: function () {
            window.location.reload();
	}
	});
}

function goCatList(el) {
    window.location = '/'+_arg+'/termekek/'+el.value;
}

function setPricelistFilter(type, value) {
	$.ajax({
		url: '/'+_arg+'/system/priceliststore/'+value+'/',
        success: function () {
            window.location.reload();
	}
	});
}

function setFilter() {
	$.ajax({
		url: '/'+_arg+'/system/setfilter/'+$('#order-name').val()+'/'+$('#filter-name').val()+'/',
        success: function () {
            window.location.reload();
	}
	});
}

function sendForm(id) {
    $('#'+id).submit();
}

function setSelect(el) {
    var key = '';
    var target = '';

    var fields = {
        'fp_search_msearch_brand': 'msearch-cat',
        'fp_search_msearch_brand2': {'id' : 'fp_search_msearch_brand', 'target': 'msearch-status'},
        'fp_search_msearch_cat': 'msearch-number',
        'fp_search_msearch_cat2': {'id' : 'fp_search_msearch_cat', 'target': 'msearch-status'},
        'fp_search_msearch_number': 'msearch-status',
        'fp_search_msearch_display1': 'msearch-display2',
        'fp_search_msearch_vga1': 'msearch-vga2',
        'fp_search_msearch_cpu1': 'msearch-cpu2',
        'fp_search_msearch_cpu2': 'msearch-cpu3',
        'fp_search_msearch_hdd1': 'msearch-hdd3'
    };

    if ( typeof(el) == 'string' ) {
        if ( !fields[el] )
            return false;

        key = el;
        el = $('#'+fields[el]['id'])[0];
        target = fields[key]['target'];

    } else if ( !fields[el.id] ) {
        return false;
    } else {
        key = el.id;
        target = fields[key];
    }

	$.ajax({
		url: '/'+_arg+'/termekek/kereses/osszetett/setselect/'+key+'/'+el.value+'/',
        success: function (data) {
            $('#'+target).html(data);

            if (key == 'fp_search_msearch_brand' && el.value != '0')
                setSelect($('#fp_search_msearch_cat')[0]);
            else if (key == 'fp_search_msearch_brand')
                setSelect('fp_search_msearch_brand2');

            if (key == 'fp_search_msearch_cat' && el.value != '0')
                setSelect($('#fp_search_msearch_number')[0]);
            else if (key == 'fp_search_msearch_cat')
                setSelect('fp_search_msearch_brand2');

            if (key == 'fp_search_msearch_number' && el.value == '0')
                setSelect('fp_search_msearch_cat2');

            if (key == 'fp_search_msearch_cpu1')
                setSelect($('#fp_search_msearch_cpu2')[0]);
    	}
	});
}
