ASPxHtmlEditorDialogSR = { };
ASPxHtmlEditorDialog = _aspxCreateClass(ASPxDialog, {      
 Execute: function(ownerControl) {
  this.htmlEditor = ownerControl;
  this.CreateSelectionInfo();
  if (__aspxIE)
   this.SaveScrollPosition();
  if(__aspxOpera)
   this.SaveDocumentScrollPosition();
  this.htmlEditor.RemoveFocus();
  if(__aspxOpera)
   this.RestoreDocumentScrollPosition();
  this.SetDialogNameInput();
  this.isOnCallbackError = false;
  ASPxDialog.prototype.Execute.call(this, ownerControl);  
 },
 OnCallbackError: function(result, data) {
  this.isOnCallbackError = true;
  this.ClearDialogNameInput();
  this.HideDialog();
  ASPxDialog.prototype.OnCallbackError.call(this, result); 
 }, 
 OnClose: function() {
  ASPxDialog.prototype.OnClose.call(this);
  this.ClearDialogNameInput();
  if (!this.isOnCallbackError)
   this.SaveEditorsState();
 },
 OnCloseButtonClick: function() { 
    this.htmlEditor.RestoreLastSelection(this.selectionInfo.selection);
  this.htmlEditor.UpdateToolbar();
 },
   OnComplete: function(result, params) {
    this.GetDialogPopup().Hide();
    this.htmlEditor.RestoreLastSelection(this.selectionInfo.selection);
  this.DoCustomAction(result, params);
  this.ClearEditorValue();
  if (!result)
   this.htmlEditor.UpdateToolbar();
   },
 OnInitComplete: function() {
  ASPxDialog.prototype.OnInitComplete.call(this);
  if (__aspxIE)
   this.RestoreScrollPositionAndSelection();
  this.htmlEditor.ClearFocusInput(); 
  this.RestoreEditorsState();
 },
 SaveEditorsState: function() {
 },
 RestoreEditorsState: function() {
 },
 ClearEditorValue: function() {
 },
 CreateSelectionInfo: function() {
  var curSelection = this.htmlEditor.CreateRestoreSelectionForDialog();
  this.selectionInfo = {
   selection: curSelection,
   isControl: curSelection.IsControl(),
   text: curSelection.GetText(),
   htmlText: curSelection.GetHtmlText(),
   selectedElement: curSelection.GetParentElement(),
   endSelectedElement: curSelection.GetEndContainer()
  };
 },
 ClearDialogNameInput: function() {
  this.htmlEditor.GetCurrentDialogHiddenInput().value = "";
 },
 SendCallback: function(callbackArgs) {
  this.ownerControl.callbackOwner = this;
  this.ownerControl.CreateCallback(callbackArgs, "", false);
  this.ShowLoadingPanelOverDialogPopup();
 },
 SetDialogNameInput: function() {
  this.htmlEditor.GetCurrentDialogHiddenInput().value = this.name;
 },
 RestoreScrollPositionAndSelection: function() {
    this.htmlEditor.RestoreLastSelection(this.selectionInfo.selection);
    if (this.savedScrollLeft > 0)
     this.htmlEditor.GetDesignViewIFrameDocument().body.scrollLeft = this.savedScrollLeft;
    if (this.savedScrollTop > 0)     
     this.htmlEditor.GetDesignViewIFrameDocument().body.scrollTop = this.savedScrollTop;
 },
 RestoreDocumentScrollPosition: function() {
    document.body.scrollLeft = this.savedDocumentScrollLeft;
    document.body.scrollTop = this.savedDocumentScrollTop;
 },
 SaveScrollPosition: function() {
  this.savedScrollLeft = this.htmlEditor.GetDesignViewIFrameDocument().body.scrollLeft;
  this.savedScrollTop = this.htmlEditor.GetDesignViewIFrameDocument().body.scrollTop;
 },
 SaveDocumentScrollPosition: function() {
  this.savedDocumentScrollLeft = _aspxGetDocumentScrollLeft();
  this.savedDocumentScrollTop = _aspxGetDocumentScrollTop();
 }, 
 IsEnabledEditor: function(editor) {
  return _aspxGetElementVisibility(editor.GetMainElement());
 }
});
__aspxDefaultLinkHref = "http://"; 
__aspxMailtToPrefix = "mailto:";
__aspxMailtToSubjectPrefix = "?subject=";
__aspxOpenInNewWindowTarget = "_blank";
InsertLinkDialog = _aspxCreateClass(ASPxHtmlEditorDialog , {
 DoCustomAction: function(result, params) {
  if (result) {   
   var target = "";
   var title = "";
   var text = "";
   var url = "";
   title = params.title;
   text = params.text;
   switch (_dxeRblLinkType.GetValue()) {
    case "Email":
      url = __aspxMailtToPrefix + params.url;
      if (_aspxIsExists(params.subject))
       url += __aspxMailtToSubjectPrefix + params.subject;
      break;
    case "URL":
      url = params.url;
      target = params.isCheckedOpenInNewWindow ? __aspxOpenInNewWindowTarget : "";
      break;
   }
   if (params.isTextOnlySelected && (text == ""))
    text = params.url;
   this.htmlEditor.InsertLink(url, text, target, title);
  }
 },
 GetDialogCaptionText: function() {
  return InsertLinkDialog.prototype.IsLink(this.selectionInfo.selectedElement) 
   ? ASPxHtmlEditorDialogSR.ChangeLink
   : ASPxHtmlEditorDialogSR.InsertLink;
 },
 GetInitInfoObject: function() {
  var linkInfoObject = {
   href: "",
   text: "",
   title: "",
   target: ""
  };
  var link = _aspxGetParentByTagName(this.selectionInfo.selectedElement, "A");
  var isTextEditorVisible =true;
  if (_aspxIsExists(link)) {
   if (!InsertLinkDialog.prototype.ContaintTextNodeOnly(link) || this.selectionInfo.isControl)
    isTextEditorVisible = false;     
  }
  else {
   var img = _aspxGetParentByTagName(this.selectionInfo.selectedElement, "img");
   if (_aspxIsExists(img))
    isTextEditorVisible = false;
   else {
    var text = this.selectionInfo.text;
    if (text) text = this.selectionInfo.htmlText;
    isTextEditorVisible = !ASPxClientSelection.IsHtml(_aspxTrim(text));
   }
  }
  linkInfoObject.isTextEditorVisible = isTextEditorVisible;
  linkInfoObject.text = this.selectionInfo.text;
  if (_aspxIsExists(link)) {
   linkInfoObject.href = _aspxGetAttribute(link, "href");
   linkInfoObject.text = link.innerHTML;
   linkInfoObject.title = _aspxGetAttribute(link, "title");
   linkInfoObject.target = _aspxGetAttribute(link, "target");
  }
  if (linkInfoObject.href == "")
   linkInfoObject.href = __aspxDefaultLinkHref;
  return linkInfoObject;
 },
 InitializeDialogFields: function(linkInfo) {
  var isLinkSelected = InsertLinkDialog.prototype.IsLink(this.selectionInfo.selectedElement);
  this.GetChangeButton().SetVisible(isLinkSelected);
  this.GetInsertButton().SetVisible(!isLinkSelected);
  if ((linkInfo.href != "") && (linkInfo.href.indexOf(__aspxMailtToPrefix) > -1)) {   
   var mailtoIndex = linkInfo.href.indexOf(__aspxMailtToPrefix);
   var subjectIndex = linkInfo.href.indexOf(__aspxMailtToSubjectPrefix);
   var index = subjectIndex > -1 ? subjectIndex : linkInfo.href.length;
   this.GetEmailToTextBox().SetValue(linkInfo.href.substring(mailtoIndex + __aspxMailtToPrefix.length, index));
   var subject = "";
   if (subjectIndex > -1)
    subject = linkInfo.href.substring(subjectIndex + __aspxMailtToSubjectPrefix.length);
   this.GetSubjectTextBox().SetValue(subject);
   this.GetLinkTypeRadioButtonList().SetValue("Email");
  }
  else {
   this.GetLinkTypeRadioButtonList().SetValue("URL");
   this.GetUrlTextBox().SetValue(linkInfo.href);
   this.GetOpenInNewWindowCheckBox().SetValue(linkInfo.target == __aspxOpenInNewWindowTarget);
  }
  this.GetToolTipTextBox().SetValue(linkInfo.title);
  if (linkInfo.isTextEditorVisible)
   this.GetTextTextBox().SetValue(linkInfo.text);
  else {
   this.GetTextTextBox().SetEnabled(false);
   this.GetLabelText().SetEnabled(false);
  }
  this.GetLinkTypeRadioButtonList().RaiseSelectedIndexChanged();  
 },
 ClearEditorValue: function() {
  this.GetEmailToTextBox().SetValue(null);
  this.GetSubjectTextBox().SetValue(null);
  this.GetUrlTextBox().SetValue(null);
  this.GetToolTipTextBox().SetValue(null);
  this.GetTextTextBox().SetValue(null);
 },
 SetFocusInField: function() {
  if (this.GetLinkTypeRadioButtonList().GetValue() == "URL")
   _aspxSetFocusToTextEditWithDelay(_dxeTxbURL.name);
  else
   _aspxSetFocusToTextEditWithDelay(_dxeTxbEmailTo.name);
 },
 GetChangeButton: function() {
  return _aspxIsExists(window._dxeBtnChange) ? _dxeBtnChange : null;
 },
 GetEmailToTextBox: function() {
  return _dxeTxbEmailTo;
 },
 GetInsertButton: function() {
  return _dxeBtnOk;
 },   
 GetLabelText: function() {
  return _dxeLblText;
 },
 GetLinkTypeRadioButtonList: function() {
  return _dxeRblLinkType;
 },
 GetOpenInNewWindowCheckBox: function() {
  return _dxeCkbOpenInNewWindow;
 },
 GetTextTextBox: function() {
  return _dxeTxbText;
 },
 GetToolTipTextBox: function() {
  return _dxeTxbToolTip;
 },
 GetSubjectTextBox: function() {
  return _dxeTxbSubject;
 }, 
 GetUrlTextBox: function() {
  return _dxeTxbURL;
 }
});
InsertLinkDialog.prototype.ContaintTextNodeOnly = function(linkElement) {
 if (linkElement.childNodes.length > 0) {
  for (var i = 0; i < linkElement.childNodes.length; i++) {
   if (linkElement.childNodes[i].nodeType != 3)
    return false;
  }
 }
 return true;
};
InsertLinkDialog.prototype.IsLinkSelected = function(htmlEditor) {
 var curSelection = ASPxClientHtmlEditorSelection.Create(htmlEditor);
 return InsertLinkDialog.prototype.IsLink(curSelection.GetParentElement());
};
InsertLinkDialog.prototype.IsLink = function(element) {
 return _aspxIsExists(_aspxGetParentByTagName(element, "A"));
};
var __aspxPreviewTextElementID = "_dxInsertImagePreviewText";
var __aspxPreviewImageElementID = "_dxInsertImagePreviewImage";
InsertImageDialog = _aspxCreateClass(ASPxHtmlEditorDialog , {
 DoCustomAction: function(result, params) {
  if (result) {
   if (_aspxIsExists(this.selectedImageElement))
    this.htmlEditor.ChangeImage(this.selectedImageElement, params.src, 
           params.width, params.height,
           params.align, params.alt, params.useFloat);
   else
    this.htmlEditor.InsertImage(params.src, params.width, params.height, 
           params.align, params.alt, 
           params.useFloat);
  }
 },
 GetDialogCaptionText: function() {
  var img = InsertImageDialog.prototype.GetImage(this.selectionInfo.selectedElement);
  return _aspxIsExists(img) 
   ? ASPxHtmlEditorDialogSR.ChangeImage
   : ASPxHtmlEditorDialogSR.InsertImage;
 },
 GetInitInfoObject: function() {
  var imageInfoObject = {
   isCustomSize: false,
   src: "",
   width: "",
   height: "",
   align: "",
   alt: "",
   useFloat: false
  };
  this.constrainProportions = true;
  this.selectedImageElement = InsertImageDialog.prototype.GetImage(this.selectionInfo.selectedElement);
  if (_aspxIsExists(this.selectedImageElement))
   imageInfoObject = ChangeImageCommand.GetImageProperties(this.selectedImageElement);
  return imageInfoObject;
 },
 InitializeDialogFields: function(imageInfo) {
  var isImage = _aspxIsExists(this.selectedImageElement);
  this.GetChangeButton().SetVisible(isImage);
  this.GetInsertButton().SetVisible(!isImage);
  if (imageInfo.src) {
   this.fieldInitializing = true;
   _dxeTbxInsertImageUrl.SetValue(imageInfo.src);
   this.OnImageSrcChanged(imageInfo.src);
  }
  this.UpdateSizeFields(imageInfo.width ? imageInfo.width : 0, imageInfo.height ? imageInfo.height : 0);
  if (imageInfo.isCustomSize) {
   _dxeCmbSize.SetValue("custom");
   _dxeCmbSize.OnSelectChanged();
  }
  if (imageInfo.align)
   _dxeCmbImagePosition.SetValue(imageInfo.align);
  if (imageInfo.alt)
   _dxeTxbDescription.SetValue(imageInfo.alt);
  if (imageInfo.useFloat)
   _dxeCkbWrapTextArroundImage.SetChecked(imageInfo.useFloat);
 },
 ClearEditorValue: function() {
  _dxeTbxInsertImageUrl.SetValue(null);
  _dxeTxbDescription.SetValue(null);
  _dxeCkbWrapTextArroundImage.SetChecked(false);
  this.GetThumbnailFileNameTextBox().SetValue(null);
 },
 SaveEditorsState: function() {
  var checkBox = this.GetCheckBoxMoreImageOptions();
  if (_aspxIsExists(checkBox)) {
   this.htmlEditor.moreImageOptions = checkBox.GetChecked();
  }
 },
 RestoreEditorsState: function() {  
  if (_aspxIsExists(this.htmlEditor.moreImageOptions)) {
   this.GetCheckBoxMoreImageOptions().SetChecked(this.htmlEditor.moreImageOptions);
   this.GetCheckBoxMoreImageOptions().RaiseCheckedChanged();
  }
 },
 GetPreviewTextElement: function() {
  return _aspxGetElementById(this.htmlEditor.name + __aspxPreviewTextElementID);
 },
 GetPreviewImageElement: function() {
  return _aspxGetElementById(this.htmlEditor.name + __aspxPreviewImageElementID);
 },
 GetPreviewAreaCell: function() {
  return _aspxGetParentByTagName(this.GetPreviewImageElement(), "td");
 },
 GetChangeButton: function() {
  return _dxeBtnChangeImage;
 },
 GetCheckBoxMoreImageOptions: function() {
  return _aspxIsExists(window._dxeCkbMoreImageOptions) ? _dxeCkbMoreImageOptions : null;
 },
 GetClientUploadDirectory: function() {
  return this.htmlEditor.uploadImageFileDirectoryPath;
 },
 GetThumbnailCheckBox: function() {
  return _dxeCkbCreateThumbnail;
 }, 
 GetErrorLabel: function() {
  return _dxeLblError;
 },
 GetInsertButton: function() {
  return _dxeBtnInsertImage;
 },   
 GetImageUploader: function() {
  return _dxeUplImage;
 },
 GetThumbnailFileNameTextBox: function() {
  return _dxeThumbnailFileName;
 },
 GetInsertImageUrlTextBox: function() {
  return _dxeTbxInsertImageUrl;
 },
 IsFieldInitializing: function() {
  if (_aspxIsExists(this.fieldInitializing))
   return this.fieldInitializing;
  return false;
 },
 SetFocusInField: function() {
  _aspxSetFocusToTextEditWithDelay(_dxeTbxInsertImageUrl.name);
 }, 
 OnCallback: function(result) {
  if (result.indexOf(__aspxHESaveImageToServerCallbackPrefix) == 0) {
   this.OnImageSavedToServer(result.substring(__aspxHESaveImageToServerCallbackPrefix.length + 1, result.length));
   this.ownerControl.callbackOwner = null;
  }
  else
   ASPxDialog.prototype.OnCallback.call(this, result);
 },
 OnComplete: function(result, params) {
  this.insertImageParams = params;
  if (result) {
   if(_dxeRblImageFromThisComputer.GetChecked())
    return this.GetImageUploader().UploadFile();
   else if (this.IsCreateThumbnail())
    return this.SaveThumbnailImageToServerViaCallback(this.GetInsertImageUrlTextBox().GetText(),
                  this.GetThumbnailFileNameTextBox().GetText(),
                  params.width, params.height);
   else if (this.IsSaveImageToServer() && _dxeRblImageFromTheWeb.GetChecked())
    return this.SaveImageToServerViaCallback(this.GetInsertImageUrlTextBox().GetText());
  }
  ASPxHtmlEditorDialog.prototype.OnComplete.call(this, result, params);
 },
 OnImageSavedToServer: function(result) {
  if (result.indexOf(__aspxSaveImageToServerErrorCallbackPrefix) > -1)
   this.ShowErrorMessage(result.substring(__aspxSaveImageToServerErrorCallbackPrefix.length + 1, result.length));
  else {
   this.insertImageParams.src = result.substr(__aspxSaveImageToServerNewUrlCallbackPrefix.length + 1, result.length);
   ASPxHtmlEditorDialog.prototype.OnComplete.call(this, 1, this.insertImageParams);
  }
 },
 OnConstrainProportionsSwitchClick: function(evt, invisibleSwitchImgID) {
  var visibleSwitchImg = _aspxGetEventSource(evt);
  var invisibleSwitchImg = _aspxGetElementById(invisibleSwitchImgID);
  _aspxSetElementDisplay(visibleSwitchImg, false);
  _aspxSetElementDisplay(invisibleSwitchImg, true); 
  this.constrainProportions = !this.constrainProportions;
  if (this.constrainProportions)
   this.UpdateSizeFields(this.initialWidth, this.initialHeight);
 },
 OnImageUploadStart: function() {
  this.ShowLoadingPanelOverDialogPopup();
 },
 OnImageUploadComplete: function(args) {
  this.HideLoadingPanelOverDialogPopup();
  if (args.isValid) {
   var fileName = this.GetClientUploadDirectory() + args.callbackData;
   this.insertImageParams.src = fileName;
   if (this.IsCreateThumbnail())
    this.SaveThumbnailImageToServerViaCallback(ASPxClientPath.GetBaseUrlPath() + fileName,
                 this.GetThumbnailFileNameTextBox().GetText(),
                 this.insertImageParams.width, this.insertImageParams.height);
   else
    ASPxHtmlEditorDialog.prototype.OnComplete.call(this, 1, this.insertImageParams);
  }
 },
 OnImageUploadTextChanged: function() {
  this.UpdateThumbnailFileName(this.GetImageUploader().GetText());
 },
 OnImageSrcChanged: function(src) {
  this.CheckImageExisting(src);
  this.UpdateThumbnailFileName(src);
 },
 OnImageFromTypeChanged: function() {
  var src = _dxeRblImageFromTheWeb.GetChecked() ? this.GetInsertImageUrlTextBox().GetText() :
              this.GetImageUploader().GetText();
  this.UpdateThumbnailFileName(src);
 },
 OnLoadTestExistingImage: function() {  
  this.GetPreviewImageElement().src = this.testImage.src;  
  var previewAreaTD = this.GetPreviewAreaCell();
  var maxWidth = previewAreaTD.clientWidth;
  var maxHeight = __aspxWebKitFamily ? previewAreaTD.offsetHeight : previewAreaTD.clientHeight;
  this.SetPreviewImageSize(this.testImage.width, this.testImage.height, maxWidth, maxHeight);  
  _aspxSetElementDisplay(this.GetPreviewTextElement(), false);
  _aspxSetElementDisplay(this.GetPreviewImageElement(), true);
  previewAreaTD.style.borderStyle = "none";
  this.UpdateSizeFieldsAfterLoad(this.testImage.width, this.testImage.height);
 },
 OnErrorTestExistingImage: function() {
  _aspxSetElementDisplay(this.GetPreviewTextElement(), true);
  _aspxSetElementDisplay(this.GetPreviewImageElement(), false);
  var previewAreaTD = this.GetPreviewAreaCell();
  previewAreaTD.style.borderStyle = "";
  this.UpdateSizeFieldsAfterLoad();
 },
 OnSizeSpinNumberChanged: function(sizeType) {
  if (this.constrainProportions)
   this.UpdateSizeSpinEditsWithConstrainProportions(sizeType);
 },
 OnSizeSpinKeyUp: function(sizeType, htmlEvent) {
  if (this.constrainProportions) {
   var keyCode = _aspxGetKeyCode(htmlEvent);  
   if (keyCode != ASPxKey.Tab && keyCode != ASPxKey.Shift)
    this.UpdateSizeSpinEditsWithConstrainProportions(sizeType);
  }
 },
 CheckImageExisting: function(checkingSrc) {
  if (document.images) {
   if (this.testImage == null) {
    this.testImage = new Image();
    _aspxAttachEventToElement(this.testImage, "load",
           new Function("aspxTestExistingImageOnLoad" + "('" + this.htmlEditor.name + "');"));
    _aspxAttachEventToElement(this.testImage, "error",
           new Function("aspxTestExistingImageOnError" + "('" + this.htmlEditor.name + "');"));
   }
   this.testImage.src = checkingSrc;
  }
 },
 IsCreateThumbnail: function() {  
  return this.GetThumbnailCheckBox().GetChecked() && _dxeCmbSize.GetValue() == "custom";
 },
 IsSaveImageToServer: function() {
  return _dxeCkbSaveToServer.GetValue() || !this.htmlEditor.allowInsertDirectImageUrls;
 },
 SetPreviewImageSize: function(sourceWidth, sourceHeight, maxWidth, maxHeight) {
  var newWidth = sourceWidth;
  var newHeight = sourceHeight;
  if ((sourceWidth > maxWidth) || 
   (sourceHeight > maxHeight)) {
   var cw = sourceWidth/maxWidth;   
   var ch = sourceHeight/maxHeight;
   if (cw > ch) {
    var cw = sourceWidth/maxWidth;   
    newWidth = Math.floor(sourceWidth/cw);
    newHeight = Math.floor(sourceHeight/cw);
   }
   else {
    newWidth = Math.floor(sourceWidth/ch);
    newHeight = Math.floor(sourceHeight/ch);
   }
  }  
  var previewImage = this.GetPreviewImageElement();
  previewImage.style.width = newWidth + "px";
  previewImage.style.height = newHeight + "px";
 },
 SaveImageToServerViaCallback: function(src) {
  this.SendCallback(_aspxFormatCallbackArg(__aspxHESaveImageToServerCallbackPrefix, src));
 },
 SaveThumbnailImageToServerViaCallback: function(src, newImageFileName, thumbnailWidth, thumbnailHeight) {
  this.SendCallback(_aspxFormatCallbackArgs([
   [ __aspxHESaveImageToServerCallbackPrefix, src ],
   [ __aspxHEThumbnailImageWidthCallbackPrefix, thumbnailWidth ],
   [ __aspxHEThumbnailImageHeightCallbackPrefix, thumbnailHeight ],
   [ __aspxHEThumbnailImageFileNameCallbackPrefix, newImageFileName ]
  ]));
 },
 HideErrorMessage: function() {
  this.GetErrorLabel().SetVisible(false);
 },
 ShowErrorMessage: function(message) {
  var textBox = this.GetInsertImageUrlTextBox();
  textBox.isValid = false;
  textBox.errorText = message;
  textBox.UpdateErrorFrameAndFocus(false, true);
 },
 UpdateConstrainProportionsCoef: function(width, height) {
  if ((width == height) || (height == 0))
   this.constrainProportionsCoef_WH = 1;
  else
   this.constrainProportionsCoef_WH = width/height;
  this.initialWidth = width;
  this.initialHeight = height;
 },
 UpdateSizeSpinEditsWithConstrainProportions: function(sizeType) {
  var newWidth = _dxeSpnWidth.GetNumber();
  var newHeight = _dxeSpnHeight.GetNumber();
  switch(sizeType) {
   case "width":
    _dxeSpnWidth.SaveSelectionStartAndEndPosition();
    newHeight = _dxeSpnWidth.GetParsedNumber()/this.constrainProportionsCoef_WH;
    _dxeSpnHeight.SetValue(Math.floor(newHeight));
    _dxeSpnWidth.RestoreSelectionStartAndEndPosition();
    break;
   case "height":
    _dxeSpnHeight.SaveSelectionStartAndEndPosition();
    newWidth = _dxeSpnHeight.GetParsedNumber()*this.constrainProportionsCoef_WH;
    _dxeSpnWidth.SetValue(Math.floor(newWidth));
    _dxeSpnHeight.RestoreSelectionStartAndEndPosition();
    break;
  }
 }, 
 UpdateSizeFields: function(imageWidth, imageHeight) {
  _dxeSpnWidth.SetValue(imageWidth >= 0 ? imageWidth : 0);
  _dxeSpnHeight.SetValue(imageHeight >=0 ? imageHeight: 0);
  this.UpdateConstrainProportionsCoef(_dxeSpnWidth.GetNumber(), _dxeSpnHeight.GetNumber());
 },
 UpdateSizeFieldsAfterLoad: function(imageWidth, imageHeight) {
  if (!this.IsFieldInitializing())
   this.UpdateSizeFields(imageWidth, imageHeight);
  else
   this.fieldInitializing = false;
 },
 UpdateThumbnailFileName: function(src) {
  var fileName = ASPxClientPath.GetFileNameWithoutExtension(src);
  if (fileName)
   fileName += "Thumbnail.jpg";
  this.GetThumbnailFileNameTextBox().SetText(fileName);
 }
});
InsertImageDialog.prototype.GetSelectedImage = function(htmlEditor) {
 var curSelection = ASPxClientHtmlEditorSelection.Create(htmlEditor);
 var containerElement = curSelection.GetParentElement();  
 return InsertImageDialog.prototype.GetImage(containerElement);
}
InsertImageDialog.prototype.GetImage = function(element) {
 return _aspxGetParentByTagName(element, "img");
}
function aspxInsertImageSrcValueChanged(src) {
 var htmlEdit = aspxGetControlCollection().Get(__aspxCurrentControlNameInDialog);
 var curDialog = htmlEdit != null ? ASPxDialog.GetLastDialog(htmlEdit) : null;
 if (curDialog != null) curDialog.OnImageSrcChanged(src);
}
function aspxConstrainProportionsSwitchClick(evt, invisibleSwitchImgID) {
 var htmlEdit = aspxGetControlCollection().Get(__aspxCurrentControlNameInDialog);
 var curDialog = htmlEdit != null ? ASPxDialog.GetLastDialog(htmlEdit) : null;
 if (curDialog != null) 
  return curDialog.OnConstrainProportionsSwitchClick(evt, invisibleSwitchImgID);
}
function aspxImageUploadStart() {
 var htmlEdit = aspxGetControlCollection().Get(__aspxCurrentControlNameInDialog);
 var curDialog = htmlEdit != null ? ASPxDialog.GetLastDialog(htmlEdit) : null;
 if (curDialog != null)
  return curDialog.OnImageUploadStart();
}
function aspxImageUploadComplete(args) {
 var htmlEdit = aspxGetControlCollection().Get(__aspxCurrentControlNameInDialog);
 var curDialog = htmlEdit != null ? ASPxDialog.GetLastDialog(htmlEdit) : null;
 if (curDialog != null)
  return curDialog.OnImageUploadComplete(args);
}
function aspxImageUploadTextChanged() {
 var htmlEdit = aspxGetControlCollection().Get(__aspxCurrentControlNameInDialog);
 var curDialog = htmlEdit != null ? ASPxDialog.GetLastDialog(htmlEdit) : null;
 if (curDialog != null)
  return curDialog.OnImageUploadTextChanged();
}
function aspxOnImageFromTypeChanged() {
 var htmlEdit = aspxGetControlCollection().Get(__aspxCurrentControlNameInDialog);
 var curDialog = htmlEdit != null ? ASPxDialog.GetLastDialog(htmlEdit) : null;
 if (curDialog != null)
  return curDialog.OnImageFromTypeChanged();
}
function aspxTestExistingImageOnLoad(name) {
 var htmlEdit = aspxGetControlCollection().Get(name);
 var curDialog = htmlEdit != null ? ASPxDialog.GetLastDialog(htmlEdit) : null;
 if (curDialog != null) curDialog.OnLoadTestExistingImage();
}
function aspxTestExistingImageOnError(name) {
 var htmlEdit = aspxGetControlCollection().Get(name);
 var curDialog = htmlEdit != null ? ASPxDialog.GetLastDialog(htmlEdit) : null;
 if (curDialog != null) curDialog.OnErrorTestExistingImage();
}
function aspxSizeSpinNumberChanged(sizeType) {
 var htmlEdit = aspxGetControlCollection().Get(__aspxCurrentControlNameInDialog);
 var curDialog = htmlEdit != null ? ASPxDialog.GetLastDialog(htmlEdit) : null;
 if (curDialog != null) 
  return curDialog.OnSizeSpinNumberChanged(sizeType);
}
function aspxSizeSpinKeyUp(sizeType, htmlEvent) {
 var htmlEdit = aspxGetControlCollection().Get(__aspxCurrentControlNameInDialog);
 var curDialog = htmlEdit != null ? ASPxDialog.GetLastDialog(htmlEdit) : null;
 if (curDialog != null)
  return curDialog.OnSizeSpinKeyUp(sizeType, htmlEvent);
}
InsertTableDialog = _aspxCreateClass(ASPxHtmlEditorDialog, {
 DoCustomAction: function(result, cmdValue) {
  if (result)
   this.htmlEditor.ExecuteCommand(ASPxClientCommandConsts.INSERTTABLE_COMMAND, cmdValue, true);
 },
 GetDialogCaptionText: function() {
  return ASPxHtmlEditorDialogSR.InsertTable;
 },
 InitializeDialogFields: function(tableInfo) {
  this.SetDisplayColumnsAndRowsEditors(true);
 },
 SetFocusInField: function() {
  _aspxSetFocusToTextEditWithDelay(_dxeSpnTableColumns.name);
 },
 SetDisplayColumnsAndRowsEditors: function(display) {
  _dxeCkbColumnsEqualWidth.SetClientVisible(display);
  var row = this.GetRowsAndColumnsRowElement();
  _aspxSetElementDisplay(row, display);
  _aspxSetElementDisplay(_aspxHETableHelper.GetNextRow(row), display);
 },
 GetRowsAndColumnsRowElement: function() {
  return _aspxGetParentByTagName(_dxeSpnTableColumns.GetMainElement(), "TR");
 }
});
TablePropertiesDialog = _aspxCreateClass(InsertTableDialog, {
 DoCustomAction: function(result, cmdValue) {
  if (result) {
   cmdValue = { tableElement: this.selectedTable, tableProperties: cmdValue.tableProperties };
   this.htmlEditor.ExecuteCommand(ASPxClientCommandConsts.CHANGETABLE_COMMAND, cmdValue, true);
  }
 },
 GetInitInfoObject: function() {
  var tableInfoObject = {
   borderWidth: null,
   borderColor: "",
   backgroundColor: "",
   width: "",
   height: "",
   cellPadding: "",
   cellSpacing: "",
   align: null,
   accessibility: null
  };
  this.selectedTable = _aspxHETableHelper.GetTable(this.selectionInfo.selectedElement);
  if (_aspxIsExists(this.selectedTable))
   tableInfoObject = _aspxHETableHelper.GetTableProperties(this.selectedTable);
  return tableInfoObject;
 },
 InitializeDialogFields: function(tableInfo) {
  this.SetDisplayColumnsAndRowsEditors(false);
  TablePropertiesDialog.SetSizeEditors(_dxeCmbTableWidth, _dxeCmbTableWidthType, _dxeTxbTableWidth, tableInfo.width);
  TablePropertiesDialog.SetSizeEditors(_dxeCmbTableHeight, _dxeCmbTableHeightType, _dxeTxbTableHeight, tableInfo.height);
  _dxeSpnCellPadding.SetText(tableInfo.cellPadding);
  _dxeSpnCellSpacing.SetText(tableInfo.cellSpacing);
  _dxeCmbTableAlign.SetValue(tableInfo.align);
  if (tableInfo.align)
   _dxeCmbTableAlign.SetValue(tableInfo.align.toLowerCase());
  _dxeSpnTableBorderSize.SetText(tableInfo.borderWidth);
  _dxeTxbTableBorderColor.SetText(tableInfo.borderColor);
  _dxeTxbTableBackgroundColor.SetText(tableInfo.backgroundColor);
  var accessibility = tableInfo.accessibility;
  _dxeTxbTableSummary.SetText(accessibility.summary);
  _dxeTxbTableCaption.SetText(accessibility.caption);
  _dxeCmbTableHeaders.SetValue(accessibility.headers);
 },
 GetDialogCaptionText: function() {
  return ASPxHtmlEditorDialogSR.ChangeTable;
 },
 SetFocusInField: function() {
  _aspxSetFocusToTextEditWithDelay(_dxeCmbTableWidth.name);
 }
});
TablePropertiesDialog.SetSizeEditors = function(cmb, cmbType, spinEdit, value) {
 cmb.SetValue(value);
 var selectedItem = cmb.GetSelectedItem();
 if (selectedItem == null) {
  cmb.SetValue("custom");
  var res = _aspxHETableHelper.ParseSizeString(value);
  if (res.valueType) {
   value = res.value;
   cmbType.SetValue(res.valueType);
   cmbType.RaiseValueChangedEvent();
  }
  spinEdit.SetText(value);
 }
 cmb.RaiseValueChangedEvent();
}
TableCellPropertiesDialog = _aspxCreateClass(ASPxHtmlEditorDialog, {
 DoCustomAction: function(result, cmdValue) {
  if (result) {
   cmdValue = { cellElement: this.selectedCell, properties: cmdValue };
   this.htmlEditor.ExecuteCommand(ASPxClientCommandConsts.CHANGETABLECELL_COMMAND, cmdValue, true);
  }
 },
 GetDialogCaptionText: function() {
  return ASPxHtmlEditorDialogSR.ChangeTableCell;
 },
 InitializeDialogFields: function(cellInfo) {
  this.SetSizeEditorsDisplay(false);
  _dxeCkbApplyForAllElements.SetVisible(true);
  _dxeTxbTableColumnBackgroundColor.SetText(cellInfo.backgroundColor);
  _dxeCmbTableColumnAlign.SetValue(cellInfo.align);
  if (cellInfo.align)
   _dxeCmbTableColumnAlign.SetValue(cellInfo.align.toLowerCase());
  _dxeCmbTableColumnVAlign.SetValue(cellInfo.vAlign);
  if (cellInfo.vAlign)
   _dxeCmbTableColumnVAlign.SetValue(cellInfo.vAlign.toLowerCase());
 },
 GetInitInfoObject: function() {
  var cellInfoObject = {
   backgroundColor: "",
   align: null,
   vAlign: null
  };
  this.selectedCell = _aspxHETableHelper.GetTableCellBySelection(this.selectionInfo.selectedElement,
                  this.selectionInfo.endSelectedElement);
  if (_aspxIsExists(this.selectedCell))
   cellInfoObject = _aspxHETableHelper.GetCellProperties(this.selectedCell);
  return cellInfoObject;
 },
 SetFocusInField: function() {
  _aspxSetFocusToTextEditWithDelay(_dxeCmbTableColumnAlign.name);
 },
 SetSizeEditorsDisplay: function(display) {
  _dxeRPTableColumnSize.SetVisible(display);
  var firstMainElem = _dxeRPTableColumnSize.GetMainElement();
  var secondMainElem = _dxeRPTableLayout.GetMainElement();
  if (_aspxIsExists(firstMainElem) && _aspxIsExists(secondMainElem)) {
   var curElem = firstMainElem.nextSibling;
   while (curElem != secondMainElem) {
    if (curElem.nodeType == 1)
     _aspxSetElementDisplay(curElem, display);
    curElem = curElem.nextSibling;
   }
  }
 },
 OnComplete: function(result, params) {
  ASPxHtmlEditorDialog.prototype.OnComplete.call(this, result, params);
  _dxeCkbApplyForAllElements.SetChecked(false);
 },
 SetWidthEditorsDisplay: function(display) {
  _aspxSetElementDisplay(_aspxGetElementById(this.GetWidthEditorsTRID()), display);
 },
 SetHeightEditorsDisplay: function(display) {
  _aspxSetElementDisplay(_aspxGetElementById(this.GetHeightEditorsTRID()), display);
 },
 GetWidthEditorsTRID: function() {
  return this.htmlEditor.name + "_dxeColumnWidthCell";
 },
 GetHeightEditorsTRID: function() {
  return this.htmlEditor.name + "_dxeColumnHeightCell";
 }
});
TableColumnPropertiesDialog = _aspxCreateClass(TableCellPropertiesDialog, {
 DoCustomAction: function(result, cmdValue) {
  if (result) {
   cmdValue = { cell: this.selectedCell, properties: cmdValue };
   this.htmlEditor.ExecuteCommand(ASPxClientCommandConsts.CHANGETABLECOLUMN_COMMAND, cmdValue, true);
  }
 },
 SetFocusInField: function() {
  _aspxSetFocusToTextEditWithDelay(_dxeCmbTableColumnAlign.name);
 },
 GetInitInfoObject: function() {
  var columnInfoObject = {
   backgroundColor: "",
   width: "",
   align: null,
   vAlign: null
  };
  var table = _aspxHETableHelper.GetTable(this.selectionInfo.selectedElement);
  this.selectedCell = _aspxHETableHelper.GetTableCellBySelection(this.selectionInfo.selectedElement,
                 this.selectionInfo.endSelectedElement);
  if (_aspxIsExists(table))
   columnInfoObject = _aspxHETableHelper.GetColumnProperties(this.selectedCell);
  return columnInfoObject;
 },
 InitializeDialogFields: function(columnInfo) {
  _dxeTxbTableColumnBackgroundColor.SetText(columnInfo.backgroundColor);
  _dxeCkbApplyForAllElements.SetVisible(false);
  this.SetWidthEditorsDisplay(true);
  this.SetHeightEditorsDisplay(false);
  this.SetSizeEditorsDisplay(true);
  _dxeCmbTableColumnAlign.SetValue(columnInfo.align);
  if (columnInfo.align)
   _dxeCmbTableColumnAlign.SetValue(columnInfo.align.toLowerCase());
  _dxeCmbTableColumnVAlign.SetValue(columnInfo.vAlign);
  if (columnInfo.vAlign)
   _dxeCmbTableColumnVAlign.SetValue(columnInfo.vAlign.toLowerCase());
  TablePropertiesDialog.SetSizeEditors(_dxeCmbTableColumnWidth, _dxeCmbTableColumnWidthType,
           _dxeTxbTableColumnWidth, columnInfo.width);
 },
 GetDialogCaptionText: function() {
  return ASPxHtmlEditorDialogSR.ChangeTableColumn;
 }
});
TableRowPropertiesDialog = _aspxCreateClass(TableCellPropertiesDialog, {
 DoCustomAction: function(result, cmdValue) {
  if (result) {
   cmdValue = { cell: this.selectedCell, properties: cmdValue };
   this.htmlEditor.ExecuteCommand(ASPxClientCommandConsts.CHANGETABLEROW_COMMAND, cmdValue, true);
  }
 },
 SetFocusInField: function() {
  _aspxSetFocusToTextEditWithDelay(_dxeCmbTableColumnAlign.name);
 },
 GetInitInfoObject: function() {
  var rowInfoObject = {
   backgroundColor: "",
   height: "",
   align: null,
   vAlign: null
  };
  var table = _aspxHETableHelper.GetTable(this.selectionInfo.selectedElement);
  this.selectedCell = _aspxHETableHelper.GetTableCellBySelection(this.selectionInfo.selectedElement,
                 this.selectionInfo.endSelectedElement);
  if (_aspxIsExists(this.selectedCell))
   rowInfoObject = _aspxHETableHelper.GetRowProperties(this.selectedCell);
  return rowInfoObject;
 },
 GetDialogCaptionText: function() {
  return ASPxHtmlEditorDialogSR.ChangeTableRow;
 },
 InitializeDialogFields: function(rowInfo) {
  _dxeTxbTableColumnBackgroundColor.SetText(rowInfo.backgroundColor);
  _dxeCkbApplyForAllElements.SetVisible(false);
  this.SetWidthEditorsDisplay(false);
  this.SetHeightEditorsDisplay(true);
  this.SetSizeEditorsDisplay(true);
  _dxeCmbTableColumnAlign.SetValue(rowInfo.align);
  if (rowInfo.align)
   _dxeCmbTableColumnAlign.SetValue(rowInfo.align.toLowerCase());
  _dxeCmbTableColumnVAlign.SetValue(rowInfo.vAlign);
  if (rowInfo.vAlign)
   _dxeCmbTableColumnVAlign.SetValue(rowInfo.vAlign.toLowerCase());
  TablePropertiesDialog.SetSizeEditors(_dxeCmbTableRowHeight, _dxeCmbTableRowHeightType, _dxeTxbTableRowHeight, rowInfo.height);
 }
});
PasteFromWordDialog = _aspxCreateClass(ASPxHtmlEditorDialog, {
 DoCustomAction: function(result, cmdValue) {
  _aspxRemoveElement(this.GetPasteContainerIFrame());
  if (result && cmdValue.html)
   this.htmlEditor.ExecuteCommand(ASPxClientCommandConsts.PASTEFROMWORD_COMMAND, cmdValue, true);
 },
 InitializeDialogFields: function() {
  var contentDocument = this.GetPasteContainerIFrame().contentWindow.document;
  contentDocument.open();
  contentDocument.write("<head><style></style></head><body></body>");
  contentDocument.close();
  if (__aspxIE)
   contentDocument.body.contentEditable = true;
  else {
   contentDocument.body.spellcheck = false;
   contentDocument["designMode"] = "on";
  }
  _aspxAttachEventToElement(contentDocument, "keypress", aspxHEPasteFromWordContainerKeyPress);
  contentDocument.body.style.margin = "0px";
  contentDocument.body.style.padding = "2px";
  contentDocument.body.style.border = "Solid 0px";
 },
 SetFocusInField: function() {
  _aspxSetTimeout("_aspxIFrameWindow('" + this.GetPasteContainerIFrameName() + "').focus();", 500);
 },
 GetDialogCaptionText: function() {
  return ASPxHtmlEditorDialogSR.PasteFromWord;
 },
 OnPasteContainerKeyPress: function(evt) {
  if (evt.keyCode == ASPxKey.Esc)
   this.HideDialog();
 },
 GetPasteContainerIFrame: function() {
  return _aspxGetElementById(this.GetPasteContainerIFrameName());
 },
 GetPasteContainerIFrameName: function() {
  return this.htmlEditor.name + "_dxePasteFromWordContainer";
 }
});
function aspxHEPasteFromWordContainerKeyPress(evt) {
 var htmlEdit = aspxGetControlCollection().Get(__aspxCurrentControlNameInDialog);
 var curDialog = htmlEdit != null ? ASPxDialog.GetLastDialog(htmlEdit) : null;
 if (curDialog != null)
  return curDialog.OnPasteContainerKeyPress(evt);
}
var ASPxHtmlEditorDialogList = {};
ASPxHtmlEditorDialogList[ASPxClientCommandConsts.INSERTLINK_DIALOG_COMMAND] = new InsertLinkDialog(ASPxClientCommandConsts.INSERTLINK_DIALOG_COMMAND);
ASPxHtmlEditorDialogList[ASPxClientCommandConsts.CHANGELINK_DIALOG_COMMAND] = new InsertLinkDialog(ASPxClientCommandConsts.INSERTLINK_DIALOG_COMMAND);
ASPxHtmlEditorDialogList[ASPxClientCommandConsts.INSERTIMAGE_DIALOG_COMMAND] = new InsertImageDialog(ASPxClientCommandConsts.INSERTIMAGE_DIALOG_COMMAND);
ASPxHtmlEditorDialogList[ASPxClientCommandConsts.CHANGEIMAGE_DIALOG_COMMAND] = new InsertImageDialog(ASPxClientCommandConsts.INSERTIMAGE_DIALOG_COMMAND);
ASPxHtmlEditorDialogList[ASPxClientCommandConsts.INSERTTABLE_DIALOG_COMMAND] = new InsertTableDialog(ASPxClientCommandConsts.INSERTTABLE_DIALOG_COMMAND);
ASPxHtmlEditorDialogList[ASPxClientCommandConsts.TABLEPROPERTIES_DIALOG_COMMAND] = new TablePropertiesDialog(ASPxClientCommandConsts.INSERTTABLE_DIALOG_COMMAND);
ASPxHtmlEditorDialogList[ASPxClientCommandConsts.TABLECELLPROPERTIES_DIALOG_COMMAND] = new TableCellPropertiesDialog(ASPxClientCommandConsts.TABLECOLUMNPROPERTIES_DIALOG_COMMAND);
ASPxHtmlEditorDialogList[ASPxClientCommandConsts.TABLECOLUMNPROPERTIES_DIALOG_COMMAND] = new TableColumnPropertiesDialog(ASPxClientCommandConsts.TABLECOLUMNPROPERTIES_DIALOG_COMMAND);
ASPxHtmlEditorDialogList[ASPxClientCommandConsts.TABLEROWPROPERTIES_DIALOG_COMMAND] = new TableRowPropertiesDialog(ASPxClientCommandConsts.TABLECOLUMNPROPERTIES_DIALOG_COMMAND);
ASPxHtmlEditorDialogList[ASPxClientCommandConsts.PASTEFROMWORDDIALOG_COMMAND] = new PasteFromWordDialog(ASPxClientCommandConsts.PASTEFROMWORDDIALOG_COMMAND);
