table+ "</tr>";
}
table+=" </table>";
insHTML(table)
}
}
function doWin(URL) {
ppw=wn.open(URL,'popWhizz','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=640,height=480,top=100');
ppw.focus();
}
function spellCheck(){
try {
var axo=new ActiveXObject("ieSpell.ieSpellExtension");
axo.CheckAllLinkedDocuments(document);
} catch(e) {
if(e.number==-2146827859) {
if(confirm("ieSpell is not installed on your computer. \n Click [OK] to go to download page."))
{wn.open("http://www.iespell.com/download.php","DownLoad")}
}else{
alert("Error Loading ieSpell: Exception " + e.number)
}
}
}
function getWinSize(){
var winW=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:document.body.clientWidth;
var winH=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:document.body.clientHeight;
return {w:winW,h:winH}
}
function fullscreen() { //Enable or disable fullscreen
var container=o("CONTAINER"+idTa);
if(!isFullscreen()) {
if(document.body.style.overflow){document.body.style.overflow="hidden";}else{document.documentElement.style.overflow="hidden";}
document.body.style.visibility="hidden";
container.style.visibility="visible"
container.style.position="absolute";
container.style.top=(window.pageYOffset?window.pageYOffset:document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop) + "px";
container.style.left="0";
container.style.width=getWinSize().w+"px";
container.style.height=getWinSize().h+"px";
o("whizzy"+idTa).style.backgroundColor="#fff";
o("whizzy"+idTa).style.height=getWinSize().h-o("CONTROLS"+idTa).offsetHeight+"px";
}
else {
if(document.body.style.overflow){document.body.style.overflow="visible";}else{document.documentElement.style.overflow="";}
document.body.style.visibility="visible";
container.style.position="relative";
container.style.top=o(idTa).style.top?o(idTa).style.top:"0px";
container.style.left=o(idTa).style.left?o(idTa).style.left:"0px";
container.style.width=taOrigSize[idTa].w;
container.style.height="auto";
o("whizzy"+idTa).style.backgroundColor="transparent";
o("whizzy"+idTa).style.height=taOrigSize[idTa].h;
}
}
function getDir() { //Detect current whizzywig directory
var base=location.href,e=document.getElementsByTagName('base'),i;
for(i=0;i<e.length;i++){
if(e[i].href){base = e[i].href}
}
e=document.getElementsByTagName('script');
for(i=0;i<e.length;i++) {
if(e[i].src && /(^|\/)whizzywig\.js([?#].*)?$/i.test(e[i].src)){
return e[i].src.replace(/whizzywig\.js/i.exec(e[i].src),'')
}
else if(e[i].src && /(^|\/)whizzywig[^\/].*?\.js([?#].*)?$/i.test(e[i].src)){
return e[i].src.replace(/whizzywig[^\/].*?\.js/i.exec(e[i].src), '')
}
}
return '';
}
function isFullscreen(){
if(o("CONTAINER"+idTa).style.width==getWinSize().w+"px"){return true}
return false
}
function hideDialogs() {
h('LINK_FORM'+idTa); h('IMAGE_FORM'+idTa); h('COLOR_FORM'+idTa); h('TABLE_FORM'+idTa); h('TABLE_CONTROLS'+idTa);
}
function showDesign(){
oW.document.body.innerHTML=tidyD(o(idTa).value);
h(idTa); h('showWYSIWYG'+idTa); s('CONTROLS'+idTa); s('whizzy'+idTa);
if(o("whizzy"+idTa).contentDocument){o("whizzy"+idTa).contentDocument.designMode="on"}
oW.focus()
}
function showHTML(){
o(idTa).value=tidyH(oW.document);
h('CONTROLS'+idTa); h('whizzy'+idTa); s(idTa); s('showWYSIWYG'+idTa);
if(isFullscreen()){
o(idTa).style.width=getWinSize().w+"px";
o(idTa).style.height=(getWinSize().h-o('showWYSIWYG'+idTa).offsetHeight)+"px";
o(idTa).style.borderWidth = "0px"
}else{
o(idTa).style.position="relative";
o(idTa).style.width=taOrigSize[idTa].w;
o(idTa).style.height=taOrigSize[idTa].h;
o(idTa).style.borderWidth="1px"
}
o(idTa).focus()
}
function syncTextarea(){//tidy up before we go-go
for (var i=0;i<whizzies.length;i++){
var t=whizzies[i];
var d=o("whizzy"+t).contentWindow.document;
if (o(t).style.display=='block'){d.body.innerHTML=o(t).value}
var ret=(o(t).nodeName!="TEXTAREA") ? o('wzhid_'+o(t).id) : o(t);
ret.value=tidyH(d)
}
}
function cleanUp(){xC("removeformat",null); tidyH(oW.document)}
function tidyD(h){//FF designmode likes <B>,<I>...
h=h.replace(/<(\/?)strong([^>]*)>/gi,"<$1B$2>").replace(/<(\/?)em>/gi,"<$1I>");
return h
}
function tidyH(d){//attempt valid xhtml
function lc(str){return str.toLowerCase()}
function qa(str){return str.replace(/(\s+\w+=)([^"][^>\s]*)/gi,'$1"$2"');}
function sa(str){return str.replace(/("|;)\s*[A-Z-]+\s*:/g,lc);}
var sz=['medium','xx-small','x-small','small','medium','large','x-large','xx-large'],
fs=d.getElementsByTagName("FONT"),i,ih;
for (i=0;i<fs.length;i++){
if (fs[i].face) {fs[i].style.fontFamily = fs[i].face; fs[i].removeAttribute('face')}
if (fs[i].size) {fs[i].style.fontSize = sz[fs[i].size]; fs[i].removeAttribute('size')}
if (fs[i].color) {fs[i].style.color = fs[i].color; fs[i].removeAttribute('color')}
}
ih=d.body.innerHTML;
ih=ih.replace(/(<\/?)FONT([^>]*)/gi,"$1span$2")
.replace(/(<\/?)[B](\s+[^>]*)?>/gi, "$1strong$2>")
.replace(/(<\/?)[I](\s+[^>]*)?>/gi, "$1em$2>")
.replace(/<\/?(COL|XML|ST1|SHAPE|V:|O:|F:|F |PATH|LOCK|IMAGEDATA|STROKE|FORMULAS)[^>]*>/gi, "")
.replace(/\bCLASS="?(MSOw*|Apple-style-span)"?/gi,"")
.replace(/<[^>]+=[^>]+>/g,qa) //quote all atts
.replace(/<(TABLE|TD|TH|COL)(.*)(WIDTH|HEIGHT)=["'0-9A-Z]*/gi, "<$1$2")//no fixed size tables (%OK) [^A-Za-z>]
.replace(/<([^>]+)>\s*<\/\1>/g, "")
.replace(/><(H|P|D|T|BLO|FOR|IN|SE|OP|UL|OL|LI|SC)/gi,">\n<$1")adjacent blocks
.replace(/(<BR ?\/?>)([^\r\n])/gi,"$1\n$2")
.replace(/([^\n])<(P|DIV|TAB|FOR)/gi,"$1\n\n<$2")
.replace(/([^\n])<\/(UL|OL|DL|DIV|TAB|FOR)/gi,"$1\n</$2")
.replace(/([^\n])(<\/TR)/gi,"$1\n $2") //end row
.replace(/\n<(BLO|LI|OP|TR|IN|DT)/gi,"\n <$1")
.replace(/\n<(TD|TH|DD)/gi,"\n <$1")
.replace(window.location.href+'#','#')
.replace(/<(IMG|INPUT|BR|HR|LINK|META)([^>]*)>/gi,"<$1$2 />")
.replace(/(<\/?[A-Z]*)/g,lc)
.replace(/STYLE="[^"]*"/gi,sa);
return ih
}
function kb_handler(e){
var cmd=false, prm=false,k;
if(e && (e.ctrlKey && e.keyCode==e.DOM_VK_V)||(e.shiftKey && e.keyCode==e.DOM_VK_INSERT))
{setTimeout('cleanUp()',10)}
else if(e && e.keyCode==13 && !e.shiftKey &&papa.nodeName=="BODY"){cmd="formatblock";prm="<p>"}
else if(e && e.ctrlKey){
k=String.fromCharCode(e.charCode).toLowerCase();
cmd=(k=='b')?'bold':(k=='i')?'italic':(k=='l')?'link':(k=='m')?'image':false;
}
if(cmd){
makeSo(cmd,prm);
e.preventDefault();
e.stopPropagation()
}
}
function doTag(html){
var url,close='',before,after;
if(!html){html=prompt("Enter some HTML or text to insert:", "")}
o(idTa).focus();
if(html=='<a>'){
url=prompt("Link address:","http://");
html='<a href="'+url+'">'
}
if(html=='<img>'){
url=prompt("Address of image:","http://");
var alt=prompt("Description of image");
html ='<img src="'+url+'" alt="'+alt+'">';
}
if(html.indexOf('<')===0 && html.indexOf('br') != 1 && html.indexOf('img') != 1)
{close=html.replace(/<([a-z0-6]+).*/,"<\/$1>")}
if(html != '<strong>' && html != '<em>'){close+='\n'}
if (document.selection){
sel=document.selection.createRange();
sel.text=html+sel.text+close
}else{
before=o(idTa).value.slice(0,o(idTa).selectionStart);
sel=o(idTa).value.slice(o(idTa).selectionStart,o(idTa).selectionEnd);
after=o(idTa).value.slice(o(idTa).selectionEnd);
o(idTa).value =before+html+sel+close+after
}
o(idTa).focus()
}
function insHTML(html){//insert HTML at current selection
if(!html){html=prompt(t("Enter some HTML or text to insert:"), "")}
if(html.indexOf('js:')===0){
try{eval(html.replace(/^js:/,''))} catch(e){}
return
}
whereAmI();
try {xC("inserthtml",html+sel)}
catch(e){if (document.selection) {
if(papa&&papa.nodeName=='IMG'){papa.outerHTML=html+papa.outerHTML;}
else if(rng){rng.select(); rng.pasteHTML(html+rng.htmlText)}
} }
}
function whereAmI(e){
if(!e){e=wn.event}
var mu=e&&e.type=='mouseup',pa,id;
if (msIE){
oW.document.getElementsByTagName("body")[0].focus();
sel=oW.document.selection;
rng=sel.createRange();
papa=mu?e.srcElement:(sel.type == "Control")?rng.item(0):rng.parentElement();
}else{
sel=oW.getSelection();sn=sel.anchorNode;
papa=mu?e.target:(sn.nodeName == '#text')?sn.parentNode:sn;
}
pa=papa;
trail=papa.nodeName;
while(!pa.nodeName.match(/^(HTML|BODY)/) && pa.className!="wzCtrl"){
pa=pa.parentNode;
trail=pa.nodeName+'>'+trail
}
if(pa.className=="wzCtrl"){trail=sel=rng=null}
id=pa.nodeName=="HTML" ? pa.getElementsByTagName("BODY")[0].id : pa.id.replace("CONTROL","");
c(id);
wn.status=id+":"+trail;
if(trail.indexOf('TABLE')>0){s('TABLE_CONTROLS'+idTa)}else{h('TABLE_CONTROLS'+idTa)}
}
function c(id){//set current whizzy
if(id==="" || whizzies.join().indexOf(id)=='-1'){return}
if (id!=idTa){
idTa=id;
try {oW=o("whizzy"+id).contentWindow;} catch(e){alert('set current: '+id)}
if(oW){if(oW.focus){oW.focus()}wn.status=oW.document.body.id}
}
}
function w(str,finalize){
if(!w.temp){w.temp=""}
w.temp+=str;
if(finalize){
o("CONTAINER"+idTa).innerHTML+=w.temp;
w.temp=""
}
}
function textSel(){if(sel && sel.type != "None" && sel.type != "Caret"){return true}else{alert(t("Select some text first")); return false}}
function s(id){o(id).style.display='block'}
function h(id){o(id).style.display='none'}
function o(id){return document.getElementById(id)}//get element by ID
function t(key){return (wn.language && language[key]) ? language[key] : key;}