
String.prototype.entityify=function(){return this.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");}
String.prototype.quote=function(){return'"'+this.replace(/(["\\])/g,'\\$1')+'"';}
String.prototype.supplant=function(oProps,bReplaceWithBlank,oCallBack){var i,j,vValue;var sString=this;var q=0;var sOpenTag=(isUndefined(oProps.__open_tag))?'{':oProps.__open_tag;var sCloseTag=(isUndefined(oProps.__close_tag))?'}':oProps.__close_tag;for(;;){i=q+sString.substring(q,sString.length).indexOf(sOpenTag);if(i<0){break;}
if(i+1<=q){break;}
j=sString.indexOf(sCloseTag,i+1);if(j==-1){break;}
if(isDefined(oCallBack)){vValue=oCallBack(sString.substring(i+1,j),oProps);}else{vValue=oProps[sString.substring(i+1,j)];}
if(isUndefined(vValue)){if(bReplaceWithBlank){vValue='';}else{q=i+1;continue;}}
sString=sString.substring(0,i)+vValue+sString.substring(j+1);}
return sString;}
String.prototype.trim=function(){return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/,"$1");}
if(!isFunction(Function.apply)){Function.prototype.apply=function(o,a){var r,x='____apply';if(!isObject(o)){o={};}
o[x]=this;switch((a&&a.length)||0){case 0:r=o[x]();break;case 1:r=o[x](a[0]);break;case 2:r=o[x](a[0],a[1]);break;case 3:r=o[x](a[0],a[1],a[2]);break;case 4:r=o[x](a[0],a[1],a[2],a[3]);break;case 5:r=o[x](a[0],a[1],a[2],a[3],a[4]);break;case 6:r=o[x](a[0],a[1],a[2],a[3],a[4],a[5]);break;default:}
delete o[x];return r;}}
Function.prototype.inherits=function(parent){var d=0,p=(this.prototype=new parent());this.prototype.uber=function uber(name){var f,r,t=d,v=parent.prototype;if(t){while(t){v=v.constructor.prototype;t-=1;}
f=v[name];}else{f=p[name];if(f==this[name]){f=v[name];}}
d+=1;r=f.apply(this,Array.prototype.slice.apply(arguments,[1]));d-=1;return r;}
return this;}
Function.prototype.swiss=function(parent){for(var i=1;i<arguments.length;i+=1){var name=arguments[i];this.prototype[name]=parent.prototype[name];}
return this;}
function isAlien(a){return isObject(a)&&typeof a.constructor!='function';}
function isArray(a){return isObject(a)&&a.constructor==Array;}
function isBoolean(a){return typeof a=='boolean';}
function isEmpty(o){var i,v;if(isObject(o)){for(i in o){v=o[i];if(isUndefined(v)&&isFunction(v)){return false;}}}
return true;}
function isFunction(a){return typeof a=='function';}
function isNull(a){return typeof a=='object'&&!a;}
function isNumber(a){return typeof a=='number'&&isFinite(a);}
function isObject(a){return(a&&typeof a=='object')||isFunction(a);}
function isString(a){return typeof a=='string';}
function isUndefined(a){return typeof a=='undefined';}
function isDefined(a){return typeof a!='undefined';}
function stringify(arg){var i,o,v;switch(typeof arg){case'object':if(arg){if(arg.constructor==Array){o='[';for(i=0;i<arg.length;++i){v=stringify(arg[i]);if(v!='function'&&!isUndefined(v)){o+=(o!='['?',':'')+v;}else{o+=',';}}
return o+']';}else if(typeof arg.toString!='undefined'){o='{';for(i in arg){v=stringify(arg[i]);if(v!='function'&&!isUndefined(v)){o+=(o!='{'?',':'')+
i.quote()+':'+v;}}
return o+'}';}else{return;}}
return'null';case'unknown':case'undefined':return;case'string':return arg.quote();case'function':return'function';default:return String(arg);}}


function GetFieldValue(oField){var vValue;if(oField.type=='text'||oField.type=='hidden'||oField.type=='password'||oField.tagName=='TEXTAREA'){vValue=oField.value;}else if(oField.type=='checkbox'){vValue=oField.checked;}else if(oField.type=='radio'){vValue=oField.value;}else if(oField.tagName=='SELECT'){vValue=oField.options[oField.selectedIndex].value;}
return vValue;}
function SetFieldValue(oField,vValue){if(!oField){return false;}
if(oField.type=='text'||oField.type=='hidden'||oField.type=='password'||oField.tagName=='TEXTAREA'){oField.value=(vValue!=null)?vValue:'';}else if(oField.type=='checkbox'){var bChecked=false;if(vValue=='true'){bChecked=true;}else if(vValue=='false'){bChecked=false;}else if(vValue>0){bChecked=true;}else{bChecked=vValue;}
oField.checked=bChecked;}else if(oField.type=='radio'){}else if(oField.tagName=='SELECT'){return ListSetSelectedValue(oField,vValue,true);}
return true;}
function ListSetSelectedValue(oList,vValue,bSelectFirstWhenNotFound){if(!oList){return;}
ListResetSelection(oList);var bFound=false;for(var i=0;i<oList.options.length;i++){if(oList.options[i].value==vValue){oList.options[i].selected=true;bFound=true;break;}}
if((!bFound)&&bSelectFirstWhenNotFound&&(oList.options.length>0)){oList.options[0].selected=true;}
return bFound;}
function ListResetSelection(oList){if(!oList){return;}
for(var i=0;i<oList.options.length;i++){oList.options[i].selected=false;}}
function ListMoveOptions(sFromId,sToId){var oDest=document.getElementById(sToId);var oFrom=document.getElementById(sFromId);var arrSelectedOptions=ListCutSelectedOptions(sFromId);for(var i=0;i<arrSelectedOptions.length;i++){arrSelectedOptions[i].selected=false;oDest.options[oDest.options.length]=arrSelectedOptions[i];}}
function ListCutSelectedOptions(sListID){var oList=document.getElementById(sListID);if(!oList){return[];}
var arrSelectedOptions=[];for(var i=0;i<oList.options.length;i++){if(oList.options[i].selected&&oList.options[i].value!=''){arrSelectedOptions[arrSelectedOptions.length]=oList.options[i];oList.remove(i);i--;}}
return arrSelectedOptions;}
function Filter_Trim(vValue){return vValue.trim();}
function Filter_Integer(vValue){return(isNaN(parseInt(vValue,10)))?'':parseInt(vValue,10);}
var MapFilterName_Filter={__filter__trim:Filter_Trim,__filter__int:Filter_Integer};function FilterFieldValue(vValue,vFilter){var vFilteredValue=vValue;var arrFilters=vFilter.split(',');for(var i=0;i<arrFilters.length;i++){var sCurrFilter=arrFilters[i].trim();if(isDefined(MapFilterName_Filter[sCurrFilter])){vFilteredValue=MapFilterName_Filter[sCurrFilter](vFilteredValue);}}
return vFilteredValue;}
function FilterField(oField,vFilter){SetFieldValue(oField,FilterFieldValue(GetFieldValue(oField),vFilter));}
function Validator_None(vValue){return true;}
function Validator_None_Message(){return'';}
function Validator_IsInteger(vValue){return(parseInt(vValue).toString().length==vValue.toString().length&&!isNaN(parseInt(vValue,10)));}
function Validator_IsInteger_Message(){return'An integer number is required.';}
function Validator_IsPositiveInteger(vValue){return(Validator_IsInteger(vValue)&&vValue>0);}
function Validator_IsPositiveInteger_Message(){return'A positive integer number is required.';}
function Validator_IsNonNegativeInteger(vValue){return(Validator_IsInteger(vValue)&&vValue>=0);}
function Validator_IsNonNegativeInteger_Message(){return'A non-negative integer number is required.';}
function Validator_IsNotEmpty(vValue){return(vValue.toString()!='');}
function Validator_IsNotEmpty_Message(){return'This field may not be empty.';}
function Validator_EmptyOrPositiveInteger(vValue){return(!Validator_IsNotEmpty(vValue)||Validator_IsPositiveInteger(vValue));}
function Validator_EmptyOrPositiveInteger_Message(){return'Either enter a positive integer number or leave the field empty.';}
function Validator_EmptyOrNonNegativeInteger(vValue){return(!Validator_IsNotEmpty(vValue)||Validator_IsNonNegativeInteger(vValue));}
function Validator_EmptyOrNonNegativeInteger_Message(){return'Either enter a non-negative integer number or leave the field empty.';}
function Validator_Email(vValue){return(vValue.match(/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,5}|[0-9]{1,5})(\]?)$/)!=null||vValue.match(/^\$/));}
function Validator_Email_Message(){return'Enter a valid email address.'}
function Validator_Character(vValue,oOptions){if(vValue.match(/^[a-z\n\r]+$/i)==null){return false;}
if(isDefined(oOptions)){vValue=vValue.replace(/\n|\r/g,'');if(isDefined(oOptions.length_from)&&oOptions.length_from!=''){if(vValue.toString().length<oOptions.length_from){return false;}}
if(isDefined(oOptions.length_to)&&oOptions.length_to!=''){if(vValue.toString().length>oOptions.length_to){return false;}}}
return true;}
function Validator_Character_Message(oOptions){if(isDefined(oOptions)){var sMessage='';if(oOptions.length_from){sMessage+='Enter not less than '+oOptions.length_from+' letters. ';}
if(oOptions.length_to){sMessage+='Enter not more than '+oOptions.length_to+' letters.';}
if(oOptions.length_from&&oOptions.length_to){sMessage='Enter not less than '+oOptions.length_from+' and not more than '+oOptions.length_to+' letters.';}
if(sMessage!=''){return sMessage;}}
return'Enter one or more letters.';}
function Validator_Number(vValue,oOptions){if(vValue.match(/^[\-]*[\d]+[\.]{0,1}[\d]*$/)==null){return false;}
if(isDefined(oOptions)){if(isDefined(oOptions.range_from)&&oOptions.range_from.toString()!=''){if(parseFloat(vValue)<parseFloat(oOptions.range_from)){return false;}}
if(isDefined(oOptions.range_to)&&oOptions.range_to.toString()!=''){if(parseFloat(vValue)>parseFloat(oOptions.range_to)){return false;}}}
return true;}
function Validator_Number_Message(oOptions){if(isDefined(oOptions)){var sMessage='';var bRangeFromFound=false;if(isDefined(oOptions.range_from)&&oOptions.range_from.toString()!=''){sMessage+='Enter a number not less than '+oOptions.range_from+'. ';bRangeFromFound=true;}
var bRangeToFound=false;if(isDefined(oOptions.range_to)&&oOptions.range_to.toString()!=''){sMessage+='Enter a number up to '+oOptions.range_to+'.';bRangeToFound=true;}
if(bRangeFromFound&&bRangeToFound){sMessage='Enter a number between '+oOptions.range_from+' and '+oOptions.range_to+'.';}
if(sMessage!=''){return sMessage;}}
return'Please enter a valid number.';}
var mapPhoneFormat_Data={"1":{reg_exp:/^\(\d{3}\) \d{3} \d{4}$/,format:'(310) 571 3135'},"2":{reg_exp:/^\d{3}\.\d{3}\.\d{4}$/,format:'310.571.3135'},"3":{reg_exp:/^\d{3} \d{3} \d{4}$/,format:'310 571 3135'},"4":{reg_exp:/^\d{3}\-\d{3}\-\d{4}$/,format:'310-571-3135'}}
function Validator_Phone(vValue,oOptions){if(isDefined(oOptions)&&isDefined(oOptions.phone_format)){var sPhoneFormatId=oOptions.phone_format;var oData=mapPhoneFormat_Data[sPhoneFormatId];if(isDefined(oData)){var oRegExp=oData.reg_exp;return(vValue.match(oRegExp)!=null);}}
var oDefaultPhoneRe=/^[\(\)\.x\ \-\d]+$/;var sDigitsOnly=vValue.replace(/[^\d]+/g,'');return(vValue.match(oDefaultPhoneRe)!=null&&sDigitsOnly.toString().length>4);}
function Validator_Phone_Message(oOptions){if(isDefined(oOptions)&&isDefined(oOptions.phone_format)){var sPhoneFormatId=oOptions.phone_format;var oData=mapPhoneFormat_Data[sPhoneFormatId];if(isDefined(oData)){var sFormat=oData.format;return'The required phone number format is ['+sFormat+'].';}}
return'A phone number is considered valid if it has at least 5 digits separated by space, dot, dash, "x" or parenthesis.';}
var mapDateFormat_Data={"1":{handler:ValidDate_1,format:'YYYY-MM-DD'},"2":{handler:ValidDate_2,format:'YY-MM-DD'},"3":{handler:ValidDate_3,format:'DD-MM-YYYY'},"4":{handler:ValidDate_4,format:'DD-MM-YY'}}
function IsValidDateCombination(iYear,iMonth,iDate){if(iYear<0){return false;}
if(iDate<1||iDate>31){return false;}
if(iMonth<1||iMonth>12){return false;}
return true;}
function ValidDate_1(sDate){var re=/^(\d{4})\-(\d{2})\-(\d{2})$/;if(sDate.match(re)==null){return false;}
var arr=re.exec(sDate);return IsValidDateCombination(parseInt(RegExp.$1,10),parseInt(RegExp.$2,10),parseInt(RegExp.$3,10));}
function ValidDate_2(sDate){var re=/^(\d{2})\-(\d{2})\-(\d{2})$/;if(sDate.match(re)==null){return false;}
var arr=re.exec(sDate);return IsValidDateCombination(parseInt(RegExp.$1,10),parseInt(RegExp.$2,10),parseInt(RegExp.$3,10));}
function ValidDate_3(sDate){var re=/^(\d{2})\-(\d{2})\-(\d{4})$/;if(sDate.match(re)==null){return false;}
var arr=re.exec(sDate);return IsValidDateCombination(parseInt(RegExp.$3,10),parseInt(RegExp.$2,10),parseInt(RegExp.$1,10));}
function ValidDate_4(sDate){var re=/^(\d{2})\-(\d{2})\-(\d{2})$/;if(sDate.match(re)==null){return false;}
var arr=re.exec(sDate);return IsValidDateCombination(parseInt(RegExp.$3,10),parseInt(RegExp.$2,10),parseInt(RegExp.$1,10));}
function Validator_Date(vValue,oOptions){vValue=vValue.replace(/[\/\.\\]+/g,'-');if(isDefined(oOptions)&&isDefined(oOptions.date_format)){var sDateFormatId=oOptions.date_format;var oData=mapDateFormat_Data[sDateFormatId];if(isDefined(oData)){var oValidateFunction=oData.handler;return oValidateFunction(vValue);}}
return false;}
function Validator_Date_Message(oOptions){if(isDefined(oOptions)&&isDefined(oOptions.date_format)){var sDateFormatId=oOptions.date_format;var oData=mapDateFormat_Data[sDateFormatId];if(isDefined(oData)){var sFormat=oData.format;return'The required date format is ['+sFormat+'].';}}
return'Enter a valid date.';}
function Validator_RegExp(vValue,oOptions){if(isDefined(oOptions)&&isDefined(oOptions.reg_exp)){var sRegExp=oOptions.reg_exp;if(sRegExp.indexOf('/')==-1){sRegExp='/'+sRegExp+'/';}
var oRegExp=eval(sRegExp);return(vValue.match(oRegExp)!=null);}
return true;}
function Validator_RegExp_Message(oOptions){if(isDefined(oOptions)&&isDefined(oOptions.reg_exp)){var sRegExp=oOptions.reg_exp;return'A value that matches the regular expression ['+sRegExp+'] is required.';}
return'';}
var MapValidatorName_Validator={__validator__int:Validator_IsInteger,__validator__positive_int:Validator_IsPositiveInteger,__validator__nonnegative_int:Validator_IsNonNegativeInteger,__validator__not_empty:Validator_IsNotEmpty,__validator__empty_or_positive_int:Validator_EmptyOrPositiveInteger,__validator__empty_or_nonnegative_int:Validator_EmptyOrNonNegativeInteger,__validator__none:Validator_None,__validator__email:Validator_Email,__validator__character:Validator_Character,__validator__number:Validator_Number,__validator__phone:Validator_Phone,__validator__date:Validator_Date,__validator__reg_exp:Validator_RegExp}
var MapValidatorName_Message={__validator__int:Validator_IsInteger_Message,__validator__positive_int:Validator_IsPositiveInteger_Message,__validator__nonnegative_int:Validator_IsNonNegativeInteger_Message,__validator__not_empty:Validator_IsNotEmpty_Message,__validator__empty_or_positive_int:Validator_EmptyOrPositiveInteger_Message,__validator__empty_or_nonnegative_int:Validator_EmptyOrNonNegativeInteger_Message,__validator__none:Validator_None_Message,__validator__email:Validator_Email_Message,__validator__character:Validator_Character_Message,__validator__number:Validator_Number_Message,__validator__phone:Validator_Phone_Message,__validator__date:Validator_Date_Message,__validator__reg_exp:Validator_RegExp_Message}
function ValidateFieldValue(vValue,vValidator,oOptions){if(isDefined(MapValidatorName_Validator[vValidator])){return MapValidatorName_Validator[vValidator](vValue,oOptions);}
return true;}
var ATTRIBUTE_VALIDATOR_VALUE='value_validator';var ATTRIBUTE_VALIDATOR_OPTIONS='validator_options';function ValidateField(oField){var sValidatorValue=oField.getAttribute(ATTRIBUTE_VALIDATOR_VALUE);if(sValidatorValue!=null){var oOptions=null;var sOptions=oField.getAttribute(ATTRIBUTE_VALIDATOR_OPTIONS);if(sOptions!=null){oOptions=eval('('+sOptions+')')}
return ValidateFieldValue(GetFieldValue(oField),sValidatorValue,oOptions);}
return true;}
function CheckFieldValidation(oField){if(!ValidateField(oField)){alert('Incorect Value!\n\nValue should be validated as:\n'+Validator_GetMessage(oField));}}
function Validator_SetFieldValidators(oField,sValidatorIdent,sValidatorOptions){if(sValidatorOptions){oField.setAttribute(ATTRIBUTE_VALIDATOR_OPTIONS,sValidatorOptions);}
oField.setAttribute(ATTRIBUTE_VALIDATOR_VALUE,sValidatorIdent);}
function Validator_SetFieldEvents(oField,sAction){if(!sAction){sAction='CheckFieldValidation(this)';}
if(oField.tagName=='INPUT'||oField.tagName=='TEXTAREA'){if(oField.getAttribute('type')=='checkbox'||oField.getAttribute('type')=='radio'){oField.onclick=new Function(sAction);}else{oField.onblur=new Function(sAction);}}else if(oField.tagName=='SELECT'){oField.onchange=new Function(sAction);}}
function Validator_GetMessage(oField){var vValidator=oField.getAttribute(ATTRIBUTE_VALIDATOR_VALUE);if(vValidator!=null){var oOptions=null;var sOptions=oField.getAttribute(ATTRIBUTE_VALIDATOR_OPTIONS);if(sOptions!=null){oOptions=eval('('+sOptions+')')}
if(isDefined(MapValidatorName_Message[vValidator])){return MapValidatorName_Message[vValidator](oOptions);}}
return'';}
function AddWildcard(sFieldID,sValue){var oField=document.getElementById(sFieldID);if(oField!=null){oField.value+=" "+sValue;}}
function ToggleWildcardsLink(){var wcHiddenLayer=document.getElementById('wildcards_list');var wcLinksLayer=document.getElementById('wildcards_list_link');if(wcHiddenLayer&&wcLinksLayer){if(wcHiddenLayer.style.display!='none'){wcHiddenLayer.style.display='none';wcLinksLayer.innerHTML='More &raquo;';}else{wcHiddenLayer.style.display='block';wcLinksLayer.innerHTML='Hide &laquo;';}}}


function Stack(){var self=new Array();self.top=function(){if(this.length){return this[this.length-1];}else{return null;}}
self.isEmpty=function(){return(this.length==0);}
self.empty=function(){this.length=0;}
return self;}


function GetElementText(oElement){var sText='';if(document.all){sText=oElement.innerText;}else{for(var i=0;i<oElement.childNodes.length;i++){var oChildNode=oElement.childNodes[i];if(oChildNode.nodeType==RTE_CONST.NODE_TYPE_TEXT){sText+=oChildNode.nodeValue;}else{sText+=GetElementText(oChildNode);}}}
return sText;}
function MoveCursorAfterElement(oElement,oRng){var oTextSibling=oElement.ownerDocument.createElement('FONT');oTextSibling.className=RTE_CONST.DEFAULT_CSS_STYLE;oTextSibling.innerHTML='&nbsp;';if(oElement.nextSibling){oElement.parentNode.insertBefore(oTextSibling,oElement.nextSibling);}else{oElement.parentNode.appendChild(oTextSibling);}
var oNextSibling=oTextSibling;oRng.moveToElementText(oNextSibling);}
function MoveCursorBeforeElement(oElement,oRng){var oTextSibling=oElement.ownerDocument.createElement('FONT');oTextSibling.className=RTE_CONST.DEFAULT_CSS_STYLE;oTextSibling.innerHTML='&nbsp;';oElement.parentNode.insertBefore(oTextSibling,oElement);var oPrevSibling=oTextSibling;oRng.moveToElementText(oPrevSibling);}
function IsCharacterKeyDown(iKeyCode){if((iKeyCode<48||iKeyCode>111)&&iKeyCode!=9&&iKeyCode!=32&&iKeyCode!=144&&iKeyCode!=188&&iKeyCode!=190&&iKeyCode!=191&&iKeyCode!=192&&iKeyCode!=219&&iKeyCode!=220&&iKeyCode!=221&&iKeyCode!=222){return false;}
return true;}


function Tidy(){var stack=new Stack;var delay=new Stack;var clean=new Stack;var usage=new Object;var arrAllowedTags={};var arrReplaceTags={};var arrTagRules={};var arrRecursiveRemoveTags={};function HandleTagAttributes(oElement){var sTag=oElement.tag;KeepAttributes(oElement,arrAllowedTags[sTag]);}
function HandleAllTagAttributes(oElement){KeepAttributes(oElement,arrAllowedTags[TIDY_CONST.TAG_ALL]);}
function KeepAttributes(oElement,arrAttributes){for(var iAttrIndex=0;iAttrIndex<arrAttributes.length;iAttrIndex++){var sAttrName=arrAttributes[iAttrIndex];var sValue=oElement.getAttribute(sAttrName);if(sValue!=undefined){oElement.setAttribute(sAttrName,sValue);}}}
function RecursiveRemove(oElement){if(isDefined(arrRecursiveRemoveTags[oElement.tag])){oElement.skip(1);}}
this.filter=function(sSource){var oBaseTransform=new TidyTransformation();oBaseTransform.addRule(TIDY_CONST.TAG_ALL,RecursiveRemove);for(var sTag in arrTagRules){for(var i=0;i<arrTagRules[sTag].length;i++){oBaseTransform.addRule(sTag,arrTagRules[sTag][i]);}}
for(var sTag in arrAllowedTags){var oHandler=(sTag==TIDY_CONST.TAG_ALL)?HandleAllTagAttributes:HandleTagAttributes;oBaseTransform.addRule(sTag,oHandler);}
return this.transform(sSource,[oBaseTransform])}
this.transform=function(sSource,arrTidyTransformations){sSource=sSource.replace(/<!--(\n|.)*?-->/gi,'');sSource=sSource.replace(/\r\n|\n|\n\r/g,' ');stack.empty();delay.empty();clean.empty();var iCurr;var arrElements=new Array();var re=new RegExp(/(<([^<>])+>)|([^<>]+)/gi);var arr=sSource.match(re);if(arr){for(iCurr=0;iCurr<arr.length;iCurr++){var oElement=new TidyElement(arr[iCurr]);arrElements[arrElements.length]=oElement;}}
for(iCurr=0;iCurr<arrElements.length;iCurr++){var currElem=arrElements[iCurr];if(currElem.isText){InsertText(currElem);}
else if(currElem.isClosing){InsertClosingTag(currElem);}
else{InsertOpeningTag(currElem);}}
Finalize();return BuildClean(arrTidyTransformations);}
this.addTagReplacement=function(sTag,sNewTag){arrReplaceTags[sTag]=sNewTag;}
this.addTagToRemoveRecursive=function(sTagName){arrRecursiveRemoveTags[sTagName]=1;}
this.addAllowedTag=function(sTagName,arrAttributes){if(isUndefined(arrAllowedTags[sTagName])){arrAllowedTags[sTagName]=[];}
for(var i=0;i<arrAttributes.length;i++){arrAllowedTags[sTagName].push(arrAttributes[i]);}}
this.addTagRule=function(sTagName,fRule){if(isUndefined(arrTagRules[sTagName])){arrTagRules[sTagName]=[];}
arrTagRules[sTagName].push(fRule);}
this.isTagAllowed=function(sTagName){return isDefined(arrAllowedTags[sTagName]);}
function InsertText(oElement){if((!stack.isEmpty()&&stack.top().applyDelayedFormatting)||stack.isEmpty()){while(!delay.isEmpty()){var delayed=delay.pop();stack.push(delayed);clean.push(delayed);}}
clean.push(oElement);}
function InsertOpeningTag(oElement){if(oElement.isSingle){clean.push(oElement);return;}
if(oElement.isSection){while(!stack.isEmpty()&&(stack.top().isFormatting||!stack.top().canNest(oElement))){ImplicitClose();}}
stack.push(oElement);clean.push(oElement);if(usage[oElement.tag]){usage[oElement.tag]++;}
else{usage[oElement.tag]=1;}
if(oElement.applyDelayedFormatting){for(var i=delay.length-1;i>=0;i--){var delayed=delay[i].clone();stack.push(delayed);clean.push(delayed);}}}
function InsertClosingTag(oElement){if((stack.isEmpty()||!oElement.isSection&&oElement.tag!=stack.top().tag)||(oElement.isSection&&!usage[oElement.tag])){if(!delay.isEmpty()&&oElement.tag==delay.top().tag){delay.pop();return;}
return;}
while(!stack.isEmpty()&&stack.top().tag!=oElement.tag){ImplicitClose();}
clean.push(oElement);stack.pop();while(!delay.isEmpty()&&delay.top().level-1>stack.length){var delayed=delay.pop();}}
function ImplicitClose(){var oElement=stack.top();if(oElement.isFormatting){oElement.level=stack.length;delay.push(oElement);}
if(oElement.isTag){var sChunk='</'+oElement.tag+'>';clean.push(new TidyElement(sChunk));}
stack.pop();usage[oElement.tag]--;}
function Finalize(){while(!stack.isEmpty()){ImplicitClose();}}
function BuildClean(arrTidyTransformations){var iCurr,iIndex;var stack=new Stack;var ident=new Stack;var iSkipping=0;for(iCurr=0;iCurr<clean.length;iCurr++){var oElement=clean[iCurr];if(oElement.isTag){oElement.parseAttributes();if(!self.isTagAllowed(oElement.tag)){oElement.skip();}
if(arrTidyTransformations){for(var iIndex=0;iIndex<arrTidyTransformations.length;iIndex++){arrTidyTransformations[iIndex].apply(oElement,ident);}}
switch(oElement.skipFlag){case 1:continue;case 2:iSkipping+=((oElement.isClosing)?1:-1);};if(iSkipping){continue;}
oElement.buildAttributes();if(oElement.isOpening&&!ident.isEmpty()&&!oElement.canBeNestedInTag(ident.top())){continue;}
if(oElement.isClosing&&(ident.isEmpty()||ident.top()!=oElement.tagId)){continue;}
if(oElement.isOpening){if(!oElement.isSingle){ident.push(oElement.tagId);}}
else{ident.pop();}}
if(iSkipping){continue;}
if(!stack.isEmpty()&&oElement.isClosing&&oElement.isFormatting&&oElement.tagId==stack.top().tagId&&stack.top().isOpening){stack.pop();}
else{stack.push(oElement);}}
var arrTags=new Array(stack.length);for(iCurr=0;iCurr<stack.length;iCurr++){arrTags[iCurr]=stack[iCurr].value;}
return arrTags.join('');}
var self=this;}


function TidyElement(sChunk){this.isTag=false;this.isText=false;var sValue,bIsClosing,sTagName,sAttributes;if(sChunk.match(/^(<(\/?)([a-z0-9:?]+)\s*(.*)>)$/im)){sValue=RegExp.$1;bIsClosing=(RegExp.$2=='/');sTagName=RegExp.$3.toUpperCase();sAttributes=RegExp.$4;this.isTag=true;}else{this.isText=true;sValue=sChunk;}
this.sourceChunk=sChunk;if(this.isText){this.value=sValue;this.attributes='';}else{this.value=sValue;this.isClosing=bIsClosing;this.isOpening=!this.isClosing;this.tag=sTagName.toUpperCase();this.attributes=sAttributes;this.skipFlag=0;this.canNest=TidyElement__CanNest;this.canBeNestedInTag=TidyElement__CanBeNestedInTag;this.parseAttributes=TidyElement__ParseAttributes;this.buildAttributes=TidyElement__BuildAttributes;this.getAttribute=TidyElement__GetAttribute;this.setAttribute=TidyElement__SetAttribute;this.delAttribute=TidyElement__DelAttribute;this.skip=TidyElement__Skip;this.rename=TidyElement__Rename;this.clone=TidyElement__Clone;this.newAttributesCollection=new Object;this.oldAttributesCollection=new Object;this.tagId=TidyTagIds[sTagName];this.isFormatting=TidyTagFormat[this.tagId];this.isSingle=TidyTagSingle[this.tagId];this.isSection=TidyTagSection[this.tagId];this.isTextContainer=TidyTagContainer[this.tagId];this.applyDelayedFormatting=TidyTagDFApply[this.tagId];this.resetDelayedFormatting=TidyTagDFReset[this.tagId];}}
function TidyElement__Clone(){var oNewElem=new TidyElement(this.sourceChunk);for(var prop in this){oNewElem[prop]=this[prop]}
return oNewElem;}
function TidyElement__CanNest(oElement){if(this.isText){return false;}
else if(oElement.isText){return true;}
var bCanNest=false;try{bCanNest=TidyTagNest[this.tagId][oElement.tagId];}catch(e){}
return bCanNest}
function TidyElement__CanBeNestedInTag(iTagId){return TidyTagNest[iTagId][this.tagId];}
function TidyElement__ParseAttributes(){this.oldAttributesCollection=new Object;this.newAttributesCollection=new Object;if(this.isClosing){return;}
var sAttributes;var arrPair;var iIndex;sAttributes=this.attributes.match(/([a-z_\-]+)\s*=\s*("[^"]*"|'[^']*'|[^\s]*)/ig);if(sAttributes!=null){for(iIndex=0;iIndex<sAttributes.length;iIndex++){arrPair=sAttributes[iIndex].match(/^([a-z_\-]+)\s*=\s*("[^"]*"|'[^']*'|[^\s]*)$/i);var sName=arrPair[1];var sValue=arrPair[2];if(sValue.charAt(0)=="'"||sValue.charAt(0)=='"'){sValue=sValue.substr(1,sValue.length-2);}
this.oldAttributesCollection[sName.toLowerCase()]=sValue;}}}
function TidyElement__GetAttribute(sName){sName=sName.toLowerCase();var sValue=(typeof(this.newAttributesCollection[sName])!='undefined')?this.newAttributesCollection[sName]:this.oldAttributesCollection[sName]
return sValue;}
function TidyElement__SetAttribute(sName,sValue){return this.newAttributesCollection[sName]=sValue;}
function TidyElement__DelAttribute(sName){this.newAttributesCollection[sName]=null;this.oldAttributesCollection[sName]=null;}
function TidyElement__BuildAttributes(){if(this.isOpening){var iIndex;var arrChunks=new Array;for(var sName in this.newAttributesCollection){arrChunks[arrChunks.length]=' ';arrChunks[arrChunks.length]=sName;var sAttrValue=this.newAttributesCollection[sName];sQuoteChar="'";if(sAttrValue){sQuoteChar=(sAttrValue.toString().indexOf("'")>-1)?'"':"'";}
arrChunks[arrChunks.length]='='+sQuoteChar;arrChunks[arrChunks.length]=sAttrValue;arrChunks[arrChunks.length]=sQuoteChar;}
this.attributes=arrChunks.join('');}
this.value='<'+(this.isClosing?'/':'')+this.tag+this.attributes+'>';}
function TidyElement__Rename(sTagName){sTagName=sTagName.toUpperCase();this.tag=sTagName;this.tagId=TidyTagIds[sTagName];this.isSingle=TidyTagSingle[this.tagId];}
function TidyElement__Skip(bRecursive){this.skipFlag=(bRecursive)?2:1;}


