﻿//-------------------------------------------------------------------------------
//
// URIA WebEditor API Version 4.0.2010.11.11.01
// uriaeditor40.js
// Copyright U&wise Co., Ltd.
//
//------------------------------------------------------------------------------

var _uriaEditorCnt       = 0;
var _uriaEditor          = new Array();
var _uriaCurrentIndex    = 0;

var _uriaClientbinPath   = "clientbin";
var _urianewDocumentURL  = "";
var _uriaConfigURL       = "";
var _uriaSplashID = "UriaSplash";
var _uriaHolderID = "UriaPlaceHolder";

var _uriaZindex = 300;

function uriaSetClientbinPath(path) { _uriaClientbinPath = path; }
function uriaSetNewDocumentURL(url) { _urianewDocumentURL = url; }
function uriaSetNewConfigURL(url) { _uriaConfigURL = url; }
function uriaSetSplashID(id) { _uriaSplashID = id; }
function uriaPlaceHoderID(id) { _uriaHolderID = id; }

function URIAEditor40(uriaHolderID) {
    if (uriaHolderID == undefined) uriaHolderID = _uriaHolderID;

    _uriaHolderID = uriaHolderID;

    _uriaEditorCnt++;
    _uriaZindex--;
    
    var newEditorID = "URIAEditor" + _uriaEditorCnt;
    this.ID = newEditorID;
    this.URIAHolderID = _uriaHolderID;

    var uriaedtor;
    uriaedtor = '<div id="silverlightControlHost" style="height:0;">';
    uriaedtor += '<object id="' + this.ID + '" data="data:application/x-silverlight-2," type="application/x-silverlight-2" style="position:absolute; width:0px; height:0px; z-index:' + _uriaZindex + '" >';
    uriaedtor += '<param name="source" value="' + _uriaClientbinPath + '/uriasoft.editor40.xap"/>';
    uriaedtor += '<param name="onError" value="onSilverlightError" />';
    uriaedtor += '<param name="minRuntimeVersion" value="4.0.50401.0" />';
    uriaedtor += '<param name="autoUpgrade" value="true" />';
    uriaedtor += '<param name="InitParams" value="uriaEditorHolder=' + uriaHolderID + ',uriaEditorConfig=' + _uriaConfigURL + ',UriaSplash=' + _uriaSplashID + ', newDocumentUrl=' + _urianewDocumentURL + '" />';
    uriaedtor += '<param name="windowless" value="true" />';
    uriaedtor += '<param name="background" value="Transparent" />';
    uriaedtor += '<param name="pluginbackground" value="Transparent" />';
    uriaedtor += '<param name="allowHtmlPopupWindow" value="true" />';
    uriaedtor += '<param name="enablehtmlaccess" value="true" />';

    uriaedtor += '<param name="autoUpgrade" value="true" />';

	
    uriaedtor += '<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50401.0" style="text-decoration:none">';
    uriaedtor += '<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Microsoft Silverlight 얻기" style="border-style:none"/>';
    uriaedtor += '</a>';
    uriaedtor += '</object>';
    uriaedtor += '<iframe style="visibility:hidden;height:0;width:0;border:0px"></iframe>';
    uriaedtor += '</div>';

    try {
    	if (!Silverlight.isInstalled("4.0.50401.0")) {
	        document.getElementById(uriaHolderID).innerHTML = uriaedtor;
            document.getElementById(uriaHolderID).style.paddingTop = "150px";
            document.getElementById(uriaHolderID).style.paddingLeft = "150px";
        }
        else {
            document.getElementById(uriaHolderID).innerHTML = uriaedtor;
        }    
        this.Editor = null;
        _uriaEditor[_uriaEditorCnt - 1] = this;
        
         
    } catch (e) { };
}

function URIAEvent_EditorLoadedAPI(idEditor) {
    for (var idx = 0; idx < _uriaEditorCnt; idx++) {
        if (_uriaEditor[idx].ID == idEditor) {
            _uriaEditor[idx].Editor = document.getElementById(idEditor).Content.URIAEditor;
           return;
        }
    }

}

function URIAEvent_FullScreen(idEditor, state) {


    if (state == 'True') {

        for (var idx = 0; idx < _uriaEditorCnt; idx++) {
            if (_uriaEditor[idx].ID != idEditor) {
                _uriaEditor[idx].setEditorHidden();
            }
        }
        
    }
    else {
        for (var idx = 0; idx < _uriaEditorCnt; idx++) {
            if (_uriaEditor[idx].ID != idEditor) {
                _uriaEditor[idx].setEditorShow(1);
            }
        }
        
    }

    for (var idx = 0; idx < _uriaEditorCnt; idx++) {
        if (_uriaEditor[idx].ID == idEditor) {
            _uriaEditor[idx].setCaretPosition(1);
        }
    }


}


