//
//***********************************************************************************
//***********************************************************************************
//***********************************************************************************
//
var htmEd_CodePage     = "Windows-1251";
var htmEd_css          = "htm_ed_0000.css";
var htmEd_root         = "file://c:\\rdsx\\projects\\rds11\\$-root\\patrns";
var htmEd_initial      = "Hello world!";
var UPLOAD_FULL_URL    = '';

var UPLOAD_ALIGN        = 'middle'; // top middle left right
var UPLOAD_VSPACE       = '20';
var UPLOAD_HSPACE       = '20';
 
// for create link //var LINK_FULL_URL      = '';
// for create link //var htmEd_choose_image = '';

var htmEd_create_link  = 'file://c:\\rdsx\\projects\\rds11\\$-root\\patrns\rds_htm_ed_0000.htm';
var htmEd_ON           = false;
//
//***********************************************************************************
//***********************************************************************************
//***********************************************************************************
//
var htmEd_isGecko = false;
var htmEd_iframe  = null;
var htmEd_iWin    = null;
var htmEd_iDoc    = null;
//
//***********************************************************************************
// 
function htmEd_wrButton(sClick,sImage,sAlt) {
document.write("<a href='#' onclick='" + sClick + "'>");
document.write("<img hspace='0' vspace='0' border='0'");
document.write("src = '" + htmEd_root + "/" + sImage + "' alt='" + sAlt + "'>");
document.write("</a>");
}
//
//***********************************************************************************
//
function htmEd_Bold(exec_click) {                //  Toggles the current
                                                 //  selection between bold and nonbold.
  if (exec_click) {
	htmEd_iWin.focus();
    htmEd_iWin.document.execCommand("Bold", null, "");
  } else {
	htmEd_wrButton('htmEd_Bold(true)','edt_bold.png','выделить жирным шрифтом');
  }
}

function htmEd_CreateLink(exec_click) {          // Inserts a hyperlink on the
                                                 // current selection, or displays
                                                 // a dialog box enabling the user
                                                 // to specify a URL to insert as
                                                 // a hyperlink on the current selection.
// for create link //  if (exec_click) {
// for create link //    if ( LINK_FULL_URL == '' ) {
// for create link //	window.open(htmEd_create_link,'Link','scrollbars=1,width=660,height=700')
// for create link //        return;
// for create link //
// for create link //    } else {	
// for create link //    	htmEd_iWin.focus();
// for create link //    	htmEd_iWin.document.execCommand("CreateLink",true);
// for create link //    }
// for create link //  } else {
// for create link //	htmEd_wrButton('htmEd_CreateLink(true)', 'edt_link.png','вставить ссылку');
// for create link //  }





}

function htmEd_InsertImage(exec_click) {         // Overwrites an image on the text selection.

  return;
  
  if (htmEd_choose_image == null)  {
  
    return;
  
  }
  
  if (exec_click) {
	
	if (UPLOAD_FULL_URL == '') {
	
	  window.open(htmEd_choose_image,'Image','scrollbars=1,width=660,height=700')
	  
	  return;
	
	} else {

	  htmEd_iWin.focus();
          UPLOAD_FULL_URL += ' " alt="Image" align="'+UPLOAD_ALIGN+'" border="0" hspace="'+UPLOAD_HSPACE+'" vspace="'+UPLOAD_VSPACE+'"';
	  htmEd_iWin.document.execCommand("InsertImage", null, UPLOAD_FULL_URL);
     
	  UPLOAD_FULL_URL = '';
    }

  } else {
	
	htmEd_wrButton('htmEd_InsertImage(true)','edt_img.png','вставить изображение');
  
  }
}

function htmEd_InsertOrderedList(exec_click) {   // Toggles the text
                                                 // selection between an ordered
                                                 // list and a normal format block.

   if (exec_click) {
	htmEd_iWin.focus();
        htmEd_iWin.document.execCommand("InsertOrderedList", null, "");
  } else {
	htmEd_wrButton('htmEd_InsertOrderedList(true)', 'edt_order_list.png','нумерованный список');
  }


}

function htmEd_InsertUnorderedList(exec_click) { // Toggles the text selection
                                                 // between an ordered list
                                                 // and a normal format block.
  if (exec_click) {
	htmEd_iWin.focus();
    htmEd_iWin.document.execCommand("InsertUnorderedList", null, "");
  } else {
	htmEd_wrButton('htmEd_InsertUnorderedList(true)', 'edt_list.png','маркированный список');
  }

}

function htmEd_Italic(exec_click) {              // Toggles the current selection
                                                 // between italic and nonitalic.
  if (exec_click) {
	htmEd_iWin.focus();
    htmEd_iWin.document.execCommand("Italic", null, "");
  } else {
	htmEd_wrButton('htmEd_Italic(true)', 'edt_italic.png','сделать шрифт наклонным');
  }
}



function htmEd_JustifyCenter(exec_click) {       // Centers the format block
                                                 // in which the current selection is located.


   if (exec_click) {
	htmEd_iWin.focus();
        htmEd_iWin.document.execCommand("JustifyCenter", null, "");
  } else {
	htmEd_wrButton('htmEd_JustifyCenter(true)', 'edt_center_align.png','по центру');
  }

}