var TIDY_CONST={TAG_ALL:'*',ELEMENT_TYPE_TEXT:1,ELEMENT_TYPE_TAG:2}


var TidyTags=['A','AREA','B','BLOCKQUOTE','BODY','BR','CENTER','COL','COLGROUP','DIV','EM','FONT','FORM','HR','I','IMG','INPUT','LI','MAP','NOBR','OL','OPTION','P','SELECT','SPAN','STRIKE','STRONG','SUB','SUP','TABLE','TBODY','TD','TEXTAREA','TFOOT','TH','THEAD','TR','U','UL','SCRIPT'];var TidyTagIds={};for(var i=0;i<TidyTags.length;i++){TidyTagIds[TidyTags[i]]=i;}
var TidyTagNest=[];TidyTagNest[0]=[0,0,1,0,0,1,0,0,0,0,1,1,0,0,1,1,0,0,0,1,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,1,0,0];TidyTagNest[1]=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];TidyTagNest[2]=[1,0,1,0,0,1,1,0,0,0,1,1,1,1,1,1,1,0,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,0,0,0,0,1,1,0];TidyTagNest[3]=[1,0,1,1,0,1,1,0,0,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,0,0,1,0,0,0,0,1,1,0];TidyTagNest[4]=[1,0,1,1,0,1,1,0,0,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,0,0,1,0,0,0,0,1,1,0];TidyTagNest[5]=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];TidyTagNest[6]=[1,0,1,0,0,1,0,0,0,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,0,0,1,0,0,0,0,1,1,0];TidyTagNest[7]=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];TidyTagNest[8]=[0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];TidyTagNest[9]=[1,0,1,1,0,1,1,0,0,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,0,0,1,0,0,0,0,1,1,0];TidyTagNest[10]=[1,0,1,0,0,1,1,0,0,0,1,1,1,1,1,1,1,0,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,0,0,0,0,1,1,0];TidyTagNest[11]=[1,0,1,0,0,1,1,0,0,0,1,1,1,1,1,1,1,0,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,0,0,0,0,1,1,0];TidyTagNest[12]=[1,0,1,1,0,1,1,0,0,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,0,0,1,0,0,0,0,1,1,0];TidyTagNest[13]=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];TidyTagNest[14]=[1,0,0,0,0,1,1,0,0,0,1,1,1,1,1,1,1,0,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,0,0,0,0,1,1,0];TidyTagNest[15]=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];TidyTagNest[16]=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];TidyTagNest[17]=[1,0,1,1,0,1,1,0,0,1,1,1,1,1,1,1,1,0,1,1,1,0,1,0,1,1,1,1,1,1,0,0,1,0,0,0,0,1,1,0];TidyTagNest[18]=[0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];TidyTagNest[19]=[1,0,1,0,0,1,1,0,0,0,1,1,1,1,1,1,1,0,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,0,0,0,0,1,1,0];TidyTagNest[20]=[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0];TidyTagNest[21]=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];TidyTagNest[22]=[1,0,1,1,0,1,1,0,0,1,1,1,1,1,1,1,1,0,1,1,1,0,0,1,1,1,1,1,1,1,0,0,1,0,0,0,0,1,1,0];TidyTagNest[23]=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];TidyTagNest[24]=[1,0,1,0,0,1,1,0,0,0,1,1,1,1,1,1,1,0,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,0,0,0,0,1,1,0];TidyTagNest[25]=[1,0,1,0,0,1,1,0,0,0,1,1,1,1,1,1,1,0,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,0,0,0,0,1,1,0];TidyTagNest[26]=[1,0,1,0,0,1,1,0,0,0,1,1,1,1,1,1,1,0,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,0,0,0,0,1,1,0];TidyTagNest[27]=[1,0,1,0,0,1,1,0,0,0,1,1,1,1,1,1,1,0,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,0,0,0,0,1,1,0];TidyTagNest[28]=[1,0,1,0,0,1,1,0,0,0,1,1,1,1,1,1,1,0,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,0,0,0,0,1,1,0];TidyTagNest[29]=[0,0,0,0,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,1,1,0,0,0];TidyTagNest[30]=[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,0,0];TidyTagNest[31]=[1,0,1,1,0,1,1,0,0,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,0,0,1,0,0,0,0,1,1,0];TidyTagNest[32]=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,0];TidyTagNest[33]=[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,0,0];TidyTagNest[34]=[1,0,1,1,0,1,1,0,0,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,0,0,1,0,0,0,0,1,1,0];TidyTagNest[35]=[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,1,0,0,0];TidyTagNest[36]=[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0];TidyTagNest[37]=[1,0,1,0,0,1,1,0,0,0,1,1,1,1,1,1,1,0,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,0,0,0,0,1,1,0];TidyTagNest[38]=[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0];TidyTagNest[39]=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];var TidyTagFormat=[0,0,1,0,0,0,0,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,1,0,0];var TidyTagSingle=[0,1,0,0,0,1,0,1,0,0,0,0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];var TidyTagSection=[0,0,0,1,1,1,0,0,0,1,0,0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,0,0,1,1,1,0,1,1,1,1,0,1,0];var TidyTagDFApply=[0,0,0,1,1,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];var TidyTagDFReset=[0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0];var TidyTagContainer=[1,0,0,0,1,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,1,0,1,0,0,1,1,0,0,1,0,0,0,0,0,0,0,0];


