
var timer = 0;
var ptag = String.fromCharCode(5, 6, 7);
function visualisation() {
	if (document.getElementById) {
		t = document.getElementById("commentform").c_content.value;
		t = smiley_to_html(t);
		t = code_to_html(t);
		document.getElementById("live-preview").innerHTML = t;

tt = document.getElementById("commentform").c_nom.value;
tss = document.getElementById("commentform").c_site.value;
tss = (tss != "" && tss != "http://") ? "<a href=\"" + tss + "\">" + tt + "</a>" : tt;

		document.getElementById("c_preview_nom").innerHTML = tss;



		//if (document.getElementById("auto").checked) timer = setTimeout(visualisation, 1000);
	} else {
		return;
	}
}
function showpreview() {
	//if(document.getElementById("commentform").c_content.value == "") {
		document.getElementById("c_preview_live").style.display = "";
		document.getElementById("c_preview_block").style.display = "";
document.getElementById("comclear").style.display = "";
		tn = document.getElementById("commentform").c_nom.value;
		tm = document.getElementById("commentform").c_mail.value;
		ts = document.getElementById("commentform").c_site.value;
		
		tm = (tm != "") ? " :: <a href=\"mailto:" + tm + "\">email</a>" : "";
		ts = (ts != "" && ts != "http://") ? "<a href=\"" + ts + "\">" + tn + "</a>" : "";
		document.getElementById("c_preview_nom").innerHTML = ts;
		visualisation();
	//}
}
function hidepreview() {
	if(document.getElementById("commentform").c_content.value == "") {
		document.getElementById("c_preview_live").style.display = "none";
		document.getElementById("c_preview_block").style.display = "none";
document.getElementById("comclear").style.display = "none";
	}
}
function automatique() {
	//if (document.getElementById("auto").checked) visualisation();
}
function smiley_to_html(t) {
	t = remplace_tag(/(\:\-?\))/g,'<img style=\"margin-bottom: -3px;\" src=\"http://blog.hivacruz.com/themes/moonstyle/smilies/rofl.gif\" alt=\"$1\" class=\"smiley\" />',t);
	t = remplace_tag(/(\;\-?\))/g,'<img style=\"margin-bottom: -3px;\" src=\"http://blog.hivacruz.com/themes/moonstyle/smilies/wink.gif\" alt=\"$1\" class=\"smiley\" />',t);


	t = remplace_tag(/(\:\-?\o)/g,'<img style=\"margin-bottom: -3px;\" src=\"http://blog.hivacruz.com/themes/moonstyle/smilies/117.gif\" alt=\"$1\" class=\"smiley\" />',t);
