﻿// =============================================================================
// edit-on(R) Pro by RealObjects
// Version 4.1.81, 2004-12-17
// Copyright (c) 2000-2004, RealObjects GmbH. All rights reserved.
// Visit http://www.realobjects.com for more information.
// =============================================================================

// =============================================================================
// Global variables
// =============================================================================

// Enable/disable debug mode
var debug =  true;

// =============================================================================
// Main constructor
// =============================================================================

var eopInstances = new Array();
var eopInstance = 0;

function editOnPro(width, height, appletName, id, eopobj) {
	
	// Determines whether caching should be active or not. Default is true.
	this.caching = true;
	// edit-on Pro version to be cached
	this.cacheVersion = "4.1.81.0";

	// Basic applet configuration
	this.width = width;
	this.height = height;
	this.appletName = appletName;

	// Name of the editOnPro object
	this.eopobj = eopobj;
	// Event handler
	this.handler = this.eopobj+".pumpEvents";
	// Enable auto-download of the JRE by default
	this.isJREAutoDownloadEnabled = true;

	// Applet id is set to the applet's name if no id was specified
	if(id) {
		this.id = id;
	} else {
		this.id = this.appletName;
	}

	// The applet's archive atribute
	this.archive = "edit-on-pro-4.jar";
	this.cacheArchive = this.archive+";"+this.cacheVersion;

	// The applet's codebase atribute
	this.codebase = "";

	// The applet's code attribute
	this.code = "com.realobjects.eop.japplet.SwingEditorApplet";

	// Applet params are set using the setParam() method
	this.params = "";
	this.attribs = "";

	// Browser detection variables
	this.isIE52 = false;
	this.errorMsg = "";
	this.isMSIE = false;
	this.isMac = false;

	// Javascript API methods
	this.getCurrentElement = EOP_getCurrentElement;
	this.getCurrentElementContent = EOP_getCurrentElementContent;
	this.getHeadElementContent = EOP_getHeadElementContent;
	this.getHTMLData = EOP_getHTMLData;
	this.getPlainText = EOP_getPlainText;
	this.getSelectedHTMLData = EOP_getSelectedHTMLData;
	this.getStyleSheet = EOP_getStyleSheet;
	this.getCustomField = EOP_getCustomField;
	this.getEncoding = EOP_getEncoding;
	this.getGetErrorTarget = EOP_getGetErrorTarget;
	this.getGetErrorURL = EOP_getGetErrorURL;
	this.getGetHTMLDataURL = EOP_getGetHTMLDataURL;
	this.getGetOKTarget = EOP_getGetOKTarget;
	this.getGetOKURL = EOP_getGetOKURL;
	this.getExportAsNumerical = EOP_getExportAsNumerical;
	this.getLocaleCode = EOP_getLocaleCode;
	this.getLocaleURL = EOP_getLocaleURL;
	this.getNewDocumentDialog = EOP_getNewDocumentDialog;
	this.getSourceView = EOP_getSourceView;
	this.getSetErrorTarget = EOP_getSetErrorTarget;
	this.getSetErrorURL = EOP_getSetErrorURL;
	this.getSetOKTarget = EOP_getSetOKTarget;
	this.getSetOKURL = EOP_getSetOKURL;
	this.getImageBase = EOP_getImageBase;
	this.getCharWithSpacesStatistic = EOP_getCharWithSpacesStatistic;
	this.getCharNoSpacesStatistic = EOP_getCharNoSpacesStatistic;
	this.getWordsStatistic = EOP_getWordsStatistic;
	this.getImagesStatistic = EOP_getImagesStatistic;
	this.getLinesStatistic = EOP_getLinesStatistic;
	this.getParagraphsStatistic = EOP_getParagraphsStatistic;
	this.getStatistics = EOP_getStatistics;
	this.getReadOnly = EOP_getReadOnly;
    this.getDTDBase = EOP_getDTDBase;
    this.getActiveSpellChecker = EOP_getActiveSpellChecker;
	
	this.insertCustomTag = EOP_insertCustomTag;
	this.insertImage = EOP_insertImage;
	this.insertHTMLData = EOP_insertHTMLData;
	this.insertHTMLDataFromURL = EOP_insertHTMLDataFromURL;
	this.uploadImages = EOP_uploadImages;
	
	this.addStyleSheet = EOP_addStyleSheet;
	this.cleanStyleSheet = EOP_cleanStyleSheet;
	this.clear = EOP_clear;
	this.decode = EOP_decode;
	this.encode = EOP_encode;
	this.hasContentChanged = EOP_hasContentChanged;
	this.postDocumentToServer = EOP_postDocumentToServer;

	this.setCurrentElementContent = EOP_setCurrentElementContent;
	this.setHeadElementContent = EOP_setHeadElementContent;
	this.setHTMLData = EOP_setHTMLData;
	this.setHTMLDataFromURL = EOP_setHTMLDataFromURL;
	this.setStyleSheet = EOP_setStyleSheet;
	this.setStyleSheetURL = EOP_setStyleSheetURL;
	this.showWYSIWYGAreaOnly = EOP_showWYSIWYGAreaOnly;
	this.setLookAndFeel = EOP_setLookAndFeel;
	this.setTemplate = EOP_setTemplate;
	this.setTemplateURL = EOP_setTemplateURL;
	this.setEncoding = EOP_setEncoding;
	this.setGetErrorTarget = EOP_setGetErrorTarget;
	this.setGetErrorURL = EOP_setGetErrorURL;
	this.setGetHTMLDataURL = EOP_setGetHTMLDataURL;
	this.setGetOKTarget = EOP_setGetOKTarget;
	this.setGetOKURL = EOP_setGetOKURL;
	this.setExportAsNumerical = EOP_setExportAsNumerical;
	this.setLocaleCode = EOP_setLocaleCode;
	this.setLocaleURL = EOP_setLocaleURL;
	this.setNewDocumentDialog = EOP_setNewDocumentDialog;
	this.setSourceView = EOP_setSourceView;
	this.setSetErrorTarget = EOP_setSetErrorTarget;
	this.setSetErrorURL = EOP_setSetErrorURL;
	this.setSetOKTarget = EOP_setSetOKTarget;
	this.setSetOKURL = EOP_setSetOKURL;
	this.setStartUpScreenBackgroundColor = EOP_setStartUpScreenBackgroundColor;
	this.setStartUpScreenTextColor = EOP_setStartUpScreenTextColor;
	this.setConfigURL = EOP_setConfigURL;
	this.setUIConfigURL = EOP_setUIConfigURL;
	this.setOnEditorLoaded = EOP_setOnEditorLoaded;
	this.setImageBase = EOP_setImageBase;
	this.setStandAloneMode = EOP_setStandAloneMode;
	this.setLicenseKey = EOP_setLicenseKey;
	this.setOnDataLoaded = EOP_setOnDataLoaded;
	this.setOnDataPosted = EOP_setOnDataPostedError;
	this.setOnDataPostedError = EOP_setOnDataPostedError;
	this.setCaretAtDocumentStart = EOP_setCaretAtDocumentStart;
	this.setCustomField = EOP_setCustomField;
	this.setElementAttributes = EOP_setElementAttributes;
	this.setReadOnly = EOP_setReadOnly;
	this.setConfig = EOP_setConfig;
	this.setUIConfig = EOP_setUIConfig;
	this.setCookie = EOP_setCookie;
	this.setHeartBeatURL = EOP_setHeartBeatURL;
	this.setHeartBeatInterval = EOP_setHeartBeatInterval;
    this.setDTDBase = EOP_setDTDBase;
    this.setActiveSpellChecker = EOP_setActiveSpellChecker;
    this.setDebug = EOP_setDebug;
	
	// Configuration of the auto-download of the JRE in Win IE
	this.setJREAutoDownloadURL = EOP_setJREAutoDownloadURL;
	this.setJREAutoDownload = EOP_setJREAutoDownload;
	this.jreAutoDownloadURL = "http://java.sun.com/products/plugin/autodl/jinstall-1_4-windows-i586.cab";
	this.jreMinVersion = "#Version=1,4,2";
	this.setJREMinVersion = EOP_setJREMinVersion;

	// Sets the name of the edit-on Pro archive to be loaded
	this.setArchive = EOP_setArchive;
	// Adds an archive to the archives to be loaded
	this.addArchive = EOP_addArchive;
	// Add an applet param
	this.setParam = EOP_setParam;
	// Load the applet
	this.loadEditor = EOP_loadEditor;
	// Set the applet's codebase attribute
	this.setCodebase = EOP_setCodebase;
	// Disable caching
	this.disableCaching = EOP_disableCaching;
	// Object containing the editor
	this.obj = "";
	// Set the object containing the editor
	this.setObj = EOP_setObj;

	// General Helper functions used within this script
	this.getOSInfo = EOP_getOSInfo;
	this.getAppletTag = EOP_getAppletTag;
	this.getArchive = EOP_getArchive;
	this.getLocaleFromBrowser = EOP_getLocaleFromBrowser;

	// Determines whether the browser/OS config is supported
	this.getOSInfo();

	this.started = false;
    this.initialized = false;
	this.registerMethod = EOP_registerMethod;
	this.unReg = EOP_unReg;
	this.pumpEvents = EOP_pumpEvents;
	this.initializeJS = EOP_initializeJS;

	this.sequence = new Array();
	this.args = new Array();
	this.seq = 0;

	this.doSetStyleSheet = EOP_doSetStyleSheet;
	this.doInsertHTMLData = EOP_doInsertHTMLData;
	this.doInsertHTMLDataFromURL = EOP_doInsertHTMLDataFromURL;
	this.doSetHTMLDataFromURL = EOP_doSetHTMLDataFromURL;
	this.doSetHTMLData = EOP_doSetHTMLData;
	this.doPostDocumentToServer = EOP_doPostDocumentToServer;
	this.doInsertImage = EOP_doInsertImage;
	this.doClear = EOP_doClear;
	this.doInsertCustomTag = EOP_doInsertCustomTag;
	this.doAddStyleSheet = EOP_doAddStyleSheet;
	this.doSetStyleSheetURL = EOP_doSetStyleSheetURL;
	this.doCleanStyleSheet = EOP_doCleanStyleSheet;
	this.doSetCurrentElementContent = EOP_doSetCurrentElementContent;
	this.doSetHeadElementContent = EOP_doSetHeadElementContent;
	this.doShowWYSIWYGAreaOnly = EOP_doShowWYSIWYGAreaOnly;
	this.doSetLookAndFeel = EOP_doSetLookAndFeel;
	this.doSetTemplate = EOP_doSetTemplate;
	this.doSetTemplateURL = EOP_doSetTemplateURL;
	this.doSetCustomField = EOP_doSetCustomField;
	this.doSetEncoding = EOP_doSetEncoding;
	this.doSetGetErrorTarget = EOP_doSetGetErrorTarget;
	this.doSetGetErrorURL = EOP_doSetGetErrorURL;
	this.doSetGetHTMLDataURL = EOP_doSetGetHTMLDataURL;
	this.doSetGetOKTarget = EOP_doSetGetOKTarget;
	this.doSetGetOKURL = EOP_doSetGetOKURL;
	this.doSetSourceView = EOP_doSetSourceView;
	this.doSetSetErrorTarget = EOP_doSetSetErrorTarget;
	this.doSetSetErrorURL = EOP_doSetSetErrorURL;
	this.doSetSetOKTarget = EOP_doSetSetOKTarget;
	this.doSetSetOKURL = EOP_doSetSetOKURL;
	this.doSetImageBase = EOP_doSetImageBase;
	this.doSetStandAloneMode = EOP_doSetStandAloneMode;
	this.doUploadImages = EOP_doUploadImages;
	this.doSetCaretAtDocumentStart = EOP_doSetCaretAtDocumentStart;
	this.doSetElementAttributes = EOP_doSetElementAttributes;
	this.doSetReadOnly = EOP_doSetReadOnly;
	this.doSetCookie = EOP_doSetCookie;
    this.doSetDTDBase = EOP_doSetDTDBase;
    this.doSetActiveSpellChecker = EOP_doSetActiveSpellChecker;
	
	//getElementAttributes
	this.getElementAttributes = EOP_getElementAttributes;
	
	// image upload
	this.imageUploadStateHandler = EOP_imageUploadStateHandler;
	this.userImageUploadHandler = "";
	
}

