function ulubione(obj){
    title = document.title;
    url = document.location;
    if (window.sidebar) {
        window.sidebar.addPanel(title, url, "");
    }
    else 
        if (window.external) {
            window.external.AddFavorite(url, title);
        }
        else 
            if (window.opera && window.print) {
                /**
         * Opera wymaga ustawienia parametru REL dla linku
         * Firefox także wspiera takie rozwiązanie, jednak w typ wypadku
         * spowodowało by to wywołanie 2 okienek dodania - jednego pustego
         * dlatego ustawiamy parametr poprzez JavaScript
         */
                obj.rel = 'sidebar';
                return true;
            }
    return false;
}

window.addEvent('domready', function(){
    var sqB = SqueezeBox.assign($$('a[rel=boxed]'), {
        size: {
            y: 540,
            x: 930
        },
        ajaxOptions: {
            method: 'get' // we use GET for requesting plain HTML
        }
    });
    
    if ($('newsticker')) {
        flObj = new Swiff('ticker.swf', {
            id: 'flTicker',
            width: 320,
            height: 22,
            params: {
                wmode: 'transparent'
            }
        });
        
        //just caching the DOM lookup here, nothing else
        var domTickInsert = $('newsticker');
        
        domTickInsert.grab(flObj);
        
        //this is the the fix	
        if (window.ie) {
            domTickInsert.innerHTML = domTickInsert.innerHTML;
        }
    }
    validateEmail = function(email){
        var emailRegex = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;
        var result = emailRegex.test(email);
        if (!result) 
            alert('Wprowadź poprawny adres email');
        return result;
    }
    if ($('form1')) 
        $('form1').addEvent('submit', function(e){
            e.stop();
            if ($('zapytaj') && validateEmail($('nadawca').value)) 
                e.target.submit();
            
            if ($('powiadom') && validateEmail($('adresat').value)) {
                e.target.submit();
            }
            
        })
    
    if ($('newsletter')) 
        $('newsletter').addEvent('submit', function(e){
            e.stop();
            if (validateEmail(e.target.email.value)) {
            
                var req = new Request.HTML({
                    method: 'get',
                    url: 'lib/ajax/newsletter.php?u=' + e.target.email.value,
                    data: {
                        'do': '1'
                    },
                    evalScripts: false,
                    evalResponse: false,
                    onRequest: function(){
                        e.target.HTML = ('Wysyłam dane. Proszę czekać');
                    },
                    update: $('message-here'),
                    onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
                        $exec(responseHTML);
                    }
                }).send();
            }
            else {
            
            }
            
        });
    $('qsearch').addEvent('submit', function(e){
        e.stop();
        var searchstr = e.target.searchstr.value;
        var emailRegex = /^[a-z0-9-\/\\ ]{1,255}$/i;
        if (emailRegex.test(searchstr)&&searchstr.trim()!='') {
        
            var req = new Request.HTML({
                method: 'get',
                url: 'lib/ajax/search.php?s=' + searchstr,
                data: {
                    'do': '1'
                },
                onRequest: function(){
                    e.target.HTML = ('Wysyłam dane. Proszę czekać');
                },
                update: $('search-result'),
                onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
                    $('search-result').setStyles({
                        'display': 'block',
                        'opacity': 1
                    });
                }
            }).send();
        }
        else {
            alert('Wprowadź minimum 1 literę szukanej frazy');
        }
        
    });
    inputClick = function(params){
        params.each(function(a, b){
            if ($defined($(a.inid))) {
                $(a.inid).value = a.text;
                $(a.inid).setStyle('color', '#BBB');
                $(a.inid).addEvent('focus', function(e){
                    if ($(a.inid).value == a.text) {
                        $(a.inid).value = '';
                        $(a.inid).setStyle('color', '#333');
                    }
                });
                $(a.inid).addEvent('blur', function(e){
                    if ($(a.inid).value == '') {
                        $(a.inid).value = a.text;
                        $(a.inid).setStyle('color', '#BBB');
                    }
                });
            }
        })
    }
    inputClick([{
        inid: 'searchstr',
        text: 'wpisz szukane słowo'
    }, {
        inid: 'email',
        text: 'wpisz adres e-mail'
    }]);
    closesearch = function(){
        new Fx.Morph($('search-result'), {
            duration: 1000,
            transition: 'quad:out'
        }).start({
            opacity: [1, 0]
        });
        
    }
    
    if ($('poll')) 
        $('poll').addEvent('submit', function(e){
            e.stop();
            var r = false
            $('poll').getElements('input[type=radio]').each(function(e){
                r = r || e.checked
            });
            if (r) {
                $('poll').set('send', {
                    update: 'poll',
                    onSuccess: function(res){
                        $('poll').set('html', res);
                    }
                });
                $('poll').send();
            }
            else 
                alert('Wybierz jedną z opcji');
        });
    if ($('qsearch')) {
        //$('qsearch').addEvent('click',alert("fokus"));
    }
    showHide = function(e){
        var solution = e.getNext('.show-hide');
        var toggler = new Fx.Morph(solution, {
            duration: 500,
            transition: 'quad:out'
        });
        if (solution.getStyle('visibility') != 'visible') {
            solution.setStyle('display', 'block');
            toggler.start({
                opacity: [0, 1]
            })
        }
        else {
            solution.setStyle('display', 'none');
            toggler.start({
                opacity: [1, 0]
            })
        }
    }
    $$('.show-hide').each(function(e, idx){
        var problem = e.getPrevious().getPrevious();
        var link = new Element('a', {
            name: 'pr' + idx,
            href: "#pr" + idx
        }).wraps(problem);
        link.addEvent('click', function(e){
            e.stop();
            showHide(e.target.getParent());
        });
        
    })
    if (window.location.pathname == "/konfigurator_n"||window.location.hash == "#konfigurator") {
        SqueezeBox.open('/konfigurator', {
            size: {
                y: 540,
                x: 930
            }
        });
    }
});

//z dreamveawera

function MM_preloadImages(){ //v3.0
    var d = document;
    if (d.images) {
        if (!d.MM_p) 
            d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
        for (i = 0; i < a.length; i++) 
            if (a[i].indexOf("#") != 0) {
                d.MM_p[j] = new Image;
                d.MM_p[j++].src = a[i];
            }
    }
}

function MM_swapImgRestore(){ //v3.0
    var i, x, a = document.MM_sr;
    for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) 
        x.src = x.oSrc;
}

function MM_findObj(n, d){ //v4.01
    var p, i, x;
    if (!d) 
        d = document;
    if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document;
        n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) 
        x = d.all[n];
    for (i = 0; !x && i < d.forms.length; i++) 
        x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) 
        x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) 
        x = d.getElementById(n);
    return x;
}

function MM_swapImage(){ //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments;
    document.MM_sr = new Array;
    for (i = 0; i < (a.length - 2); i += 3) 
        if ((x = MM_findObj(a[i])) != null) {
            document.MM_sr[j++] = x;
            if (!x.oSrc) 
                x.oSrc = x.src;
            x.src = a[i + 2];
        }
}
