//Standard characters
var dot = '.';
var and = '&';
var qstn = '?';
var eql = '=';
var or = "||";

//Standard strings
var http = "http://";
var www = "www";
var httpwww = http + www;
var https = "https://";
var cgi = "cgi";
var scgi = "s"+cgi;
var jsExt = dot+"js";
var tclExt = dot+"tcl";
var com = "com";
var dotCom = dot+com;
var scriptOpen = '<SC' + 'RIPT SRC="';
var scriptClose = '"></SC' + 'RIPT>';

//Location strings
var thisPage = location.href.toLowerCase();
var lastPage = "";											
if (history.length > 1)
	lastPage = document.referrer.toLowerCase();
var thisPageURL, thisPageURI, lastPageURL, lastPageURI;

function openLink(URI){
	// pour ouvrir les liens créés dans une nouvelle fenetre
	win = window.open(URI,"secWin");
	win.focus;
}

function openLien(sel){
	var larg_ecran = screen.width;
	var haut_ecran = screen.height;
	var height_lien=150;
	var width_lien=450;
	var left = (larg_ecran/2) - width_lien/2;
	var top = (haut_ecran/2) - height_lien/2;
	var styleStr = 'toolbar=no,location=no,directories=no,status=yes,titlebar=yes,menubar=no,scrollbar=yes,resizable=yes,width='+width_lien+',height='+height_lien+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	var msgWindow = window.open('richlink.html',sel.id, styleStr);
} 

function Is()
{
	// initializing objects
	// - created t varable to save on download time
	var t = true;
	var agt = navigator.userAgent.toLowerCase();
	
	// - backwards compatible
	this.major = parseInt(navigator.appVersion);
	this.webTV = this.opera = this.nav = this.ie = this.safari = this.chrome = false;

	//Browser and version detection
	//Do least common browsers first because many browsers report "msie"
	//as a compatible engine
	var vInd = 0;
	if (agt.indexOf("webtv") != -1)
	{
		this.webTV = t;
		vInd = agt.indexOf("webtv/") + 6;
	}
	// else if (agt.indexOf("safari") != -1)		//
	// {
		// this.safari = t;
		// vInd = agt.lastIndexOf("safari") + 7;
	// }
	else if (agt.indexOf("chrome") != -1)		//
	{
		this.chrome = t;
		vInd = agt.lastIndexOf("chrome") + 7;
	}
	else if (agt.indexOf("opera") != -1)
	{
		this.opera = t;
		vInd = agt.lastIndexOf("opera") + 6;
	}
	else if (navigator.appName == "Netscape")
	{
		this.nav = t;
		vInd = agt.lastIndexOf("/") + 1;
	}
	else if (agt.indexOf("msie") != -1)
	{
		this.ie = t;
		vInd = agt.indexOf("msie") + 4;
	}
	this.ver = parseInt(agt.substring(vInd));

	//Operating system detection
	this.win = (agt.indexOf("win") != -1);
	//jad081604 - Add XP detection
	this.winXP = (this.win && (agt.indexOf("windows nt 5.1;") != -1));
	this.mac = (agt.indexOf("mac") != -1);
	this.macppc = (this.mac && ((agt.indexOf("ppc")!=-1) || 
                           (agt.indexOf("powerpc")!=-1)));
	this.xpSp2 = (agt.indexOf("sv1") != -1);
}
var client = new Is();

var DOM = document;

//Onload functionalities
var onLoadFunctions = new Array();
var anchorOnLoad = null;
				
function addOnLoadFunction(f){
	onLoadFunctions[onLoadFunctions.length] = f;
}

function OnLoad() {
	if ( anchorOnLoad ) {
		Anchor = eval('onLoadAnchor');
		Anchor.click();
	}
	for(var i = 0; i < onLoadFunctions.length; i++ ) {
		var current = onLoadFunctions[i];
		var parenIndex = current.indexOf("(");
		if(parenIndex != -1) {
			var command = current.substring(0,parenIndex);
			eval('if(typeof('+ command+ ') == "function") {eval(onLoadFunctions[i]);}');
		}
	}
}

