// Debut Ajax
var Ajax_request = 	function() { this.request.apply(this, arguments); };
Ajax_request.prototype = {
	request: function (url, options) {	
		this.getObject();		
		if (this.Ajax_object === null) {
			//alert('No Ajax with this navigator!');
			return;
		}
		document.body.style.cursor = "wait";
		if ( typeof(options) == 'undefined' ) {options = [];} // new Array();}
		if ( typeof(options) == 'object' ) {
			var method = options.method || 'post';
			var successEnd = options.onSuccess || alert('Ajax_request: Error - onSuccess undefined !');
			var errorEnd = options.onError || this.defaultErrorMessage.bind(this);
			var paramString = typeof(options.params) == 'undefined' ? '' : (options.method == 'get' ? '?'+options.params : options.params);
						
			if ( typeof(options.async) != 'undefined' && typeof(options.async) != 'boolean' ) {
				alert('Ajax_request: Error - async lust boolean');
				return;
			}
			else { var async = typeof(options.async) == 'undefined' || typeof(options.async) != 'boolean'? true : options.async; }									
			this.setProperties(method,successEnd,errorEnd,paramString,async);
		}								
		if ( typeof(url) != 'string' ) {
			alert('Ajax_request: Error - url undefined !');
			return;
		}
		else {this.properties.url = url;}						
		this.setReadyProcess();
		this.processRequest();
	},
	getObject: function() {
		// FF / OPERA / NETSCAPE
		if(window.XMLHttpRequest) {this.Ajax_object = new XMLHttpRequest();}
		// Internet Explorer
		else if (window.ActiveXObject) { 
			try {
				this.Ajax_object = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try { this.Ajax_object = new ActiveXObject("Microsoft.XMLHTTP"); } 
				catch (e1) { this.Ajax_object = null; }
			}
		}
		else  { this.Ajax_object = null; }
		// this.Ajax_object = null; // Force pas d'ajax sur le navigateur...
		this.properties = []; //new Array();
	},	
	setProperties: function() {
		this.properties = {
			method : arguments[0],
			successEnd : arguments[1],
			errorEnd : arguments[2],
			paramString : arguments[3],
			async : arguments[4]
		};
	},
	setReadyProcess: function() {
		this.Ajax_object.onreadystatechange = function() {
			if (this.Ajax_object.readyState == 4 ) {
				responseText = this.Ajax_object.responseText;				
				responseXML = this.Ajax_object.responseXML;
				this.responseText = this.Ajax_object.responseText;
				this.responseXML = this.Ajax_object.responseXML;
				if ( this.Ajax_object.status == 200 ) {this.properties.successEnd(this.Ajax_object);}
				else { this.properties.errorEnd(this.Ajax_object);}
				document.body.style.cursor = "default";
			}
		}.bind(this);
	},
	
	defaultErrorMessage: function(xhr)  {
		alert('Error ' + xhr.status + ' -- ' + xhr.statusText);
	},
	processRequest: function() {
		this.Ajax_object.open(
			this.properties.method,
			this.properties.method == 'post' ?
				this.properties.url : this.properties.url+this.properties.paramString,
			this.properties.async
		);
		if ( this.properties.method == 'post' )
			{ this.Ajax_object.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); }
		this.Ajax_object.send(this.properties.method == 'post' ? this.properties.paramString : null);
	}
};
Function.prototype.bind = function(object) {
	var __method = this;
	return function() {
		return __method.apply(object, arguments);
	};
};
// ***** Fin Ajax
function mycleanhtml(content){ 	
	if (content && content.length > 0) {
		content = content.replace(/<!--([\s\S]*?)-->|<style>[\s\S]*?<\/style>/g, "");  // Word comments
		content = content.replace(/<(meta|link)[^>]+>/g, ""); // Header elements
		content = content.replace(/<\\?\?xml[^>]*>/gi, ""); // xml
		content = content.replace(new RegExp('<(\\w[^>]*) style="([^"]*)"([^>]*)', 'gi'), "<$1$3"); // style attrib
		content = content.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3"); // class attrib
		content = content.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3");		
		content = content.replace(/<\/?span[^>]*>/gi, ""); // span
		content = content.replace(/<\/?font[^>]*>/gi, ""); // font
		content = content.replace(/<\/?div[^>]*>/gi, ""); // div
		content =  content.replace(/&nbsp;/g," ");		
		// Supprime tous les tags HTML
		content =  content.replace(/(<([^>]+)>)/ig,""); 
		content =  content.replace(/^\s+/, "").replace(/\s+$/, "");
	}	
	return content;
}
function fldErr(fld,alert_bgcolor,msg_error) {
	var fldwysiwyg = document.getElementById('wysiwyg'+fld.name);
	if ((fldwysiwyg !== undefined) && (fldwysiwyg  !== null)) 
		{ fldwysiwyg.contentWindow.document.body.style.backgroundColor = alert_bgcolor; }
	else 
		{ fld.style.backgroundColor = alert_bgcolor; }
	var fldmsg = document.getElementById(fld.name +'_amsg');
	if ((fldmsg !== undefined) && (fldmsg  !== null))
		{fldmsg.innerHTML ='&#136;'+msg_error;}						
}
function fldNoErr(alert_bgcolor,pass_bgcolor) {
	for (var i=0;i<document.forms[0].elements.length;i++) {	
		var champ = document.forms[0].elements[i];
		var fld_msg =document.getElementById(champ.name +'_amsg');
		if ((fld_msg !== undefined) && (fld_msg  !== null)) {
				fld_msg.innerHTML='';
				champ.style.backgroundColor = pass_bgcolor;
				var fld_span =document.getElementById(champ.name +'_span');
				if ((fld_span !== undefined) && (fld_span  !== null)) {fld_span.style.backgroundColor = "transparent";}
				var fldwysiwyg = document.getElementById('wysiwyg'+champ.name);
				if ((fldwysiwyg !== undefined) && (fldwysiwyg  !== null)) {fldwysiwyg.contentWindow.document.body.style.backgroundColor = pass_bgcolor;}
		}
	}
}
function helper(form_name, field_name){
	var formObj = document.getElementById(field_name+'_helper');
	if(formObj.style.visibility == 'visible'){
		formObj.style.visibility = 'hidden';
		formObj.style.display = 'none';
	}
	else{
		formObj.style.visibility = 'visible';
		formObj.style.display = 'block';
	}
}
function countChars(element,min_length,max_length,form_name,counter_name,field_label) {
	var checker_button = '';
	 if( element.value.length > max_length ) {
	 	 element.focus();
		 document.getElementById(counter_name).style.color = 'red';
	 }
	 else if( element.value.length < min_length ) {
	 	 element.focus();
		 document.getElementById(counter_name).style.color = 'red';
	 }
	 else
		 { document.getElementById(counter_name).style.color = '#333333'; } // can be remoevd if colors clash
	 document.getElementById(counter_name).innerHTML = element.value.length+checker_button;
}


function removeAccents(s){
    var r=s.toLowerCase();
    r = r.replace(new RegExp(/\s/g),"");
    r = r.replace(new RegExp(/[àáâãäå]/g),"a");
    r = r.replace(new RegExp(/æ/g),"ae");
    r = r.replace(new RegExp(/ç/g),"c");
    r = r.replace(new RegExp(/[èéêë]/g),"e");
    r = r.replace(new RegExp(/[ìíîï]/g),"i");
    r = r.replace(new RegExp(/ñ/g),"n");                
    r = r.replace(new RegExp(/[òóôõö]/g),"o");
    r = r.replace(new RegExp(/œ/g),"oe");
    r = r.replace(new RegExp(/[ùúûü]/g),"u");
    r = r.replace(new RegExp(/[ýÿ]/g),"y");
    r = r.replace(new RegExp(/\W/g),"");
    return r;
};


//retourne chaine de minuscule ou 0..9 sans espace ni autres caract�res
function cleandata(data) {	 
	if (data!=="") {
		var temp = removeAccents(data);	
		temp = temp.toLowerCase();
		var RegClean = /[^a-z0-9]/g; 
		temp= temp.replace(RegClean, "");
		temp = temp.replace(/33/g,"0");
		return temp;
	} else {return "";}
}
function check_noref(fldokref,alert_bgcolor,msg_error) {
	// return "";
	var ErrMsg = "";
	var ResMsg = "";
	var dicoRegEx = [ /(\.com|\.fr|\.org|\.net|\.be)\S*/,
	                  /(http|ftp|ftps|https)\S*/,
	                  /[0-9]{6,12}/,
	                  /[0-9]{2}[\-| |.|\\][0-9]{2}[\-| |.|\\][0-9]{2}[\-| |.|\\][0-9]{2}[\-| |.|\\][0-9]{2}|[+][0-9]{2}[\-| |.|\\][0-9]{2}[\-| |.|\\][0-9]{2}[\-| |.|\\][0-9]{2}[\-| |.|\\][0-9]{2}[\-| |.|\\][0-9]{2}/,
	                  /[a-z0-9._-]+@[a-z0-9._-]+[.][a-z]{2,3}/	                  		 	  
           		 ];
	for (var j=0;j<document.forms[0].elements.length;j++) {	
		   var champ = document.forms[0].elements[j];
		   var ch_name = champ.name;
		   if (undefined !== champ.ch_name) {
				   if (fldokref.indexOf(champ.name) == -1) {		   
					   if (champ.type !== 'hidden') {
						   if (undefined !== champ.value) {
							   var data = champ.value.toLowerCase();
							   var fldlabel = document.getElementById('lab_'+champ.name);			   
							   for (var i = 0; i < dicoRegEx.length; i++) {
								   var result = dicoRegEx[i].test(data);
								   if (result===true) {					
									   fldErr(champ,alert_bgcolor,msg_error);
										if ((undefined !== fldlabel) && (null !== fldlabel))
											{ ErrMsg = fldlabel.title+'\n';}
										ResMsg += '     - ' + ErrMsg;
										break;
								   } 
							   }
						   }
					   }
				   }
			   }
	}
	return ResMsg;
}
function check_dicoSuppAuto(fldprivate,dico_suppAuto) {
	var i, j;
	var temp = "";
	for (i=0;i<document.forms[0].elements.length;i++) {	
		   var champ = document.forms[0].elements[i];	
		   if (undefined !== champ) {
			   if (fldprivate.indexOf(champ.name) == -1) {
				   if (champ.type !== 'hidden') {
					   temp = champ.value;
					   if (undefined !== temp) {
						   for (j = 0; j < dico_suppAuto.length; j++) {
								if (temp.indexOf(dico_suppAuto[j]) != -1){
									var MonReg = new RegExp(dico_suppAuto[j], "i");
									temp = temp.replace(MonReg, "");
								}
							}
						   champ.value = temp;
				   		}
				   }
			   }
		   }
	}		
}

