/**
  *  File: /javascipt/search.js
  *  Description: Search Functions
  *  Author: Chris.Geheran@barclaysglobal.com
**/

function searchLink(url) {
  var paramConcat = "&showURL="+showURL+"&showDesc="+showDesc;
  self.location.href = url+paramConcat;
}

function flipElementsByClassName(classname,display) {
  var node = document.getElementsByTagName("body")[0];
  var a = [];
  var re = new RegExp('\\b' + classname + '\\b');
  var els = node.getElementsByTagName("*");

  for(var i=0,j=els.length; i<j; i++)
    if(re.test(els[i].className)) els[i].style.display=display;
}

function flipClass(classname,type) {
  var linkDiv = document.getElementById(classname);
  var linkNode = linkDiv.getElementsByTagName('a');
  var display,newDisp,oldText,newtext = new String();

  switch(type) {
    case "_off" : display = "none"; newdisp = "_on"; oldtext = "Hide"; newtext = "Show";
                  break;
    default     : display = "block"; newdisp = "_off"; oldtext = "Show"; newtext = "Hide";
                  break;
  }

  switch(classname) {
    case "results_url"          : showURL = (type=='_on') ? true : false;
                                  break;
    case "results_description"  : showDesc = (type=='_on') ? true : false;
                                  break;
  }

  flipElementsByClassName(classname,display);
  linkNode[0].href = linkNode[0].href.replace(type,newdisp);
  linkNode[0].firstChild.nodeValue = linkNode[0].firstChild.nodeValue.replace(oldtext,newtext);
}

  // jj tweak added for Ultraseek
  // 2. create hover effect for the Links that require Login (and user not logged in)
  function createCategoryHideShowSliders() {
    // this loops through all divs that have class 'lock_box'
    $('.cat_container').each(function(i){
      // for this lock_box find the children we know should be there -  icon_lock  and balloon_basic
      var curr_controller = $(this).find('.subcat_show_controller');
      var curr_subcats = $(this).find('.subcat_container');

      // toggle to show/hide the subcategory  as well as PLUS or MINUS image user clicked on
      $(curr_controller).toggle(
        function () {   // 1st click hides subcats (which are displayed by default) User clicked Minus icon
          $(curr_subcats).slideUp("fast");
          $(curr_controller).removeClass('showhide_minus_icon')
          $(curr_controller).addClass('showhide_plus_icon')
        },
        function () {   //  2nd click shows subcats. User clicked Plus icon
          $(curr_subcats).slideDown("fast");
          $(curr_controller).removeClass('showhide_plus_icon')
          $(curr_controller).addClass('showhide_minus_icon')
        }
      );
  });

}

var tipsWindow;
showSearchTips = function() {
  tipsWindow = window.open("/search/search_tips.htm", "tipsWindow", "height=600px,width=800px,statusbar=no,titlebar=no,scrollbars=yes,location=no,menubar=no,directories=no,toolbar=no,status=no");
  tipsWindow.focus();
}
