function tabselect(tab, ulId) {
  var tablist = $(ulId).getElementsByTagName('a');
  var nodes = $A(tablist);

  nodes.each(function(node){
	if (node.id == tab.id) {
		document.getElementById('contenu_'+tab.id).style.display = "block";
		tab.id=tab.id+'_hover';
	} else{
		node.id = node.id.replace(/_.*/, '')
		document.getElementById('contenu_'+node.id).style.display = "none";
	}
  });
}

function tabshow(tab)
{
	document.getElementById(tab).style.display = "block";
}
function tabhide(tab)
{
	document.getElementById(tab).style.display = "none";
}

function showIt(n)
{
	for (i=1; i<27; i++) {
		if(i== n){
			document.getElementById("tab"+n).style.display = "block";
		}else{
			document.getElementById("tab"+i).style.display = "none";
		}
	}
}

function openSqueezeBox(url) {
	//alert(url);
	SqueezeBox.open(url);
}

function reload(){
	cat='0';
	for(var i = 0; i < document.formsearch.categorie.length; i++) {
		if(document.formsearch.categorie[i].checked) {
			cat = document.formsearch.categorie[i].value;
		}
	}
	zone = document.formsearch.region.options[document.formsearch.region.selectedIndex].value;
	
	vil = document.formsearch.ville.options[document.formsearch.ville.selectedIndex].value;
	
	if (vil!='0') {
		url = "resultats.php?zone="+zone+"&categorie="+cat+"&ville="+vil;
	}else{
		url = "deplacements.php?zone="+zone+"&categorie="+cat;
	}
	window.location.href = url;	
}


function affichepopup(){
	document.getElementById("popup01").innerHTML = '<img src="img/onglet_comer.jpg" width="200" height="32" border="0"/>';
	document.getElementById("popup02").innerHTML = '<img src="img/onglet_comer.jpg" width="200" height="32" border="0"/>';
	document.getElementById("popup03").innerHTML = '<img src="img/onglet_comer.jpg" width="200" height="32" border="0"/>';
	document.getElementById("popupalpha").innerHTML = '<img src="img/lienlistealpha.gif" alt="Voir la liste par ordre alphab&eacute;tique" width="243" height="15" border="0">';
	//alert('hello');
}
function affichepopup2(){

	document.getElementById("popupalpha").innerHTML = '<img src="img/lienlistealpha.gif" alt="Voir la liste par ordre alphab&eacute;tique" width="243" height="15" border="0">';
	//alert('hello');
}

function getVar(name)  
{  
	get_string = document.location.search;  
	return_value = '';  

	do { //cette boucle va capturer toutes les instances des variables GET.  
		name_index = get_string.indexOf(name + '=');  
		if(name_index != -1)  
		{  
			get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);  

			end_of_value = get_string.indexOf('&');  
			if(end_of_value != -1)  
				value = get_string.substr(0, end_of_value);  
				else  
					value = get_string;                  
					if(return_value == '' || value == '')  
						return_value += value;  
					else  
						return_value += ', ' + value;  
					}  
				} while(name_index != -1)  
				
				space = return_value.indexOf('+');  
				while(space != -1)  
				{  
					return_value = return_value.substr(0, space) + ' ' +  
					return_value.substr(space + 1, return_value.length);
					
					space = return_value.indexOf('+');  
	}  
	return(return_value);  
}  

function openmenu(){
	nummenu = getVar('menu');
	if(nummenu){
		tabselect($(nummenu), 'offres6_menu');
	}else{
		tabselect($('menu1'), 'offres6_menu');
	}
}

function init(){
	SqueezeBox.assign($$('a[rel=boxed]'), {
		size: {x: 778, y: 700},
		options: {automaticResize: false},
		ajaxOptions: {
			method: 'get' // we use GET for requesting plain HTML (you can skip it, it is the default value)
		}
		
	});
}

function ie7Ready(){
//prevent duplicate call of init function
  if (Browser.Engine.trident) init();
}