// =============================================================================
// Public methods
// =============================================================================

// Sets the archive to be loaded
function EOP_setArchive(strArchive) {
	if(this.caching) {
		this.cacheArchive = strArchive+";"+this.cacheVersion;
	} else {
		this.archive = strArchive;
	}
}

function EOP_addArchive(sArc,sVer) {
	this.cacheArchive = this.cacheArchive+","+sArc+";"+sVer;
	this.archive = this.archive+","+sArc;
}

// Loads the applet
function EOP_loadEditor() {
	// Determines whether to enable caching or not
	this.getArchive();
    // Enables the JRE progress bar
    this.setParam("progressbar","true");
    this.setParam("boxmessage","");
	// Builds the applet tag
	this.getAppletTag();
}

// Adds a param to the applet tag
function EOP_setParam(name, value) {
	this.params += '<param name="'+name+'" value="'+value+'" />\n';
	this.attribs += ' '+name+'="'+value+'"';
}

// Sets the applet's codebase
function EOP_setCodebase(sCodebase) {
	this.codebase  = sCodebase;
}

// Disable applet caching
function EOP_disableCaching() {
	this.caching = false;
}

// Sets the background color displayed while the applet is loading
function EOP_setStartUpScreenBackgroundColor(strColor) {
	this.setParam("startupscreenbackgroundcolor",strColor);
	this.setParam("boxbgcolor",strColor);
}

