var isOpera = (navigator.userAgent.indexOf('Opera') != -1);
var isIE    = (!isOpera && navigator.userAgent.indexOf('MSIE') != -1);
var deb = "";  
var longueur = 0;
var lastlongueur = 0;
var timer;
var lastChoice = 0;
var StrMail = /^[A-Za-z0-9._-]+@[a-zA-Z0-9._-]{2,}[.][A-Za-z]{2,4}$/
var StrChamp =/^[0-9A-Za-zàâäéèêëïìîôöòùûü -]{2,}$/
var StrPseudo =/^[0-9A-Za-z_-]{2,}$/
var StrPhone =/^[0-9]{10}$/
function init_menu()
{
	var obj = document.getElementById('onglet_home');	
	
	obj.style.height = "32px";
	obj.style.width = "83px";
	obj.style.top = "13px";
	obj.style.padding = "4px 0px 0px 0px";
	obj.style.background = "url(image/v1/onglet_blanc.png) no-repeat";
	
	var obj2 = document.getElementById('onglet_assistance');	
	
	obj2.style.height = "32px";
	obj2.style.width = "83px";
	obj2.style.top = "13px";
	obj2.style.padding = "4px 0px 0px 0px";
	obj2.style.background = "url(image/v1/onglet_orange.png) no-repeat";
	
	var obj3 = document.getElementById('onglet_formation');	
	
	obj3.style.height = "32px";
	obj3.style.width = "83px";
	obj3.style.top = "13px";
	obj3.style.padding = "4px 0px 0px 0px";
	obj3.style.background = "url(image/v1/onglet_rose.png) no-repeat";
	
	var obj4 = document.getElementById('onglet_creation');	
	
	obj4.style.height = "32px";
	obj4.style.width = "83px";
	obj4.style.top = "13px";
	obj4.style.padding = "4px 0px 0px 0px";
	obj4.style.background = "url(image/v1/onglet_marron.png) no-repeat";
	
	var obj5 = document.getElementById('onglet_hosting');	
	
	obj5.style.height = "32px";
	obj5.style.width = "83px";
	obj5.style.top = "13px";
	obj5.style.padding = "4px 0px 0px 0px";
	obj5.style.background = "url(image/v1/onglet_vert.png) no-repeat";
	
	var obj6 = document.getElementById('onglet_societe');	
	
	obj6.style.height = "32px";
	obj6.style.width = "83px";
	obj6.style.top = "13px";
	obj6.style.padding = "4px 0px 0px 0px";
	obj6.style.background = "url(image/v1/onglet_bleu.png) no-repeat";
	
}
if ( document.all )
{
	function blink_show()
	{
		blink_tags  = document.all.tags('blink');
		blink_count = blink_tags.length;
		for ( i = 0; i < blink_count; i++ )
		{
			blink_tags[i].style.visibility = 'visible';
		}
		
		window.setTimeout( 'blink_hide()', 700 );
	}
	
	function blink_hide()
	{
		blink_tags  = document.all.tags('blink');
		blink_count = blink_tags.length;
		for ( i = 0; i < blink_count; i++ )
		{
			blink_tags[i].style.visibility = 'hidden';
		}
		
		window.setTimeout( 'blink_show()', 250 );
	}
	window.onload = blink_show;
	
}

function submitmyform(evt,f,e) {
	if (evt.keyCode == 13) {
		f.submit();
		e.value='';
	}
}
	

function check_date(ladate) {
	reg = /[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4,4}/
	if (ladate.match(reg))
	{
		d = ladate.substring(0, ladate.indexOf("/"));
		rest = ladate.substring(ladate.indexOf("/") + 1, 100);
		m = rest.substring(0, rest.indexOf("/"));
		y = rest.substring(rest.indexOf("/") + 1, 100);
		if (d==""&&m==""&&y=="")return 0;
		else if (d>0&&d<=31&&m>0&&m<=12&&y>0){if (m==4||m==6||m==9||m==11)
		if (d!=31) return 1; else return -1;
		else if (m!=2) return 1; else{if (d<=28) return 1;
		else if (d==29){if (y%4==0)if (y%400==0||y%100!=0) return 1;
		else return -1; else return -1; }else return -1;} }else return -1;
	}
	else
	{
		return -1;  
	}
}  
	 
