var htmlobj, textCtrl
var bodyProcessed


function BodyOnLoad()
{
	textCtrl = GetControl("KR1096");
	htmlobj = GetControl("htmled");	

	if (htmlobj != null && textCtrl != null){
		bodyProcessed = true;
	 	if (textCtrl.value != null && textCtrl.value.length > 0) {		
			htmlobj.DocumentHTML = textCtrl.value;		
		}
		htmlobj.focus();
	} 

}

function GetHTMLText(idHtml, idText)
{
	textCtrl = GetControl(idText);
	htmlobj = GetControl(idHtml);	
	if (htmlobj != null && textCtrl != null){
		textCtrl.style.visibility = 'hidden';
		if (bodyProcessed)
			textCtrl.value = htmlobj.DocumentHTML;				
	}
}

function htlmedChanged() {
fuSelection();
}

function FontName_onchange() {
  document.htmled.ExecCommand(5044, 0, document.Form1.FontName.value);
  document.htmled.DOM.focus();
}

function FontSize_onchange() {
  document.htmled.ExecCommand(5045, 0, parseInt(document.Form1.FontSize.value));
  document.htmled.DOM.focus();
}

function DECMD_BOLD_onclick() {
  document.htmled.ExecCommand(5000,0);  
  document.htmled.DOM.focus();
}

function DECMD_ITALIC_onclick() {
  document.htmled.ExecCommand(5023,0);
  document.htmled.DOM.focus();
}

function DECMD_UNDERLINE_onclick() {
  document.htmled.ExecCommand(5048,0);
  document.htmled.DOM.focus();
}

function DECMD_SETFORECOLOR_onclick() {
  var arr = showModalDialog( "./Inc/selcolor.htm",
                             "",
                             "font-family:Verdana; font-size:12; dialogWidth:30em; dialogHeight:34em" );

  if (arr != null) {
    document.htmled.ExecCommand(5046,0, arr);    
  }  
  document.htmled.DOM.focus();
}

function DECMD_SETBACKCOLOR_onclick() {
  var arr = showModalDialog( "./Inc/selcolor.htm",
                             "",
                             "font-family:Verdana; font-size:12; dialogWidth:30em; dialogHeight:34em" );

  if (arr != null) {
    document.htmled.ExecCommand(5042,0, arr);
  }
  document.htmled.DOM.focus();
}

function DECMD_HYPERLINK_onclick() {
  document.htmled.ExecCommand(5016,0);  
  document.htmled.DOM.focus();
}

function DECMD_CUT_onclick() {
  document.htmled.ExecCommand(5003,0);
  document.htmled.DOM.focus();
}

function DECMD_COPY_onclick() {
  document.htmled.ExecCommand(5002,0);
  document.htmled.DOM.focus();
}

function DECMD_PASTE_onclick() {
  document.htmled.ExecCommand(5032,0);
  document.htmled.DOM.focus();
}

function DECMD_ORDERLIST_onclick() {
  document.htmled.ExecCommand(5030,0);
  document.htmled.DOM.focus();
}

function DECMD_UNORDERLIST_onclick() {
  document.htmled.ExecCommand(5051,0);
  document.htmled.DOM.focus();
}

function DECMD_FINDTEXT_onclick() {
  document.htmled.ExecCommand(5008,0);
  document.htmled.DOM.focus();
}

function fuSelection() {
  sel = document.htmled.DOM.selection;
  if ( "Text" == sel.type )
  {
    range = sel.createRange();
  }
	//Handle Bold button bgcolor
    s = document.htmled.QueryStatus(5000);
    if (s == 1 || s == 0) {
      document.getElementById("DECMD_BOLD").style.backgroundColor = "buttonface";
    } else if (s == 3  || s == 11) {
       document.getElementById("DECMD_BOLD").style.backgroundColor = "buttonface";
    } else { // DECMDF_LATCHED
       document.getElementById("DECMD_BOLD").style.backgroundColor = "oldlace";
    }
	//Handle Italic button bgcolor
    s = document.htmled.QueryStatus(5023);
    if (s == 1 || s == 0) {
      document.getElementById("DECMD_ITALIC").style.backgroundColor = "buttonface";
    } else if (s == 3  || s == 11) {
       document.getElementById("DECMD_ITALIC").style.backgroundColor = "buttonface";
    } else { // DECMDF_LATCHED
       document.getElementById("DECMD_ITALIC").style.backgroundColor = "oldlace";
    }
    //Handle Underlined button bgcolor
    s = document.htmled.QueryStatus(5048);
    if (s == 1 || s == 0) {
      document.getElementById("DECMD_UNDERLINE").style.backgroundColor = "buttonface";
    } else if (s == 3  || s == 11) {
       document.getElementById("DECMD_UNDERLINE").style.backgroundColor = "buttonface";
    } else { // DECMDF_LATCHED
       document.getElementById("DECMD_UNDERLINE").style.backgroundColor = "oldlace";
    }
    //Handle Orderlist button bgcolor
    s = document.htmled.QueryStatus(5030);
    if (s == 1 || s == 0) {
      document.getElementById("DECMD_ORDERLIST").style.backgroundColor = "buttonface";
    } else if (s == 3  || s == 11) {
       document.getElementById("DECMD_ORDERLIST").style.backgroundColor = "buttonface";
    } else { // DECMDF_LATCHED
       document.getElementById("DECMD_ORDERLIST").style.backgroundColor = "oldlace";
    }
	//Handle UnOrderlist button bgcolor
    s = document.htmled.QueryStatus(5051);
    if (s == 1 || s == 0) {
      document.getElementById("DECMD_UNORDERLIST").style.backgroundColor = "buttonface";
    } else if (s == 3  || s == 11) {
       document.getElementById("DECMD_UNORDERLIST").style.backgroundColor = "buttonface";
    } else { // DECMDF_LATCHED
       document.getElementById("DECMD_UNORDERLIST").style.backgroundColor = "oldlace";
    }
	//Handle fontname
	s = document.htmled.QueryStatus(5013);
	if (s == 1 || s == 0) {
		document.Form1.FontName.disabled = true;
	} else {
		document.Form1.FontName.disabled = false;
		document.Form1.FontName.value = document.htmled.ExecCommand(5013, 0);
	}
	//Handle fotnsize
	if (s == 1 || s == 0) {
		document.Form1.FontSize.disabled = true;
	} else {
		document.Form1.FontSize.disabled = false;
		document.Form1.FontSize.value = document.htmled.ExecCommand(5014, 0);
	}	
}

/*
function fvSetReadFlag(bool bFlag)
begin
	ifl bFlag
		mex_getmessage_info(nSessionID, 13, 0, lsGetMsgID(), "") // sätt som läst
	else
		mex_getmessage_info(nSessionID, 14, 0, lsGetMsgID(), "") // sätt som oläst
	endifl
end
*/


	