// Sets the foreground and text color displayed while the applet is loading
function EOP_setStartUpScreenTextColor(strColor) {
	this.setParam("startupscreentextcolor",strColor);
	this.setParam("boxfgcolor",strColor);
}

function EOP_pumpEvents() {
	if(this.initialized) {
		for(var prop in this.sequence) {
			if(this.sequence[prop]!=null) {
				this.sequence[prop](this,prop);
				return null;
			}
		}
		if(this.oneditorloaded!=null) {
			eval(this.oneditorloaded+"()");
			this.oneditorloaded = null;
			return null;
		}
	}
}

function EOP_setJREAutoDownload(bAutoDL) {
	this.isJREAutoDownloadEnabled = bAutoDL;
}

function EOP_setJREAutoDownloadURL(sURL) {
	this.jreAutoDownloadURL = sURL;
}

function EOP_setJREMinVersion(sVer) {
	this.jreMinVersion = "#Version="+sVer;
}

// =============================================================================
// Private methods
// =============================================================================

// Set the object containing the editor
function EOP_setObj() {
	// Object containing the editor
	this.obj = document.applets[this.appletName];
}

// Builds the applet tag
function EOP_getAppletTag() {
	appletTag='';
	if(this.errorMsg=="") {
		if(this.isMSIE) {
			appletTag+='<object ';
			if(this.isJREAutoDownloadEnabled) {
				appletTag+='classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" ';
				appletTag+='codebase="'+this.jreAutoDownloadURL+this.setJREMinVersion+'" ';
			}
			appletTag+='width="'+this.width+'" height="'+this.height+'" name="'+this.appletName+'" id="'+this.id+'" ';
			appletTag+='>\n';
			appletTag+='<param name="name" value="'+this.appletName+'" />\n';
			appletTag+='<param name="java_codebase" value="'+this.codebase+'" />\n';
			appletTag+='<param name="code" value="'+this.code+'" />\n';
			appletTag+='<param name="mayscript" value="true" />\n';
			appletTag+='<param name="scriptable" value="true" />\n';
			appletTag+='<param name="jsobject" value="'+this.eopobj+'" />\n';
			appletTag+=this.params;
			appletTag+='<param name="oneditorloaded" value="'+this.eopobj+'.initializeJS" />';
			appletTag+='</object>';
		} else {
			appletTag+='<applet ';
			appletTag+='code="'+this.code+'.class" ';
			appletTag+='type="application/x-java-applet;version=1.4" ';
			appletTag+='width="'+this.width+'" ';
			appletTag+='height="'+this.height+'" ';
			appletTag+='name="'+this.appletName+'" ';
			appletTag+='id="'+this.id+'" ';
			appletTag+='codebase="'+this.codebase+'" ';
			appletTag+='mayscript="true" ';
			appletTag+='scriptable="true">';
			appletTag+='<param name="oneditorloaded" value="'+this.eopobj+'.initializeJS" />';
			appletTag+='<param name="jsobject" value="'+this.eopobj+'" />\n';
			appletTag+=this.params;
			appletTag+='</applet>';
		}
	} else {
		appletTag+='<div name="'+this.appletDiv+'" align="center"><p>'+this.errorMsg+'</p></div>';
	}
    // Set the started variable to true to prevent the adding of further params
    this.started = true;
	// Create applet tag
	document.write(appletTag);
}

