//Modified by A. Riverin, on 2008-05-28
var ongletHelp = 'tle_tab_se';
var textHelp = '1';


var TabsManager = {
	
  current: 'web',
  tabMap: {"lcn" : {"tabid" : "lcn_tab", "ctnid" : "lcn_container", "show_sponsor" : true},
          "quebec" : {"tabid" : "quebec_tab", "ctnid" : "quebec_container", "show_sponsor" : true},
          "montreal" : {"tabid" : "montreal_tab", "ctnid" : "montreal_container", "show_sponsor" : true},          
          "site" : {"tabid" : "site_tab", "ctnid" : "site_container", "show_sponsor" : true},
          "tle" : {"tabid" : "tle_tab", "ctnid" : "tle_container", "show_sponsor" : true},
          "web" : {"tabid" : "web_tab", "ctnid" : "web_container", "show_sponsor" : true},
          "news" : {"tabid" : "news_tab", "ctnid" : "news_container", "show_sponsor" : true},
          "img" : {"tabid" : "images_tab", "ctnid" : "img_container", "show_sponsor" : false},
          "ent" : {"tabid" : "enterprises_tab", "ctnid" : "ent_container", "show_sponsor" : false},
          "shopping" : {"tabid" : "shopping_tab", "ctnid" : "shopping_container", "show_sponsor" : false}
          },
  lang : 'fr',
  changed : false,
	
	setCurrentTab : function(atab)
	{
	  if ( !this.changed && this.tabMap[atab] )
	    this.current = atab;
	},
	
  changeTab : function(atab)
	{
    
		if ( !this.tabMap[atab] ) return;
	 
	  if ( document.getElementById('searchbar_en') )
	    this.lang = 'en';
	 
	  var tabobj = this.tabMap[atab];
	  var curtabobj = this.tabMap[this.current];
	 
	 
	  var tab = document.getElementById(tabobj.tabid);
	  var tab_ctn = document.getElementById(tabobj.ctnid);
	  var current_tab = document.getElementById(curtabobj.tabid);
	  var current_tab_ctn = document.getElementById(curtabobj.ctnid);
	 
	  if ( current_tab_ctn && current_tab_ctn.style.display == 'none' )
	    return;
	 
    current_tab_ctn.style.display = 'none';
    current_tab.className = '';
		tab_ctn.style.display = '';
		tab.className = 'current';
		
		var current_query = this.findCtnQueryField(current_tab_ctn);
		var query = this.findCtnQueryField(tab_ctn);
		
		//set query courant et focus
		if ( query && current_query ) {
		  var val = current_query.value;
    
    // Symbole ISO volontairement ajoutÃ© pour les sites qui le sont. NE PAS ENLEVER
    if ( this.current == 'ent' && (val == 'Nom, prÃ©nom' || val == 'Nom, prénom' || val == 'Last, First' || val == 'Entreprise' || val == 'Business') ) 
    {
      val = '';
    }
                  
      if ( atab == 'ent'){
        
				if( val != ''){
          query.value = val;
					query.style.color = "black";
          var city = this.findCtnLocationField(tab_ctn);         
        }
      } else {
        query.value = val;
        query.focus();
      }
		}
	 
	  // web sponsor
	  var web_el = document.getElementById('web_sponsor');
	  if ( web_el ) {
 	    if ( tabobj.show_sponsor )
	      web_el.style.display = '';
	    else
	      web_el.style.display = 'none';
	  }
		
	  this.current = atab;
    this.changed = true;
		
		if ( !document.getElementById('searchbar_en') && document.getElementById('tle_trad')) {
		
			TabsSelected = atab;
			
			document.getElementById('tle_trad').style.display = "none";
			document.getElementById('web_trad').style.display = "none";
			document.getElementById('act_trad').style.display = "none";
			document.getElementById('img_trad').style.display = "none";
			document.getElementById('411_trad').style.display = "none";
			document.getElementById('shopping_trad').style.display = "none";
			
			switch(TabsSelected) {
				case"img":
					ongletHelp = 'images_tab_se';
					textHelp = '4';
					document.getElementById('img_trad').style.display = "block";
					break;
									
				case"tle":
					ongletHelp = 'tle_tab_se';
					textHelp = '1';
					document.getElementById('tle_trad').style.display = "block";
					break;
									
				case"shopping":
					ongletHelp = 'shopping_tab_se';
					textHelp = '6';
					document.getElementById('shopping_trad').style.display = "block";
					break;
				
				case"act":
					ongletHelp = 'news_tab_se';
					textHelp = '3';
					document.getElementById('act_trad').style.display = "block";
					
					break;
				
				case"ent":
					ongletHelp = 'entreprises_tab_se';
					textHelp = '5';
					document.getElementById('411_trad').style.display = "block";
					break;
				
				default:
					ongletHelp = 'web_tab_se';
					textHelp = '2';
					document.getElementById('web_trad').style.display = "block";
			}
		}		
	},
	
	findCtnQueryField: function(container)
	{
	  var inputs = container.getElementsByTagName('input');
	  for (var i=0; i < inputs.length; i++)
		  if (inputs[i].type == 'text' && (inputs[i].name == 'q' || inputs[i].name == 'what' || inputs[i].name == 'term' || inputs[i].name == 'name'))
		 	  return inputs[i];
			
		return null;
	},
        
  findCtnLocationField: function(container)
	{
	  var inputs = container.getElementsByTagName('input');
	  for (var i=0; i < inputs.length; i++)
		  if (inputs[i].type == 'text' && (inputs[i].name == 'location'))
		 	  return inputs[i];
			
		return null;
	}
}