function inverse_date(ladate) {
	reg = /[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4,4}/;
	nothing ="";
	if (ladate.match(reg))
	{
		d = ladate.substring(0, ladate.indexOf("/"));
		rest = ladate.substring(ladate.indexOf("/") + 1, 100);
		m = rest.substring(0, rest.indexOf("/"));
		y = rest.substring(rest.indexOf("/") + 1, 100);
		if (d.length == 1)
			d = "0"+d;
		if (m.length == 1)
			m = "0"+m;
		return y+m+d;
	}
	else
		return -1;
}

function send_form_dedicace_step_1(f) {
	donnee = "titre="+f.titre.value;
	
	for(i=0;i<f.elements['lstartistebyid[]'].length;i++)
	{
		if(f.elements['lstartistebyid[]'].options[i].selected == true)
		{	   
			donnee	+= "&lstartistebyid[]="+f.elements['lstartistebyid[]'].options[i].value;
		} 
	} 	
   sendData('p=dedicace_radio&search=ok&'+donnee,'./ajax/ajax_loader.ajx.php','bloc_center');
   return false;

}

function send_form_dedicace_step_2(f) 
{	   
	donnee="";
	for (var i=0; i<f.pls.length;i++) {
		if (f.pls[i].checked) {
			donnee = "&pls="+f.pls[i].value;		
		}
	}
	if (donnee.length) {  
		sendData('p=dedicace_radio&step=2'+donnee,'./ajax/ajax_loader.ajx.php','bloc_center');
	}	 
	return false;  

} 

function send_form_dedicace_step_3(f) {	   
	if (f.from.value != '' && f.to.value != '' && f.message.value != '' && f.title.value != '' && f.pls.value != '') 
	{
		donnee = "&from="+f.from.value;
		donnee += "&to="+f.to.value;
		donnee += "&message="+f.message.value;		
		donnee += "&title="+f.title.value;
		donnee += "&pls="+f.pls.value;  		
		sendData('p=dedicace_radio'+donnee,'./ajax/ajax_loader.ajx.php','bloc_center');
	}
	return false;
} 

function send_form_chat(f)
{			  
	StrMessage = "";
	if (!(f.wantedPseudo.value.match(StrPseudo)))
		StrMessage = "Votre pseudo est invalide, merci d'utiliser des caractères alaphanumérique sans accent";
		
	donnee	= "wantedPseudo="+f.wantedPseudo.value;
	donnee += "&acces_code="+f.acces_code.value;
	donnee += "&interface_choose="+f.interface_choose.options[f.interface_choose.selectedIndex].value;	 
	donnee += "&chan="+f.chan.value;
	donnee += "&otherNick="+f.otherNick.value;
	donnee += "&try="+f.tryz.value;
	donnee += "&display="+f.display.value;
	donnee += "&onglet="+f.onglet.value;
	donnee += "&fichier="+f.fichier.value;
	donnee += "&step="+f.step.value;
	donnee += "&mystep="+f.mystep.value;
	donnee += "&duree="+f.duree.value;
	donnee += "&name="+f.name.value;
	donnee += "&submit="+f.submit.value;	
	i		= 1; 
	while (document.getElementById('code'+i)) {
		donnee += '&code'+i+"="+document.getElementById('code'+i).value;
		i++;
	}		 
	if (StrMessage.length)
	{
		alert("Erreur :\n" + StrMessage);
	}
	else
	{
		sendData('p=chat_lyon_gratuit&connect=yes&'+donnee,'./ajax/ajax_loader.ajx.php','bloc_center');
	}		
	return false;
}


function send_form_create_fiche(f) {

  	StrMessage = "";
	if (!(f.nom_ac.value.match(StrPseudo)))
		StrMessage += "» Votre pseudo est invalide, merci d'utiliser des caractères alaphanumérique sans accent\r\n";
	if (!(f.mail_ac.value.match(StrMail)))
		StrMessage += "» Votre mail est invalide, merci d'utiliser une adresse email valide\r\n";
	if (f.mail_ac.value != f.conf_mail_ac.value)
		StrMessage += "» Votre mail est different de celui saisie dans la boite de confirmation\r\n";
				
	donnee	= "nom_ac="+f.nom_ac.value;
	donnee += "&mail_ac="+f.mail_ac.value;
	donnee += "&conf_mail_ac="+f.conf_mail_ac.value;
	if (StrMessage.length)
	{
		alert("Erreur :\n" + StrMessage);
	}
	else
	{
		sendData('p=inscription_chat_lyon&insert=yes&'+donnee,'./ajax/ajax_loader.ajx.php','bloc_center');
	}		
	return false;
}


