var objEditor = new proEditor();

//--- Editor
//--- Defense if focus set txtEditor else if no txtEditor exit funciton.
function proEditor() {
//--- Ut 2008.04.30 *Dc*
    this.txtEditor = undefined;
}
proEditor.prototype.initEditor = function(elmObj) {
    var strEvent = objTest.addEvent('initEditor(' + getId(elmObj) + ')');
    if (this.txtEditor) { return true; } // Defense
    this.blnChange = false; //--- Mouse up set ary edit
    this.aryEdit = new Array();
    this.intEdit = 0;
    this.strClip = '';
    this.txtEditor = elmObj;
    this.pushText();
}
proEditor.prototype.pressKeyDown = function(intCharCode, blnAlt, blnCtrl, blnShift) {
    if (!this.txtEditor) return true; //--- Defense
    intCharCode = toUpper(intCharCode);
    if (blnCtrl) {
        switch (intCharCode) {
            case 67:
                this.copyText();
                return false;
            case 80:
                this.pasteText();
                return false;
            case 83:
                //this.saveEdit();
                return false;
            case 88:
                this.cutText();
                return false;
            case 89:
                this.redoEdit();
                return false;
            case 90:
                this.undoEdit();
                return false;
        }
        return true; //--- All pass
    }
}
proEditor.prototype.pressKey = function(intCharCode, blnAlt, blnCtrl, blnShift) {
    if (!this.txtEditor) return false; //--- Defense
    intCharCode = toUpper(intCharCode)
    this.blnChange = (isNumber(intCharCode, blnAlt, blnCtrl, blnShift) //--- Number
        || isAlpha(intCharCode, blnAlt, blnCtrl, blnShift) //--- Letter
        || isSpecial(intCharCode, blnAlt, blnCtrl, blnShift) //--- Special
        || isChange(intCharCode, blnAlt, blnCtrl, blnShift)); //--- Change
    return true;
}
proEditor.prototype.pressKeyUp = function(intCharCode, blnAlt, blnCtrl, blnShift) {
    if (!this.txtEditor) return false; //--- Defense
    if (this.blnChange) { this.pushText(); }
    return true; 
}
proEditor.prototype.undoEdit = function() {
    if (!this.txtEditor) return false; //--- Defense
    this.txtEditor.focus();
    if (blnIx) {
        document.execCommand('undo');
    } else {
        if (this.intEdit > 0) {
            this.intEdit -= 1;
            this.txtEditor.value = this.aryEdit[this.intEdit];
        }
    }
    this.txtEditor.focus();
}
proEditor.prototype.redoEdit = function() {
    if (!this.txtEditor) return false; //--- Defense
    this.txtEditor.focus();
    if (blnIx) {
        document.execCommand('redo');
    } else {
        if (this.intEdit < (this.aryEdit.length - 1)) {
            this.intEdit += 1;
            this.txtEditor.value = this.aryEdit[this.intEdit];
        }
    }
    this.txtEditor.focus();
}
proEditor.prototype.pushText = function() {
    if (!this.txtEditor) return false; //--- Defense
    //this.aryEdit.slice(this.intEdit, this.aryEdit.length)
    this.aryEdit.push(this.txtEditor.value);
    this.intEdit = (this.aryEdit.length - 1);
}
proEditor.prototype.copyText = function() {
    if (!this.txtEditor) return false; //--- Defense
    this.txtEditor.focus();
    if (blnIx) {
        document.execCommand('copy');
    } else {
        if ((this.txtEditor.selectionEnd - this.txtEditor.selectionStart) > 0) { this.strClip = this.txtEditor.value.substring(this.txtEditor.selectionStart, this.txtEditor.selectionEnd); }
    }
    this.txtEditor.focus();
}
proEditor.prototype.cutText = function() {
    if (!this.txtEditor) return false; //--- Defense
    this.txtEditor.focus();
    if (blnIx) {
        document.execCommand('cut');
    } else {
        var intCursor = this.txtEditor.selectionStart;
        this.copyText();
        this.txtEditor.value = this.txtEditor.value.substring(0, this.txtEditor.selectionStart) + this.txtEditor.value.substring(this.txtEditor.selectionEnd, this.txtEditor.value.length);
        this.txtEditor.setSelectionRange(intCursor, intCursor);
    }
    this.pushText();
    this.txtEditor.focus();
}
proEditor.prototype.pasteText = function() {
    if (!this.txtEditor) return false; //--- Defense
    this.txtEditor.focus();
    if (blnIx) {
        document.execCommand('paste');
    } else {
        var intCursor = (this.txtEditor.selectionStart + this.strClip.length);
        if (!isNOE(this.strClip)) { this.txtEditor.value = this.txtEditor.value.substring(0, this.txtEditor.selectionStart) + this.strClip + this.txtEditor.value.substring(this.txtEditor.selectionEnd, this.txtEditor.value.length); }
        this.txtEditor.setSelectionRange(intCursor, intCursor);
    }
    this.pushText();
    this.txtEditor.focus();
}
//proEditor.prototype.getEditor(current) {
//	var i;
//	ancestorID = getId(current.parentNode.parentNode.parentNode.parentNode);
//	for (i = 0; i < objects.length; i ++)
//	{
//		if (objects[i].ID == ancestorID)
//			return objects[i];
//	}	
//}
//proEditor.prototype.callFormatting(str,current) {	
//	try
//	{
//		editor = GetEditor(current);
//		document.getElementById(editor.DivID).focus();
//		editor.format(str);
//	}catch(e){
//		alert("Unable to preform format operation");
//	}	
//}
//proEditor.prototype.formatText(strCommandPk, strControlPk) {
//var strEvent = objTest.addEvent(strCommandPk);
//    document.execCommand(strCommandPk); 
//    document.getElementById(strControlPk).focus();
//}
//proEditor.prototype.currentEditor(current) {
//	//Retrieve the actual ContactList id using the HTML button received.
//	current = getId(current.parentNode.parentNode.parentNode.parentNode);
//	
//	var i;
//	for (i = 0; i < objects.length; i ++)
//		if (objects[i].UniqueId == current)
//			return objects[i];
//}
//proEditor.prototype.setFont(val,e) {
//	editor = GetEditor(e);
//	document.getElementById(editor.DivID).focus();
//	document.execCommand('fontname', false, val);
//}
//proEditor.prototype.setFontSize(val,e) {
//	editor = GetEditor(e);
//	document.getElementById(editor.DivID).focus();
//	document.execCommand('fontsize', false, val);
//}
//proEditor.prototype.setHeader(val) {
//	document.execCommand('formatblock', false, val);  
//}
//proEditor.prototype.setStyle(value) {
//	document.execCommand('removeFormat');
//	document.execCommand('formatBlock','','Normal');
//	selection = document.selection.createRange();
//	html = '<font class=\'' + value + '\'>' + selection.htmlText + '</font>';
//	selection.pasteHTML(html);
//}
//proEditor.prototype.selectStyle(e) {
//	editor = GetEditor(e);
//	document.getElementById(editor.DivID).focus();
//	index = document.getElementById(getId(editor)+"_cssSelect").selectedIndex;
//	setStyle(document.getElementById(getId(editor)+"_cssSelect").options[index].text,editor);
//}
//proEditor.prototype.insertTime(e) {
//	var d = new Date();
//	insertString(d.toLocaleTimeString(),e);	
//}
//proEditor.prototype.insertDate(strControlPk) {
//var strEvent = objTest.addEvent('insertDate ' + strControlPk);
//	var d = new Date();
//	insertString(d.toLocaleDateString()+" "+d.toLocaleTimeString(),document.getElementById(strControlPk));	
//}
//proEditor.prototype.insertString(val,e) {
//	ed = GetEditor(e);
//	document.getElementById(ed.DivID).focus();
//	sel = document.selection.createRange();
//	sel.pasteHTML(val);
//}
//proEditor.prototype.insertTable(path) {
//var strEvent = objTest.addEvent('insertTable ' + path);
//	showModalDialog(path + "InsertTable.htm","resizable: yes; help: no; status: no; scroll: no; ");
//}
//proEditor.prototype.insertImage(path) {
//var strEvent = objTest.addEvent('insertImage ' + path);
//	showModalDialog(path + "InsertImage.htm","resizable: yes; help: no; status: no; scroll: no; ");
//}
//proEditor.prototype.changeForeColor() {
//var strEvent = objTest.addEvent('changeForeColor ' + sInitColor);
//	if (sInitColor == null) 
//		var sColor = document.dlgHelper.ChooseColorDlg();
//	else
//		var sColor = document.dlgHelper.ChooseColorDlg(sInitColor);
//	    //change the return value from a decimal value to a hex value and make sure the value has 6
//	    //digits to represent the RRGGBB schema required by the color table
//	    sColor = sColor.toString(16);
//	    if (sColor.length < 6) {
//		    var sTempString = "000000".substring(0,6-sColor.length);
//		    sColor = sTempString.concat(sColor);
//	    }
//	    document.execCommand("ForeColor", false, sColor);
//	    sInitColor = sColor;
//}
//proEditor.prototype.changeBackColor() {
//var strEvent = objTest.addEvent('changeBackColor ' + sInitColor);
//	if (sInitColor == null) 
//		var sColor = document.dlgHelper.ChooseColorDlg();
//	else
//		var sColor = document.dlgHelper.ChooseColorDlg(sInitColor);
//	    //change the return value from a decimal value to a hex value and make sure the value has 6
//	    //digits to represent the RRGGBB schema required by the color table
//	    sColor = sColor.toString(16);
//	    if (sColor.length < 6) {
//		    var sTempString = "000000".substring(0,6-sColor.length);
//		    sColor = sTempString.concat(sColor);
//	    }
//	    document.execCommand("BackColor", false, sColor);
//	    sInitColor = sColor;
//}
//proEditor.prototype.getText(e) {
//	document.getElementById(getId(e)+"_htmlhidden").value = document.getElementById(getId(e)).innerHTML;		
//}
//proEditor.prototype.getTextfromTA(e) {
//	ancestor = getId(e.parentNode.parentNode.parentNode.parentNode.parentNode);
//	document.getElementById(ancestor+"_Div_htmlhidden").value = document.getElementById(ancestor+"_Div_htmltextarea").innerText;	
//}
//RichTextEditor.prototype.format = format;
//RichTextEditor.prototype.setFont = setFont;
//RichTextEditor.prototype.setFontSize = setFontSize;
//RichTextEditor.prototype.setHeader = setHeader;
//RichTextEditor.prototype.setStyle = setStyle;
//RichTextEditor.prototype.selectStyle = selectStyle;
//RichTextEditor.prototype.insertTime = insertTime;
//RichTextEditor.prototype.insertDate = insertDate;
//RichTextEditor.prototype.insertString = insertString;
//RichTextEditor.prototype.insertTable = insertTable;
//RichTextEditor.prototype.about = about;
//RichTextEditor.prototype.changeForeColour = changeForeColour;
//RichTextEditor.prototype.getText = getText;

