Changed newlines of typo3/jsfunc.tbe_editor.js from Windows (\r\n) to Unix (\n) style
authorMichael Stucki <michael.stucki@typo3.org>
Sun, 4 Feb 2007 17:03:14 +0000 (17:03 +0000)
committerMichael Stucki <michael.stucki@typo3.org>
Sun, 4 Feb 2007 17:03:14 +0000 (17:03 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@1973 709f56b5-9817-0410-a4d7-c38de5d9e867

typo3/jsfunc.tbe_editor.js

index 255c8fe..63b3199 100644 (file)
-/***************************************************************\r
-*  Copyright notice\r
-*\r
-*  (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)\r
-*  All rights reserved\r
-*\r
-*  This script is part of the TYPO3 project. The TYPO3 project is\r
-*  free software; you can redistribute it and/or modify\r
-*  it under the terms of the GNU General Public License as published by\r
-*  the Free Software Foundation; either version 2 of the License, or\r
-*  (at your option) any later version.\r
-*\r
-*  The GNU General Public License can be found at\r
-*  http://www.gnu.org/copyleft/gpl.html.\r
-*  A copy is found in the textfile GPL.txt and important notices to the license\r
-*  from the author is found in LICENSE.txt distributed with these scripts.\r
-*\r
-*\r
-*  This script is distributed in the hope that it will be useful,\r
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-*  GNU General Public License for more details.\r
-*\r
-*  This copyright notice MUST APPEAR in all copies of the script!\r
-***************************************************************/\r
-/**\r
- * Contains JavaScript for TYPO3 Core Form generator - AKA "TCEforms"\r
- *\r
- * $Id: $\r
- *\r
- * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>\r
- * @coauthor   Oliver Hader <oh@inpublica.de>\r
- */\r
-\r
-\r
-var TBE_EDITOR = {\r
-       /* Example:\r
-               elements: {\r
-                       'data[table][uid]': {\r
-                               'field': {\r
-                                       'range':                [0, 100],\r
-                                       'rangeImg':             '',\r
-                                       'required':             true,\r
-                                       'requiredImg':  ''\r
-                               }\r
-                       }\r
-               \r
-               },\r
-       */\r
-       \r
-       elements: {},\r
-       recentUpdatedElements: {},\r
-       actionChecks: { submit: [] },\r
-       \r
-       formname: '',\r
-       formnameUENC: '',\r
-       loadTime: 0,\r
-       isChanged: 0,\r
-       auth_timeout_field: 0,\r
-\r
-       backPath: '',\r
-       prependFormFieldNames: 'data',\r
-       prependFormFieldNamesUENC: 'data',\r
-       prependFormFieldNamesCnt: 0,\r
-       \r
-       isPalettedoc: null,\r
-       doSaveFieldName: 0,\r
-       \r
-       labels: {},\r
-       images: {\r
-               req: new Image(),\r
-               cm: new Image(),\r
-               sel: new Image(),\r
-               clear: new Image()\r
-       },      \r
-\r
-       // Handling of data structures:\r
-       addElements: function(elements) {\r
-               TBE_EDITOR.recentUpdatedElements = elements;\r
-               TBE_EDITOR.elements = $H(TBE_EDITOR.elements).merge(elements);\r
-       },\r
-       removeElement: function(record) {\r
-               if (TBE_EDITOR.elements && TBE_EDITOR.elements[record]) {\r
-                       delete(TBE_EDITOR.elements[record]);\r
-               }\r
-       },\r
-       getElement: function(record, field, type) {\r
-               var result = null;\r
-               var element;\r
-               \r
-               if (TBE_EDITOR.elements && TBE_EDITOR.elements[record] && TBE_EDITOR.elements[record][field]) {\r
-                       element = TBE_EDITOR.elements[record][field];\r
-                       if (type) {\r
-                               if (element[type]) result = element;\r
-                       } else {\r
-                               result = element;\r
-                       }\r
-               }\r
-               \r
-               return result;\r
-       },\r
-       checkElements: function(type, recentUpdated, record, field) {\r
-               var result = 1;\r
-               var elementName, elementData, elementRecord, elementField;\r
-               var source = recentUpdated ? TBE_EDITOR.recentUpdatedElements : TBE_EDITOR.elements;\r
-\r
-               if (type) {\r
-                       if (record && field) {\r
-                               elementName = record+'['+field+']';\r
-                               elementData = TBE_EDITOR.getElement(record, field, type);\r
-                               if (elementData) {\r
-                                       if (!TBE_EDITOR.checkElementByType(type, elementName, elementData)) result = 0;\r
-                               }\r
-                               \r
-                       } else {\r
-                               var elementFieldList, elRecIndex, elRecCnt, elFldIndex, elFldCnt;\r
-                               var elementRecordList = $H(source).keys();\r
-                               for (elRecIndex=0, elRecCnt=elementRecordList.length; elRecIndex<elRecCnt; elRecIndex++) {\r
-                                       elementRecord = elementRecordList[elRecIndex];\r
-                                       elementFieldList = $H(source[elementRecord]).keys();\r
-                                       for (elFldIndex=0, elFldCnt=elementFieldList.length; elFldIndex<elFldCnt; elFldIndex++) {\r
-                                               elementField = elementFieldList[elFldIndex];\r
-                                               elementData = TBE_EDITOR.getElement(elementRecord, elementField, type);\r
-                                               if (elementData) {\r
-                                                       elementName = elementRecord+'['+elementField+']';\r
-                                                       if (!TBE_EDITOR.checkElementByType(type, elementName, elementData)) result = 0;\r
-                                               }\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-               \r
-               return result;\r
-       },\r
-       checkElementByType: function(type, elementName, elementData) {\r
-               var result = 1;\r
-               \r
-               if (type) {\r
-                       if (type == 'required') {\r
-                               if (!document[TBE_EDITOR.formname][elementName].value) {\r
-                                       result = 0;\r
-                                       TBE_EDITOR.setImage('req_'+elementData.requiredImg, TBE_EDITOR.images.req);\r
-                               }\r
-                       } else if (type == 'range' && elementData.range) {\r
-                               var formObj = document[TBE_EDITOR.formname][elementName+'_list'];\r
-                               if (!formObj) {\r
-                                               // special treatment for IRRE fields:\r
-                                       var tempObj = document[TBE_EDITOR.formname][elementName];\r
-                                       if (tempObj && Element.hasClassName(tempObj, 'inlineRecord')) {\r
-                                               formObj = tempObj.value ? tempObj.value.split(',') : [];\r
-                                       }\r
-                               }\r
-                               if (!TBE_EDITOR.checkRange(formObj, elementData.range[0], elementData.range[1])) {\r
-                                       result = 0;\r
-                                       TBE_EDITOR.setImage('req_'+elementData.rangeImg, TBE_EDITOR.images.req);\r
-                               }\r
-                       }\r
-               }\r
-               \r
-               return result;\r
-       },\r
-       addActionChecks: function(type, checks) {\r
-               TBE_EDITOR.actionChecks[type].push(checks);\r
-       },\r
-       \r
-       // Regular TCEforms JSbottom scripts:\r
-       loginRefreshed: function() {\r
-               var date = new Date();\r
-               TBE_EDITOR.loadTime = Math.floor(date.getTime()/1000);\r
-               if (top.busy && top.busy.loginRefreshed) { top.busy.loginRefreshed(); }\r
-       },\r
-       checkLoginTimeout: function() {\r
-               var date = new Date();\r
-               var theTime = Math.floor(date.getTime()/1000);\r
-               if (theTime > TBE_EDITOR.loadTime+TBE_EDITOR.auth_timeout_field-10) {\r
-                       return true;\r
-               }\r
-       },\r
-       setHiddenContent: function(RTEcontent,theField) {\r
-               document[TBE_EDITOR.formname][theField].value = RTEcontent;\r
-               alert(document[TBE_EDITOR.formname][theField].value);\r
-       },\r
-       fieldChanged_fName: function(fName,el) {\r
-               var idx=2+TBE_EDITOR.prependFormFieldNamesCnt;\r
-               var table = TBE_EDITOR.split(fName, "[", idx);\r
-               var uid = TBE_EDITOR.split(fName, "[", idx+1);\r
-               var field = TBE_EDITOR.split(fName, "[", idx+2);\r
-\r
-               table = table.substr(0,table.length-1);\r
-               uid = uid.substr(0,uid.length-1);\r
-               field = field.substr(0,field.length-1);\r
-               TBE_EDITOR.fieldChanged(table,uid,field,el);\r
-       },\r
-       fieldChanged: function(table,uid,field,el) {\r
-               var theField = TBE_EDITOR.prependFormFieldNames+'['+table+']['+uid+']['+field+']';\r
-               var theRecord = TBE_EDITOR.prependFormFieldNames+'['+table+']['+uid+']';\r
-               TBE_EDITOR.isChanged = 1;\r
-\r
-                       // Set change image:\r
-               var imgObjName = "cm_"+table+"_"+uid+"_"+field;\r
-               TBE_EDITOR.setImage(imgObjName,TBE_EDITOR.images.cm);\r
-\r
-                       // Set change image\r
-               if (document[TBE_EDITOR.formname][theField] && document[TBE_EDITOR.formname][theField].type=="select-one" && document[TBE_EDITOR.formname][theField+"_selIconVal"])     {\r
-                       var imgObjName = "selIcon_"+table+"_"+uid+"_"+field+"_";\r
-                       TBE_EDITOR.setImage(imgObjName+document[TBE_EDITOR.formname][theField+"_selIconVal"].value,TBE_EDITOR.images.clear);\r
-                       document[TBE_EDITOR.formname][theField+"_selIconVal"].value = document[TBE_EDITOR.formname][theField].selectedIndex;\r
-                       TBE_EDITOR.setImage(imgObjName+document[TBE_EDITOR.formname][theField+"_selIconVal"].value,TBE_EDITOR.images.sel);\r
-               }\r
-\r
-                       // Set required flag:\r
-               var imgReqObjName = "req_"+table+"_"+uid+"_"+field;\r
-               if (TBE_EDITOR.getElement(theRecord,field,'required') && document[TBE_EDITOR.formname][theField])       {\r
-                       if (TBE_EDITOR.checkElements('required', false, theRecord, field)) {\r
-                               TBE_EDITOR.setImage(imgReqObjName,TBE_EDITOR.images.clear);\r
-                       } else {\r
-                               TBE_EDITOR.setImage(imgReqObjName,TBE_EDITOR.images.req);\r
-                       }\r
-               }\r
-               if (TBE_EDITOR.getElement(theRecord,field,'range') && document[TBE_EDITOR.formname][theField]) {\r
-                       if (TBE_EDITOR.checkElements('range', false, theRecord, field)) {\r
-                               TBE_EDITOR.setImage(imgReqObjName,TBE_EDITOR.images.clear);\r
-                       } else {\r
-                               TBE_EDITOR.setImage(imgReqObjName,TBE_EDITOR.images.req);\r
-                       }\r
-               }\r
-               \r
-               if (TBE_EDITOR.isPalettedoc) { TBE_EDITOR.setOriginalFormFieldValue(theField) };\r
-       },\r
-       setOriginalFormFieldValue: function(theField) {\r
-               if (TBE_EDITOR.isPalettedoc && (TBE_EDITOR.isPalettedoc).document[TBE_EDITOR.formname] && (TBE_EDITOR.isPalettedoc).document[TBE_EDITOR.formname][theField]) {\r
-                       (TBE_EDITOR.isPalettedoc).document[TBE_EDITOR.formname][theField].value = document[TBE_EDITOR.formname][theField].value;\r
-               }\r
-       },\r
-       isFormChanged: function(noAlert) {\r
-               if (TBE_EDITOR.isChanged && !noAlert && confirm(TBE_EDITOR.labels.fieldsChanged)) {\r
-                       return 0;\r
-               }\r
-               return TBE_EDITOR.isChanged;\r
-       },\r
-       checkAndDoSubmit: function(sendAlert) {\r
-               if (TBE_EDITOR.checkSubmit(sendAlert)) { TBE_EDITOR.submitForm(); }\r
-       },\r
-       /**\r
-        * Checks if the form can be submitted according to any possible restrains like required values, item numbers etc.\r
-        * Returns true if the form can be submitted, otherwise false (and might issue an alert message, if "sendAlert" is 1)\r
-        * If "sendAlert" is false, no error message will be shown upon false return value (if "1" then it will).\r
-        * If "sendAlert" is "-1" then the function will ALWAYS return true regardless of constraints (except if login has expired) - this is used in the case where a form field change requests a form update and where it is accepted that constraints are not observed (form layout might change so other fields are shown...)\r
-        */\r
-       checkSubmit: function(sendAlert) {\r
-               var funcIndex, funcMax, funcRes;\r
-               if (TBE_EDITOR.checkLoginTimeout() && confirm(TBE_EDITOR.labels.refresh_login)) {\r
-                       vHWin=window.open(TBE_EDITOR.backPath+'login_frameset.php?','relogin','height=300,width=400,status=0,menubar=0');\r
-                       vHWin.focus();\r
-                       return false;\r
-               }\r
-               var OK=1;\r
-\r
-               // $this->additionalJS_submit:\r
-               if (TBE_EDITOR.actionChecks && TBE_EDITOR.actionChecks.submit) {\r
-                       for (funcIndex=0, funcMax=TBE_EDITOR.actionChecks.submit.length; funcIndex<funcMax; funcIndex++) {\r
-                               eval(TBE_EDITOR.actionChecks.submit[funcIndex]);\r
-                       }\r
-               }\r
-\r
-               if(!OK) {\r
-                       if (!confirm(unescape("SYSTEM ERROR: One or more Rich Text Editors on the page could not be contacted. This IS an error, although it should not be regular.\nYou can save the form now by pressing OK, but you will loose the Rich Text Editor content if you do.\n\nPlease report the error to your administrator if it persists.")))  {\r
-                               return false;\r
-                       } else {\r
-                               OK = 1;\r
-                       }\r
-               }\r
-               // $reqLinesCheck\r
-               if (!TBE_EDITOR.checkElements('required', false)) { OK = 0; }\r
-               // $reqRangeCheck\r
-               if (!TBE_EDITOR.checkElements('range', false)) { OK = 0; }\r
-                               \r
-               if (OK || sendAlert==-1) {\r
-                       return true;\r
-               } else {\r
-                       if(sendAlert) alert(TBE_EDITOR.labels.fieldsMissing);\r
-                       return false;\r
-               }\r
-       },\r
-       checkRange: function(el,lower,upper) {\r
-               if (el && el.length>=lower && el.length<=upper) {\r
-                       return true;\r
-               } else {\r
-                       return false;\r
-               }\r
-       },\r
-       initRequired: function() {\r
-               // $reqLinesCheck\r
-               TBE_EDITOR.checkElements('required', true);\r
-\r
-               // $reqRangeCheck\r
-               TBE_EDITOR.checkElements('range', true);\r
-       },\r
-       setImage: function(name,image) {\r
-               if (document[name]) {\r
-                       if (typeof image == 'object') {\r
-                               document[name].src = image.src;\r
-                       } else {\r
-                               document[name].src = eval(image+'.src');\r
-                       }\r
-               }\r
-       },\r
-       submitForm: function() {\r
-               if (TBE_EDITOR.doSaveFieldName) {\r
-                       document[TBE_EDITOR.formname][TBE_EDITOR.doSaveFieldName].value=1;                      \r
-               }\r
-               document[TBE_EDITOR.formname].submit();\r
-       },\r
-       split: function(theStr1, delim, index) {\r
-               var theStr = ""+theStr1;\r
-               var lengthOfDelim = delim.length;\r
-               sPos = -lengthOfDelim;\r
-               if (index<1) {index=1;}\r
-               for (var a=1; a<index; a++)     {\r
-                       sPos = theStr.indexOf(delim, sPos+lengthOfDelim);\r
-                       if (sPos==-1) { return null; }\r
-               }\r
-               ePos = theStr.indexOf(delim, sPos+lengthOfDelim);\r
-               if(ePos == -1) { ePos = theStr.length; }\r
-               return (theStr.substring(sPos+lengthOfDelim,ePos));\r
-       },\r
-       palUrl: function(inData,fieldList,fieldNum,table,uid,isOnFocus) {\r
-               var url = TBE_EDITOR.backPath+'alt_palette.php?inData='+inData+'&formName='+TBE_EDITOR.formnameUENC+'&prependFormFieldNames='+TBE_EDITOR.prependFormFieldNamesUENC;\r
-               var field = "";\r
-               var theField="";\r
-               for (var a=0; a<fieldNum;a++)   {\r
-                       field = TBE_EDITOR.split(fieldList, ",", a+1);\r
-                       theField = TBE_EDITOR.prependFormFieldNames+'['+table+']['+uid+']['+field+']';\r
-                       if (document[TBE_EDITOR.formname][theField]) url+="&rec["+field+"]="+TBE_EDITOR.rawurlencode(document[TBE_EDITOR.formname][theField].value);\r
-               }\r
-               if (top.topmenuFrame)   {\r
-                       top.topmenuFrame.location.href = url+"&backRef="+(top.content.list_frame ? (top.content.list_frame.view_frame ? "top.content.list_frame.view_frame" : "top.content.list_frame") : "top.content");\r
-               } else if (!isOnFocus) {\r
-                       var vHWin=window.open(url,"palette","height=300,width=200,status=0,menubar=0,scrollbars=1");\r
-                       vHWin.focus();\r
-               }\r
-       },\r
-       curSelected: function(theField) {\r
-               var fObjSel = document[TBE_EDITOR.formname][theField];\r
-               var retVal="";\r
-               if (fObjSel)    {\r
-                       if (fObjSel.type=='select-multiple' || fObjSel.type=='select-one')      {\r
-                               var l=fObjSel.length;\r
-                               for (a=0;a<l;a++)       {\r
-                                       if (fObjSel.options[a].selected==1)     {\r
-                                               retVal+=fObjSel.options[a].value+",";\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-               return retVal;\r
-       },\r
-       rawurlencode: function(str,maxlen) {\r
-               var output = str;\r
-               if (maxlen)     output = output.substr(0,200);\r
-               output = escape(output);\r
-               output = TBE_EDITOR.str_replace("*","%2A", output);\r
-               output = TBE_EDITOR.str_replace("+","%2B", output);\r
-               output = TBE_EDITOR.str_replace("/","%2F", output);\r
-               output = TBE_EDITOR.str_replace("@","%40", output);\r
-               return output;\r
-       },\r
-       str_replace: function(match,replace,string) {\r
-               var input = ''+string;\r
-               var matchStr = ''+match;\r
-               if (!matchStr) { return string; }\r
-               var output = '';\r
-               var pointer=0;\r
-               var pos = input.indexOf(matchStr);\r
-               while (pos!=-1) {\r
-                       output+=''+input.substr(pointer, pos-pointer)+replace;\r
-                       pointer=pos+matchStr.length;\r
-                       pos = input.indexOf(match,pos+1);\r
-               }\r
-               output+=''+input.substr(pointer);\r
-               return output;\r
-       }\r
-};\r
-\r
-function typoSetup     () {\r
-       this.passwordDummy = '********';\r
-       this.decimalSign = '.';\r
-}\r
-var TS = new typoSetup();\r
-var evalFunc = new evalFunc();\r
-\r
-// backwards compatibility for extensions\r
-var TBE_EDITOR_loginRefreshed = TBE_EDITOR.loginRefreshed;\r
-var TBE_EDITOR_checkLoginTimeout = TBE_EDITOR.checkLoginTimeout;\r
-var TBE_EDITOR_setHiddenContent = TBE_EDITOR.setHiddenContent;\r
-var TBE_EDITOR_isChanged = TBE_EDITOR.isChanged;\r
-var TBE_EDITOR_fieldChanged_fName = TBE_EDITOR.fieldChanged_fName;\r
-var TBE_EDITOR_fieldChanged = TBE_EDITOR.fieldChanged;\r
-var TBE_EDITOR_setOriginalFormFieldValue = TBE_EDITOR.setOriginalFormFieldValue;\r
-var TBE_EDITOR_isFormChanged = TBE_EDITOR.isFormChanged;\r
-var TBE_EDITOR_checkAndDoSubmit = TBE_EDITOR.checkAndDoSubmit;\r
-var TBE_EDITOR_checkSubmit = TBE_EDITOR.checkSubmit;\r
-var TBE_EDITOR_checkRange = TBE_EDITOR.checkRange;\r
-var TBE_EDITOR_initRequired = TBE_EDITOR.initRequired;\r
-var TBE_EDITOR_setImage = TBE_EDITOR.setImage;\r
-var TBE_EDITOR_submitForm = TBE_EDITOR.submitForm;\r
-var TBE_EDITOR_split = TBE_EDITOR.split;\r
-var TBE_EDITOR_palUrl = TBE_EDITOR.palUrl;\r
-var TBE_EDITOR_curSelected = TBE_EDITOR.curSelected;\r
-var TBE_EDITOR_rawurlencode = TBE_EDITOR.rawurlencode;\r
-var TBE_EDITOR_str_replace = TBE_EDITOR.str_replace;\r
-\r
-\r
-var typo3form = {\r
-       fieldSet: function(theField, evallist, is_in, checkbox, checkboxValue) {\r
-               if (document[TBE_EDITOR.formname][theField])    {\r
-                       var theFObj = new evalFunc_dummy (evallist,is_in, checkbox, checkboxValue);\r
-                       var theValue = document[TBE_EDITOR.formname][theField].value;\r
-                       if (checkbox && theValue==checkboxValue)        {\r
-                               document[TBE_EDITOR.formname][theField+"_hr"].value="";\r
-                               if (document[TBE_EDITOR.formname][theField+"_cb"])      document[TBE_EDITOR.formname][theField+"_cb"].checked = "";\r
-                       } else {\r
-                               document[TBE_EDITOR.formname][theField+"_hr"].value = evalFunc.outputObjValue(theFObj, theValue);\r
-                               if (document[TBE_EDITOR.formname][theField+"_cb"])      document[TBE_EDITOR.formname][theField+"_cb"].checked = "on";\r
-                       }\r
-               }\r
-       },\r
-       fieldGet: function(theField, evallist, is_in, checkbox, checkboxValue, checkbox_off, checkSetValue) {\r
-               if (document[TBE_EDITOR.formname][theField])    {\r
-                       var theFObj = new evalFunc_dummy (evallist,is_in, checkbox, checkboxValue);\r
-                       if (checkbox_off)       {\r
-                               if (document[TBE_EDITOR.formname][theField+"_cb"].checked)      {\r
-                                       document[TBE_EDITOR.formname][theField].value=checkSetValue;\r
-                               } else {\r
-                                       document[TBE_EDITOR.formname][theField].value=checkboxValue;\r
-                               }\r
-                       }else{\r
-                               document[TBE_EDITOR.formname][theField].value = evalFunc.evalObjValue(theFObj, document[TBE_EDITOR.formname][theField+"_hr"].value);\r
-                       }\r
-                       typo3form.fieldSet(theField, evallist, is_in, checkbox, checkboxValue);\r
-               }\r
-       }\r
-};\r
-\r
-// backwards compatibility for extensions\r
-var typo3FormFieldSet = typo3form.fieldSet;\r
-var typo3FormFieldGet = typo3form.fieldGet;\r
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  All rights reserved
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*  A copy is found in the textfile GPL.txt and important notices to the license
+*  from the author is found in LICENSE.txt distributed with these scripts.
+*
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+/**
+ * Contains JavaScript for TYPO3 Core Form generator - AKA "TCEforms"
+ *
+ * $Id: $
+ *
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
+ * @coauthor   Oliver Hader <oh@inpublica.de>
+ */
+
+
+var TBE_EDITOR = {
+       /* Example:
+               elements: {
+                       'data[table][uid]': {
+                               'field': {
+                                       'range':                [0, 100],
+                                       'rangeImg':             '',
+                                       'required':             true,
+                                       'requiredImg':  ''
+                               }
+                       }
+               
+               },
+       */
+       
+       elements: {},
+       recentUpdatedElements: {},
+       actionChecks: { submit: [] },
+       
+       formname: '',
+       formnameUENC: '',
+       loadTime: 0,
+       isChanged: 0,
+       auth_timeout_field: 0,
+
+       backPath: '',
+       prependFormFieldNames: 'data',
+       prependFormFieldNamesUENC: 'data',
+       prependFormFieldNamesCnt: 0,
+       
+       isPalettedoc: null,
+       doSaveFieldName: 0,
+       
+       labels: {},
+       images: {
+               req: new Image(),
+               cm: new Image(),
+               sel: new Image(),
+               clear: new Image()
+       },      
+
+       // Handling of data structures:
+       addElements: function(elements) {
+               TBE_EDITOR.recentUpdatedElements = elements;
+               TBE_EDITOR.elements = $H(TBE_EDITOR.elements).merge(elements);
+       },
+       removeElement: function(record) {
+               if (TBE_EDITOR.elements && TBE_EDITOR.elements[record]) {
+                       delete(TBE_EDITOR.elements[record]);
+               }
+       },
+       getElement: function(record, field, type) {
+               var result = null;
+               var element;
+               
+               if (TBE_EDITOR.elements && TBE_EDITOR.elements[record] && TBE_EDITOR.elements[record][field]) {
+                       element = TBE_EDITOR.elements[record][field];
+                       if (type) {
+                               if (element[type]) result = element;
+                       } else {
+                               result = element;
+                       }
+               }
+               
+               return result;
+       },
+       checkElements: function(type, recentUpdated, record, field) {
+               var result = 1;
+               var elementName, elementData, elementRecord, elementField;
+               var source = recentUpdated ? TBE_EDITOR.recentUpdatedElements : TBE_EDITOR.elements;
+
+               if (type) {
+                       if (record && field) {
+                               elementName = record+'['+field+']';
+                               elementData = TBE_EDITOR.getElement(record, field, type);
+                               if (elementData) {
+                                       if (!TBE_EDITOR.checkElementByType(type, elementName, elementData)) result = 0;
+                               }
+                               
+                       } else {
+                               var elementFieldList, elRecIndex, elRecCnt, elFldIndex, elFldCnt;
+                               var elementRecordList = $H(source).keys();
+                               for (elRecIndex=0, elRecCnt=elementRecordList.length; elRecIndex<elRecCnt; elRecIndex++) {
+                                       elementRecord = elementRecordList[elRecIndex];
+                                       elementFieldList = $H(source[elementRecord]).keys();
+                                       for (elFldIndex=0, elFldCnt=elementFieldList.length; elFldIndex<elFldCnt; elFldIndex++) {
+                                               elementField = elementFieldList[elFldIndex];
+                                               elementData = TBE_EDITOR.getElement(elementRecord, elementField, type);
+                                               if (elementData) {
+                                                       elementName = elementRecord+'['+elementField+']';
+                                                       if (!TBE_EDITOR.checkElementByType(type, elementName, elementData)) result = 0;
+                                               }
+                                       }
+                               }
+                       }
+               }
+               
+               return result;
+       },
+       checkElementByType: function(type, elementName, elementData) {
+               var result = 1;
+               
+               if (type) {
+                       if (type == 'required') {
+                               if (!document[TBE_EDITOR.formname][elementName].value) {
+                                       result = 0;
+                                       TBE_EDITOR.setImage('req_'+elementData.requiredImg, TBE_EDITOR.images.req);
+                               }
+                       } else if (type == 'range' && elementData.range) {
+                               var formObj = document[TBE_EDITOR.formname][elementName+'_list'];
+                               if (!formObj) {
+                                               // special treatment for IRRE fields:
+                                       var tempObj = document[TBE_EDITOR.formname][elementName];
+                                       if (tempObj && Element.hasClassName(tempObj, 'inlineRecord')) {
+                                               formObj = tempObj.value ? tempObj.value.split(',') : [];
+                                       }
+                               }
+                               if (!TBE_EDITOR.checkRange(formObj, elementData.range[0], elementData.range[1])) {
+                                       result = 0;
+                                       TBE_EDITOR.setImage('req_'+elementData.rangeImg, TBE_EDITOR.images.req);
+                               }
+                       }
+               }
+               
+               return result;
+       },
+       addActionChecks: function(type, checks) {
+               TBE_EDITOR.actionChecks[type].push(checks);
+       },
+       
+       // Regular TCEforms JSbottom scripts:
+       loginRefreshed: function() {
+               var date = new Date();
+               TBE_EDITOR.loadTime = Math.floor(date.getTime()/1000);
+               if (top.busy && top.busy.loginRefreshed) { top.busy.loginRefreshed(); }
+       },
+       checkLoginTimeout: function() {
+               var date = new Date();
+               var theTime = Math.floor(date.getTime()/1000);
+               if (theTime > TBE_EDITOR.loadTime+TBE_EDITOR.auth_timeout_field-10) {
+                       return true;
+               }
+       },
+       setHiddenContent: function(RTEcontent,theField) {
+               document[TBE_EDITOR.formname][theField].value = RTEcontent;
+               alert(document[TBE_EDITOR.formname][theField].value);
+       },
+       fieldChanged_fName: function(fName,el) {
+               var idx=2+TBE_EDITOR.prependFormFieldNamesCnt;
+               var table = TBE_EDITOR.split(fName, "[", idx);
+               var uid = TBE_EDITOR.split(fName, "[", idx+1);
+               var field = TBE_EDITOR.split(fName, "[", idx+2);
+
+               table = table.substr(0,table.length-1);
+               uid = uid.substr(0,uid.length-1);
+               field = field.substr(0,field.length-1);
+               TBE_EDITOR.fieldChanged(table,uid,field,el);
+       },
+       fieldChanged: function(table,uid,field,el) {
+               var theField = TBE_EDITOR.prependFormFieldNames+'['+table+']['+uid+']['+field+']';
+               var theRecord = TBE_EDITOR.prependFormFieldNames+'['+table+']['+uid+']';
+               TBE_EDITOR.isChanged = 1;
+
+                       // Set change image:
+               var imgObjName = "cm_"+table+"_"+uid+"_"+field;
+               TBE_EDITOR.setImage(imgObjName,TBE_EDITOR.images.cm);
+
+                       // Set change image
+               if (document[TBE_EDITOR.formname][theField] && document[TBE_EDITOR.formname][theField].type=="select-one" && document[TBE_EDITOR.formname][theField+"_selIconVal"])     {
+                       var imgObjName = "selIcon_"+table+"_"+uid+"_"+field+"_";
+                       TBE_EDITOR.setImage(imgObjName+document[TBE_EDITOR.formname][theField+"_selIconVal"].value,TBE_EDITOR.images.clear);
+                       document[TBE_EDITOR.formname][theField+"_selIconVal"].value = document[TBE_EDITOR.formname][theField].selectedIndex;
+                       TBE_EDITOR.setImage(imgObjName+document[TBE_EDITOR.formname][theField+"_selIconVal"].value,TBE_EDITOR.images.sel);
+               }
+
+                       // Set required flag:
+               var imgReqObjName = "req_"+table+"_"+uid+"_"+field;
+               if (TBE_EDITOR.getElement(theRecord,field,'required') && document[TBE_EDITOR.formname][theField])       {
+                       if (TBE_EDITOR.checkElements('required', false, theRecord, field)) {
+                               TBE_EDITOR.setImage(imgReqObjName,TBE_EDITOR.images.clear);
+                       } else {
+                               TBE_EDITOR.setImage(imgReqObjName,TBE_EDITOR.images.req);
+                       }
+               }
+               if (TBE_EDITOR.getElement(theRecord,field,'range') && document[TBE_EDITOR.formname][theField]) {
+                       if (TBE_EDITOR.checkElements('range', false, theRecord, field)) {
+                               TBE_EDITOR.setImage(imgReqObjName,TBE_EDITOR.images.clear);
+                       } else {
+                               TBE_EDITOR.setImage(imgReqObjName,TBE_EDITOR.images.req);
+                       }
+               }
+               
+               if (TBE_EDITOR.isPalettedoc) { TBE_EDITOR.setOriginalFormFieldValue(theField) };
+       },
+       setOriginalFormFieldValue: function(theField) {
+               if (TBE_EDITOR.isPalettedoc && (TBE_EDITOR.isPalettedoc).document[TBE_EDITOR.formname] && (TBE_EDITOR.isPalettedoc).document[TBE_EDITOR.formname][theField]) {
+                       (TBE_EDITOR.isPalettedoc).document[TBE_EDITOR.formname][theField].value = document[TBE_EDITOR.formname][theField].value;
+               }
+       },
+       isFormChanged: function(noAlert) {
+               if (TBE_EDITOR.isChanged && !noAlert && confirm(TBE_EDITOR.labels.fieldsChanged)) {
+                       return 0;
+               }
+               return TBE_EDITOR.isChanged;
+       },
+       checkAndDoSubmit: function(sendAlert) {
+               if (TBE_EDITOR.checkSubmit(sendAlert)) { TBE_EDITOR.submitForm(); }
+       },
+       /**
+        * Checks if the form can be submitted according to any possible restrains like required values, item numbers etc.
+        * Returns true if the form can be submitted, otherwise false (and might issue an alert message, if "sendAlert" is 1)
+        * If "sendAlert" is false, no error message will be shown upon false return value (if "1" then it will).
+        * If "sendAlert" is "-1" then the function will ALWAYS return true regardless of constraints (except if login has expired) - this is used in the case where a form field change requests a form update and where it is accepted that constraints are not observed (form layout might change so other fields are shown...)
+        */
+       checkSubmit: function(sendAlert) {
+               var funcIndex, funcMax, funcRes;
+               if (TBE_EDITOR.checkLoginTimeout() && confirm(TBE_EDITOR.labels.refresh_login)) {
+                       vHWin=window.open(TBE_EDITOR.backPath+'login_frameset.php?','relogin','height=300,width=400,status=0,menubar=0');
+                       vHWin.focus();
+                       return false;
+               }
+               var OK=1;
+
+               // $this->additionalJS_submit:
+               if (TBE_EDITOR.actionChecks && TBE_EDITOR.actionChecks.submit) {
+                       for (funcIndex=0, funcMax=TBE_EDITOR.actionChecks.submit.length; funcIndex<funcMax; funcIndex++) {
+                               eval(TBE_EDITOR.actionChecks.submit[funcIndex]);
+                       }
+               }
+
+               if(!OK) {
+                       if (!confirm(unescape("SYSTEM ERROR: One or more Rich Text Editors on the page could not be contacted. This IS an error, although it should not be regular.\nYou can save the form now by pressing OK, but you will loose the Rich Text Editor content if you do.\n\nPlease report the error to your administrator if it persists.")))  {
+                               return false;
+                       } else {
+                               OK = 1;
+                       }
+               }
+               // $reqLinesCheck
+               if (!TBE_EDITOR.checkElements('required', false)) { OK = 0; }
+               // $reqRangeCheck
+               if (!TBE_EDITOR.checkElements('range', false)) { OK = 0; }
+                               
+               if (OK || sendAlert==-1) {
+                       return true;
+               } else {
+                       if(sendAlert) alert(TBE_EDITOR.labels.fieldsMissing);
+                       return false;
+               }
+       },
+       checkRange: function(el,lower,upper) {
+               if (el && el.length>=lower && el.length<=upper) {
+                       return true;
+               } else {
+                       return false;
+               }
+       },
+       initRequired: function() {
+               // $reqLinesCheck
+               TBE_EDITOR.checkElements('required', true);
+
+               // $reqRangeCheck
+               TBE_EDITOR.checkElements('range', true);
+       },
+       setImage: function(name,image) {
+               if (document[name]) {
+                       if (typeof image == 'object') {
+                               document[name].src = image.src;
+                       } else {
+                               document[name].src = eval(image+'.src');
+                       }
+               }
+       },
+       submitForm: function() {
+               if (TBE_EDITOR.doSaveFieldName) {
+                       document[TBE_EDITOR.formname][TBE_EDITOR.doSaveFieldName].value=1;                      
+               }
+               document[TBE_EDITOR.formname].submit();
+       },
+       split: function(theStr1, delim, index) {
+               var theStr = ""+theStr1;
+               var lengthOfDelim = delim.length;
+               sPos = -lengthOfDelim;
+               if (index<1) {index=1;}
+               for (var a=1; a<index; a++)     {
+                       sPos = theStr.indexOf(delim, sPos+lengthOfDelim);
+                       if (sPos==-1) { return null; }
+               }
+               ePos = theStr.indexOf(delim, sPos+lengthOfDelim);
+               if(ePos == -1) { ePos = theStr.length; }
+               return (theStr.substring(sPos+lengthOfDelim,ePos));
+       },
+       palUrl: function(inData,fieldList,fieldNum,table,uid,isOnFocus) {
+               var url = TBE_EDITOR.backPath+'alt_palette.php?inData='+inData+'&formName='+TBE_EDITOR.formnameUENC+'&prependFormFieldNames='+TBE_EDITOR.prependFormFieldNamesUENC;
+               var field = "";
+               var theField="";
+               for (var a=0; a<fieldNum;a++)   {
+                       field = TBE_EDITOR.split(fieldList, ",", a+1);
+                       theField = TBE_EDITOR.prependFormFieldNames+'['+table+']['+uid+']['+field+']';
+                       if (document[TBE_EDITOR.formname][theField]) url+="&rec["+field+"]="+TBE_EDITOR.rawurlencode(document[TBE_EDITOR.formname][theField].value);
+               }
+               if (top.topmenuFrame)   {
+                       top.topmenuFrame.location.href = url+"&backRef="+(top.content.list_frame ? (top.content.list_frame.view_frame ? "top.content.list_frame.view_frame" : "top.content.list_frame") : "top.content");
+               } else if (!isOnFocus) {
+                       var vHWin=window.open(url,"palette","height=300,width=200,status=0,menubar=0,scrollbars=1");
+                       vHWin.focus();
+               }
+       },
+       curSelected: function(theField) {
+               var fObjSel = document[TBE_EDITOR.formname][theField];
+               var retVal="";
+               if (fObjSel)    {
+                       if (fObjSel.type=='select-multiple' || fObjSel.type=='select-one')      {
+                               var l=fObjSel.length;
+                               for (a=0;a<l;a++)       {
+                                       if (fObjSel.options[a].selected==1)     {
+                                               retVal+=fObjSel.options[a].value+",";
+                                       }
+                               }
+                       }
+               }
+               return retVal;
+       },
+       rawurlencode: function(str,maxlen) {
+               var output = str;
+               if (maxlen)     output = output.substr(0,200);
+               output = escape(output);
+               output = TBE_EDITOR.str_replace("*","%2A", output);
+               output = TBE_EDITOR.str_replace("+","%2B", output);
+               output = TBE_EDITOR.str_replace("/","%2F", output);
+               output = TBE_EDITOR.str_replace("@","%40", output);
+               return output;
+       },
+       str_replace: function(match,replace,string) {
+               var input = ''+string;
+               var matchStr = ''+match;
+               if (!matchStr) { return string; }
+               var output = '';
+               var pointer=0;
+               var pos = input.indexOf(matchStr);
+               while (pos!=-1) {
+                       output+=''+input.substr(pointer, pos-pointer)+replace;
+                       pointer=pos+matchStr.length;
+                       pos = input.indexOf(match,pos+1);
+               }
+               output+=''+input.substr(pointer);
+               return output;
+       }
+};
+
+function typoSetup     () {
+       this.passwordDummy = '********';
+       this.decimalSign = '.';
+}
+var TS = new typoSetup();
+var evalFunc = new evalFunc();
+
+// backwards compatibility for extensions
+var TBE_EDITOR_loginRefreshed = TBE_EDITOR.loginRefreshed;
+var TBE_EDITOR_checkLoginTimeout = TBE_EDITOR.checkLoginTimeout;
+var TBE_EDITOR_setHiddenContent = TBE_EDITOR.setHiddenContent;
+var TBE_EDITOR_isChanged = TBE_EDITOR.isChanged;
+var TBE_EDITOR_fieldChanged_fName = TBE_EDITOR.fieldChanged_fName;
+var TBE_EDITOR_fieldChanged = TBE_EDITOR.fieldChanged;
+var TBE_EDITOR_setOriginalFormFieldValue = TBE_EDITOR.setOriginalFormFieldValue;
+var TBE_EDITOR_isFormChanged = TBE_EDITOR.isFormChanged;
+var TBE_EDITOR_checkAndDoSubmit = TBE_EDITOR.checkAndDoSubmit;
+var TBE_EDITOR_checkSubmit = TBE_EDITOR.checkSubmit;
+var TBE_EDITOR_checkRange = TBE_EDITOR.checkRange;
+var TBE_EDITOR_initRequired = TBE_EDITOR.initRequired;
+var TBE_EDITOR_setImage = TBE_EDITOR.setImage;
+var TBE_EDITOR_submitForm = TBE_EDITOR.submitForm;
+var TBE_EDITOR_split = TBE_EDITOR.split;
+var TBE_EDITOR_palUrl = TBE_EDITOR.palUrl;
+var TBE_EDITOR_curSelected = TBE_EDITOR.curSelected;
+var TBE_EDITOR_rawurlencode = TBE_EDITOR.rawurlencode;
+var TBE_EDITOR_str_replace = TBE_EDITOR.str_replace;
+
+
+var typo3form = {
+       fieldSet: function(theField, evallist, is_in, checkbox, checkboxValue) {
+               if (document[TBE_EDITOR.formname][theField])    {
+                       var theFObj = new evalFunc_dummy (evallist,is_in, checkbox, checkboxValue);
+                       var theValue = document[TBE_EDITOR.formname][theField].value;
+                       if (checkbox && theValue==checkboxValue)        {
+                               document[TBE_EDITOR.formname][theField+"_hr"].value="";
+                               if (document[TBE_EDITOR.formname][theField+"_cb"])      document[TBE_EDITOR.formname][theField+"_cb"].checked = "";
+                       } else {
+                               document[TBE_EDITOR.formname][theField+"_hr"].value = evalFunc.outputObjValue(theFObj, theValue);
+                               if (document[TBE_EDITOR.formname][theField+"_cb"])      document[TBE_EDITOR.formname][theField+"_cb"].checked = "on";
+                       }
+               }
+       },
+       fieldGet: function(theField, evallist, is_in, checkbox, checkboxValue, checkbox_off, checkSetValue) {
+               if (document[TBE_EDITOR.formname][theField])    {
+                       var theFObj = new evalFunc_dummy (evallist,is_in, checkbox, checkboxValue);
+                       if (checkbox_off)       {
+                               if (document[TBE_EDITOR.formname][theField+"_cb"].checked)      {
+                                       document[TBE_EDITOR.formname][theField].value=checkSetValue;
+                               } else {
+                                       document[TBE_EDITOR.formname][theField].value=checkboxValue;
+                               }
+                       }else{
+                               document[TBE_EDITOR.formname][theField].value = evalFunc.evalObjValue(theFObj, document[TBE_EDITOR.formname][theField+"_hr"].value);
+                       }
+                       typo3form.fieldSet(theField, evallist, is_in, checkbox, checkboxValue);
+               }
+       }
+};
+
+// backwards compatibility for extensions
+var typo3FormFieldSet = typo3form.fieldSet;
+var typo3FormFieldGet = typo3form.fieldGet;