	  // the cse class encapsulates a left and right search control
      // both controls are driven by a shared search form
      function cse(search_type) {
		 if(search_type == undefined){
			search_type = "RSNA"; 
		 }

        var sFormDiv = document.getElementById("searchForm");
        var leftScDiv = document.getElementById("leftSearchControl_" + search_type);

        // create a left, right search control
        // create a custom search form
        this.leftControl = 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 small result sets
        this.leftControl.setResultSetSize(GSearch.LARGE_RESULTSET);
	   this.leftControl.setSearchCompleteCallback(this, cse.prototype.updateTitleLinks);

        var searcher;
        var options;

        // configure left control
        // Site Restrict to CSE ID for reviews
        searcher = new GwebSearch();
        options = new GsearcherOptions();
	   
	   
		if(search_type == 'Yottalook'){
			searcher.setSiteRestriction("002399708225919668872:zs40jgruyqg");	
			searcher.setUserDefinedLabel("Yottalook Web Search Results");			
		}else if(search_type == 'Google'){
			searcher.setUserDefinedLabel("Google Search Results");
		}else{
			searcher.setSiteRestriction("010590255508194535560:sda_mrayv-u");	
//			searcher.setSiteRestriction("010590255508194535560:sda_mrayv-u", null,"/yottalook/more_results.cfm?cx=010590255508194535560%3Asda_mrayv-u&q=__QUERY__&sa=Search&client=google-coop-np&cof=FORID%3A9%3BCX%3A&hl=__HL__");
        		searcher.setUserDefinedLabel("RSNA Search Results");			

		}
        options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
	   
        this.leftControl.addSearcher(searcher, options);		
		
		var customer = document.getElementById('ys_customer').value;
		if(customer != "" && customer != undefined){
			this.leftControl.setOnKeepCallback( this, cse.prototype.onKeep, "Add to myBookmarks" );
		}

        // draw the left and right controls
        // the right control is drawn in tabbed mode
        var drawOptions = new GdrawOptions();
//        drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);
		drawOptions.setDrawMode(GSearchControl.DRAW_MODE_LINEAR);

        this.leftControl.draw(leftScDiv, drawOptions);

		var q = document.getElementById('ys_q').value;

		// execute a starter search
        	this.searchForm.execute(q);

      }

      // 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);
        }
        return false;
      }

      // when the form fires a clear, call the left and right control
      cse.prototype.onClear = function(form) {
        this.leftControl.clearAllResults();
        form.input.value = "";
        return false;
      }

      function OnLoad(search_type) {
        new cse(search_type);
      }
//      GSearch.setOnLoadCallback(OnLoad);

	  
/***********************************************************************************************************/	  

function openSearchWindow(title,url){
/*	var treenode = createSearchNode(title,url);	
	handleFileClick('',treenode,true,true);*/
	
	
	var h = getHeight()-50;
	var w = getWidth()-50;

	if(url.search('lakeside2007') >= 0){
		window.open(url,"lakeside2007","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=1024,height=768,left=0,top=0");	
	}else{
		
		if(url.search('rsnajnls') >= 0 || url.search('www.ajronline.org') >= 0 || url.search('www.ajnr.org') >= 0 || url.search('bjr.birjournals.org') >= 0 || url.search('jnm.snmjournals.org') >= 0){
			var URL = 'http://' + myRSNAhost + myRSNApath + 'myfiles/viewURL.cfm?link='+escape(url);
		}else{
			var URL = url;
		}
		
		launchExtWindow(URL,title,h,w,'tree-URL',true);	
	}	
}

/***********************************************************************************************************/	  


cse.prototype.onKeep = function(result) {
	var customer = document.getElementById('ys_customer').value;
	var the_url = result.url;
	var the_descr = result.titleNoFormatting;
	bookmark_popup('URL','mySearch',the_descr,the_url);
//	the_link.href = "/customcf/myrsna/plugins/my_bookmarks/bookmark_alert.cfm?customer=" + customer + "&BM_URL=" + the_url + "&link_source=RSNA%20Search&bm_descr=" + the_descr; 
//	the_link.onclick();
}