function htmEd_JustifyLeft(exec_click) {         // Left-justifies the format block
                                                 // in which the current selection is located.

   if (exec_click) {
	htmEd_iWin.focus();
        htmEd_iWin.document.execCommand("JustifyLeft", null, "");
  } else {
	htmEd_wrButton('htmEd_JustifyLeft(true)', 'edt_left_align.png','по левому краю');
  }


}

function htmEd_JustifyRight(exec_click) {        // Right-justifies the format block
                                                 // in which the current selection is located.

   if (exec_click) {
	htmEd_iWin.focus();
        htmEd_iWin.document.execCommand("JustifyRight", null, "");
  } else {
	htmEd_wrButton('htmEd_JustifyRight(true)', 'edt_right_align.png','по правому краю');
  }

}


function htmEd_JustifyFull(exec_click) {        // Full-justifies the format block
                                                 // in which the current selection is located.

   if (exec_click) {
	htmEd_iWin.focus();
        htmEd_iWin.document.execCommand("JustifyFull", null, "");
  } else {
	htmEd_wrButton('htmEd_JustifyFull(true)', 'edt_justify_align.png','по краям');
  }

}

function htmEd_Empty() {        // Full-justifies the format block
                                                 // in which the current selection is located.

    htmEd_wrButton('', 'edt_short_empt.png','');

}




function htmEd_Underline(exec_click) {           // Toggles the current selection
                                                 // between underlined and not underlined.
  if (exec_click) {
	htmEd_iWin.focus();
    htmEd_iWin.document.execCommand("Underline", null, "");
  } else {
	htmEd_wrButton('htmEd_Underline(true)','edt_undeline.png','подчекнуть текст');
  }
}
function htmEd_move_content(dst) {               
  
  if (htmEd_ON == false) {
    
	return;  
  
  }
  
  el = document.getElementById(dst);
  
  if (!el) {
    return;  
  }
  
  var cntt = htmEd_iDoc.body.innerHTML;

  el.value = cntt;
}

function htmEd_draw() {

  document.write("<div id='htmEd_zone' class='htmEd_zone'>"); 
  
    document.write("<div id='htmEd_toolbar' class='htmEd_toolbar'>"); 

      htmEd_Bold(false);
      htmEd_Italic(false);
      htmEd_Underline(false);

      htmEd_JustifyLeft(false);
      htmEd_JustifyCenter(false);
      htmEd_JustifyRight(false);
      htmEd_JustifyFull(false)
      htmEd_Empty();

      htmEd_InsertOrderedList(false);
      htmEd_InsertUnorderedList(false);
      /*htmEd_Empty();*/
  
      /*htmEd_CreateLink(false);*/
      htmEd_InsertImage(false);

    document.write("</div>");

    document.write("<iframe scrolling='auto' frameborder='no'");
    document.write(" id='htmEd_frame' name='htmEd_frame' class='htmEd_frame'>");
    document.write("</iframe>");

  document.write("</div>"); 

  htmEd_isGecko = navigator.userAgent.toLowerCase().indexOf("gecko") != -1;

  htmEd_iframe = (htmEd_isGecko) ?

                         document.getElementById("htmEd_frame") :
                          
						                     frames["htmEd_frame"]; 
  
  htmEd_iWin   = (htmEd_isGecko) ? htmEd_iframe.contentWindow : htmEd_iframe.window;
  
  htmEd_iDoc   = (htmEd_isGecko) ? htmEd_iframe.contentDocument : htmEd_iframe.document;

  var iHTML = "";

  iHTML += "<html><head>\n";
  iHTML += "<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=" + htmEd_CodePage + "'>\n";
  iHTML += "<link rel='stylesheet' href='" + htmEd_root + "/" + htmEd_css + "' type='text/css'>\n";
  iHTML += "</head>\n";
  iHTML += "<body>" + htmEd_initial + "</body>";
  iHTML += "</html>";

  htmEd_iDoc.open();
  htmEd_iDoc.write(iHTML);
  htmEd_iDoc.close();

  if (!htmEd_iDoc.designMode) { 
   
	htmEd_ON = false;

	return htmEd_ON; 

  } else { 
  
        design_State = (htmEd_isGecko) ? "on" : "On";
        setTimeout(function() { htmEd_iDoc.designMode = design_State; },10);
    
	htmEd_ON = true;

	return htmEd_ON; 

  }
}

function htmEd_GO() {

 if (htmEd_draw()) {

   document.write("<input type='hidden' id='htmEd_content' name='htmEd_content' value='" + htmEd_initial + "'>");

   return; 
 }
 
 el = document.getElementById("htmEd_zone");
 
 if (el) {
   
   el.style='display:none';
 
 }
 
 document.write("<textarea id='htmEd_content' name='htmEd_content' class='htmEd_textarea' rows='8'>");
 
 document.write(htmEd_initial);
 
 document.writeln("</textarea>");

}
