var viewMode = 1; // WYSIWYG
var  align_type;
var h_space;
var v_space;
var border;
var i_height;
var toggle_mode = "on";
var img_list;
var class_on = "off";
<!--
//-->
function _wordClean() {
    editor.focus();
    var D = editor.innerHTML;
    if (D.indexOf("class=Mso") >= 0 || D.indexOf("mso") >= 0 || D.indexOf("Mso") >= 0) {

        // make one line
        D = D.replace(/\r\n/g, ' ').
            replace(/\n/g, ' ').
            replace(/\r/g, ' ').
            replace(/\&nbsp\;/g,' ');

        // keep tags, strip attributes
        D = D.replace(/ class=[^\s|>]*/gi,'').
            //replace(/<p [^>]*TEXT-ALIGN: justify[^>]*>/gi,'<p align="justify">').
            replace(/ style=\"[^>]*\"/gi,'').
            replace(/ align=[^\s|>]*/gi,'');

        //clean up tags
        D = D.replace(/<b [^>]*>/gi,'<b>').
            replace(/<i [^>]*>/gi,'<i>').
            replace(/<li [^>]*>/gi,'<li>').
            replace(/<ul [^>]*>/gi,'<ul>');

        // replace outdated tags
        D = D.replace(/<b>/gi,'<strong>').
            replace(/<\/b>/gi,'</strong>');

        // mozilla doesn't like <em> tags
        D = D.replace(/<em>/gi,'<i>').
            replace(/<\/em>/gi,'</i>');

        // kill unwanted tags
        D = D.replace(/<\?xml:[^>]*>/g, '').       // Word xml
            replace(/<\/?st1:[^>]*>/g,'').     // Word SmartTags
            replace(/<\/?[a-z]\:[^>]*>/g,'').  // All other funny Word non-HTML stuff
            replace(/<\/?font[^>]*>/gi,'').    // Disable if you want to keep font formatting
            replace(/<\/?span[^>]*>/gi,' ').
            replace(/<\/?div[^>]*>/gi,' ').
            replace(/<\/?pre[^>]*>/gi,' ').
            replace(/<\/?h[1-6][^>]*>/gi,' ');

        //remove empty tags
        //D = D.replace(/<strong><\/strong>/gi,'').
        //replace(/<i><\/i>/gi,'').
        //replace(/<P[^>]*><\/P>/gi,'');

        // nuke double tags
        oldlen = D.length + 1;
        while(oldlen > D.length) {
            oldlen = D.length;
            // join us now and free the tags, we'll be free hackers, we'll be free... ;-)
            D = D.replace(/<([a-z][a-z]*)> *<\/\1>/gi,' ').
                replace(/<([a-z][a-z]*)> *<([a-z][^>]*)> *<\/\1>/gi,'<$2>');
        }
        D = D.replace(/<([a-z][a-z]*)><\1>/gi,'<$1>').
            replace(/<\/([a-z][a-z]*)><\/\1>/gi,'<\/$1>');

        // nuke double spaces
        D = D.replace(/  */gi,' ');
        editor.innerHTML = D;
//        this.setHTML(D);
 //       this.updateToolbar();
    }
}
function stil()
{
 editor.focus();
 var str = editor.document.selection.createRange().text;
 var sel = editor.document.selection.createRange();
 st = document.editor_form.stiliai.value;
 alert (str.length);
 if (str.length<=0)
 {
    sel.cutHTML;
    if (class_on == "off")
    {
      sel.pasteHTML("<FONT CLASS=\'" + st + "\'>&nbsp;");
      class_on = "on";
    }
    else
    {
      sel.pasteHTML("</FONT><FONT CLASS=\'" + st + "\'>&nbsp;");
      class_on = "off";
    }

 }
 else
 {
   sel.cutHTML;
   sel.pasteHTML("<FONT CLASS=\'" + st + "\'>" + str + "</FONT>");
 }
 return;
}
//Nuorodos iterpimas
function insert_link()
{
  editor.focus();
  var str = editor.document.selection.createRange().text;
    if (str == "" || !str) 
        {
          lnk =  showModalDialog("bar_tools/insert_link.php", "", "resizable: no; help: no; status: no; scroll: no;");
      if (lnk)
          {
             var sel = editor.document.selection.createRange();
         sel.cutHTML;
         sel.pasteHTML("<a href=\'" + lnk + "\'>" + lnk + "</a>");
          }
        }
        else 
        {
           lnk =  showModalDialog("bar_tools/insert_link.php", "", "resizable: no; help: no; status: no; scroll: no;");
           if (lnk)
           {
          str2 = str;
                 // alert (lnk);
                     var sel = editor.document.selection.createRange();
                  //sel.cutHTML;
                  //lnk =escape(lnk);
                  sel.pasteHTML("<a href=\'" + lnk + "\' target='_parent'>" + str + "</a>");
           }
        }
  return;            
}
//Naujas  Nuorodos iterpimas
function insert_link_new()
{
img_list = showModalDialog("prisegimai_main.php", "", "resizable: no; help: no; status: no; scroll: no;");
if (img_list)
{
insertHtml(img_list); 
}            
}
//Linijos interpimas
function insert_line()
{
 editor.focus();
 var sel = editor.document.selection.createRange();
 sel.pasteHTML("<hr>");
}
function cell_prop()
{
  editor.focus();
    var ct = getTable(editor); // current table
    var cr = getTR(editor); // current row
    var cd = getTD(editor); 
        if (ct&&cr&&cd)
          lnk =  showModalDialog("cell_prop.htm", cd, "resizable: no; help: no; status: no; scroll: no;");  

}
//Paveiksliuko savybes
function img_properties()
{
  editor.focus();
  if (editor.document.selection.type == "Control")
   { 
      var oControlRange = editor.document.selection.createRange();
          var prop;
      for (i = 0; i < oControlRange.length; i++)
      {  
                    if (oControlRange(i).nodeName == "IMG")lnk =  showModalDialog("img_prop.htm", oControlRange(i), "resizable: no; help: no; status: no; scroll: no;");  
      }
   }
}
//Lenteles savybes
function tbl_properties()
{
  editor.focus();
  if (editor.document.selection.type == "Control")
   { 
      var oControlRange = editor.document.selection.createRange();          
      for (i = 0; i < oControlRange.length; i++)
      {  
                   if (oControlRange(i).nodeName == "TABLE") lnk =  showModalDialog("tbl_prop.htm", oControlRange(i), "resizable: no; help: no; status: no; scroll: no;");  
      }
   }
}

// returns current table cell  
  function getTD()
  {
    if (editor.document.selection.type != "Control")
    {
      var tControl = editor.document.selection.createRange();
      tControl = tControl.parentElement();
      while ((tControl.tagName != 'TD') && (tControl.tagName != 'TH') && (tControl.tagName != 'TABLE') && (tControl.tagName != 'BODY'))
      {
        tControl = tControl.parentElement;
      }
      if ((tControl.tagName == 'TD') || (tControl.tagName == 'TH'))
        return(tControl);
      else

        return(null);
    }
    else
    {
      return(null);
    }
  }

  // returns current table row  
  function getTR()
  {
    if (window.editor.document.selection.type != "Control")
    {
      var tControl = window.editor.document.selection.createRange();
      tControl = tControl.parentElement();
      while ((tControl.tagName != 'TR') && (tControl.tagName != 'TABLE') && (tControl.tagName != 'BODY'))
      {
        tControl = tControl.parentElement;
      }
      if (tControl.tagName == 'TR')
        return(tControl);
      else
        return(null);
    }
    else
    {
      return(null);
    }
  }
  
  // returns current table  
  function getTable()
  {
    
        if (window.editor.document.selection.type == "Control")
    { 
      var tControl = window.editor.document.selection.createRange();
      if (tControl(0).tagName == 'TABLE')
        return(tControl(0));
      else
        return(null);
    }
    else
    {
      var tControl = window.editor.document.selection.createRange();
      tControl = tControl.parentElement();
      while ((tControl.tagName != 'TABLE') && (tControl.tagName != 'BODY'))
      {
        tControl = tControl.parentElement;
      }
      if (tControl.tagName == 'TABLE')
        return(tControl);
      else
        return(null);
    }
  }
//iterpiai eilute
function insert_row()
{
  editor.focus();
  var ct = getTable(editor); // current table
    var cr = getTR(editor); // current row

    if (ct && cr)
    {
      var newr = ct.insertRow(cr.rowIndex+1);
      for (i=0; i<cr.cells.length; i++)
      {
        if (cr.cells(i).rowSpan > 1)
        {
          // increase rowspan
          cr.cells(i).rowSpan++;
        }
        else
        {
          var newc = cr.cells(i).cloneNode();
          newr.appendChild(newc);
        }
      }
      // increase rowspan for cells that were spanning through current row
      for (i=0; i<cr.rowIndex; i++)
      {
        var tempr = ct.rows(i);
        for (j=0; j<tempr.cells.length; j++)
        {
          if (tempr.cells(j).rowSpan > (cr.rowIndex - i))
            tempr.cells(j).rowSpan++;
        }
      }
    } 

}

function formCellMatrix(ct)
  {
    var tm = new Array();
    for (i=0; i<ct.rows.length; i++)
      tm[i]=new Array();

    for (i=0; i<ct.rows.length; i++)
    {
      jr=0;
      for (j=0; j<ct.rows(i).cells.length;j++)
      {
        while (tm[i][jr] != undefined) 
          jr++;

        for (jh=jr; jh<jr+(ct.rows(i).cells(j).colSpan?ct.rows(i).cells(j).colSpan:1);jh++)
        {
          for (jv=i; jv<i+(ct.rows(i).cells(j).rowSpan?ct.rows(i).cells(j).rowSpan:1);jv++)
          {
            if (jv==i)
            {
              tm[jv][jh]=ct.rows(i).cells(j).cellIndex;
            }
            else
            {
              tm[jv][jh]=-1;
            }
          }
        }
      }
    }
    return(tm);
  }
//iterpia stulpeli
function insert_col()
{
    editor.focus();
        var ct = getTable(editor); // current table
    var cr = getTR(editor); // current row
    var cd = getTD(editor); // current row
    if (cd && cr && ct)
    {
      // get "real" cell position and form cell matrix
      var tm = formCellMatrix(ct);
      
      for (j=0; j<tm[cr.rowIndex].length; j++)
      {
        if (tm[cr.rowIndex][j] == cd.cellIndex)
        {
          realIndex=j;
          break;
        }
      }
      
      // insert column based on real cell matrix
      for (i=0; i<ct.rows.length; i++)
      {
        if (tm[i][realIndex] != -1)
        {
          if (ct.rows(i).cells(tm[i][realIndex]).colSpan > 1)
          {
            ct.rows(i).cells(tm[i][realIndex]).colSpan++;
          }
          else
          {
            var newc = ct.rows(i).insertCell(tm[i][realIndex]+1)
            var nc = ct.rows(i).cells(tm[i][realIndex]).cloneNode();
            newc.replaceNode(nc);
          }
        }
      }
        }
}

//------
function table_cell_merge_right_click()
  {
    editor.focus();
        var ct = getTable(editor); // current table
    var cr = getTR(editor); // current row
    var cd = getTD(editor); // current row

    if (cd && cr && ct)
    {
      // get "real" cell position and form cell matrix
      var tm = formCellMatrix(ct);
      
      for (j=0; j<tm[cr.rowIndex].length; j++)
      {
        if (tm[cr.rowIndex][j] == cd.cellIndex)
        {
          realIndex=j;
          break;
        }
      }
      
      if (cd.cellIndex+1<cr.cells.length)
      {
        ccrs = cd.rowSpan?cd.rowSpan:1;
        cccs = cd.colSpan?cd.colSpan:1;
        ncrs = cr.cells(cd.cellIndex+1).rowSpan?cr.cells(cd.cellIndex+1).rowSpan:1;
        nccs = cr.cells(cd.cellIndex+1).colSpan?cr.cells(cd.cellIndex+1).colSpan:1;
        // check if theres nothing between these 2 cells
        j=realIndex;
        while(tm[cr.rowIndex][j] == cd.cellIndex) j++;
        if (tm[cr.rowIndex][j] == cd.cellIndex+1)
        {
          // proceed only if current and next cell rowspans are equal
          if (ccrs == ncrs)
          {
            // increase colspan of current cell and append content of the next cell to current
            cd.colSpan = cccs+nccs;
            cd.innerHTML += cr.cells(cd.cellIndex+1).innerHTML;
            cr.deleteCell(cd.cellIndex+1);
          }
        }
      }
    }
   //  update_toolbar(editor, true);    
  } // mergeRight


  function  table_cell_merge_down_click()
  {
       editor.focus();
        var ct = getTable(editor); // current table
    var cr = getTR(editor); // current row
    var cd = getTD(editor); // current row

    if (cd && cr && ct)
    {
      // get "real" cell position and form cell matrix
      var tm = formCellMatrix(ct);
      
      for (j=0; j<tm[cr.rowIndex].length; j++)
      {
        if (tm[cr.rowIndex][j] == cd.cellIndex)
        {
          crealIndex=j;
          break;
        }
      }
      ccrs = cd.rowSpan?cd.rowSpan:1;
      cccs = cd.colSpan?cd.colSpan:1;
      if (cr.rowIndex+ccrs<ct.rows.length)
      {
        ncellIndex = tm[cr.rowIndex+ccrs][crealIndex];
        if (ncellIndex != -1 && (crealIndex==0 || (crealIndex>0 && (tm[cr.rowIndex+ccrs][crealIndex-1]!=tm[cr.rowIndex+ccrs][crealIndex]))))
        {
          
          ncrs = ct.rows(cr.rowIndex+ccrs).cells(ncellIndex).rowSpan?ct.rows(cr.rowIndex+ccrs).cells(ncellIndex).rowSpan:1;
          nccs = ct.rows(cr.rowIndex+ccrs).cells(ncellIndex).colSpan?ct.rows(cr.rowIndex+ccrs).cells(ncellIndex).colSpan:1;
          // proceed only if current and next cell colspans are equal
          if (cccs == nccs)
          {
            // increase rowspan of current cell and append content of the next cell to current
            cd.innerHTML += ct.rows(cr.rowIndex+ccrs).cells(ncellIndex).innerHTML;
            ct.rows(cr.rowIndex+ccrs).deleteCell(ncellIndex);
            cd.rowSpan = ccrs+ncrs;
          }
        }
      }
    }
    // update_toolbar(editor, true);    
  } // mergeDown
  
  function  table_row_delete_click()
  {
       editor.focus();
        var ct = getTable(editor); // current table
    var cr = getTR(editor); // current row
    var cd = getTD(editor); // current cell

    if (cd && cr && ct)
    {
      // if there's only one row just remove the table
      if (ct.rows.length<=1)
      {
        ct.removeNode(true);
      }
      else
      {
        // get "real" cell position and form cell matrix
        var tm = formCellMatrix(ct);
        
        
        // decrease rowspan for cells that were spanning through current row
        for (i=0; i<cr.rowIndex; i++)
        {
          var tempr = ct.rows(i);
          for (j=0; j>tempr.cells.length; j++)
          {
            if (tempr.cells(j).rowSpan > (cr.rowIndex - i))
              tempr.cells(j).rowSpan--;
          }
        }
    
        
        curCI = -1;
        // check for current row cells spanning more than 1 row
        for (i=0; i<tm[cr.rowIndex].length; i++)
        {
          prevCI = curCI;
          curCI = tm[cr.rowIndex][i];
          if (curCI != -1 && curCI != prevCI && cr.cells(curCI).rowSpan>1 && (cr.rowIndex+1)<ct.rows.length)
          {
            ni = i;
            nrCI = tm[cr.rowIndex+1][ni];
            while (nrCI == -1) 
            {
              ni++;
              if (ni>ct.rows(cr.rowIndex+1).cells.length)
                nrCI = tm[cr.rowIndex+1][ni];
              else
                nrCI = ct.rows(cr.rowIndex+1).cells.length;
            }
            
            var newc = ct.rows(cr.rowIndex+1).insertCell(nrCI);
            ct.rows(cr.rowIndex).cells(curCI).rowSpan--;
            var nc = ct.rows(cr.rowIndex).cells(curCI).cloneNode();
            newc.replaceNode(nc);
            // fix the matrix
            cs = (cr.cells(curCI).colSpan>1)?cr.cells(curCI).colSpan:1;
            for (j=i; j<(i+cs);j++)
            {
              tm[cr.rowIndex+1][j] = nrCI;
              nj = j;
            }
            for (j=nj; j<tm[cr.rowIndex+1].length; j++)
            {
              if (tm[cr.rowIndex+1][j] != -1)
                tm[cr.rowIndex+1][j]++;
            }
          }
        }
        // delete row
        ct.deleteRow(cr.rowIndex);
      }
    }
     //update_toolbar(editor, true);    
  } // deleteRow
  
  function  table_column_delete_click()
  {
      editor.focus();
    var ct = getTable(editor); // current table
    var cr = getTR(editor); // current row
    var cd = getTD(editor); // current cell

    if (cd && cr && ct)
    {
      // get "real" cell position and form cell matrix
      var tm = formCellMatrix(ct);
    
      // if there's only one column delete the table
      if (tm[0].length<=1)  
      {
        ct.removeNode(true);
      }
      else
      {
              
        for (j=0; j<tm[cr.rowIndex].length; j++)
        {
          if (tm[cr.rowIndex][j] == cd.cellIndex)
          {
                    realIndex=j;
            break;
          }
        }
            var k = 0;
        while (k<ct.rows.length)
        {
                if (tm[k][realIndex] != -1)
          { 
                    if (ct.rows(k).cells(tm[k][realIndex]).colSpan>1)
              ct.rows(k).cells(tm[k][realIndex]).colSpan--;
            else
              ct.rows(k).deleteCell(tm[k][realIndex]);
          }
                  k++;
        }
      }
    }
    // update_toolbar(editor, true);    
  } // deleteColumn
  
  // split cell horizontally
  function  table_cell_split_horizontal_click()
  {
       editor.focus();
        var ct = getTable(editor); // current table
    var cr = getTR(editor); // current row
    var cd = getTD(editor); // current cell

    if (cd && cr && ct)
    {
      // get "real" cell position and form cell matrix
      var tm = formCellMatrix(ct);
  
      for (j=0; j<tm[cr.rowIndex].length; j++)
      {
        if (tm[cr.rowIndex][j] == cd.cellIndex)
        {
          realIndex=j;
          break;
        }
      }
      
      if (cd.rowSpan>1) 
      {
        // split only current cell
        // find where to insert a cell in the next row
        i = realIndex;
        while (tm[cr.rowIndex+1][i] == -1) i++;
        if (i == tm[cr.rowIndex+1].length) 
          ni = ct.rows(cr.rowIndex+1).cells.length;
        else
          ni = tm[cr.rowIndex+1][i];
          
        var newc = ct.rows(cr.rowIndex+1).insertCell(ni);
        cd.rowSpan--;
        var nc = cd.cloneNode();
        newc.replaceNode(nc);
  
        cd.rowSpan = 1;
      }
      else
      {
        // add new row and make all other cells to span one row more
        ct.insertRow(cr.rowIndex+1);
        for (i=0; i<cr.cells.length; i++)
        {
          if (i != cd.cellIndex)
          {
            rs = cr.cells(i).rowSpan>1?cr.cells(i).rowSpan:1;
            cr.cells(i).rowSpan = rs+1;
          }
        }
  
        for (i=0; i<cr.rowIndex; i++)
        {
          var tempr = ct.rows(i);
          for (j=0; j>tempr.cells.length; j++)
          {
            if (tempr.cells(j).rowSpan > (cr.rowIndex - i))
              tempr.cells(j).rowSpan++;
          }
        }
        
        // clone current cell to new row
        var newc = ct.rows(cr.rowIndex+1).insertCell(0);
        var nc = cd.cloneNode();
        newc.replaceNode(nc);
      }
    }
     //update_toolbar(editor, true);    
  } // splitH
  function table_cell_split_vertical_click()
  {
       editor.focus();
        var ct = getTable(); // current table
    var cr = getTR(); // current row
    var cd = getTD(); // current cell

    if (cd && cr && ct)
    {
      // get "real" cell position and form cell matrix
      var tm = formCellMatrix(ct);
  
      for (j=0; j<tm[cr.rowIndex].length; j++)
      {
        if (tm[cr.rowIndex][j] == cd.cellIndex)
        {
          realIndex=j;
          break;
        }
      }
      
      if (cd.colSpan>1)    
      {
        // split only current cell
        var newc = ct.rows(cr.rowIndex).insertCell(cd.cellIndex+1);
        cd.colSpan--;
        var nc = cd.cloneNode();
        newc.replaceNode(nc);
        cd.colSpan = 1;
      }
      else
      {
        // clone current cell
        var newc = ct.rows(cr.rowIndex).insertCell(cd.cellIndex+1);
        var nc = cd.cloneNode();
        newc.replaceNode(nc);
        
        for (i=0; i<tm.length; i++)
        {
          if (i!=cr.rowIndex && tm[i][realIndex] != -1)
          {
            cs = ct.rows(i).cells(tm[i][realIndex]).colSpan>1?ct.rows(i).cells(tm[i][realIndex]).colSpan:1;
            ct.rows(i).cells(tm[i][realIndex]).colSpan = cs+1;
          }
        }
      }
    }
    //update_toolbar(editor, true);    
  } // splitV
  
//------
function sup(){
    editor.document.execCommand('superscript');
    }        
//Subscript
function sub(){
    editor.document.execCommand('subscript');
    }        
//Boldinimas
function b(){
    editor.document.execCommand("Bold", false, null);
    }
//Italic
function ital(){
    editor.document.execCommand("Italic", false, null);
    }
//Underline
function u(){
    editor.document.execCommand("underline", false, null);
    }
//Font spalva
function font_color(){
    f_clr = showModalDialog("bar_tools/select_color.html", "", "resizable: no; help: no; status: no; scroll: no;");
    editor.document.execCommand("ForeColor", false, f_clr);
    }
function fill_color(){
    f_clr = showModalDialog("bar_tools/select_color.html", "", "resizable: no; help: no; status: no; scroll: no;");
    editor.document.execCommand("BackColor", false, f_clr);
    }
//Nustato fonta
function  get_font()
{
var family = document.selection.createRange(); //create text range

// don't get font face for image or table
if (document.selection.type == 'Control') {
   return;
}

var el = family.parentElement(); //get parent element
var tag = el.nodeName.toUpperCase(); //convert tag element to upper case

    if (typeof(el.parentElement) != "undefined" && tag == "FONT") { //only do function if tag is font - this is for greater execution speed
        var elface = el.getAttribute('FACE'); //get the font tags FACE attribute
        return elface; //return the value of the face attribute to the reset() function
    }
}
//Paveiksliukas
function im(failas){
    editor.document.execCommand("InsertImage", false, failas);
    }
//Naujo lango atidarymas
popUpWin = 0;
function new_window(URLStr)
{
  if (URLStr == 'img')
  {
      if(popUpWin)
      {
        if(!popUpWin.closed) popUpWin.close();
      }
        popUpWin = open("img_upl.php",'popUpWin',"toolbar=no,scrollbar=no,resizable=no,width=350,height=140 top=20 left=400");
  }
  else
  {
      html = showModalDialog("table_form.php", "", "resizable: no; help: no; status: no; scroll: no;");
          if (html)
          {
             insertHtml(html);
          }
  }
}

function  indent_right ()
{
  editor.document.execCommand("Indent");
}

function  indent_left ()
{
  editor.document.execCommand("Outdent");
}

// insertHtml(): Insert the supplied HTML into the current position
// within the document.
function insertHtml(html)
{
   editor.focus();
   var sel = editor.document.selection.createRange();
   // don't try to insert HTML into a control selection (ie. image or table)
   sel.pasteHTML(html);
}

//Sukuria popup objekta
var oPopup = window.createPopup();
function openPopup()
{
    //var oPopBody = oPopup.document.body;
    img = document.file_frm.img_list.value;
   /* oPopBody.innerHTML ="<IMG SRC='"+img+"' WIDTH=60 HEIGTH=60>";
    // Parameters of the show method are in the following order: x-coordinate,
    // y-coordinate, width, height, and the element to which the x,y
    // coordinates are relative. Note that this popup object is displayed
    // relative to the body of the document.
    oPopup.show(10, 200, 60, 60, document.body);*/
        document.preview.src = img; 

}

//Kopijavimas
function copy(){
    editor.focus();
    editor.document.execCommand("Copy", false, null);
    }
//Pastinimas
function paste(){
    editor.focus();
    editor.document.execCommand("Paste", false, null);
    }
//Cut
function cut(){
    editor.focus();
    editor.document.execCommand("Cut", false, null);
    }
//Undo
function undo(){
    editor.focus();
    editor.document.execCommand("Undo", '', null);
    }
//Redo
function redo(){
    editor.focus();
    editor.document.execCommand("Redo", '', null);
    }	
//Align = left
function left(){
    editor.document.execCommand("JustifyLeft", false, null);
    }
//Align = center
function center(){
    editor.document.execCommand("JustifyCenter", false, null);
    }
//Align = right
function right(){
    editor.document.execCommand("JustifyRight", false, null);
    }
//Align = full
function full(){
    editor.document.execCommand("JustifyFull", false, null);
    }
// Fontai
function font(laukas){
    var fontas = laukas.value;
    editor.document.execCommand("FontName", false, fontas);
    return;
    }
// Fontai
function stil2(f)
{
 //editor.focus();
 var str = editor.document.selection.createRange().text;
 var sel = editor.document.selection.createRange();
 //st = document.editor_form.stiliai.value;
  sel.cutHTML;
   sel.pasteHTML("<FONT CLASS=\'" + f + "\'>" + str + "</FONT>");
 return;
}
//Popupas paveiksliuko dydzio
function PopUpImg(ImagePath) {
 if (ImagePath != null) {
  var fullURL = document.location;
  var textURL = fullURL.toString();
  var URLlen = textURL.length;
  var lenMinusPage = textURL.lastIndexOf("/");
  lenMinusPage += 1; 
  var fullPath = textURL.substring(0, lenMinusPage);
  TmpImg = new Image(); 
  TmpImg.src = ImagePath;
  PopUpWin = window.open("","","width="+TmpImg.width +",height="+TmpImg.height+",menubar=no,toolbar=no");
  PopUpWin.document.write('<HTML><HEAD><TITLE>'+ImagePath+'</TITLE>');
  PopUpWin.document.write("</HEAD><BODY>");
  PopUpWin.document.write('<div style="position:absolute;width:'+TmpImg.width+'px;height:'+TmpImg.height+'px;left:0px;top:0px">');
  PopUpWin.document.write('<IMG SRC="' + fullPath + ImagePath + '"border=0>');
  PopUpWin.document.write("</BODY></HTML>");
  PopUpWin.document.close();
  TmpImg.close();
 }
}
//Paveiksliukas
function insert_img()
{
img_list = showModalDialog("nuotraukos_main.php?nr=1&fix=div_nuot", "", "resizable: no; help: no; status: no; scroll: no;");
if (img_list)
{
insertHtml(img_list);
}
}


//Fonto dydis
function font_size(laukas){
    sizas = laukas.value;
    editor.document.execCommand("FontSize", false, sizas);
    return;
    }
//Formos apdirbimas
function send()
{
    editor.focus();
        window.document.form1.content.value = editor.innerHTML;
    form1.submit();
}
//Naujienu siuntimas
function send_news()
{ 
    if (!window.document.form1.show_date.value)
        {
      alert ('Pasirinkite iki kada rodyti naujiena!');
        }
    else
        {
          window.document.form1.content.value = editor.innerHTML;
      form1.submit();
        }
}
function send_cont()
{
    window.document.form1.short.value = window.document.brief.short_contact.value;
	window.document.form1.content.value = editor.innerHTML;
	window.document.form1.action_type.value = 'contact';
    window.document.form1.submit();
}
//Iniciavimas
function Init()
{
 //editor.document.designMode = 'On';
 editor.focus();
 toggle_border();
}
//HTML / TEXT vaizdo perziura
function doToggleView()

{

if(viewMode == 1)

    {

        iHTML = editor.innerHTML;

        editor.innerText = iHTML;

        editor.focus();

        viewMode = 2; // Code

    }

else

    {

        iText = editor.innerText;

        editor.innerHTML = iText;

        editor.focus();

        viewMode = 1; // WYSIWYG

    }

}

//Remeliai
function toggle_border ()
{
if (toggle_mode == "on")
      {
        toggle_mode = "off";
      }
      else
      {
        toggle_mode = "on";
      }
if (editor.document.tagName == "TABLE")
    {
      tbls[0] = editor;
    }
    else
    {
      tbls = editor.getElementsByTagName("TABLE");
 }
 var tbln = 0;
    if (tbls != null) tbln = tbls.length;
    for (ti = 0; ti<tbln; ti++)
    {
      if ((tbls[ti].style.borderWidth == 0 || tbls[ti].style.borderWidth == "0px") &&
          (tbls[ti].border == 0 || tbls[ti].border == "0px") &&
          (toggle_mode == "on"))
      {
        tbls[ti].runtimeStyle.borderWidth = "1px";
        tbls[ti].runtimeStyle.borderStyle = "dashed";
        tbls[ti].runtimeStyle.borderColor = "#aaaaaa";
      } // no border
      else 
      {
        tbls[ti].runtimeStyle.borderWidth = "";
        tbls[ti].runtimeStyle.borderStyle = "";
        tbls[ti].runtimeStyle.borderColor = "";
      }
        
      var cls = tbls[ti].cells;
      // loop through cells
      for (ci = 0; ci<cls.length; ci++)
      {
        if ((tbls[ti].style.borderWidth == 0 || tbls[ti].style.borderWidth == "0px") &&
            (tbls[ti].border == 0 || tbls[ti].border == "0px") && 
            (cls[ci].style.borderWidth == 0 || cls[ci].style.borderWidth == "0px") && 
            (toggle_mode == "on"))
        {
          cls[ci].runtimeStyle.borderWidth = "1px";
          cls[ci].runtimeStyle.borderStyle = "dashed";
          cls[ci].runtimeStyle.borderColor = "#aaaaaa";
                  
        }
        else 
        {
          cls[ci].runtimeStyle.borderWidth = "";
          cls[ci].runtimeStyle.borderStyle = "";
          cls[ci].runtimeStyle.borderColor = "";
                
        }
      } // cells loop
    } // tables loop
        
}
<!---Toolbaras
function mouseover(el) {
  el.className = "raised";
}

function mouseout(el) {
  el.className = "button";
}

function mousedown(el) {
  el.className = "pressed";
}

function mouseup(el) {
  el.className = "raised";
}

function check_enter()
{
  if (ord == 13) 
  {
    event.returnValue = false;
    iText = editor.document.body.innerHTML;
    iText=iText+'<BR>';
        editor.document.body.innerHTML = iText;
    return;
  }
}       
function fndet()
{
 oWorkItem = event.srcElement;
   // Make sure menu doesn't interfere with links and buttons.

        document.body.setCapture();
         // Show the menu.
                 alert ("OK");
 



}