function TidyTransformation(){var rules=[];this.addRule=function(sTagName,fHandler){if(sTagName==TIDY_CONST.TAG_ALL){if(typeof(rules[TIDY_CONST.TAG_ALL])=='undefined'){rules[TIDY_CONST.TAG_ALL]=[];}
rules[TIDY_CONST.TAG_ALL].push(fHandler);}else{var iTagId=TidyTagIds[sTagName];if(typeof(iTagId)=='undefined'){return;}
if(!rules[iTagId]){rules[iTagId]=[];}
rules[iTagId].push(fHandler);}}
this.apply=function(oElement,arrStack){var arrTrans=rules[oElement.tagId];if(arrTrans){for(var iCurr=0;iCurr<arrTrans.length;iCurr++){arrTrans[iCurr](oElement,arrStack);}}
for(var iCurr=0;iCurr<rules[TIDY_CONST.TAG_ALL].length;iCurr++){rules[TIDY_CONST.TAG_ALL][iCurr](oElement,arrStack);}}}


RTE_CONST={COMMAND_INSERT_ORDERED_LIST:'InsertOrderedList',COMMAND_INSERT_UNORDERED_LIST:'InsertUnorderedList',COMMAND_BOLD:'Bold',COMMAND_ITALIC:'Italic',COMMAND_UNDERLINE:'Underline',COMMAND_STRIKETHROUGH:'StrikeThrough',COMMAND_ALIGN_RIGHT:'JustifyRight',COMMAND_ALIGN_CENTER:'JustifyCenter',COMMAND_ALIGN_LEFT:'JustifyLeft',COMMAND_ALIGN_JUSTIFY:'JustifyFull',COMMAND_COPY:'Copy',COMMAND_CUT:'Cut',COMMAND_PASTE:'Paste',COMMAND_INSERT_IMAGE:'InsertImage',COMMAND_INSERT_LINK:'CreateLink',COMMAND_UNLINK:'UnLink',COMMAND_INDENT_INCREASE:'Indent',COMMAND_INDENT_DECREASE:'Outdent',COMMAND_UNSELECT:'Unselect',COMMAND_UNDO:'Undo',COMMAND_REDO:'Redo',COMMAND_LIVE_RESIZE:'LiveResize',COMMAND_USE_CSS:'UseCss',COMMAND_SUBSCRIPT:'Subscript',COMMAND_SUPERSCRIPT:'Superscript',COMMAND_DELETE:'Delete',COMMAND_REMOVE_FORMAT:'RemoveFormat',COMMAND_FONT_NAME:'FontName',COMMAND_FORE_COLOR:'ForeColor',EVENT_SELECTION_CHANGED:'rte_selection_changed',EVENT_NEW_CONTENT_SET:'rte_new_content_set',EVENT_EXPORT_CONTENT:'rte_export_content',EVENT_RTE_INSTANTIATED:'rte_instantiated',EVENT_RTE_CONTENT_RESIZED:'rte_content_resized',EVENT_FINISH_EDIT:'rte_finish_edit',LANG_EN:'en',LANG_BG:'bg',PLUGINS_REL_DIR:'Plugins/',IMAGES_REL_DIR:'Images/',CONTENT_AREA_PREFIX:'ca',TAG_ALL:'*',EDITOR_PREFIX:'rte_editor_',TOOLBAR_PREFIX:'rte_toolbar_',EDITOR_STYLE_HOLDER:'css_style',HELP_KEY_CTRL:1,HELP_KEY_ALT:2,HELP_KEY_SHIFT:3,CTRL_KEY_SHORTCUT:1,PLAIN_SHORTCUT:2,ALT_KEY_SHORTCUT:3,SHIFT_KEY_SHORTCUT:4,DEFAULT_CSS_STYLE:'plain',SELECTED_CSS_STYLE:'selected',PROP_PANEL_LAYOUT_AREA_PREFIX:'ppla',PROP_PANEL_TITLE_AREA_PREFIX:'pplt',BOTTOM_RIGHT_AREA_PREFIX:'bra',TMP_ID:'temp_id',TMP_ID2:'temp_id2',TMP_ID3:'temp_id3',TMP_ID4:'temp_id4',NODE_TYPE_TEXT:3,NODE_TYPE_ELEMENT:1,MESSAGE_TYPE_WARNING:1,MESSAGE_TYPE_INFO:2,MESSAGE_TYPE_WAIT:3,MESSAGE_TYPE_HINT:4,LL_DEBUG:1,LL_ACTION:2,HINT_TEXT_ATTR:'hint_message',qqq:'qqq'}
RTE_CONST.DEFAULT_LANGUAGE_ID=RTE_CONST.LANG_EN;


function assert(sMessage,bCondition){if(!bCondition){throw new RTEException('Assert: '+sMessage);}}


var RTE_Config={"ext_file_dep":{"js":["/Scripts/lib/ecma_extensions.js","/Scripts/lib/form_fields_helpers.js","/Scripts/lib/stack.js","/Scripts/lib/dom_utils.js","/Scripts/Tidy/Tidy.js","/Scripts/Tidy/TidyElement.js","/Scripts/Tidy/Tidy_Constants.js","/Scripts/Tidy/Tidy_Config.js","/Scripts/Tidy/TidyTransformation.js","RTE_CONST.js","assert.js","RTE_Config.js","RTEEventManager.js","RTEException.js","RTEExceptions.js","RTEFeatureSet.js","RTEPlugin.js","RTEPropertyPanel.js","RTEPropertyPanel_Config.js","RTERange.js","RTESelection.js","RTEToolbar.js","RTEToolbar_Config.js","RTEToolbarItem.js","RTEHelpers.js","ToolbarItems/RTEButton.js","ToolbarItems/RTEButton_Config.js"],"html":["templates.html"]},"editor_width":300,"editor_height":300,"css":["Core/css/rte.css","Core/css/rte_global.css"],"css_editor_style":"","baseDir":"","body_css_class":"rte","icon_info_msg":"icon_info_msg.gif","icon_wait_msg":"icon_wait_msg.gif","icon_warning_msg":"icon_warning_msg.gif","icon_hint_msg":"icon_hint_msg.gif","icon_resize_up":"icon_resize_up.gif","icon_resize_down":"icon_resize_down.gif","time_to_display_status_message":4000,"templates_holder_id":"rte_core_templates"}
RTE_Config.language=RTE_CONST.LANG_BG;RTE_Config.log_level=RTE_CONST.LL_ACTION;


