function popupLinks(popurl, x, y)
{
    var winpops=window.open(popurl,"","width="+x+",height="+y+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1")
}
var otworzFormularz = function(url, title, params, type) {
    window.open(url, title, params);
  };

function block_checkbox(checked)
{
    if(checked.length==2)
        {
            $('input:checkbox.check_por').each(function(i)
            {
                if($(this).is(':checked'))
                {
                    
                }
                else
                {
                    $(this).attr('disabled', true);
                }
            });
        }
        else
        {
            $('input:checkbox.check_por').each(function(i)
            {
                $(this).attr('disabled', false);
            });
        }
}

$(document).ready(function()
{
     // operacje dla opcji porĂłwnania ofert
    var checked = new Array();
    var url = '';
    
    $(".popupLink").live("click", function()
    {   
        var rel = $(this).attr('rel');
        var poz = rel.split("_");
        popupLinks($(this).attr('href'), poz[0], poz[1]);
        return false; 
    });
    
    $('input:checkbox.check_por').live('click', function()
    {
        // dodanie wybranego produktu do porĂłwnania
        if($(this).is(':checked'))
        {
            checked.push($(this).val());
            block_checkbox(checked);
        }
        else
        {
            checked.shift();
            block_checkbox(checked);
        }
       
    });
    
    $('.compare_products').live('click', function()
    { 
        url = document.location.pathname;
            var m = url.split(",");
            
            var build_url = m[0].split("-");
            
            var compare = checked[0]+"_"+checked[1];
            
            if (typeof build_url[1] == 'undefined') { 
                var matches = build_url[0].match(/^\/(.+)\/$/);
                var new_url = "http://"+document.location.hostname+"/porownanie-"+matches[1]+","+compare+".html";
            } else {
                var new_url = "http://"+document.location.hostname+"/porownanie-"+build_url[1]+","+compare+","+m[1];
            }

            window.location=new_url;
            return false;
    });
});