function check_anonymat(arrfldprivate, arrfldpublic,alert_bgcolor,msg_duplicate,msg_not_allowed) {
	var ResMsg = "";
	if ((arrfldprivate !== undefined) && (arrfldprivate.length >0)) { 
		for (var i=0; i < arrfldprivate.length; i++) {
			var fld_private = document.getElementById(arrfldprivate[i]);
			if (undefined !== fld_private) {
				var data_private = cleandata(fld_private.value);
				if (data_private!=="") {
					for (var j=0; j < arrfldpublic.length; j++) {
						var fld_public = document.getElementById(arrfldpublic[j]);
						if ((undefined !== fld_public) && (null !== fld_public)) {
							var data_public = cleandata(fld_public.value); 
							if (data_public.indexOf(data_private) != (-1)) {
								var ErrMsg = document.getElementById(arrfldprivate[i]).value + ' ' + msg_not_allowed + '\n';
								var fldlabel = document.getElementById('lab_'+fld_private.name);
								if ((undefined !== fldlabel) && (null !== fldlabel))
									{ErrMsg = msg_duplicate + ' '+ fldlabel.title.toLowerCase() + ' ' +ErrMsg;}
								fldErr(fld_public,alert_bgcolor,ErrMsg);
								fldlabel = document.getElementById('lab_'+fld_public.name);
								if (undefined !== fldlabel)
									{ErrMsg = fldlabel.title+'\n';}
								ResMsg += '     - ' + ErrMsg;
							}
						}				
					}				
				}
			}
		}
	}
	return ResMsg;
}
function check_repeat_char(alert_bgcolor,msg_error) {
	var ErrMsg = "";
	var ResMsg = "";	
	var repeatedCharacter = /([a-zA-Z0-9=\+<>\*\$%!;&:_])\1{5,}/;  
	for (var i=0;i<document.forms[0].elements.length;i++) {	
		   var champ = document.forms[0].elements[i];
		   if (champ.type !== 'hidden') {
			   var result = repeatedCharacter.test(champ.value);
			   if (result===true) {
				   fldErr(champ,alert_bgcolor,msg_error);
				   var fldlabel = document.getElementById('lab_'+champ.name);
					if (undefined !== fldlabel)
						{ErrMsg = fldlabel.title+'\n';}
					ResMsg += '     - ' + ErrMsg;			   
			   }
		   }
	}
	return ResMsg;
}
function check_repeat_charseq(alert_bgcolor,msg_error) {
	var ErrMsg = "";
	var ResMsg = "";		
	var repeatedCharacter = /([0-9a-zA-Z!"#$%'()*+,-./:?@[\\\]_`{|}~]{2,20}.{1})\1{2,}/;  
	for (var i=0;i<document.forms[0].elements.length;i++) {	
		   var champ = document.forms[0].elements[i];
		   var result = repeatedCharacter.test(mycleanhtml(champ.value)+' ');
		   if (result===true) {
			   fldErr(champ,alert_bgcolor,msg_error);
			   var fldlabel = document.getElementById('lab_'+champ.name);
				if (undefined !== fldlabel)
					{ErrMsg = fldlabel.title+'\n';}
				ResMsg += '     - ' + ErrMsg;			   
		   }
	}
	return ResMsg;
}
function add_lang(fld_name,fld_idx, fld_max) {
	// Ajout bt remove l+
	var fld_idx_open = fld_idx + 1;
	var fObj = document.getElementById('del_'+fld_name+'_'+fld_idx_open);
	fObj.style.visibility = 'visible';
	fObj.style.display = 'inline';
	// Show l+1
	var formObj = document.getElementById('line_'+fld_name+'_'+fld_idx_open);
	formObj.style.visibility = 'visible';
	formObj.style.display = 'block';
	// Supprime les bouttons remove et add l 
	if (fld_idx>1) {
		fObj = document.getElementById('del_'+fld_name+'_'+fld_idx);
		fObj.style.visibility = 'hidden';
		fObj.style.display = 'none';
	}	
	fObj = document.getElementById('add_'+fld_name+'_'+fld_idx);
	fObj.style.visibility = 'hidden';
	fObj.style.display = 'none';
}
function remove_lang(fld_name,fld_idx, fld_max) {
	// Ajout le boutton remove et add l-1
	var fld_idx_shw = fld_idx - 1;
	if (fld_idx_shw>1) {
		var fObj = document.getElementById('del_'+fld_name+'_'+fld_idx_shw);
		fObj.style.visibility = 'visible';
		fObj.style.display = 'inline';
	}
	if (fld_idx_shw>0) {
		fObj = document.getElementById('add_'+fld_name+'_'+fld_idx_shw);
		fObj.style.visibility = 'visible';
		fObj.style.display = 'inline';
	}
	// Remove l
	if (fld_idx>1) {
		var formObj = document.getElementById('line_'+fld_name+'_'+fld_idx);
		formObj.style.visibility = 'hidden';
		formObj.style.display = 'none';
	}	
}	
// Debut Calendar
var weekStartsOnSunday = true;  // true = Start the week on Sunday, false = start the week on Monday
var pathToImages = '../__/calendar/';	// Relative to your HTML file
var calendarDiv = false;
var MSIE = false;
var Opera = false;
if(navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('Opera')<0) {MSIE=true;}
if(navigator.userAgent.indexOf('Opera')>=0) {Opera=true;}
var todayString = "Aujourd'hui";
var daysInMonthArray = [31,28,31,30,31,30,31,31,30,31,30,31];
var currentMonth;
var currentYear;
var calendarContentDiv;
var returnDateTo;
var returnFormat;
var activeSelectBoxMonth;
var activeSelectBoxYear;
var iframeObj = false;
//// fix for EI frame problem on time dropdowns 09/30/2006
var iframeObj2 =false;
function getleftPos(inputObj)
{
  var returnValue = inputObj.offsetLeft;
  while((inputObj = inputObj.offsetParent) !== null) {returnValue += inputObj.offsetLeft;}
  return returnValue;
}
function EIS_FIX_EI1(where2fixit)
{
		if(!iframeObj2) {return;}
		iframeObj2.style.display = 'block';
		iframeObj2.style.height =document.getElementById(where2fixit).offsetHeight+1;
		iframeObj2.style.width=document.getElementById(where2fixit).offsetWidth;
		iframeObj2.style.left=getleftPos(document.getElementById(where2fixit))+1;
		iframeObj2.style.top=getTopPos(document.getElementById(where2fixit))-document.getElementById(where2fixit).offsetHeight;
}

function EIS_Hide_Frame(){if(iframeObj2) {iframeObj2.style.display = 'none';}}
// fix for EI frame problem on time dropdowns 09/30/2006
var returnDateToYear;
var returnDateToMonth;
var returnDateToDay;
var inputYear;
var inputMonth;
var inputDay;
var selectBoxHighlightColor = '#D60808'; // Highlight color of select boxes
var selectBoxRolloverBgColor = '#E2EBED'; // Background color on drop down lists(rollover)
var selectBoxMovementInProgress = false;
var activeSelectBox = false;
//var activeSelectBoxMonth = false;
var activeSelectBoxDirection = false;

function cancelCalendarEvent(){ return false;}
function isLeapYear(inputYear){	if(inputYear%400===0||(inputYear%4===0&&inputYear%100!==0)) {return true;} 	return false;}
function highlightMonthYear()
{
	if(activeSelectBoxMonth){activeSelectBoxMonth.className='';}
	activeSelectBox = this;
	if(this.className=='monthYearActive'){
		this.className='';
	}else{
		this.className = 'monthYearActive';
		activeSelectBoxMonth = this;
	}
	if(this.innerHTML.indexOf('-')>=0 || this.innerHTML.indexOf('+')>=0){
		if(this.className=='monthYearActive')
			{ selectBoxMovementInProgress = true; }
		else
			{ selectBoxMovementInProgress = false; }
		if(this.innerHTML.indexOf('-')>=0) { activeSelectBoxDirection = -1;} else {activeSelectBoxDirection = 1;}
	}else {selectBoxMovementInProgress = false;}
}
function showMonthDropDown()
{
	if(document.getElementById('monthDropDown').style.display=='block'){
		document.getElementById('monthDropDown').style.display='none';
		//// fix for EI frame problem on time dropdowns 09/30/2006
		EIS_Hide_Frame();
	}else{
		document.getElementById('monthDropDown').style.display='block';
		document.getElementById('yearDropDown').style.display='none';
		if (MSIE) { EIS_FIX_EI1('monthDropDown');}
		// fix for EI frame problem on time dropdowns 09/30/2006
	}
}
function showYearDropDown()
{
	if(document.getElementById('yearDropDown').style.display=='block'){
		document.getElementById('yearDropDown').style.display='none';
		// fix for EI frame problem on time dropdowns 09/30/2006
		EIS_Hide_Frame();
	}else{
		document.getElementById('yearDropDown').style.display='block';
		document.getElementById('monthDropDown').style.display='none';
		if (MSIE) { EIS_FIX_EI1('yearDropDown');}
		// fix for EI frame problem on time dropdowns 09/30/2006
	}
}
function selectMonth()
{
	document.getElementById('calendar_month_txt').innerHTML = this.innerHTML;
	currentMonth = this.id.replace(/[^\d]/g,'');
	document.getElementById('monthDropDown').style.display='none';
	// fix for EI frame problem on time dropdowns 09/30/2006
	EIS_Hide_Frame();
	for(var no=0;no<monthArray.length;no++){
		document.getElementById('monthDiv_'+no).style.color='';
	}
	this.style.color = selectBoxHighlightColor;
	activeSelectBoxMonth = this;
	writeCalendarContent();
}
function selectYear()
{
	document.getElementById('calendar_year_txt').innerHTML = this.innerHTML;
	currentYear = this.innerHTML.replace(/[^\d]/g,'');
	document.getElementById('yearDropDown').style.display='none';
	// fix for EI frame problem on time dropdowns 09/30/2006
	EIS_Hide_Frame();
	if(activeSelectBoxYear){
		activeSelectBoxYear.style.color='';
	}
	activeSelectBoxYear=this;
	this.style.color = selectBoxHighlightColor;
	writeCalendarContent();
}
function switchMonth()
{
	if(this.src.indexOf('left')>=0){
		currentMonth=currentMonth-1;
		if(currentMonth<0){
			currentMonth=11;
			currentYear=currentYear-1;
		}
	}else{
		currentMonth=currentMonth+1;
		if(currentMonth>11){
			currentMonth=0;
			currentYear=currentYear/1+1;
		}
	}
	writeCalendarContent();
}
function createMonthDiv(){
	var div = document.createElement('DIV');
	div.className='monthYearPicker';
	div.id = 'monthPicker';
	for(var no=0;no<monthArray.length;no++){
		var subDiv = document.createElement('DIV');
		subDiv.innerHTML = monthArray[no];
		subDiv.onmouseover = highlightMonthYear;
		subDiv.onmouseout = highlightMonthYear;
		subDiv.onclick = selectMonth;
		subDiv.id = 'monthDiv_' + no;
		subDiv.style.width = '56px';
		subDiv.onselectstart = cancelCalendarEvent;
		div.appendChild(subDiv);
		if(currentMonth && currentMonth==no){
			subDiv.style.color = selectBoxHighlightColor;
			activeSelectBoxMonth = subDiv;
		}
	}
	return div;
}
function changeSelectBoxYear(e,inputObj)
{
	if(!inputObj) {inputObj =this;}
	var startYear;
	var yearItems = inputObj.parentNode.getElementsByTagName('DIV');
	if(inputObj.innerHTML.indexOf('-')>=0){
		startYear = yearItems[1].innerHTML/1 -1;
		if(activeSelectBoxYear){
			activeSelectBoxYear.style.color='';
		}
	}else{
		startYear = yearItems[1].innerHTML/1 +1;
		if(activeSelectBoxYear){
			activeSelectBoxYear.style.color='';
		}
	}
	for(var no=1;no<yearItems.length-1;no++){
		yearItems[no].innerHTML = startYear+no-1;
		yearItems[no].id = 'yearDiv' + (startYear/1+no/1-1);
	}
	if(activeSelectBoxYear){
		activeSelectBoxYear.style.color='';
		if(document.getElementById('yearDiv'+currentYear)){
			activeSelectBoxYear = document.getElementById('yearDiv'+currentYear);
			activeSelectBoxYear.style.color=selectBoxHighlightColor;
		}
	}
}
function updateYearDiv()
{
    var yearSpan = 5;
	var div = document.getElementById('yearDropDown');
	var yearItems = div.getElementsByTagName('DIV');
	for(var no=1;no<yearItems.length-1;no++){
		yearItems[no].innerHTML = currentYear/1 -yearSpan + no;
		if(currentYear==(currentYear/1 -yearSpan + no)){
			yearItems[no].style.color = selectBoxHighlightColor;
			activeSelectBoxYear = yearItems[no];
		}else{
			yearItems[no].style.color = '';
		}
	}
}
function updateMonthDiv()
{
	for(var no=0;no<12;no++){
		document.getElementById('monthDiv_' + no).style.color = '';
	}
	document.getElementById('monthDiv_' + currentMonth).style.color = selectBoxHighlightColor;
	activeSelectBoxMonth = 	document.getElementById('monthDiv_' + currentMonth);
}
function createYearDiv()
{
	var div;
	if(!document.getElementById('yearDropDown')){
		div = document.createElement('DIV');
		div.className='monthYearPicker';
	}else{
		div = document.getElementById('yearDropDown');
		var subDivs = div.getElementsByTagName('DIV');
		for(var noz=0;noz<subDivs.length;noz++){
			subDivs[noz].parentNode.removeChild(subDivs[noz]);
		}
	}
	var d = new Date();
	if(currentYear){
		d.setFullYear(currentYear);
	}
	var startYear = d.getFullYear()/1 - 5;
    var yearSpan = 10;
	var subDiv = document.createElement('DIV');
	subDiv.innerHTML = '&nbsp;&nbsp;- ';
	subDiv.onclick = changeSelectBoxYear;
	subDiv.onmouseover = highlightMonthYear;
	subDiv.onmouseout = function(){ selectBoxMovementInProgress = false;};
	subDiv.onselectstart = cancelCalendarEvent;
	div.appendChild(subDiv);
	for(var no=startYear;no<(startYear+yearSpan);no++){
		subDiv = document.createElement('DIV');
		subDiv.innerHTML = no;
		subDiv.onmouseover = highlightMonthYear;
		subDiv.onmouseout = highlightMonthYear;
		subDiv.onclick = selectYear;
		subDiv.id = 'yearDiv' + no;
		subDiv.onselectstart = cancelCalendarEvent;
		div.appendChild(subDiv);
		if(currentYear && currentYear==no){
			subDiv.style.color = selectBoxHighlightColor;
			activeSelectBoxYear = subDiv;
		}
	}
	subDiv = document.createElement('DIV');
	subDiv.innerHTML = '&nbsp;&nbsp;+ ';
	subDiv.onclick = changeSelectBoxYear;
	subDiv.onmouseover = highlightMonthYear;
	subDiv.onmouseout = function(){ selectBoxMovementInProgress = false;};
	subDiv.onselectstart = cancelCalendarEvent;
	div.appendChild(subDiv);
	return div;
}
function slideCalendarSelectBox()
{
	if(selectBoxMovementInProgress){
		if(activeSelectBox.parentNode.id=='yearDropDown'){
			changeSelectBoxYear(false,activeSelectBox);
		}
	}
	setTimeout('slideCalendarSelectBox()',100); // 100=rapide, 200=lent
}
function highlightSelect()
{
	if(this.className=='selectBox'){
		this.className = 'selectBoxOver';
		this.getElementsByTagName('IMG')[0].src = pathToImages + 'down_over.gif';
	}else if(this.className=='selectBoxOver'){
		this.className = 'selectBox';
		this.getElementsByTagName('IMG')[0].src = pathToImages + 'down.gif';
	}
}
function highlightArrow()
{
	if(this.src.indexOf('over')>=0){
		if(this.src.indexOf('left')>=0) {this.src = pathToImages + 'left.gif';}
		if(this.src.indexOf('right')>=0) {this.src = pathToImages + 'right.gif';}
	}else{
		if(this.src.indexOf('left')>=0) {this.src = pathToImages + 'left_over.gif';}
		if(this.src.indexOf('right')>=0) {this.src = pathToImages + 'right_over.gif';}
	}
}
function highlightClose(){if(this.src.indexOf('over')>=0){this.src = pathToImages + 'close.gif';}else{ this.src = pathToImages + 'close_over.gif';} }
function closeCalendar(){
	document.getElementById('yearDropDown').style.display='none';
	document.getElementById('monthDropDown').style.display='none';
	calendarDiv.style.display='none';
	if(iframeObj){
		iframeObj.style.display='none';
		 // fix for EI frame problem on time dropdowns 09/30/2006
		EIS_Hide_Frame();}
	if(activeSelectBoxMonth) {activeSelectBoxMonth.className='';}
	if(activeSelectBoxYear) {activeSelectBoxYear.className='';}
}
function writeTopBar()
{
	var topBar = document.createElement('DIV');
	topBar.className = 'topBar';
	topBar.id = 'topBar';
	calendarDiv.appendChild(topBar);
	// Left arrow
	var leftDiv = document.createElement('DIV');
	leftDiv.style.marginRight = '1px';
	var img = document.createElement('IMG');
	img.src = pathToImages + 'left.gif';
	img.onmouseover = highlightArrow;
	img.onclick = switchMonth;
	img.onmouseout = highlightArrow;
	leftDiv.appendChild(img);
	topBar.appendChild(leftDiv);
	if(Opera) {leftDiv.style.width = '16px';}
	// Right arrow
	var rightDiv = document.createElement('DIV');
	rightDiv.style.marginRight = '1px';
	img = document.createElement('IMG');
	img.src = pathToImages + 'right.gif';
	img.onclick = switchMonth;
	img.onmouseover = highlightArrow;
	img.onmouseout = highlightArrow;
	rightDiv.appendChild(img);
	if(Opera) {rightDiv.style.width = '16px';}
	topBar.appendChild(rightDiv);
	// Month selector
	var monthDiv = document.createElement('DIV');
	monthDiv.id = 'monthSelect';
	monthDiv.onmouseover = highlightSelect;
	monthDiv.onmouseout = highlightSelect;
	monthDiv.onclick = showMonthDropDown;
	var span = document.createElement('SPAN');
	span.innerHTML = monthArray[currentMonth];
	span.id = 'calendar_month_txt';
	monthDiv.appendChild(span);
	img = document.createElement('IMG');
	img.src = pathToImages + 'down.gif';
	img.style.position = 'absolute';
	img.style.right = '0px';
	monthDiv.appendChild(img);
	monthDiv.className = 'selectBox';
	if(Opera){
		img.style.cssText = 'float:right;position:relative';
		img.style.position = 'relative';
		img.style.styleFloat = 'right';
	}
	topBar.appendChild(monthDiv);
	var monthPicker = createMonthDiv();
	monthPicker.style.left = '37px';
	monthPicker.style.top = monthDiv.offsetTop + monthDiv.offsetHeight + 1 + 'px';
	monthPicker.style.width ='60px';
	monthPicker.id = 'monthDropDown';
	calendarDiv.appendChild(monthPicker);
	// Year selector
	var yearDiv = document.createElement('DIV');
	yearDiv.onmouseover = highlightSelect;
	yearDiv.onmouseout = highlightSelect;
	yearDiv.onclick = showYearDropDown;
	span = document.createElement('SPAN');
	span.innerHTML = currentYear;
	span.id = 'calendar_year_txt';
	yearDiv.appendChild(span);
	topBar.appendChild(yearDiv);
	img = document.createElement('IMG');
	img.src = pathToImages + 'down.gif';
	yearDiv.appendChild(img);
	yearDiv.className = 'selectBox';
	if(Opera){
		yearDiv.style.width = '50px';
		img.style.cssText = 'float:right';
		img.style.position = 'relative';
		img.style.styleFloat = 'right';
	}
	var yearPicker = createYearDiv();
	yearPicker.style.left = '113px';
	yearPicker.style.top = monthDiv.offsetTop + monthDiv.offsetHeight + 1 + 'px';
	yearPicker.style.width = '35px';
	yearPicker.id = 'yearDropDown';
	calendarDiv.appendChild(yearPicker);
	img = document.createElement('IMG');
	img.src = pathToImages + 'close.gif';
	img.style.styleFloat = 'right';
	img.onmouseover = highlightClose;
	img.onmouseout = highlightClose;
	img.onclick = closeCalendar;
	topBar.appendChild(img);
	if(!document.all){
		img.style.position = 'absolute';
		img.style.right = '2px';
	}
}
function writeCalendarContent()
{
	var calendarContentDivExists = true;
	if(!calendarContentDiv){
		calendarContentDiv = document.createElement('DIV');
		calendarDiv.appendChild(calendarContentDiv);
		calendarContentDivExists = false;
	}
	currentMonth = currentMonth/1;
	var d = new Date();

	d.setFullYear(currentYear);
	d.setDate(1);
	d.setMonth(currentMonth);

	var dayStartOfMonth = d.getDay();
	document.getElementById('calendar_year_txt').innerHTML = currentYear;
	document.getElementById('calendar_month_txt').innerHTML = monthArray[currentMonth];
	var existingTable = calendarContentDiv.getElementsByTagName('TABLE');
	if(existingTable.length>0){
		calendarContentDiv.removeChild(existingTable[0]);
	}
	var calTable = document.createElement('TABLE');
	calTable.width = '100%';
	calTable.cellSpacing = '0';
	calendarContentDiv.appendChild(calTable);
	var calTBody = document.createElement('TBODY');
	calTable.appendChild(calTBody);
	var row = calTBody.insertRow(-1);
	row.className = 'calendar_week_row';
	var cell;
	for(var no=0;no<dayArray.length;no++){
		cell = row.insertCell(-1);
		cell.innerHTML = dayArray[no];
	}
	row = calTBody.insertRow(-1);   
	for(no=0;no<dayStartOfMonth;no++){
		cell = row.insertCell(-1);
		cell.innerHTML = '&nbsp;';
	}
	var colCounter = dayStartOfMonth;
	var daysInMonth = daysInMonthArray[currentMonth];
	if(daysInMonth==28){
		if(isLeapYear(currentYear)) {daysInMonth=29;}
	}
	for(no=1;no<=daysInMonth;no++){
		d.setDate(no-1);
		if(colCounter>0 && colCounter%7===0){
			row = calTBody.insertRow(-1);
		}
		cell = row.insertCell(-1);
		if(currentYear==inputYear && currentMonth == inputMonth && no==inputDay){
			cell.className='activeDay';
		}
		cell.innerHTML = no;
		cell.onclick = pickDate;
		colCounter++;
	}
	if(!document.all){
		if(calendarContentDiv.offsetHeight)
			{ document.getElementById('topBar').style.top = calendarContentDiv.offsetHeight +  document.getElementById('topBar').offsetHeight -1 + 'px'; }
		else{
			document.getElementById('topBar').style.top = '';
			document.getElementById('topBar').style.bottom = '0px';
		}
	}
	if(iframeObj){
		if(!calendarContentDivExists)
			 {setTimeout('resizeIframe()',350);}
		else {setTimeout('resizeIframe()',10);}
	}
}
function resizeIframe()
{
	iframeObj.style.width = calendarDiv.offsetWidth + 'px';
	iframeObj.style.height = calendarDiv.offsetHeight + 'px';
}
function pickDate(e,inputDay)
{
	var month = currentMonth/1 +1;
	if(month<10) {month = '0' + month;}
	var day;
	if(!inputDay && this) {day = this.innerHTML;} else {day = inputDay;}
	if(day/1<10) {day = '0' + day;}
	if(returnFormat){
		returnFormat = returnFormat.replace('dd',day);
		returnFormat = returnFormat.replace('mm',month);
		returnFormat = returnFormat.replace('yyyy',currentYear);
		returnFormat = returnFormat.replace('d',day/1);
		returnFormat = returnFormat.replace('m',month/1);
		returnDateTo.value = returnFormat;
		try{
			returnDateTo.onchange();
		}catch(e){

		}
	}else{
		var no=0;
		for(no=0;no<returnDateToYear.options.length;no++){
			if(returnDateToYear.options[no].value==currentYear){
				returnDateToYear.selectedIndex=no;
				break;
			}
		}
		for(no=0;no<returnDateToMonth.options.length;no++){
			if(returnDateToMonth.options[no].value==parseInt(month)){
				returnDateToMonth.selectedIndex=no;
				break;
			}
		}
		for(no=0;no<returnDateToDay.options.length;no++){
			if(returnDateToDay.options[no].value==parseInt(day)){
				returnDateToDay.selectedIndex=no;
				break;
			}
		}
	}
	closeCalendar();
}
function pickTodaysDate()
{
	var d = new Date();
	currentMonth = d.getMonth();
	currentYear = d.getFullYear();
	pickDate(false,d.getDate());
}

function getWeek(year,month,day){
    day = (day/1)+1;
	year = year /1;
    month = month/1 + 1; //use 1-12
    var a = Math.floor((14-(month))/12);
    var y = year+4800-a;
    var m = (month)+(12*a)-3;
    var jd = day + Math.floor(((153*m)+2)/5) +
                 (365*y) + Math.floor(y/4) - Math.floor(y/100) +
                 Math.floor(y/400) - 32045;      // (gregorian calendar)
    var d4 = (jd+31741-(jd%7))%146097%36524%1461;
    var L = Math.floor(d4/1460);
    var d1 = ((d4-L)%365)+L;
    return  Math.floor(d1/7) + 1;
}
function writeBottomBar()
{
	var d = new Date();
	var bottomBar = document.createElement('DIV');
	bottomBar.id = 'bottomBar';
	bottomBar.style.cursor = 'pointer';
	bottomBar.className = 'todaysDate';
	var subDiv = document.createElement('DIV');
	subDiv.onclick = pickTodaysDate;
	subDiv.id = 'todaysDateString';
	var day = d.getDay();
	subDiv.innerHTML = todayString+' '+dayArray[day]+' '+d.getDate()+' '+monthArrayShort[d.getMonth()]+' '+d.getFullYear();
	bottomBar.appendChild(subDiv);
	calendarDiv.appendChild(bottomBar);
}
function getTopPos(inputObj)
{
  var returnValue = inputObj.offsetTop + inputObj.offsetHeight;
  while((inputObj = inputObj.offsetParent) != null) {returnValue += inputObj.offsetTop;}
  return returnValue;
}
function positionCalendar(inputObj)
{
	calendarDiv.style.left = getleftPos(inputObj) + 'px';
	calendarDiv.style.top = getTopPos(inputObj) + 'px';
	if(iframeObj){
		iframeObj.style.left = calendarDiv.style.left;
		iframeObj.style.top =  calendarDiv.style.top;
		//// fix for EI frame problem on time dropdowns 09/30/2006
		iframeObj2.style.left = calendarDiv.style.left;
		iframeObj2.style.top =  calendarDiv.style.top;
	}
}
function initCalendar()
{
	if(MSIE){
		iframeObj = document.createElement('IFRAME');
		iframeObj.style.filter = 'alpha(opacity=0)';
		iframeObj.style.position = 'absolute';
		iframeObj.border='0px';
		iframeObj.style.border = '0px';
		iframeObj.style.backgroundColor = '#FF0000';
		// fix for EI frame problem on time dropdowns 09/30/2006
		iframeObj2 = document.createElement('IFRAME');
		iframeObj2.style.position = 'absolute';
		iframeObj2.border='0px';
		iframeObj2.style.border = '0px';
		iframeObj2.style.height = '1px';
		iframeObj2.style.width = '1px';
		// fix for EI frame problem on time dropdowns 09/30/2006
		// Added fixed for HTTPS
		iframeObj2.src = 'blank.html';
		iframeObj.src = 'blank.html';
		document.body.appendChild(iframeObj2);  // gfb move this down AFTER the .src is set
		document.body.appendChild(iframeObj);
	}
	calendarDiv = document.createElement('DIV');
	calendarDiv.id = 'calendarDiv';
	calendarDiv.style.zIndex = 1000;
	slideCalendarSelectBox();
	document.body.appendChild(calendarDiv);
	writeBottomBar();
	writeTopBar();
	if(!currentYear){
		var d = new Date();
		currentMonth = d.getMonth();
		currentYear = d.getFullYear();
	}
	writeCalendarContent();
}
function calendarSortItems(a,b){ return a/1 - b/1;}
function displayCalendar(inputField,format,buttonObj)
{
	if(inputField.value.length>6){ //dates must have at least 6 digits...		
       if(!inputField.value.match(/^[0-9]*?$/gi)){       	
			var items = inputField.value.split(/[^0-9]/gi);
			var positionArray = {m:0, d:0, y:0, h:0, i:0}; // new Object();
			positionArray.m = format.indexOf('mm');
			if(positionArray.m==-1) {positionArray.m = format.indexOf('m');}
			positionArray.d = format.indexOf('dd');
			if(positionArray.d==-1) {positionArray.d = format.indexOf('d');}
			positionArray.y = format.indexOf('yyyy');			
			positionArray.h = format.indexOf('hh');
			positionArray.i = format.indexOf('ii');
			var elements = ['y','m','d'];
			var properties = ['currentYear','currentMonth','inputDay'];
			var propertyLength = [4,2,2];			
			for(var i=0;i<elements.length;i++) {
				if(positionArray[elements[i]]>=0) {
					window[properties[i]] = inputField.value.substr(positionArray[elements[i]],propertyLength[i])/1;
				}					
			}			
			currentMonth--;
		}else{
			var monthPos = format.indexOf('mm');
			currentMonth = inputField.value.substr(monthPos,2)/1 -1;
			var yearPos = format.indexOf('yyyy');
			currentYear = inputField.value.substr(yearPos,4);
			var dayPos = format.indexOf('dd');
			tmpDay = inputField.value.substr(dayPos,2);
		}
	}else{
		var d = new Date();
		currentMonth = d.getMonth();
		currentYear = d.getFullYear();
		inputDay = d.getDate()/1;
	}
	inputYear = currentYear;
	inputMonth = currentMonth;
	if(!calendarDiv){
		initCalendar();
	}else{
		if(calendarDiv.style.display=='block'){
			closeCalendar();
			return false;
		}
		writeCalendarContent();
	}
	returnFormat = format;
	returnDateTo = inputField;
	positionCalendar(buttonObj);
	calendarDiv.style.visibility = 'visible';
	calendarDiv.style.display = 'block';
	if(iframeObj){
		iframeObj.style.display = '';
		iframeObj.style.height = '140px';
		iframeObj.style.width = '195px';
		iframeObj2.style.display = '';
		iframeObj2.style.height = '140px';
		iframeObj2.style.width = '195px';
	}
	document.getElementById('todaysDateString').style.width = '100%';	
	updateYearDiv();
	updateMonthDiv();
	return true;
}

//global variables //
var TIMER = 5;
var SPEED = 10;
var WRAPPER = 'content';

// calculate the current window width //
function pageWidth() {
  return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

// calculate the current window height //
function pageHeight() {
  return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

// calculate the current window vertical offset //
function topPosition() {
  return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

// calculate the position starting at the left of the window //
function leftPosition() {
  return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}

// build/show the dialog box, populate the data and call the fadeDialog function //
function showDialog(title,message,type,autohide) {
  if(!type) {
    type = 'error';
  }
  var dialog;
  var dialogheader;
  var dialogclose;
  var dialogtitle;
  var dialogcontent;
  var dialogmask;
  if(!document.getElementById('dialog')) {
    dialog = document.createElement('div');
    dialog.id = 'dialog';
    dialogheader = document.createElement('div');
    dialogheader.id = 'dialog-header';
    dialogtitle = document.createElement('div');
    dialogtitle.id = 'dialog-title';
    dialogclose = document.createElement('div');
    dialogclose.id = 'dialog-close'
    dialogcontent = document.createElement('div');
    dialogcontent.id = 'dialog-content';
    dialogmask = document.createElement('div');
    dialogmask.id = 'dialog-mask';
    document.body.appendChild(dialogmask);
    document.body.appendChild(dialog);
    dialog.appendChild(dialogheader);
    dialogheader.appendChild(dialogtitle);
    dialogheader.appendChild(dialogclose);
    dialog.appendChild(dialogcontent);;
    dialogclose.setAttribute('onclick','hideDialog()');
    dialogclose.onclick = hideDialog;
  } else {
    dialog = document.getElementById('dialog');
    dialogheader = document.getElementById('dialog-header');
    dialogtitle = document.getElementById('dialog-title');
    dialogclose = document.getElementById('dialog-close');
    dialogcontent = document.getElementById('dialog-content');
    dialogmask = document.getElementById('dialog-mask');
    dialogmask.style.visibility = "visible";
    dialog.style.visibility = "visible";
  }
  dialog.style.opacity = .00;
  dialog.style.filter = 'alpha(opacity=0)';
  dialog.alpha = 0;
  var width = pageWidth();
  var height = pageHeight();
  var left = leftPosition();
  var top = topPosition();
  var dialogwidth = dialog.offsetWidth;
  var dialogheight = dialog.offsetHeight;
  var topposition = top + (height / 3) - (dialogheight / 2);
  var leftposition = left + (width / 2) - (dialogwidth / 2);
  dialog.style.top = topposition + "px";
  dialog.style.left = leftposition + "px";
  dialogheader.className = type + "header";
  dialogtitle.innerHTML = title;
  dialogcontent.className = type;
  dialogcontent.innerHTML = message;
  var content = document.getElementById(WRAPPER);
  dialogmask.style.height = content.offsetHeight + 'px';
  dialog.timer = setInterval("fadeDialog(1)", TIMER);
  if(autohide) {
    dialogclose.style.visibility = "hidden";
    window.setTimeout("hideDialog()", (autohide * 1000));
  } else {
    dialogclose.style.visibility = "visible";
  }
}

// hide the dialog box //
function hideDialog() {
  var dialog = document.getElementById('dialog');
  clearInterval(dialog.timer);
  dialog.timer = setInterval("fadeDialog(0)", TIMER);
}

// fade-in the dialog box //
function fadeDialog(flag) {
  if(flag == null) {
    flag = 1;
  }
  var dialog = document.getElementById('dialog');
  var value;
  if(flag == 1) {
    value = dialog.alpha + SPEED;
  } else {
    value = dialog.alpha - SPEED;
  }
  dialog.alpha = value;
  dialog.style.opacity = (value / 100);
  dialog.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(dialog.timer);
    dialog.timer = null;
  } else if(value <= 1) {
    dialog.style.visibility = "hidden";
    document.getElementById('dialog-mask').style.visibility = "hidden";
    clearInterval(dialog.timer);
  }
}
// Images Directory
var imagesDir = "../__/wysiwyg_icons/";
var Fonts = ["Arial", "Sans Serif", "Tahoma", "Verdana", "Courier New", "Georgia", "Times New Roman", "Impact", "Comic Sans MS"];
var FontSizes = ["1", "2", "3", "4", "5", "6", "7"];
var buttonName = ["bold", "italic", "underline", "seperator", "subscript", "superscript"];
var buttonName2 = ["justifyleft","justifycenter","justifyright","seperator","unorderedlist","orderedlist","outdent","indent"]; 
var ToolbarList = {
  "bold":           ['Bold',                 'Bold',               imagesDir + 'bold.gif',               imagesDir + 'bold_on.gif'],
  "italic":         ['Italic',               'Italic',             imagesDir + 'italics.gif',            imagesDir + 'italics_on.gif'],
  "underline":      ['Underline',            'Underline',          imagesDir + 'underline.gif',          imagesDir + 'underline_on.gif'],
  "seperator":      ['',                     '',                   imagesDir + 'seperator.gif',          imagesDir + 'seperator.gif'],
  "subscript":      ['Subscript',            'Subscript',          imagesDir + 'subscript.gif',          imagesDir + 'subscript_on.gif'],
  "superscript":    ['Superscript',          'Superscript',        imagesDir + 'superscript.gif',        imagesDir + 'superscript_on.gif'],
  "justifyleft":    ['Justifyleft',          'Justifyleft',        imagesDir + 'justify_left.gif',       imagesDir + 'justify_left_on.gif'],
  "justifycenter":  ['Justifycenter',        'Justifycenter',      imagesDir + 'justify_center.gif',     imagesDir + 'justify_center_on.gif'],
  "justifyright":   ['Justifyright',         'Justifyright',       imagesDir + 'justify_right.gif',      imagesDir + 'justify_right_on.gif'],
  "unorderedlist":  ['InsertUnorderedList',  'InsertUnorderedList',imagesDir + 'list_unordered.gif',     imagesDir + 'list_unordered_on.gif'],
  "orderedlist":    ['InsertOrderedList',    'InsertOrderedList',  imagesDir + 'list_ordered.gif',       imagesDir + 'list_ordered_on.gif'],
  "outdent":        ['Outdent',              'Outdent',            imagesDir + 'indent_left.gif',        imagesDir + 'indent_left_on.gif'],
  "indent":         ['Indent',               'Indent',             imagesDir + 'indent_right.gif',       imagesDir + 'indent_right_on.gif'],
  "cut":            ['Cut',                  'Cut',                imagesDir + 'cut.gif',                imagesDir + 'cut_on.gif'],
  "copy":           ['Copy',                 'Copy',               imagesDir + 'copy.gif',               imagesDir + 'copy_on.gif'],
  "paste":          ['Paste',                'Paste',              imagesDir + 'paste.gif',              imagesDir + 'paste_on.gif'],
  "undo":           ['Undo',                 'Undo',               imagesDir + 'undo.gif',               imagesDir + 'undo_on.gif'],
  "redo":           ['Redo',                 'Redo',               imagesDir + 'redo.gif',               imagesDir + 'redo_on.gif'],
  "viewSource":     ['ViewSource',           'ViewSource',         imagesDir + 'view_source.gif',        imagesDir + 'view_source_on.gif'],
  "viewText":       ['ViewText',             'ViewText',           imagesDir + 'view_text.gif',          imagesDir + 'view_text_on.gif'],
  "selectfont":     ['SelectFont',           'SelectFont',         imagesDir + 'select_font.gif',        imagesDir + 'select_font_on.gif'],
  "selectsize":     ['SelectSize',           'SelectSize',         imagesDir + 'select_size.gif',        imagesDir + 'select_size_on.gif']
};

var viewTextMode = 0;
if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement){
  HTMLElement.prototype.insertAdjacentElement = function  (where,parsedNode)
  {
	  switch (where){
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode,this);
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling) 
				 {this.parentNode.insertBefore(parsedNode,this.nextSibling);}
			else {this.parentNode.appendChild(parsedNode);}
			break;
		}
  };
  HTMLElement.prototype.insertAdjacentHTML = function (where,htmlStr)
  {
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML);
  };
  HTMLElement.prototype.insertAdjacentText = function (where,txtStr)
  {
		var parsedText = document.createTextNode(txtStr);
		this.insertAdjacentElement(where,parsedText);
  };
}