function RTEEventManager(oRTE){if(isUndefined(oRTE)){throw new IllegalArgumentException('No RTE object passed!');}
this.RTE=oRTE;var eventHandlers={};var isIE=(document.all);this.addEventHandler=function(sEventType,oObjHandler,sMethodName,oOptions){if(isUndefined(sEventType)||sEventType==''){throw new IllegalArgumentException('No Event type passed!');}
if(isUndefined(oObjHandler)){throw new IllegalArgumentException('No ObjectHandler passed!');}
if(isUndefined(sMethodName)||sMethodName==''){throw new IllegalArgumentException('No Method name passed!');}
if(isUndefined(oObjHandler[sMethodName])){throw new IllegalArgumentException('Passed Method name ['+sMethodName+'] not found in object !');}
if(isUndefined(eventHandlers[sEventType])){eventHandlers[sEventType]=[];}
eventHandlers[sEventType].push({obj:oObjHandler,method:sMethodName,options:oOptions});}
function RegisterEvent(sEventType,oDocument){assert('No event type passed',(isDefined(sEventType)&&sEventType!=''));assert('No document object passed',isDefined(oDocument));if(isIE){oRTE.rootElement().attachEvent('on'+sEventType,new Function('RTE_GetById("'+self.RTE.id+'").handleEvent()'));}else{oDocument.addEventListener(sEventType,new Function('e','RTE_GetById("'+self.RTE.id+'").handleEvent(e)'),true);}}
this.fireEvent=function(sEventType){if(isUndefined(sEventType)||sEventType==''){throw new IllegalArgumentException('No Event type passed!');}
return this.handleEvent({type:sEventType});}
this.stopEvent=function(oEvent){if(isUndefined(oEvent)){throw new IllegalArgumentException('No Event passed!');}
oEvent.canceled=true;}
this.handleEvent=function(oEvent){if(isUndefined(oEvent)||isUndefined(oEvent.type)){throw new IllegalArgumentException('No Event object passed!');}
var sEventType=oEvent.type;if(isUndefined(eventHandlers[sEventType])){return;}
for(var i=0;i<eventHandlers[sEventType].length;i++){var oObjHandler=eventHandlers[sEventType][i].obj;var sMethod=eventHandlers[sEventType][i].method;var oOptions=eventHandlers[sEventType][i].options;if(isDefined(oOptions)&&typeof(oOptions.skip_pass_event_object)!='undefined'&&oOptions.skip_pass_event_object){oObjHandler[sMethod]();}else{oObjHandler[sMethod](oEvent);}
if(oEvent.canceled){return false;}}
return true;}
this.init=function(oDocument){if(isUndefined(oDocument)){throw new IllegalArgumentException('No document object passed!');}
for(var i in eventHandlers){RegisterEvent(i,oDocument);}}
this.cancelEventBubbling=function(oEvent){if(isUndefined(oEvent)){throw new IllegalArgumentException('No Event object passed!');}
if(document.all){oEvent.keyCode=0;oEvent.cancelBubble=true;oEvent.returnValue=false;}else{oEvent.preventDefault();oEvent.preventBubble();oEvent.stopPropagation();}}
var self=this;}


function RTEException(sMessage){this.message=sMessage;this.stackTrace=function(){var sTrace='';if(document.all){var oCallerFunction=RTEException.caller;var MAX_LOOP=5;var i=0;while(!isNull(oCallerFunction)&&i<MAX_LOOP){var re=new RegExp("^function (\\w+)","i");if(re.test(oCallerFunction)){sTrace=' -> '+RegExp.$1+sTrace;}
oCallerFunction=oCallerFunction.caller;i++;}}else{try{foo.bar;}catch(e){var arrStackRaw=e.stack.split('\n');var stack=[];for(var i=0;i<arrStackRaw.length-1;i++){var name=arrStackRaw[i].match(/^(\w*)/)[1];if(!name){name='anonymous';}
if(name=='assert'||name=='RTEException'){continue;}
stack.push(name);}
for(var i=1;i<stack.length;i++){sTrace='-> '+stack[i]+sTrace;}}}
return sTrace;}
if(typeof(RTE_ReportError)!='undefined'){RTE_ReportError(undefined,'RTEException thrown:\n'+'Message:['+this.message+']\n'+'StackTrace:['+this.stackTrace()+']');}}


function IllegalArgumentException(sMessage){throw new RTEException(sMessage);}
function RuntimeException(sMessage){throw new RTEException(sMessage);}


function RTEFeatureSet(){this.config={};this.applyPlugins=function(oRTE){if(isUndefined(this.config.plugins)){throw new RuntimeException('No plugins found in config!');}
for(var i=0;i<this.config.plugins.length;i++){oRTE.createAndRegisterPlugin(this.config.plugins[i]);}}
this.apply=function(){}}


function RTEPlugin(){this.id='base_plugin';this.RTE=null;this.config={};this.eventHandlers=[];this.requiredTags=[];this.tagRules=[];this.shortcuts=[];this.watchTags=[];this.toolbarItems={};this.propertyPanel;this.select=function(){}
this.cleanupContent=function(oRootElement){}
this.processPastedContent=function(oRootElement){}
this.handlePropPanelValueChange=function(sPropName,vPropValue){}
this.buildPropPanelValuesFromElement=function(oElement){var oProps={};var sTagName=oElement.tagName;if(isDefined(this.mapPanelProps_AttrNames[sTagName])){for(var sPropName in this.mapPanelProps_AttrNames[sTagName]){var sAttrName=this.getAttrNameForPropName(sTagName,sPropName);var sAttrValue=oElement.getAttribute(sAttrName);oProps[sPropName]=this.getPropValueForAttrValue(sTagName,sAttrName,sAttrValue);}}
return oProps;}
this.setImageHolders=function(sAttrName,sAttrValue,sImageSrc){this.logMessage('setImageHolders','.');var arrAllImages=this.RTE.rootElement().getElementsByTagName('IMG');for(var i=0;i<arrAllImages.length;i++){var oImage=arrAllImages[i];if(oImage.getAttribute(sAttrName)==sAttrValue){oImage.setAttribute('src',sImageSrc);}}}
this.buildElementValuesFromPropPanel=function(sTagName){var oProps={};if(isDefined(this.mapPanelProps_AttrNames[sTagName])){for(var sPropName in this.mapPanelProps_AttrNames[sTagName]){var vPropValue=this.propertyPanel.getPropValue(sPropName);oProps[this.mapPanelProps_AttrNames[sTagName][sPropName]]=this.getAttrValueForPropValue(sTagName,sPropName,vPropValue);}}
return oProps;}
this.getPanelPropertiesList=function(sTagName){var arrPanelProps=[];var oProps=this.mapPanelProps_AttrNames[sTagName];if(isDefined(oProps)){for(var sPropName in oProps){arrPanelProps.push(sPropName);}}
return arrPanelProps;}
this.getTagNameForPropName=function(sPropName){return this.mapPanelProps_TagNames[sPropName];}
this.getPropNameForAttrName=function(sTagName,sAttrName){assert('Tag name ['+sTagName+'] not found in structure.',isDefined(this.mapAttrNames_PanelProps[sTagName]));return this.mapAttrNames_PanelProps[sTagName][sAttrName];}
this.getAttrNameForPropName=function(sTagName,sPropName){assert('Tag name ['+sTagName+'] not found in structure.',isDefined(this.mapPanelProps_AttrNames[sTagName]));return this.mapPanelProps_AttrNames[sTagName][sPropName];}
this.getAttrValueForPropValue=function(sTagName,sPropName,vPropValue){if(isDefined(this.mapPanelProps_AttrValues[sTagName])&&isDefined(this.mapPanelProps_AttrValues[sTagName][sPropName])){var vAttrValue=this.mapPanelProps_AttrValues[sTagName][sPropName][vPropValue]
if(isDefined(vAttrValue)){return vAttrValue;}}
return vPropValue;}
this.getPropValueForAttrValue=function(sTagName,sAttrName,sAttrValue){if(isDefined(this.mapAttrValue_PanelProps[sTagName])&&isDefined(this.mapAttrValue_PanelProps[sTagName][sAttrName])){var vPropValue=this.mapAttrValue_PanelProps[sTagName][sAttrName][sAttrValue];if(isDefined(vPropValue)){return vPropValue;}}
return sAttrValue;}
this.reversePropertiesMaps=function(){assert('No map found for panel property names <-> attribute names!',isDefined(this.mapPanelProps_AttrNames));assert('No map found for panel property values <-> attribute value!',isDefined(this.mapPanelProps_AttrValues));this.mapAttrNames_PanelProps={};this.mapPanelProps_TagNames={};for(var sTagName in this.mapPanelProps_AttrNames){this.mapAttrNames_PanelProps[sTagName]={};for(var sPanelPropName in this.mapPanelProps_AttrNames[sTagName]){this.mapAttrNames_PanelProps[sTagName][this.mapPanelProps_AttrNames[sTagName][sPanelPropName]]=sPanelPropName;assert('Duplicated property name ['+sPanelPropName+']',isUndefined(this.mapPanelProps_TagNames[sPanelPropName]));this.mapPanelProps_TagNames[sPanelPropName]=sTagName;}}
this.mapAttrValue_PanelProps={};for(var sTagName in this.mapPanelProps_AttrValues){this.mapAttrValue_PanelProps[sTagName]={};for(var sPropName in this.mapPanelProps_AttrValues[sTagName]){var sAttrName=this.getAttrNameForPropName(sTagName,sPropName);this.mapAttrValue_PanelProps[sTagName][sAttrName]={};for(var sPropValue in this.mapPanelProps_AttrValues[sTagName][sPropName]){var sAttrValue=this.mapPanelProps_AttrValues[sTagName][sPropName][sPropValue];this.mapAttrValue_PanelProps[sTagName][sAttrName][sAttrValue]=sPropValue;}}}}
this.createPropPanel=function(sPanelLayout){this.propertyPanel=new RTEPropertyPanel(this.RTE,this);this.propertyPanel.setTitle(this.getText('prop_panel_title'));var sLayout=(isDefined(sPanelLayout))?sPanelLayout:this.config.prop_panel_layout;this.propertyPanel.setLayout(sLayout);}
this.hideOtherPanels=function(){if(this.RTE.hasPropertyPanelShown()){var oShownPropPanel=this.RTE.getShownPropertyPanel();if(oShownPropPanel.isPinned()){this.RTE.displayStatusMessage(this.getText('msg_close_other_panel'),RTE_CONST.MESSAGE_TYPE_WARNING);return false;}
this.RTE.hidePropertyPanel();}
return true;}
this.hasPropertyPanel=function(){return(this.propertyPanel!=null);}
this.isLinkSelected=function(){var oLinkElement=this.RTE.searchElement('A',this.RTE.currentElement());if(oLinkElement!=null){return true;}
if(this.RTE.selection.isControl()){return false;}
if(document.all){var oRng=this.RTE.selectionRange().domRange.duplicate();oRng.collapse(true);var oStartElement=oRng.parentElement();if(this.RTE.searchElement('A',oStartElement)!=null){return true;}
var oRng=this.RTE.selectionRange().domRange.duplicate();oRng.collapse(false);var oEndElement=oRng.parentElement();if(this.RTE.searchElement('A',oEndElement)!=null){return true;}}else{var oFocusNode=this.RTE.selection.domSelection.focusNode;var oAnchorNode=this.RTE.selection.domSelection.anchorNode;if(this.RTE.searchElement('A',oFocusNode)!=null||this.RTE.searchElement('A',oAnchorNode)!=null){return true;}}
return false}
this.init=function(){this.register();}
this.configure=function(oConfig){if(isUndefined(oConfig)){throw new IllegalArgumentException('No Config passed!');}
for(var i in oConfig){this.config[i]=oConfig[i];}}
this.imagesDir=function(){return this.RTE.baseDir()+RTE_CONST.PLUGINS_REL_DIR+this.id+'/'+RTE_CONST.IMAGES_REL_DIR;}
this.getImageUrl=function(sImageUrl){if(sImageUrl.indexOf('http://')==0||sImageUrl.indexOf('/')>-1){return sImageUrl;}else{return this.imagesDir()+sImageUrl;}}
this.getText=function(sTextIdent){if(isUndefined(sTextIdent)||sTextIdent==''){throw new IllegalArgumentException('No Text identifier passed!');}
var arrTextProps=this.textProps();if(isUndefined(arrTextProps[sTextIdent])){throw new RuntimeException('Invalid Text identifier ['+sTextIdent+']!');}
return arrTextProps[sTextIdent];}
this.textProps=function(){var iLanguage=this.RTE.getLanguage();if(isUndefined(this.config.texts[iLanguage])){iLanguage=RTE_CONST.DEFAULT_LANGUAGE_ID;assert('No default language found for plugin ['+this.id+']',isDefined(this.config.texts[iLanguage]))}
return this.config.texts[iLanguage];}
this.logMessage=function(sIdent,sMessage,iLogLevel){this.RTE.logMessage(this.id+'::'+sIdent,sMessage,iLogLevel);}
this.register=function(){for(var i=0;i<this.requiredTags.length;i++){this.RTE.addRequiredTag(this.requiredTags[i].tagName,this.requiredTags[i].attributes);}
for(var i=0;i<this.tagRules.length;i++){this.RTE.addTagRule(this.tagRules[i].tagName,this.tagRules[i].handler);}
for(var i=0;i<this.eventHandlers.length;i++){this.RTE.eventManager().addEventHandler(this.eventHandlers[i].type,this,this.eventHandlers[i].method);}
for(var i=0;i<this.shortcuts.length;i++){var iHelpKey=null;if(this.shortcuts[i].ctrlKey){iHelpKey=RTE_CONST.HELP_KEY_CTRL;}else if(this.shortcuts[i].altKey){iHelpKey=RTE_CONST.HELP_KEY_ALT;}else if(this.shortcuts[i].shiftKey){iHelpKey=RTE_CONST.HELP_KEY_SHIFT;}
this.RTE.addShortcut(this.shortcuts[i].key,iHelpKey,this,this.shortcuts[i].method,this.shortcuts[i].skipPreventDefault)}
for(var i in this.toolbarItems){this.RTE.addToolbarItem(this.toolbarItems[i]);}
for(var i=0;i<this.watchTags.length;i++){this.RTE.addWatchTag(this.watchTags[i].tagName,this.watchTags[i].attributes,this)}}
this.shortcut2String=function(oShortcut){if(isUndefined(oShortcut)){throw new IllegalArgumentException('No Shortcut passed!');}
if(isUndefined(oShortcut.key)){throw new IllegalArgumentException('No Shortcut Key passed!');}
var sHelpKeyText='';if(oShortcut.ctrlKey){sHelpKeyText='Ctrl';}else if(oShortcut.altKey){sHelpKeyText='Alt';}else if(oShortcut.shiftKey){sHelpKeyText='Shift';}
if(sHelpKeyText!=''){sHelpKeyText+='+';}
var sKeyText=(isDefined(oShortcut.charCode))?oShortcut.charCode:String.fromCharCode(oShortcut.key);return sHelpKeyText+sKeyText.toUpperCase();}
this.checkSelection=function(){}
this.initToolbarItems=function(){}}


