	/* HABYeditor2007 2007.09.15.SBVF4ZEHJD */

	var _eVersion    = 'HABYeditor2007F.37.6b';

	var _IsMSIE      = (navigator.userAgent.indexOf('MSIE') > -1)   ? true : false; /* ie      */
	var _IsGecko     = (navigator.userAgent.indexOf('Gecko') > -1)  ? true : false; /* firefox */
	var _IsOpera     = (navigator.userAgent.indexOf('Opera') > -1)  ? true : false; /* opera   */
	var _IsSafari    = (navigator.userAgent.indexOf('Safari') > -1) ? true : false; /* safari  */

	var _eArrPopup   = new Array(); /* fireFox, opera */
	var _eOpenWindow = new Array();	/* fireFox, opera */
	var _eInnerMedia = new Array();	/* upload media   */

	var _eBasePath   = (document.getElementsByTagName('SCRIPT')['HABYEditor'].src) ? document.getElementsByTagName('SCRIPT')['HABYEditor'].src : null;

	if(_eBasePath)
	{
		 _eBasePath = _eBasePath.substring(0, _eBasePath.lastIndexOf('/'));
	}

	function _Include(srcUrl)
	{
		document.write('<script type="text/javascript" src="' + srcUrl + '"><\/script>');
	}

	_Include(_eBasePath + '/conf/setdomain.conf.js');
	_Include(_eBasePath + '/conf/setconfig.conf.js');
	_Include(_eBasePath + '/htmlarea/class/getelement.class.js');
	_Include(_eBasePath + '/htmlarea/class/getxhtml.class.js');
	_Include(_eBasePath + '/htmlarea/class/getconvert.class.js');
	_Include(_eBasePath + '/htmlarea/class/getstring.class.js');

	/* editor object */
	var HABYeditor = function(eId)
	{
		this.__eId     = eId;
		this.setConfig = new Object();
	}

	/* editor frmae replace */
        HABYeditor.prototype.Create = function ()
	{
		var activeEditor = this;
		var oTextarea    = _GetE(document, this.__eId, 'TEXTAREA', false);

		if(oTextarea)
		{
			oTextarea.cfg           = new HABYconfig(this.__eId, this.setConfig);
			oTextarea.style.display = 'none';
		}
		else
		{
			return;
		}

                
		if(_eBasePath && this.IsCompatible())
		{
			/* editor config */
			this.__cfg = oTextarea.cfg;

			/* editor stylesheet */
			var oStyle = '<link href="' + this.__cfg.StylePath + this.__cfg.MainStyle +'" rel="stylesheet" type="text/css" />';

			/* editor ifrmae */
			var oFrame = '<iframe id="' + this.__eId + '_HABYEditor" name="' + this.__eId + '_HABYEditor" src="' + _eBasePath + '/htmlarea/habyeditor.htm?id=' + this.__eId + '&lang=' + this.__cfg.Language + '" width="' + this.__cfg.Width + '" height="' + this.__cfg.Height + '" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="z-index:' + this.__cfg.BoxIndex + ';"></iframe>';

			/* editor replace */
			if(oTextarea.insertAdjacentHTML)	/* IE      */
			{
				oTextarea.insertAdjacentHTML('beforeBegin', oStyle);
				oTextarea.insertAdjacentHTML('beforeBegin', oFrame);
			}
			else		/* FireFox */
			{
				var oRange = document.createRange();
				oRange.setStartBefore(oTextarea);

				var cStyle = oRange.createContextualFragment(oStyle);
				oTextarea.parentNode.insertBefore(cStyle, oTextarea);

				var cFrame = oRange.createContextualFragment(oFrame);
				oTextarea.parentNode.insertBefore(cFrame, oTextarea);

			}

			/* toggle html checkbox */
			this.HTMLCheck();
		}
	}

	/* toggle html mode */
        HABYeditor.prototype.HTMLCheck = function ()
	{
		/* toggle html checkbox */
		if(this.__cfg.ToggleHtmlId && _GetE(document, this.__cfg.ToggleHtmlId, '', true))
		{
			var oCheckbox = _GetE(document, this.__cfg.ToggleHtmlId, '', true);

			oCheckbox.value = this.__cfg.ToggleHtmlOn;

			if(oCheckbox.type && oCheckbox.type.toLowerCase() == 'checkbox')
			{
				oCheckbox.checked = true;
			}
		}
	}

	/* toggle editing mode */
        HABYeditor.prototype.Mode = function (mode)
	{
		var oTextarea = _GetE(document, this.__eId, 'TEXTAREA', false);

		if(!oTextarea)
		{
			return;
		}

		var oFrame   = _GetE(document, this.__eId + '_HABYEditor', 'IFRAME', false);
		var Htmlarea = this.__cfg.Htmlarea;
		var Textarea = this.__cfg.Textarea;

		if(mode == 0 || oTextarea.style.display == 'none')
		{
			if(this.__cfg.HtmlMode == true)
			{
				var nowContent = _HTMLtoTEXT(Htmlarea.contentWindow.document, this.__cfg.EnableXHTML, this.__cfg.RelativeURL);
			}
			else
			{		
				var nowContent = Textarea.value;
			}

			var tmpContent = nowContent.toLowerCase().trim();

			tmpContent = tmpContent.replace(/\r\n/g, '');
			tmpContent = tmpContent.replace(/&nbsp;/g, '');

			if(tmpContent == '' || /^\s*(<br>|<br\s*\/>|<p>&nbsp;<\/p>||<p><\/p>|<div><\/div>|<div>&nbsp;<\/div>)\s*$/.test(tmpContent))
			{
				nowContent = '';
			}

			oTextarea.value = nowContent.htmlformat(this.__cfg.EnableFormat);

			oFrame.style.display    = 'none';
			oTextarea.style.display = '';
		}
		else
		{
			if(Htmlarea.style.display == 'none')
			{
				Textarea.value = oTextarea.value;
			}
			else
			{
				Htmlarea.contentWindow.document.body.innerHTML = _TEXTtoHTML(oTextarea.value, this.__cfg.IconsPath, this.__cfg.RelativeURL);
			}

			this.HTMLCheck();

			oFrame.style.display    = '';
			oTextarea.style.display = 'none';
		}
	}

        HABYeditor.prototype.IsCompatible = function()
	{
		if(typeof(document.execCommand) == 'undefined')
		{
			return false;
		}

		if(_IsMSIE)
		{
			if(navigator.appVersion.match(/MSIE (.\..)/)[1] >= 6.0)
			{
				return true;
			}
		}

		if(_IsGecko && !_IsSafari)
		{
			if(navigator.productSub >= 20030101)
			{
				return true;
			}
		}

		if(_IsOpera)
		{
			if(navigator.appVersion.split(' (')[0] >= 9.00)
			{
				return true;
			}
		}

		if(_IsSafari)
		{
			return true;
		}

		return false;
	}

