
function SearchBar_Suggest_Off(inObj)
{
$('QueryIndicatorId2').show();
inObj.deactivate();
$('QueryId').setStyle('width:230px;');
}

function SearchBar_Suggest_On(inObj)
{
$('QueryIndicatorId2').hide();
inObj.activate();
$('QueryId').setStyle('width:242px;');
}

function SearchBar_Suggest()
{
return new Ajax.Autocompleter('QueryId', 'QueryChoiceId', 'http://be.socompetent.com/ajax/SearchBarSuggest-VLLcatJJZZ65.html', {
  paramName: 'value',
  minChars: 1, 
  indicator: 'QueryIndicatorId',
  callback: SearchBar_Suggest_CallBack
});
}

function SearchBar_Suggest_CallBack(element,entry)
{
  NbSelectedCat = CatTreeObj.getNbItemSelected();
  SelectedTab   = SearchBar_GetSelectedTab();
  NbSelectedZones = ZoneTreeObj.getNbItemSelected();
  Near = SearchBar_GetNearValue();
  Show = 0;
  if ((0 == NbSelectedCat) && (((1 == SelectedTab) && (''==Near)) || (0 == NbSelectedZones)))
    {
      Show=1;
    }
  return entry+'&show='+Show;
}

function SearchBar_setImgPath()
{
window.dhx_globalImgPath='http://be.socompetent.com/lib/dhtmlx/sources/imgs/';
}

function SearchBar_CreateCatTree(inList,inListNb,inNow)
{
         var CatComboObj=new dhtmlXCombo('combo_cat','alfa3','270', 'default');
         CatComboObj.readonly(true);
         
         var CatTreeObj=new dhtmlXTreeObject('tree_cat','270','307',0);   
         CatTreeObj.enableCheckBoxes(1);
         CatTreeObj.enableThreeStateCheckboxes(true);
         CatTreeObj.SelectionChange (' catégorie sélectionnée',' catégories sélectionnées');
         CatTreeObj.MaximumSelection(50,' nombre maximum de catégories');
         CatTreeObj.TooMuchSelectionTxt(' trop de catégories sélectionnées');
         CatTreeObj.setImagePath('http://be.socompetent.com/lib/dhtmlx/sources/imgs/csh_bluebooks/'); 
         CatTreeObj.setPictoPath('http://be.socompetent.com/bitmaps/pictos/small/');
if (1 == inNow)
{
CatTreeObj.XmlUrl('http://be.socompetent.com/ajax/getCatCached.php?rec=1&amp;id=0&amp;lang=fr',0,'');
}
else
{
CatTreeObj.XmlUrl('http://be.socompetent.com/ajax/getCatCached.php?rec=0&amp;id=0&amp;lang=fr',1,'http://be.socompetent.com/ajax/getCatCached.php?rec=1&amp;lang=fr');
}
CatTreeObj.DefaultSelection('Sélectionnez jusqu\'à 50 catégories')
         CatTreeObj.attachToCombo(CatComboObj);
         CatTreeObj.checkList(inList);
         CatTreeObj.nbItemsSelected(inListNb);
        return CatTreeObj;
}

function SearchBar_CreateRayCombo(inRa)
{
        var RayComboObj=dhtmlXComboFromSelect('combo_ray','63px');
        RayComboObj.readonly(true);
        RayComboObj.DefaultSelection('Rayon');
        RayComboObj.selectOption(RayComboObj.getOptionId(inRa),null,true);

        return RayComboObj;
}

