function ctime()
{
	var compteur=document.getElementById('compteur');
	s=duree;
	m=0;h=0;j=0;
	if(s<0)
	{
		compteur.innerHTML="I'm in France !!!"
	}
	else
	{
	// Passe � l'unit� sup�rieure
		if(s>59)
		{
			m=Math.floor(s/60);
			s=s-m*60
		}
		if(m>59)
		{
			h=Math.floor(m/60);
			m=m-h*60
		}
		if(h>23)
		{
			j=Math.floor(h/24);
			h=h-j*24
		}
	// [0] Met un Z�r0 quand moins de 10 (peut �tre enlev�)
		if(s<10)
		{
			s="0"+s
		}
		if(m<10)
		{
			m="0"+m
		}
		if(h<10)
		{
			h="0"+h
		}
	// [/0]
		if(j>0) {
			compteur.innerHTML="<b>"+j+" jours "+h+"h"+m+"m"+s+"s</b>"
		}
		else {
			compteur.innerHTML="<b>"+h+"h"+m+"m"+s+"s</b>"
		}
	}
	duree-=1;
	window.setTimeout("ctime();",999);
}

function remplace(data, search, replace)
{
   var temp = data;
   var longueur = search.length;
   while (temp.indexOf(search) > -1)
   {
      pos = temp.indexOf(search);
      temp = (temp.substring(0, pos) + replace + temp.substring((pos + longueur), temp.length));
   }
   return temp;
}

function storeCaret(id_textarea)
{ 
   champ = document.getElementById(id_textarea);
   if (champ.createTextRange)
      champ.curseur = document.selection.createRange().duplicate();
}
	
//ins�re une balise dans le textarea
function balise(balise_debut, balise_fin, id_textarea, local)
{
   if (typeof local == "undefined") 
      var champ = document.getElementById(id_textarea);
   else
      var champ = window.opener.document.getElementById(id_textarea);
   
   var scroll = champ.scrollTop;
   balise_debut = remplace(balise_debut, '<br />', "\n");

   if(balise_fin == '')
      balise_debut = ' ' + balise_debut + ' ';

   if (champ.curseur)
   {
      champ.curseur.text = balise_debut + champ.curseur.text + balise_fin;
   }
   else if (champ.selectionStart >= 0 && champ.selectionEnd >= 0)
   {
      var debut = champ.value.substring(0, champ.selectionStart);
      var entre = champ.value.substring(champ.selectionStart, champ.selectionEnd);
      var fin = champ.value.substring(champ.selectionEnd);
      champ.value = debut + balise_debut + entre + balise_fin + fin;
      champ.focus();
      champ.setSelectionRange(debut.length + balise_debut.length, champ.value.length - fin.length - balise_fin.length);
   }
   else
   {
      champ.value  += balise_debut + balise_fin;
      champ.focus();
   }
   champ.scrollTop = scroll;
}

var height_avant = 200;

function resizeForm(id_textarea, nb_px)
{
// 	var formulaire = document.getElementById(id_form);
// 	taille_voulue = formulaire.style.height+Number(nb_px);
// 	formulaire.style.height = taille_voulue+"px";
// 
// 	return false;
	var champ = document.getElementById(id_textarea);
	
	height_avant = height_avant + Number(nb_px);
		if (height_avant < 200)
		height_avant = 200;
		if (height_avant > 2000)
		height_avant = 2000;
	
	change = height_avant+"px";
	
	champ.style.height = change;

	return false;
}

$.fn.pause = function(milli,type) {
	milli = milli || 1000;
	type = type || "fx";
	return this.queue(type,function(){
		var self = this;
		setTimeout(function(){
			$.dequeue(self);
		},milli);
	});
};

$.fn.clearQueue = $.fn.unpause = function(type) {
	return this.each(function(){
		type = type || "fx";
		if(this.queue && this.queue[type]) {
			this.queue[type].length = 0;
		}
	});
};

function popUp(title, text)
{
	$("body").append("<div id=darkbg></div><div id=dialogbox><div id=dialoghead>"+title+"<div class=float_right>[<a href=# id=close_popUp>X</a>]</div></div><div id=dialogtext>"+text+"</div></div>");
	$('a#close_popUp').click(function (event)
	{
		event.preventDefault();
		$('div#darkbg').remove();
		$(this).parent("div").parent("div").parent('div#dialogbox').remove();
	});
	$(document).keyup( function(event)
	{
		if(event.keyCode == 27)
			$("a#close_popUp").click();
	});
	$(function ()
	{
		$('div#dialogbox').draggable({handle: 'div#dialoghead'});
		$('div#dialoghead').css('cursor','move');
	});
}
