<!-- hide from non JavaScript browsers 

/*              IEWedit                  -->
<!--       version 0.2_beta4             -->

<!-- scripted by Paul Trafford           -->
<!-- Oxford University Computing Services-->
<!-- paul.trafford@oucs.ox.ac.uk         -->
<!--                                     -->
<!-- a very simple DHTML inline editor   -->
<!-- based on an article in              -->
<!-- Inside Technique:                   -->
<!-- WYSIWYG HTML Editor                 -->
<!-- by Scott Isaacs                     -->
<!-- http://www.insidedhtml.com/tips/contents/ts12/page1.asp -->
<!-- which states that its code cannot   -->
<!-- be used on commercial sites without -->
<!-- explicit permission.                --> 
*/
 

 
// Call the formatting command in the editor
// For a complete list of allowable query commands consult MSDN site:
// http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/commandids.asp

  function doFormat(formlabel,fieldlabel,what) {
	
	docform=eval('document.'+formlabel+'.backup'+fieldlabel);
    preedit=eval('WinPre.'+formlabel);
	Edframe=eval('WinPre.frames.'+formlabel);
	docform.value= Edframe.document.body.innerHTML;
    var tr = Edframe.document.selection.createRange()
	if (arguments[3]==null)
	{
	 tr.execCommand(what)
	} 
	else
	{
	 tr.execCommand(what, false, arguments[3])
	}
    tr.select()
	copyValue(formlabel,fieldlabel)
    Edframe.focus()
  }
  
  function copyValue(formlabel,fieldlabel) {
    field=eval('document.'+formlabel+'.'+fieldlabel);
    form =eval('WinPre.'+formlabel); 
    field.value = "" + form.document.body.innerHTML + "";
  }

  
  function undo(formlabel,fieldlabel)
{
    form=eval('document.'+formlabel);
    field=eval('document.'+formlabel+'.'+fieldlabel);
    fieldbakstring = 'document.'+formlabel+'.backup'+fieldlabel;
	fieldbak=eval(fieldbakstring);
	field.value= fieldbak.value;

	framedoc=eval('WinPre.'+formlabel+'.document');
	frameform=eval('WinPre.frames.'+formlabel);
	framedoc.body.innerHTML=fieldbak.value;
	WinPre.focus()
}

  function preview(formlabel,fieldlabel){
  
// extract information

    formstring = 'document.'+formlabel;
	displaystring = 'the form label is'+formlabel;
    form = eval('document'+'\.'+formlabel);	
	field = eval(formstring+'\.'+fieldlabel);
	previewstatus = eval(formstring+'\.prev'+fieldlabel);
   
// check to see if there are any para graph tags.
// if not, for the first preview, insert line breaks

	 thetext=field.value;

if (previewstatus.value == '' &! (/\<[Pp]\>/.test(thetext))){

     thetext="<p>"+thetext;
	 
// insert line breaks (catering for different platforms)

     thetext = thetext.replace(/(\n\n)/g, "</p>$1<p>");
     thetext = thetext.replace(/(\r\n\r\n)/g, "</p>$1<p>");
     thetext = thetext+"</p>";
	 
     field.value=thetext;
     previewstatus.value='done';

	}

    contentstring=field.value;
	displaystring = 'the window label is '+fieldlabel;
	var WinPreName = fieldlabel;	

	WinPre = window.open('','FirstWin','scrollbars=yes,resizable=1,width=500,height=350');

	WinPre.document.writeln('<html><head><title>');
	WinPre.document.writeln('Preview Window ('+WinPreName+')');
	WinPre.document.writeln('</title>');

	WinPre.document.writeln('</head>');
    WinPre.document.writeln('<body>');
	WinPre.document.writeln('<FORM name=previewform ONSUBMIT=\"window.opener.copyValue(this); return false\">');
	WinPre.document.writeln('<INPUT onclick="window.opener.doFormat(\''+formlabel+'\',\''+fieldlabel+'\',\'FormatBlock\',\'<H2>\')" type=button value=" Heading ">'); 
    WinPre.document.writeln(' <INPUT onclick="window.opener.doFormat(\''+formlabel+'\',\''+fieldlabel+'\',\'FormatBlock\',\'<H3>\')" type=button value=" SubHead "> ');
    WinPre.document.writeln(' <INPUT onclick="window.opener.doFormat(\''+formlabel+'\',\''+fieldlabel+'\',\'Bold\')" type=button value=" B ">');
    WinPre.document.writeln(' <INPUT onclick="window.opener.doFormat(\''+formlabel+'\',\''+fieldlabel+'\',\'Italic\')" type=button value=" I  "> ');
    WinPre.document.writeln(' <INPUT onclick="window.opener.doFormat(\''+formlabel+'\',\''+fieldlabel+'\',\'Underline\')" type=button value=" U ">'); 
    WinPre.document.writeln(' <INPUT onclick="window.opener.doFormat(\''+formlabel+'\',\''+fieldlabel+'\',\'Createlink\')" type=button value=" Link ">'); 
    WinPre.document.writeln(' <INPUT onclick="window.opener.undo(\''+formlabel+'\',\''+fieldlabel+'\')" type=button value="Undo"> ');
    WinPre.document.writeln(' <INPUT TYPE="button" VALUE="Save" OnClick="window.opener.copyValue(\''+formlabel+'\',\''+fieldlabel+'\'); return false"><br>');
    WinPre.document.writeln(' <INPUT TYPE="button" VALUE="Close" OnClick="window.opener.copyValue(\''+formlabel+'\',\''+fieldlabel+'\');window.close()"><br>');
	WinPre.document.writeln('<IFRAME WIDTH=450 HEIGHT=250 ID=\''+formlabel+'\'></IFRAME><BR>');
    WinPre.document.writeln('</FORM>');
	WinPre.document.writeln('</body></html>');

	WinPre.document.close();
	WinPre.focus();

	myEd=eval('WinPre.frames.'+formlabel+'.document');
	myEd.designMode = "On";

// quick fix for unstable behaviour - sometimes myEd.body is not defined initially ..
        while (!myEd.body){}
 
	myEd.body.innerHTML+=contentstring;
  }

//-->

