//************************************************
var lastSelection = null;
function select(element) {
  var e, r, c;
  if (element == null) {
    e = window.event.srcElement;
  } else {
    e = element;
  }
  if ((window.event.altKey) || (e.tagName == "TR")) {
    r = findRow(e);
    if (r != null) {
      if (lastSelection != null) {
        deselectRowOrCell(lastSelection);
      }
      selectRowOrCell(r);
      lastSelection = r;
    }
  } else {
    c = findCell(e);
    if (c != null) {
      if (lastSelection != null) {
        deselectRowOrCell(lastSelection);
      }
      selectRowOrCell(c);
      lastSelection = c;
    }
  }

  window.event.cancelBubble = true;
} 

if(document.getElementById){ //marek
	document.getElementById('oSource').onclick = select;
	document.getElementById('oDiv').onclick = select;
}else{
	oSource.onclick = select;
	oDiv.onclick = select;
}

function cancelSelect() {

  if (window.event.srcElement.tagName != "BODY") 
    return;

  if (lastSelection != null) {
    deselectRowOrCell(lastSelection);
    lastSelection = null;
  }
}

document.onclick = cancelSelect;

function findRow(e) {
  if (e.tagName == "TR") {
    return e;
  } else if (e.tagName == "BODY") {
    return null;
  } else {
    return findRow(e.parentElement);
  }
}

function findCell(e) {
  if (e.tagName == "TD") {
    return e;
  } else if (e.tagName == "BODY") {
    return null;
  } else {
    return findCell(e.parentElement);
  }
}

function deselectRowOrCell(r) {
  r.runtimeStyle.backgroundColor = "";
  r.runtimeStyle.color = "";
  //r.runtimeStyle.fontFamily = "Verdana";
}

function selectRowOrCell(r) {
 // r.runtimeStyle.backgroundColor = "darkblue";
 // r.runtimeStyle.color = "white";
  //r.runtimeStyle.fontFamily = "Verdana";
}

function addRow() {
  var r, p, nr;
  if (lastSelection == null) {
    r = null;
    p = TheTable.children[0];
  } else {
    r = lastSelection;

    if (r.tagName == "TD") {
      r = r.parentElement;
    }

    p = r.parentElement;
  }

  nr = document.createElement("TR");

  p.insertBefore(nr, r);

  select(nr);

  addCell();

  return nr;    
}

function removeRow() {
  var r, p, nr;
  if (lastSelection == null)
    return false;

  r = lastSelection;

  if (r.tagName == "TD") {
    r = r.parentElement;
  }

  p = r.parentElement;

  p.removeChild(r);

  lastSelection = null;
 
  return r; 
}

function addCell() {
  var r, p, c, nc, text;
  if (lastSelection == null)
    return false;

  r = lastSelection;

  if (r.tagName == "TD") {
    r = r.parentElement;
    c = lastSelection;
  } else {
    c = null;
  }

  nc = document.createElement("TD");
  text = document.createTextNode("");

  nc.insertBefore(text, null);
  r.insertBefore(nc, c);

  select(nc);

  return nc;
}

function removeCell() {
  var c, p, nr;
  if (lastSelection == null)
    return false;

  c = lastSelection;

  if (c.tagName != "TD") {
    return null;
  }

  p = c.parentElement;

  p.removeChild(c);

  lastSelection = null;
 
  return c; 
}

function editContents() {
  var c, p, nr;
  if (lastSelection == null)
    return false;

  c = lastSelection;

  if (c.tagName != "TD") {
    return null;
  }

  EditCell.style.display = "";

  EditCell.value = c.innerHTML;

  c.setExpression("innerHTML", "EditCell.value");

  EditCell.focus();

  EditCell.onblur = unhookContentsExpression;
}

function unhookContentsExpression() {
  lastSelection.removeExpression("innerHTML");
  EditCell.value = '';
  EditCell.style.display = "none";
}

function editStyle() {
  var c;

  if (lastSelection == null) {
    c = TheTable;
  } else {
    c = lastSelection;
  }
  
  EditStyle.style.display = "";

  EditStyle.value = c.style.cssText;

  c.style.setExpression("cssText", "EditStyle.value");

  EditStyle.focus();

  EditStyle.onblur = unhookStyleExpression;
}