function EOP_getArchive() {
	if(this.caching) {
		this.setParam("cache_archive_ex",this.cacheArchive);
		this.setParam("cache_option","plugin");
	} else {
		this.setParam("archive",this.archive);
	}
}

function EOP_registerMethod(sHandler,arrArgs) {
	this.sequence[this.seq] = sHandler;
	this.args[this.seq] = arrArgs;
	this.seq++;
}

function EOP_unReg(seq) {
    this.sequence[seq] = null;
    this.args[seq] = null;
}

function EOP_initializeJS() {
    this.initialized = true;
	this.setObj();
    this.pumpEvents();
}

// =============================================================================
// JavaScript API SET functions
// =============================================================================

function EOP_setStyleSheet(sStyles) {
	this.registerMethod(this.doSetStyleSheet,EOP_setStyleSheet.arguments);
}

function EOP_doSetStyleSheet(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setStyleSheetAsync(tempSeq[0], clObj.handler);
}

function EOP_insertHTMLData(sData) {
	this.registerMethod(this.doInsertHTMLData,EOP_insertHTMLData.arguments);
}

function EOP_doInsertHTMLData(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.insertHTMLDataAsync(tempSeq[0], clObj.handler);
}

function EOP_setHTMLDataFromURL(sURL) {
	this.registerMethod(this.doSetHTMLDataFromURL,EOP_setHTMLDataFromURL.arguments);
}

function EOP_doSetHTMLDataFromURL(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setHTMLDataFromURLAsync(tempSeq[0], clObj.handler);
}

function EOP_setHTMLData(sData) {
	this.registerMethod(this.doSetHTMLData,EOP_setHTMLData.arguments);
}

function EOP_doSetHTMLData(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setHTMLDataAsync(tempSeq[0], clObj.handler);
}

function EOP_postDocumentToServer() {
	this.registerMethod(this.doPostDocumentToServer,EOP_postDocumentToServer.arguments);
}

function EOP_doPostDocumentToServer(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.postDocumentToServerAsync(clObj.handler);
}

function EOP_insertHTMLDataFromURL(sURL) {
	this.registerMethod(this.doInsertHTMLDataFromURL,EOP_insertHTMLDataFromURL.arguments);
}

function EOP_doInsertHTMLDataFromURL(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.insertHTMLDataFromURLAsync(tempSeq[0], clObj.handler);
}

function EOP_insertImage(sURL, sWidth, sHeight, sBorder, sAlt) {
	this.registerMethod(this.doInsertImage,EOP_insertImage.arguments);
}

function EOP_doInsertImage(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.insertImageAsync(tempSeq[0], tempSeq[1], tempSeq[2], tempSeq[3], tempSeq[4], clObj.handler);
}

function EOP_clear() {
	this.registerMethod(this.doClear,EOP_clear.arguments);
}

function EOP_doClear(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.clearAsync(clObj.handler);
}

function EOP_insertCustomTag(sTagName, sEmpty, sAttributes) {
	this.registerMethod(this.doInsertCustomTag,EOP_insertCustomTag.arguments);
}

