﻿        google.load('search', '1', {language : g_search_lang_S});

        var searchControl = null;
        
        google.setOnLoadCallback(
            function() {
            
                // Create a search control
                searchControl = new GSearchControl();

                // create a searcher options object
                var optionsD = new GsearcherOptions();
                // set up for open expansion mode (works only in linear draw mode!)
                optionsD.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
                // no hits text
                optionsD.setNoResultsString(g_search_nohits_S);

                // site restricted web search with custom label
                // trenutno je prvi StudioD, ker ima kaj zadetkov
                var siteSearchD = new GwebSearch();
                siteSearchD.setUserDefinedLabel("www.sava-osiguranje.rs");
                siteSearchD.setSiteRestriction("www.sava-osiguranje.rs");
                siteSearchD.setQueryAddition("site:www.sava-osiguranje.rs/");
                siteSearchD.setUserDefinedClassSuffix("siteSearch");
                searchControl.setResultSetSize(GSearch.LARGE_RESULTSET);
                searchControl.addSearcher(siteSearchD, optionsD);
                // set target, *after* adding searcher to search control
                siteSearchD.setLinkTarget(GSearch.LINK_TARGET_BLANK);  // LINK_TARGET_SELF

                var drawOptions = new GdrawOptions();
                // search form root
                drawOptions.setSearchFormRoot(document.getElementById("searchForm"));
                // tell the searcher to draw itself in tabbed mode
                // drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);

                // search control callbacks
                //searchControl.setSearchStartingCallback(this, gsearchOnSearchStarting);
                searchControl.setSearchCompleteCallback(this, gsearchOnSearchComplete);

                // Tell the searcher to draw itself
                searchControl.draw(document.getElementById("searchOne"), drawOptions);

                // Execute an inital search
                if ( g_search_query_S.length > 1 ) 
                    gsearchExecute(g_search_query_S);

            }, true
        );
        
        function gsearchExecute(q_S) {
            if ( searchControl ) {
                if ( document.frmSearch && document.frmSearch.q && document.frmSearch.q.value ) {
                    document.frmSearch.q.value = q_S;
                }
                searchControl.execute(q_S);
            }
            // supress submit
            return false;
        }

        function gsearchOnSearchComplete(sc, searcher) {
            if ( document.frmSearch && document.frmSearch.elements[1] ) 
                document.frmSearch.elements[1].style.visibility = "visible";
            if ( document.frmSearch2 && document.frmSearch2.elements[1] ) 
                document.frmSearch2.elements[1].style.visibility = "visible";
            //for (p in searcher)
            //	document.getElementById("dbg").innerHTML += '<br />' + p
            return;
            
            if ( searcher.results && searcher.results.length > 0) {
                for (var i = 0; i < searcher.results.length; i++) {
                    var result = searcher.results[i];
                        document.getElementById("dbg").appendChild(result.html);
                }
            }
        }

        function gsearchOnSearchStarting(sc, searcher, query) {
        }


        function gsearchKeepHandler(result) {
            // clone the result html node
            var node = result.html.cloneNode(true);

            // attach it
            var savedResults = document.getElementById("searchStore");
            savedResults.appendChild(node);
        }