t = remplace_tag(/(\:\-?\p)/g,'<img style=\"margin-bottom: -3px;\" src=\"http://blog.hivacruz.com/themes/moonstyle/smilies/104.gif\" alt=\"$1\" class=\"smiley\" />',t);
	t = remplace_tag(/(\:\-?D)/g,'<img style=\"margin-bottom: -3px;\" src=\"http://blog.hivacruz.com/themes/moonstyle/smilies/106.gif\" alt=\"$1\" class=\"smiley\" />',t);
	t = remplace_tag(/(\:\-?\()/g,'<img style=\"margin-bottom: -3px;\" src=\"http://blog.hivacruz.com/themes/moonstyle/smilies/126.gif\" alt=\"$1\" class=\"smiley\" />',t);
//t = remplace_tag(/(\:\-?\s)/g,'<img style=\"margin-bottom: -3px;\" src=\"http://blog.hivacruz.com/themes/moonstyle/smilies/133.gif\" alt=\"$1\" class=\"smiley\" />',t);
t = remplace_tag(/(\:\-?d)/g,'<img style=\"margin-bottom: -3px;\" src=\"http://blog.hivacruz.com/themes/moonstyle/smilies/106.gif\" alt=\"$1\" class=\"smiley\" />',t);

t = remplace_tag(/(\:\-?s)/g,'<img style=\"margin-bottom: -3px;\" src=\"http://blog.hivacruz.com/themes/moonstyle/smilies/133.gif\" alt=\"$1\" class=\"smiley\" />',t);
t = remplace_tag(/(\:\-?S)/g,'<img style=\"margin-bottom: -3px;\" src=\"http://blog.hivacruz.com/themes/moonstyle/smilies/133.gif\" alt=\"$1\" class=\"smiley\" />',t);
t = remplace_tag(/(\:\-?\P)/g,'<img style=\"margin-bottom: -3px;\" src=\"http://blog.hivacruz.com/themes/moonstyle/smilies/104.gif\" alt=\"$1\" class=\"smiley\" />',t);
	t = remplace_tag(/(\:'\-?\()/g,'<img style=\"margin-bottom: -3px;\" src=\"http://blog.hivacruz.com/themes/moonstyle/smilies/127.gif\" alt=\"$1\" class=\"smiley\" />',t);
	t = remplace_tag(/(\:\-?\O)/g,'<img style=\"margin-bottom: -3px;\" src=\"http://blog.hivacruz.com/themes/moonstyle/smilies/117.gif\" alt=\"$1\" class=\"smiley\" />',t);
	t = remplace_tag(/(\:\-?\x)/g,'<img style=\"margin-bottom: -3px;\" src=\"http://blog.hivacruz.com/themes/moonstyle/smilies/142.gif\" alt=\"$1\" class=\"smiley\" />',t);

	t = remplace_tag(/(\:\-?\X)/g,'<img style=\"margin-bottom: -3px;\" src=\"http://blog.hivacruz.com/themes/moonstyle/smilies/142.gif\" alt=\"$1\" class=\"smiley\" />',t);

	return t;
}
function code_to_html(t) {
	t=nl2khol(t);
// balise Gras
	t = deblaie(/(\[\/b\])/g,t);
	t = remplace_tag(/\[b\](.+)\[\/b\]/g,'<strong>$1</strong>',t);
	t = remblaie(t);
// balise Italique
	t = deblaie(/(\[\/i\])/g,t);
	t = remplace_tag(/\[i\](.+)\[\/i\]/g,'<em>$1</em>',t);
	t = remblaie(t);
// balise Underline
	t = deblaie(/(\[\/u\])/g,t);
	t = remplace_tag(/\[u\](.+)\[\/u\]/g,'<span style="text-decoration:underline">$1</span>',t);
	t = remblaie(t);
// balise Supprime
	t = deblaie(/(\[\/s\])/g,t);
	t = remplace_tag(/\[s\](.+)\[\/s\]/g,'<del>$1</del>',t);
	t = remblaie(t);
// balise quote
	t = deblaie(/(\[\/quote\])/g,t);
	t = remplace_tag(/\[quote\](.+)\[\/quote\]/g,'<q>$1</q>',t);
	t = remblaie(t);
// balise quote=
	t = deblaie(/(\[\/quote\])/g,t);
	t = remplace_tag(/\[quote=([^"]+)\](.+)\[\/quote\]/g,'<strong>$1 :</strong><br /><q>$2</q>',t);
	t = remblaie(t);
// balise quote=""
	t = deblaie(/(\[\/quote\])/g,t);
	t = remplace_tag(/\[quote=\"(.+)\"\](.+)\[\/quote\]/g,'<strong>$1 :</strong><br /><q>$2</q>',t);
	t = remblaie(t);
// balise code	
	t = remplace_tag(/\[code\](.+)\[\/code\]/g,'<code>$1</code>',t);
// balise URL	
	t = remplace_tag(/\[url\](.+)\[\/url\]/g,'<a href="$1">$1</a>',t);
// balise URL=	
	t = remplace_tag(/\[url=([^\s<>]+)\](.+)\[\/url\]/g,'<a href="$1">$2</a>',t);
/*// balise Img
	t = deblaie(/(\[\/img\])/g,t)
	t = remplace_tag(/\[img\](.+)\[\/img\]/g,'<img src="$1" />',t)
	t = remblaie(t)*/
/*// balise Color	
	t = deblaie(/(\[\/color\])/g,t)
	t = remplace_tag(/\[color=(#[a-fA-F0-9]{6})\](.+)\[\/color\]/g,'<font color="$1">$2</font>',t)
	t = remblaie(t)
// balise size	
	t = deblaie(/(\[\/size\])/g,t)
	t = remplace_tag(/\[size=([+-]?[0-9])\](.+)\[\/size\]/g,'<font size="$1">$2</font>',t)
	t = remblaie(t)*/
	t = unkhol(t)
	t = nl2br(t)
	return t
}
function deblaie(reg,t) {
	texte=new String(t);
	return texte.replace(reg,'$1\n');
}
function remblaie(t) {
	texte=new String(t);
	return texte.replace(/\n/g,'');
}
function remplace_tag(reg,rep,t) {
	texte=new String(t);
	return texte.replace(reg,rep);
}
function nl2br(t) {
	texte=new String(t);
	return texte.replace(/\n/g,'<br/>');
}
function nl2khol(t) {
	texte=new String(t);
	return texte.replace(/\n/g,ptag);
}
function unkhol(t) {
	texte=new String(t);
	return texte.replace(new RegExp(ptag,'g'),'\n');
}