function EOP_doInsertCustomTag(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.insertCustomTagAsync(tempSeq[0], tempSeq[1], tempSeq[2], clObj.handler);
}

function EOP_addStyleSheet(sStyles) {
	this.registerMethod(this.doAddStyleSheet,EOP_addStyleSheet.arguments);
}

function EOP_doAddStyleSheet(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.addStyleSheetAsync(tempSeq[0], clObj.handler);
}

function EOP_setStyleSheetURL(sURL) {
	if(this.started) {
		this.registerMethod(this.doSetStyleSheetURL,EOP_setStyleSheetURL.arguments);
	} else {
		this.setParam("stylesheeturl",sURL);
	}
}

function EOP_doSetStyleSheetURL(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setStyleSheetURLAsync(tempSeq[0], clObj.handler);
}

function EOP_cleanStyleSheet() {
	this.registerMethod(this.doCleanStyleSheet,EOP_cleanStyleSheet.arguments);
}

function EOP_doCleanStyleSheet(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.cleanStyleSheetAsync(clObj.handler);
}

function EOP_setCurrentElementContent(sCon) {
	this.registerMethod(this.doSetCurrentElementContent,EOP_setCurrentElementContent.arguments);
}

function EOP_doSetCurrentElementContent(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setCurrentElementContentAsync(tempSeq[0], clObj.handler);
}

function EOP_setHeadElementContent(sContent) {
	this.registerMethod(this.doSetHeadElementContent,EOP_setHeadElementContent.arguments);
}

function EOP_doSetHeadElementContent(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setHeadElementContentAsync(tempSeq[0], clObj.handler);
}

function EOP_showWYSIWYGAreaOnly(bShow) {
	if(this.started) {
		this.registerMethod(this.doShowWYSIWYGAreaOnly,EOP_showWYSIWYGAreaOnly.arguments);
	} else {
		this.setParam("showwysiwygareaonly",bShow.toString());
	}
}

function EOP_doShowWYSIWYGAreaOnly(clObj,seq) {
  var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.showWYSIWYGAreaOnlyAsync(tempSeq[0], clObj.handler);
}

function EOP_setLookAndFeel(sLook) {
	if(this.started) {
		this.registerMethod(this.doSetLookAndFeel,EOP_setLookAndFeel.arguments);
	} else {
		this.setParam("lookandfeel",sLook);
	}
}

function EOP_doSetLookAndFeel(clObj,seq) {
  var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setLookAndFeelAsync(tempSeq[0], clObj.handler);
}

function EOP_setTemplate(sTempl) {
	this.registerMethod(this.doSetTemplate,EOP_setTemplate.arguments);
}

function EOP_doSetTemplate(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setTemplateAsync(tempSeq[0], clObj.handler);
}

function EOP_setTemplateURL(sURL) {
	if(this.started) {
		this.registerMethod(this.doSetTemplateURL,EOP_setTemplateURL.arguments);
	} else {
		this.setParam("templateurl",sURL);
	}
}

function EOP_doSetTemplateURL(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setTemplateURLAsync(tempSeq[0], clObj.handler);
}

function EOP_setCustomField(strField) {
	if(this.started) {
		this.registerMethod(this.doSetCustomField,EOP_setCustomField.arguments);
	} else {
		this.setParam("customfield",strField);
	}
}

function EOP_doSetCustomField(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setCustomFieldAsync(tempSeq[0], clObj.handler);
}

function EOP_setEncoding(strEncoding) {
	if(this.started) {
		this.registerMethod(this.doSetEncoding,EOP_setEncoding.arguments);
	} else {
		this.setParam("encoding",strEncoding);
	}
}

function EOP_doSetEncoding(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setEncodingAsync(tempSeq[0], clObj.handler);
}

function EOP_setGetErrorTarget(strGetErrTarget) {
	if(this.started) {
		this.registerMethod(this.doSetGetErrorTarget,EOP_setGetErrorTarget.arguments);
	} else {
		this.setParam("get_error_target",strGetErrTarget);
	}
}

function EOP_doSetGetErrorTarget(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setGetErrorTargetAsync(tempSeq[0], clObj.handler);
}

function EOP_setGetErrorURL(strGetErrURL) {
	if(this.started) {
		this.registerMethod(this.doSetGetErrorURL,EOP_setGetErrorURL.arguments);
	} else {
		this.setParam("get_error_url",strGetErrURL);
	}
}

function EOP_doSetGetErrorURL(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setGetErrorURLAsync(tempSeq[0], clObj.handler);
}

function EOP_setGetHTMLDataURL(strURL) {
	if(this.started) {
		this.registerMethod(this.doSetGetHTMLDataURL,EOP_setGetHTMLDataURL.arguments);
	} else {
		this.setParam("gethtmldataurl",strURL);
	}
}

function EOP_doSetGetHTMLDataURL(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setGetHTMLDataURLAsync(tempSeq[0], clObj.handler);
}