cse.prototype.updateTitleLinks = function(searchControl,searcher) {

	var isTitle;
	if(!Ext.isIE){
//		var links = searchControl.za.getElementsByClassName('gs-title');
		var links = Ext.getCmp('dpstabs').getActiveTab().getEl().dom.getElementsByClassName('gs-title');
		for(var i=0; i<links.length; i++){
			isTitle = (links[i].tagName == 'A' ? true : false);
			
			if(isTitle){
				links[i].target = '';
				var title = (Ext.isIE ? links[i].innerText : links[i].textContent);
				links[i].href = 'Javascript:openSearchWindow("'+title+'","'+links[i].href+'");';
			}
		}
	}else{
		var links = Ext.getCmp('dpstabs').getActiveTab().getEl().dom.getElementsByTagName('A');
		var isMoreResults;
		for(var i=0; i<links.length; i++){
			isTitle = (links[i].className == 'gs-title' ? true : false);
			isMoreResults = (links[i].className == 'gsc-trailing-more-results' ? true : false);
			
			if(isTitle){
				links[i].target = '';
				var title = (Ext.isIE ? links[i].innerText : links[i].textContent);
				links[i].href = 'Javascript:openSearchWindow("'+title+'","'+links[i].href+'");';
			}
			
			if(isMoreResults){
				links[i].innerHTML = '';
			}
		}
	}


}
    /**
     * searchComplete - called when a search completed. Note the searcher
     * that is completing is passes as an arg because thats what we arranged
     * when we called setSearchCompleteCallback
     */
    cse.prototype.searchComplete = function(searchControl,searcher) {
//debugger;
      // always clear old from the page
      this.clearAllResults();

      // if the searcher has results then process them
      if (searcher.results && searcher.results.length > 0) {

        // print the result titles
        var div = createDiv("Result Titles", "header");
        this.results.appendChild(div);
        for (var i=0; i<searcher.results.length; i++) {
          var result = searcher.results[i];
          var titleLine = result.title;

          // add in lat,lng for local results
          if (result.GsearchResultClass == GlocalSearch.RESULT_CLASS) {
            titleLine += " (" + result.lat + ", " + result.lng + ")";
          }
          if (result.html) {
            titleLine += " ** html is present **";
          }
		titleLine = 'test';
          div = createDiv(titleLine);
          this.results.appendChild(div);
        }

        // now manually generate the html that we disabled
        // initially and display it
        var div = createDiv("Result Html", "header");
        this.results.appendChild(div);
        for (var i=0; i<searcher.results.length; i++) {
          var result = searcher.results[i];
          searcher.createResultHtml(result);
          if (result.html) {
            div = result.html.cloneNode(true);
          } else {
            div = createDiv("** failure to create html **");
          }
          this.results.appendChild(div);
        }

        // now, see if we have a cursor, and if so, create the 
        // cursor control
        if (searcher.cursor) {
          var cursorNode = createDiv(null, "gsc-cursor");
          for (var i=0; i<searcher.cursor.pages.length; i++) {
            var className = "gsc-cursor-page";
            if (i == searcher.cursor.currentPageIndex) {
              className = className + " gsc-cursor-current-page";
            }
            var pageNode = createDiv(searcher.cursor.pages[i].label, className);
            pageNode.onclick = methodClosure(this, this.gotoPage, 
                                             [searcher, i]); 
            cursorNode.appendChild(pageNode);
          }
          this.cursor.appendChild(cursorNode);
          var more = createLink(searcher.cursor.moreResultsUrl,
                                GSearch.strings["more-results"] + "&nbsp;&raquo;",
                                GSearch.LINK_TARGET_SELF,
                                "gsc-trailing-more-results");
          this.cursor.appendChild(more);
        }
      }
    }
    
    /**
     * clearResults - clear out any old search results
     */
    cse.prototype.clearResults = function() {
      removeChildren(this.results);
      removeChildren(this.cursor);
    }



/**
 * Various Static DOM Wrappers.
*/
function method_closure(object, method, opt_argArray) {
  return function() {
    return method.apply(object, opt_argArray);
  }
}

function removeChildren(parent) {
  while (parent.firstChild) {
    parent.removeChild(parent.firstChild);
  }
}

function cssSetClass(el, className) {
  el.className = className;
}

function createDiv(opt_text, opt_className) {
  var el = document.createElement("div");
  if (opt_text) {
    el.innerHTML = opt_text;
  }
  if (opt_className) { el.className = opt_className; }
  return el;
}

function prependNode(el, node) {
  if ( el.childNodes.length ) {
    el.insertBefore(node, el.childNodes[0]);
  } else {
    el.appendChild(node);
  }
}

function createForm(opt_className) {
  var el = document.createElement("form");
  if (opt_className) { el.className = opt_className; }
  return el;
}

function createTextInput(opt_className) {
  var el = document.createElement("input");
  el.setAttribute("autoComplete", "off"); // fixes firefox auto-complete bug
  el.type = "text";
  if (opt_className) { el.className = opt_className; }
  return el;
}

function createTable(opt_className) {

  var el = document.createElement("table");
  if (opt_className) { el.className = opt_className; }
  return el;
}

function createTableRow(table) {
  var tr = table.insertRow(-1);
  return tr;
}

function createTableCell(tr, opt_className) {
  var td = tr.insertCell(-1);
  if (opt_className) { td.className = opt_className; }
  return td;
}
	  