// (c) 2004-2011 Ali Jahanshiri

var $I=function(selector){return document.getElementById(selector);};var $T=function(selector,context){if(!context){context=document;}
return context.getElementsByTagName(selector);};var $H=function(selector,context){if(!context){context=document;};var elems=$T(selector,context),i=0,il=elems.length,ret=[];for(;i<il;i+=1){if(elems[i].parentNode===context){ret.push(elems[i]);}}
return ret;};var Browser={info:navigator.userAgent.toLowerCase(),isIE:function(){return(this.info.indexOf('msie')!==-1);}};var doMail=function(){var o=$T('address'),i=0,il=o.length,m=['alijsh','&#6','4;','gm','ai','l.','com'].join(''),a=['<a href="','ma','il','to:',m,'">',m,'<\/a>'].join('');for(;i<il;i+=1){o[i].innerHTML=a;}};if(!String.prototype.trim){String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,'');};}
String.prototype.endsWith=function(exp){return(this.search(new RegExp(exp+'$'))!==-1);};String.prototype.contains=function(string){return(' '+this+' ').indexOf(' '+string+' ')>-1;};var Elem={hide:function(l){l.style.display='none';},show:function(l){l.style.display='block';},showhide:function(l,m){this.show(l);this.hide(m);},swapClass:function(l,c1,c2){l.className=((' '+l.className+' ').replace(' '+c1+' ',' '+c2+' ')).trim();},addClass:function(l,c){if(!l.className.contains(c)){l.className=(l.className+' '+c).trim();}},removeClass:function(l,c){l.className=((' '+l.className+' ').replace(' '+c+' ','')).trim();},hasClass:function(l,c){return l.className.contains(c);},isAllWS:function(nod){return!(/[^\t\n\r ]/.test(nod.data));},isIgnorable:function(nod){return(nod.nodeType==8)||((nod.nodeType==3)&&this.isAllWS(nod));},sibBefore:function(sib){while(sib=sib.previousSibling){if(!this.isIgnorable(sib)){return sib;}}
return null;},sibAfter:function(sib){while(sib=sib.nextSibling){if(!this.isIgnorable(sib)){return sib;}}
return null;},getText:function(l){if(l.textContent){return l.textContent;}
if(l.innerText){return l.innerText;}}};var TabView=function(args){if(args.premade){this.box=$I(args.id);this.bar=$T('ul',this.box)[0];this.frame=$T('div',this.box)[0];this.selIndex=args.active||0;}else{this.box=document.createElement('div');this.bar=document.createElement('ul');this.frame=document.createElement('div');this.box.id=args.id;Elem.addClass(this.box,'tabview');$I(args.parent).appendChild(this.box);this.box.appendChild(this.bar);this.box.appendChild(this.frame);this.selIndex=-1;}
Elem.addClass(this.bar,'tabbar');Elem.addClass(this.frame,'tabframe');this.index=-1;this.isCloseable=args.closeable||false;this.pfxTab=args.id+'-tab';this.pfxPage=args.id+'-page';this.tabs=$T('li',this.bar);if(args.premade){this.init();}
this.addEvent();};TabView.prototype={init:function(index){var DIVs=$H('div',this.frame),i=0,il=DIVs.length;for(;i<il;i+=1){Elem.addClass(DIVs[i],'tabpage');DIVs[i].id=this.pfxPage+i;this.tabs[i].id=this.pfxTab+i;}
this.index=i;this.selectTab(this.selIndex);},getTab:function(index){return $I(this.pfxTab+index);},getTabIndex:function(tab){return parseInt(tab.id.replace(this.pfxTab,''),10);},getPage:function(index){return $I(this.pfxPage+index);},selectTab:function(index){var tab=this.getTab(index);if(!tab){return;}
Elem.addClass(tab,'active');Elem.addClass(this.getPage(index),'active');this.selIndex=index;},deselectTab:function(index){var tab=this.getTab(index);if(!tab){return;}
Elem.removeClass(tab,'active');Elem.removeClass(this.getPage(index),'active');},showTab:function(index){this.deselectTab(this.selIndex);this.selectTab(index);},addEvent:function(){var self=this;this.bar.onmouseup=function(e){var ev=window.event||e,tab=ev.target||ev.srcElement,btn=null;if(tab.nodeType===3||tab.nodeName.toLowerCase()!=='li'){tab=tab.parentNode;}
if('object'===typeof ev){if(Browser.isIE()){switch(ev.button){case 1:btn='l';break;case 4:btn='m';break;}}else{switch(ev.button){case 0:btn='l';break;case 1:btn='m';break;}}
switch(btn){case'l':self.showTab(self.getTabIndex(tab));break;case'm':if(self.isCloseable){self.removeTab(self.getTabIndex(tab));}
break;}}};},addTab:function(args){var tab=document.createElement('li'),page=document.createElement('div');this.index+=1;tab.id=this.pfxTab+this.index;tab.appendChild(document.createTextNode(args.caption));Elem.addClass(page,'tabpage');page.id=this.pfxPage+this.index;page.innerHTML=args.content;if(args.cls){Elem.addClass(tab,args.cls);}
this.bar.appendChild(tab);this.frame.appendChild(page);this.showTab(this.index);},removeTab:function(index){this.switchTab(index);this.bar.removeChild(this.getTab(index));this.frame.removeChild(this.getPage(index));},switchTab:function(index){if(index!==this.selIndex){return;}
var tab=this.getTab(index),sw=Elem.sibBefore(tab);if(!sw){sw=Elem.sibAfter(tab);}
if(sw){this.showTab(this.getTabIndex(sw));}}};var KB={init:function(){var i,il,j,jl,keyrows=['q w e r t y u i o p','a s d f g h j k l _','z x c v b n m _ _ _','â ch gh kh sh zh ` _ _ _'],keys=[],out='<table class="kb"><tr>'+'<td class="button" onclick="KB.clear()">'+Res.of('clear')+'</td>'+'<td class="button" onclick="KB.space()">'+Res.of('space')+'</td>'+'<td class="button" onclick="KB.backspace()">'+Res.of('backspace')+'</td>'+'</tr></table><div id="plchars">';function makeKB(c){out+='<table class="'+c+'">';var b=(c.indexOf('rt')>-1)?' rtl':'';for(i=0,il=keyrows.length;i<il;i+=1){out+='<tr>';keys=keyrows[i].split(' ');for(j=0,jl=keys.length;j<jl;j+=1){out+='<td'+((keys[j]==='_')?' class="hdn"':'')+' class="button'+b+'" onclick="KB.insert(\''+keys[j]+'\')">'+keys[j]+'</td>';}
out+='</tr>';}
out+='</table>'}
makeKB('kb');keyrows=['âdan ândan idan ndan rdan udan dan','ftan stan shtan khtan tan _ _'];makeKB('kb');out+='</div><div id="pachars">';keyrows=['آ ا ب پ ت ث ج چ ح خ د','ذ ر ز ژ س ش ص ض ط ظ ع','غ ف ق ک گ ل م ن و ه ی'];makeKB('kb rtl');keyrows=['اندن ادن ردن ندن ودن یدن دن','ختن ستن شتن فتن تن _ _'];makeKB('kb rtl');out+='</div>';$I('kb').innerHTML=out;},ed:$I('txtVerb'),insert:function(str){this.ed.value+=str;this.ed.focus();},space:function(){this.ed.value+=' ';this.ed.focus();},clear:function(){this.ed.value='';this.ed.focus();},backspace:function(){var str=this.ed.value;if(str.length>0){this.ed.value=str.substring(0,str.length-1);this.ed.focus();}}};var Res={problem:{en:'There was a problem. Please try again later.',es:'Hubo un problema. ¡Inténtalo otra vez!',fa:'مشکلی هست. دوباره بیازمایید',fr:'Il y avait un problème. Merci de réessayer un peu plus tard.',pt:'Houve um problema. Tente novamente!'},XMLHTTP:{en:'Giving up: your browser does not support the required functionality (XMLHTTP)',es:'Saliendo: tu navegador no sostiene la funcionalidad necesaria (XMLHTTP)',fa:'مرورگری که به کار می‌برید نیازمندیهای این برنامه را پشتیبانی نمی‌کند',fr:'Quittant : votre navigateur ne supporte pas la fonctionnalité requise. (XMLHTTP)',pt:'Saindo: seu navegador não sustenta a funcionalidade necessária (XMLHTTP)'},NAV:{en:'You have not entered an infinitive.',es:'No has introducido un infinitivo.',fa:'آنچه وارد کرده‌اید به شکل مصدری نیست',fr:'Votre verb n\'est pas à l\'infinitif.',pt:'Você entrou não é um infinitivo.'},NV:{en:'Enter your verb!',es:'Introduce tu verbo!',fa:'نخست فعل دلخواه‌تان را وارد کنید',es:'Introduce tu verbo!',fr:'Entrez votre verbe!',pt:'Entre com seu verbo!'},check:{en:'Check your input! There are invalid characters.',es:'Verifica lo que has entrado! Hay caracteres inválidos.',fa:'در آنچه وارد کرده‌اید نویسه‌های نامربوط دیده می‌شود ',fr:'Vérifiez ce que vous avez entré! Il ya des caractères invalides.',pt:'Verifique sua grafia! Hão caracteres inválidos.'},space:{en:'Space',es:'Espacio',fa:'فاصله',fr:'Espace',pt:'Espaço'},print:{en:'Print',es:'Imprimir',fa:'چاپ',fr:'Imprimer',pt:'Imprimir'},backspace:{en:'Backspace',es:'Retroceso',fa:'پس‌گرد',fr:'Retour arrière',pt:'Retorno'},clear:{en:'Clear',es:'Borrar',fa:'پاک کردن',fr:'Supprimer',pt:'Apagar'},clickTo:{en:'Click to conjugate',es:'Haz clic para conjugar',fa:'کلیک کنید تا صرف بشود',fr:'Cliquez pour le conjuguer',pt:'Clique para conjugar'},of:function(s){return this[s][Page.lang]||this[s]['en'];}};var AJAX={status:'ready',tip:$I('statbox'),ready:function(){Elem.hide(this.tip);this.status='ready';clearInterval(this.timeout);},busy:function(){this.status='busy';Elem.show(this.tip);},fail:function(){window.alert(Res.of('problem'));this.ready();},success:function(){Page.tvwContent.showTab(0);Page.tvwConjs.addTab({cls:(Conjugator.mode=='pa')?'rtl':'',caption:Conjugator.verb,content:'<span class="button noprint f-'+(Page.lang=='fa'?'l':'r')+'" onclick="window.print()">'+Res.of('print')+'</span>'+
this.xhr.responseText});this.ready();},send:function(url){var self=this;this.xhr.onreadystatechange=function(){self.query();};this.xhr.open('GET',url,true);this.xhr.send(null);this.timeout=setTimeout(function(){self.xhr.abort();},10E3);},query:function(){try{if(this.xhr.readyState==4){if(this.xhr.status==200){this.success();}else{this.fail();}}else{this.busy();}}catch(e){window.alert(e.description);}},init:function(){var versions=['Msxml2.XMLHTTP','Microsoft.XMLHTTP'],i=0;this.xhr=null;if(window.XMLHttpRequest){this.xhr=new XMLHttpRequest();if(this.xhr.overrideMimeType){this.xhr.overrideMimeType('text/xml');}}else if(window.ActiveXObject){for(;i<2;i+=1){try{this.xhr=new ActiveXObject(versions[i]);break;}
catch(e){}}}
if(this.xhr===null){this.status='busy';window.alert(Res.of('XMLHTTP'));}}};var Conjugator={init:function(){AJAX.init();this.mode='pa';},err:function(s){window.alert(s);$I('txtVerb').focus();}};Conjugator.InputOK=function(mode){var str=$I('txtVerb').value.trim().toLowerCase(),erroneous=false,re='';if(str.length===0){this.err(Res.of('NV'));return false;}
switch(mode){case'pa':str=str.replace(/\u0643/g,'\u06A9');str=str.replace(/[\u0649\u064A]/g,'\u06CC');break;case'pl':str=str.replace(/\'/g,'`').replace(/aa/g,'â');break;default:return false;}
$I('txtVerb').value=str;switch(mode){case'pa':re='[^\u0622-\u0648\u067E\u0686\u0698\u06AF\u06A9\u06CC\u200C\u064E\u064F\u0650\u0651 ]';erroneous=($I('txtVerb').value.search(re)!=-1);break;case'pl':re="[^a-zâ`' ]";erroneous=($I('txtVerb').value.search(re)!=-1);break;}
if(erroneous){this.err(Res.of('check'));return false;}
switch(mode){case'pa':if((str.length<3)||(!str.endsWith('[\u062F\u062A]\u0646'))){this.err(Res.of('NAV'));return false;}
break;case'pl':if((str.length<5)||(!str.endsWith('[dt]an'))){this.err(Res.of('NAV'));return false;}
break;}
return true;};Conjugator.conjugate=function(verb,mode){if(AJAX.status!=='ready'){return;}
if(!mode){mode=this.mode;}
if(mode){this.mode=mode;}
if(!verb){if(this.InputOK(mode)){verb=$I('txtVerb').value;}else{return;}}
this.verb=verb;AJAX.send(((mode=='pa')?'pvcpa.php':'pvcpl.php')+'?verb='+encodeURIComponent(verb.trim())+'&lang='+Page.lang);};$I('txtVerb').onkeydown=function(e){if(AJAX.status!=='ready'){return;}
var keynum=(window.event)?e.keyCode:e.which;if(keynum==13){Conjugator.conjugate();}};$I('cboScript').onchange=function(){Conjugator.mode=this.options[this.selectedIndex].value;switch(Conjugator.mode){case'pa':Elem.swapClass($I('txtVerb'),'ltr','rtl');Elem.showhide($I('pachars'),$I('plchars'));break;case'pl':Elem.swapClass($I('txtVerb'),'rtl','ltr');Elem.showhide($I('plchars'),$I('pachars'));break;}};var Page={};Page.makeTopList=function(){function make(items,mode){var s='';for(var i=0;i<20;i+=1){s+='<a href ="#" title="'+Res.of('clickTo')+'" onclick="Conjugator.conjugate(\''+items[i]+'\',\''+mode+'\')">'+
items[i]+'</a> ';}
$I('vl-'+mode).innerHTML+=s;}
make(['آمدن','آوردن','بودن','خواستن','خواندن','خوردن','دادن','داشتن','دانستن','دیدن','رَفتن','زدن','شدن','شستن','شنیدن','کردن','گرفتن','گشتن','گفتن','نوِشتن'],'pa');make(['âmadan','bastan','bordan','budan','didan','dâdan','dânestan','dâshtan','gereftan','goftan','kardan','khordan','khwândan','khwâstan','neveshtan','raftan','shekastan','shenidan','shodan','shostan'],'pl');};Page.init=function(){this.html=$T('html')[0];this.lang=this.html.getAttribute('xml:lang')||this.html.getAttribute('lang')||'en';this.lang=this.lang.split('-')[0];this.tvwContent=new TabView({premade:true,id:'tvwContent',active:2});this.tvwConjs=new TabView({id:'tvwConjs',parent:'output',closeable:true});this.makeTopList();KB.init();Conjugator.init();$I('cboScript').selectedIndex=0;$I('cboScript').onchange();doMail();$I('btnConj').onclick=function(){Conjugator.conjugate();};};Page.init();