function unhookStyleExpression() {
  var c;

  if (lastSelection == null) {
    c = TheTable;
  } else {
    c = lastSelection;
  }
  c.style.removeExpression("cssText");

  EditStyle.value = '';
  EditStyle.style.display = "none";
}

function moveUp() {
  var r, p, ls;
  if (lastSelection == null)
    return false;

  r = lastSelection;

  if (r.tagName != "TR") {
    return null;
  }

  if (r.rowIndex == 0) 
    return;

  ls = r.previousSibling;

  p = ls.parentElement;

  p.insertBefore(r, ls);

  return r;
}

function moveDown() {
  var r, p, ls;
  if (lastSelection == null)
    return false;

  r = lastSelection;

  if (r.tagName != "TR") {
    return null;
  }

  ls = r.nextSibling;

  if (ls == null)
    return null;

  p = ls.parentElement;

  ls = ls.nextSibling;

  p.insertBefore(r, ls);

  return r;
}

function moveLeft() {
  var c, p, ls;
  if (lastSelection == null)
    return false;

  c = lastSelection;

  if (c.tagName != "TD") {
    return null;
  }

  ls = c.previousSibling;

  if (ls == null)
    return null;

  p = ls.parentElement;

  p.insertBefore(c, ls);

  return c;
}

function moveRight() {
  var c, p, ls;
  if (lastSelection == null)
    return false;

  c = lastSelection;

  if (c.tagName != "TD") {
    return null;
  }

  ls = c.nextSibling;

  if (ls == null)
    return null;

  p = ls.parentElement;

  ls = ls.nextSibling;

  p.insertBefore(c, ls);

  return c;
}

function nothingSelected() {
  return (lastSelection == null);
}

function rowSelected() {
  var c;
  if (lastSelection == null)
    return false;

  c = lastSelection;

  return (c.tagName == "TR")
}

function cellSelected() {
  var c;
  if (lastSelection == null)
    return false;

  c = lastSelection;

  return (c.tagName == "TD")
}

function whatIsSelected() {
  if (lastSelection == null) 
    return "Table";
  if (lastSelection.tagName == "TD") 
    return "Cell";
  if (lastSelection.tagName == "TR")
    return "Row";
}


//********************************************************************






function fnInit(){                                        
    for (i=0; i<document.all.length; i++)
            document.all(i).unselectable = "on";                                  
    oDiv.unselectable = "off";
    oTextarea.unselectable = "off";
}
function fnToggleEdits(oObj,oBtn) {
    currentState = oObj.isContentEditable;
    newState = !currentState;
    oObj.contentEditable = newState;
    
    newState==false ? oBtn.innerHTML='Turn Editing On' :
        oBtn.innerHTML='Turn Editing Off';
}

var sSource="";
window.onload=fnInit;


function fnInit(){
	if(document.getElementById){ //marek
		sSource=document.getElementById('oSource').innerHTML;
	}else{	
		sSource=oSource.innerHTML;
	}
//	tbContentElement.focus();
//	var asd = new QueryStatusItem(DECMD_INSERTTABLE, document.body.all["DECMD_INSERTTABLE"]);
}

function fnView(){
	alert("outerHTML: " + oSource.children[0].outerHTML + "\n\nonclick: " + oSource.children[0].onclick + "\n\nID: " + oSource.children[0].id);	
}
function fnClear(){
	oSource.children[0].clearAttributes();
	fnView();
}
function fnReset(){
	oSource.innerHTML="";
	oSource.innerHTML=sSource;
//	fnView();
}
var sInitColor = null;


/*
if (sInitColor == null) 
		//display color dialog box
		var sColor = dlgHelper.ChooseColorDlg();
	else
		var sColor = dlgHelper.ChooseColorDlg(sInitColor);
		//change decimal to hex
		sColor = sColor.toString(16);
		//add extra zeroes if hex number is less than 6 digits
	if (sColor.length < 6) {
		var sTempString = "000000".substring(0,6-sColor.length);
		sColor = sTempString.concat(sColor);
	}
*/


function callColorDlg(sColorType){
	var arr = null;
	 var args = new Array();
	 arr = showModalDialog( "./edit/inscolor.htm",
                             args,
                             "font-family:Verdana; font-size:12; dialogWidth:30em; dialogHeight:30em");
	if(arr != null)
		document.execCommand(sColorType, false, arr["v2rv"]);
}