function RTEPropertyPanel(oRTE,oPlugin){this.id=oRTE.id+'_'+oPlugin.id;assert('RTE object not passed!',typeof(oRTE)!='undefined');assert('Plugin object not passed!',typeof(oPlugin)!='undefined');assert('Property panel config was not found!',typeof(RTEPropertyPanel_Config)!='undefined');assert('Space image src [SPACE_IMG_SRC global js var ] not set!',typeof(SPACE_IMG_SRC)!='undefined');var sTitle;var sLayout;var sComposedLayout;var bPinned=false;var oConfig=RTEPropertyPanel_Config;this.setTitle=function(s){if(isUndefined(s)){throw new IllegalArgumentException('No Title passed!');}
sTitle=s;}
this.getTitle=function(){if(isUndefined(sTitle)){throw new RuntimeException('Title not set!');}
return sTitle;}
this.setPinned=function(b){if(isUndefined(b)){throw new IllegalArgumentException('No pinned param passed!');}
bPinned=b;}
this.isPinned=function(){return bPinned;}
this.setLayout=function(s){if(isUndefined(s)){throw new IllegalArgumentException('No Layout passed!');}
sLayout=s;}
this.getPropValue=function(sPropName){if(isUndefined(sPropName)||sPropName==''){throw new RuntimeException('No property name passed!');}
var oField=this.getPropElementByName(sPropName);if(oField==null){throw new RuntimeException('No field for property name ['+sPropName+'] found!');}
return GetFieldValue(oField);}
this.setPropValue=function(sPropName,vValue){if(isUndefined(sPropName)||sPropName==''){throw new RuntimeException('No property name passed!');}
if(isUndefined(vValue)){throw new RuntimeException('No property value for prop name ['+sPropName+'] passed!');}
var oField=this.getPropElementByName(sPropName);if(oField==null){throw new RuntimeException('No field for property name ['+sPropName+'] found!');}
SetFieldValue(oField,vValue);}
this.getPropElementByName=function(sPropName){if(isUndefined(sPropName)||sPropName==''){throw new RuntimeException('No property name passed!');}
return document.getElementById(this.getPropElementId(sPropName));}
this.propElementByNameSetDisabledState=function(sPropName,bDisabled){var oField=this.getPropElementByName(sPropName);if(!oField){throw new RuntimeException('No field for property name ['+sPropName+'] found!');}
oField.disabled=bDisabled;}
this.getHtmlElementById=function(sElementId){if(isUndefined(sElementId)||sElementId==''){throw new RuntimeException('No element id passed!');}
return document.getElementById(this.getHtmlElementId(sElementId));}
this.handlePropValueChange=function(oFormElement){if(isUndefined(oFormElement)){throw new RuntimeException('No Form Element passed!');}
assert('Passed Form Element is with missing ID',oFormElement.id!='');var sPropName=GetPropNameFromElementId(oFormElement.id);var vPropValue=this.getPropValue(sPropName);var vUserSetValue=vPropValue;if(oFormElement.getAttribute('value_filter')){vPropValue=FilterFieldValue(vPropValue,oFormElement.getAttribute('value_filter'));SetFieldValue(oFormElement,vPropValue);}
if(oFormElement.getAttribute('value_validator')){var bValid=ValidateField(oFormElement);if(!bValid){var sInvalidValueMsg=oFormElement.getAttribute('value_invalid_msg');if(sInvalidValueMsg==null){sInvalidValueMsg=oConfig.msg_incorrect_value;sInvalidValueMsg+="\n\nThe field should be validated as:\n"+Validator_GetMessage(oFormElement);}
SetFieldValue(oFormElement,vUserSetValue);this.decorateInValidField(oFormElement);alert(sInvalidValueMsg);return;}
this.decorateValidField(oFormElement);}
oPlugin.handlePropPanelValueChange(sPropName,vPropValue);}
this.getPropElementId=function(sPropName){assert('Property name not passed',isDefined(sPropName)&&sPropName!='');return sPropNamePreffix+sPropName;}
this.getHtmlElementId=function(sElementId){assert('Element id not passed',isDefined(sElementId)&&sElementId!='');return'pp_elem_'+this.id+sElementId;}
this.composeLayout=function(){if(isUndefined(sLayout)){throw new RuntimeException('No Layout set!');}
if(isDefined(sComposedLayout)){return sComposedLayout;}
var oTmplProps=this.getLayoutProps();sComposedLayout=sLayout.supplant(oTmplProps,false,ReplaceTmplVariable);return sComposedLayout;}
this.getLayoutProps=function(){var oTmplProps={};for(var i in oConfig.styles){oTmplProps['__style__'+i]=oConfig.styles[i];}
var sCodeToExecuteOnPropValueChange='RTE_GetById("'+oRTE.id+'").getPluginById("'+oPlugin.id+'").propertyPanel.handlePropValueChange(this)';oTmplProps['__action__onchange']=' onchange = \''+sCodeToExecuteOnPropValueChange+'\'';oTmplProps['__action__onblur']=' onblur   = \''+sCodeToExecuteOnPropValueChange+'\'';oTmplProps['__action__onclick']=' onclick  = \''+sCodeToExecuteOnPropValueChange+'\'';oTmplProps['__action__notify_plugin']=sCodeToExecuteOnPropValueChange;oTmplProps['__hint__init_code']='RTE_GetById("'+oRTE.id+'").showHint(this,this.getAttribute("'+RTE_CONST.HINT_TEXT_ATTR+'"))';oTmplProps['__hint__init']=' onclick = \''+oTmplProps['__hint__init_code']+'\'';var oPluginTextProps=oPlugin.textProps();for(var i in oPluginTextProps){oTmplProps['__text__'+i]=oPluginTextProps[i];}
for(var i in oPlugin.toolbarItems){var oTItem=oPlugin.toolbarItems[i];oTmplProps['__toolbar_item__'+oTItem.name]=oTItem.getHTML();}
oTmplProps['__rte_id__']=oRTE.id;oTmplProps['__plugin_id__']=oPlugin.id;oTmplProps['__image__space']=SPACE_IMG_SRC;return oTmplProps;}
function ReplaceTmplVariable(sVarName,oProps){assert('Variable name not passed',isDefined(sVarName));assert('Variables hash not passed',isDefined(oProps));if(sVarName.indexOf('__propname__')==0){return self.getPropElementId(sVarName.substring('__propname__'.length));}else if(sVarName.indexOf('__elementid__')==0){return self.getHtmlElementId(sVarName.substring('__elementid__'.length));}
return oProps[sVarName];}
var sPropNamePreffix='pp_prop_'+this.id+'_';function GetPropNameFromElementId(sElementId){assert('Element id not passed',isDefined(sElementId)&&sElementId!='');return sElementId.substring(sPropNamePreffix.length);}
this.decorateInValidField=function(oField){oField.style.backgroundColor=oConfig.invalid_field_bckg_color;}
this.decorateValidField=function(oField){oField.style.backgroundColor=oConfig.valid_field_bckg_color;}
this.hide=function(){if(oPlugin.hidePropertyPanelHook){oPlugin.hidePropertyPanelHook(this);}}
this.show=function(){if(oPlugin.showPropertyPanelHook){oPlugin.showPropertyPanelHook(this);}}
var self=this;}


var RTEPropertyPanel_Config={"styles":{"table_fields_holder":" cellpadding='0' cellspacing='2' border='0' style='margin-left:10px;margin-right:10px' align='center'","fielddesc":"class='plain'","fieldholder":"class='plain'","field_text":"class='textfield'          style = 'width:178px;'","field_text_medium":"class='textfield'          style = 'width:106px;'","field_text_small":"class='textfieldsmall'     style = 'width:30px;'","field_select":"class='selectobject'       style = 'width:178px;'","field_select_medium":"class='selectobjectshort'  style = 'width:106px;'","field_select_small":"class='selectobjectshort'  style = 'width:30px;'","field_checkbox":"class='checkbox' style = 'width:13px;height:13px;margin-left:0px;margin-right:0px;margin-top:2px;margin-bottom:2px;'","control_default":"class='control'","default":"class='plain'","section_header":"class='plain' style = 'font-weight:bold;padding:5px' align = 'center' "},"msg_incorrect_value":"Incorrect value!\nPlease correct the marked field.","invalid_field_bckg_color":"#FFFFBF","valid_field_bckg_color":"#FFFFFF"}


function RTERange(oRTESelection){var isIE=(!!document.all);var s=oRTESelection.domSelection;if(isUndefined(oRTESelection)){throw new IllegalArgumentException('No RTESelection instance passed!');}
this.domRange=null;if(isIE){this.domRange=s.createRange();}else{try{this.domRange=s.getRangeAt(0);}catch(ex){this.domRange=oRTESelection.window.document.createRange();try{this.domRange.setStart(s.anchorNode,s.anchorOffset);this.domRange.setEnd(s.focusNode,s.focusOffset);}catch(ex){}}}
this.collapse=function(bStart){if(oRTESelection.isControl()||isDefined(this.domRange.length))return;if(isUndefined(bStart)){bStart=true;}
if(isIE){this.domRange.collapse(bStart);this.domRange.select();}else{if(bStart){oRTESelection.domSelection.collapseToStart();}else{oRTESelection.domSelection.collapseToEnd();}}}
this.currentElement=function(){var r=this.domRange;if(document.all){if(oRTESelection.isControl()||isDefined(r.length)){return r.item(0);}else{return r.parentElement();}}else{var oNode=r.commonAncestorContainer;var helpers=new RTEHelpers;var isSafari=helpers.isSafari();while(oNode.nodeType!=RTE_CONST.NODE_TYPE_ELEMENT){oNode=oNode.parentNode;}
var sContainer=r.startContainer;var sOffset=r.startOffset;var eContainer=r.endContainer;var eOffset=r.endOffset;var sParent=sContainer.parentNode;var eParent=eContainer.parentNode;if(isSafari&&(oNode.tagName.toUpperCase()=='P'||oNode.tagName.toUpperCase()=='A'||oNode.tagName.toUpperCase()=='TD')){var iNumChildren=0;var aChildren=[];var iNumImages=0;var img=null;for(var i=0;i<oNode.childNodes.length;i++){if(oNode.childNodes[i]&&oNode.childNodes[i].tagName){if(oNode.childNodes[i].tagName=='IMG'){iNumImages++;img=oNode.childNodes[i];}
aChildren.push(oNode.childNodes[i]);}}
if(iNumImages==1&&img!=null&&((img.style.float=='right'&&img.align=='right')||(img.style.float=='left'&&img.align=='left'))){return img;}}
if(sContainer.nodeType==RTE_CONST.NODE_TYPE_TEXT&&sContainer.nodeValue.length<=sOffset){for(sOffset=0;sOffset<sParent.childNodes.length;sOffset++){if(sParent.childNodes[sOffset]==sContainer.nextSibling)break;}
sContainer=sParent;}
if(eContainer.nodeType==RTE_CONST.NODE_TYPE_TEXT&&eOffset==0){for(eOffset=0;eOffset<=eParent.childNodes.length;eOffset++){if(eParent.childNodes[eOffset]==eContainer)break;}
eContainer=eParent;}
if(sContainer.nodeType==RTE_CONST.NODE_TYPE_ELEMENT&&sContainer==eContainer&&sOffset==eOffset-1){oNode=sContainer.childNodes[r.startOffset];}
return oNode;}}
this.moveToElementText=function(oElement){var sel=oRTESelection.domSelection;var rng=this.domRange;if(isUndefined(oElement)){throw new IllegalArgumentException('No HTMLElement instance passed!');}
if(isIE){if(oRTESelection.isControl()||isDefined(rng.length))return;var oRng=oRTESelection.window.document.body.createTextRange();oRng.collapse();oRng.moveToElementText(oElement);oRng.select();this.domRange=oRng;}else{if(sel.setBaseAndExtent){var length=oElement.innerText.length;if(length){sel.setBaseAndExtent(oElement,0,oElement,length-1);}else{rng.selectNode(oElement);sel.removeAllRanges();sel.addRange(rng);}}else
if(sel.selectAllChildren){sel.selectAllChildren(oElement);}}}}


function RTESelection(oWindow){var helpers=new RTEHelpers;var isIE=helpers.isIE();var isSafari=helpers.isSafari();if(isUndefined(oWindow)){throw new IllegalArgumentException('No Window instance passed!');}
this.window=oWindow;var arrControlSelectionTags=['IMG','TABLE'];this.domSelection=(isIE)?oWindow.document.selection:oWindow.getSelection();this.createRange=function(){if(Browser.Engine.trident&&navigator.appVersion.indexOf("MSIE 8")==-1)this.window.focus();return new RTERange(this);}
this.clear=function(){if(isIE){this.selection.clear();}else{this.selection.deleteFromDocument();}}
this.isControl=function(){if(isIE){return(this.domSelection.type=='Control')}else{if(this.domSelection.toString()!=''){return false}
var oFocusNode=this.domSelection.focusNode;if(!oFocusNode||oFocusNode.nodeType==RTE_CONST.NODE_TYPE_TEXT){return false;}
var arrFocusNodes=[oFocusNode];if(isSafari){for(var idx=0;idx<oFocusNode.childNodes.length;idx++){arrFocusNodes.push(oFocusNode.childNodes[idx]);}}
for(var idx=0;idx<arrFocusNodes.length;idx++){var oSelectedTag=arrFocusNodes[idx].tagName;for(var i=0;i<arrControlSelectionTags.length;i++){if(arrControlSelectionTags[i]==oSelectedTag){return true;}}}
return false}}}


