function poem_setDefaultVar(){poemDefaultFont="simplified arabic,tahoma,ms sans serif,verdana,arial,helvetica";poemType="0",poemAlign="center",poemLine="0";poemUse="ex";poemFontName="",poemFontSize="4",poemFontColor="",poemFontBold="",poemFontItalic="";poemBackColor="none",poemBackImage="none";poemBorderStyle="none",poemBorderWidth="4",poemBorderColor="gray";poemSerialNum="0",poemSerialNumColor=""}var poemSpaceWidth,poemExtendWidth;var poemToolFix,poemPrevHTML,poemMargin,poemPadding;var poemLetters1="ÇÃÅÂÄÁÏÐÑÒæÉì";var poemLetters2="ÇÃÅÂÄÆÈÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÝÞßáãäåæíÉì";var poemLetters3="ðñòóõöøú";if(typeof HTMLElement!="undefined"&&!HTMLElement.prototype.insertAdjacentElement){HTMLElement.prototype.insertAdjacentElement=function(a,b){switch(a){case"beforeBegin":this.parentNode.insertBefore(b,this);break;case"afterBegin":this.insertBefore(b,this.firstChild);break;case"beforeEnd":this.appendChild(b);break;case"afterEnd":if(this.nextSibling){this.parentNode.insertBefore(b,this.nextSibling)}else{this.parentNode.appendChild(b)}break}};HTMLElement.prototype.insertAdjacentHTML=function(b,d){var c=this.ownerDocument.createRange();c.setStartBefore(this);var a=c.createContextualFragment(d);this.insertAdjacentElement(b,a)};HTMLElement.prototype.insertAdjacentText=function(b,c){var a=document.createTextNode(c);this.insertAdjacentElement(b,a)}}function create_poemTestWidth_table(){if(!document.getElementById("poemtestWidth")){var a="<table border=1 width=1px style='visibility:hidden;position:absolute'>";a+="<tr><td id='poemTestWidth' width='0px' nowrap></td></tr>";a+="</table>";document.body.insertAdjacentHTML("afterBegin",a)}}function poem_getValue(c,e){var d=new RegExp('([ "]|^)'+c+'[ ]*=[ ]*"[^"]*"',"i");var a=e.match(d);if(!a){d=new RegExp('([ "]|^)'+c+'[ ]*=[ ]*[^" ]*([ ]|$)',"i");a=e.match(d);if(!a){return""}}a=a[0];a=a.replace(/\"/gi,"");var b=a.search("=");return a.substring(b+1).replace(/[\(\)\&\[\]\;]/g,"")}function poem_getDefault(b,c){var a=((b)?b:c);return poem_trim(a)}function poem_setArg(a){var c,d;c=poem_getValue("font",a)+",,,,";c=c.split(",");poemFontName=poem_getDefault(c[0],poemFontName);poemFontName=poemFontName.replace(/\-/g,",");d=parseInt(poem_getDefault(c[1],poemFontSize));if(isNaN(d)){d=0}if(d<1||d>7){d=poemFontSize}poemFontSize=d;poemFontColor=poem_getDefault(c[2],poemFontColor);poemFontBold=poem_getDefault(c[3],poemFontBold);poemFontItalic=poem_getDefault(c[4],poemFontItalic);c=poem_getValue("border",a)+",,";c=c.split(",");poemBorderStyle=poem_getDefault(c[0],poemBorderStyle);poemBorderWidth=poem_getDefault(c[1],poemBorderWidth);poemBorderColor=poem_getDefault(c[2],poemBorderColor);c=poem_getValue("num",a)+",";c=c.split(",");poemSerialNum=poem_getDefault(c[0],poemSerialNum);if(!poemSerialNum){poemSerialNum=0}else{poemSerialNum=parseInt(poemSerialNum);if(isNaN(poemSerialNum)){poemSerialNum=0}}poemSerialNumColor=poem_getDefault(c[1],poemSerialNumColor);c=poem_getValue("type",a);poemType=poem_getDefault(c,poemType);c=poem_getValue("align",a);poemAlign=poem_getDefault(c,poemAlign).toLowerCase();c=poem_getValue("line",a);poemLine=poem_getDefault(c,poemLine);poemLine=parseInt(poemLine);if(isNaN(poemLine)){poemLine=0}if(poemLine==0){poemPadding="5px";poemMargin=""}else{poemPadding=15;poemMargin="margin-bottom:"+poemPadding}c=poem_getValue("use",a);poemUse=poem_getDefault(c,poemUse).toLowerCase();c=poem_getValue("bkcolor",a);poemBackColor=poem_getDefault(c,poemBackColor);c=poem_getValue("bkimage",a);poemBackImage=poem_getDefault(c,poemBackImage);var b=new Array("xx-small","x-small","small","medium","large","x-large","xx-large");poemFontSize=b[poemFontSize-1];poemFontName+=","+poemDefaultFont;if(document.all){}else{poemTestWidth=document.getElementById("poemTestWidth")}poemTestWidth.style.fontFamily=poemFontName;poemTestWidth.style.fontSize=poemFontSize;poemTestWidth.style.fontWeight=poemFontBold;poemTestWidth.style.fontStyle=poemFontItalic}function poem_trim(a){a=a.replace(/^[ ]+/,"");a=a.replace(/[ ]+$/,"");return a}function poem_textWidth(a){a=a.replace(/ /g,"&nbsp;");a=a.replace(/\^/g,"");poemTestWidth.innerHTML=a;return(poemTestWidth.clientWidth-2)*0.75}function poem_strReplace(e,d,a,g){if(g<=0){return}e=e.split(d);var f="";for(var b=e.length-1;b>0;b--){if(g-->0){f=a+e[b]+f}else{f=d+e[b]+f}}f=e[0]+f;return f}function poem_count(d,b){var e=0;for(var a=0;a<d.length;a++){e+=(d.charAt(a)==b)}return e}function poem_space(a){if(a==1){return" "}return" "+poem_space(a-1)}function poem_createExtend(b){var a="ÇÃÅÂ";var d="";var e="",c="";b=b.replace(/Çááå/g,"alh");b=b.replace(/ááå/g,"lah");for(i=0;i<b.length;i++){c=b.charAt(i);if(poemLetters2.indexOf(c.charAt(0))!=-1||c.charAt(0)=="Á"){if(e!=""){if(poemLetters1.indexOf(e.charAt(0))==-1&&poemLetters2.indexOf(c.charAt(0))!=-1&&(e.charAt(0)!="á"||a.indexOf(c.charAt(0))==-1)){d+="^"}}e=c;d+=c}else{d+=c;if(poemLetters3.indexOf(c.charAt(0))==-1){e=""}}}d=d.replace(/alh/g,"Çááå");d=d.replace(/lah/g,"ááå");return d}function poem_extend(a){if(a<=0){return""}if(a==1){return"Ü"}return"Ü"+poem_extend(a-1)}function poem_justifyBYextend(f,b){var e=0,c,h,j,g,a;e=poem_count(f,"^");if(e==0){return f}h=Math.floor((b-poem_textWidth(f.replace(/\^/g,"")))/poemExtendWidth);f=f.split(" ");j=0;for(c=0;c<f.length;c++){j+=(f[c].indexOf("^")!=-1)}g=Math.floor(h/j);a=h%j;for(c=f.length-1;c>=0;c--){e=poem_count(f[c],"^");if(e==0){continue}h=g+(a-->0);j=Math.floor(h/e);if(j>0){f[c]=f[c].replace(/\^/g,"^"+poem_extend(j))}if(h%e>0){f[c]=poem_strReplace(f[c],"^","Ü",h%e)}}f=f.join(" ");f=f.replace(/\^/g,"");return f}function poem_justifyBYspace(f,a,c){var g=0,e,h,b,j;g=poem_count(f," ");if(g!=0){h=Math.floor((a-poem_textWidth(f))/poemSpaceWidth);j=Math.floor(h/g);if(j>0){f=f.replace(/ /g,poem_space(j+1))}if(h%g>0){f=poem_strReplace(f,poem_space(j+1),poem_space(j+2),h%g)}}b=a-poem_textWidth(f);if(b>0){e=f.lastIndexOf(" ");if(e==-1){if(c==0){return f}else{e=((c==2)?-1:f.length-1)}}}else{b=0}f=f.substr(0,e+1)+poemToolFix.replace(/%w%/,b+"pt")+f.substr(e+1);return f}function poem_justify(c,a,b){if(poemUse=="ex"){c=poem_justifyBYextend(c,a)}return poem_justifyBYspace(c,a,b)}function showPoemLine(b,a){if(b){poemPrevHTML+=a}else{document.write(a)}}function doPoem(p){var m=0,o;poem_setDefaultVar();if(p){o=poemExample;poemPrevHTML=""}else{var w=document.getElementsByTagName("div");o=w[w.length-1]}var b=o.innerHTML.replace(/<br \/>|<br>/gi,"\r");if(b==""){return}if(!o.tag){o.tag=""}if(!p){o.innerHTML=""}var f=o.tag.replace(/\\\"/g,"'");create_poemTestWidth_table();poem_setArg(f);poemToolFix="<span style='font-size:1pt;padding-right:%w%;'></span>";poemToolFix=poemToolFix.replace(/ /g,"^");b=b.replace(/</g,"&lt;");b=b.replace(/>/g,"&gt;");b=b.replace(/[\^]|^[\r]+|[\r]+$|\n/g,"");b=b.replace(/^[ ]+|[ ]+$|/g,"");b=b.replace(/[Ü]+( |$)/g,"ext1");b=b.replace(/(^| )[Ü]+/g,"ext2");b=b.replace(/Ü/g,"");b=b.replace(/ext1/g,"Ü");b=b.replace(/ext2/g,"Ü");b=b.replace(/[ ]+/g," ");b=b.replace(/[ ]*=[ ]*/g,"=");b=b.replace(/[ ]+\r|\r[ ]+/g,"\r");if(b.substring(b.length-1)!="\r"){b+="\r"}poemExtendWidth=poem_textWidth("ÔÜÜÔ");poemExtendWidth-=poem_textWidth("ÔÜÔ");poemSpaceWidth=poem_textWidth("Ô&nbsp;&nbsp;Ô");poemSpaceWidth-=poem_textWidth("Ô&nbsp;Ô");var x,h,n;x="\r"+b+"\r";x=x.replace(/\r[^\r]+\=[^\r]+/gi,"");x=x.replace(/\r/g,"<br>");var n=poem_textWidth(x);x="\r"+b+"\r";x=x.replace(/\r[^=]+\r/gi,"\r");x=x.replace(/=/g,"<br>");x=x.replace(/\r/g,"<br>");var h=poem_textWidth(x);x="";if(poemUse=="ex"){var v=poem_textWidth(b);b=poem_createExtend(b);v=(poem_textWidth(b.replace(/\^/g,"Ü"))-v)/poem_count(b,"^")}var q="",k="";k+=";font-family:"+poemFontName;k+=";font-size:"+poemFontSize;k+=";color:"+poemFontColor;k+=";font-weight:"+poemFontBold;k+=";font-style:"+poemFontItalic;q+=k;q+=";background-color:"+poemBackColor;q+=";background-image:url("+poemBackImage+")";q+=";border:"+poemBorderWidth+"px "+poemBorderStyle+" "+poemBorderColor;showPoemLine(p,"<div align='"+poemAlign+"'>");showPoemLine(p,"<table dir='rtl' border='0' cellpadding='0' cellspacing='0' width='1px' style='"+q+";'>");b="\r"+b;var l,e,s,r=0,g=0,u=0;var c,t,a;if(poemSerialNum>0){u=poemSerialNum-1}while(1){t="";c="";if(u==0){c="<div style='height:"+poemPadding+"px;font-size:1'></div>"}g=b.indexOf("\r",g);if(g==-1){break}if(b.substring(r,g)!=""){s=b.indexOf("=",r);if(s==-1||s>g){s=g}l=b.substring(r,s);if(l!="\r"&&l!=""){if(s!=g){l=poem_justify(l,h,1)}else{l=poem_justify(l,n,0)}l=l.replace(/ /g,"&nbsp;");l=l.replace(/\^/g," ")}e=b.substring(s+1,g);if(e!="\r"&&e!=""){e=poem_justify(e,h,2);e=e.replace(/ /g,"&nbsp;");e=e.replace(/\^/g," ")}if(poemType==0){if(s!=g){if(l!=""&&e==""){c=l}else{if(l==""&&e!=""){c=e}else{if(l!=""&&e!=""){c=l+poemToolFix.replace(/%w%/,Math.floor(h/2.1)+"px").replace(/\^/," ")+e}}}}else{c=l}c="<div align=center style='"+k+";"+poemMargin+"'>"+c+"</div>";t=++u}else{if(poemType==1){if(s==g){c="<div align=center style='"+k+";"+poemMargin+"'>"+l+"</div>"}else{c="<div align='right' style='"+k+"; margin-left:"+Math.round(h)+"pt;"+poemMargin+"'>"+l+"</div>";c+="<div align='left' style='"+k+"; margin-right:"+Math.round(h)+"pt;"+poemMargin+"'>"+e+"</div>"}t=++u}else{if(poemType==2||poemType>3||poemType<1){if(s==g){c="<div align=center style='"+k+";"+poemMargin+"'>"+l+"</div>"}else{c="<div align='right' style='"+k+"; margin-left:"+Math.round(h/2)+"pt;"+poemMargin+"'>"+l+"</div>";c+="<div align='left' style='"+k+"; margin-right:"+Math.round(h/2)+"pt;"+poemMargin+"'>"+e+"</div>"}t=++u}else{if(poemType==3){t=++u;c="<div style='"+k+";"+poemMargin+"'>"+l+"</div>";c+="<div style='"+k+";"+poemMargin+"'>"+e+"</div>"}}}}}if(poemSerialNum>0&&t!=""){showPoemLine(p,"<tr><td align=left valign=top style='"+k+"; color:"+poemSerialNumColor+"' nowrap>&nbsp;&nbsp;"+t+"</td>")}showPoemLine(p,"<td align=center valign=middle style='"+k+";padding-left:15px;padding-right:15px;' nowrap>"+c+"</td></tr>");g+=1;r=g}if(poemLine==0){c="<div style='height:"+poemPadding+"px;font-size:1'></div>";if(poemSerialNum>0&&t!=""){showPoemLine(p,"<tr><td align=left valign=top style='"+k+"; color:"+poemSerialNumColor+"' nowrap>&nbsp;&nbsp;"+t+"</td>")}showPoemLine(p,"<td align=center valign=middle style='"+k+";padding-left:15px;padding-right:15px;' nowrap>"+c+"</td></tr>")}showPoemLine(p,"</table></div>");if(p){poemPreview.innerHTML=poemPrevHTML}poemPrevHTML="";poem_textWidth("")};