function fnRandom(iModifier){
   return parseInt(Math.random()*iModifier);
}
function fnSetValues(){
   var iHeight=fnRandom(document.body.clientHeight);
   var sFeatures="dialogHeight: " + iHeight + "px;";
   return sFeatures;
}

function makew_mail(v) {
	var arr;
	var args = new Array();
	arr = null;
	var sel = document.selection.createRange();
	if(document.selection.type=='Control'){
		alert('Valige pilt ơieti !');
	}else{
		str = sel.text;
		var tag;
		tag = sel.parentElement();
		if(sel.parentElement().target){
			args["target"] = "_blank";
		}else{
			args["target"] = "asd";
		}
		if(sel.parentElement().protocol){
			args["prot"] = sel.parentElement().protocol;
		}else{
			args["prot"] = "http://";
		}
		if(sel.parentElement().href && str!=""){
			args["href"] = sel.parentElement().href;
		}else{
			args["href"] = "http://";
		}
		
		
		
		if(str=="")
			str = sel.htmlText;
		arr = showModalDialog( "./edit/insurl.htm?<?=RAND(1,1000)?>",
							 args,
							 "font-family:Verdana; font-size:12; dialogWidth:30em; dialogHeight:15em");
		if(arr != null){
			alert(sel.parentElement().parent());
			if(tag=="A"){	
				sel.parentElement().href = arr["link"];
				sel.parentElement().target = arr["aken"];
			}else{
				str = "<a href=\"" + arr["link"] + "\" "+arr["aken"]+">" + str + "</a>";
				sel.pasteHTML(str);
			}
		}
	}
	  return;
}

function asd(x){
if (oDiv.isContentEditable==true)document.execCommand(x);
}
function showDetails() {
	//document.style.lineBreak[=sBreak]; 
}

var gsEDIT_DOCUMENT;
function PTRprnttg(p,tgn){
		while( p!=null && p.tagName != tgn ){
			p=(p.parentElement)?p.parentElement:null;
		}
		return p;
	};

function disable_div(nr){
//	document.all.main_div.style.display = "inline-block"; 
}

function koodvaade(){
	if(document.all.html.value=="Koodvaade"){
		document.all.html.value = "Tavavaade";
		document.all.oDiv.style.display = 'none';
		document.all.kala.style.display = 'block';
		document.all.kala.value=oDiv.innerHTML;
		if(document.all.kkk.value==1){
			document.all.sisu.style.display = 'none';
			document.all.kala2.style.display = 'block';
			document.all.kala2.value=sisu.innerHTML;
		}
		document.all.kala.focus();
		disable_div(1);
	}else{
		document.all.html.value = "Koodvaade";
		document.all.oDiv.style.display = 'block';
		document.all.kala.style.display = 'none';
		oDiv.innerHTML= document.all.kala.value;
		if(document.all.kkk.value==1){
			document.all.sisu.style.display = 'block';
			document.all.kala2.style.display = 'none';
			sisu.innerHTML=document.all.kala2.value;
		}
		document.all.oDiv.focus();
		disable_div(0);
	}
	set_odiv_expr();
	set_img_expr();
}

function eelvaade(){
		var pealkiri;
		if(!document.editMessageForm.alam_pealkiri)
			pealkiri = document.editMessageForm.nimi.value;
		else
			pealkiri = document.editMessageForm.alam_pealkiri.value;
		pop=window.open("","","toolbar=no,location=no,left=10,top=10,directories=no,status=No,menubar=yes,scrollbars=yes,resizable=yes,width=600,height=400");      
		pop.document.write("<html><head><title>Eelvaade</title><link rel='stylesheet' type='text/css' href='client/art/lahendused.css'></head><body body bgcolor=#FFFFFF topmargin=15 leftmargin=10><table width=98%><tr><td><p class=header>"+pealkiri+"</p>"+document.all.oDiv.innerHTML+"</td></tr></table></body></html>");
	}