function RTEToolbar(id){if(isUndefined(id)){throw new IllegalArgumentException('No ID passed!');}
this.id=id;assert('Config was not found',typeof(RTEToolbar_Config)!='undefined')
var config=RTEToolbar_Config;var items=[];var sLayoutTemplate;this.disable=function(){for(var i=0;i<items.length;i++){items[i].disable();}}
this.enable=function(){for(var i=0;i<items.length;i++){items[i].enable();}}
this.composeLayout=function(){assert('No Layout template set!',isDefined(sLayoutTemplate));var oProps={__delimiter__:config.delimiter};for(var i=0;i<items.length;i++){var oItem=items[i];var sItemIdent='__'+oItem.plugin.id+'__'+oItem.name;oProps[sItemIdent]=oItem.getHTML();}
return'<span style = "display:block" id = '+this.id+'>'+sLayoutTemplate.supplant(oProps)+'</span>';}
this.addItem=function(oToolbarItem){if(isUndefined(oToolbarItem)){throw new IllegalArgumentException('No ToolbarItem passed!');}
items.push(oToolbarItem);}
this.setLayoutTemplate=function(sLayout){if(isUndefined(sLayout)||sLayout==''){throw new IllegalArgumentException('No layout passed!');}
sLayoutTemplate=sLayout;}
this.hide=function(){if(!IsInstantiated()){throw new RuntimeException('Toolbar not instantiated!');}
document.getElementById(this.id).style.display='none';}
this.show=function(){if(!IsInstantiated()){throw new RuntimeException('Toolbar not instantiated!');}
document.getElementById(this.id).style.display='block';}
this.isShown=function(){return(document.getElementById(this.id).style.display=='block');}
function IsInstantiated(){var oDomElement=document.getElementById(self.id);if(oDomElement==null){return false;}
return true;}
var self=this;}


RTEToolbar_Config={layout:'',delimiter:'<img width = 5 height = 1  src = "{__img_space__}">'}


function RTEToolbarItem(){this.id=null;var disabled=false;this.plugin=null;this.name=null;this.disable=ToolbarItem__Disable;this.enable=ToolbarItem__Enable;this.getHTML=ToolbarItem__GetHTML;}
function ToolbarItem__Disable(){}
function ToolbarItem__Enable(){}
function ToolbarItem__GetHTML(){return'';}


function RTEHelpers()
{this.isBrowserSupported=function(){if(document.all){var version=navigator.appVersion.substr(navigator.appVersion.indexOf('MSIE')+5);if(navigator.userAgent.toLowerCase().indexOf('opera')>-1){return false;}
if(isNaN(parseInt(version))||parseInt(version)<5.5){return false;}}else{var iRV=navigator.userAgent.indexOf('rv:');if(iRV==-1){if(navigator.vendor.indexOf('Apple')!=-1||navigator.vendor.indexOf('Google')!=-1){var version=parseInt(navigator.appVersion.substr(navigator.appVersion.indexOf('Safari')+7));if(version>=500)return true;}
return false;}else{var iVersion=parseFloat(navigator.userAgent.substring(iRV+3));if(iVersion<1.4){return false;}}}
return true;}
this.isIE=function(){return!!document.all;}
this.isSafari=function(){return(navigator&&navigator.vendor&&navigator.vendor.indexOf('Apple')!=-1);}
this.isSafari3=function(){return(navigator&&navigator.vendor&&navigator.vendor.indexOf('Apple')!=-1&&navigator.userAgent.indexOf("Version/3")!=-1);}
this.isMozilla=function(){return(navigator.userAgent&&navigator.userAgent.indexOf('rv:')!=-1);}}


function RTEButton(oProps){if(isUndefined(oProps)){throw new IllegalArgumentException('No properties passed!');}
if(isUndefined(oProps.id)){throw new IllegalArgumentException('No ID passed!');}
if(isUndefined(oProps.description)){throw new IllegalArgumentException('No description passed!');}
if(isUndefined(oProps.imageSrc)||oProps.imageSrc==''){throw new IllegalArgumentException('No image source passed!');}
if(isUndefined(oProps.plugin)){throw new IllegalArgumentException('No plugin passed!');}
if(isUndefined(oProps.method)||oProps.method==''){throw new IllegalArgumentException('No method passed!');}
if(isUndefined(oProps.name)){throw new IllegalArgumentException('No button name passed!');}
assert('No config for RTE button found',typeof(RTEButton_Config)!='undefined')
var config=RTEButton_Config;var iImageWidth=config.image_width;if(isDefined(oProps.image_width)){iImageWidth=oProps.image_width;}
var iImageHeight=config.image_height;if(isDefined(oProps.image_height)){iImageHeight=oProps.image_height;}
this.id=oProps.id;this.plugin=oProps.plugin;this.name=oProps.name;this.command=oProps.command;var sShortcut=oProps.shortcut;this.domImgId='btn_'+this.id;var description=oProps.description;var imageSrc=oProps.imageSrc;var disabled=false;var method=oProps.method;this.getHTML=function(){var sTitle=description.replace('\"','&#34;');if(isDefined(sShortcut)){var sShortcutText='';sShortcutText=' ('+sShortcut+')';sTitle+=sShortcutText;}
return'<img '+' style  = "border-color:'+config.border_color_normal+';" border = '+config.border_width+''+' id     = "'+this.domImgId+'"'+' width  = "'+iImageWidth+'"'+' height = "'+iImageHeight+'"'+' title  = "'+sTitle+'"'+' src    = "'+imageSrc+'"'+' onmouseover = "RTEButton_GetById(\''+this.id+'\').mouseOver()"'+' onmouseout  = "RTEButton_GetById(\''+this.id+'\').mouseOut()"'+' onclick     = "RTEButton_GetById(\''+this.id+'\').executeAction()"'+'border = 0 hspace      = "'+config.hspace+'"'+'>';}
this.select=function(){if(!IsInstantiated())return;if(disabled)return;document.getElementById(this.domImgId).style.borderColor=config.border_color_selected;}
this.deselect=function(){if(!IsInstantiated())return;if(disabled)return;document.getElementById(this.domImgId).style.borderColor=config.border_color_normal;}
this.mouseOver=function(){if(!IsInstantiated())return;if(disabled)return;ChangeOpacity(config.opacity_mouse_over)}
this.mouseOut=function(){if(!IsInstantiated())return;if(disabled)return;ChangeOpacity(config.opacity_normal)}
this.disable=function(){if(!IsInstantiated())return;disabled=true;ChangeOpacity(config.opacity_disabled)}
this.enable=function(){if(!IsInstantiated())return;disabled=false;ChangeOpacity(config.opacity_normal)}
this.isEnabled=function(){return(!disabled);}
this.hide=function(){if(!IsInstantiated())return;document.getElementById(this.domImgId).style.display='none';}
this.show=function(){if(!IsInstantiated())return;document.getElementById(this.domImgId).style.display='inline';}
this.executeAction=function(){if(!IsInstantiated())return;if(disabled)return;this.plugin[method]();}
function ChangeOpacity(iOpacity){if(!IsInstantiated())return;if(document.all){document.getElementById(self.domImgId).style.filter='alpha(opacity='+iOpacity+')';}else{document.getElementById(self.domImgId).style.MozOpacity=iOpacity/100;}}
function IsInstantiated(){return(document.getElementById(self.domImgId)!=null);}
var self=this;}
RTEButton.prototype=new RTEToolbarItem;var arrRTEButtons=[];var RTEButtons_counter=0;function RTEButton_Create(oProps){if(isUndefined(oProps)){throw new IllegalArgumentException('No props passed!');}
RTEButtons_counter++;oProps.id='rb_'+RTEButtons_counter;var oRTEButton=new RTEButton(oProps);arrRTEButtons[oProps.id]=oRTEButton;return oRTEButton;}
function RTEButton_GetById(sID){if(isUndefined(sID)){throw new IllegalArgumentException('No ID passed!');}
if(isUndefined(arrRTEButtons[sID])){throw new RuntimeException('Button with such ID ['+sID+'] not found!');}
return arrRTEButtons[sID];}


var RTEButton_Config={opacity_mouse_over:50,opacity_normal:100,opacity_disabled:40,border_color_selected:'#C6C6C6',border_color_normal:'#F7F7F7',border_width:1,hspace:1,image_width:20,image_height:20}


