



/*

                        if(children[i].hasChildNodes() == true) {
                                regInChildren(children[i]); }
        var what = new RegExp('( )(' + string + ')( )', 'gi');
        var into = '$1<span style="border: 1px solid #118A01; background: url(\'grafika/transparent.gif\')">$2</span>$3';
 * /* highlightSearchTerms('" . $_GET["podswietlenie"] . "'
 * asd
 * This is the function that actually highlights a text string by
 * adding HTML tags before and after all occurrences of the search
 * term. You can pass your own tags if you'd like, or if the
 * highlightStartTag or highlightEndTag parameters are omitted or
 * are empty strings then the default <font> tags will be used.
 */
function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag)
{
  // the highlightStartTag and highlightEndTag parameters are optional
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<span style=\"border: 1px solid #118A01; background: url('grafika/transparent.gif')\">";
    highlightEndTag = "</span>";
  }

  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();

  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
        }
      }
    }
  }

  return newText;
}


/*
 * This is sort of a wrapper function to the doHighlight function.
 * It takes the searchText that you pass, optionally splits it into
 * separate words, and transforms the text on the current web page.
 * Only the "searchText" parameter is required; all other parameters
 * are optional and can be omitted.
 */
function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
{
  // if the treatAsPhrase parameter is true, then we should search for
  // the entire phrase that was entered; otherwise, we will split the
  // search string so that each word is searched for and highlighted
  // individually
  if (treatAsPhrase) {
    searchArray = [searchText];
  } else {
    searchArray = searchText.split(" ");
  }

  if (!document.body || typeof(document.body.innerHTML) == "undefined") {
    if (warnOnFailure) {
      alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
    }
    return false;
  }

  var bodyText = document.body.innerHTML;
  for (var i = 0; i < searchArray.length; i++) {
    bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
  }

  document.body.innerHTML = bodyText;
  return true;
}


/*
 * This displays a dialog box that allows a user to enter their own
 * search terms to highlight on the page, and then passes the search
 * text or phrase to the highlightSearchTerms function. All parameters
 * are optional.
 */
function searchPrompt(defaultText, treatAsPhrase, textColor, bgColor)
{
  // This function prompts the user for any words that should
  // be highlighted on this web page
  if (!defaultText) {
    defaultText = "";
  }

  // we can optionally use our own highlight tag values
  if ((!textColor) || (!bgColor)) {
    highlightStartTag = "";
    highlightEndTag = "";
  } else {
    highlightStartTag = "<font style='color:" + textColor + "; background-color:" + bgColor + ";'>";
    highlightEndTag = "</font>";
  }

  if (treatAsPhrase) {
    promptText = "Please enter the phrase you'd like to search for:";
  } else {
    promptText = "Please enter the words you'd like to search for, separated by spaces:";
  }

  searchText = prompt(promptText, defaultText);

  if (!searchText)  {
    alert("No search terms were entered. Exiting function.");
    return false;
  }

  return highlightSearchTerms(searchText, treatAsPhrase, true, highlightStartTag, highlightEndTag);
}


/*
 * This function takes a referer/referrer string and parses it
 * to determine if it contains any search terms. If it does, the
 * search terms are passed to the highlightSearchTerms function
 * so they can be highlighted on the current page.
 */