function make_mail(admin_menu_id,menu_id,news_id,lng,action,query,form,ss,b){
	var vIn     = new Object();
	var vOut    = null;
	var oParent = null;

	vIn['present'] = document.queryCommandEnabled('createlink');
	// alert(vIn['present']);
	if (!vIn['present']) return -1;
	var REQUIRELINKERACTION = false;
	var oSel = document.selection;
	var sType=oSel.type;
	vIn['present'] = document.queryCommandEnabled('Unlink');
	if(vIn['present']){
		if(sType=='Text' || sType=='None'){
			oParent = PTRprnttg(oSel.createRange().parentElement(),'A');
		}  else {
			// f'it commonParentElement...
			oParent = PTRprnttg(oSel.createRange().item(0),'A');
		};
	}else {
	};
	if (oParent && oParent.href){
		vIn['tref']     = oParent;
	}else{
	};
	// vOut = showModalDialog( /*'../../+'*/ './edit/insurl.php?popup=lhaldur&a_menu_id='+admin_menu_id+'&menu_id='+menu_id+'&news_id='+news_id+'&lng='+lng+'&action='+action+'&query='+query+'&form='+form+'&ss='+ss,vIn,'font-family:Verdana;font-size:12px;dialogWidth:564px;dialogHeight:564px;status:no;help:no;scroll:no;');
	vOut = showModalDialog( /*'../../+'*/ './edit/insurl.php?popup=lhaldur&a_menu_id='+admin_menu_id+'&menu_id='+menu_id+'&news_id='+news_id+'&lng='+lng+'&action='+action+'&query='+query+'&form='+form+'&ss='+ss,vIn,'font-family:Verdana;font-size:12px;dialogWidth:800px;dialogHeight:700px;status:no;help:no;scroll:no;');
	if (vOut != null){
		if (vIn['present']	){
			if (	typeof vOut=='string' && vOut=='MMCMDMSG_performunlink'){
					document.execCommand('Unlink');
					return;
			}else{  // user changed link props
				if(oParent != null ){
					oParent.setAttribute('href',vOut['url']);
					if(vOut['target'])oParent.setAttribute('target',vOut['target']);
				}
				else{
					REQUIRELINKERACTION = true;
				};
			};
		};
		if (!vIn['present'] || REQUIRELINKERACTION ){
			// two params are mutually exlcusive
			if (REQUIRELINKERACTION) document.execCommand('Unlink');
			document.execCommand('createlink',false,vOut['url']);
			oSel = document.selection;
			sType=oSel.type;
			vIn['present'] = document.queryCommandEnabled('Unlink');
			if(vIn['present']){
				if(sType=='Text' || sType=='None'){
					oParent = PTRprnttg(oSel.createRange().parentElement(),'A');
				}  else {
					oParent = PTRprnttg(oSel.createRange().item(0),'A');
				};
				if(vOut['target'])oParent.setAttribute('target',vOut['target']);
			}else {
			};
		};
	};
};


function forecolor(){
	var vIn     = new Object();
	var vOut    = null;
	vIn['present'] = document.queryCommandEnabled("backcolor");
	if (!vIn['present']) return -1;
	vOut = showModalDialog( './edit/inscolor.htm','','font-family:Verdana;font-size:12px;dialogWidth:630px;dialogHeight:270px;status:no;help:no;');
	if(vOut){
		document.execCommand('forecolor',0, vOut);
	};
};


	// set font background color GUI call
function backcolor(){
	var vIn     = new Object();
	var vOut    = null;
	vIn['present'] = document.queryCommandEnabled("backcolor");
	// alert(vIn['present']);
	if (!vIn['present']) return -1;
	vOut = showModalDialog( './edit/inscolor.htm','','font-family:Verdana;font-size:12px;dialogWidth:630px;dialogHeight:270px;status:no;help:no;');
	if(vOut){
			document.execCommand('backcolor',0, vOut);
	};
};






//************* UUS TABELI PORNO***********************


 function set_odiv_expr(){
	var tables_length,tables,cells;
	if(document.getElementById){ //marek
		tables = document.getElementById('oDiv').getElementsByTagName("TABLE");
	}else{	
		tables = document.all.oDiv.all.tags("TABLE");
	}

	tables_length = tables.length;
	for(var i=0;i<tables_length;i++){
		if(tables[i-1] && !tables[i-1].contains(tables[i])){
			tables[i].ondblclick = celledit;
		}else if(!tables[i-1]){
			tables[i].ondblclick = celledit;
		}
		tables[i].ondragend = set_odiv_expr;
	}

	if(document.getElementById){ //marek
		tables = document.getElementById('sisu').getElementsByTagName("TABLE");
	}else{	
		tables = document.all.sisu.all.tags("TABLE");
	}

	tables_length = tables.length;
	for(var i=0;i<tables_length;i++){
		if(tables[i-1] && !tables[i-1].contains(tables[i])){
			tables[i].ondblclick = celledit;
		}else if(!tables[i-1]){
			tables[i].ondblclick = celledit;
		}
		tables[i].ondragend = set_odiv_expr;
	}
}
function celledit(){
	var oNode=event.srcElement;
	if(oNode.tagName == 'TD'){
		table_cell_prop_click(oNode);
	}
	if(oNode.tagName == 'TABLE'){
		Table_properties(oNode);
	}
}