function RTE(id){if(isUndefined(id)){throw new IllegalArgumentException('No id passed!');}
this.id=id;this.selection=null
var oEventManager=new RTEEventManager(this);var iStatusMsgTimerId=null;var oShownPropertyPanel=null;var oHelpers=new RTEHelpers;this.setContent=function(sContent){if(isUndefined(sContent)){throw new IllegalArgumentException('No content passed!');}
this.setInternalContent(sContent);this.eventManager().fireEvent(RTE_CONST.EVENT_NEW_CONTENT_SET);}
this.getInternalContent=function(){return this.rootElement().innerHTML;}
this.setInternalContent=function(sContent){if(isUndefined(sContent)){throw new IllegalArgumentException('No content passed!');}
LogMessage('setInternalContent','.');LogMessage('setInternalContent','Setting Content ['+sContent+']',RTE_CONST.LL_DEBUG);this.rootElement().innerHTML=sContent;}
this.isExportContentRunning=false;this.exportContent=function(){var sIdent='exportContent';LogMessage(sIdent,'.');if(this.isExportContentRunning){LogMessage(sIdent,'Another export still running. Skipping this one.');return{isOK:false,html:''};}
var sInternalContent=this.getInternalContent();LogMessage(sIdent,'Got internal content ['+sInternalContent+']',RTE_CONST.LL_ACTION);this.isExportContentRunning=true;var bEventHandledOK=this.eventManager().fireEvent(RTE_CONST.EVENT_EXPORT_CONTENT);if(!bEventHandledOK){LogMessage(sIdent,'Export Content Event canceled.');this.isExportContentRunning=false;return{isOK:false,html:''};}
var sInternalContent=this.getInternalContent();var oHTMLElement=document.createElement('SPAN');LogMessage(sIdent,'Got internal content after export event ['+sInternalContent+']',RTE_CONST.LL_ACTION);oHTMLElement.innerHTML=sInternalContent;LogMessage(sIdent,'Start cleanup of export content.');for(var i in plugins){plugins[i].cleanupContent(oHTMLElement);}
this.isExportContentRunning=false;LogMessage(sIdent,'Done.');LogMessage(sIdent,'Exported content is ['+oHTMLElement.innerHTML+']',RTE_CONST.LL_ACTION);return{isOK:true,html:oHTMLElement.innerHTML};}
this.finishEdit=function(){this.eventManager().fireEvent(RTE_CONST.EVENT_FINISH_EDIT);}
this.configure=function(oConfig){if(isUndefined(oConfig)){throw new IllegalArgumentException('No Config passed!');}
LogMessage('configure','Configuring['+stringify(oConfig)+']',RTE_CONST.LL_DEBUG);for(var i in oConfig){config[i]=oConfig[i];}}
this.instantiate=function(){var sIdent='instantiate';LogMessage(sIdent,'.');Init();Print();InitToolbarItems();InitEditor();assert('No editor window set!',(!isNull(editor.window)))
this.selection=new RTESelection(editor.window);InitShortcuts();InitStatusMessages();assert('No editor document set!',(!isNull(editor.document)))
this.eventManager().init(editor.document);this.focus();if(!document.all){this.setInternalContent('<p>&nbsp;</p>');this.selectionRange().moveToElementText(this.rootElement());}
this.eventManager().fireEvent(RTE_CONST.EVENT_RTE_INSTANTIATED);LogMessage(sIdent,'Done.');}
this.execCommand=function(sCommand,bDisplayUserInterface,vValue){LogMessage('execCommand','Executing Command['+sCommand+'] with Value['+vValue+']');if(isUndefined(sCommand)||sCommand==''){throw new IllegalArgumentException('No command passed!');}
this.focus();assert('No editor document set!',(!isNull(editor.document)))
try{var bReturnCode=editor.document.execCommand(sCommand,bDisplayUserInterface,vValue);}catch(e){throw new RuntimeException('Error executing command ['+sCommand+'], with value ['+vValue+']. Error thrown:['+e+']!');}
this.eventManager().fireEvent(RTE_CONST.EVENT_SELECTION_CHANGED);return bReturnCode;}
this.focus=function(){assert('No editor window set!',(!isNull(editor.window)));editor.window.focus();}
this.queryCommandValue=function(sCommand){if(isUndefined(sCommand)||sCommand==''){throw new IllegalArgumentException('No command passed!');}
assert('No editor document set!',(!isNull(editor.document)))
var vRes=editor.document.queryCommandValue(sCommand)
LogMessage('queryCommandValue','Quering Command['+sCommand+'], got Result ['+vRes+']',RTE_CONST.LL_DEBUG);return vRes;}
this.queryCommandState=function(sCommand){if(isUndefined(sCommand)||sCommand==''){throw new IllegalArgumentException('No command passed!');}
assert('No editor document set!',(!isNull(editor.document)))
return editor.document.queryCommandState(sCommand);}
this.queryCommandSupported=function(sCommand){if(isUndefined(sCommand)||sCommand==''){throw new IllegalArgumentException('No command passed!');}
assert('No editor document set!',(!isNull(editor.document)))
return editor.document.queryCommandSupported(sCommand);}
this.setContentAreaDimensions=function(sWidth,sHeight){var oContentAreaContainer=document.getElementById(editor.domId);if(sWidth){oContentAreaContainer.width=sWidth;}
if(sHeight){oContentAreaContainer.height=sHeight;}
this.eventManager().fireEvent(RTE_CONST.EVENT_RTE_CONTENT_RESIZED);}
this.getContentAreaDimensions=function(){var oContentAreaContainer=document.getElementById(editor.domId);var sWidth=(oContentAreaContainer.width)?oContentAreaContainer.width:config.editor_width;var sHeight=(oContentAreaContainer.height)?oContentAreaContainer.height:config.editor_height;return{width:sWidth,height:sHeight};}
this.hasPropertyPanelArea=function(){if(!document.getElementById(RTE_CONST.PROP_PANEL_TITLE_AREA_PREFIX+this.id)){return false;}
if(!document.getElementById(RTE_CONST.PROP_PANEL_LAYOUT_AREA_PREFIX+this.id)){return false;}
return true;}
this.canShowPropertyPanel=function(){if(!this.hasPropertyPanelArea()){return false;}
if(this.hasPropertyPanelShown()&&!this.isPPanelAvailForHide){return false;}
return true;}
this.hasPropertyPanelShown=function(){if(oShownPropertyPanel==null){return false;}
return true;}
this.getShownPropertyPanel=function(){return oShownPropertyPanel;}
this.isPropertyPanelShown=function(oPropPanel){return(oShownPropertyPanel!=null&&oShownPropertyPanel==oPropPanel);}
this.showPropertyPanel=function(oPropertyPanel){if(isUndefined(oPropertyPanel)){throw new IllegalArgumentException('No prop panel object passed!');}
if(!this.canShowPropertyPanel()){throw new RuntimeException('Can not show property panel ['+oPropertyPanel.getTitle()+']!');}
LogMessage('showPropertyPanel','Showing property panel ['+oPropertyPanel.getTitle()+']');window.clearTimeout(iTimeoutToShowHidePropPanelId);if(oShownPropertyPanel!=oPropertyPanel){oShownPropertyPanel=oPropertyPanel;document.getElementById(RTE_CONST.PROP_PANEL_TITLE_AREA_PREFIX+this.id).innerHTML=oPropertyPanel.getTitle();document.getElementById(RTE_CONST.PROP_PANEL_LAYOUT_AREA_PREFIX+this.id).innerHTML=oPropertyPanel.composeLayout();}
LogMessage('showPropertyPanel','Done. Showing property panel');oShownPropertyPanel.show();}
var iTimeoutToShowHidePropPanel=1;var iTimeoutToShowHidePropPanelId=null;this.hidePropertyPanel=function(bForcePinned){if(!this.hasPropertyPanelArea()||!oShownPropertyPanel){return true;}
LogMessage('hidePropertyPanel','Hide property panel ['+oShownPropertyPanel.getTitle()+']');oShownPropertyPanel.hide();if(oShownPropertyPanel.isPinned()&&!bForcePinned){return false;}
document.getElementById(RTE_CONST.PROP_PANEL_TITLE_AREA_PREFIX+this.id).innerHTML='';if(document.all){document.getElementById(RTE_CONST.PROP_PANEL_LAYOUT_AREA_PREFIX+this.id).innerHTML='';}else{iTimeoutToShowHidePropPanelId=window.setTimeout("document.getElementById('"+RTE_CONST.PROP_PANEL_LAYOUT_AREA_PREFIX+this.id+"').innerHTML = ''",iTimeoutToShowHidePropPanel);}
oShownPropertyPanel=null;return true;}
this.insertHTML=function(sHTML){if(isUndefined(sHTML)){throw new IllegalArgumentException('No html string passed!');}
var sIdent='insertHTML';LogMessage(sIdent,'.');LogMessage(sIdent,'Inserting HTML ['+sHTML+']',RTE_CONST.LL_DEBUG);this.focus();if(this.selection.isControl()){LogMessage(sIdent,'Control Selection detected.');if(!document.all){var oControlElement=this.currentElement();oControlElement.parentNode.removeChild(oControlElement);}else{this.execCommand(RTE_CONST.COMMAND_DELETE);}}
var oSelectionRange=this.selectionRange();if(oSelectionRange){if(document.all){try{oSelectionRange.domRange.pasteHTML(sHTML);}catch(e){oSelectionRange.domRange.collapse();oSelectionRange.domRange.pasteHTML(sHTML);}}else{var oRng=oSelectionRange.domRange;oRng.deleteContents();oRng.insertNode(oRng.createContextualFragment(sHTML));}}
LogMessage(sIdent,'Done.');}
this.filterHTML=function(sHTML){if(isUndefined(sHTML)){throw new IllegalArgumentException('No html string passed!');}
return sHTML;LogMessage('filterHTML','.');LogMessage('filterHTML','HTML ['+sHTML+']',RTE_CONST.LL_DEBUG);return tidy.filter(sHTML);}
this.processPastedContent=function(oHTMLElement){LogMessage('processPastedContent','.');oHTMLElement.innerHTML=this.filterHTML(oHTMLElement.innerHTML);LogMessage('processPastedContent','Content before processing ['+oHTMLElement.innerHTML+']');for(var i in plugins){plugins[i].processPastedContent(oHTMLElement);}
LogMessage('processPastedContent','Content after processing ['+oHTMLElement.innerHTML+']');return oHTMLElement.innerHTML;}
this.addTagRule=function(sTagName,fRule){if(isUndefined(sTagName)){throw new IllegalArgumentException('No tag name passed!');}
if(isUndefined(fRule)){throw new IllegalArgumentException('No rule function pointer passed!');}
LogMessage('addTagRule','Adding rule for tag ['+sTagName+']',RTE_CONST.LL_DEBUG);tidy.addTagRule(sTagName,fRule);}
this.rootElement=function(){if(isNull(editor.document)){throw new IllegalArgumentException('Editor document not set!');}
return editor.document.body;}
this.eventManager=function(){return oEventManager;}
this.currentElement=function(){return this.selectionRange().currentElement();}
this.getLanguage=function(){return config.language;}
this.setLanguage=function(sLanguage){if(isUndefined(sLanguage)||sLanguage==''){throw new IllegalArgumentException('No language passed!');}
LogMessage('setLanguage','Setting language to ['+sLanguage+']');config.language=sLanguage;}
this.selectionRange=function(){var range=null;try{range=this.selection.createRange();}catch(ex){}
return range;}
this.searchElement=function(sTagName,oFromElement,iMaxIteration){if(isUndefined(sTagName)||sTagName==''){throw new IllegalArgumentException('No tag passed!');}
if(isUndefined(oFromElement)){throw new IllegalArgumentException('No from element passed!');}
var oElement=oFromElement;var oRootElement=this.rootElement();if(!iMaxIteration){iMaxIteration=1000000;}
var iCurrentIteration=0;while(oElement.parentNode&&oElement.tagName!=sTagName&&oElement!=oRootElement&&iCurrentIteration<=iMaxIteration){oElement=oElement.parentNode;iCurrentIteration++;}
if(oElement.tagName==sTagName){return oElement}
return null;}
this.createAndRegisterPlugin=function(sPluginName){LogMessage('createAndRegisterPlugin','Registering plugin ['+sPluginName+']',RTE_CONST.LL_DEBUG);if(isUndefined(sPluginName)||sPluginName==''){throw new IllegalArgumentException('No plugin name passed!');}
var oPlugin=CreatePlugin(sPluginName);RegisterPlugin(oPlugin);return oPlugin;}
this.getPluginById=function(sPluginId){if(isUndefined(sPluginId)||sPluginId==''){throw new IllegalArgumentException('No plugin id passed!');}
if(isUndefined(plugins[sPluginId])){return null;}
return plugins[sPluginId];}
this.addShortcut=function(iKeyCode,iHelpKey,oObject,sMethod,bSkipPreventDefault){if(isUndefined(iKeyCode)){throw new IllegalArgumentException('No key passed!');}
if(isUndefined(oObject)){throw new IllegalArgumentException('No object passed!');}
if(isUndefined(sMethod)){throw new IllegalArgumentException('No method passed!');}
if(isUndefined(bSkipPreventDefault)){bSkipPreventDefault=false;}
var iType=RTE_CONST.PLAIN_SHORTCUT;if(iHelpKey!=null){if(iHelpKey==RTE_CONST.HELP_KEY_CTRL){iType=RTE_CONST.CTRL_KEY_SHORTCUT;}else if(iHelpKey==RTE_CONST.HELP_KEY_ALT){iType=RTE_CONST.ALT_KEY_SHORTCUT;}else if(iHelpKey==RTE_CONST.HELP_KEY_SHIFT){iType=RTE_CONST.SHIFT_KEY_SHORTCUT;}}
LogMessage('addShortcut','Adding shortcut. Type['+iType+'], KeyCode['+iKeyCode+']',RTE_CONST.LL_DEBUG);if(isUndefined(shortcuts[iType])){shortcuts[iType]=[];}
if(isDefined(shortcuts[iType][iKeyCode])){throw new RuntimeException('Shortcut already registered. Key['+iKeyCode+'], Type['+iType+'], Method['+shortcuts[iType][iKeyCode].method+']');}
shortcuts[iType][iKeyCode]={obj:oObject,method:sMethod,skipPreventDefault:bSkipPreventDefault};}
this.addRequiredTag=function(sTagName,arrAttributes){LogMessage('addRequiredTag','Adding required tag. TagName['+sTagName+'], Attributes['+stringify(arrAttributes)+']',RTE_CONST.LL_DEBUG);if(isUndefined(sTagName)){throw new IllegalArgumentException('No tag name passed!');}
tidy.addAllowedTag(sTagName,arrAttributes);}
this.addTagToRemoveRecursive=function(sTagName){LogMessage('addTagToRemoveRecursive','TagName['+sTagName+']',RTE_CONST.LL_DEBUG);if(isUndefined(sTagName)){throw new IllegalArgumentException('No tag name passed!');}
tidy.addTagToRemoveRecursive(sTagName);}
this.addWatchTag=function(sTagName,arrAttributes,oPlugin){LogMessage('addWatchTag','TagName['+sTagName+'], Attributes['+stringify(arrAttributes)+'], Plugin ['+oPlugin.id+']',RTE_CONST.LL_DEBUG);if(isUndefined(sTagName)||isUndefined(arrAttributes)||isUndefined(oPlugin)){throw new IllegalArgumentException('No tag definition object passed!');}
if(isUndefined(watchedTags[sTagName])){watchedTags[sTagName]={plugin:null,attributes:[]};}
if(arrAttributes.length==0){if(!isNull(watchedTags[sTagName].plugin)){throw new RuntimeException('There is already a default plugin for this tag['
+sTagName+']!');}
watchedTags[sTagName].plugin=oPlugin;}else{for(var i=0;i<arrAttributes.length;i++){var sAttrName=arrAttributes[i].name;var sAttrValue=arrAttributes[i].value;if(isUndefined(watchedTags[sTagName].attributes[sAttrName])){watchedTags[sTagName].attributes[sAttrName]=[];}
if(isDefined(watchedTags[sTagName].attributes[sAttrName][sAttrValue])){throw new RuntimeException('There is already registered plugin for this attr value!'+'tagName  ['+sTagName+'],'+'attrName ['+sAttrName+']'+'attrValue['+sAttrValue+']');}else{watchedTags[sTagName].attributes[sAttrName][sAttrValue]={};}
watchedTags[sTagName].attributes[sAttrName][sAttrValue].plugin=oPlugin;}}}
this.helpers=function(){return oHelpers;}
this.addToolbarItem=function(oToolbarItem){if(isUndefined(oToolbarItem)){throw new IllegalArgumentException('No ToolbarItem object passed!');}
toolbar.addItem(oToolbarItem);}
this.getElementById=function(sElementID){if(isUndefined(sElementID)){throw new IllegalArgumentException('No Element ID passed!');}
assert('Editor document not set!',(!isNull(editor.document)));return editor.document.getElementById(sElementID);}
this.editorWindow=function(){return editor.window;}
this.editorContainer=function(){return document.getElementById(editor.domId).parentNode;}
this.bottomRightArea=function(){return document.getElementById(RTE_CONST.BOTTOM_RIGHT_AREA_PREFIX+this.id);}
this.handleEvent=function(e){if(document.all){e=editor.window.event;}
LogMessage('handleEvent','Handle event ['+e.type+']',RTE_CONST.LL_DEBUG);this.eventManager().handleEvent(e);}
this.setToolbarLayout=function(sLayout){if(isUndefined(sLayout)||sLayout==''){throw new IllegalArgumentException('No toolbar layout passed!');}
toolbar.setLayoutTemplate(sLayout);}
this.checkSelection=function(){var oCurrentElement=this.currentElement();LogMessage('checkSelection','.',RTE_CONST.LL_DEBUG);if(lastSelectedElement==oCurrentElement){LogMessage('checkSelection','Return',RTE_CONST.LL_DEBUG);return;}
this.eventManager().fireEvent(RTE_CONST.EVENT_SELECTION_CHANGED);}
this.handleMouseUp=function(oEvent){LogMessage('handleMouseUp','.',RTE_CONST.LL_DEBUG);if(!this.helpers().isIE()&&oEvent.target.tagName=='IMG'){this.selectionRange().moveToElementText(oEvent.target);LogMessage('handleMouseUp','Moved to image.Current Tag is ['+this.currentElement().tagName+']',RTE_CONST.LL_DEBUG);}
LogMessage('handleMouseUp','Current Tag ['+this.currentElement().tagName+']',RTE_CONST.LL_DEBUG);this.checkSelection(oEvent);}
this.handleShortcut=function(oEvent){var iType=RTE_CONST.PLAIN_SHORTCUT;if(oEvent.ctrlKey){iType=RTE_CONST.CTRL_KEY_SHORTCUT;}else if(oEvent.altKey){iType=RTE_CONST.ALT_KEY_SHORTCUT;}else if(oEvent.shiftKey){iType=RTE_CONST.SHIFT_KEY_SHORTCUT;}
bPreventFFDefaultShortcut=false;var iKeyCode=oEvent.keyCode;if(isDefined(shortcuts[iType])&&isDefined(shortcuts[iType][iKeyCode])){LogMessage('handleShortcut','Type ['+iType+'], KeyCode['+iKeyCode+']');var oShortcut=shortcuts[iType][iKeyCode];oShortcut.obj[oShortcut.method](oEvent);if(!shortcuts[iType][iKeyCode].skipPreventDefault){bPreventFFDefaultShortcut=true;this.eventManager().cancelEventBubbling(oEvent);}}}
this.preventDefaultShortcutFF=function(oEvent){if(bPreventFFDefaultShortcut){this.eventManager().cancelEventBubbling(oEvent);}}
this.isPPanelAvailForHide=false;this.handleSelectionChanged=function(){this.isPPanelAvailForHide=(oShownPropertyPanel==null||!oShownPropertyPanel.isPinned());this.setSelectedElement();var bPluginWithPPanelFound=IdentifyPlugin();if(!bPluginWithPPanelFound){this.hidePropertyPanel();}}
this.setSelectedElement=function(){LogMessage('setSelectedElement','Setting to ['+this.currentElement().tagName+']',RTE_CONST.LL_DEBUG)
lastSelectedElement=this.currentElement();}
this.selectedElement=function(){return lastSelectedElement;}
this.baseDir=function(){return config.baseDir;}
this.hideToolbar=function(){toolbar.hide();}
this.showToolbar=function(){toolbar.show();}
this.isToolbarShown=function(){return toolbar.isShown();}
this.hasStatusMessagesArea=function(){if(!document.getElementById(RTE_CONST.MESSAGES_AREA_PREFIX+this.id)){return false;}
return true;}
this.showHint=function(oDomObj,sHint){if(sHint){if(isDefined(config.external_hint_handler)){config.external_hint_handler(sHint,oDomObj)
return;}
var sMessage=sHint;if(isDefined(config.hint_message_layout)){sMessage=config.hint_message_layout.supplant({hint:sHint});}
var iDisplayInterval=config.time_to_display_status_message*3;this.displayStatusMessage(sMessage,RTE_CONST.MESSAGE_TYPE_HINT,false,iDisplayInterval);}}
this.displayStatusMessage=function(sMessage,iMessageType,bPin,iDisplayInterval){if(!this.hasStatusMessagesArea()){return;}
var sMessageIconSrc=oMsgIcons["default"];if(iMessageType){sMessageIconSrc=oMsgIcons[iMessageType];}
assert('No messages area layout found!',isDefined(config.messages_area_layout));var sMessageAreaHTML=config.messages_area_layout.supplant({icon_src:sMessageIconSrc,message:sMessage});document.getElementById(RTE_CONST.MESSAGES_AREA_PREFIX+self.id).innerHTML=sMessageAreaHTML;if(!bPin){var iDisplayTime=(isDefined(iDisplayInterval))?iDisplayInterval:config.time_to_display_status_message;var iOptimalMessageLength=60;if(sMessage.length>iOptimalMessageLength){iDisplayTime*=(sMessage.length/iOptimalMessageLength);}
window.clearTimeout(this.statusMsgTimerId);this.statusMsgTimerId=window.setTimeout('RTE_GetById("'+this.id+'").hideStatusMessage()',iDisplayTime);}}
this.hideStatusMessage=function(){if(!this.hasStatusMessagesArea()){return;}
document.getElementById(RTE_CONST.MESSAGES_AREA_PREFIX+self.id).innerHTML='';window.clearTimeout(this.statusMsgTimerId);}
this.imagesDir=function(){return this.baseDir()+RTE_CONST.IMAGES_REL_DIR;}
this.getImageUrl=function(sImageUrl){if(sImageUrl.indexOf('http://')==0||sImageUrl.indexOf('/')>-1){return sImageUrl;}else{return this.imagesDir()+sImageUrl;}}
this.getLogMessages=function(){return sLog;}
this.logMessage=function(sIdent,sMessage,iLogLevel){if(isUndefined(iLogLevel)){iLogLevel=RTE_CONST.LL_ACTION;}
if(iLogLevel<config.log_level){return;}
var oDate=new Date();sLog='['+oDate.toGMTString()+']'+'::'+'['+sIdent+']'+'::'+sMessage+'\n'+sLog;}
this._checkFFKey=function(oEvent){if(document.all)return;if(oEvent.keyCode!=46&&oEvent.keyCode!=8){return;}
var currentElement=this.currentElement();if(currentElement.tagName=='IMG'){currentElement.parentNode.removeChild(currentElement);this.eventManager().cancelEventBubbling(oEvent);}}
var config={};var requiredTags=[];var watchedTags=[];var shortcuts=[];var editor={domId:RTE_CONST.EDITOR_PREFIX+this.id,document:null,window:null}
var lastSelectedElement=null;var plugins={};var toolbar=new RTEToolbar(RTE_CONST.TOOLBAR_PREFIX+this.id);var tidy=new Tidy();var sLog='';function CreatePlugin(sPluginName){if(isUndefined(sPluginName)||sPluginName==''){throw new IllegalArgumentException('No plugin name passed!');}
try{var fPluginConstructor=eval('RTEPlugin_'+sPluginName);return new fPluginConstructor(self);}catch(e){throw new RuntimeException('RTE Plugin with name ['+sPluginName+'] can not beconstructed!');}}
function RegisterPlugin(oPlugin){if(isUndefined(oPlugin)){throw new IllegalArgumentException('No plugin passed!');}
assert('A plugin with this id ['+oPlugin.id+'] already exists!',isUndefined(plugins[oPlugin.id]));plugins[oPlugin.id]=oPlugin;}
function ReadConfig(){assert('Config was not found',typeof(RTE_Config)!='undefined')
assert('Default width for the editor not found in config',isDefined(RTE_Config.editor_width));assert('Default height for the editor not found in config',isDefined(RTE_Config.editor_height));assert('Default language not found in config',isDefined(RTE_Config.language));assert('Default css not found in config',isDefined(RTE_Config.css));assert('Body css class not found in config',isDefined(RTE_Config.body_css_class));assert('Default basDir not found in config',isDefined(RTE_Config.baseDir));assert('Time to display status message not found in config',isDefined(RTE_Config.time_to_display_status_message));assert('Info icon src not found in config[icon_info_msg]',isDefined(RTE_Config.icon_info_msg));assert('Wait icon src not found in config[icon_wait_msg]',isDefined(RTE_Config.icon_wait_msg));assert('Warning icon src not found in config[icon_warning_msg]',isDefined(RTE_Config.icon_warning_msg));assert('ResizeUp icon src not found in config[icon_resize_up]',isDefined(RTE_Config.icon_resize_up));assert('ResizeDown icon src not found in config[icon_resize_down]',isDefined(RTE_Config.icon_resize_down));assert('No core tempates holder id found in config[templates_holder_id]',isDefined(RTE_Config.templates_holder_id));assert('No default log level found in config [log_level]',isDefined(RTE_Config.log_level));config=RTE_Config;}
function Print(){LogMessage('Print','.');if(isDefined(config.holder_element_id)){var oHolderElement=document.getElementById(config.holder_element_id);if(!oHolderElement){throw new RuntimeException('Can not get RTE holder Element with ID ['+config.holder_element_id+']!');}
oHolderElement.innerHTML=ComposeLayout();}else{document.write(ComposeLayout());}}
function ComposeLayout(){LogMessage('ComposeLayout','.');assert('Space image src [SPACE_IMG_SRC global js var ] not set!',typeof(SPACE_IMG_SRC)!='undefined');var sToolbarHTML=toolbar.composeLayout();if(isUndefined(config.layout)){var oTemplatesHolder=document.getElementById(config.templates_holder_id).contentWindow.document;var oDefaultLayoutHolder=oTemplatesHolder.getElementById('rte_default_layout');assert('No default layout found. Element with id [rte_default_layout] not found.',oDefaultLayoutHolder!=null);config.layout=oDefaultLayoutHolder.value;}
var sEditorHTML='<iframe'+' id     = "'+editor.domId+'"'+' width  = "'+config.editor_width+'"'+' height = "'+config.editor_height+'"'+' frameborder = "0" '+
(document.all?'scrolling="yes"':'style="overflow-y:scroll"')+'></iframe>';var sMessagesHTML='<span id = "'+
RTE_CONST.MESSAGES_AREA_PREFIX+self.id+'"'+'></span>';var sPropPanelLayoutHTML='<span id = "'+
RTE_CONST.PROP_PANEL_LAYOUT_AREA_PREFIX+self.id+'"'+'></span>';var sPropPanelTitleHTML='<span id = "'+
RTE_CONST.PROP_PANEL_TITLE_AREA_PREFIX+self.id+'"'+'></span>';var sBottomRightHTML='<div id="'+
RTE_CONST.BOTTOM_RIGHT_AREA_PREFIX+self.id+'"'+'></div>';var sHTML=config.layout.supplant({__toolbar_area__:sToolbarHTML,__editor_area__:sEditorHTML,__messages_area__:sMessagesHTML,__property_panel_layout_area__:sPropPanelLayoutHTML,__property_panel_title_area__:sPropPanelTitleHTML,__bottom_right_area__:sBottomRightHTML,__rte_id__:self.id,__img_space__:SPACE_IMG_SRC,__icon_resize_up__:self.getImageUrl(config.icon_resize_up),__icon_resize_down__:self.getImageUrl(config.icon_resize_down)});return sHTML;}
function Init(){LogMessage('Init','.');InitLog();for(var i in plugins){plugins[i].init();}
LogMessage('Init','Done.');}
function InitToolbarItems(){LogMessage('InitToolbarItems','.');for(var i in plugins){plugins[i].initToolbarItems();}
LogMessage('InitToolbarItems','Done.');}
function InitLog(){sLog='Log start ['+(new Date()).toGMTString()+']\n'+'Browser ['+navigator.userAgent+']\n'+'================================================\n\n';}
function LogMessage(sIdent,sMessage,iLogLevel){self.logMessage('RTE'+'::'+sIdent,sMessage,iLogLevel);}
function RegisterCoreEvents(){LogMessage('RegisterCoreEvents','.');if(!document.all){self.eventManager().addEventHandler('keydown',self,'_checkFFKey');}
self.eventManager().addEventHandler('keyup',self,'checkSelection');self.eventManager().addEventHandler('mouseup',self,'handleMouseUp');self.eventManager().addEventHandler(RTE_CONST.EVENT_SELECTION_CHANGED,self,'handleSelectionChanged',{skip_pass_event_object:true});}
function InitEditor(){LogMessage('InitEditor','.');assert('Editor not instantiated',(document.getElementById(editor.domId)!=null))
editor.window=document.getElementById(editor.domId).contentWindow;editor.document=editor.window.document;EnableEditMode();var sCSS='';for(var i=0;i<config.css.length;i++){sCSS+='@import url("'+config.css[i]+'");';}
var sCSSEditorStyle='';if(typeof config.css_editor_style!='undefined')
sCSSEditorStyle=config.css_editor_style;var sEncodingLine="";var sEncoding=document.charset||document.defaultCharset;if(!sEncoding){$$('meta').each(function(e){if(e.get('content')){var pair=e.get('content').split('=');if(pair.length==2&&pair[0].indexOf("charset")!=-1){sEncoding=pair[1];}}});}
if(sEncoding){sEncodingLine='<meta http-equiv="Content-Type" content="text/html; charset='+sEncoding+'">';}
editor.document.open();editor.document.write(sEncodingLine+'<style id = "'+RTE_CONST.EDITOR_STYLE_HOLDER+'">'+
((document.all)?sCSS:'')+
((document.all)?sCSSEditorStyle:'')+'</style><body class = '+config.body_css_class+' ></body>');editor.document.close();if(document.all){editor.document.execCommand(RTE_CONST.COMMAND_LIVE_RESIZE,false,true);}else{EnableEditMode();editor.document.getElementById(RTE_CONST.EDITOR_STYLE_HOLDER).appendChild(editor.document.createTextNode(sCSS+sCSSEditorStyle));editor.document.execCommand(RTE_CONST.COMMAND_USE_CSS,false,true);}
LogMessage('InitEditor','Done.');}
var bPreventFFDefaultShortcut=false;function InitShortcuts(){LogMessage('InitShortcuts','.');self.eventManager().addEventHandler('keydown',self,'handleShortcut');if(!document.all){self.eventManager().addEventHandler('keypress',self,'preventDefaultShortcutFF');}}
var oMsgIcons={};function InitStatusMessages(){if(!self.hasStatusMessagesArea()){return;}
oMsgIcons[RTE_CONST.MESSAGE_TYPE_INFO]=self.getImageUrl(config.icon_info_msg);oMsgIcons[RTE_CONST.MESSAGE_TYPE_WAIT]=self.getImageUrl(config.icon_wait_msg);oMsgIcons[RTE_CONST.MESSAGE_TYPE_WARNING]=self.getImageUrl(config.icon_warning_msg);oMsgIcons[RTE_CONST.MESSAGE_TYPE_HINT]=self.getImageUrl(config.icon_hint_msg);oMsgIcons["default"]=oMsgIcons[RTE_CONST.INFO_MESSAGE_TYPE];if(isUndefined(config.messages_area_layout)){var oTemplatesHolder=document.getElementById(config.templates_holder_id).contentWindow.document;var oDefaultLayoutHolder=oTemplatesHolder.getElementById('rte_default_messages_area_layout');if(oDefaultLayoutHolder!=null){config.messages_area_layout=oDefaultLayoutHolder.value.supplant({__rte_id__:self.id,__img_space__:SPACE_IMG_SRC});}}
if(isUndefined(config.hint_message_layout)){var oTemplatesHolder=document.getElementById(config.templates_holder_id).contentWindow.document;var oDefaultLayoutHolder=oTemplatesHolder.getElementById('rte_default_hint_area_layout');if(oDefaultLayoutHolder!=null){config.hint_message_layout=oDefaultLayoutHolder.value.supplant({__rte_id__:self.id,__img_space__:SPACE_IMG_SRC});}}}
function EnableEditMode(){LogMessage('EnableEditMode','.');assert('Editor document not set!',(!isNull(editor.document)));editor.document.designMode='on';editor.document=editor.window.document;}
function IdentifyPlugin(){var oElement=self.currentElement();var oRootElement=self.rootElement();var bPluginWithPPanelFound=false;while(oElement&&oElement!=oRootElement){var oCurrentElement=oElement;oElement=oElement.parentNode;if(isDefined(watchedTags[oCurrentElement.tagName])){var bPluginIdentified=false;var oPlugin=null;for(var sAttrName in watchedTags[oCurrentElement.tagName].attributes){if(!isNull(oCurrentElement.getAttribute(sAttrName))){var sAttributeValue=oCurrentElement.getAttribute(sAttrName);for(var sAttrValue in watchedTags[oCurrentElement.tagName].attributes[sAttrName]){if(sAttributeValue==sAttrValue){oPlugin=watchedTags[oCurrentElement.tagName].attributes[sAttrName][sAttrValue].plugin;break;}}}
if(oPlugin!=null){break;}}
if(oPlugin==null&&!isNull(watchedTags[oCurrentElement.tagName].plugin)){oPlugin=watchedTags[oCurrentElement.tagName].plugin;}
if(oPlugin!=null){if(document.all){oPlugin.select();if(oPlugin.hasPropertyPanel()){self.isPPanelAvailForHide=false;}}else{LogMessage('identifyPlugin','Calling plugin ['+oPlugin.id+'], Curr Elem tag['+oCurrentElement.tagName+'], Real elem tag ['+self.currentElement().tagName+']',RTE_CONST.LL_DEBUG);window.setTimeout('RTE_GetById("'+self.id+'").getPluginById("'+oPlugin.id+'").select()',iTimeoutToShowHidePropPanel);if(oPlugin.hasPropertyPanel()){window.setTimeout('RTE_GetById("'+self.id+'").isPPanelAvailForHide = false;',iTimeoutToShowHidePropPanel);}}
if(oPlugin.hasPropertyPanel()){bPluginWithPPanelFound=true;}}}}
return bPluginWithPPanelFound;}
var self=this;ReadConfig();RegisterCoreEvents();}
var arrRTEs=[];var RTE_Counter=0;function RTE_Create(){RTE_Counter++;var id='rte_'+RTE_Counter;var oRTE=new RTE(id);arrRTEs[id]=oRTE;return oRTE;}
function RTE_GetById(sID){if(isUndefined(sID)){throw new IllegalArgumentException('No ID passed!');}
if(isUndefined(arrRTEs[sID])){throw new RuntimeException('RTE with such ID ['+sID+'] not found!');}
return arrRTEs[sID];}

