// getElementById
function Id(elementid) { 
	return document.getElementById(elementid); 
}

function FormatText(command, option){
	frames.message.focus();
  	frames.message.document.execCommand(command, false, option);
  	frames.message.focus();
}

function AddImage(){	
	imagePath = prompt('Укажите адрес изображения', 'http://');				
	frames.message.focus();
	if ((imagePath != null) && (imagePath != "")){					
		frames.message.document.execCommand('InsertImage', false, imagePath);
  		frames.message.focus();
	}
	frames.message.focus();			
}

function ShowHTML(){
	document.all.im2.style.display = '';
	document.all.im1.style.display = 'none';
	NewHTML = frames.message.document.body.innerHTML;
	document.all.Frm.style.display = 'none';
	Add.NMH.value = NewHTML;
	Add.NMH.style.display = 'block';
}

function ShowNormal(){
	document.all.im1.style.display = '';
	document.all.im2.style.display = 'none';
	NewHTML = Add.NMH.value;
	Add.NMH.style.display = 'none';
	frames.message.document.body.innerHTML = NewHTML;
	document.all.Frm.style.display = 'block';
}

function a(obj){
	obj.style.border = "0";
}

function b(obj){
	obj.style.border = "1px Solid Gray";
}

function UPfile(){
	document.all.MenuFile.style.display='';
	HiddenS();
}

function DOWNfile(){
	document.all.MenuFile.style.display='none';
	ShowS();
}

function HiddenS(){
	Add.Heading.style.visibility='hidden';
	Add.selectFont.style.visibility='hidden';
}

function ShowS(){
	Add.Heading.style.visibility='visible';
	Add.selectFont.style.visibility='visible';
}

function Preview(){
	
	var TXT = frames.message.document.body.innerHTML;
	var board=window.open("","Preview"); 
	board.document.open(); 
	board.document.write("<html>"); 
	board.document.write("<head><title>Mouse DHTML - Preview</title></head>"); 
	board.document.write(TXT); 
	board.document.write("</body>"); 
	board.document.write("</html>"); 
	board.document.close();

	return board;
}

function Save(){
	
	board = Preview();
  	board.document.execCommand('SaveAs');
	board.window.close();
}

function PrintPage(){
	
	board = Preview();
  	board.document.execCommand('Print');
	board.window.close();
}

function AddHTML(AnCode) {

	var range = frames.message.document.selection.createRange();
	range.pasteHTML(AnCode); //range.insertHTML(AnCode);
	range.select();
	range.execCommand();

 	frames.message.focus();
 	
 	//InsertTag(AnCode,'');
}

function InsertTag(start,end) {
	//var el = Id(elementid);
	var el = frames.message;
	el.focus();
	if (el.setSelectionRange) {
		el.value = el.value.substring(0,el.selectionStart) + start + el.value.substring(el.selectionStart,el.selectionEnd) + end + el.value.substring(el.selectionEnd,el.value.length);
	} else {
		var str = document.selection.createRange();
		document.selection.createRange().text = start + str.text + end;
	}
	el.focus();
} 

