function bookmarkPage(title, url)
{
    if (window.sidebar) // firefox
        window.sidebar.addPanel(title, url, "");
    else if(window.opera && window.print) // opera
    {
        var elem = document.createElement('a');
        elem.setAttribute('href', url);
        elem.setAttribute('title', title);
        elem.setAttribute('rel', 'sidebar');
        elem.click();
    } 
    else if(document.all) // ie
        window.external.AddFavorite(url, title);
}

/**
 * el {HTMLElement} the link that opens the modal
 * @return {void}
 */
function openModal(el, config) {
    config = $.extend({
        title: '',
        width: 380,
        height: 370,
        iframeWidth: '100%',
        iframeHeight: '100%',
        iframeScroll: '',
        callback: null,
        excludeCss: []
    }, config);

    var transform = ['iframeWidth', 'iframeHeight'];
    $.each(transform, function (index, value) {
        if (isNaN(config[value]) === false) {
            config[value] += 'px';
        }
    });
    
    if (config.iframeScroll !== '') {
        config.iframeScroll = 'scrolling="' + config.iframeScroll + '" ';
    }

    //split string some ie 6 version fails to load it corectly ?!
    var ifr = '<div><iframe frameborder="0" id="popupIFrame" src';
    ifr += '="'+el.href+'" '+ config.iframeScroll +'style="height: ' + config.iframeHeight + ';width: ' + config.iframeWidth + '"></iframe></div>';
    var x = $(ifr)
        .dialog({
            width: config.width,
            height: config.height,
            modal:true,
            title: config.title || el.title,
            draggable:false,
            resizable:false,
            close:function(){
                closeModal();
                if (config.callback) {
                    config.callback();
                }
            }
        });
    
    // apply to the modal container the CSS classes of the element
    var className = el.className;
    $.each(config.excludeCss, function (index, value) {
        className = className.replace(value, '');
    });

    x[0].parentNode.className += ' ' + className || '';
} 

function closeModal()
{
    $("#popupIFrame").parent().dialog("destroy").remove();
}

function collapseAccordion(){
    //collapse all the accordion headers that don't have the 'block-collapse' class
    $(".accordion-header").each(function (index) {
        if ($(this).hasClass('block-collapse')) {
            $(this).removeClass('block-collapse');
        } else {
            $(this).removeClass('active');
            $("ul", this).hide();
        }
    });
    
}

function activateAccordion(el){
    if($(el).parent().hasClass('active')){
        collapseAccordion();
        return;
    }
    collapseAccordion();
    $(el).parent().addClass('active');
    $(el).parent().find("ul").show();
}