set_odiv_expr();

 function InsertTable(){
	  var nt = showModalDialog('./edit/instable.htm', null, 
			'dialogHeight:250px; dialogWidth:366px; resizable:no; status:no');  
		   
	  if (nt)
	  {
		oDiv.focus();
	
		var newtable = document.createElement('TABLE');
		try {
		  newtable.width = (nt.width)?nt.width:'';
		  newtable.height = (nt.height)?nt.height:'';
		  newtable.border = (nt.border)?nt.border:'';
		  if (nt.cellPadding) newtable.cellPadding = nt.cellPadding;
		  if (nt.cellSpacing) newtable.cellSpacing = nt.cellSpacing;
		  newtable.bgColor = (nt.bgColor)?nt.bgColor:'';
		  
		  // create rows
		  for (i=0;i<parseInt(nt.rows);i++)
		  {
			var newrow = document.createElement('TR');
			for (j=0; j<parseInt(nt.cols); j++)
			{
			  var newcell = document.createElement('TD');
			  newrow.appendChild(newcell);
			}
			newtable.appendChild(newrow);
		  }

		  
		   var oSel;
			 oSel = document.selection.createRange();
			 if(document.selection.type!='None'){
				oSel.collapse(false);
				oSel.pasteHTML(newtable.outerHTML);
			 }else{
				document.all.oDiv.insertAdjacentHTML("afterBegin",newtable.outerHTML)
			 }
		}
		catch (excp)
		{
		  alert('error');
		}
	  }
	  set_odiv_expr();
 }
 function Table_properties(table)
  {
	  var tTable;
	  var tControl = document.selection.createRange();
      if (!table && document.selection.type=="Control" && tControl(0).tagName == 'TABLE')
      {
        tTable = tControl(0);
      }
	  if(table)tTable = table;
	 if(tTable){
			var tProps = {};
			tProps.width = (tTable.style.width)?tTable.style.width:tTable.width;
			tProps.height = (tTable.style.height)?tTable.style.height:tTable.height;
			tProps.border = tTable.border;
			tProps.cellPadding = tTable.cellPadding;
			tProps.cellSpacing = tTable.cellSpacing;
			tProps.bgColor = tTable.bgColor;
			
			var ntProps = showModalDialog('./edit/instable.htm', tProps, 
			  'dialogHeight:250px; dialogWidth:366px; resizable:no; status:no');  
			
			if (ntProps)
			{
			  // set new settings
			  tTable.width = (ntProps.width)?ntProps.width:'';
			  tTable.style.width = (ntProps.width)?ntProps.width:'';
			  tTable.height = (ntProps.height)?ntProps.height:'';
			  tTable.style.height = (ntProps.height)?ntProps.height:'';
			  tTable.border = (ntProps.border)?ntProps.border:'';
			  if (ntProps.cellPadding) tTable.cellPadding = ntProps.cellPadding;
			  if (ntProps.cellSpacing) tTable.cellSpacing = ntProps.cellSpacing;
			  tTable.bgColor = (ntProps.bgColor)?ntProps.bgColor:'';
			}
	 }

 }


 function table_cell_prop_click(cell)
  {
    var cd = cell; // current cell
   
    if (cd)
    {
      var cProps = {};
      cProps.width = (cd.style.width)?cd.style.width:cd.width;
      cProps.height = (cd.style.height)?cd.style.height:cd.height;
      cProps.bgColor = cd.bgColor;
      cProps.align = cd.align;
      cProps.vAlign = cd.vAlign;
      cProps.className = cd.className;
      cProps.noWrap = cd.noWrap;
      cProps.styleOptions = cd.className;
      var ncProps = showModalDialog('./edit/td.html', cProps, 
        'dialogHeight:220px; dialogWidth:366px; resizable:no; status:no');  
      
      if (ncProps)  
      {
        cd.align = (ncProps.align)?ncProps.align:'';
        cd.vAlign = (ncProps.vAlign)?ncProps.vAlign:'';
        cd.width = (ncProps.width)?ncProps.width:'';
        cd.style.width = (ncProps.width)?ncProps.width:'';
        cd.height = (ncProps.height)?ncProps.height:'';
        cd.style.height = (ncProps.height)?ncProps.height:'';
        cd.bgColor = (ncProps.bgColor)?ncProps.bgColor:'';
        cd.className = (ncProps.className)?ncProps.className:'';
        cd.noWrap = ncProps.noWrap;
      }      
    }
    //SPAW_updateField(editor,"");
  }


  //********************IMAGE V2RK