function EOP_setGetOKTarget(strTarget) {
	if(this.started) {
		this.registerMethod(this.doSetGetOKTarget,EOP_setGetOKTarget.arguments);
	} else {
		this.setParam("get_ok_target",strTarget);
	}
}

function EOP_doSetGetOKTarget(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setGetOKTargetAsync(tempSeq[0], clObj.handler);
}

function EOP_setGetOKURL(strURL) {
	if(this.started) {
		this.registerMethod(this.doSetGetOKURL,EOP_setGetOKURL.arguments);
	} else {
		this.setParam("get_ok_url",strURL);
	}
}

function EOP_doSetGetOKURL(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setGetOKURLAsync(tempSeq[0], clObj.handler);
}

function EOP_setSourceView(bView) {
	if(this.started) {
		this.registerMethod(this.doSetSourceView,EOP_setSourceView.arguments);
	} else {
		this.setParam("sourceview",bView.toString());
	}
}

function EOP_doSetSourceView(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setSourceViewAsync(tempSeq[0], clObj.handler);
}

function EOP_setSetErrorTarget(strErrTarget) {
	if(this.started) {
		this.registerMethod(this.doSetSetErrorTarget,EOP_setSetErrorTarget.arguments);
	} else {
		this.setParam("set_error_target",strErrTarget);
	}
}

function EOP_doSetSetErrorTarget(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setSetErrorTargetAsync(tempSeq[0], clObj.handler);
}

function EOP_setSetErrorURL(strURL) {
	if(this.started) {
		this.registerMethod(this.doSetSetErrorURL,EOP_setSetErrorURL.arguments);
	} else {
		this.setParam("set_error_url",strURL);
	}
}

function EOP_doSetSetErrorURL(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setSetErrorURLAsync(tempSeq[0], clObj.handler);
}

function EOP_setSetOKTarget(strOKTarget) {
	if(this.started) {
		this.registerMethod(this.doSetSetOKTarget,EOP_setSetOKTarget.arguments);
	} else {
		this.setParam("set_ok_target",strOKTarget);
	}
}

function EOP_doSetSetOKTarget(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setSetOKTargetAsync(tempSeq[0], clObj.handler);
}

function EOP_setSetOKURL(strURL) {
	if(this.started) {
		this.registerMethod(this.doSetSetOKURL,EOP_setSetOKURL.arguments);
	} else {
		this.setParam("set_ok_url",strURL);
	}
}

function EOP_doSetSetOKURL(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setSetOKURLAsync(tempSeq[0], clObj.handler);
}

function EOP_setImageBase(sURL) {
	this.registerMethod(this.doSetImageBase,EOP_setImageBase.arguments);
}

function EOP_doSetImageBase(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setImageBaseAsync(tempSeq[0], clObj.handler);
}

function EOP_uploadImages(sEvent) {
	this.registerMethod(this.doUploadImages, EOP_uploadImages.arguments);
}

function EOP_doUploadImages(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.userImageUploadHandler = tempSeq[0];
	clObj.obj.uploadImagesAsync("imageUploadStateHandler");
}

function EOP_imageUploadStateHandler(list) {
	func = this.userImageUploadHandler;
	if (list) { 
		values = list.getValuesLength();
		len = list.getListLength();
		outerarr = new Array();
		for (i=0;i<len;i++) {
			innerarr = new Array();
			for (j=0;j<values;j++) {
				innerarr[j] = list.getListValueAt(i,j);
			}
			outerarr[i] = innerarr;
		}
		eval(func+"(outerarr);");	
	} else {
		eval(func+"(false)");
	}
}

function EOP_getImageBase() {
	return this.obj.getImageBase();
}

function EOP_setStandAloneMode(bMode) {
	this.registerMethod(this.doSetStandAloneMode,EOP_setStandAloneMode.arguments);
}

function EOP_doSetStandAloneMode(clObj,seq) {
  var tempSeq=clObj.args[seq];
  clObj.unReg(seq);
  clObj.obj.setStandAloneModeAsync(tempSeq[0], clObj.handler);
}

function EOP_setCaretAtDocumentStart() {
	this.registerMethod(this.doSetCaretAtDocumentStart,EOP_setCaretAtDocumentStart.arguments);
}

function EOP_doSetCaretAtDocumentStart(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setCaretAtDocumentStartAsync(clObj.handler);
}

function EOP_setElementAttributes(arr) {
		this.registerMethod(this.doSetElementAttributes,EOP_setElementAttributes.arguments);
}

function EOP_doSetElementAttributes(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	arr = tempSeq[0];
	hash = clObj.obj.getHashtableWrapper();
	for (prop in arr) {
		hash.putValue(prop,arr[prop]);
	}
	clObj.obj.setElementAttributesAsync(hash, clObj.handler);
}

function EOP_setReadOnly(bOnly) {
	this.registerMethod(this.doSetReadOnly,EOP_setReadOnly.arguments);
}

function EOP_doSetReadOnly(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setReadOnlyAsync(tempSeq[0],clObj.handler);
}

function EOP_setCookie(sCookie) {
	this.registerMethod(this.doSetCookie,EOP_setCookie.arguments);
}