function OuvrirPopup(page,nom,hauteur,largeur,option) { 
    var top=(screen.height-hauteur)/2;
    var left=(screen.width-largeur)/2;		
 	window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+option);
}

function emptyValue (elem, value) {
	if (elem.value == value) {
		elem.value = '';
	}
}

function checkKey(ev, lst) {
	clearTimeout(timer);
	var c = "";
	var s = document.getElementById(lst);
	if(ev && ev.which) c = ev.which;
	if(isIE)           c = window.event.keyCode;

	if (c < 96 || c > 105) {
		deb += String.fromCharCode(c).toLowerCase();
	}
	else {
		c = c - 48;
		deb += String.fromCharCode(c).toLowerCase();		
	}
	for(var i=0; i<s.options.length; ++i) {
		if(s.options[i].text.substr(0,deb.length).toLowerCase() == deb) {
			s.selectedIndex = i;
			lastChoice      = i;
			timer = setTimeout('resetString()', 1000);
			return;
		}
	}
	timer = setTimeout('resetString()', 500);
	s.selectedIndex = lastChoice;
	
}

function resetString() {
	deb = "";
}

function sendData(param, page,div)
{	 
	var content = document.getElementById(""+div+"");
	content.innerHTML = "<br><br><center><img src='./image/ajax-loader.gif'></center>";

	if(window.ActiveXObject)
	{
		//Internet Explorer
		var XhrObj = new ActiveXObject("Microsoft.XMLHTTP") ;
		XhrObj.onreadystatechange = function()
		{
			/*
			content.innerHTML = "<font class='text' style='text-align:center'><img src='image/ajax-loader-square.gif'>&nbsp;&nbsp;</font>";
			if (XhrObj.readyState == 0)
				content.innerHTML += "<font class='tinytext' style='text-align:center'>Requête en cours d'envoie</font>";	
			if (XhrObj.readyState == 1)
				 content.innerHTML += "<font class='tinytext' style='text-align:center'>En cours d'analyse</font>";
			if (XhrObj.readyState == 2)
				 content.innerHTML += "<font class='tinytext' style='text-align:center'>Requête reçue</font>";
			if (XhrObj.readyState == 3)
				 content.innerHTML += "<font class='text' style='text-align:center'>Réponse en cours</font>";	
			*/	
			if (XhrObj.readyState == 4 && XhrObj.status == 200)
				if (content)
					content.innerHTML = XhrObj.responseText ; 
				if(param=="p=assistance"){
					 init_menu();
					
					 obja = document.getElementById('onglet_assistance');			
				     obja.style.height = "45px";
					obja.style.width = "101px";
					obja.style.top = "0px";
					obja.style.padding = "17px 0px 0px 0px";
					obja.style.background = "url(image/v1/onglet_orange_grand.png) no-repeat";
					}
				else if(param=="p=home"){
					 init_menu();
					 objb = document.getElementById('onglet_home');			
				     objb.style.height = "45px";
					objb.style.width = "101px";
					objb.style.top = "0px";
					objb.style.padding = "17px 0px 0px 0px";
					objb.style.background = "url(image/v1/onglet_blanc_grand.png) no-repeat";
					}
					else if(param=="p=formation"){
					 init_menu();
					 objc = document.getElementById('onglet_formation');			
				     objc.style.height = "45px";
					objc.style.width = "101px";
					objc.style.top = "0px";
					objc.style.padding = "17px 0px 0px 0px";
					objc.style.background = "url(image/v1/onglet_rose_grand.png) no-repeat";
					}
					else if(param=="p=creation"){
					 init_menu();
					 objd = document.getElementById('onglet_creation');			
				     objd.style.height = "45px";
					objd.style.width = "101px";
					objd.style.top = "0px";
					objd.style.padding = "17px 0px 0px 0px";
					objd.style.background = "url(image/v1/onglet_marron_grand.png) no-repeat";
					}
					else if(param=="p=hosting"){
					 init_menu();
					 obje = document.getElementById('onglet_hosting');			
				     obje.style.height = "45px";
					obje.style.width = "101px";
					obje.style.top = "0px";
					obje.style.padding = "17px 0px 0px 0px";
					obje.style.background = "url(image/v1/onglet_vert_grand.png) no-repeat";
					}
					else if(param=="p=societe"){
					 init_menu();
					 objf = document.getElementById('onglet_societe');			
				     objf.style.height = "45px";
					objf.style.width = "101px";
					objf.style.top = "0px";
					objf.style.padding = "17px 0px 0px 0px";
					objf.style.background = "url(image/v1/onglet_bleu_grand.png) no-repeat";
					}	
		}	
		XhrObj.open("POST", page, true);
		XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		XhrObj.send(param);		
		
	}//fin if
	else  if(window.XMLHttpRequest)
	{
	    //Mozilla
		var XhrObj = new XMLHttpRequest();	
		XhrObj.open("POST", page, false);
		XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		XhrObj.send(param);	
		if (XhrObj.readyState == 4 && XhrObj.status == 200) {
			if(content) {
				content.innerHTML = XhrObj.responseText;
				if(param=="p=assistance"){
					 init_menu();
					
					 obja = document.getElementById('onglet_assistance');			
				     obja.style.height = "45px";
					obja.style.width = "101px";
					obja.style.top = "0px";
					obja.style.padding = "17px 0px 0px 0px";
					obja.style.background = "url(image/v1/onglet_orange_grand.png) no-repeat";
					}
				else if(param=="p=home"){
					 init_menu();
					 objb = document.getElementById('onglet_home');			
				     objb.style.height = "45px";
					objb.style.width = "101px";
					objb.style.top = "0px";
					objb.style.padding = "17px 0px 0px 0px";
					objb.style.background = "url(image/v1/onglet_blanc_grand.png) no-repeat";
					}
					else if(param=="p=formation"){
					 init_menu();
					 objc = document.getElementById('onglet_formation');			
				     objc.style.height = "45px";
					objc.style.width = "101px";
					objc.style.top = "0px";
					objc.style.padding = "17px 0px 0px 0px";
					objc.style.background = "url(image/v1/onglet_rose_grand.png) no-repeat";
					}
					else if(param=="p=creation"){
					 init_menu();
					 objd = document.getElementById('onglet_creation');			
				     objd.style.height = "45px";
					objd.style.width = "101px";
					objd.style.top = "0px";
					objd.style.padding = "17px 0px 0px 0px";
					objd.style.background = "url(image/v1/onglet_marron_grand.png) no-repeat";
					}
					else if(param=="p=hosting"){
					 init_menu();
					 obje = document.getElementById('onglet_hosting');			
				     obje.style.height = "45px";
					obje.style.width = "101px";
					obje.style.top = "0px";
					obje.style.padding = "17px 0px 0px 0px";
					obje.style.background = "url(image/v1/onglet_vert_grand.png) no-repeat";
					}
					else if(param=="p=societe"){
					 init_menu();
					 objf = document.getElementById('onglet_societe');			
				     objf.style.height = "45px";
					objf.style.width = "101px";
					objf.style.top = "0px";
					objf.style.padding = "17px 0px 0px 0px";
					objf.style.background = "url(image/v1/onglet_bleu_grand.png) no-repeat";
					}
				
					
				
				
				
				
				//longueur=content.innerHTML.length
			}
		}		
	}
	//fin else
}

