  var test;
  
  function Init() 
  {
  	iView.document.designMode = 'On';
	iView.document.onkeyup = enablebtn;
  }

  function enablebtn() {
  	widgetHandler("enablesave");
  }

  function selOn(ctrl)
  {
	ctrl.style.borderColor = '#000000';
	ctrl.style.backgroundColor = '#B5BED6';
	ctrl.style.cursor = 'hand';
  }

  function selOff(ctrl)
  {
	ctrl.style.borderColor = '#D6D3CE';
	ctrl.style.backgroundColor = '#D6D3CE';
  }

  function selDown(ctrl)
  {
	ctrl.style.backgroundColor = '#8492B5';
  }

  function selUp(ctrl)
  {
    ctrl.style.backgroundColor = '#B5BED6';
  }

  function doCut()
  {
	iView.document.execCommand('cut', false, null);
  	widgetHandler("enablesave");
  }

  function doCopy()
  {
	iView.document.execCommand('copy', false, null);
  	widgetHandler("enablesave");
  }

  function doPaste()
  {
	iView.document.execCommand('paste', false, null);
  	widgetHandler("enablesave");
  }

  function doBold()
  {
	iView.document.execCommand('bold', false, null);
  	widgetHandler("enablesave");
  }

  function doItalic()
  {
	iView.document.execCommand('italic', false, null);
  	widgetHandler("enablesave");
  }

  function doUnderline()
  {
	iView.document.execCommand('underline', false, null);
  	widgetHandler("enablesave");
  }

  function doLeft()
  {
    	iView.document.execCommand('justifyleft', false, null);
  	widgetHandler("enablesave");
  }

  function doCenter()
  {
    	iView.document.execCommand('justifycenter', false, null);
  	widgetHandler("enablesave");
  }

  function doRight()
  {
    	iView.document.execCommand('justifyright', false, null);
  	widgetHandler("enablesave");
  }

  function doOrdList()
  {
    	iView.document.execCommand('insertorderedlist', false, null);
  	widgetHandler("enablesave");
  }

  function doOutdent()
  {
    	iView.document.execCommand('outdent', false, null);
  	widgetHandler("enablesave");
  }

  function doIndent()
  {
    	iView.document.execCommand('indent', false, null);
  	widgetHandler("enablesave");
  }

  function doBulList()
  {
    	iView.document.execCommand('insertunorderedlist', false, null);
  	widgetHandler("enablesave");
  }

  function doForeCol()
  {
    //var fCol = prompt('Enter foreground color', '');
	var fCol = showModalDialog("ColorSelect.html", "iView", "font-family:Verdana;font-size:12;dialogWidth:28em;dialogHeight:32em");

    if(fCol != null)
      iView.document.execCommand('forecolor', false, fCol);
  }

  function doBackCol()
  {
    //var bCol = prompt('Enter background color', '');
	var bCol = showModalDialog("ColorSelect.html", "", "font-family:Verdana;font-size:12;dialogWidth:28em;dialogHeight:32em");

    if(bCol != null)
      iView.document.execCommand('backcolor', false, bCol);
  }

  function doLink()
  {
  	iView.document.execCommand('createlink');
  	widgetHandler("enablesave");
  }