function EOP_doSetCookie(clObj,seq) {
	var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setCookieAsync(tempSeq[0],clObj.handler);
}

function EOP_setDTDBase(sBase) {
    if(this.started) {
        this.registerMethod(this.doSetDTDBase, EOP_setDTDBase.arguments);
    } else {
        this.setParam("dtdbase",sBase);
    }
}

function EOP_doSetDTDBase(clObj,seq) {
    var tempSeq=clObj.args[seq];
	clObj.unReg(seq);
	clObj.obj.setDTDBaseAsync(tempSeq[0],clObj.handler);
}

function EOP_setActiveSpellChecker(sAct) {
    this.registerMethod(this.doSetActiveSpellChecker, EOP_setActiveSpellChecker.arguments);
}

function EOP_doSetActiveSpellChecker(clObj,seq) {
    var tempSeq=clObj.args[seq];
    clObj.unReg(seq);
    clObj.obj.setActiveSpellCheckerAsync(tempSeq[0],clObj.handler);
}

function EOP_setExportAsNumerical(bExpAsNum) {
	this.setParam("exportasnumerical",bExpAsNum.toString());
}

function EOP_setLocaleCode(strLocale) {
	this.setParam("locale",strLocale);
}

function EOP_setLocaleURL(strURL) {
	this.setParam("localeurl",strURL);
}

function EOP_setNewDocumentDialog(bNewDocDlg) {
	this.setParam("newdocumentdialog",bNewDocDlg.toString());
}

function EOP_setConfigURL(sURL) {
	this.setParam("configurl",sURL);
}

function EOP_setUIConfigURL(sURL) {
	this.setParam("uiconfigurl",sURL);
}

function EOP_setOnEditorLoaded(sFunc) {
	this.oneditorloaded = sFunc;
}

function EOP_setLicenseKey(sLic) {
	this.setParam("licensekey",sLic);
}

function EOP_setOnDataLoaded(sFunc) {
	this.setParam("ondataloaded",sFunc);
}

function EOP_setOnDataPosted(sFunc) {
	this.setParam("ondataposted",sFunc);
}

function EOP_setOnDataPostedError(sFunc) {
	this.setParam("ondatapostederror",sFunc);
}

function EOP_setConfig(sConf) {
	this.setParam("config",escape(sConf));
}

function EOP_setUIConfig(sConf) {
	this.setParam("uiconfig",escape(sConf));
}

function EOP_setHeartBeatURL(sURL) {
	this.setParam("heartbeaturl",sURL);
}

function EOP_setHeartBeatInterval(sInt) {
	this.setParam("heartbeatinterval",sInt);
}

function EOP_setDebug(bDbg) {
    this.setParam("debug",bDbg);
}

// =============================================================================
// Javascript API GET functions
// =============================================================================

// getHTMLData function
function EOP_getHTMLData() {
	return this.obj.getHTMLData();
}

// getSelectedHTMLData function
function EOP_getSelectedHTMLData() {
	return this.obj.getSelectedHTMLData();
}

// getPlainText function
function EOP_getPlainText() {
	return this.obj.getPlainText();
}

// hasContentChanged function
function EOP_hasContentChanged() {
	return this.obj.hasContentChanged();
}

// getStyleSheet function
function EOP_getStyleSheet() {
	return this.obj.getStyleSheet();
}

// getCurrentElement function
function EOP_getCurrentElement() {
	return this.obj.getCurrentElement();
}

// getCurrentElementContent function
function EOP_getCurrentElementContent() {
	return this.obj.getCurrentElementContent();
}

// getHeadElementContent function
function EOP_getHeadElementContent() {
	return this.obj.getHeadElementContent();
}

// encode function
function EOP_encode(sDec) {
	return this.obj.encode(sDec);
}

// decode function
function EOP_decode(sEnc) {
	return this.obj.decode(sEnc);
}

// getCustomField function
function EOP_getCustomField() {
	return this.obj.getCustomField();
}

// getEncoding function
function EOP_getEncoding() {
	return this.obj.getEncoding();
}

// getGetErrorTarget function
function EOP_getGetErrorTarget() {
	return this.obj.getGetErrorTarget();
}

// getGetErrorURL function
function EOP_getGetErrorURL() {
	return this.obj.getGetErrorURL();
}

// getGetHTMLDataURL function
function EOP_getGetHTMLDataURL() {
	return this.obj.getGetHTMLDataURL();
}

// getGetOKTarget function
function EOP_getGetOKTarget() {
	return this.obj.getGetOKTarget();
}

// getGetOKURL function
function EOP_getGetOKURL() {
	return this.obj.getGetOKURL();
}

// getExportAsNumerical function
function EOP_getExportAsNumerical() {
	return this.obj.getExportAsNumerical();
}

// getLocaleCode function
function EOP_getLocaleCode() {
	return this.obj.getLocaleCode();
}

// getLocaleURL function
function EOP_getLocaleURL() {
	return this.obj.getLocaleURL();
}

// getNewDocumentDialog function
function EOP_getNewDocumentDialog() {
	return this.obj.getNewDocumentDialog();
}