function viewSource(n) {
  var getDocument = document.getElementById("wysiwyg" + n).contentWindow.document;
  var browserName = navigator.appName;	
  if (browserName == "Microsoft Internet Explorer") {
	// View Source for IE 	 
    var iHTML = getDocument.body.innerHTML;
    getDocument.body.innerText = iHTML;
  } else {
    // View Source for Mozilla/Netscape
    var html = document.createTextNode(getDocument.body.innerHTML);
    getDocument.body.innerHTML = "";
    getDocument.body.appendChild(html);
  }  
  // Hide the HTML Mode button and show the Text Mode button
  document.getElementById('HTMLMode' + n).style.display = 'none'; 
  document.getElementById('textMode' + n).style.display = 'block';
  // set the font values for displaying HTML source
  getDocument.body.style.fontSize = "12px";
  getDocument.body.style.fontFamily = "Courier New"; 	
  viewTextMode = 1;
}
function viewText(n) { 
  var getDocument = document.getElementById("wysiwyg" + n).contentWindow.document;
  var browserName = navigator.appName;	
  if (browserName == "Microsoft Internet Explorer") {
	// View Text for IE 	  	 
    var iText = getDocument.body.innerText;
    getDocument.body.innerHTML = iText;
  } else {
	// View Text for Mozilla/Netscape 
    var html = getDocument.body.ownerDocument.createRange();
    html.selectNodeContents(getDocument.body);
    getDocument.body.innerHTML = html.toString();
  }
  // Hide the Text Mode button and show the HTML Mode button
  document.getElementById('textMode' + n).style.display = 'none'; 
  document.getElementById('HTMLMode' + n).style.display = 'block';	
  // reset the font values
  getDocument.body.style.fontSize = "";
  getDocument.body.style.fontFamily = ""; 
  viewTextMode = 0;
}
/* ---------------------------------------------------------------------- *\
  Function    : insertNodeAtSelection()
  Description : insert HTML into WYSIWYG in rich text (mozilla)
  Usage       : insertNodeAtSelection(insertNode, n)
  Arguments   : insertNode - The HTML being inserted (must be innerHTML 
	                           inserted within a div element)
                n          - The editor identifier that the HTML will be 
								             inserted into (the textarea's ID)
\* ---------------------------------------------------------------------- */
function insertNodeAtSelection(insertNode, n) {
  // get current selection
  var sel = document.getElementById('wysiwyg' + n).contentWindow.getSelection();
  // get the first range of the selection (there's almost always only one range)
  var range = sel.getRangeAt(0);
  // deselect everything
  sel.removeAllRanges();
  // remove content of current selection from document
  range.deleteContents();
  // get location of current selection
  var container = range.startContainer;
  var pos = range.startOffset;
  // make a new range for the new selection
  range=document.createRange();
  if (container.nodeType==3 && insertNode.nodeType==3) {
    // if we insert text in a textnode, do optimized insertion
    container.insertData(pos, insertNode.nodeValue);
    // put cursor after inserted text
    range.setEnd(container, pos+insertNode.length);
    range.setStart(container, pos+insertNode.length);
  } else {
    var afterNode;    
	if (container.nodeType==3) {
      // when inserting into a textnode, we create 2 new textnodes,and put the insertNode in between 
      var textNode = container;
      container = textNode.parentNode;
      var text = textNode.nodeValue;
      // text before the split
      var textBefore = text.substr(0,pos);
      // text after the split
      var textAfter = text.substr(pos);
      var beforeNode = document.createTextNode(textBefore);
      afterNode = document.createTextNode(textAfter);
      // insert the 3 new nodes before the old one
      container.insertBefore(afterNode, textNode);
      container.insertBefore(insertNode, afterNode);
      container.insertBefore(beforeNode, insertNode);
      // remove the old node
      container.removeChild(textNode);
    } else {
      // else simply insert the node
      afterNode = container.childNodes[pos];
      container.insertBefore(insertNode, afterNode);
    }
    range.setEnd(afterNode, 0);
    range.setStart(afterNode, 0);
  }
  sel.addRange(range);
}
/* ---------------------------------------------------------------------- *\
  Function    : generate_wysiwyg()
  Description : replace textarea with wysiwyg editor
  Usage       : generate_wysiwyg("textarea_id");
  Arguments   : textarea_id - ID of textarea to replace
\* ---------------------------------------------------------------------- */
function generate_wysiwyg(textareaID,tabidx) { 
	// Hide the textarea 
	document.getElementById(textareaID).style.display = 'none';
    // Pass the textareaID to the "n" variable.
	var n = textareaID;
	// Generate WYSIWYG toolbar one
	var toolbar =  '<table cellpadding="0" cellspacing="0" border="0" class="toolbar1" style="width:100%;"><tr><td style="width: 6px;"><img src="' +imagesDir+ 'seperator2.gif" alt="" hspace="3"></td>';
	var buttonObj;
	var buttonID;
	var buttonTitle;
	var buttonImage;
	var buttonImageRollover;
	// Create IDs for inserting Font Type and Size drop downs
//	toolbar += '<td style="width: 90px;"><span id="FontSelect' + n + '"></span></td>';
//	toolbar += '<td style="width: 60px;"><span id="FontSizes'  + n + '"></span></td>';  
	// Output all command buttons that belong to toolbar one
	for (var i = 0; i <= buttonName.length;) { 
    if (buttonName[i]) {
	    buttonObj            = ToolbarList[buttonName[i]];
		buttonID             = buttonObj[0];
	    buttonTitle          = buttonObj[1];
	    buttonImage          = buttonObj[2];
		buttonImageRollover  = buttonObj[3];	    
		if (buttonName[i] == "seperator") {
		    toolbar += '<td style="width: 12px;" align="center"><img src="' +buttonImage+ '" border=0 unselectable="on" width="2" height="18" hspace="2" unselectable="on"></td>';
		}  else {
		    toolbar += '<td style="width: 22px;"><img src="' +buttonImage+ '" border=0 unselectable="on" title="' +buttonTitle+ '" id="' +buttonID+ '" class="button" onClick="formatText(this.id,\'' + n + '\');" onmouseover="if(className==\'button\'){className=\'buttonOver\'}; this.src=\'' + buttonImageRollover + '\';" onmouseout="if(className==\'buttonOver\'){className=\'button\'}; this.src=\'' + buttonImage + '\';" unselectable="on" width="20" height="20"></td>';
	    }
    }
    i++;
  }
  toolbar += '<td>&nbsp;</td></tr></table>';  

  // Generate WYSIWYG toolbar two
  var toolbar2 = '<table cellpadding="0" cellspacing="0" border="0" class="toolbar2" style="width:100%;"><tr><td style="width: 6px;"><img src="' +imagesDir+ 'seperator2.gif" alt="" hspace="3"></td>';
 
  // Output all command buttons that belong to toolbar two
  for (var j = 0; j <= buttonName2.length;) {
    if (buttonName2[j]) {
	    buttonObj            = ToolbarList[buttonName2[j]];
		buttonID             = buttonObj[0];
	    buttonTitle          = buttonObj[1];
        buttonImage          = buttonObj[2];
		buttonImageRollover  = buttonObj[3];
	  
		if (buttonName2[j] == "seperator") {
		    toolbar2 += '<td style="width: 12px;" align="center"><img src="' +buttonImage+ '" border=0 unselectable="on" width="2" height="18" hspace="2" unselectable="on"></td>';
		} else if (buttonName2[j] == "viewSource") {
		    toolbar2 += '<td style="width: 22px;">';
			toolbar2 += '<span id="HTMLMode' + n + '"><img src="'  +buttonImage+  '" border=0 unselectable="on" title="' +buttonTitle+ '" id="' +buttonID+ '" class="button" onClick="formatText(this.id,\'' + n + '\');" onmouseover="if(className==\'button\'){className=\'buttonOver\'}; this.src=\'' +buttonImageRollover+ '\';" onmouseout="if(className==\'buttonOver\'){className=\'button\'}; this.src=\'' + buttonImage + '\';" unselectable="on"  width="20" height="20"></span>';
			toolbar2 += '<span id="textMode' + n + '"><img src="' +imagesDir+ 'view_text.gif" border=0 unselectable="on" title="viewText"          id="ViewText"       class="button" onClick="formatText(this.id,\'' + n + '\');" onmouseover="if(className==\'button\'){className=\'buttonOver\'}; this.src=\'' +imagesDir+ 'view_text_on.gif\';"    onmouseout="if(className==\'buttonOver\'){className=\'button\'}; this.src=\'' +imagesDir+ 'view_text.gif\';" unselectable="on"  width="20" height="20"></span>';
			toolbar2 += '</td>';
		} else {
		    toolbar2 += '<td style="width: 22px;"><img src="' +buttonImage+ '" border=0 unselectable="on" title="' +buttonTitle+ '" id="' +buttonID+ '" class="button" onClick="formatText(this.id,\'' + n + '\');" onmouseover="if(className==\'button\'){className=\'buttonOver\'}; this.src=\'' +buttonImageRollover+ '\';" onmouseout="if(className==\'buttonOver\'){className=\'button\'}; this.src=\'' + buttonImage + '\';" unselectable="on" width="20" height="20"></td>';
	    }
    }
    j++;
  }
  toolbar2 += '<td>&nbsp;</td></tr></table>';  	 	
  // Create iframe which will be used for rich text editing
  var iframe = '<iframe width="99%" height="80%" class="wysiwyg_text" frameborder="2" tabindex="'+tabidx+'" id="wysiwyg' + n + '"></iframe>\n';
  // Insert after the textArea both toolbar one and two
  document.getElementById(n).insertAdjacentHTML("afterEnd", toolbar + toolbar2 + iframe);		  
  
  // Insert the Font Type and Size drop downs into the toolbar
//  outputFontSelect(n);
//  outputFontSizes(n); 	
  // Hide the dynamic drop down lists for the Font Types and Sizes
//  hideFonts(n);
//  hideFontSizes(n);
	
  // Hide the "Text Mode" button
//  document.getElementById("textMode" + n).style.display = 'none'; 
	
	// Give the iframe the global wysiwyg height and width
//  document.getElementById("wysiwyg" + n).style.height = wysiwygHeight + "px";
//  document.getElementById("wysiwyg" + n).style.width = wysiwygWidth + "px";
//  document.getElementById("wysiwyg" + n).style.height ="100%";
//  document.getElementById("wysiwyg" + n).style.width = "100%";
	
  var new_height = (document.getElementById(textareaID).rows * 23);	
  document.getElementById("wysiwyg" + n).style.height =new_height+"px";		
  // Pass the textarea's existing text over to the content variable
  var content = document.getElementById(n).value;	
  var doc = document.getElementById("wysiwyg" + n).contentWindow.document;	
  // Write the textarea's content into the iframe
  doc.open();
  doc.write(content);
  doc.close();	
  // Make the iframe editable in both Mozilla and IE
  doc.body.contentEditable = true;
  doc.designMode = "on";
	
  // Update the textarea with content in WYSIWYG when user submits form
/*  var browserName = navigator.appName;
  if (browserName == "Microsoft Internet Explorer") {
    for (var idx=0; idx < document.forms.length; idx++) {
      document.forms[idx].attachEvent('onsubmit', function() { updateTextArea(n); });
    }
  }
  else {
  	for (var idx=0; idx < document.forms.length; idx++) {
    	document.forms[idx].addEventListener('submit',function OnSumbmit() { updateTextArea(n); }, true);
    }
  } */ 	
}
/* ---------------------------------------------------------------------- *\
  Function    : formatText()
  Description : replace textarea with wysiwyg editor
  Usage       : formatText(id, n, selected);
  Arguments   : id - The execCommand (e.g. Bold)
                n  - The editor identifier that the command 
								     affects (the textarea's ID)
                selected - The selected value when applicable (e.g. Arial)
\* ---------------------------------------------------------------------- */
function formatText(id, n, selected) {
  // When user clicks toolbar button make sure it always targets its respective WYSIWYG
  document.getElementById("wysiwyg" + n).contentWindow.focus();
  // When in Text Mode these execCommands are disabled
  var formatIDs = ["FontSize","FontName","Bold","Italic","Underline","Subscript","Superscript","Strikethrough","Justifyleft","Justifyright","Justifycenter","InsertUnorderedList","InsertOrderedList","Indent","Outdent","ForeColor","BackColor","InsertImage","InsertTable","CreateLink"];  
  // Check if button clicked is in disabled list
  for (var i = 0; i <= formatIDs.length;) {
	  if (formatIDs[i] == id) {  var disabled_id = 1; }
	  i++;
  }	
  // Check if in Text Mode and disabled button was clicked
  if (viewTextMode == 1 && disabled_id == 1) { alert("You are in HTML Mode. This feature has been disabled.");}	
  else {	
	  // FontSize
	  if (id == "FontSize") { document.getElementById("wysiwyg" + n).contentWindow.document.execCommand("FontSize", false, selected);}	  
	  // FontName
	  else if (id == "FontName") { document.getElementById("wysiwyg" + n).contentWindow.document.execCommand("FontName", false, selected); }	  
	  // ViewSource
	  else if (id == "ViewSource") {viewSource(n);}		
	  // ViewText
	  else if (id == "ViewText") {viewText(n);}
	  // Every other command
	  else {document.getElementById("wysiwyg" + n).contentWindow.document.execCommand(id, false, null);}
  }
}
/* ---------------------------------------------------------------------- *\
  Function    : insertHTML()
  Description : insert HTML into WYSIWYG in rich text
  Usage       : insertHTML(<b>hello</b>, "textareaID")
  Arguments   : html - The HTML being inserted (e.g. <b>hello</b>)
                n  - The editor identifier that the HTML 
								     will be inserted into (the textarea's ID)
\* ---------------------------------------------------------------------- */
function insertHTML(html, n) {
    var browserName = navigator.appName;
	if (browserName == "Microsoft Internet Explorer") {	  
	  document.getElementById('wysiwyg' + n).contentWindow.document.selection.createRange().pasteHTML(html);   
	} else {
	  var div = document.getElementById('wysiwyg' + n).contentWindow.document.createElement("div");		 
	  div.innerHTML = html;
	  var node = insertNodeAtSelection(div, n);		
	}	
}


