/* Rich Text Editor */
/* Copyright 2007 Active Media Architects   http://www.activema.com */
function wysiWindow(){
	
	this.rootid = '';
	this.WysiButtonState = [0,0,0];
	this.cmp_frame;
	this.mouseCheck;
	this.outputMethod = 1;
	this.fixNode;
	
	this.evalthis = function(command){
		eval(command);
	}
	
	
	this.wysInit = function(){
		if ( window.parent.document.getElementById('wysiRichText').contentDocument ) {
			this.cmp_frame = window.parent.document.getElementById('wysiRichText').contentDocument;
			this.cmp_frame.getElementsByTagName('body')[0].style.font = '12px Arial, Helvetica, sans-serif';
			var inputString = document.getElementById('wysiPlainTextarea').value;
			if(inputString != ''){
				this.cmp_frame.getElementsByTagName('body')[0].innerHTML = this.bbCode_to_Moz(inputString);
			}
			this.cmp_frame.designMode = "On"; 
		} else {
			this.cmp_frame = window.parent.document.frames['wysiRichText'].document;
			this.cmp_frame.getElementsByTagName('body')[0].style.font = '12px Arial, Helvetica, sans-serif';
			this.cmp_frame.getElementsByTagName('body')[0].contentEditable = true;
			this.cmp_frame.execCommand('LiveResize', false, true);
			var inputString = document.getElementById('wysiPlainTextarea').value;
			if(inputString != ''){
				this.cmp_frame.getElementsByTagName('body')[0].innerHTML = this.bbCode_to_IE(inputString);
			}
		}
		this.mouseCheck = window.setTimeout('wysiText.mouseChecker()', 250);
	}

	this.mouseChecker = function(){
		
		if(!this.disableChecker){
			if ( window.parent.document.getElementById('wysiRichText').contentDocument ) {
				if(window.parent.document.getElementById('wysiRichText').contentWindow.getSelection()){
				var mousePos = window.parent.document.getElementById('wysiRichText').contentWindow.getSelection();
				mousePos = mousePos.getRangeAt(0);
				if(mousePos != this.lastMousePos && window.parent.document.getElementById('wysiRichText').contentWindow.getSelection() == '' ){
					this.getPosition();
					this.lastMousePos = mousePos;
				}
				} 
				
				
			} else {
				var mousePos = document.frames['wysiRichText'].document.selection.createRange();
				if(mousePos != this.lastMousePos && mousePos.text == ''){
					this.getPosition();
					this.lastMousePos = mousePos;
				}
				
			}
		}
		this.mouseCheck = window.setTimeout('wysiText.mouseChecker()', 250);
	}
	this.lastMousePos;
	this.disableChecker = 0;

	this.sendExec = function(cmd, value){
		if ( typeof(value) == 'undefined' ) {
			value = null;
		}
		if ( window.parent.document.getElementById('wysiRichText').contentDocument ) {
			this.cmp_frame.execCommand(cmd, false, value);
		} else if(this.selectionInFrame()) { 
			this.cmp_frame.execCommand(cmd, false, value);
		}
	}

	this.selectionInFrame = function(){
		var node = document.frames['wysiRichText'].document.selection;
		var nodei = ( node.type == "Control" ) ? node.createRange().item(0) : node.createRange().parentElement();
		return (nodei.ownerDocument.location == 'about:blank') ? true : false;
		
	}
	
	this.WysiClickButton = function(type){
		var types = [0, 'bold', 'italic', 'underline'];
		this.sendExec(types[type]);
		document.getElementById('wysiRichText').contentWindow.focus();
		if(this.WysiButtonState[type]){
			this.setWysiButton(type,false);
			this.WysiButtonState[type] = 0;
		} else {
			this.setWysiButton(type,true);
			this.WysiButtonState[type] = 1;
		}
	}

	this.fontsize = function(){
		var selector = document.getElementById('wysiFontsize')
		var i = selector.selectedIndex;
		var value = selector[i].value;
		this.sendExec('fontsize', value);
		window.parent.document.getElementById('wysiRichText').contentWindow.focus();
	}

	this.setWysiFontsize = function(size){
		document.getElementById('wysiFontsize').value = size;
	}


	this.fontcolor = function(){
		if(document.getElementById('wysColorSelect').style.display == 'block'){
			document.getElementById('wysColorSelect').style.display = 'none';
			document.getElementById('wysiRichText').contentWindow.focus();
		} else {
			document.getElementById('wysColorSelect').style.display = 'block';
		}
	}

	this.setWysiButton = function(id, state){
		if(state){
			document.getElementById('wysibutton'+id).style.backgroundColor = '#ccc';
		} else {
			document.getElementById('wysibutton'+id).style.backgroundColor = '';
		}
	}

	this.selectColor = function(hex){
		document.getElementById('wysColorSelect').style.display = 'none';
		document.getElementById('wysFontColor').style.backgroundColor = '#' + hex; 
		if ( document.getElementById('wysiRichText').contentDocument ) {
			this.sendExec( 'forecolor', hex); 
		} else {
			var tr = document.frames['wysiRichText'].document.selection.createRange();
			this.sendExec( 'forecolor', '#' + hex); 
		}
		document.getElementById('wysiRichText').contentWindow.focus();
	}

	
	this.getPosition = function(){
		this.wysStyle.underline = 0;
		this.wysStyle.bold = 0;
		this.wysStyle.italic = 0;
		this.wysStyle.fontsize = 0;
		this.wysStyle.color = 0;
		this.wysStyle.link = '';
		this.wysStyle.list = 0;

		if ( document.getElementById('wysiRichText').contentDocument ) {
			
			var node = document.getElementById('wysiRichText').contentWindow.getSelection().getRangeAt(0).startContainer.parentNode;
			this.walkStyle(node);
			
			var i1 = document.getElementById('wysiRichText').contentWindow.getSelection().getRangeAt(0).startOffset;
			var i2 = document.getElementById('wysiRichText').contentWindow.getSelection().getRangeAt(0).startContainer.length;
			if(i1 == i2 && this.wysStyle.link != '' ){
				// allow ff to leave link
				this.sendExec('unlink');
				this.wysStyle.link = '';
			}
			
			if(this.wysStyle.underline){this.setWysiButton(3,true);}else {this.setWysiButton(3,false);}
			if(this.wysStyle.bold){this.setWysiButton(1,true);}else {this.setWysiButton(1,false);}
			if(this.wysStyle.italic){this.setWysiButton(2,true);}else {this.setWysiButton(2,false);}
			if(this.wysStyle.link != ''){this.setWysiButton(4,true);}else {this.setWysiButton(4,false);}
			if(this.wysStyle.list){this.setWysiButton(5,true);}else {this.setWysiButton(5,false);}
			
			//document.getElementById('wysFontColor').style.backgroundColor = (this.wysStyle.color) ? this.wysStyle.color : '#000000';
			//if(this.wysStyle.fontsize == 0){this.wysStyle.fontsize = 3;}
			//this.setWysiFontsize(this.wysStyle.fontsize);
			
		} else {
			// ie
			var node = document.frames['wysiRichText'].document.selection;
			var nodei = ( node.type == "Control" ) ? node.createRange().item(0) : node.createRange().parentElement();
			this.walkStyleIE(nodei);
			if(this.wysStyle.underline){this.setWysiButton(3,true);}else {this.setWysiButton(3,false);}
			if(this.wysStyle.bold){this.setWysiButton(1,true);}else {this.setWysiButton(1,false);}
			if(this.wysStyle.italic){this.setWysiButton(2,true);}else {this.setWysiButton(2,false);}
			if(this.wysStyle.link != ''){this.setWysiButton(4,true);}else {this.setWysiButton(4,false);}
			if(this.wysStyle.list){this.setWysiButton(5,true);}else {this.setWysiButton(5,false);}
			//document.getElementById(this.rootid+'wysFontColor').style.backgroundColor = (this.wysStyle.color) ? this.wysStyle.color : '#000000';
			//if(this.wysStyle.fontsize == 0){this.wysStyle.fontsize = 3;}
			//this.setWysiFontsize(this.wysStyle.fontsize);
		}
		
	}


	this.wysStyle = Object();
	this.wysStyle.link = '';
	
	this.walkStyle = function(n){ 
		// walk up looking for style changes
		var s = n.style;
		if(s){
			if(s.textDecoration == 'underline'){this.wysStyle.underline = 1;}
			if(s.fontWeight == 'bold'){this.wysStyle.bold = 1;}
			if(s.fontStyle == 'italic'){ this.wysStyle.italic = 1;}
			if(s.color && this.wysStyle.color == 0){this.wysStyle.color = s.color;}
			if(n.size && this.wysStyle.fontsize == 0){this.wysStyle.fontsize = n.size;}
		}
		if(n.tagName == 'A'){this.wysStyle.link = n.href;}
		if(n.tagName == 'LI'){this.wysStyle.list = 1;}
		if(n.tagName != 'BODY' && n.tagName != 'HTML'){
			var parent = n.parentNode; 
			if(parent.tagName != 'BODY'){this.walkStyle(parent);}
		}
	}

	this.walkStyleIE = function(n){
		switch(n.tagName){
			case 'STRONG':
				this.wysStyle.bold = 1; break;
			case 'EM':
			case 'I':
				this.wysStyle.italic = 1; break;
			case 'U':
				this.wysStyle.underline = 1; break;
			case 'FONT':
				if(n.size && this.wysStyle.fontsize == 0){this.wysStyle.fontsize = n.size;}
				if(n.color && this.wysStyle.color == 0){this.wysStyle.color = n.color;}
				break;	
			case 'A':
				this.wysStyle.link = n.href;
				break;
			case 'LI':
				this.wysStyle.list = 1; break;
				
		}
		if(n.tagName != 'BODY' && n.tagName != 'HTML'){
			var parent = n.parentNode; 
			if(parent.tagName != 'BODY'){this.walkStyleIE(parent);}
		}
	}

	this.colorPick = function( e, b){
		if(b == 1){
			if(e.clientX){
				
				var h = e.clientX - document.getElementById('picker').offsetLeft  - document.getElementById(this.rootid+'wysColorSelect').offsetLeft - 4;
				h = 1.0 * h / 100;
				var rgb = this.convertHSVToRGB(h, 1.0, 0.8);
				var hex = this.convertRGBToHex(rgb);
				this.selectColor(hex);
				
			} else {
				
				var h = window.event.clientX - document.getElementById('picker').offsetLeft - document.getElementById(this.rootid+'wysColorSelect').offsetLeft - 4;
				h = 1.0 * h / 100;
				var rgb = this.convertHSVToRGB(h, 1.0, 0.8);
				var hex = this.convertRGBToHex(rgb);
				this.selectColor(hex);
				
			}
		}
	}


	this.convertRGBToHex = function(rgb){
		var ret = ''
		for(var i = 0; i < 3; i++){
			var c = rgb[i];
			if(c == 0){ 
				ret += '00';
			} else {
				ret += "0123456789ABCDEF".charAt((c-c%16)/16) + "0123456789ABCDEF".charAt(c%16);
			}
		}
		return ret;
	}

	this.convertHSVToRGB = function($H, $S, $V){
		$Hi = Math.floor($H*6);
		$f = ($H*6) - $Hi;
		$p = $V * (1 - $S);
		$q = $V * (1 - $f*$S);
		$t = $V * (1 - (1-$f)*$S);
		var $R = 0; var $G = 0; var $B = 0;
		switch($Hi)
		{
			case 0:
				$R = $V*255; $G = $t*255; $B = $p*255;
				break;
			case 1:
				$R = $q*255; $G = $V*255; $B = $p*255;
				break;
			case 2:
				$R = $p*255; $G = $V*255; $B = $t*255;
				break;
			case 3:
				$R = $p*255; $G = $q*255; $B = $V*255;
				break;
			case 4:
				$R = $t*255; $G = $p*255; $B = $V*255;
				break;
			case 5:
				$R = $V*255; $G = $p*255; $B = $q*255;
				break;
		}
		var ret = [Math.round($R), Math.round($G), Math.round($B)];
		return ret;
	}

	this.convertToBBCode = function(){
		if(this.outputMethod == 0){return true;} // no parsing required
		var output = '';
		if ( document.getElementById('wysiRichText').contentDocument ) {
			// walk moz
			output = this.bbCodeWalk(document.getElementById('wysiRichText').contentDocument.getElementsByTagName('body')[0]);
			output = this.cleanBBCode(output);
		} else {
			// walk ie
			output = this.bbCodeWalkIE(document.frames['wysiRichText'].document.getElementsByTagName('body')[0]);
			output = this.cleanBBCode(output);
		}
		document.getElementById('wysiPlainTextarea').value = output;
		document.getElementById('wysiPlainTextarea').style.display='block';
	}
	
	this.cleanBBCode = function(s){
		
		s = s.replace(/\[i\]\[\/i\]/g, '');
		s = s.replace(/\[b\]\[\/b\]/g, '');
		s = s.replace(/\[u\]\[\/u\]/g, '');
		s = s.replace(/\[size=\w{1,2}\]\[\/size\]/g, '');
		s = s.replace(/\[color=#\w{6}\]\[\/color\]/g, '');
		s = s.replace(/\[\/i\]\[i\]/g, '');
		s = s.replace(/\[\/b\]\[b\]/g, '');
		s = s.replace(/\[\/u\]\[u\]/g, '');
		return s;
		
	}
	
	
	this.bbCodeWalk = function(node){ 
		var string = '';
		if(node.hasChildNodes){
			var children = node.childNodes;
			for(c in children){
				var lastTag = '';
				var cn = children[c];
				if(cn.nodeType == 3){
					string += cn.nodeValue;
					
				}
				if(cn.nodeType == 1){
					if(cn.tagName == 'P' && lastTag != 'p'){string += "\n";}
					lastTag = '';
					if(cn.tagName == 'BR'){string += "\n";} 
					if(cn.tagName == 'STRONG'){string += '[b]';}
					if(cn.tagName == 'OL'){string += '[ol]';}
					if(cn.tagName == 'UL'){string += '[list]';}
					if(cn.tagName == 'LI'){string += '[li]';}
					if(cn.size){string += '[size='+(cn.size*4)+']';}
					if(cn.style.color){string += '[color='+this.getStyleColor(cn.style.color)+']'};
					if(cn.style.fontWeight == 'bold'){string += '[b]';}
					if(cn.style.fontStyle == 'italic'){string += '[i]';}
					if(cn.style.textDecoration == 'underline'){string += '[u]';}
					if(cn.href){string += '[url='+cn.href+']';}
					if(cn.src){string += '[img]'+cn.src;}
					string += this.bbCodeWalk(cn);
					if(cn.src){string += '[/img]';}
					if(cn.href){string += '[/url]';}
					if(cn.style.textDecoration == 'underline'){string += '[/u]';}
					if(cn.style.fontStyle == 'italic'){string += '[/i]';}
					if(cn.style.fontWeight == 'bold'){string += '[/b]';}
					if(cn.style.color){string += '[/color]';}
					if(cn.size){string += '[/size]';}
					if(cn.tagName == 'LI'){string += '[/li]';}
					if(cn.tagName == 'UL'){string += '[/list]';}
					if(cn.tagName == 'OL'){string += '[/ol]';}
					if(cn.tagName == 'STRONG'){string += '[/b]';}
					if(cn.tagName == 'P'){string += "\n"; lastTag = 'p';}
				}
			}
		}
		return string;
	}
	
	
	this.bbCodeWalkIE = function(node){ 
		var string = '';
		if(node.hasChildNodes){
			var children = node.childNodes;
			for(c in children){
				var lastTag = '';
				var cn = children[c];
				if(cn.nodeType == 3){
					string += cn.nodeValue;
					
				}
				if(cn.nodeType == 1){
					
					switch(cn.tagName){
						case 'STRONG':
							string += '[b]'; break;
						case 'EM':
							string += '[i]'; break;
						case 'U':
							string += '[u]'; break;
						case 'FONT':
							if(cn.size){string += '[size='+(cn.size*4)+']';}
							if(cn.color){string += '[color='+(cn.color)+']';}
							break;
						case 'A':
							string += '[url='+cn.href+']';break;
						case 'IMG':
							string += '[img]'+cn.src;break;
						case 'OL':
							string += '[ol]'; break;
						case 'UL':
							string += '[list]'; break;
						case 'LI':
							string += '[li]'; break;
						case 'P':	
							if(lastTag != 'p'){string += "\n";} break;
						case 'BR':
							string += "\n";break;
						
					}
					lastTag = '';
					string += this.bbCodeWalkIE(cn);
					
					switch(cn.tagName){
						case 'STRONG':
							string += '[/b]'; break;
						case 'EM':
							string += '[/i]'; break;
						case 'U':
							string += '[/u]'; break;
						case 'FONT':
							if(cn.size){string += '[/size]';}
							if(cn.color){string += '[/color]';}
							break;	
							
						case 'A':
							string += '[/url]'; break;
						case 'IMG':
							string += '[/img]';break;
						case 'UL':
							string += '[/list]'; break;
						case 'OL':
							string += '[/ol]'; break;
						case 'LI':
							string += '[/li]'; break;
						case 'P':	
							string += "\n"; break;
					}
				}
			}
		}
		return string;
	}
	
	
	this.getStyleColor = function(string){
		string = string.substring(4);
		var stringarray = string.split(')');
		var parts = stringarray[0].split(',');
		var ret = '#';
		for(var i = 0; i < 3; i++){
			var c = parseInt(parts[i]);
			if(c == 0){ 
				ret += '00';
			} else {
				ret += "0123456789ABCDEF".charAt((c-c%16)/16) + "0123456789ABCDEF".charAt(c%16);
			}
		}
		return ret;
	}
	
	
	
	this.bbCode_to_Moz = function(s){
		// string to mozilla/FF structure
		
		s = s.replace(/\[i\]\[\/i\]/g, '');
		s = s.replace(/\[b\]\[\/b\]/g, '');
		s = s.replace(/\[u\]\[\/u\]/g, '');
		s = s.replace(/\[size=\w{1,2}\]\[\/size\]/g, '');
		s = s.replace(/\[color=#\w{6}\]\[\/color\]/g, '');
		s = s.replace(/\[list\]\[\/list\]/g, '');
		
		var f;
		do{
			f = s.match(/\[size=\w+\]/);
			if(f != null){
				var fontsize = f[0].match(/size=(\w+)/);
				var size = parseInt(fontsize[1]) / 4;
				var newf = '<font size="'+size+'">'; 
				s= s.replace(f, newf);
			}
		} while (f != null);
		s = s.replace(/\[\/size\]/g, '</font>');

		var c;
		do{
			c = s.match(/\[color=#\w{6}\]/);
			if(c != null){
				var color = c[0].match(/#(\w{6})/);
				var newc = '<span style="color:#'+color[1]+'">';
				s= s.replace(c, newc);
			}
		} while (c != null);
		s = s.replace(/\[\/color\]/g, '</span>');
		
		s = s.replace(/\[i\]/g, '<span style="font-style: italic;">');
		s = s.replace(/\[\/i\]/g, '</span>');
		s = s.replace(/\[b\]/g, '<span style="font-weight: bold;">');
		s = s.replace(/\[\/b\]/g, '</span>');
		s = s.replace(/\[u\]/g, '<span style="text-decoration: underline;">');
		s = s.replace(/\[\/u\]/g, '</span>');
		
		s = s.replace(/\[ol\]/g, '<ol>');
		s = s.replace(/\[\/ol\]/g, '</ol>');
		s = s.replace(/\[list\]/g, '<ul>');
		s = s.replace(/\[\/list\]/g, '</ul>');
		s = s.replace(/\[\*\]/g, '<li>');
		s = s.replace(/\[li\]/g, '<li>');
		s = s.replace(/\[\/li\]/g, '</li>');
		
		s = s.replace(/\n/g, '<br/>');
		
		var L;
		do{
			L = s.match(/\[url=[a-zA-Z0-9_:\.\/\\\+\?\-]+\]/);
			if(L != null){
				var link = L[0].match(/=([a-zA-Z0-9_:\.\/\\\+\?\-]+)\]/);
				var newL = '<a href="'+link[1]+'">';
				s= s.replace(L, newL);
			}
		} while (L != null);
		s = s.replace(/\[\/url\]/g, '</a>');
		
		var I;
		do{
			I = s.match(/\[img\]([a-zA-Z0-9_:\.\/\\\+\?\-]+)\[\/img\]/);
			if ( I != null ) {
				var newI = '<img src="'+I[1]+'" />';
				s = s.replace(I[0], newI);
			}
		} while ( I != null );
		
		return s;
		
	}
	
	this.bbCode_to_IE = function(s){
		// string to IE structure
		
		s = s.replace(/\[i\]\[\/i\]/g, '');
		s = s.replace(/\[b\]\[\/b\]/g, '');
		s = s.replace(/\[u\]\[\/u\]/g, '');
		s = s.replace(/\[size=\w{1,2}\]\[\/size\]/g, '');
		s = s.replace(/\[color=#\w{6}\]\[\/color\]/g, '');
		
		var f;
		do{
			f = s.match(/\[size=\w+\]/);
			if(f != null){
				var fontsize = f[0].match(/size=(\w+)/);
				var size = parseInt(fontsize[1]) / 4;
				var newf = '<font size="'+size+'">'; 
				s= s.replace(f, newf);
			}
		} while (f != null);
		s = s.replace(/\[\/size\]/g, '</font>');
		
		var c;
		do{
			c = s.match(/\[color=#\w{6}\]/);
			if(c != null){
				var color = c[0].match(/#(\w{6})/);
				var newc = '<font color="#'+color[1]+'">';
				s= s.replace(c, newc);
			}
		} while (c != null);
		s = s.replace(/\[\/color\]/g, '</font>');
		
		s = s.replace(/\[i\]/g, '<i>');
		s = s.replace(/\[\/i\]/g, '</i>');
		s = s.replace(/\[b\]/g, '<strong>');
		s = s.replace(/\[\/b\]/g, '</strong>');
		s = s.replace(/\[u\]/g, '<u>');
		s = s.replace(/\[\/u\]/g, '</u>');
		
		
		s = s.replace(/\[ol\]/g, '<ol>');
		s = s.replace(/\[\/ol\]/g, '</ol>');
		s = s.replace(/\[list\]/g, '<ul>');
		s = s.replace(/\[\/list\]/g, '</ul>');
		s = s.replace(/\[\*\]/g, '<li>');
		s = s.replace(/\[li\]/g, '<li>');
		s = s.replace(/\[\/li\]/g, '</li>');
		
		s = s.replace(/\n/g, '<br/>');
		
		var L;
		do{
			L = s.match(/\[url=[a-zA-Z0-9_:\.\/\\\+\?\-]+\]/);
			if(L != null){
				var link = L[0].match(/=([a-zA-Z0-9_:\.\/\\\+\?\-]+)\]/);
				var newL = '<a href="'+link[1]+'">';
				s= s.replace(L, newL);
			}
		} while (L != null);
		s = s.replace(/\[\/url\]/g, '</a>');
		
		var I;
		do{
			I = s.match(/\[img\]([a-zA-Z0-9_:\.\/\\\+\?\-]+)\[\/img\]/);
			if ( I != null ) {
				var newI = '<img src="'+I[1]+'" />';
				s = s.replace(I[0], newI);
			}
		} while ( I != null );
		
		return s;
	}
	
	
	this.WysiClickLinkButton = function(){
		var defaultURL = this.wysStyle.link;
		
		if ( !window.parent.document.getElementById('wysiRichText').contentDocument ) {
			// a fix for IE losing focus
			var range = document.frames['wysiRichText'].document.selection.createRange();
			var range2 = range.duplicate();
			var range3 = range.duplicate();
			range2.setEndPoint('EndToEnd', range);
			var start = range2.text.length - range.text.length;
			var end = start + range.text.length;
			if(start == end){
				alert('Please select text before creating link');
				return;
			}
			this.fixNode = [start, end, range3];
			
		} else {
			var selcheck = document.getElementById('wysiRichText').contentWindow.getSelection();
			if(selcheck == ''){
				alert('Please select text before creating link');
				return;
			}
		}
		document.getElementById('wysiLinkwindow').style.display='';
		document.getElementById('wysiWeblink').value = defaultURL;
	}
	
	this.WysiSubmitLink = function(){
		var url = document.getElementById('wysiWeblink').value;
		if(this.fixNode){
			document.getElementById('wysiRichText').contentWindow.focus();			
			var range = this.fixNode[2];
			range.collapse();
			range.moveStart('character', this.fixNode[0]);
			range.moveEnd('character', this.fixNode[1]);
			range.select();
			this.fixNode = 0;
		}
		if(!url){
			this.sendExec('unlink', url);
			document.getElementById('wysiRichText').contentWindow.focus();
		} else {
			if(url.substr(0,7) != 'http://'){url = 'http://'+url;}
			this.sendExec('createlink', url);
			document.getElementById('wysiRichText').contentWindow.focus();
		}
		document.getElementById('wysiLinkwindow').style.display='none';
	}
	
	this.WysiClickListButton = function(){
		
		this.sendExec('insertunorderedlist', '');
		document.getElementById('wysiRichText').contentWindow.focus();
	}
	
	
	
	
}

var wysiText = new wysiWindow();

function wysiStart(){
	var b = navigator.userAgent.toLowerCase().indexOf('khtml');
	if(b != -1){
		// not supporting rich text 
		wysiText.outputMethod = 0;
		if ( document.getElementById('wysiLiteEditor') ) {
			document.getElementById('wysiLiteEditor').style.display = '';
		}
	} else {
		// supporting
		if ( document.getElementById('wysiPlainText') ) {
			document.getElementById('wysiPlainText').style.display = 'none';
		}
		if ( document.getElementById('wysiEditor') ) {
			document.getElementById('wysiEditor').style.display = '';
		}
		
		if ( document.getElementById('wysiPlainText') || document.getElementById('wysiEditor') ) {
			wysiText.wysInit();
		}
	}
}


function showWysiHelp(){
	document.getElementById('wysiLitePreview').style.display = 'none';
	document.getElementById('wysiLiteHelp').style.display = '';
}

function showWysiPreview(){
	document.getElementById('wysiLiteHelp').style.display = 'none';
	var text = wysiText.bbCode_to_Moz(document.getElementById('wysiPlainTextarea').value);
	text = text.replace(/\n\r/g, '<br/>'); text = text.replace(/\n/g, '<br/>'); text = text.replace(/\r/g, '<br/>');
	document.getElementById('wysiLitePreview').innerHTML = text;
	
	document.getElementById('wysiLitePreview').style.display = '';
}

function hideWysiLite(){
	document.getElementById('wysiLitePreview').style.display = 'none';
	document.getElementById('wysiLiteHelp').style.display = 'none';
}