function verifData(param, page,div)
{	 
	var content = document.getElementById(""+div+"");
	
	if(window.ActiveXObject)
	{
		//Internet Explorer
		var XhrObj = new ActiveXObject("Microsoft.XMLHTTP") ;
		XhrObj.onreadystatechange = function()
		{
			if (XhrObj.readyState == 4 && XhrObj.status == 200) {
				if (content)
					content.innerHTML = XhrObj.responseText ; 		 
			}
		}	
		XhrObj.open("POST", page, true);
		XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		XhrObj.send(param);			
	}//fin if
	else  if(window.XMLHttpRequest)
	{
	    //Mozilla
		var XhrObj = new XMLHttpRequest();	
		XhrObj.open("POST", page, false);
		
		XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		XhrObj.send(param);	
		if (XhrObj.readyState == 4 && XhrObj.status == 200) {
			if(content) {
				content.innerHTML = XhrObj.responseText; 
				
			}
		}		
	}
	//fin else
}

//FONCTION WYSIWYG

//init variables
var isRichText = false;
var rng;
var currentRTE;


function initRTE() {
	//check to see if designMode mode is available
	if (document.getElementById) {
		if (document.all) {
			//check for internet explorer 5.5+
			if (document.URLUnencoded) isRichText = true;
		} else {
			//check for browsers that support designmode
			if (document.designMode) isRichText = true;
		}
	}
}