// getSourceView function
function EOP_getSourceView() {
	return this.obj.getSourceView();
}

// getSetErrorTarget function
function EOP_getSetErrorTarget() {
	return this.obj.getSetErrorTarget();
}

// getSetErrorURL function
function EOP_getSetErrorURL() {
	return this.obj.getSetErrorURL();
}

// getSetOKTarget function
function EOP_getSetOKTarget() {
	return this.obj.getSetOKTarget();
}

// getSetOKURL function
function EOP_getSetOKURL() {
	return this.obj.getSetOKURL();
}

// getCharWithSpacesStatistic function
function EOP_getCharWithSpacesStatistic() {
	return this.obj.getCharWithSpacesStatistic();
}

// getCharNoSpacesStatistic function
function EOP_getCharNoSpacesStatistic() {
	return this.obj.getCharNoSpacesStatistic();
}

// getWordsStatistic function
function EOP_getWordsStatistic() {
	return this.obj.getWordsStatistic();
}

// getImagesStatistic function
function EOP_getImagesStatistic() {
	return this.obj.getImagesStatistic();
}

// getLinesStatistic function
function EOP_getLinesStatistic() {
	return this.obj.getLinesStatistic();
}

// getParagraphsStatistic function
function EOP_getParagraphsStatistic() {
	return this.obj.getParagraphsStatistic();
}

function EOP_getStatistics() {
	hash = this.obj.getStatisticsJS();
	arr = new Array();
	for (i=0;i<hash.getSize();i++) {
		str = hash.getKey(i);
		arr[str] = hash.getValue(str);
	}
	return arr;
}

// getElementAttributes functiion
function EOP_getElementAttributes() {
	hash = this.obj.getElementAttributesJS();
	arr = new Array();
	for (i=0;i<hash.getSize();i++) {
		str = hash.getKey(i);
		arr[str] = hash.getValue(str);
	}
	return arr;
}

function EOP_getReadOnly() {
	return this.obj.getReadOnly();
}

function EOP_getDTDBase() {
    return this.obj.getDTDBase();
}

function EOP_getActiveSpellChecker() {
    return this.obj.getActiveSpellChecker();
}

// =============================================================================
// Helper functions
// =============================================================================

// Print debugging info
function dbg(sDbg) {
	if(debug) {
		alert(sDbg);
	}
}

// Determines whether the browser/OS config is supported
function EOP_getOSInfo() {
	if(navigator.userAgent.indexOf("Mac")!=-1) this.isMac = true;
	if(this.isMac) {
		if(navigator.userAgent.indexOf("Safari")!=-1) {
            num = navigator.userAgent;
            loc = num.lastIndexOf("/")+1;
            num = num.slice(loc,loc+3);
            num = parseInt(num);
			// if Safari < 1.2
            if(num<120) {
                this.errorMsg += "You are using a Safari version below version 1.2. Please upgrade to version 1.2 or better to use edit-on Pro 4.";
            }
		} else {
			this.errorMsg += "You are using an unsupported browser. Only the Safari browser (version 1.2 or better) is Supported on Mac OS";
		}
	} else {
		if(navigator.userAgent.indexOf("MSIE")!=-1) {
			if(navigator.userAgent.indexOf("5.")!=-1||navigator.userAgent.indexOf("6.")!=-1) {
				this.isMSIE = true;
			} else {
				this.errorMsg += "You are using an old version of Internet Explorer which is not supported by edit-on Pro 4. Please upgrade to Internet Explorer 5 or better";
			}
		} else if(navigator.userAgent.indexOf("Netscape/7")!=-1||navigator.userAgent.indexOf("Netscape6")!=-1||navigator.userAgent.indexOf("Firefox")!=-1) {
			//do nothing
		} else if (navigator.userAgent.indexOf("Mozilla/4.7")!=-1) {
			this.errorMsg += "You are using Netscape 4.7 which is not supported. Please contact your system administrator.";
		} else if(navigator.userAgent.indexOf("Mozilla/4.8")!=-1) { 
			this.errorMsg += "You are using Netscape 4.8 which is not supported. Please contact your system administrator.";
		} else if(navigator.userAgent.indexOf("Gecko")!=-1) {
			if(navigator.userAgent.indexOf("0.")!=-1||navigator.userAgent.indexOf("1.0")!=-1||navigator.userAgent.indexOf("1.1")!=-1) {
				this.errorMsg += "You are using an unsupported browser. Please contact your system administrator.";
			}
		} else {
			this.errorMsg += "You are using an unsupported browser. Please contact your system administrator.";
		}
	}
}

// Returns the current locale code that can be used by EOP
function EOP_getLocaleFromBrowser() {
	var language = "";
	if(this.isMSIE) {
		language = navigator.browserLanguage;
	} else {
		language = navigator.language;
	}
	language = language.substr(0,2);
	if(language=="de") {
		return "de_DE";
	} else if(language=="fr") {
		return "fr_FR";
	} else if(language=="es") {
		return "es_ES";
	} else {
		return "en_US";
	}
}
