/*
*       $Header: /home/cvsd/rittalfp/site/frontend/page/menu.js,v 1.2 2006/07/21 14:58:24 paulinad Exp $
*/
        
        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: funkcja zalatwia problem z wstawianiem flashy do IE
        //
        function drawFlash( path, param, quality, bgcolor, width, height, name )
        {
                document.write( '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+width+'" height="'+height+'" id="mainElem" align="middle">' );
                document.write( '<param name="allowScriptAccess" value="sameDomain" />' );
                document.write( '<param name="movie" value="'+path+'" />' );
                document.write( '<param name="quality" value="'+quality+'" />' );
                document.write( '<param name="bgcolor" value="'+bgcolor+'" />' );
                document.write( '<param name="wmode" value="transparent" >' );
                document.write( '<param name="FlashVars" value="'+param+'" >' );
                document.write( '<embed src="'+path+'?'+param+'" quality="'+quality+'" bgcolor="'+bgcolor+'" width="'+width+'" height="'+height+'" name="'+name+'" wmode="transparent" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' );
                document.write( '</object>' );
        }

        //global object that contains popup image data
        var popupImageObj;
        
        /**
         * Global array PARAM_ARRAY that contains all param data MUST be provided!
         * Global variable EMPTY_OPTION_VALUE that contains first element name in param select MUST be provided!
         */

        //global array that contains product data
        var products = new Array();

        
        
//------------------------------------------------------------------------------------------------------------

        //global object that contains popup image data
        var popupImageObj;
        
        /**
         * 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
        //
        function showImage( pathToImage )
        {
                popupImageObj = new Image();
                popupImageObj.src = pathToImage;
                
                showImagePopupWindow( popupImageObj );
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: funkcja sprawdza, czy grafika jest aktywna, czy nie
        //
        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
        //
        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: usowa nadmiarowe spacje ze stringa
        //
        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
        //
        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
        //
        function SendWords( a_host, a_id, text_to_alert1, text_to_alert2, a_type )
        {
                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: odsyla do wyszukiwania ze stronicowania
        //
        function sendPaging( a_adres )
        {
                document.forms.searchtop.action = a_adres;
                document.forms.searchtop.submit();
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: odsyla do wyszukiwania ze stronicowania
        //
        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
        //
        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 );
        }

//-------------------------------------------------------------------------------
//
//      ponizej kod dla menu rozwijanego
//
//-------------------------------------------------------------------------------

        var lastMenu = "";
        var lastOff = "";
        var currentMenu = "";
        var timeOutMenu = 0;
        
        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: funkcja pokazuje menu rozwijane
        //
        function showMenu( a_id, a_zind )
        {
                if( ( a_id == lastMenu ) || ( a_id == currentMenu ) )
                {
                        clearTimeout( timeOutMenu );
                }
                else
                {
                        currentMenu = a_id;
                        hideMenu( lastMenu, 0 );
                }
                /*minLeft = document.getElementById( "dropdowndiv" ).offsetLeft;
                maxLeft = minLeft + 720;
                uA = window.navigator.userAgent;
                if( ( uA.indexOf( "Gecko" ) == -1 ) && ( uA.indexOf( "Opera" ) == -1 ) )
                {
                        agent = 0;
                        minLeft += 15;
                        maxLeft += 15;
                }
                else
                {
                        agent = 1;
                }*/
                minLeft = 0;
                maxLeft = 720;
                sTab = a_id.split( "_" );
                num = sTab.length-1;
                i = 0;
                sId = "" + sTab[i] + "";
                firstMenu = document.getElementById( "" + sTab[0] + "" );
                przesuniecie = firstMenu.offsetLeft;
                if( ( przesuniecie + 292 ) > maxLeft )
                {
                        nextEl = 140;
                }
                else
                {
                        nextEl = 0;
                }
                back = 0;
                while( i <= num )
                {
                        k = 0;
                        subM = "" + sId + "_m" + k + "";
                        while( oMenu = document.getElementById( subM ) )
                        {
                                oMenu.style.display = "block";
                                k++;
                                subM = "" + sId + "_m" + k + "";
                        }
                        mMenu = document.getElementById( "" + sId + "" );
                        posLeft = mMenu.offsetLeft;
                        hMenu = document.getElementById( "" + sId + "h" );
                        hMenu.style.top = "" + ( mMenu.offsetTop + 10 ) + "px";
                        przesun = przesuniecie;
                        if( i == 1 )
                        {
                                nextElem = nextEl;
                        }
                        else
                        {
                                nextElem = 0;
                        }
                        if( ( przesuniecie + nextElem + 152 ) > maxLeft )
                        {
                                if( i == 0 )
                                {
                                        //back = maxLeft - przesuniecie;
                                        back = przesuniecie + 150 - maxLeft;
                                        przesuniecie -= back;
                                }
                                else
                                {
                                        przesuniecie -= 140;
                                }
                        }
                        else// if( i > 0 )
                        {
                                przesuniecie += 140;
                        }
                        if( i > 0 )
                        {
                                if( ( przesun + nextElem + 152 ) > maxLeft )
                                {
                                        hMenu.style.left = "" + ( posLeft - 140 ) + "px";
                                }
                                else
                                {
                                        hMenu.style.left = "" + ( posLeft + 140 ) + "px";
                                }
                        }
                        else
                        {
                                if( ( przesun + 152 ) > maxLeft )
                                {
                                        hMenu.style.left = "" + ( posLeft - back ) + "px";
                                }
                                else
                                {
                                        hMenu.style.left = "" + ( posLeft + 0 ) + "px";
                                }
                        }
                        i++;
                        if( i <= num )
                        {
                                sId += "_" + sTab[i] + "";
                        }
                }
                if( a_id != currentMenu )
                {
                        lastMenu = currentMenu;
                }
                colorMenu( a_id, "#c0d8e9" );
                currentMenu = a_id;
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: funkcja ukrywa menu rozwijane
        //
        function setHideMenu( a_id, a_zind )
        {
                if( a_id == currentMenu )
                {
                        clearTimeout( timeOutMenu );
                        timeOutMenu = setTimeout( "hideMenu( '" + a_id + "', 0 )", 300 );
                }
                lastOff = a_id;
                lastMenu = currentMenu;
                colorMenu( a_id, "#ffffff" );
                currentMenu = "";
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: funkcja ukrywa menu rozwijane
        //
        function hideMenu( a_id, a_num )
        {
                if( currentMenu == "" )
                {
                        sTabC = a_id.split( "_" );
                        cLength = sTabC.length-1;
                        num = 0;
                        sId = sTabC[num];
                        while( num <= cLength )
                        {
                                hideElements( sId );
                                num++;
                                if( num <= cLength )
                                {
                                        sId += "_" + sTabC[num];
                                }
                        }
                }
                else
                {
                        sTabC = a_id.split( "_" );
                        sTabL = currentMenu.split( "_" );
                        cLength = sTabC.length-1;
                        lLength = sTabL.length-1;
                        sId = "";
                        if( cLength >= lLength )
                        {
                                num = cLength;
                        }
                        else
                        {
                                num = lLength;
                        }
                        for( i = 0; i <= num; i++ )
                        {
                                if( cLength >= lLength )
                                {
                                        if( i == 0 )
                                        {
                                                sId = "" + sTabC[i];
                                        }
                                        else
                                        {
                                                sId += "_" + sTabC[i];
                                        }
                                        if( i <= lLength )
                                        {
                                                if( sTabL[i] != sTabC[i] )
                                                {
                                                        hideElements( sId );
                                                }
                                        }
                                        else
                                        {
                                                hideElements( sId );
                                        }
                                }
                                else
                                {
                                        if( i <= cLength )
                                        {
                                                if( i == 0 )
                                                {
                                                        sId = "" + sTabC[i];
                                                }
                                                else
                                                {
                                                        sId += "_" + sTabC[i];
                                                }
                                                if( sTabL[i] != sTabC[i] )
                                                {
                                                        hideElements( sId );
                                                }
                                        }
                                        else
                                        {
                                                i = num + 1;
                                        }
                                }
                        }
                }
                lastMenu = "";
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: funkcja ukrywa menu rozwijane
        //
        function hideElements( a_id )
        {
                k = 0;
                subM = "" + a_id + "_m" + k + "";
                while( oMenu = document.getElementById( subM ) )
                {
                        oMenu.style.display = "none";
                        k++;
                        subM = "" + a_id + "_m" + k + "";
                }
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: funkcja ukrywa menu rozwijane
        //
        function colorMenu( a_id, a_color )
        {
                sTab = a_id.split( "_" );
                num = sTab.length-1;
                i = 0;
                sId = "" + sTab[i] + "";
                while( i <= num )
                {
                        mMenu = document.getElementById( "" + sId + "" );
                        if( i > 0 )
                        {
                                mMenu.style.backgroundColor = a_color;
                        }
                        i++;
                        if( i <= num )
                        {
                                sId += "_" + sTab[i] + "";
                        }
                }
        }


//-------------------------------------------------------------------------------


        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: funkcja wysyla zamowienie z materialow drukowanych
        //
        function checkOrderForm( txt, txt2 )
        {
                if( ( document.getElementById( "pmimie" ).value != "" ) && ( document.getElementById( "pmnazwisko" ).value != "" ) && ( document.getElementById( "pmfirma" ).value != "" ) && ( document.getElementById( "pmulica" ).value != "" ) && ( document.getElementById( "pmcode" ).value != "" ) && ( document.getElementById( "pmmiasto" ).value != "" ) && ( document.getElementById( "pmphone" ).value != "" ) && ( document.getElementById( "pmemail" ).value != "" ) )
                {
                        i = 0;
                        ord = "";
                        ordid = "";
                        while( inp = document.getElementById( "pm" + i + "" ) )
                        {
                                if( inp.checked )
                                {
                                        ord += document.getElementById( "pmv" + i + "" ).value + ";";
                                        ordid += document.getElementById( "pmid" + i + "" ).value + ";";
                                }
                                i++;
                        }
                        if( ord != "" )
                        {
                                document.getElementById( "pmorder" ).value = ord;
                                document.getElementById( "pmorderid" ).value = ordid;
                                document.forms.printedForm.submit();
                        }
                        else
                        {
                                alert( txt2 );
                        }
                }
                else
                {
                        alert( txt );
                }
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: funkcja chowa lub pokazuje to co ukryte/odkryte
        //
        function clearOrderForm()
        {
                document.forms.printedForm.reset();
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: sbmituje zmiane w ofercie aukcyjnej
        //
        function auctionFormSubmit( a_txt, a_txt2 )
        {
                formatPrice( "acprice" );
                formatNumber( "acpayment" );
                formatNumber( "acdelivery" );
                acprice = document.getElementById( "acprice" ).value;
                acpayment = document.getElementById( "acpayment" ).value;
                acdelivery = document.getElementById( "acdelivery" ).value;
                if( ( acprice != "0.00" ) && ( acpayment != "0" ) && ( acdelivery != "0" ) )
                {
                        if( confirm( a_txt2 ) )
                        {
                                document.getElementById( "accheck" ).value = "1";
                                document.forms.auctionForm.submit();
                        }
                }
                else
                {
                        alert( a_txt );
                }
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: odsyla do wyszukiwania ze stronicowania
        //
        function formatPrice( id )
        {
                oPrice = document.getElementById( id );
                price = oPrice.value;
                pos = price.indexOf( "," )
                if( pos >= 0 )
                {
                        val = price.split( "," );
                        price = val[0] + "." + val[1];
                }
                pF = parseFloat( price );
                price = "" + pF + "";
                if( isNaN( pF ) )
                {
                        oPrice.value = "0.00";
                }
                else
                {
                        if( price.indexOf( "." ) >= 0 )
                        {
                                val = price.split( "." );
                                begin = val[0];
                                end = val[1];
                                if( end.length > 0 )
                                {
                                        pI = parseInt( end );
                                        if( isNaN( pI ) )
                                        {
                                                price = begin + ".00";
                                        }
                                        else
                                        {
                                                if( end.length > 2 )
                                                {
                                                        end = end.substr( 0, 2 );
                                                }
                                                else if( end.length < 2 )
                                                {
                                                        end += "0";
                                                }
                                        }
                                        price = begin + "." + end;
                                }
                                else
                                {
                                        price = begin + ".00";
                                }
                        }
                        else
                        {
                                price += ".00"
                        }
                        oPrice.value = price;
                }
        }

        /////////////////////////////////////////////////////////////////////////
        //
        //  Opis: odsyla do wyszukiwania ze stronicowania
        //
        function formatNumber( id )
        {
                oNum = document.getElementById( id );
                num = oNum.value;
                pI = parseInt( num );
                if( isNaN( pI ) )
                {
                        oNum.value = "0";
                }
        }