function affichebulle(hide){
	if (hide==1){$('bull').style.display = 'block';}
	else{$('bull').style.display = 'none';}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

/* AGENDA */
function updatetab(mois, annee){
	var req = new Request.HTML({url:'include/ajax_calendrier.php', 
		method : 'get',
		data: 'annee='+annee+'&mois='+mois,
		onSuccess: function(html) {
			$('result').set('text', '');
			$('result').adopt(html);
		},
		onFailure: function() {
			$('result').set('text', 'The request failed.');
		}
	});
	$('infobulle').set('opacity', '0');
	req.send();

}


function showEvent(date){
   var req2 = new Request.HTML({url:'include/ajax_event.php', 
		method : 'get',
		data: 'date='+date,
		onSuccess: function(html) {
			$('infobulle').set('text', '');
			$('infobulle').adopt(html);
		},
		onFailure: function() {
			$('infobulle').set('text', 'The request failed.');
		}
	});
	req2.send();

	$('joursdumois').addEvent('mousemove',function(event){
		$('infobulle').setStyle('top', event.page.y+21);
		$('infobulle').setStyle('left', event.page.x-36);
	});
	$('infobulle').set('opacity', '1');
}

function hideEvent(date){
	$('infobulle').set('text', '');
	$('infobulle').set('opacity', '0');
}

function listEvent(date){
   var req2 = new Request.HTML({url:'include/ajax_listevent.php', 
		method : 'get',
		data: 'date='+date,
		onSuccess: function(html) {
			$('listevt').set('text', '');
			$('listevt').adopt(html);
		},
		onFailure: function() {
			$('listevt').set('text', 'The request failed.');
		}
	});
	req2.send();
}

function IE6isdead(){
	var IE6 = false
	var strChUserAgent = navigator.userAgent;
	var intSplitStart = strChUserAgent.indexOf("(",0);
	var intSplitEnd = strChUserAgent.indexOf(")",0);
	var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);
	
	if(strChMid.indexOf("MSIE 6") != -1) {
		IE6 = true;
		$('error').set('html', '<a href=\'http://www.microsoft.com/france/windows/internet-explorer\' target=\'_blank\'>Certaines fonctionnalités ne sont pas disponibles pour Internet Explorer 6 ou inférieur, veuillez mettre à jour votre navigateur<a>');
	}
}


function slideEvent(cat, menu, pane, current, length){
	if(pane==''){pane='pane01';}
	$('principal_flash').setStyle('display', 'none');
	$('principal').setStyle('display', 'block');
   var req2 = new Request.HTML({url:'include/ajax_slidevent.php', 
		method : 'get',
		data: 'cat='+cat,
		onSuccess: function(html) {
			$('principal').set('text', '');
			$('principal').adopt(html);
			myTabs = new SlidingTabs('buttons','content', pane, 'previous', 'next', current, length);
			
			var tablist = $('evenements_menu').getElementsByTagName('a');
			var nodes = $A(tablist);
			
			nodes.each(function(node){
				if (node.id == menu.id) {
					menu.id=menu.id+'_hover';
				} else{
					node.id = node.id.replace(/_.*/, '');
				}
			});

		},
		onFailure: function() {
			$('principal').set('text', 'The request failed.');
		}
	});
	req2.send();	
}

function TMP_slideEvent(cat, menu, pane, current, length){
	if(pane==''){pane='pane01';}
	$('principal_flash').setStyle('display', 'none');
	$('principal').setStyle('display', 'block');
   var req2 = new Request.HTML({url:'include/TMP_ajax_slidevent.php', 
		method : 'get',
		data: 'cat='+cat,
		onSuccess: function(html) {
			$('principal').set('text', '');
			$('principal').adopt(html);
			myTabs = new SlidingTabs('buttons','content', pane, 'previous', 'next', current, length);
			
			var tablist = $('evenements_menu').getElementsByTagName('a');
			var nodes = $A(tablist);
			
			nodes.each(function(node){
				if (node.id == menu.id) {
					menu.id=menu.id+'_hover';
				} else{
					node.id = node.id.replace(/_.*/, '');
				}
			});

		},
		onFailure: function() {
			$('principal').set('text', 'The request failed.');
		}
	});
	req2.send();	
}

function ecrire_cookie(nom, valeur, expires) {
  document.cookie=nom+"="+escape(valeur)+
  ((expires==null) ? "" : ("; expires="+expires.toGMTString()));
}

function arguments_cookie(offset){
  var endstr=document.cookie.indexOf (";", offset);
  if (endstr==-1) endstr=document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr)); 
}

function lire_cookie(nom) {
  var deb,fin
      deb = document.cookie.indexOf(nom + "=")
      if (deb >= 0) {
         deb += nom.length + 1
         fin = document.cookie.indexOf(";",deb)
         if (fin < 0) fin = document.cookie.length
         return unescape(document.cookie.substring(deb,fin))
         }
      return ""
}



