if(oW.addEventListener){oW.addEventListener("keypress", kb_handler, true)}
else{d.body.attachEvent("onpaste",function(){setTimeout('cleanUp()',10)})}
addEvt(d,"mouseup", whereAmI); addEvt(d,"keyup", whereAmI); addEvt(d,"dblclick", doDbl);
taObject = o(idTa);
o("CONTAINER"+idTa).removeChild(o(idTa));
o("CONTAINER"+idTa).appendChild(taObject);
idTa=null;
}
function whizzywig(controls){
var i,ta=document.getElementsByTagName('TEXTAREA');
for (i=0;i<ta.length;i++){
if(!ta[i].id){ta[i].id=ta.name}
makeWhizzyWig(ta[i].id,controls);
}
}
function addEvt(o,e,f){if(wn.addEventListener){o.addEventListener(e, f, false)}else{o.attachEvent("on"+e,f)}}
function doDbl(){if(papa.nodeName == 'IMG'){doImage()}else{if(papa.nodeName=='A'){doLink()}}}
function makeButton(button){// assemble the button requested
var butHTML, ucBut=button.substring(0,1).toUpperCase();
ucBut += button.substring(1);
ucBut=t(ucBut.replace(/_/g,' '));
if(!document.frames && (button=="spellcheck")){return}
if(o(idTa).nodeName!="TEXTAREA" && button=="html"){return}
if(!buttonExt){buttonExt='.gif'}
if (buttonPath == "textbuttons"){butHTML='<button type=button onClick=makeSo("'+button+'")>'+ucBut+"</button>\n"}
else{butHTML='<button title="'+ucBut+'" type=button onClick=makeSo("'+button+'")>'+(btn[button]!=undefined?'<div style="width:'+btn._w+'px;height:'+btn._h+'px;background-image:url('+btn._f+');background-position:-'+btn[button]+'px 0px"></div>':'<img src="'+buttonPath+button+buttonExt+'" alt="'+ucBut+'" onError="this.parentNode.innerHTML=this.alt">')+'</button>\n'}
w(butHTML)
}
function fGo(id){return '<div id="'+id+'_FORM'+idTa+'" unselectable="on" style="display:none" onkeypress="if(event.keyCode==13) {return false;}"><hr>'+"\n"}//new form
function fNo(txt,go){//form do it/cancel buttons
return ' <input type="button" onclick="'+go+'" value="'+txt+'"> <input type="button" onclick="hideDialogs();" value='+t("Cancel")+"></div>\n";
}
function makeSelect(select){
var values,options,h,i;
if (select == 'formatblock'){
h="Heading";
values=["<p>", "<p>", "<h1>", "<h2>", "<h3>", "<h4>", "<h5>", "<h6>", "<address>", "<pre>"];
options=[t("Choose style")+":", t("Paragraph"), t(h)+" 1 ", t(h)+" 2 ", t(h)+" 3 ", t(h)+" 4 ", t(h)+" 5 ", t(h)+" 6", t("Address"), t("Fixed width<pre>")];
}else if (select == 'fontname') {
values=["Arial, Helvetica, sans-serif", "Arial, Helvetica, sans-serif","'Arial Black', Helvetica, sans-serif", "'Comic Sans MS' fantasy", "Courier New, Courier, monospace", "Georgia, serif", "Impact,sans-serif","'Times New Roman', Times, serif", "'Trebuchet MS',sans-serif", "Verdana, Arial, Helvetica, sans-serif"];
options=[t("Font")+":", "Arial","Arial Black", "Comic", "Courier", "Georgia", "Impact","Times New Roman", "Trebuchet","Verdana"]
}else if(select == 'fontsize'){
values=["3", "1", "2", "3", "4", "5", "6", "7"];
options=[t("Font size")+":", "1 "+t("Small"), "2", "3", "4", "5", "6", "7 "+t("Big")]
}else{
values=vals[select];
options=opts[select]
}
w('<select id="'+select+idTa+'" onchange="doSelect(this.id);">'+"\n");
for (i=0;i<values.length;i++){w(' <option value="' + values[i] + '">' + options[i] + "</option>\n")}
w("</select>\n")
}
function tagButs(){
w('<input type="button" onclick=\'doTag("<h1>")\' value="H1" title="<H1>"><input type="button" onclick=\'doTag("<h2>")\' value="H2" title="<H2>"><input type="button" onclick=\'doTag("<h3>")\' value="H3" title="<H3>"><input type="button" onclick=\'doTag("<h4>")\' value="H4" title="<H4>"><input type="button" onclick=\'doTag("<p>")\' value="P" title="<P>"><input type="button" onclick=\'doTag("<strong>")\' value="S" title="<STRONG>" style="font-weight:bold"><input type="button" onclick=\'doTag("<em>")\' value="E" title="<EM>" style="font-style:italic;"><input type="button" onclick=\'doTag("<li>")\' value="•—" title="<LI>"><input type="button" onclick=\'doTag("<a>")\' value="@" title="<A HREF= >"><input type="button" onclick=\'doTag("<img>")\' value="[♥]" title="<IMG SRC= >"><input type="button" onclick=\'doTag("<br />")\' value="←" title="<BR />">');
}
function xC(c,o){return oW.document.execCommand(c,false,o)}
function makeSo(cm,op){
hideDialogs();
oW.focus();
if(dobut[cm]) {insHTML(dobut[cm]); return;}
if (/Firefox/.test(navigator.userAgent)) {xC("styleWithCSS",cm=="hilite")}
if(cm=="justify"){cm="full"}
if("leftrightcenterfull".indexOf(cm)!=-1){cm="justify"+cm}
else if(cm=="number"){cm="insertorderedlist"}
else if(cm=="bullet"){cm="insertunorderedlist"}
else if (cm=="rule"){cm="inserthorizontalrule"}
switch(cm){
case "color":o('cf_cmd'+idTa).value="forecolor"; if(textSel()){s('COLOR_FORM'+idTa)} break;
case "hilite":o('cf_cmd'+idTa).value=cm; if(textSel()){s('COLOR_FORM'+idTa)} break;
case "image":doImage(); break;
case "link":doLink(); break;
case "html":showHTML(); break;
case "table":doTable(); break;
case "delete_row":doRow('delete','0'); break;
case "add_row_above":doRow('add','0'); break;
case "add_row_below":doRow('add','1'); break;
case "delete_column":doCol('delete','0'); break;
case "add_column_before":doCol('add','0'); break;
case "add_column_after":doCol('add','1'); break;
case "table_in_cell":hideDialogs(); s('TABLE_FORM'+idTa); break;
case "clean":cleanUp(); break;
case "spellcheck":spellCheck(); break;
case "fullscreen":fullscreen(); break;
default:xC(cm,op); break;
}
oW.focus();
}
function doSelect(selectname) {
var idx=o(selectname).selectedIndex;
var selected=o(selectname).options[idx].value;
o(selectname).selectedIndex=0;
selectname=selectname.replace(idTa,"");
if (" _formatblock_fontname_fontsize".indexOf('_'+selectname) > 0) {
var cmd=selectname;
oW.focus();
xC(cmd,selected);
} else {
insHTML(selected);
}
oW.focus();
}
function vC(colour){
if(!colour){colour=o('cf_color'+idTa).value}
o('cPrvw'+idTa).style.backgroundColor=colour;
o('cf_color'+idTa).value=colour
}
function sC(color) {
hideDialogs();
var cmd=o('cf_cmd'+idTa).value;
if(!color){color=o('cf_color'+idTa).value}
if(rng){rng.select();}
if(cmd=="hilite"){try{xC("hilitecolor",color)}catch(e){xC("backcolor",color)}}
else{xC(cmd,color)}
oW.focus();
}
function doLink(){
if(textSel()){
if(papa.nodeName=='A'){o("lf_url"+idTa).value=papa.href}
s('LINK_FORM'+idTa)
}
}
function insertLink(url) {
if (rng){rng.select()}
var a,i,mk='http://whizzy.wig/mark',
URL=url ? url : o("lf_url"+idTa).value;
if (URL.replace(/ /g,"")===""){xC('Unlink',null)}else{
xC('CreateLink',mk);
a=oW.document.body.getElementsByTagName("A");
for (i=0;i<a.length;i++){
if (a[i].href==mk){a[i].href=URL; if(o("lf_new"+idTa).checked){a[i].target="_blank"}break}
}
}
hideDialogs();
}
function doImage(){
if (papa && papa.nodeName == 'IMG'){
o("if_url"+idTa).value=papa.src;
o("if_alt"+idTa).value=papa.alt;
var position = papa.style.cssFloat?papa.style.cssFloat:papa.style.styleFloat;
o("if_side"+idTa).selectedIndex=(position=="left")?1:(position=="right")?2:0;
o("if_border"+idTa).value=papa.style.border?papa.style.border:papa.border>0?papa.border:0;
o("if_margin"+idTa).value=papa.style.margin?papa.style.margin:papa.hspace>0?papa.hspace:0;
}
s('IMAGE_FORM'+idTa);
}
function insertImage(URL, side, border, margin, alt) {
hideDialogs();
if(!URL){URL=o("if_url"+idTa).value}
if (URL) {
if (!alt){alt=o("if_alt"+idTa).value ? o("if_alt"+idTa).value: URL.replace(/.*\/(.+)\..*/,"$1")}
img='<img alt="' + alt + '" src="' + URL +'" ';
if(!side){side=o("if_side"+idTa).value}
if((side=="left") || (side=="right")){align='float:'+side+';'}else{align=''}
if(!border){border=o("if_border"+idTa).value}
if(border.match(/^\d+$/)){border+='px solid'}
if(!margin){margin=o("if_margin"+idTa).value}
if(margin.match(/^\d+$/)){margin+='px'}
if(border || margin){img+=' style="border:'+border+';margin:'+margin+';'+align+ '"'}
img+='/>';
insHTML(img)
}
}
function doTable(){ //show table controls if in a table, else make table
if(trail && trail.indexOf('TABLE') > 0){s('TABLE_CONTROLS'+idTa)}
else{s('TABLE_FORM'+idTa)}
}
function doRow(toDo,below) {
var pa=papa,tRow,tCols,newRow,newCell;
while(pa.tagName != "TR"){pa=pa.parentNode}
tRow=pa.rowIndex;
tCols=pa.cells.length;
while(pa.tagName != "TABLE"){pa=pa.parentNode}
if(toDo=="delete"){pa.deleteRow(tRow)}
else{
newRow=pa.insertRow(tRow+parseInt(below,10));//1=below 0=above
for(i=0;i<tCols;i++){
newCell=newRow.insertCell(i);
newCell.innerHTML="#";
}
}
}
function doCol(toDo,after) {//insert or delete a column
var pa=papa,tCol,tRows,i,newCell;
while(pa.tagName != 'TD'){pa=pa.parentNode}
tCol=pa.cellIndex;
while(pa.tagName != "TABLE"){pa=pa.parentNode}
tRows=pa.rows.length;
for(i=0;i<tRows;i++){
if(toDo=="delete"){pa.rows[i].deleteCell(tCol)}
else{
newCell=pa.rows[i].insertCell(tCol+parseInt(after,10));//if after=0 then before
newCell.innerHTML="#";
}
}
}
function makeTable() {
hideDialogs();
var rows=o('tf_rows'+idTa).value, cols=o('tf_cols'+idTa).value, border=o('tf_border'+idTa).value, head=o('tf_head'+idTa).value, table,i,j;
if ((rows>0)&&(cols>0)){
table='<table border="'+border+'">';
for (i=1;i<=rows;i++){
table=table+"<tr>";
for (j=1;j<=cols;j++){
if (i==1){
if(head=="1"){table += "<th>Title"+j+"</th>"}//Title1 Title2 etc.
else{table+="<td>"+j+"</td>"}
}
else if(j==1){table+="<td>"+i+"</td>"}
else{table += "<td>#</td>"}
}