/*
*       $Header: /repos/lingua/site/page/menu.js,v 1.4 2005/05/04 13:06:58 piotrj Exp $
*/

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: funkcja otwiera nowe okno z zawartoscia do wydruku
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function checkTestForm( a_text )
        {
                ok = 1;
                if( document.getElementById( "imnaz" ).value == "" )
                {
                        document.getElementById( "imnazc" ).style.color = "#ff0000";
                        ok = 0;
                }
                else
                {
                        document.getElementById( "imnazc" ).style.color = "#41494f";
                }
                if( document.getElementById( "email" ).value == "" )
                {
                        document.getElementById( "emailc" ).style.color = "#ff0000";
                        ok = 0;
                }
                else
                {
                        document.getElementById( "emailc" ).style.color = "#41494f";
                }
                if( document.getElementById( "wiek" ).value == "" )
                {
                        document.getElementById( "wiekc" ).style.color = "#ff0000";
                        ok = 0;
                }
                else
                {
                        document.getElementById( "wiekc" ).style.color = "#41494f";
                }
                for( i = 1; i <= 60; i++ )
                {
                        checked = 0;
                        for( j = 0; j <= 3; j++ )
                        {
                                if( document.getElementById( "q"+i+"a"+j ).checked == true )
                                {
                                        checked = 1;
                                }
                        }
                        if( checked == 0 )
                        {
                                ok = 0;
                                document.getElementById( "q"+i+"c" ).style.color = "#ff0000";
                        }
                        else
                        {
                                document.getElementById( "q"+i+"c" ).style.color = "#41494f";
                        }
                }
                if( ok == 1 )
                {
                        document.forms.testform.submit();
                }
                else
                {
                        alert( a_text );
                }
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: funkcja zmienia odpowiednio ilosc dni w kalendarzu ze wzgledu na wybrany rok i miesiac
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function checkCallendar( a_day, a_month, a_year )
        {
                var newopt;
                year = document.getElementById( "rok" ).value;
                month = document.getElementById( "miesiac" ).value;
                selday = document.getElementById( "dzien" );
                day = selday.value;
                numdays = selday.length;
                if( a_year == year )
                {
                        if( month == a_month )
                        {
                                if( day < a_day )
                                {
                                        selday.value = a_day;
                                        day = a_day;
                                }
                        }
                        else if( month < a_month )
                        {
                                document.getElementById( "miesiac" ).value = a_month;
                                month = a_month;
                        }
                }
                if( month == 2 )
                {
                        przestepny = ( year % 4 );
                        if( przestepny == 0 )
                        {
                                maxday = 29;
                        }
                        else
                        {
                                maxday = 28;
                        }
                }
                else
                {
                        if( ( month == 1 ) || ( month == 3 ) || ( month == 5 ) || ( month == 7 ) || ( month == 8 ) || ( month == 10 ) || ( month == 12 ) )
                        {
                                maxday = 31;
                        }
                        else
                        {
                                maxday = 30;
                        }
                }
                if( day > maxday )
                {
                        daysel = selday.value = maxday;
                        
                }
                if( maxday <= numdays )
                {
                        num = maxday;
                        for( i = maxday+1; i <= numdays; i++ )
                        {
                                selday.remove( maxday );
                        }
                }
                else
                {
                        for( i = numdays+1; i <= maxday; i++ )
                        {
                                newopt = document.createElement( "option" );
                                newopt.value = i;
                                //to dla IE
                                newopt.innerText = ""+i+"";
                                //to dla mozilli
                                newopt.text = ""+i+"";
                                selday.appendChild( newopt );
                        }
                }
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: funkcja otwiera nowe okno z zawartoscia do wydruku
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function checkTourForm( a_text )
        {
                if( ( document.getElementById( "imnaz" ).value != "" ) && ( document.getElementById( "email" ).value != "" ) && ( document.getElementById( "okres" ).value != "" ) && ( document.getElementById( "jezyk" ).value != "" ) && ( document.getElementById( "kraj" ).value != "" ) && ( document.getElementById( "rodzaj" ).value != "" ) && ( document.getElementById( "kwatera" ).value != "" ) )
                {
                        document.forms.tourform.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 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 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 );
                }
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: pokazuje obrazek w nowym dopasowanym oknie
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function showImage( a_sciezka )
        {
                imageObj = new Image();
                imageObj.src = a_sciezka;
                x = Math.round((document.body.clientWidth - 20)/10);
                y = Math.round((document.body.clientHeight - 100)/10);
                winObj = window.open( a_sciezka, "image_window", "channelmode=no, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, titlebar=no, width=20, height=20, left="+x+", top="+y+"" );
                resizeImageWindow( imageObj, winObj );
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  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 podmienia obrazki bez tekstu przy wywolaniu
        //
        //  Historia zmian:
        //  data              Kto        Opis
        //  ---------------------------------------------------------------------
        //  2004-08-20 13:19  piotrj     stworzenie
        //
        function changeImage2( a_name, on_off ) 
        {
                //alert( a_name );
                old_img = document.getElementById( a_name );
                old_src = old_img.src;
                len = old_src.length;
                roz = old_src.substr( len-4, len );
                if( on_off == 1 )
                {
                        new_src = old_src.substr( 0, len-4 ) + "_a" + roz;
                }
                else
                {
                        if( old_src.charAt(len-5) == "a" )
                        {
                                new_src = old_src.substr( 0, len-6 ) + roz;
                        }
                        else
                        {
                                new_src = old_src;
                        }
                }
                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_alert )
        {
                //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" );
                                //alert( words+" --> "+words2 );
                                adres = a_host + "/wyszukiwanie/slowa/" + words2;
                                window.location = adres;
                        }
                        else
                        {
                                alert( text_to_alert );
                        }
                }
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  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();
                        }
                }
        }


