/*
*       $Header: /home/cvsd/pbuch/site/page/menu.js,v 1.1 2006/07/06 12:30:24 karolc Exp $
*/

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: odsyla do wyszukiwania ze stronicowania
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function checkNumChars( id, num )
        {
                oTxt = document.getElementById( id );
                vTxt = oTxt.value;
                if( vTxt.length > num )
                {
                        vTxt = vTxt.substr( 0, num );
                        oTxt.value = vTxt;
                }
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: odsyla do wyszukiwania ze stronicowania
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function submitContactForm( a_txt )
        {
                oName = document.getElementById( "name" ).value;
                oSurName = document.getElementById( "surname" ).value;
                oEmail = document.getElementById( "conemail" ).value;
                oPhone = document.getElementById( "phone" ).value;
                oContent = document.getElementById( "content" ).value;
                if( ( oName != "" ) && ( oSurName != "" ) && ( oEmail != "" ) && ( oPhone != "" ) && ( oContent != "" ) )
                {
                        document.forms.contactForm.submit();
                }
                else
                {
                        alert( a_txt );
                }
        }

        //global object that contains popup image data
        var popupImageObj;
        
        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: funkcja otwiera nowe okno z zawartoscia do wydruku
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function checkContactForm( a_text )
        {
                if( ( document.getElementById( "imnaz" ).value != "" ) && ( document.getElementById( "email" ).value != "" ) )
                {
                        document.forms.kontaktform.submit();
                }
                else
                {
                        alert( a_text );
                }
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: funkcja otwiera nowe okno z zawartoscia do wydruku
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function docPrinter( a_url )
        {
                a_text = ""+document.getElementById( "pagecontent" ).value+"";
                winObj = window.open( a_url, "_blank", "channelmode=no, toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, titlebar=yes, fullscreen=yes" );
                winObj.document.open();
                winObj.document.write( a_text );
                winObj.document.close();
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: funkcja chowa lub pokazuje to co ukryte/odkryte
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function showHideAll( a_name, a_nr, a_ilosc )
        {
                for( i = 0; i < a_ilosc; i++ )
                {
                        if( i != a_nr )
                        {
                                docid = a_name+""+i+"";
                                document.getElementById( docid ).style.display = 'none';
                        }
                }
                docid = a_name+""+a_nr+"";
                obj = document.getElementById( docid );
                if( obj.style.display == 'none' )
                {
                        obj.style.display = 'block';
                }
                else
                {
                        obj.style.display = 'none';
                }
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: funkcja chowa lub pokazuje to co ukryte/odkryte
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function showHide( a_docid )
        {
                obj = document.getElementById( a_docid );
                if( obj.style.display == 'none' )
                {
                        obj.style.display = 'block';
                }
                else
                {
                        obj.style.display = 'none';
                }
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: zmienia rozmiar okna
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function resizeImageWindow( imageObj, winObj )
        {
                if( imageObj.complete == true )
                {
                        l_width = imageObj.width+30;
                        l_height = imageObj.height+90;
                        winObj.resizeTo( l_width, l_height );
                }
                else
                {
                        setTimeout( "resizeImageWindow( imageObj, winObj )", 10 );
                }
        }

        /**
         * Function is used to show image popup window.
         * Window is created after complete image loading
         *
         * @param popupImageObj global variable - image to show object
         */
        function showImagePopupWindow()
        {
                if( popupImageObj.complete == true )
                {
                        windowWidth = popupImageObj.width + 20;
                        windowHeight = popupImageObj.height + 30;
                        
                        verticalPosition = (document.body.clientWidth - windowWidth) / 2;
                        if(verticalPosition < 0) verticalPosition = 0;
                        
                        horizontalPosition = (document.body.clientHeight - windowHeight) / 2;
                        if(horizontalPosition < 0) horizontalPosition = 0;
                        
                        popupWindowObj = window.open(   popupImageObj.src, 
                                                        "image_window", 
                                                        "channelmode=no, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, titlebar=no, \
                                                        width="+ windowWidth +", height="+ windowHeight +", \
                                                        left="+ verticalPosition +", top="+ horizontalPosition +"" );
                        popupWindowObj.focus();
                }
                else
                {
                        setTimeout( "showImagePopupWindow()", 10 );
                }
        }
        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: pokazuje obrazek w nowym dopasowanym oknie
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function showImage( pathToImage )
        {
                popupImageObj = new Image();
                popupImageObj.src = pathToImage;
                
                showImagePopupWindow( popupImageObj );
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: zmienia lokacje na podany adres
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function go_to_location( a_location )
        {
                window.location = a_location;
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: przypisuje akcje do wykonania i robi submita
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-26 10:57  piotrj     stworzenie
        //
        function sendReferenceMail( a_text )
        {
                l_adresat = document.getElementById( "adresat" );
                l_nadawca = document.getElementById( "nadawca" );
                if( ( l_adresat.value == "" ) || ( l_nadawca.value == "" ) )
                {
                        alert( a_text );
                }
                else
                {
                        document.forms.polec_nas.submit();
                }
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: przypisuje akcje do wykonania i robi submita
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-26 10:57  piotrj     stworzenie
        //
        function SubscriptAction( a_akcja )
        {
                l_hidden_action = document.getElementById( "akcja" );
                l_hidden_action.value = a_akcja;
                document.forms.subskrypt_form.submit();
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: funkcja sprawdza, czy grafika jest aktywna, czy nie
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function checkIsOn( a_id )
        {
                oButton = document.getElementById( a_id );
                sSrc = oButton.src;
                iLen = sSrc.length;
                sRoz = sSrc.substr( iLen-6, 2 );
                if( sRoz == "_a" )
                {
                        return 1;
                }
                else
                {
                        return 0;
                }
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: funkcja podmienia obrazki bez tekstu przy wywolaniu
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function changeImage2( a_name, on_off ) 
        {
                old_img = document.getElementById( a_name );
                old_src = old_img.src;
                len = old_src.length;
                roz = old_src.substr( len-4, len );
                new_src = old_src;
                if( on_off == 1 )
                {
                        if( checkIsOn( a_name ) == 0 )
                        {
                                new_src = old_src.substr( 0, len-4 ) + "_a" + roz;
                        }
                }
                else
                {
                        if( checkIsOn( a_name ) == 1 )
                        {
                                new_src = old_src.substr( 0, len-6 ) + roz;
                        }
                }
                old_img.src = new_src
        } 

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: zmienia lokacje strony na podany adres
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function LocationFromMenu( adres )
        {
                window.location = adres;
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: usowa nadmiarowe spacje ze stringa
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function erase_space( str )
        {
                newstr = "";
                i = 0;
                strlen = str.length;
                znak = str.charAt(i);
                while( ( znak != "" ) && ( i < strlen ) )
                {
                        if( znak == " " )
                        {
                                i++;
                        }
                        else
                        {
                                while( ( znak != "" ) && ( znak != " " ) && ( i < strlen ) )
                                {
                                        newstr = newstr + znak;
                                        i++;
                                        znak = str.charAt(i);
                                }
                                newstr = newstr + "+";
                                i++;
                        }
                        znak = str.charAt(i);
                }
                len = newstr.length;
                znak = newstr.charAt( len-1 );
                if( znak == "+" )
                {
                        newstr = newstr.substr( 0, len-1 );
                }
                return newstr;
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: sprawdza dlugosc wszystkich podanych slow
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function checkWordsLength( a_str )
        {
                l_ok = 1;
                l_str = "";
                l_index = 0;
                l_len = a_str.length;
                if( l_len > 1 )
                {
                        l_index = a_str.indexOf( "+" );
                        if( l_index > 0 )
                        {
                                l_str = a_str.substr( 0, l_index );
                                if( l_str.length > 1 )
                                {
                                        r_str = a_str.substr( l_index+1, l_len );
                                        l_ok = checkWordsLength( r_str );
                                }
                                else
                                {
                                        if( l_str.length > 0 )
                                        {
                                                l_ok = 0;
                                        }
                                }
                        }
                }
                else
                {
                        l_ok = 0;
                }
                return l_ok;
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: odsyla do wyszukiwania, jesli wpisano slowa
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function SendWords( a_host, a_id, text_to_alert1, text_to_alert2, a_type )
        {
                //check_forbidden_chars( a_id, text_to_alert );
                word_container = document.getElementById( a_id );
                words = word_container.value;
                if( words != "" )
                {
                        words = words.toLocaleLowerCase();
                        re = /(\+)/g;
                        words = words.replace( re, "d7d18cfb3a0d8293e2f5d94ea30e04d2" );
                        words = erase_space( words );
                        is_ok = checkWordsLength( words );
                        if( is_ok == 1 )
                        {
                                words = encodeURI(words);
                                re = /(\%25+)/g;
                                words2 = words.replace( re, "e1e4faf650b9178c832fd6ce887e11d4" );
                                re = /(\/)/g;
                                words2 = words2.replace( re, "9fbbaa4cc515bc46e0c12e82a31df736" );
                                adres = a_host + "/wyszukiwanie/slowa/" + words2;
                                if( a_type == 1 )
                                {
                                        document.forms.searchmod.action = adres;
                                        document.forms.searchmod.submit();
                                }
                                else if( a_type == 2 )
                                {
                                        document.forms.searchtop.action = adres;
                                        document.forms.searchtop.submit();
                                }
                                else
                                {
                                        window.location = adres;
                                }
                        }
                        else
                        {
                                alert( text_to_alert1 );
                        }
                }
                else
                {
                        alert( text_to_alert2 );
                }
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: sprawdza, czy w stringu nie ma zabronionych znakow
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function check_forbidden_chars( element_id, send, text_to_alert )
        {
                send_text_el = document.getElementById( element_id );
                send_text = send_text_el.value;
                pos = send_text.indexOf( "%" );
                pos2 = send_text.indexOf( "_" );
                if( ( pos >= 0 ) || ( pos2 >= 0 ) )
                {
                        send_text_el.value = "";
                        alert( text_to_alert );
                }
                if( send == 1 )
                {
                        if( send_text_el.value != "" )
                        {
                                document.forms.product_search.submit();
                        }
                }
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: odsyla do wyszukiwania ze stronicowania
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function sendPaging( a_adres )
        {
                document.forms.searchtop.action = a_adres;
                document.forms.searchtop.submit();
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: odsyla do wyszukiwania ze stronicowania
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function sendModuleSearch( a_adres )
        {
                document.getElementById( "moduleSearch1" ).value = 0;
                document.forms.searchmod.action = a_adres;
                document.forms.searchmod.submit();
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: funkcja otwiera nowe okno z zawartoscia do wydruku
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function openMinimized( a_url )
        {
                winObj = window.open( a_url, "_blank", "channelmode=no, toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, scrollbars=no, resizable=yes, titlebar=yes, fullscreen=no, modal=no" );
                //winObj.moveTo( 0, 0 );
        }