function writeRichText(rte, html, width, height, buttons) {
	if (isRichText) {
		writeRTE(rte, html, width, height, buttons);
	} else {
		writeDefault(rte, html, width, height, buttons);
	}
}

function writeDefault(rte, html, width, height, buttons) {
	document.writeln('<textarea name="' + rte + '" id="' + rte + '" style="width: ' + width + 'px; height: ' + height + 'px;">' + html + '</textarea>');
}

function writeRTE(rte, html, width, height, buttons) {
	if (buttons == true) {
		document.writeln('<style type="text/css">');
		document.writeln('.btnImage {cursor: pointer; cursor: hand;}');
		document.writeln('</style>');
		/*document.writeln('<table id="Buttons1_' + rte + '">');
		document.writeln('	<tr>');
		document.writeln('		<td>');
		document.writeln('			<select id="formatblock" onchange="Select(\'' + rte + '\', this.id);" class="input">');
		document.writeln('				<option value="<p>">Normal</option>');
		document.writeln('				<option value="<p>">Paragraph</option>');
		document.writeln('				<option value="<h1>">Heading 1 <h1></option>');
		document.writeln('				<option value="<h2>">Heading 2 <h2></option>');
		document.writeln('				<option value="<h3>">Heading 3 <h3></option>');
		document.writeln('				<option value="<h4>">Heading 4 <h4></option>');
		document.writeln('				<option value="<h5>">Heading 5 <h5></option>');
		document.writeln('				<option value="<h6>">Heading 6 <h6></option>');
		document.writeln('				<option value="<address>">Address <ADDR></option>');
		document.writeln('				<option value="<pre>">Formatted <pre></option>');
		document.writeln('			</select>');
		document.writeln('		</td>');
		document.writeln('		<td>');
		document.writeln('			<select id="fontname" name="selectFont" onchange="Select(\'' + rte + '\', this.id)" class="input">');
		document.writeln('				<option value="Font" selected>Font</option>');
		document.writeln('				<option value="Arial, Helvetica, sans-serif">Arial</option>');
		document.writeln('				<option value="Arial Black, Helvetica, sans-serif">Arial Black</option>');		
		document.writeln('				<option value="Comic Sans MS, mono">Comic Sans Ms</option>');		
		document.writeln('				<option value="Courier, mono">Courier</option>');		
		document.writeln('				<option value="Courier New, Courier, mono">Courier New</option>');
		document.writeln('				<option value="Georgia, mono">Georgia</option>');		
		document.writeln('				<option value="Impact, mono">Impact</option>');						
		document.writeln('				<option value="Sympbol, mono">Sympbol</option>');				
		document.writeln('				<option value="Times New Roman, Times, serif">Times New Roman</option>');
		document.writeln('				<option value="Trebuchet MS, mono">Trebuchet MS</option>');						
		document.writeln('				<option value="Verdana, Arial, Helvetica, sans-serif">Verdana</option>');
		document.writeln('				<option value="Webdings, mono">Webdings</option>');									  		   
		document.writeln('			</select>');
		document.writeln('		</td>');
		document.writeln('		<td>');
		document.writeln('			<select unselectable="on" id="fontsize" onchange="Select(\'' + rte + '\', this.id);" class="input">');
		document.writeln('				<option value="Size">Size</option>');
		document.writeln('				<option value="1">1</option>');
		document.writeln('				<option value="2">2</option>');
		document.writeln('				<option value="3">3</option>');
		document.writeln('				<option value="4">4</option>');
		document.writeln('				<option value="5">5</option>');
		document.writeln('				<option value="6">6</option>');
		document.writeln('				<option value="7">7</option>');
		document.writeln('			</select>');
		document.writeln('		</td>');
		document.writeln('	</tr>');
		document.writeln('</table>');
		*/
		document.writeln('<table id="Buttons2_' + rte + '" cellpadding="1" cellspacing="0">');
		document.writeln('	<tr>');
		document.writeln('		<td><img class="btnImage" src="image/bold.gif" width="25" height="24" alt="Bold" title="Bold" onClick="FormatText(\'' + rte + '\', \'bold\', \'\')"></td>');
		document.writeln('		<td><img class="btnImage" src="image/italic.gif" width="25" height="24" alt="Italic" title="Italic" onClick="FormatText(\'' + rte + '\', \'italic\', \'\')"></td>');
		document.writeln('		<td><img class="btnImage" src="image/underline.gif" width="25" height="24" alt="Underline" title="Underline" onClick="FormatText(\'' + rte + '\', \'underline\', \'\')"></td>');
		document.writeln('		<td>&nbsp;</td>');
		document.writeln('		<td><img class="btnImage" src="image/justifyleft.gif" width="25" height="24" alt="Align Left" title="Align Left" onClick="FormatText(\'' + rte + '\', \'justifyleft\', \'\')"></td>');
		document.writeln('		<td><img class="btnImage" src="image/justifycenter.gif" width="25" height="24" alt="Center" title="Center" onClick="FormatText(\'' + rte + '\', \'justifycenter\', \'\')"></td>');
		document.writeln('		<td><img class="btnImage" src="image/justifyright.gif" width="25" height="24" alt="Align Right" title="Align Right" onClick="FormatText(\'' + rte + '\', \'justifyright\', \'\')"></td>');
		document.writeln('		<td><img class="btnImage" src="image/justifyfull.gif" width="25" height="24" alt="Justify Full" title="Justify Full" onclick="FormatText(\'' + rte + '\', \'justifyfull\', \'\')"></td>');		
		document.writeln('		<td>&nbsp;</td>');
		document.writeln('		<td><img class="btnImage" src="image/hr.gif" width="25" height="24" alt="Horizontal Rule" title="Horizontal Rule" onClick="FormatText(\'' + rte + '\', \'inserthorizontalrule\', \'\')"></td>');		
		document.writeln('		<td><img class="btnImage" src="image/orderedlist.gif" width="25" height="24" alt="Ordered List" title="Ordered List" onClick="FormatText(\'' + rte + '\', \'insertorderedlist\', \'\')"></td>');
		document.writeln('		<td><img class="btnImage" src="image/unorderedlist.gif" width="25" height="24" alt="Unordered List" title="Unordered List" onClick="FormatText(\'' + rte + '\', \'insertunorderedlist\', \'\')"></td>');
		document.writeln('		<td>&nbsp;</td>');
		document.writeln('		<td><img class="btnImage" src="image/outdent.gif" width="25" height="24" alt="Outdent" title="Outdent" onClick="FormatText(\'' + rte + '\', \'outdent\', \'\')"></td>');
		document.writeln('		<td><img class="btnImage" src="image/indent.gif" width="25" height="24" alt="Indent" title="Indent" onClick="FormatText(\'' + rte + '\', \'indent\', \'\')"></td>');
//		document.writeln('		<td><div id="forecolor"><img class="btnImage" src="image/forecolor.gif" width="25" height="24" alt="Text Color" title="Text Color" onClick="FormatText(\'' + rte + '\', \'forecolor\', \'\')"></div></td>');
//		document.writeln('		<td><div id="hilitecolor"><img class="btnImage" src="image/backcolor.gif" width="25" height="24" alt="Background Color" title="Background Color" onClick="FormatText(\'' + rte + '\', \'hilitecolor\', \'\')"></div></td>');
		document.writeln('		<td>&nbsp;</td>');
		document.writeln('		<td><img class="btnImage" src="image/link.gif" width="25" height="24" alt="Insert Link" title="Insert Link" onClick="FormatText(\'' + rte + '\', \'createlink\')"></td>');
//		document.writeln('		<td><img class="btnImage" src="image/image.gif" width="25" height="24" alt="Add Image" title="Add Image" onClick="AddImage(\'' + rte + '\')"></td>');
//		if (document.all) document.writeln('		<td><img class="btnImage" src="image/spellcheck.gif" width="25" height="24" alt="Add Image" title="Add Image" onClick="checkspell()"></td>');
//		document.writeln('		<td>&nbsp;</td>');
//		document.writeln('		<td><img class="btnImage" src="image/post_button_cut.gif" width="25" height="24" alt="Cut" title="Cut" onClick="FormatText(\'' + rte + '\', \'cut\')"></td>');
//		document.writeln('		<td><img class="btnImage" src="image/post_button_copy.gif" width="25" height="24" alt="Copy" title="Copy" onClick="FormatText(\'' + rte + '\', \'copy\')"></td>');
//		document.writeln('		<td><img class="btnImage" src="image/post_button_paste.gif" width="25" height="24" alt="Paste" title="Paste" onClick="FormatText(\'' + rte + '\', \'paste\')"></td>');
//		document.writeln('		<td>&nbsp;</td>');
//		document.writeln('		<td><img class="btnImage" src="image/post_button_undo.gif" width="25" height="24" alt="Undo" title="Undo" onClick="FormatText(\'' + rte + '\', \'undo\')"></td>');
//		document.writeln('		<td><img class="btnImage" src="image/post_button_redo.gif" width="25" height="24" alt="Redo" title="Redo" onClick="FormatText(\'' + rte + '\', \'redo\')"></td>');
		document.writeln('	</tr>');
		document.writeln('</table>');
	}
	document.writeln('<iframe id="' + rte + '" width="' + width + 'px" height="' + height + 'px" src="blank.htm""></iframe>');
//	document.writeln('<br /><input type="checkbox" id="chkSrc' + rte + '" onclick="toggleHTMLSrc(\'' + rte + '\');" />&nbsp;Mode HTML');
	document.writeln('<iframe width="500" height="300" id="cp' + rte + '" src="palette.php" marginwidth="0" marginheight="0" scrolling="no" style="visibility:hidden; position: absolute;"></iframe>');
	document.writeln('<input type="hidden" id="hdn' + rte + '" name="' + rte + '" value="">');
	document.getElementById('hdn' + rte).value = html;
	setTimeout('enableDesignMode(\'' + rte + '\', \'' + html + '\')', 250);
}

