// <script>

function add_table()
  {
  data = showModalDialog("tools/_add_table.html","","help:no;status:no;dialogWidth:300px;dialogHeight:300px");
  if (data)  
     {
      array=data.split("##");
      mainframe.focus();
      test = mainframe.document.selection.createRange();
      height = "";
      if (array[2]!="") height = "height=\""+array[2]+"\"";
      if (array[6]=="") array[6] = 0;
      if (array[7]=="") array[7] = 0;
      if (array[3]=="") array[3] = 1;
      if (array[4]=="") array[4] = 1;
 
      _html = "<TABLE class=myTableOuter cellSpacing=\"0\" cellPadding=\"0\" width=\""+array[1]+"\" border=0 "+height+">";
      _html += "<TR>";
      _html += "<TD>";
      _html += "<TABLE class=myTable cellSpacing="+array[5]+" cellPadding="+array[7]+" width=\"100%\">";

      for (x=0;x<array[3];x++)
         {
         _html += "<TR>";
         for (y=0;y<array[4];y++)
            {
            _html += "<TD class=myTD>"+x+"-"+y+"</TD>";
         }
         _html += "</TR>";
      }
      
      _html += "</TABLE>";
      _html += "</TD>";
      _html += "</TR>";
      _html += "</TABLE>";
      test.pasteHTML(_html);
  }
}


table_mode = false;
function table_editmode(mode)
  {
  if (mode==1 && table_mode==false)
     {
     change_tables();
     mainframe.document.attachEvent("onclick", check_click);
     table_mode = true;
  }
  if (mode==0 && table_mode==true)
     {
     tables_return();
     mainframe.document.detachEvent("onclick",check_click);  
     table_mode = false;
  }
}



function tables_return()
  {
  var oClass;
  var o_color;
  
  b=mainframe.document.body;
  f=b.getElementsByTagName('TD');
  if(f.length+''!='undefined')
	for(i=f.length-1;i>=0;i--)
       {
       o_color = f[i].getAttribute("oldcolor");
       oClass = f[i].className;

       f[i].clearAttributes();
       if (o_color)
           f[i].style.backgroundColor = color;
       if (oClass)
          f[i].className = oClass;
          
    }

  f=b.getElementsByTagName('TABLE');
  if(f.length+''!='undefined')
	for(i=f.length-1;i>=0;i--)
       {
       oBorder = f[i].getAttribute('oldborder');
       f[i].style.cursor = "";
       if (oBorder)
         {
         f[i].setAttribute("border",oBorder);
         f[i].removeAttribute('oldborder');
       }
    }
}

function change_tables()
  {
  b=mainframe.document.body;
  f=b.getElementsByTagName('TABLE');
  var oBorder;
  var oClass;
  var o_color;
  
  if(f.length+''!='undefined')
    {
	for(i=f.length-1;i>=0;i--)
       {
       oClass = f[i].className;
       if (oClass!='myTable' && oClass!='myTableOuter')
          {
           oBorder = f[i].getAttribute('border');
           if (oBorder)
              f[i].setAttribute("oldborder",oBorder);
              f[i].setAttribute("border",0);
  
          // Smotrim vse tegi v tekushej tablice

          tags = f[i].all;
          for(b=tags.length-1;b>=0;b--)
              {
               if (tags[b].tagName == "TD")
                {
//              tags[b].style.backgroundColor = "";
                oClass = tags[b].className;
                oAlignment = tags[b].align;
                oValignment = tags[b].vAlign;
                tags[b].clearAttributes();
//                tags[b].style.border = "1px solid red";
                if (oAlignment)
                    tags[b].align = oAlignment;
                if (oValignment)
                    tags[b].vAlign = oValignment;

                if (o_color)
                   tags[b].setAttribute("oldcolor",color);
                if (oClass)
                   tags[b].className = oClass;
             } // if
          } // for
       } // if 
    } // for 
  } //if
}


function check_click()
  {
  
}

