function changeDiv(the_div, the_change)
{
    var the_style = getStyleObject(the_div);
    if (the_style != false)
    {
        if (the_change || the_change=='') {
            the_style.display = the_change;
        } else if (the_style.display == 'none') {
            the_style.display = 'block';
        } else {
            the_style.display = 'none';
        }
    }
}

function getStyleObject(objectId)
{
    if ((document.getElementById) && (document.getElementById(objectId)))
    {
        return document.getElementById(objectId).style;
    }
    else if ((document.all) && (document.all(objectId)))
    {
        return document.all(objectId).style;
    } else {
        return false;
    }
}


function patronat(){
if(!document.getElementById("patronat")){
    var pat_form = document.createElement("div");
    pat_form.innerHTML = document.getElementById("tresc_form").innerHTML;
    document.getElementById("tresc_form").innerHTML="";
    pat_form.id = "patronat";
    pat_form.className = "patronat";
    document.body.appendChild(pat_form);

    if(dragdrop_patronat){
        var box = mint.gui.RegisterDragObject("patronat");
        box.AddGrip("deklaracja_ptr", false);
        dragdrop_patronat = false;
    }
}else document.getElementById("patronat").style.display = "block";
    
    document.body.scrollTop = 0+"px"; 
    document.body.scrollLeft= 0+"px";
}

    var resCount, reservation_price, currency, selCount, selling_price;
            function sumValue(quantity)
            {
                var max   = resCount;
                var price = reservation_price;
                
                if(quantity > max) {
                    document.getElementById('ilosc2').value = max;
                    document.getElementById('suma').innerHTML = (max*price)+' '+currency;
                    alert('Zbyt duża ilość biletów');
                } else {
                    document.getElementById('suma').innerHTML = (quantity*price)+' '+currency;
                }
            }
    
            function maxValue(quantity)
            {
                var max   = selCount;
                var price = selling_price;
                if(quantity > max) {
                    document.getElementById('ilosc').value = max;
                    document.getElementById('suma2').innerHTML = (max*price)+' zł';
                    alert('Zbyt duża ilość biletów');
                } else {
                    document.getElementById('suma2').innerHTML = (quantity*price)+' zł';
                }
            }
            
            function hideAll()
            {
                changeDiv("bilety","none");
                changeDiv("payment","none");
                changeDiv("inforezerwacji","none");
                changeDiv("infosprzedaz","none");
                changeDiv("polesumy","none");
                changeDiv("polesumy2","none");
            }

            function getStyleObject(objectId)
            {
                if ((document.getElementById) && (document.getElementById(objectId))) {
                    return document.getElementById(objectId).style;
                } else {
                    if ((document.all) && (document.all(objectId))) {
                        return document.all(objectId).style;
                    } else {
                        return false;
                    }
                }
            }
             function selling()
            {
                hideAll();
                changeDiv('polesumy2','block');
                changeDiv('payment','block');
                document.getElementById('button1').value = 'Kup';
                changeDiv('infosprzedaz','block');
                changeDiv('zapkt','');
            }

            function reserve()
            {
                hideAll();
                changeDiv('polesumy','block');
                changeDiv('bilety','block');
                changeDiv('inforezerwacji','block');
                document.getElementById('button1').value = 'Zarezerwuj';
                changeDiv('zapkt','none');
            }
            
    function DeleteItem(idp, idn) {
        var parametry = "idp="+idp+"&idn="+idn+"&action=del";
        var myAjax = new Ajax.Request(
        "/news/powiazania_engine.php", 
        {
            method: 'get',
            parameters: parametry,
            onComplete: function(originalRequest){
                var tab = originalRequest.responseText.split(',');
                if (tab[0] == 'error')
                    alert(tab[1]);
                var fItm = $('Selected_item_' + idp);
                $('Selected_container').removeChild(fItm);
            }
        });
    }
    function SelectorToggle(obj,idn) {
        var fItm = $('Selected_item_' + obj.id);
        if (fItm != null) {
             $('Selected_container').removeChild(fItm);
        } else {
            fItm = document.createElement('div');
            fItm.id = 'Selected_item_'+ obj.id;
            fItm.innerHTML = obj.value;
            fItm.onclick = function() { SelectorToggle( obj ); };
            fItm.style.cssText = 'cursor:pointer;';
            
            var img = document.createElement('img');
            img.src = '/gfx/cross.png';
            img.title = 'kliknij, aby usunąć';
            
            fItm.innerHTML += ' ';
            fItm.appendChild(img);
            
            var In = document.createElement('input');
                 In.name = "wykonawcy[]";
                 In.value = obj.id;
                 In.type = 'hidden';
                 fItm.appendChild(In);
             
             var parametry = "idp="+obj.id+"&idn="+idn+"&action=add";
             var myAjax = new Ajax.Request(
            "/news/powiazania_engine.php", 
            {
                method: 'get',
                parameters: parametry,
                onComplete: function(originalRequest){
                    var tab = originalRequest.responseText.split(',');
                    if (tab[0] == 'error')
                        alert(tab[1]);
                    $('test_json').value = "";
                    $('Selected_container').appendChild(fItm);
            }
            });
        }
    }
