var format = "HTML";
var initHTML = "";
var edit;
var RangeType;
function setFocus() {
	textEdit.focus();
}
function selectRange(){
	edit = textEdit.document.selection.createRange();
	RangeType = textEdit.document.selection.type;
}



//***Funtion the images
function addpic (what,opt,which) {

	myEditor = textEdit.document.selection.createRange();
	RangeType = textEdit.document.selection.type;

if (RangeType == "Control") {
EditCtrl.document.execCommand("InsertImage",true);
} 
else {
	


var picvar = which;
//var picvar = showModalDialog ("images.php", "", "dialogWidth:30em; dialogHeight:13em; status:0");
if (picvar != null) {
picvar = picvar.split("*");
var src_v = picvar[0]; //images source 
if (src_v != "" ) {
var alt_v = picvar[4];
var arrange_v = picvar[2]; //mode
var border_v = picvar[3];  //images border
if (border_v == "") {
border_v = "0";
}
var image = "<img src=\""+src_v+"\" alt=\""+alt_v+"\" border=\""+border_v+"\" align=\""+arrange_v+"\">";
var link_v = picvar[1]; //images URL
if (link_v != "" && link_v != "http:\/\/") {
image = "<a href=\""+link_v+"\" target=\"_blank\">"+image+"</a>";
}
//edit.pasteHTML (image);
myEditor.pasteHTML(image);
}}

}

}



function execCommand(command) {	
	if (format == "HTML"){
		setFocus();
		selectRange();	
		if ((command == "Undo") || (command == "Redo"))
			document.execCommand(command);
		else{
			if (arguments[1]==null)				
				edit.execCommand(command);
			else
				edit.execCommand(command, false, arguments[1]);}
		textEdit.focus();
		if (RangeType != "Control") edit.select();
	}	
}
function swapModes(Mode) {	
	switch(Mode){
		case 1:
			if (format == "ABC"){
				textEdit.document.body.innerHTML = textEdit.document.body.innerText;
				textEdit.document.body.style.fontFamily = "";
				textEdit.document.body.style.fontSize ="";
			}
			else{
				initHTML = textEdit.document.body.innerHTML;
				initEditor();
			}
			format = "HTML";
			break;	
		case 2:
			if (format == "PREVIEW"){
				initHTML = textEdit.document.body.innerHTML;
				initEditor();
			}	
			textEdit.document.body.innerText = textEdit.document.body.innerHTML;
			textEdit.document.body.style.fontFamily = "Verdana";
			textEdit.document.body.style.fontSize = "9pt";
			format = "ABC";
			break;
		case 3:
			var strHTML = "";
			if(format == "ABC"){
				strHTML = textEdit.document.body.innerText;
				textEdit.document.body.style.fontFamily = "";
				textEdit.document.body.style.fontSize ="";				
			}
			else{
				strHTML = textEdit.document.body.innerHTML;				
			}			
			format = "PREVIEW";
			textEdit.document.designMode="Off";
			textEdit.document.open();
			textEdit.document.write(strHTML);
			textEdit.document.close();
			if(textEdit.document.styleSheets.length == 0){
				textEdit.document.createStyleSheet();
				var oSS = textEdit.document.styleSheets[0];
				oSS.addRule("TABLE.ubb","border: 1px solid #A9A9A9;FONT-SIZE: 9pt; ");
				oSS.addRule("TD.ubb","border: 1px solid #A9A9A9;FONT-SIZE: 9pt; ");
				oSS.addRule("BODY","FONT-SIZE: 9pt;");
				oSS.addRule("IMG","border: 0");
			}
			break;
		default:
			return(0);
	}
	textEdit.focus();
	return(1);
}


//get type
function specialtype(Mark){
	if (format == "HTML"){
		var strHTML;
		setFocus();
		selectRange();	
		if (RangeType == "Text"){
			strHTML = "<" + Mark + ">" + edit.text + "</" + Mark + ">"; 
			edit.pasteHTML(strHTML);
			textEdit.focus();
			edit.select();			
		}
	}
}
function pasteHTML(HTML){	
	if (format == "HTML"){
		setFocus();
		selectRange();
		edit.pasteHTML(HTML);
		textEdit.focus();
		if (RangeType != "Control") edit.select();
	}
}
function initEditor() {
	textEdit.document.designMode="On";
	textEdit.document.open();
	textEdit.document.write(initHTML);
	textEdit.document.close();
	initHTML = "";
	if(textEdit.document.styleSheets.length == 0){
		textEdit.document.createStyleSheet();
		var oSS = textEdit.document.styleSheets[0];
		oSS.addRule("TABLE.ubb","border: 1px solid #A9A9A9;FONT-SIZE: 9pt; ");
		oSS.addRule("TD.ubb","border: 1px solid #A9A9A9;FONT-SIZE: 9pt; ");
		oSS.addRule("IMG","border: 0");
		oSS.addRule("BODY","font-size: 9pt");
	}	
}
function init() {
	initEditor();
	with (parent){
		if (loaded){
			parent.status = "";
			/*with (parent.document){
				all.editor.style.display = "block";
				forms[0].body.style.display = "none";
				forms[0].body.title = "";
			}*/
		}
		else
			loaded = 1;	
	}
}
initHTML = parent.parent.strHTML;
window.onload = init