/* EXECUTION AJAX */
function _rob_exec_url(url,params){
  var xhr_object = null;
  if (window.XMLHttpRequest) xhr_object = new XMLHttpRequest();
  else if(window.ActiveXObject) xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
  else {
    alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
  return;
  }
  xhr_object.open("POST", url, true);
  xhr_object.onreadystatechange = function() {
    if(xhr_object.readyState == 4) {
	eval(xhr_object.responseText);
  }
  }
  xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xhr_object.send(params);
  return xhr_object.readyState
}
/* AFFICHER/MASQUER UN CALQUE */
function _rob_showhidelayer(layer,etat) {
  if (document.getElementById(layer)!=null) {
    document.getElementById(layer).style.visibility=etat;
  }
}
/* OUVERTURE DE POPUP DHTML */
function _rob_showpopup(shellname,popname,url) {
  if (document.getElementById(popname)==null || document.getElementById(shellname)==null) {
	  alert ("layer non d\351fini");
		return;
	}
	_rob_inipopupposition(shellname,popname);
  document.getElementById(popname).style.visibility = "visible";
}
/* FERMETURE DE POPUP DHTML */
function _rob_hidepopup(popname) {
  document.getElementById(popname).style.visibility = "hidden";
}
/* INITIALISATION DE LA POSITION DE POPUP DHTML */
function _rob_inipopupposition(shellname,popname){
	theLeft = Math.floor((parseInt(document.getElementById(shellname).style.width) - parseInt (document.getElementById(popname).style.width))/2);
	theTop = Math.floor((parseInt(document.getElementById(shellname).style.height) - parseInt (document.getElementById(popname).style.height))/2);
	document.getElementById(popname).style.left = theLeft + "px";
	document.getElementById(popname).style.top = theTop + "px";
	document.getElementById(popname).style.pixelLeft = theLeft ;
	document.getElementById(popname).style.pixelTop = theTop ;
}
/* CHARGEMENT D'UNE URL AJAX */
function _rob_get_url (calque,url,params){
  if (document.getElementById(calque)==null) {
	  alert ("Layer '"+calque+"' non valide");
		return;
	}
	var xhr_object = null;
  if (window.XMLHttpRequest) xhr_object = new XMLHttpRequest();
  else if(window.ActiveXObject) xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
  xhr_object.open("POST", url, true);
  xhr_object.onreadystatechange = function() {
    if(xhr_object.readyState == 4) {
      if (xhr_object.status == 200) document.getElementById(calque).innerHTML = xhr_object.responseText;
			else {
			  alert ("Erreur XMLHttpRequest :" + xhr_object.status);
				return;
			}
		}
  }
  xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xhr_object.send(params);
}
/* ALERTES */
function _rob_errorfield(calque) {
  if (document.getElementById("libelle_"+calque)==null || document.getElementById(calque)==null) {
	  alert ("Layer non valide");
		return;
	}
	document.getElementById("libelle_"+calque).className = "libelle_error" ;
	document.getElementById(calque).className = "field_error" ;
}

function _rob_unerrorfield(calque) {
  if (document.getElementById("libelle_"+calque)==null || document.getElementById(calque)==null) {
	  alert ("Layer non valide");
		return;
	}
	document.getElementById("libelle_"+calque).className = "libelle" ;
	document.getElementById(calque).className = "field" ;
}


function _rob_alerte(libelle,champ) {
  document.getElementById("messageerreur").style.visibility = "visible";
  calque = "formsaisie_"+champ;
  document.getElementById(calque).className = "libelle_error";
  pointeur = eval('document.myform.'+champ)
  if (pointeur) pointeur.focus()
}

function _rob_unalerte(champ) {
  calque = "formsaisie_"+champ;
  document.getElementById(calque).className = "libelle";
}

function displayinfo(reinit) {
  if (reinit==true) {
	infoindex = 0;
  }
  //document.getElementById("infobarre").style.opacity = opaindex;
  document.getElementById("infobarre").innerHTML = info[infoindex];
  infoindex ++;
  if (infoindex>=info.length) infoindex=0;
  alertinfo = setTimeout("displayinfo(false)",2500);
}

function showhideinfo() {
  if (openindex=="open") {
    clearTimeout(alertinfo);
    document.getElementById("infobarre").style.display = "none";
    document.getElementById("boutoninfo").style.backgroundImage = "url(/media/image/boutonouvrir.jpg)";
    document.getElementById("boutoninfo").style.top = "1px";
    document.getElementById("bandeauinfos").style.height = "18px";
    openindex = "closed"; 
  } else {
    document.getElementById("infobarre").style.display = "block";
    document.getElementById("boutoninfo").style.backgroundImage = "url(/media/image/boutonfermer.jpg)";
    document.getElementById("boutoninfo").style.top = "6px";
    document.getElementById("bandeauinfos").style.height = "28px";
    openindex = "open"; 
	displayinfo(true);
  }
}

function openpopup(file) {
  _rob_get_url("mypopup",file,"");
  document.getElementById("mypopup").className = "popupopened";
}

function closepopup() {
  document.getElementById("laphoto").style.visibility = "hidden";
  document.getElementById("mypopup").className = "popupclosed";
}