/* ---------------------------------------------------------------------- *\
  Function    : outputFontSelect()
  Description : creates the Font Select drop down and inserts it into 
	              the toolbar
  Usage       : outputFontSelect(n)
  Arguments   : n   - The editor identifier that the Font Select will update
	                    when making font changes (the textarea's ID)
\* ---------------------------------------------------------------------- */
function outputFontSelect(n) {
  var FontSelectObj        = ToolbarList['selectfont'];
  var FontSelect           = FontSelectObj[2];
  var FontSelectOn         = FontSelectObj[3];  
  Fonts.sort();
  var FontSelectDropDown = new Array;
  FontSelectDropDown[n] = '<table border="0" cellpadding="0" cellspacing="0"><tr><td onMouseOver="document.getElementById(\'selectFont' + n + '\').src=\'' + FontSelectOn + '\';" onMouseOut="document.getElementById(\'selectFont' + n + '\').src=\'' + FontSelect + '\';"><img src="' + FontSelect + '" id="selectFont' + n + '" width="85" height="20" onClick="showFonts(\'' + n + '\');" unselectable="on"><br>';
  FontSelectDropDown[n] += '<span id="Fonts' + n + '" class="dropdown" style="width: 20em;">';

  for (var i = 0; i <= Fonts.length;) {
	  if (Fonts[i]) {
		  FontSelectDropDown[n] += '<button type="button" onClick="formatText(\'FontName\',\'' + n + '\',\'' + Fonts[i] + '\')\; hideFonts(\'' + n + '\');" onMouseOver="this.className=\'mouseOver\'" onMouseOut="this.className=\'mouseOut\'" class="mouseOut" style="width: 15em;"><table cellpadding="0" cellspacing="0" border="0"><tr><td align="left" style="font-family:' + Fonts[i] + '; font-size: 12px;">' + Fonts[i] + '</td></tr></table></button><br>';	
	  }	  
	  i++;
  }
  FontSelectDropDown[n] += '</span></td></tr></table>';
  document.getElementById('FontSelect' + n).insertAdjacentHTML("afterBegin", FontSelectDropDown[n]);
}
/* ---------------------------------------------------------------------- *\
  Function    : outputFontSizes()
  Description : creates the Font Sizes drop down and inserts it into 
	              the toolbar
  Usage       : outputFontSelect(n)
  Arguments   : n   - The editor identifier that the Font Sizes will update
	                    when making font changes (the textarea's ID)
\* ---------------------------------------------------------------------- */
function outputFontSizes(n) {

  var FontSizeObj        = ToolbarList['selectsize'];
  var FontSize           = FontSizeObj[2];
  var FontSizeOn         = FontSizeObj[3];

  FontSizes.sort();
  var FontSizesDropDown = new Array;
  FontSizesDropDown[n] = '<table border="0" cellpadding="0" cellspacing="0"><tr><td onMouseOver="document.getElementById(\'selectSize' + n + '\').src=\'' + FontSizeOn + '\';" onMouseOut="document.getElementById(\'selectSize' + n + '\').src=\'' + FontSize + '\';"><img src="' + FontSize + '" id="selectSize' + n + '" width="49" height="20" onClick="showFontSizes(\'' + n + '\');" unselectable="on"><br>';
  FontSizesDropDown[n] += '<span id="Sizes' + n + '" class="dropdown" style="width: 20em;">';

  for (var i = 0; i <= FontSizes.length;) {
	  if (FontSizes[i]) {
		  FontSizesDropDown[n] += '<button type="button" onClick="formatText(\'FontSize\',\'' + n + '\',\'' + FontSizes[i] + '\')\;hideFontSizes(\'' + n + '\');" onMouseOver="this.className=\'mouseOver\'" onMouseOut="this.className=\'mouseOut\'" class="mouseOut" style="width: 15em;"><table cellpadding="0" cellspacing="0" border="0"><tr><td align="left" style="font-family: arial, verdana, helvetica;"><font size="' + FontSizes[i] + '">size ' + FontSizes[i] + '</font></td></tr></table></button><br>';	
	  }	  
	  i++;
  }
  FontSizesDropDown[n] += '</span></td></tr></table>';
  document.getElementById('FontSizes' + n).insertAdjacentHTML("afterBegin", FontSizesDropDown[n]);
}
/* ---------------------------------------------------------------------- *\
  Function    : hideFonts()
  Description : Hides the list of font names in the font select drop down
  Usage       : hideFonts(n)
  Arguments   : n   - The editor identifier (the textarea's ID)
\* ---------------------------------------------------------------------- */
function hideFonts(n) {
  document.getElementById('Fonts' + n).style.display = 'none'; 
}
/* ---------------------------------------------------------------------- *\
  Function    : hideFontSizes()
  Description : Hides the list of font sizes in the font sizes drop down
  Usage       : hideFontSizes(n)
  Arguments   : n   - The editor identifier (the textarea's ID)
\* ---------------------------------------------------------------------- */
function hideFontSizes(n) {
  document.getElementById('Sizes' + n).style.display = 'none'; 
}
/* ---------------------------------------------------------------------- *\
  Function    : showFonts()
  Description : Shows the list of font names in the font select drop down
  Usage       : showFonts(n)
  Arguments   : n   - The editor identifier (the textarea's ID)
\* ---------------------------------------------------------------------- */
function showFonts(n) { 
  if (document.getElementById('Fonts' + n).style.display == 'block') {
    document.getElementById('Fonts' + n).style.display = 'none';
  } else {
    document.getElementById('Fonts' + n).style.display = 'block'; 
    document.getElementById('Fonts' + n).style.position = 'absolute';		
  }
}
/* ---------------------------------------------------------------------- *\
  Function    : showFontSizes()
  Description : Shows the list of font sizes in the font sizes drop down
  Usage       : showFonts(n)
  Arguments   : n   - The editor identifier (the textarea's ID)
\* ---------------------------------------------------------------------- */
function showFontSizes(n) { 
  if (document.getElementById('Sizes' + n).style.display == 'block') {
    document.getElementById('Sizes' + n).style.display = 'none';
  } else {
    document.getElementById('Sizes' + n).style.display = 'block'; 
    document.getElementById('Sizes' + n).style.position = 'absolute';		
  }
}
/* ---------------------------------------------------------------------- *\
  Function    : updateTextArea()
  Description : Updates the text area value with the HTML source of the WYSIWYG
  Usage       : updateTextArea(n)
  Arguments   : n   - The editor identifier (the textarea's ID)
\* ---------------------------------------------------------------------- */
function bbencode(content) {
	// Petit menage pr�alable...
	content = content.replace(/<!--([\s\S]*?)-->|<style>[\s\S]*?<\/style>/g, "");  // Word comments
	content = content.replace(/<(meta|link)[^>]+>/g, ""); // Header elements
	content = content.replace(/<\\?\?xml[^>]*>/gi, ""); // xml	
	content =  content.replace(/^\s+/, "").replace(/\s+$/, "");	 // Trim

	// example: <strong> to [b]
	content = content.replace(/<span style=\"text-decoration: underline;\">(.*?)<\/span>/gi,"[span_u]$1[/span]");
	content = content.replace(/<span style=\"font-style: italic;\">(.*?)<\/span>/gi,"[span_i]$1[/span]");
	content = content.replace(/<span style=\"font-weight: bold;\">(.*?)<\/span>/gi,"[span_b]$1[/span]");
	
    content = content.replace(/<\/(strong|b)>/gi,"[/b]");
	content = content.replace(/<(strong|b)>/gi,"[b]");
	content = content.replace(/<\/(em|i)>/gi,"[/i]");
	content = content.replace(/<(em|i)>/gi,"[i]");
	content = content.replace(/<\/u>/gi,"[/u]");

	content = content.replace(/<div style=\"text-align: center;\">(.*?)<\/div>/gi,"[center]$1[/div]");
    content = content.replace(/<div style=\"text-align: right;\">(.*?)<\/div>/gi,"[right]$1[/div]");
    content = content.replace(/<div style=\"text-align: left;\">(.*?)<\/div>/gi,"[left]$1[/div]");
    content = content.replace(/<div style=\"margin-left: (.*?)px;\">(.*?)<\/div>/gi,"[margin=$1]$2[/div]");
    content = content.replace(/<p align=left>(.*?)<\/p>/gi,"[p_left]$1[/p]");
    content = content.replace(/<p align=center>(.*?)<\/p>/gi,"[p_center]$1[/p]");
    content = content.replace(/<p align=right>(.*?)<\/p>/gi,"[p_right]$1[/p]");
    content = content.replace(/<p>(.*?)<\/p>/gi,"[p]$1[/p]");
    
    content = content.replace(/<u>/gi,"[u]");
	content = content.replace(/<sup>/gi,"[sup]");
	content = content.replace(/<\/sup>/gi,"[/sup]");
	content = content.replace(/<sub>/gi,"[sub]");
	content = content.replace(/<\/sub>/gi,"[/sub]");
	content = content.replace(/<ul>/gi,"[ul]");
	content = content.replace(/<\/ul>/gi,"[/ul]");
	content = content.replace(/<ol>/gi,"[ol]");
	content = content.replace(/<\/ol>/gi,"[/ol]");
	content = content.replace(/<li>/gi,"[li]");
	content = content.replace(/<\/li>/gi,"[/li]");		
	content = content.replace(/<blockquote[^>]*>/gi,"[quote]");
	content = content.replace(/<\/blockquote>/gi,"[/quote]");
	content = content.replace(/<br \/>/gi,"[br]");
	content = content.replace(/<br\/>/gi,"[br]");
	content = content.replace(/<br>/gi,"[br]");
	content = content.replace(/<p>/gi,"");
	content = content.replace(/<\/p>/gi,"[br]");
	content = content.replace(/\t/gi,"&nbsp;");
	content = content.replace(/\v/gi,"&nbsp;");
	// Supprime les balises et Trim
	content = content.replace(/(<([^>]+)>)/ig,"");
	content =  content.replace(/^\s+/, "").replace(/\s+$/, "");	
	return content; 
}
function bbdecode(content) {
	content = content.replace(/\[span_u\]/gi,'<span style="text-decoration: underline;">');
	content = content.replace(/\[span_i\]/gi,'<span style="font-style: italic;">');
	content = content.replace(/\[span_b\]/gi,'<span style="font-weight: bold;">');
	content = content.replace(/\[\/span\]/gi,'</span>');

	content = content.replace(/\[p_left\]/gi,'<p align=left>');
	content = content.replace(/\[p_center\]/gi,'<p align=center>');
	content = content.replace(/\[p_right\]/gi,'<p align=right>');
	content = content.replace(/\[\/p\]/gi,'</p>');
	content = content.replace(/\[p\]/gi,'<p>');

	content = content.replace(/\[br\]/gi,"<br/>");
	content = content.replace(/\[b\]/gi,"<b>");
	content = content.replace(/\[\/b\]/gi,"</b>");
	content = content.replace(/\[u\]/gi,"<u>");
	content = content.replace(/\[\/u\]/gi,"</u>");
	content = content.replace(/\[i\]/gi,"<i>");
	content = content.replace(/\[\/i\]/gi,"</i>");
	content = content.replace(/\[quote\]/gi,"<blockquote>");
	content = content.replace(/\[\/quote\]/gi,"</blockquote>");
	content = content.replace(/\[ol\]/gi,"<ol>");
	content = content.replace(/\[\/ol\]/gi,"</ol>");
	content = content.replace(/\[ul\]/gi,"<ul>");
	content = content.replace(/\[\/ul\]/gi,"</ul>");
	content = content.replace(/\[li\]/gi,"<li>");
	content = content.replace(/\[\/li\]/gi,"</li>");		
	content = content.replace(/\[sup\]/gi,"<sup>");
	content = content.replace(/\[\/sup\]/gi,"</sup>");
	content = content.replace(/\[sub\]/gi,"<sub>");
	content = content.replace(/\[\/sub\]/gi,"</sub>");
	content = content.replace(/\[center\]/gi,'<div style="text-align: center;">');
	content = content.replace(/\[right\]/gi,'<div style="text-align: right;">');
	content = content.replace(/\[left\]/gi,'<div style="text-align: left;">');
	content = content.replace(/\[margin=(.*?)\]/gi,"<div style=\"margin-left: $1px;\">"); 	    	
	content = content.replace(/\[\/div\]/gi,"</div>");
	// Clean empty 
	content = content.replace(/<(b|u|i)>&nbsp;<\/(b|u|i)>/gi, '');				
	return content; 
}
function updateTextArea(n) {
	var content = document.getElementById("wysiwyg" + n).contentWindow.document.body.innerHTML;
	// alert('Avant :' +content);
	content = bbencode(content);	
	content = mycleanhtml(content);
	content = bbdecode(content);
	document.getElementById("wysiwyg" + n).contentWindow.document.body.innerHTML =content;
	// alert('Apres :' +content);
	document.getElementById(n).value = content; 
}
function updateTextAreaFinal(n) {
	var content = document.getElementById("wysiwyg" + n).contentWindow.document.body.innerHTML;
	content = bbencode(content);
	content = mycleanhtml(content);	
	document.getElementById(n).value = content; 
}
//==============================
function setVille(fld_ville,s){
	var selvalue = s.options[s.selectedIndex].value;
	var formObj = document.getElementById(fld_ville);
	var tableau = selvalue.split('##'); 
	formObj.value = tableau[1];
	formObj.readonly = true;
	var formObjGeo = document.getElementById(fld_ville+'_geo');	
	formObjGeo.value = tableau[0];	
	hideDialog();
}
function noVille(fld_ville){
	var formObj = document.getElementById(fld_ville);
	formObj.readonly = false; 
	var formObjGeo = document.getElementById(fld_ville+'_geo');
	formObjGeo.value = '0';	
	hideDialog();
	formObj.focus();
}
function getCpost(prefix_fld_addr) {
	var cpost_id = document.getElementById(prefix_fld_addr+'_cp'); //prefix_fld_addr+'_cpostal'); 
	var cpost = cpost_id.value;
	var formObj = document.getElementById(prefix_fld_addr+'_ville');
	var formObjGeo = document.getElementById(prefix_fld_addr+'_ville_geo');
	formObjGeo.value = '0';	
	formObj.readonly = false; 
	new Ajax_request('/ajax_cpost.php',{method:'get',params:'prefix_fld_addr='+prefix_fld_addr+'&cpost='+cpost,onSuccess:ajaxcpost});	
}
function ajaxcpost(ajax){
	if (ajax.responseText != 'empty')
		showDialog('?',ajax.responseText,'prompt');
}