function URIAEvent_InsertPhotoviewToEditor(idEditor)
{
    for (var idx = 0; idx < _uriaEditorCnt; idx++) {
        if (_uriaEditor[idx].ID == idEditor) {
            _uriaCurrentIndex = idx;
            break;
        }
    }

    if (!window.showModalDialog) {

        var retObject = new Object();

        retObject.FullSource = "";
        retObject.PhotoFullURL = "";
        retObject.PhotoURL = "";
        retObject.Width = "";
        retObject.Height = "";
        retObject.FirstPhotoFullURL = "";
        retObject.FirstPhotoURL = "";
        retObject.ThumbFullURL = "";
        retObject.ThumbURL = "";

        var sFeatures = "";
        if (document.all)   // IE 전용
            sFeatures = "dialogWidth:550px;dialogHeight:620px;center:yes;resizable:no;status:no;";
        else
            sFeatures = "dialogWidth:550px;dialogHeight:600px;center:yes;resizable:no;status:no;";

        var retValue = window.showModalDialog("uriaphotownd.html", retObject, sFeatures);

        _uriaEditor[_uriaCurrentIndex].setPhotoviewSource(retValue);

    }
    else {
    
        var wndWidth = 550;
        var wndHeight = 600;
        var scrWidth = screen.availWidth;
        var scrHeight = screen.availHeight;
        var pLeft = (scrWidth - wndWidth) / 2;
        var pTop = (scrHeight - wndHeight) / 2;
        var sFeatures = "left=" + pLeft + ",top=" + pTop + ",width=550,height=600,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no ,modal=yes";
        window.open('uriaphotownd.html', 'PhotoWnd', sFeatures);
    }

}

// API for URIA Photoview 3.0
URIAEditor40.prototype.setPhotoviewSource = function(retValue) {
    this.Editor.setPhotoviewToBody(retValue.FullSource);
}


// Get Last Error Message
URIAEditor40.prototype.getLastMessage = function() {
    var sMessage = "";
    sMessage = this.Editor.getEditorLastMessage();
    return sMessage;    
}

// HtmlDocument getHTMLDom()
URIAEditor40.prototype.getEditorDom = function()  {
    var objRetValue = null;
    objRetValue = this.Editor.getHTMLDom();
    return objRetValue;
}

URIAEditor40.prototype.getHtmlCharSet = function() {
    
    
    return this.Editor.HtmlCharSet;
}

URIAEditor40.prototype.setHtmlCharSet = function(charSet) {

    this.Editor.HtmlCharSet = charSet;
    
}


URIAEditor40.prototype.isEmpty = function() {

    return this.Editor.isEmpty();

}

// string getHTMLExValue()
URIAEditor40.prototype.getHTMLExValue = function() {
    var sRetValue = "";
    sRetValue = this.Editor.getHTMLExValue();
    return sRetValue;
}

// string getHTMLValue()
URIAEditor40.prototype.getHTMLValue =  function() {
    var sRetValue = "";
    sRetValue = this.Editor.getHTMLValue();
    return sRetValue;
}

URIAEditor40.prototype.getHTMLValue2 = function() {
    var sRetValue = "";
    sRetValue = this.Editor.getHTMLValue2();
    return sRetValue;
}

// string getBodyExValue()
URIAEditor40.prototype.getBodyExValue = function() {
    var sRetValue = "";
    sRetValue = this.Editor.getBodyExValue();
    return sRetValue;
}

// string getBodyValue()
URIAEditor40.prototype.getBodyValue = function() {
    var sRetValue = "";
    sRetValue = this.Editor.getBodyValue();
    return sRetValue;
}


// bool setSkinColor(string colorString)
URIAEditor40.prototype.setSkinColor = function (colorVal) {
    var bRetValue = false;
    bRetValue = this.Editor.setSkinColor(colorVal);
    return bRetValue;
}

// long getHTMLFileSize()
URIAEditor40.prototype.getHTMLFileSize = function () {
    var nRetValue = 0;
    nRetValue = this.Editor.getHTMLFileSize();
    return nRetValue;
}

//bool PrintHTML()
URIAEditor40.prototype.setPrint = function () {
    var bRetValue = false;
    bRetValue = this.Editor.PrintHTML();
    return bRetValue;
}