function autrephoto(id) {
	closepopup();
  openpopup('popupphoto.php?id='+id)
}


function gosearch () {
  if (document.myform.recherche.value !="") {
	  if (document.myform.recherche.value.lenght<3) return; 
		document.myform.action = "recherche.php"
		document.myform.submit();
	}
}

function inscription() {
  self.location = "inscription.php"
}

function checkemail(etat) {
	email = document.myform.email.value;
  if (email=="e-mail" && etat=="focus") document.myform.email.value="";
  else if (email=="" && etat=="blur") document.myform.email.value="e-mail";
}

function checkpassword(etat) {
	mot_de_passe = document.myform.mot_de_passe.value;
  if (mot_de_passe=="pass" && etat=="focus") document.myform.mot_de_passe.value="";
  else if (mot_de_passe=="" && etat=="blur") document.myform.mot_de_passe.value="pass";
}

function login() {
	email = document.myform.email.value;
	mot_de_passe = document.myform.mot_de_passe.value;
  if (email=="" || email=="e-mail") return;
  if (mot_de_passe=="") return;
	params="email="+email+"&mot_de_passe="+mot_de_passe;
	_rob_get_url ("zoneinscriptionlogin","include.identification.php",params);
	if (document.getElementById("zonerubrique")!=null) {
	  //setTimeout('_rob_get_url ("zonerubrique","zonerubrique.php")',500);	
	}
}

function logout() {
	_rob_get_url ("zoneinscriptionlogin","include.identification.php","logout=true");
	//setTimeout('_rob_get_url ("zonerubrique","zonerubrique.php")',500);	
}

function relogin() {
	_rob_get_url ("zoneinscriptionlogin","include.identification.php","");
}

function commente(id_article) {
	commentaire = document.myform.commentaire.value;
  if (commentaire=="") return;
	_rob_get_url ("zonecommentaire","zonecommentaire.php","commentaire="+commentaire+"&id_article="+id_article);
}

function gonewsletter() {
	newsletter = document.myform.newsletter.value;
  if (newsletter=="") return;
	_rob_get_url ("zonenewsletter","include.newsletter.php","newsletter="+newsletter);
}


/*
* Rich HTML Ticker- by JavaScript Kit (http://www.javascriptkit.com)
* Freeware. Created Sept 13th, 08'
* This credit must stay intact for use
*/

var richhtmlticker={
loadingtext: '<em>Fetching Ticker Contents. Please wait...</em>', //Loading text if content is being fetched via Ajax

getajaxcontent:function($, config){
	config.$ticker.html(this.loadingtext)
	$.ajax({
		url: config.msgsource,
		error:function(ajaxrequest){
			config.$ticker.html('Error fetching content.<br />Server Response: '+ajaxrequest.responseText)
		},
		success:function(content){
			config.$ticker.html(content)
			richhtmlticker.setupticker(config)
		}
	})
},

rotate:function(config){
	if (config.$ticker.get(0)._hoverstate=="over"){
		setTimeout(function(){richhtmlticker.rotate(config)}, config.rotatespeed)
	}
	else{
		config.$messages.eq(config.currentmsg).fadeOut(config.animateduration, function(){
			config.currentmsg=(config.currentmsg<config.$messages.length-1)? config.currentmsg+1 : 0
			config.$messages.eq(config.currentmsg).fadeIn(config.animateduration, function(){
				setTimeout(function(){richhtmlticker.rotate(config)}, config.rotatespeed)
			})
		})
	}
},

getCookie:function(Name){ 
	var re=new RegExp(Name+"=[^;]+", "i") //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
	return null
},

setCookie:function(name, value){
	document.cookie = name+"="+value
},

setupticker:function(config){
	config.$messages=config.$ticker.find('div.'+config.msgclass).hide()
	config.currentmsg=Math.min(parseInt(richhtmlticker.getCookie(config.id) || 0), config.$messages.length-1)
	config.$messages.hide().eq(config.currentmsg).fadeIn(config.animateduration)
	setTimeout(function(){richhtmlticker.rotate(config)}, config.rotatespeed)
	$(window).bind('unload', function(){richhtmlticker.cleanup(config)})
},

define:function(config){
  jQuery(document).ready(function($){
		config.$ticker=$('#'+config.id)
		if (config.$ticker.length==0)
			return
		config.$ticker.css({overflow:'hidden'}).hover(
			function(){this._hoverstate="over"},
			function(){this._hoverstate="out"}
		)
		if (config.msgsource=="inline"){
			richhtmlticker.setupticker(config)
		}		
		else{
			richhtmlticker.getajaxcontent($,config)
		}
	})
},

cleanup:function(config){
	this.setCookie(config.id, config.currentmsg)
}

} //end richhtmlticker object

richhtmlticker.define({
	id: "myhtmlticker", //main ticker DIV id
	msgclass: "messagediv", //CSS class of DIVs containing each ticker message
	msgsource: "inline", //Where to look for the messages: "inline", or "path_to_file_on_your_server"
	rotatespeed: 3000, //pause in milliseconds between rotation
	animateduration: 1000 //duration of fade animation in milliseconds 
})

function closeticker () {
  _rob_exec_url("closeticker.php","");
	document.getElementById("bandeau").style.visibility = "hidden";
}