function set_img_expr(){
	var tables_length,tables,cells;

	if(document.getElementById){ //marek
		tables = document.getElementById('oDiv').getElementsByTagName("IMG");
	}else{	
		tables = document.all.oDiv.all.tags("IMG");
	}

	tables_length = tables.length;
	for(var i=0;i<tables_length;i++){
		tables[i].ondblclick = img_edit;
		tables[i].ondragend = set_img_expr;
	}

	if(document.getElementById){ //marek
		tables = document.getElementById('sisu').getElementsByTagName("IMG");
	}else{	
		tables = document.all.sisu.all.tags("IMG");
	}

	tables_length = tables.length;
	for(var i=0;i<tables_length;i++){
		tables[i].ondblclick = img_edit;
		tables[i].ondragend = set_img_expr;
	}
}
set_img_expr()
function img_edit(){
	var oNode=event.srcElement;
	if(oNode.tagName == 'IMG'){
		real_img_edit(oNode);
	}
}

function insert_pilt(nr,properties){
 var oSel,prop;
 prop = "";
 oSel = document.selection.createRange();
 	if(properties['alt']!='')
		prop = " alt='"+properties['alt']+"' ";
	if(properties['align']!='')
		prop+= " align='"+properties['align']+"' ";
	if(properties['border']!='')
		prop+= " border='"+properties['border']+"' ";
	if(properties['width']!='')
		prop+= " width='"+properties['width']+"' ";
	if(properties['height']!='')
		prop+= " height='"+properties['height']+"' ";
	if(properties['hspacet']!='')
		prop+= " hspace='"+properties['hspace']+"' ";
	if(properties['vspace']!='')
		prop+= " vspace='"+properties['vspace']+"' ";


 if(document.selection.type!='None'){
	oSel.collapse(false);
	oSel.pasteHTML("<IMG src='http://www.etv.ee/failid/"+nr+"' "+prop+">");
 }else{
	document.all.oDiv.insertAdjacentHTML("afterBegin","<IMG src='http://www.etv.ee/failid/"+nr+"'  "+prop+">")
 }
 set_img_expr();

}

function real_img_edit(img)
{
	var im = img; // current image

	if (im)
	{
	  var iProps = {};
	  iProps.src = im.src;
	  iProps.alt = im.alt;
	  iProps.width = (im.style.width)?im.style.width:im.width;
	  iProps.height = (im.style.height)?im.style.height:im.height;
	  iProps.border = im.border;
	  iProps.align = im.align;
	  iProps.hspace = im.hspace;
	  iProps.vspace = im.vspace;

	  var niProps = showModalDialog('./edit/image.html', iProps, 
		'dialogHeight:200px; dialogWidth:366px; resizable:no; status:no');  
	  
	  if (niProps)  
	  {
		im.src = (niProps.src)?niProps.src:'';
		if (niProps.alt) {
		  im.alt = niProps.alt;
		}
		else
		{
		  im.removeAttribute("alt");
		}
		im.align = (niProps.align)?niProps.align:'';
		im.width = (niProps.width)?niProps.width:'';
		//im.style.width = (niProps.width)?niProps.width:'';
		im.height = (niProps.height)?niProps.height:'';
		//im.style.height = (niProps.height)?niProps.height:'';
		if (niProps.border) {
		  im.border = niProps.border;
		}
		else
		{
		  im.removeAttribute("border");
		}
		if (niProps.hspace) {
		  im.hspace = niProps.hspace;
		}
		else
		{
		  im.removeAttribute("hspace");
		}
		if (niProps.vspace) {
		  im.vspace = niProps.vspace;
		}
		else
		{
		  im.removeAttribute("vspace");
		}
	  }      
	  //SPAW_updateField(editor,"");
	} // if im
	set_img_expr();
}