function enableDesignMode(rte, html) {
	if (document.all) {
		frames[rte].document.open();
		frames[rte].document.write(html);
//		frames[rte].document.write('Module de texte');
		frames[rte].document.close();
		frames[rte].document.designMode = "On";
	}
	else {
		var updateHTML = "document.getElementById('" + rte + "').contentWindow.document.body.innerHTML = '" + html + "';";
		setTimeout(updateHTML + "document.getElementById('" + rte + "').contentDocument.designMode = 'On';", 500);
		//attach a keyboard handler for Mozilla to make keyboard shortcuts for formatting text work
		document.getElementById(rte).contentWindow.document.addEventListener("keypress", kb_handler, true);
	}
}

function updateRTE(rte) {
	//set message value
	var oHdnMessage = document.getElementById('hdn' + rte);
	var oMessageFrame = document.getElementById(rte);
	
	if (isRichText) {
		if (oHdnMessage.value == null) oHdnMessage.value = "";
		oHdnMessage.value = oMessageFrame.contentWindow.document.body.innerHTML;
		//exception for Mozilla
		if (oHdnMessage.value.indexOf('<br>') > -1 && oHdnMessage.value.length == 8) oHdnMessage.value = "";
	}
}

function toggleHTMLSrc(rte) {
	//contributed by Bob Hutzel (thanks Bob!)
	var doc = document.getElementById(rte).contentWindow.document;
	
	if (document.getElementById("chkSrc" + rte).checked) {
	
		document.getElementById("Buttons1_" + rte).style.visibility = "hidden";
		document.getElementById("Buttons2_" + rte).style.visibility = "hidden";
		if (document.all) {
			doc.body.innerText = doc.body.innerHTML;
		} else {
			var htmlSrc = doc.createTextNode(doc.body.innerHTML);
			doc.body.innerHTML = "";
			doc.body.appendChild(htmlSrc);
		}

	} else {
		document.getElementById("Buttons1_" + rte).style.visibility = "visible";
		document.getElementById("Buttons2_" + rte).style.visibility = "visible";
		if (document.all) {
			doc.body.innerHTML = doc.body.innerText;
		} else {
			var htmlSrc = doc.body.ownerDocument.createRange();
			htmlSrc.selectNodeContents(doc.body);
			doc.body.innerHTML = htmlSrc.toString();
		}
	}
}