function highlightGoogleSearchTerms(referrer)
{
  // This function has only been very lightly tested against
  // typical Google search URLs. If you wanted the Google search
  // terms to be automatically highlighted on a page, you could
  // call the function in the onload event of your <body> tag,
  // like this:
  //   <body onload='highlightGoogleSearchTerms(document.referrer);'>

  //var referrer = document.referrer;
  if (!referrer) {
    return false;
  }

  var queryPrefix = "q=";
  var startPos = referrer.toLowerCase().indexOf(queryPrefix);
  if ((startPos < 0) || (startPos + queryPrefix.length == referrer.length)) {
    return false;
  }

  var endPos = referrer.indexOf("&", startPos);
  if (endPos < 0) {
    endPos = referrer.length;
  }

  var queryString = referrer.substring(startPos + queryPrefix.length, endPos);
  // fix the space characters
  queryString = queryString.replace(/%20/gi, " ");
  queryString = queryString.replace(/\+/gi, " ");
  // remove the quotes (if you're really creative, you could search for the
  // terms within the quotes as phrases, and everything else as single terms)
  queryString = queryString.replace(/%22/gi, "");
  queryString = queryString.replace(/\"/gi, "");

  return highlightSearchTerms(queryString, false);
}


/*
 * This function is just an easy way to test the highlightGoogleSearchTerms
 * function.
 */
function testHighlightGoogleSearchTerms()
{
  var referrerString = "http://www.google.com/search?q=javascript%20highlight&start=0";
  referrerString = prompt("Test the following referrer string:", referrerString);
  return highlightGoogleSearchTerms(referrerString);
}

obrazki = new Array();
preload = new Array();

obrazki[0] = 'b_sklep_b';
obrazki[1] = 'b_poradnik_a';
obrazki[2] = 'b_ciekawostki_a';
obrazki[3] = 'b_onas_a';
obrazki[4] = 'b_forum_a';
obrazki[5] = 'roll-menu-show-over';
obrazki[6] = 'roll-menu-hide-over';
obrazki[7] = 'hover_small';
obrazki[8] = 'hover_big';
obrazki[9] = 'szukaj_b';
obrazki[10] = 'szukaj1_b';
obrazki[11] = 'glosuj_b';

for(i = 0; i < obrazki.length; i++) {
        preload[i] = new Image();
        preload[i].src = 'http://www.spinpol.com.pl/grafika/' + obrazki[i] + '.gif';
}

function wyswietlanie(element) {
        (document.getElementById(element).style.display != 'block')?(document.getElementById(element).style.display = 'block'):(document.getElementById(element).style.display = 'none');
}

function podpowiedz(akcja, wartosc) {
        if(akcja == 'pokaz') {
                if(document.getElementById('podpowiedz').style.display != 'block') {
                        styl('podpowiedz', 'display', 'block');
                        zawartosc('podpowiedz', wartosc);
                }
                styl('podpowiedz', 'left', (event.x + 20) + 'px');
                styl('podpowiedz', 'top', (event.y + document.documentElement.scrollTop + 20) + 'px');
        }
        if(akcja == 'ukryj') {
                styl('podpowiedz', 'display', 'none');
                zawartosc('podpowiedz', '');
        }
}

function okno(id, url, szerokosc, wysokosc) {
        var okno = window.open(url, 'okno_' + id, 'width=' + szerokosc + 'px, height=' + wysokosc + 'px, resizable=yes, scrollbars=yes, menubar=no');
}

function odswiez() {
        opener.location.reload();
}

function zawartosc(element, wartosc) {
        document.getElementById(element).innerHTML = wartosc;
}

function styl(element, wlasciwosc, wartosc) {
        document.getElementById(element).style[wlasciwosc] = wartosc;
}

function pobierzPozycje(element, wspolrzedna) {
        x = element.offsetLeft;
        y = element.offsetTop;

        while(element.offsetParent) {
                element = element.offsetParent;

                x += element.offsetLeft;
                y += element.offsetTop;
        }

        if(wspolrzedna == 'x') { return(x); }
        if(wspolrzedna == 'y') { return(y); }
}

function menu(wywolanie, numer, dlugosc) {
        styl('menu_gora', 'display', 'block');
        styl('menu_gora', 'left', pobierzPozycje(wywolanie, 'x') + 'px');
        styl('menu_gora', 'top', pobierzPozycje(wywolanie, 'y') + 29 + 'px');
        styl('menu_gora', 'width', dlugosc + 'px');

        zawartosc('menu_gora', document.getElementById('menu_gora_zrodlo-' + numer).innerHTML);
}

function mail() {
        var konto;
        var serwer;
        var mail;

        konto = 'spinpol';
        serwer = 'spinpol.com.pl';
        mail = konto + '@' + serwer;

        location.href = 'mailto:' + mail;
}

function menuBok(adres) {
        wyswietlanie('menu_bok');

        if(document.getElementById('siodma_1').style.width != '137px') {
                document.getElementById('siodma_1').style.width = '137px';
        } else {
                document.getElementById('siodma_1').style.width = '0px';
        }

        if((document.getElementById('menu_bok_sterowanie').src == 'http://localhost/~spinpol/grafika/roll-menu-show-over.gif') || (document.getElementById('menu_bok_sterowanie').src == 'http://localhost/~spinpol/grafika/roll-menu-show.gif')) {
                document.getElementById('menu_bok_sterowanie').src = 'grafika/roll-menu-hide.gif';
                document.getElementById('menu_bok_sterowanie').onmouseover = function() { document.getElementById('menu_bok_sterowanie').src = 'grafika/roll-menu-hide-over.gif'; }
                document.getElementById('menu_bok_sterowanie').onmouseout = function() { document.getElementById('menu_bok_sterowanie').src = 'grafika/roll-menu-hide.gif'; }
        } else {
                document.getElementById('menu_bok_sterowanie').src = 'grafika/roll-menu-show.gif';
                document.getElementById('menu_bok_sterowanie').onmouseover = function() { document.getElementById('menu_bok_sterowanie').src = 'grafika/roll-menu-show-over.gif'; }
                document.getElementById('menu_bok_sterowanie').onmouseout = function() { document.getElementById('menu_bok_sterowanie').src = 'grafika/roll-menu-show.gif'; }
        }
}

function wiadomosc(typ) {
        if(typ == 'polec') {
                var temat = 'Ochrona odgromowa';
                var tresc = 'Polecam Ci stronę http://www.spinpol.com.pl firmy, która specjalizuje się w ochronie przed piorunami budynków i sprzętu elektronicznego - zajrzyj tu w wolnej chwili.'; }
                var mail = '';

        if(typ == 'ekspert') {
                var temat = 'Pytanie do eksperta';
                var tresc = 'Pytanie:';
                var mail = 'spinpol' + '@' + 'spinpol.com.pl'; }

        if(typ == 'wycena') {
                var temat = 'Zamawiam wycenę';
                var tresc = '';
                var mail = 'spinpol' + '@' + 'spinpol.com.pl'; }

        location.href = 'mailto:' + mail + '?subject=' + temat + '&amp;body=' + tresc;
}