function getOffsetLeft(elm,topId) {
	var mOffsetLeft = elm.offsetLeft;
	var mOffsetParent = elm.offsetParent;
	
	while(mOffsetParent != null && mOffsetParent.id != topId) {
		mOffsetLeft += mOffsetParent.offsetLeft;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetLeft;
}

function getOffsetTop(elm,topId) {
	var mOffsetTop = elm.offsetTop;
	var mOffsetParent = elm.offsetParent;
	
	while(mOffsetParent != null && mOffsetParent.id != topId) {
		mOffsetTop += mOffsetParent.offsetTop;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetTop;
}

/*
 * Base component
 */
function Component(name) {
	this.id = name;
	this.eElement = null;
	this.bind = function () {
		this.eElement = DOM.getElementById(this.id);
	}
	this.instanceOfType = function _instanceOfType(type) {
		if ( this.type == type )
			return true;
		/*if ( this.base != null ) {
			return this.base.prototype.instanceOfType(type);
		} */
		return false;
	}
}
Component.prototype.type = "Component";

function Form(name) 
{
 	this.base = Component;
 	this.base(name);
	this.fields = new Array();
	this.controls = new Array();
	addOnLoadFunction(name + 'Obj.bind()');
	this.bind = function (){
		this.submitForm = this.eElement = DOM.getElementById(this.id);
		var i;
		for(i = 0; i < this.fields.length; i++ ) {
			this.fields[i].bind(this.eElement);
		}
		for(i = 0; i < this.controls.length; i++ ) {
			this.eElement[this.controls[i]].value = "";
		}
		//this.eElement["Action"].value = "";
	}
	this.addField = function(field) {
		this.fields[this.fields.length] = field;
	}
	this.addControl = function(c) {
		this.controls[this.controls.length] = c;
	}
	this.submit = function() {
		for(var i = 0; i < this.fields.length; i++ ) {
			if ( this.fields[i].beforeSubmit(this.eElement) == false ) {
				return false;
			}
		}
		this.submitForm.submit();
		return false;
	}

	this.submitAction = function(action) {
		this.eElement[action].value = action;
		this.submit();
	}
	this.setSubmitForm = function(form) {
		this.submitForm = form;
	}
}
Form.prototype.type = "Component";

function FormField(name,frm) 
{
 	this.base = Component;
 	this.base(name);
	this.form = frm;

	frm.addField(this);

	this.bind = function (frm) {
		this.eElement = frm[this.id];
		if ( this.eElement == null )
			this.eElement = this.form.submitForm[this.id];
	}
	this.valueChanged=function(val) {
	}
	this.getValue=function () {
		return this.eElement.value;
	}

	this.setVisibility=function(show) {
		if ( show == "show" ) {
			this.eElement.style.visibility = "visible";
		} else if (show == "hide") {
			this.eElement.style.visibility = "hidden";
		}
	}

	this.beforeSubmit = function(frm) {
		return true;
	}

	this.disable = function(disabled) {
		var u = "undefined";
		var cntrl = this.eElement;
		//disabling control
		if(typeof(cntrl.disabled)!=u)
			cntrl.disabled = disabled;
		if(typeof(cntrl.style)!=u);
		{
			if(disabled)
				cntrl.style.background = "rgb(178,178,178)";
			else
				cntrl.style.background = "#fff";
		}
	}
}
FormField.prototype.type = "FormField";

function TextInput(name,frm) 
{
 	this.base=FormField;
 	this.base(name,frm);
	this.setValue=function(val) {
		this.eElement.value = val;
		this.valueChanged();
	}
}
TextInput.prototype.type = "TextInput";

function TextAreaInput(name,frm) 
{
 	this.base=TextInput;
 	this.base(name,frm);
}
TextAreaInput.prototype.type = "TextAreaInput";
 
function RadioInput(name,frm) 
{
 	this.base=FormField;
 	this.base(name,frm);
	this.bind = function(frm){
		this.eElements = frm[this.id];
		if (typeof(this.eElements.length) != "undefined")  {
			this.eElement = this.eElements[0];
		} else {
			this.eElement = this.eElements;
			this.eElements = new Array();
			this.eElements[0] = this.eElement;
		} 
	}

	this.getValue = function () {
		for( var i = 0; i < this.eElements.length;i++)
			if ( this.eElements[i].checked)
				return this.eElements[i].value;
		return null;
	}

	this.setValue = function(val) {
		for( var i = 0; i < this.eElements.length;i++) {
			this.eElements[i].checked = this.eElements[i].value == val;
		}
		this.valueChanged();
	} 

}
RadioInput.prototype.type = "FormField";

function CheckboxInput(name,frm) 
{
 	this.base = RadioInput;
 	this.base(name,frm);
}
function SelectInput(name,frm) 
{
 	this.base = FormField;
 	this.base(name,frm);

	this.getValue = function () {
		var selectedIndex = this.eElement.selectedIndex;
		if ( selectedIndex != null && selectedIndex >= 0 )
			return this.eElement.options[selectedIndex].value;
		return null;
	}

	this.setValue = function(val) {
		var options = this.eElement.options;
		for( var i = 0; i < options.length;i++) {
			if ( options[i].value == val ) {
				this.eElement.selectedIndex = i;
				break;
			}
		}
		this.valueChanged();
	} 

	this.replaceOptions = function (list) {
		this.clearOptions();
		var options = this.eElement.options;
		if ( list != null ) {
			for( var i = 0; i < list.length; i++ ) {
				options[i] = new Option(list[i][1],list[i][0]);
			}
		}
		this.disable(options.length == 0 );
	}

	this.clearOptions = function () {
		var options = this.eElement.options;
		for( var i = options.length - 1; i >= 0; i-- ) {
			options[i] = null;
		}
		this.eElement.selectedIndex = -1;
	}	  
		  
}
SelectInput.prototype.type = "SelectInput";

function IFrameObj(name,nobind) {
 	this.base = Component;
 	this.base(name);
	this.domain  = null;
	if ( nobind != true )
		addOnLoadFunction(name + '.bind()');
	this.bind = function () {
		var frm = this.eElement = DOM.getElementById(this.id);
		this.doc = null;
		if (frm.contentDocument) {
    		// For NS6, opera, firefox
    		this.doc = frm.contentDocument; 
  		} else if (frm.contentWindow) {
   			// For IE5.5 and IE6
    		this.doc = frm.contentWindow.document;
  		} else if (frm.document) {
    		// For IE5
    		this.doc = frm.document;
  		}
	}

	this.setDomain= function(domain) {
		this.domain = domain;
	}	

	this.getWindow = function() {
		if (document.all) {
			return this.eElement;
		} else {
			return this.eElement.contentWindow;
		}
	}

	this.writeDocument = function(content,design) {
		this.doc.open();
		this.doc.write(content);
		this.doc.close();
		if ( design )
			this.doc.designMode = "On";
		this.resetDocument(this.eElement);
	}

	this.getBodyContent = function() {
		return this.doc.body.innerHTML;
	}
		
	this.getSelection = function() {
		if (document.all) {
			return this.doc.selection; 
		} else {
			return this.eElement.contentWindow.getSelection();
		}
	}

	this.getSelectionRange = function() {
		var selection = this.getSelection();
		if ( selection != null ) {
			if (document.all) {
				return selection.createRange();
			} else {
				return selection.getRangeAt(selection.rangeCount - 1).cloneRange();
			}
		}
		return null;
	}

	this.setVisibility=function(show) {
		if ( show == "show" ) {
			this.eElement.style.visibility = "visible";
		} else if (show == "hide") {
			this.eElement.style.visibility = "hidden";
		}
	}
	this.toggleVisibility=function() {
		this.setVisibility(this.eElement.style.visibility == "visible"? "hide" : "show");
	}

	this.setLeft=function(l) {
		this.eElement.style.left = l;
	}

	this.setTop=function(t) {
		this.eElement.style.top = t;
	}

	this.execCommand = function(command, option) {
		var win;
		if (document.all) {
			win = frames[this.id];
		} else {
			win = document.getElementById(this.id).contentWindow;
		}
		try {
			win.focus();
	  		win.document.execCommand(command, false, option);
			win.focus();
		} catch (e) {
//		setTimeout("rteCommand('" + rte + "', '" + command + "', '" + option + "');", 10);
		}
	}

	this.resetDocument = function(frm) {
		if (frm.contentDocument) {
    		// For NS6, opera, firefox
    		this.doc = frm.contentDocument; 
  		} else if (frm.contentWindow) {
   			// For IE5.5 and IE6
    		this.doc = frm.contentWindow.document;
  		} else if (frm.document) {
    		// For IE5
    		this.doc = frm.document;
  		}
	}
		
}
IFrameObj.prototype.type = "IFrameObj";

	function RichTextEdit(name,frm,width,height,css,localeCss,wysiwygImagesPath,showFont,hasError) {
		this.base = TextAreaInput;
		this.base(name,frm);
		this.isRichTextEdit = document.designMode && (client.nav || client.ie || client.chrome);
		this.css = css;
		this.localeCss = localeCss;
		this.range = null;
		this.binded = false;
		this.originalDomain = document.domain;
		this.domain = null;
		if ( this.isRichTextEdit ) {
			if (width < 410) width = 410;
			var tablewidth = width;
			if (!client.ie) {
				tablewidth += 4;
			}
			var styles = [ 
				["<p>","Parag. &lt;p&gt;"],
				["<h1>","Titre 1 &lt;h1&gt;"],
				["<h2>","Titre 2 &lt;h2&gt;"],
				["<h3>","Titre 3 &lt;h3&gt;"],
				["<h4>","Titre 4 &lt;h4&gt;"],
				["<h5>","Titre 5 &lt;h5&gt;"],
				["<h6>","Titre 6 &lt;h6&gt;"]];
			var fonts = [
				["Times New Roman, Times, serif","Times"],
				["Verdana, Arial, Helvetica, sans-serif","Verdana"],
				["Arial, Helvetica, sans-serif","Arial"],
				["arial black,avant garde","Arial Black"],
				["Courier New, Courier, mono","Courier New"],
				["book antiqua,palatino,times","Book Antiqua"],
				["comic sans ms,sand","Comic Sans"],
				["georgia,palatino","Georgia"],
				["impact,chicago","Impact"],
				["tahoma,arial,helvetica,sans-serif","Tahoma"],
				["trebuchet ms,geneva","Trebuchet MS"]];
			var buttons = [
				["bold.gif","Gras","bold"],
				["italic.gif","Italique","italic"],
				["underline.gif","Souligné","underline"],
				["sep",null],
				["left_just.gif","Aligné à gauche","justifyleft"],
				["centre.gif","Centré","justifycenter"],
				["right_just.gif","Aligné à droite","justifyright"],
				["justifyfull.gif","Justifié","justifyfull"],
				["sep",null],
				["hr.gif","Ligne horizontale","inserthorizontalrule"],
				["sep",null],
				["numbered_list.gif","Liste numérotée","insertorderedlist"],
				["list.gif","Liste à puces","insertunorderedlist"],
				["sep",null],
				["outdent.gif","Diminuer le retrait","outdent"],
				["indent.gif","Augmenter le retrait","indent"],
				["sep",null],
				["textcolor.gif","Couleur du texte","forecolor"],
				["sep",null],
				["link.gif","Insérer un lien","link"],
				["sep",null]];
				//["bgcolor.gif","Couleur du fond","hilitecolor"]];
			var rteObj = "rte" + name + "Obj";	
				document.writeln('<div id="rteRoot" class="rteDiv">');
				document.writeln('<table class="rteBack" cellpadding=2 cellspacing=0 id="Buttons1_' + name + '" width="' + tablewidth + '">');
				document.writeln('	<tr>');
				// boutons
				for(i = 0; i < buttons.length; i++ ) {
					var img = buttons[i][0];
					if ( img == "sep" ) {
						document.writeln('<td><img class="rteVertSep" src="' + wysiwygImagesPath + 'blackdot.gif" width="1" height="18" border="0" alt=""></td>');
					} else {
						document.writeln('<td><img id="bold" class="rteImage" src="' + wysiwygImagesPath + buttons[i][0] + '" width="24" height="24" alt="' + buttons[i][1] +'" title="' + buttons[i][1] + '" onClick="' + rteObj + '.btn(\'' + buttons[i][2] + '\',this)"></td>');
					}
				}
				// listes
				document.writeln('		<td style="padding-left:4px"> </td>');
				document.writeln('		<td>');
				document.writeln('			<select class="richList" name="styleType" id="formatblock_' + name + '" onchange="' + rteObj + '.selectFont(this);">');
				document.writeln('				<option class="richList" value="">[Style]</option>');
			for(i = 0; i < styles.length; i++ )
				document.writeln('<option class="richList" value="' + styles[i][0] + '">' + styles[i][1] + '</option>');
				document.writeln('<option class="richList" value="$PF1">Préformaté 1</option>');
				document.writeln('<option class="richList" value="$PF2">Préformaté 2</option>');
				document.writeln('<option class="richList" value="$PF3">Préformaté 3</option>');
			document.writeln('			</select>');
			document.writeln('		</td>');
			if ( showFont ) {	
				document.writeln('		<td>');
				document.writeln('			<select class="richList" name="fontType" id="fontname_' + name + '" onchange="' + rteObj + '.selectFont(this)">');
				document.writeln('				<option class="richList" value="Font" selected>[Police]</option>');
				for(i = 0; i< fonts.length;i++)
					document.writeln('<option class="richList" value="' + fonts[i][0] + '">' + fonts[i][1] + '</option>');
				document.writeln('			</select>');
				document.writeln('		</td>');
			}
			// tailles polices
			document.writeln('		<td>');	
			document.writeln('			<select class="richList" name="fontSize" unselectable="on" id="fontsize_' + name + '" onchange="' + rteObj + '.selectFont(this)">');
			document.writeln('				<option class="richList" value="Size">[Taille]</option>');
			for( i = 1; i < 8; i++) document.writeln('<option class="richList" value="' + i + '">' + i + '</option>');
			//for( i = 3; i < 8; i++) document.writeln('<option class="richList" value="' + i + '">' + i + '</option>');
			document.writeln('			</select>');
			document.writeln('		</td>');
			
			document.writeln('		<td width="100%">');
			document.writeln('		</td>');
			document.writeln('	</tr>');
			document.writeln('</table>');
			
			document.writeln('<table class="rteBack" cellpadding="0" cellspacing="0" id="Buttons2_' + name + '" width="' + tablewidth + '">');
			document.writeln('	<tr>');
			document.writeln('		<td width="100%"></td>');
			document.writeln('	</tr>');
			document.writeln('</table>');
			
			document.write('<iframe id="rte' + name + '" name="rte' + name + '" width="' + width + 'px" height="' + height + 'px" ');
			if (hasError) {
				document.write('class="error_field" ');			
			}
			document.writeln('></iframe>');
			document.writeln('<iframe width="154" height="104" id="cp' + name + '" name="cp' + name + '" marginwidth="0" marginheight="0" scrolling="no" style="visibility:hidden; position: absolute;"></iframe>');
			document.writeln('</div>');			
		}
	
		this.insertLink =function(lien){
			if (lien !='')
				var url = 'javascript:openLink("' + lien + '")';
				this.contentFrame.execCommand('createLink', lien);
			return;
		} 
		
		this.selectFont = function(sel) {
			var idx = sel.selectedIndex;			
			// First one is always a label
			if (idx != 0) {
				var selected = sel.options[idx].value; 
				idx = sel.id.indexOf("_");
				var cmd = sel.id.substring(0,idx);
			}
			if (selected == "$PF1") {
				this.contentFrame.execCommand("forecolor", "#000066");
				this.contentFrame.execCommand("fontname", "Georgia, Palatino");
				this.contentFrame.execCommand("fontsize", 3);
			}
			else if (selected == "$PF2") {
				this.contentFrame.execCommand("forecolor", "#000066");
				this.contentFrame.execCommand("fontname", "Georgia, Palatino");
				this.contentFrame.execCommand("fontsize", 4);
				this.contentFrame.execCommand("italic");
			}
			else if (selected == "$PF3") {
				this.contentFrame.execCommand("forecolor", "#CC0000");
				this.contentFrame.execCommand("fontname", "Georgia, Palatino");
				this.contentFrame.execCommand("fontsize", 4);
				this.contentFrame.execCommand("underline");
				this.contentFrame.execCommand("italic");
				this.contentFrame.execCommand("normal");
			}
			else {
				this.contentFrame.execCommand(cmd, selected);
			}
			sel.selectedIndex = 0;
		}
	
		this.btn = function(command,button) {
			if ( command == "hilitecolor" || command == "forecolor") {
				this.popupColorPalette(command,button);
			} 
			else if ( command == "link")  {
				if (this.contentFrame.getSelectionRange()==''){
					alert("Sélectionnez d'abord une portion de texte à convertir en lien.");
				}
				else openLien(this);
			} else {
				this.contentFrame.execCommand(command,"");
			}
		}
	
		this.beforeSubmit = function(frm) {
			if ( this.isRichTextEdit)
				this.eElement.value = cleanUpHTML(this.contentFrame.getBodyContent());
			return true;
		}
	
		this.bind = function (frm) {
			this.eElement = frm[this.id];
			if ( typeof(this.eElement) == "undefined" ) {
				// form sliced into multi forms dues to EPS
				this.eElement = this.form.submitForm[this.id];
			}
			if ( this.isRichTextEdit ) {
				this.eElement.style.display = "none";  	 	
				this.contentFrame = new IFrameObj("rte" + this.id,true);
				this.contentFrame.bind();
				if ( this.domain != null )
						this.contentFrame.setDomain(this.domain);
				this.contentFrame.writeDocument(rteInitialDoc(this.getValue()),true);
				this.colorPalette = new IFrameObj("cp" + this.id,true);
				this.colorPalette.bind();
				if ( this.domain != null ) 
					this.colorPalette.setDomain(this.domain);
				this.colorPalette.writeDocument(colorPalettedContent(),false);
				if ( this.domain != null ) {
					document.domain = this.domain;
				}
			} 
		}
	
		this.popupColorPalette = function(command,btn) {
			this.range = this.contentFrame.getSelectionRange();
			var iLeftPos = getOffsetLeft(btn,"rteRoot");
			var iTopPos = getOffsetTop(btn,"rteRoot");
			this.colorPalette.setLeft((iLeftPos-200) + "px");
			// ajouté chrome
			if (client.chrome) {			
//this.colorPalette.setTop((iTopPos-250) + "px");
				if (iTopPos<200) {
					this.colorPalette.setTop((iTopPos-155) + "px");
				}
				else if (iTopPos<300){
					this.colorPalette.setTop((iTopPos-250) + "px");
				}
				else if (iTopPos<500){
					this.colorPalette.setTop((iTopPos-280) + "px");
				}
				else {
					this.colorPalette.setTop((iTopPos-75) + "px");
				}
			}
			if ((command == rteCommand) && (this == rteActive)) {
				//if current command dialog is currently open, close it
				this.colorPalette.toggleVisibility();
			} else {
				this.colorPalette.setVisibility("show");
			}
			//save current values
			rteCommand = command;
			rteActive = this;
		}
	
		this.setColor=function(command,color) {
			if (document.all) {
				if (command == "hilitecolor") command = "backcolor";
				//retrieve selected range
				this.range.select();
			}
			this.contentFrame.execCommand(command,color);
			this.colorPalette.setVisibility("hide");
		}
	
		function rteInitialDoc(html) {
			var frameHtml = "<html>\n";
			frameHtml += "<head>\n";
			frameHtml += "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\"/>\n";
			//to reference your stylesheet, set href property below to your stylesheet path and uncomment
			if ( this.css != null ) {
				frameHtml += '<link href="' + css + '" rel="stylesheet" type="text/css">';
				frameHtml += '<link href="' + localeCss + '" rel="stylesheet" type="text/css">';
			}
			frameHtml += "<style>\n";
			frameHtml += "body {\n";
			frameHtml += "	background: #FFFFFF;\n";
			frameHtml += "	margin: 0px;\n";
			frameHtml += "  text-align:left;\n";
			frameHtml += "  padding-left:0 0 0 4px;\n";
			frameHtml += "  font-family:Georgia, Palatino, Verdana, Arial, Helvetica, sans-serif;\n"; 
			frameHtml += "  font-size:16px;\n"; 
			frameHtml += "  color:#000066;\n"; 
			frameHtml += "}\n";
			frameHtml += " p {margin-top:0;margin-bottom:0; font-family:Georgia, Palatino, Verdana, Arial, Helvetica, sans-serif; color:#000066; font-size:16px;}\n"; 
			frameHtml += "}\n"; 
			frameHtml += "</style>\n";
			frameHtml += "</head>\n";
			frameHtml += "<body class='richBody'>\n";
			frameHtml += html + "\n";
			frameHtml += "</body>\n";
			frameHtml += "</html>";
			return frameHtml;
		}
	
		function colorPalettedContent() {
			var str = '<html><head></head>';
	
			str += '<body onload=parent.InitColorPalette(document) bgcolor="white" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0" topmargin="0" bottommargin="0">';
			str += '<table width="150" height="100" cellpadding="0" cellspacing="1" border="1" align="center">';
				for(var i = 0; i < bgColors.length; i++ ) {
				str += '<tr>';
				var row = bgColors[i];
				for(var j = 0; j < row.length; j++) {
					str += '<td id="' + row[j] + '" bgcolor="' + row[j] + '" width="10" height="10"><img width="1" height="1"></td>';
				}
				str += '</tr>';
			} 
			str += '</table></body></html>';
			return str;
		}
		
		function cleanUpHTML(htmlContent) {
			if (document.all) { 
				htmlContent = htmlContent.replace(/<P([^>]*)>/gi, '<DIV $1>') ; 
				htmlContent = htmlContent.replace(/<\/P>/gi, '</DIV>') ; 
					
				//MSHTML (IE) auto-detects URLs and make them click-able!! Undo it.
				//var regEx = new RegExp('<A.? href=\"(http|https|ftp|gopher|new|snews|telnet|wasis|file|nntp|newsrc|ldap|ldaps|outlook|mic|url){1}(\:){1}(\/\/)?([^\"]+)\">[^<]*</A>','gi');
				//htmlContent = htmlContent.replace(regEx, ' $1$2$3$4 ');
				//var regEx = new RegExp('<a.*href=[\"|\'](http|https|ftp|gopher|new|snews|telnet|wasis|file|nntp|newsrc|ldap|ldaps|outlook|mic|url){1}(\:){1}(\/\/)*([^(\"|\')]+)[\"|\'].*>([^<]*)</a>','gi');
				//var regEx = new RegExp('<a[^>]+?>(.*?)</a>','gi');
				//htmlContent = htmlContent.replace(regEx, ' $1$2$3$4 ');
				//var regEx = new RegExp('<A.? href=\"mailto:([^\"]+)\">[^<]*</A>','gi');
				//htmlContent = htmlContent.replace(regEx, ' $1 ');
			}
			var regEx = new RegExp('<\\?xml:namespace [^>]*>','gi');
			htmlContent = htmlContent.replace(regEx, ' ');
			
			//Remove newlines otherwise backend will add extra <p> per newline.
			htmlContent = htmlContent.replace(/\n/g," ");
			htmlContent = htmlContent.replace(/\r/g," ");
			htmlContent = htmlContent.replace(/\f/g," ");
	
			//Asian countries disreagrd <strong>, only work with <b>
			htmlContent = htmlContent.replace(/<STRONG>/gi, '<B>'); 
			htmlContent = htmlContent.replace(/<\/STRONG>/gi, '</B>'); 
	
			//Windows Word return tags
			htmlContent = htmlContent.replace(/<o:p>/gi,  " "); 
			htmlContent = htmlContent.replace(/<\/o:p>/gi, " "); 
			return htmlContent;
		}
	}
RichTextEdit.prototype.type = "RichTextEdit";
var rteInit = false;

var bgColors = [
		["#FFFFFF","#FFCCCC","#FFCC99","#FFFF99","#FFFFCC","#99FF99","#99FFFF","#CCFFFF","#CCCCFF","#FFCCFF"],
		["#CCCCCC","#FF6666","#FF9966","#FFFF66","#FFFF33","#66FF99","#33FFFF","#66FFFF","#9999FF","#FF99FF"],
		["#C0C0C0","#FF0000","#FF9900","#FFCC66","#FFFF00","#33FF33","#66CCCC","#33CCFF","#6666CC","#CC66CC"],
		["#999999","#CC0000","#FF6600","#FFCC33","#FFCC00","#33CC00","#00CCCC","#3366FF","#6633FF","#CC33CC"],
		["#666666","#990000","#CC6600","#CC9933","#999900","#009900","#339999","#3333FF","#6600CC","#993399"],
		["#333333","#660000","#993300","#996633","#666600","#006600","#336666","#000099","#333399","#663366"],
		["#000000","#330000","#663300","#663333","#333300","#003300","#003333","#000066","#330099","#330033"]];

function InitColorPalette(doc) {
	if (doc.getElementsByTagName)
		var x = doc.getElementsByTagName('TD');
	else if (doc.all)
		var x = doc.all.tags('TD');
	for (var i=0; i < x.length; i++) {
		x[i].onmouseover = over;
		x[i].onmouseout = out;
		x[i].onclick = click;
	}
}

function over() {
	this.style.border = '1px dotted white';
}

function out() {
	this.style.border = '1px solid gray';
}

function click() {
	rteActive.setColor(rteCommand,this.id);
}

var rteCommand = null;
var rteActive = null;

function subAreaChanged() {
	var sa = SubAreaObj.getValue();
	NeighborhoodObj.replaceOptions(subLocationArrays[sa]);
}

function initNeighborHood() {
	var nh = NeighborhoodObj.getValue();
	subAreaChanged();
	NeighborhoodObj.setValue(nh);
}

function replaceContent(id,content) {
	var element = document.getElementById(id);
	if ( element != null ) {
		element.innerHTML = content;
	}
}