function SearchBar_CreateZoneTree(inZl,inZNb,inNow)
{
         var ZoneComboObj=new dhtmlXCombo('combo_zone','alfa3',228, 'default');
         ZoneComboObj.readonly(true);
         
         var ZoneTreeObj=new dhtmlXTreeObject('tree_zone','228','197',0);
         ZoneTreeObj.setImagePath('http://be.socompetent.com/lib/dhtmlx/sources/imgs/csh_bluebooks/');
         ZoneTreeObj.setPictoPath('./');
         ZoneTreeObj.enableCheckBoxes(1);
         ZoneTreeObj.enableThreeStateCheckboxes(true);
         ZoneTreeObj.SelectionChange (' département sélectioné',' départements sélectionnés');
         ZoneTreeObj.MaximumSelection(20,' nombre maximum de départements');
         ZoneTreeObj.DefaultSelection('Sélectionnez jusqu\'à 20 départements');
         ZoneTreeObj.TooMuchSelectionTxt('Trop de départements sélectionnes');
         ZoneTreeObj.enableTreeImages(0);ZoneTreeObj.XmlUrl('http://be.socompetent.com/country_be/docs/fr/zone_be_fr.xml',0,'');ZoneTreeObj.attachToCombo(ZoneComboObj);
         ZoneTreeObj.checkList(inZl);
         ZoneTreeObj.nbItemsSelected(inZNb);
         return ZoneTreeObj;
}

function SearchBar_GetSelectedTab()
{
  for (var i = 1; i<3; i++)
      {
          if ('block' == $('tab'+i).style.display)
              {
                  return i;
              }
      }
  return 1;
}

function SearchBar_GetQueryValue()
{
  Value = $('QueryId').value; 
  if ( Value == "Saisir quelques mots clés")
      {
          Value = '';
      }
return Value;
}

function SearchBar_GetNearValue()
{
  Value = $('NearId').value;
  if ( Value == "code postal, ville ...")
      {
          Value = '';
      }
  return Value;
}

function SearchBar_Submit(event,inCatList,inCatNb,inZoneList,inZoneNb)
{
  if ('#' != event)
    {
      if(!event && window.event) event = window.event;
      if(event.keyCode != 13) return ;
    }

  $('CatListId').value = CatTreeObj.getAllChecked();
  $('CatNbId').value = CatTreeObj.getNbItemSelected();
  $('ZoneListId').value = ZoneTreeObj.getAllChecked();
  $('ZoneNbId').value = ZoneTreeObj.getNbItemSelected();

  if ((!CatTreeObj.isLoaded()) && (0 == $('CatNbId').value))
    {
      $('CatListId').value = inCatList;
      $('CatNbId').value = inCatNb;
    }
      
  if ((!ZoneTreeObj.isLoaded()) && (0 == $('ZoneNbId').value))
    {
      $('ZoneListId').value = inZoneList;
      $('ZoneNbId').value = inZoneNb;
    }

  $('QueryId').value = SearchBar_GetQueryValue();
  $('NearId').value = SearchBar_GetNearValue();
  $('TabId').value = SearchBar_GetSelectedTab();

  $('SearchFormId').submit();
}

function SearchBar_selectDefaultTab(inId)
{
var el = $(inId);
if (null == el) el = $('t3');
el.className += " active";
}

function SearchBar_initTabs()
{
    var sets = document.getElementsByTagName("div");

    for (var i = 0; i < sets.length; i++)
        {
            if (sets[i].className.indexOf("tabset") != -1)
                {
                    var tabs = [];
                    var links = sets[i].getElementsByTagName("a");
                    for (var j = 0; j < links.length; j++)
                        {
                            if (links[j].className.indexOf("tab") != -1)
                                {
                                    tabs.push(links[j]);
                                    links[j].tabs = tabs;

                                    if (links[j].className.indexOf("active") != -1)
                                        {
                                            var c = document.getElementById(links[j].href.substr(links[j].href.indexOf("#") + 1));
                                            if (c)
                                                c.style.display = "block";
                                        }
                                    
                                    links[j].onclick = function ()
                                    {
                                        var c = document.getElementById(this.href.substr(this.href.indexOf("#") + 1));
                                        if (c)
                                            {
                                                //reset all tabs
                                                for (var i = 0; i < this.tabs.length; i++)
                                                    {
                                                        document.getElementById(this.tabs[i].href.substr(this.tabs[i].href.indexOf("#") + 1)).style.display = "none";
                                                        this.tabs[i].className = this.tabs[i].className.replace("active", "");
                                                    }
                                                this.className += " active";
                                                c.style.display = "block";
                                                return false;
                                            }
                                    }
                                }
                        }
                }
        }
}

if (window.addEventListener)
window.addEventListener("load", SearchBar_initTabs, false);
else if (window.attachEvent)
window.attachEvent("onload", SearchBar_initTabs);
