﻿      google.load("search", "1");
			var first = true;

      // Call this function when the page has been loaded
      function cse() {
        var sFormDiv = document.getElementById("searchForm");
        var leftScDiv = document.getElementById("leftSearchControl");
        var rightScDiv = document.getElementById("rightSearchControl");

        // create a left, right search control
        // create a custom search form
        this.leftControl = new GSearchControl();
        this.rightControl = new GSearchControl();
        this.searchForm = new GSearchForm(true, sFormDiv);

        // bind clear and submit functions
        this.searchForm.setOnSubmitCallback(this, cse.prototype.onSubmit);
        this.searchForm.setOnClearCallback(this, cse.prototype.onClear);

        // set up for large result sets
        this.leftControl.setResultSetSize(GSearch.LARGE_RESULTSET);
        this.rightControl.setResultSetSize(GSearch.LARGE_RESULTSET);
				
				// set up to open link in same window
				this.leftControl.setLinkTarget(GSearch.LINK_TARGET_PARENT);
				this.rightControl.setLinkTarget(GSearch.LINK_TARGET_PARENT);

        var searcher;
        var options;

        // configure left control
        // Site Restrict to CSE ID for Q8ba7th Kuwait Site Search
        searcher = new GwebSearch();
        options = new GsearcherOptions();
        searcher.setSiteRestriction("012963694513957275259:9ikfw7jtgmy", null,	"http://q8ba7th.com/search.php?cof=FORID%3A10&q=__QUERY__&sa=Search&cx=012963694513957275259%3A9ikfw7jtgmy#1345&hl=__HL__");
        searcher.setUserDefinedLabel("Kuwait");
        options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
        this.leftControl.addSearcher(searcher, options);

        // configure left control
        // Site Restrict to CSE ID for Q8ba7th Phone Search
        searcher = new GwebSearch();
        options = new GsearcherOptions();
        searcher.setSiteRestriction("012963694513957275259:t8okaqkerva", null, "http://q8ba7th.com/search.php?cof=FORID%3A10&q=__QUERY__&sa=Search&cx=012963694513957275259%3At8okaqkerva#573&hl=__HL__");
        searcher.setUserDefinedLabel("Phones");
        this.leftControl.addSearcher(searcher, options);

        // configure right control for
        // -- cse for comparisons
        // -- cse for community
        // -- cse for shopping
        // -- blog search
        // -- video search
        searcher = new GwebSearch();
        this.rightControl.addSearcher(searcher);

        searcher = new GnewsSearch();
        this.rightControl.addSearcher(searcher);

        searcher = new GblogSearch();
        this.rightControl.addSearcher(searcher);

        searcher = new GimageSearch();
				searcher.setRestriction(GSearch.RESTRICT_SAFESEARCH,
																GSearch.SAFESEARCH_STRICT);
        this.rightControl.addSearcher(searcher);				
				
        // draw the left and right controls
        // the right control is drawn in tabbed mode
        var drawOptions = new GdrawOptions();
        drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);

        this.leftControl.draw(leftScDiv, drawOptions);
        this.rightControl.draw(rightScDiv, drawOptions);

        // bind in a videobar
        var videoBarDiv = document.getElementById("videoBar");
        var videoPlayerDiv = document.getElementById("videoPlayer")
        var vboptions = {
          largeResultSet : false,
          horizontal : true
        }

        this.videoBar = new GSvideoBar(videoBarDiv, videoPlayerDiv, vboptions);

				// Read GET Parameter 'Q' from URL
				var q = gup('q');
				
        // execute a starter search
				if(q)
					this.searchForm.execute(q);
				else
					this.searchForm.execute("kuwait");
      }
			
      google.setOnLoadCallback(OnLoad);


      // when the form fires a submit, grab its
      // value and call the left and right control
      cse.prototype.onSubmit = function(form) {
        var q = form.input.value;
        if (q && q!= "") {
					this.leftControl.execute(q);
          this.rightControl.execute(q);
          this.videoBar.execute(q);
					
					// Refresh ad boxes
					if(first){
						first = false;
					}
					else {
						var midBanner = document.getElementById("midBanner");
						midBanner.innerHTML = midBanner.innerHTML;
						var leftBanner = document.getElementById("leftBanner");
						leftBanner.innerHTML = leftBanner.innerHTML;
					}
					
        }
				
        return false;
      }

      // when the form fires a clear, call the left and right control
      cse.prototype.onClear = function(form) {
        this.leftControl.clearAllResults();
        this.rightControl.clearAllResults();
        this.videoBar.clearAllResults();
        form.input.value = "";
        return false;
      }
			
      function OnLoad() {
        new cse();
      }
			

