jQuery(document).ready(function(){
    
    jQuery(".print_button").click( function() {
        var target=null;
        if(typeof(this.href) != 'undefined') {
            target=this.href;
        } else if(jQuery(this).val().length > 0) {
            target=(jQuery(this).parent('form').attr('action')).replace(".html", ","+(jQuery(this).parent('form').children('#opisy').attr('checked'))+".html");
        }
        window.open(target, "Drukowanie", "status = 1, height = 500, width = 672, resizable = 1, scrollbars=1, menubar=yes");
        return false;
    });

    jQuery("#search1").submit( function() {
        var search_str = jQuery("#doc_find_text").val();
        if(search_str.length > 1)
        {
            findStringArt(search_str);
        }
        return false;
    });
})


function getStyle(el,styleProp)
{
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function pomniejszCzcionke() {

    if(document.getElementById("rozporzadzenie"))
    {
            if(jQuery.browser.mozilla) {size=getStyle("rozporzadzenie","font-size");} else {size=getStyle("rozporzadzenie","fontSize");}
            size_new = parseInt(size) - 1;
            if (size_new > 8)
            {
                document.getElementById('rozporzadzenie').style.fontSize=size_new+"px";
                document.cookie = "fontsize="+size_new+"px; path=/; domain=.inforlex.pl";
            }
    }
    else
    {
            if(jQuery.browser.mozilla) {size=getStyle("artykul","font-size");} else {size=getStyle("artykul","fontSize");}
            size_new = parseInt(size) - 1;
            if (size_new > 8)
            {
                document.getElementById('artykul').style.fontSize=size_new+"px";
                document.cookie = "fontsize="+size_new+"px; path=/; domain=.inforlex.pl";
            }
    }
    
    
    

}

function powiekszCzcionke() {

    if(document.getElementById("rozporzadzenie"))
    {
        if(jQuery.browser.mozilla) {size=getStyle("rozporzadzenie","font-size");} else {size=getStyle("rozporzadzenie","fontSize");}
        size_new = parseInt(size) + 1;
        if (size_new < 16)
        {
            document.getElementById('rozporzadzenie').style.fontSize=size_new+"px";
            document.cookie = "fontsize="+size_new+"px; path=/; domain=.inforlex.pl";
        }
    }
    else
    {
        if(jQuery.browser.mozilla) {size=getStyle("artykul","font-size");} else {size=getStyle("artykul","fontSize");}
        size_new = parseInt(size) + 1;
        if (size_new < 16)
        {
            document.getElementById('artykul').style.fontSize=size_new+"px";
            document.cookie = "fontsize="+size_new+"px; path=/; domain=.inforlex.pl";
        }
    }
}

function dodajDoUlubionych(){
    var title=document.title
    var url=document.URL

    if( document.all ) window.external.AddFavorite( url, title);
    
    //else if (window.sidebar) jQuery(".ulubione").html("Wciśnij Ctrl+D");

    //else if(window.opera) jQuery(".ulubione").html("Wciśnij Ctrl+D");
    
}

var TRange=null

var lastSearch=null;
var lastSearchResults=null;
var lastSearchPosition=0;
var searchableParagraphs=null;

function findStringArt (str) {
    if (searchableParagraphs == null)
    {
      searchableParagraphs=jQuery('#subartykul').find('p');
    }
    if(lastSearch == str)
    {
        lastSearchPosition++;
        if(lastSearchPosition == lastSearchResults.length)
            lastSearchPosition=0;
    }
    else
    {
        lastSearch = str;
        lastSearchPosition=0;

      searchableParagraphs.removeHighlight();
      if( navigator.appName.indexOf("Internet Explorer") < 0)
        searchableParagraphs.each(function() {$.highlight(this,str.toUpperCase())});
      else
        for(i=0; i<1; i++)
        {
          $.highlight(searchableParagraphs[i],str.toUpperCase());
        }

        if(searchableParagraphs.find('.highlight').length < 1) {
            alert("Fraza \""+str+"\" nie znaleziona.");
            lastSearch=null
            return false;
        }
        lastSearchResults=jQuery('#subartykul').find('.highlight');
    }
    lastSearchResults.removeClass('highlightactive');
    try
    {
        jQuery(lastSearchResults[lastSearchPosition]).addClass('highlightactive');
    }
    catch(err)
    {
        //alert(err);
        //Discard errors in production environment
    }
    jQuery('#artykul').scrollTo(lastSearchResults[lastSearchPosition], 300, "");
    return false;
}