//Function to format text in the text box
function FormatText(rte, command, option) {
	if ((command == "forecolor") || (command == "hilitecolor")) {
		parent.command = command;
		buttonElement = document.getElementById(command);
		document.getElementById('cp' + rte).style.left = getOffsetLeft(buttonElement) + "px";
		document.getElementById('cp' + rte).style.top = (getOffsetTop(buttonElement) + buttonElement.offsetHeight) + "px";
		if (document.getElementById('cp' + rte).style.visibility == "hidden")
			document.getElementById('cp' + rte).style.visibility="visible";
		else {
			document.getElementById('cp' + rte).style.visibility="hidden";
		}
		
		//get current selected rte
		currentRTE = rte;
		
		//get current selected range
		var sel = document.getElementById(rte).contentWindow.document.selection; 
		if (sel!=null) {
			rng = sel.createRange();
		}
	}
	else if (command == "createlink") { // && browser.isIE55up == false
		var szURL = prompt("Enter a URL:", "Http://");
		document.getElementById(rte).contentWindow.document.execCommand("Unlink",false,null);
		document.getElementById(rte).contentWindow.document.execCommand("CreateLink",false,szURL);
	}
	else {
		document.getElementById(rte).contentWindow.focus();
	  	document.getElementById(rte).contentWindow.document.execCommand(command, false, option);
		document.getElementById(rte).contentWindow.focus();
	}
}

