﻿ThePortRegisterNS("ThePort.CKEditor");   

   ThePort.CKEditor = function() 
    {
    this.m_oActiveEditor = null;
    this.m_sImageFolder = null;
    this.m_iImageMaxWidth='400';
    this.m_iImageMaxHeight='800';
    
    this.ImageBtnLabel;
    this.VideoBtnLabel;
    this.ReadMoreBtnLabel;
    this.SmileyBtnLabel;
    }
    ThePort.CKEditor.prototype.InitializeLocalization = function(img,video,smiley,readmore,local)
    {
      this.ImageBtnLabel = img;
      this.VideoBtnLabel = video;
      this.ReadMoreBtnLabel = readmore;
      this.SmileyBtnLabel = smiley;
      this.LocalizationBtnLabel = local;   
    }
    
    ThePort.CKEditor.prototype.InitializeLocalization = function(img,video,smiley,readmore)
    {
      this.ImageBtnLabel = img;
      this.VideoBtnLabel = video;
      this.ReadMoreBtnLabel = readmore;
      this.SmileyBtnLabel = smiley; 
    }
    
  ThePort.CKEditor.prototype.InitializeImageSettings = function(imgFolder, w, h)
    { 
        this.m_sImageFolder = imgFolder;
        if(arguments[1]){this.m_iImageMaxWidth=w;}
        if(arguments[2]){this.m_iImageMaxHeight=h;}
    }

  ThePort.CKEditor.prototype.InitializeEditor = function(editor)
    { 
        this.m_oActiveEditor = editor;
    }
    				
  ThePort.CKEditor.prototype.AddImage = function()
    { 
        if (!this.m_sImageFolder || this.m_sImageFolder.length ==0){alert(ThePort.CKEditor.Constants.CONST_NO_IMAGE_FOLDER_ERROR);return false;}
        ThePort.UI.PopWindow.OpenModalWindow(ThePort.CKEditor.Constants.CONST_PAGE_UPLOAD_IMAGE+"?img=("+this.m_iImageMaxWidth+","+this.m_iImageMaxHeight+")&cb=CKEDITOR.instances."+this.m_oActiveEditor.name+".ThePortCKEditor.InsertImageElement&f="+this.m_sImageFolder+"&rnd="+ Math.random(), 350,250); 
    }
    
  ThePort.CKEditor.prototype.AddLocalization = function()
    { 
        ThePort.UI.PopWindow.OpenModalWindow(ThePort.CKEditor.Constants.CONST_PAGE_LOCALIZATION_CODE+"?cb=CKEDITOR.instances."+this.m_oActiveEditor.name+".ThePortCKEditor.InsertHtml", 400, 200);  
    }
    
   ThePort.CKEditor.prototype.AddSmiley = function()
    { 
        ThePort.UI.PopWindow.OpenModalWindow(ThePort.CKEditor.Constants.CONST_PAGE_SMILEY+"?cb=CKEDITOR.instances."+this.m_oActiveEditor.name+".ThePortCKEditor.InsertImageElement", 275, 200);  
    }   
        
  ThePort.CKEditor.prototype.AddYouTube = function()
    { 
        ThePort.UI.PopWindow.OpenModalWindow(ThePort.CKEditor.Constants.CONST_PAGE_YOUTUBE+"?cb=CKEDITOR.instances."+this.m_oActiveEditor.name+".ThePortCKEditor.InsertHtml", 400, 200);
    }
    
//  ThePort.CKEditor.prototype.InsertImageUrl = function(url,filename,message)
//    {
//    alert(url + '--7');
//	    ThePort.UI.PopWindow.CloseWindow();
//	   // this.m_oActiveEditor.insertHtml("<img  src='"+url+"' border='0' class='tp_wysiwyg_gen_img'/>");
//	  //  var ele = CKEditor.dom.element.createFromHtml("<img  src='"+url+"' border='0' class='tp_wysiwyg_gen_img' ></img>");
//	    var oImage = new CKEDITOR.dom.element('img') ;
//	    oImage.setAttributes({
//            'class' : 'tp_wysiwyg_gen_img',
//            'src' : url,
//            'border' : '0' });
//        this.m_oActiveEditor.insertElement(oImage);
//	    if (arguments[2]){alert(message);}
//	} 
	
	ThePort.CKEditor.prototype.InsertImageElement = function(url,className,message)
    {
	    ThePort.UI.PopWindow.CloseWindow();
	    var oImage = new CKEDITOR.dom.element('img') ;
	    oImage.setAttributes({
            'class' : className,
            'src' : url,
            'border' : '0' });
        this.m_oActiveEditor.insertElement(oImage);
	    if (arguments[2]){alert(message);}
	} 
                  
   ThePort.CKEditor.prototype.InsertHtml = function(s,message)
	{ 
	    ThePort.UI.PopWindow.CloseWindow();
	    this.m_oActiveEditor.insertHtml(s);
	    if (arguments[2]){alert(message);}
	}
	
	ThePort.CKEditor.prototype.GetEditorData = function(oEditor)
	{ 
	    return oEditor.getData();
	} 
	
if (ThePortRegisterNS("ThePort.CKEditor.Constants")) {
    ThePort.CKEditor.Constants = 
        {
            CONST_PAGE_YOUTUBE                  : "/editor/app/wysiwyg/addyoutube.aspx",
            CONST_PAGE_LOCALIZATION_CODE        : "/editor/app/wysiwyg/addlocalization.aspx",
            CONST_PAGE_SMILEY                   : "/editor/app/wysiwyg/addsmiley.aspx",
            CONST_PAGE_UPLOAD_IMAGE             : "/editor/app/photos/uploadimage.aspx",
            CONST_POPUP_WINDOW_NAME             : "tp_Win",
            CONST_POPUP_WINDOW_IFRAME           : "iframe",
            CONST_POPUP_WINDOW_IFRAME_200_400   : "width=400px,height=200px,center=1,resize=1,scrolling=1",
            CONST_NO_IMAGE_FOLDER_ERROR         : "The image folder must be specified before this option can be utilized."
        }
    }    
