// Switch le code image du formulaire d'inscription
function switch_code() {
	var obj=document.getElementById('code_image');
	obj.src='/code.jpg?' + (Math.floor((99999999999)*Math.random()+1));
}

// Variables globales
var isMozilla = (navigator.userAgent.toLowerCase().indexOf('gecko')!=-1) ? true : false;

// Insert un texte dans un champ de formulaire donné a l'emplacement du curseur
function tag_selected_text(id_obj, tag_open, tag_close) {
	// Variables
	var obj;
	var selected_text;
	var before_selection;
	var after_selection;
	var add_len=0;
	
	// Objet
	obj=document.getElementById(id_obj);

	if(isMozilla) {
		
		var sel_start=obj.selectionStart;
		var sel_end=obj.selectionEnd;

		before_selection=obj.value.substring(0, sel_start); 
		selected_text=obj.value.substring(sel_start, sel_end); 
		after_selection=obj.value.substring(sel_end, obj.value.length);
		obj.value=before_selection + tag_open + selected_text + tag_close + after_selection;

	} else {
		obj.focus();

		var range = document.selection.createRange();
		var insText = range.text;
		range.text = tag_open + insText + tag_close;

		range = document.selection.createRange();
		if (insText.length == 0) {
		  range.move('character', -tag_close.length);
		} else {
		  range.moveStart('character', tag_open.length + insText.length + tag_close.length);
		}
		range.select();
	}
}

function showFV(poster, description, raison_refus, pct_pour, pct_contre, nb_pour, nb_contre, date_publication) {
	var html;
	var layer = document.getElementById('fenetre_volante');
	
	if((x + layer.clientWidth + 30) >= document.documentElement.clientWidth)
	layer.style.left = (posx - layer.clientWidth) + 'px';
	else
	layer.style.left = (posx + 20) + 'px';
	
	if((y + layer.clientHeight + 30) >= document.documentElement.clientHeight)
	layer.style.top = (posy - layer.clientHeight) + 'px';
	else
	layer.style.top = posy+20 + 'px';

	layer.style.display='';

	html = '<span style="color: #000000;"><b><u>Date</u> : </b>' + date_publication + '</span>';
	html = html + '<br /><span style="color: #000000;"><b><u>Posteur</u> :</b> <span class="text-user-logged">' + poster + '</span></span>';
	html = html + '<br /><span style="color: #000000;"><b><u>Description</u> :</b> ' + description + '</span>';
	
	if(raison_refus != '') html = html + '<br /><span style="color: #FF0000;"><b><u>Raison du refus</u> :</b> ' + raison_refus + '</span>';
	else {
		html = html + '<br /><img style="margin-bottom: -4px;" src="/images/icons/vote-pour.gif" border="0" /><span style="color: #00AA00;"> ' + pct_pour + '% ( ' +  nb_pour + ' votes )</span>';
		html = html + '<br /><img style="margin-bottom: -4px;" src="/images/icons/vote-contre.gif" border="0" /><span style="color: #FF0000;"> ' + pct_contre + '% ( ' +  nb_contre + ' votes )</span>';
	}
	write_html('fenetre_volante', html);
}

function hideFV() {
	elem=document.getElementById('fenetre_volante');
	elem.style.display='none';
}
	
function sourisxy(evt) {	
  var scrolltop=0; var scrollleft=0;
  if (document.layers) {
    x=evt.x; y=evt.y;
  }
  if (document.all) {
    x=event.clientX; y=event.clientY;
  } else {
    if (document.getElementById) {
      x=evt.clientX; y=evt.clientY;
    }
  }

  if (document.documentElement && document.documentElement.scrollTop)
  {
    scrolltop = document.documentElement.scrollTop;
    scrollleft = document.documentElement.scrollLeft;
  }
  else if (document.body)
  {
    scrolltop = document.body.scrollTop;
    scrollleft = document.body.scrollLeft;
  }

  posx = scrollleft + x;
  posy = scrolltop + y;
	
	
}


if(navigator.appName.substring(0,3) == "Net")
document.captureEvents(Event.mousemove);
document.onmousemove = sourisxy;



/*****************************************************************************/
/*    U N   P E U   D ' A J A X 											 */
/*****************************************************************************/

function file(fichier) {
	// FIREFOX
	if(window.XMLHttpRequest) {
		xhr_object = new XMLHttpRequest();
	}
	
	// IE
	else if(window.ActiveXObject) {
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else return(false);
	
	xhr_object.open("GET", fichier, false);
	xhr_object.send(null);
	if(xhr_object.readyState == 4) return(xhr_object.responseText);
	else return(false);
} 

// Ecrit du html dans une balise donnée
function write_html(id_obj, txt) {

	var obj=document.getElementById(id_obj);	
	if(isMozilla) {		
		if(obj.firstChild) {			
			longueurCible = obj.firstChild.length;
		}
		else {
			longueurCible=0;
		}
		
		//obj.firstChild.replaceData(0, longueurCible, "");		
		//obj.innerHTML = txt;
		obj.innerHTML = txt;
	} else {
		obj.innerHTML = txt;
	}
}