//Function to set color
function setColor(color) {
	var parentCommand = parent.command;
	var rte = currentRTE;
	
	if (document.all) {
		//retrieve selected range
		var sel = document.getElementById(rte).contentWindow.document.selection; 
		if (parentCommand == "hilitecolor") parentCommand = "backcolor";
		if (sel!=null) {
			var newRng = sel.createRange();
			newRng = rng;
			newRng.select();
		}
	}
	else {
		document.getElementById(rte).contentWindow.focus();
	}
	document.getElementById(rte).contentWindow.document.execCommand(parentCommand, false, color);
	document.getElementById(rte).contentWindow.focus();
	document.getElementById('cp' + rte).style.visibility="hidden";
}

//Function to add image
function AddImage(rte) {
	imagePath = prompt('Enter Image URL:', 'http://');				
	if ((imagePath != null) && (imagePath != "")) {
		document.getElementById(rte).contentWindow.focus()
		document.getElementById(rte).contentWindow.document.execCommand('InsertImage', false, imagePath);
	}
	document.getElementById(rte).contentWindow.focus()
}

//function to perform spell check
function checkspell() {
	try {
		var tmpis = new ActiveXObject("ieSpell.ieSpellExtension");
		tmpis.CheckAllLinkedDocuments(document);
	}
	catch(exception) {
		if(exception.number==-2146827859) {
			if (confirm("ieSpell not detected.  Click Ok to go to download page."))
				window.open("http://www.iespell.com/download.php","DownLoad");
		}
		else
			alert("Error Loading ieSpell: Exception " + exception.number);
	}
}

function getOffsetTop(elm) {
	var mOffsetTop = elm.offsetTop;
	var mOffsetParent = elm.offsetParent;
	
	while(mOffsetParent){
		mOffsetTop += mOffsetParent.offsetTop;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	
	return mOffsetTop;
}

function getOffsetLeft(elm) {
	var mOffsetLeft = elm.offsetLeft;
	var mOffsetParent = elm.offsetParent;
	
	while(mOffsetParent) {
		mOffsetLeft += mOffsetParent.offsetLeft;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	
	return mOffsetLeft;
}

function Select(rte, selectname)
{
	var cursel = document.getElementById(selectname).selectedIndex;
	// First one is always a label
	if (cursel != 0) {
		var selected = document.getElementById(selectname).options[cursel].value;
		document.getElementById(rte).contentWindow.document.execCommand(selectname, false, selected);
		document.getElementById(selectname).selectedIndex = 0;
	}
	document.getElementById(rte).contentWindow.focus();
}

function kb_handler(evt, rte) {
	//contributed by Anti Veeranna (thanks Anti!)
	if (evt.ctrlKey) {
		var key = String.fromCharCode(evt.charCode).toLowerCase();
		var cmd = '';
		switch (key) {
			case 'b': cmd = "bold"; break;
			case 'i': cmd = "italic"; break;
			case 'u': cmd = "underline"; break;
		};

		if (cmd) {
			evt.target.ownerDocument.execCommand(cmd,false,true);
			// stop the event bubble
			evt.preventDefault();
			evt.stopPropagation();
		}
 	}
}

function montre(id) { 
	var d = document.getElementById(id);
	for (var i = 1; i<=5; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
	if (d) {d.style.display='block';}
	  
}

initRTE();		