/*
  function doImage()
  {
    var imgSrc = prompt('Enter image location', '');

    if(imgSrc != null)
     iView.document.execCommand('insertimage', false, imgSrc);
  }
*/

  function doImage()
  {
    var numrows = prompt('Enter number of rows', '');

    if(numrows != null)
     buildtable(numrows);
     //iView.document.execCommand('insertimage', false, imgSrc);
  }


  function doTable()
  {
    var numrows = prompt('Enter number of rows', '');

    if(numrows != null)
     	buildtable(numrows);
  	widgetHandler("enablesave");
     //iView.document.execCommand('insertimage', false, imgSrc);
  }

  function buildtable(numrows, numcols, tborder) {
    var colwidth = parseInt(100 / numcols);
    //var coldim = "<TD WIDTH=" + colwidth + "%>";
    var mybody=iView.document.getElementsByTagName("body").item(0);
    mytable = iView.document.createElement("TABLE");
    mytable.setAttribute("border", tborder);
    mytable.setAttribute("cellpadding", 5);
    mytable.setAttribute("cellspacing", 1);
    mytablebody = iView.document.createElement("TBODY");
    for(j=0;j<numrows;j++) {
        mycurrent_row=iView.document.createElement("TR");
        
        for(i=0;i<numcols;i++) {
            //mycurrent_cell=iView.document.createElement(coldim);
            mycurrent_cell=iView.document.createElement("TD");
            currenttext=iView.document.createTextNode("cell is row "+j+", column "+i);
            //currenttext=iView.document.createTextNode("        ");
            mycurrent_cell.appendChild(currenttext);
            mycurrent_row.appendChild(mycurrent_cell);
        }
        mytablebody.appendChild(mycurrent_row);
    }
    mytable.appendChild(mytablebody);
    mybody.appendChild(mytable);
    //mytable.setAttribute("BORDER", tborder);

  }

  function doRule()
  {
    	//iView.document.body.innerHTML = "<P><A href='http://10.237.129.223/kaiser/pictures/139.jpg'></A>&nbsp;</P><P><IMG src='http://10.237.129.223/kaiser/pictures/139.jpg'></P>"
    	iView.document.execCommand('inserthorizontalrule', false, null);
  	widgetHandler("enablesave");
  }

  function doFont(fName)
  {
    if(fName != '')
      	iView.document.execCommand('fontname', false, fName);
  	widgetHandler("enablesave");
  }

  function doSize(fSize)
  {
    if(fSize != '')
      	iView.document.execCommand('fontsize', false, fSize);
  	widgetHandler("enablesave");
  }

  function doHead(hType)
  {
    if(hType != '')
    {
      iView.document.execCommand('formatblock', false, hType);
      doFont(selFont.options[selFont.selectedIndex].value);
    }
  }

  function doToggleView()
  {
    if(viewMode == 1)
    {
      iHTML = iView.document.body.innerHTML;
      iView.document.body.innerText = iHTML;

      // Hide all controls
      tblCtrls1.style.display = 'none';
      tblCtrls.style.display = 'none';
      selFont.style.display = 'none';
      selSize.style.display = 'none';
      selHeading.style.display = 'none';
      iView.focus();

      viewMode = 2; // Code
    }
    else
    {
      iText = iView.document.body.innerText;
      iView.document.body.innerHTML = iText;

      // Show all controls
      tblCtrls1.style.display = 'inline';
      tblCtrls.style.display = 'inline';
      selFont.style.display = 'inline';
      selSize.style.display = 'inline';
      selHeading.style.display = 'inline';
      iView.focus();

      viewMode = 1; // WYSIWYG
    }
  }

  function putdata() {
      iHTML = iView.document.body.innerHTML;
	  var tboxID = document.getElementById("tbox");
	  tboxID.value = iHTML;
  }

  function disableselect() {
    for(i = 0; i < document.all.length; i++){

	if (document.all(i).tagName == "!") {
		;
	} else if (document.all(i).tagName == "HTML") {
		;
	} else if (document.all(i).tagName == "HEAD") {
		;
	} else if (document.all(i).tagName == "TITLE") {
		;
	} else if (document.all(i).tagName == "META") {
		;
	} else if (document.all(i).tagName == "BASE") {
		;
	} else if (document.all(i).tagName == "DIV") {
		;
        } else {
          document.all(i).unselectable="on";
        }
    }
  }
  
  function parse(thing) { 
    var values = thing.split("; "); 
    var out = new Object; 
    for (i=0; i<values.length; i++) { 
	var keyv = values[i].split('='); 
        out[keyv[0]]=keyv[1]; 
    } 
    return out; 
  } 

  function combine(things) { 
    var out = ""; 
    for (i in things) { 
       if (out != '') out += '; '; 
       out += i + "=" + things[i]; 
    } 
    return out; 
  }
  
  function enableselect() {
    for(i = 0; i < document.all.length; i++){
       document.all(i).unselectable="off";
    }
  }