//bool setHTMLCSSURL()
URIAEditor40.prototype.setHTMLCSSURL = function (sURL) {
    var bRetValue = false;
    bRetValue = this.Editor.setHTMLCSSURL(sURL);
    return bRetValue;
}

//bool setHTMLJavascriptURL()
URIAEditor40.prototype.setHTMLJavascriptURL = function (sURL) {
    var bRetValue = false;
    bRetValue = this.Editor.setHTMLJavascriptURL(sURL);
    return bRetValue;
}

//bool setCaretPosition()
URIAEditor40.prototype.setCaretPosition = function (nCaretPos) {
    var bRetValue = false;
    bRetValue = this.Editor.setCaretPosition(nCaretPos);
    return bRetValue;
}

//bool setHTMLValueToBody()
URIAEditor40.prototype.setHTMLValueToBody = function (sHTMLValue) {
    var bRetValue = false;
    bRetValue = this.Editor.setHTMLValueToBody(sHTMLValue);
    return bRetValue;
}

//bool setImageMaxWidth()
URIAEditor40.prototype.setImageMaxWidth = function (nWidth) {
    var bRetValue = false;
    bRetValue = this.Editor.setImageMaxWidth(nWidth);
    return bRetValue;
}

//bool setImageMaxWidth()
URIAEditor40.prototype.setImageMaxHeight = function (nHeight) {
    var bRetValue = false;
    bRetValue = this.Editor.setImageMaxHeight(nHeight);
    return bRetValue;
}

//void SetImageAutoScale()
URIAEditor40.prototype.setImageAutoScale = function (bValue) {
    this.Editor.setImageAutoScale(bValue);
}

// bool setEditorHidden()
URIAEditor40.prototype.setEditorHidden = function() {

    var bRetValue = false;

    if (navigator.appName == "Netscape") //Firefox, Safari
    {
        var Holder = document.getElementById(this.URIAHolderID);
        Holder.style.display = 'none';
        bRetValue = true;
    }
    else
        bRetValue = this.Editor.setEditorHidden();

    return bRetValue;
}

// bool setEditorShow()
URIAEditor40.prototype.setEditorShow = function(nCaretPos) {

    var bRetValue = false;
    if (navigator.appName == "Netscape") //Firefox, Safari
    {
        var Holder = document.getElementById(this.URIAHolderID);
        Holder.style.display = '';
        bRetValue = true;
    }
    else
        bRetValue = this.Editor.setEditorShow(nCaretPos);

    return bRetValue;
}


URIAEditor40.prototype.setSavePrefixURL = function(sSavePrefixURL) {
    
    this.Editor.setSavePrefixURL(sSavePrefixURL);

}


URIAEditor40.prototype.getLocalImageList = function() {

    var imgList = this.Editor.getLocalImageList();

    return imgList;

}

URIAEditor40.prototype.getAllImageList = function() {

    var imgList = this.Editor.getAllImageList();

    return imgList;

}


//////////////// Admin Function, need to Administration license /////////////////////////
//bool setTableValue(string sTableID, int nRows, int nCols, string sValue, bool bUseHTML)
URIAEditor40.prototype.setTableValue = function (sTableID, nRow, nCol, sValue, bUseHTML) {
    var bRetValue = false;
    bRetValue = this.Editor.setTableValue(sTableID, nRow, nCol, sValue, bUseHTML);
    return bRetValue;
}

   function onSilverlightError(sender, args) {
   	var appSource = "";
   	if (sender != null && sender != 0) {
   		appSource = sender.getHost().Source;
   	}

   	var errorType = args.ErrorType;
   	var iErrorCode = args.ErrorCode;

   	if (errorType == "ImageError" || errorType == "MediaError") {
   		return;
   	}

   	var errMsg = "Silverlight 응용 프로그램에서 처리되지 않은 오류 " + appSource + "\n";

   	errMsg += "코드: " + iErrorCode + "    \n";
   	errMsg += "범주: " + errorType + "       \n";
   	errMsg += "메시지: " + args.ErrorMessage + "     \n";

   	if (errorType == "ParserError") {
   		errMsg += "파일: " + args.xamlFile + "     \n";
   		errMsg += "줄: " + args.lineNumber + "     \n";
   		errMsg += "위치: " + args.charPosition + "     \n";
   	}
   	else if (errorType == "RuntimeError") {
   		if (args.lineNumber != 0) {
   			errMsg += "줄: " + args.lineNumber + "     \n";
   			errMsg += "위치: " + args.charPosition + "     \n";
   		}
   		errMsg += "메서드 이름: " + args.methodName + "     \n";
   	}

   	throw new Error(errMsg);
   }

/// Common Javascript /////////////////////////////////////////////////////////

