//Correct with Z_Haghdel
var keyboardLayout={};
var langCycle=[''];
(function($){var k=null;var tt=null;function sh(l){var t='Language: ';for(var i=0;i<langCycle.length;i++){var x=lfc(i)||'default';t+=(i==l?'['+x+']':x)+' ';}if(tt)clearTimeout(tt);document.t=document.t||document.title;document.title=t;tt=setTimeout(function(){document.title=document.t;document.t=undefined;tt=null;},1000);}function lfc(i){return langCycle[i].lang?langCycle[i].lang:langCycle[i];}function dfc(i){return langCycle[i].direction?langCycle[i].direction:'';}function nli(t){var ni=langCycle.length?0:-1;for(var i=0;i<langCycle.length;i++){if(lfc(i)==t)ni=i<langCycle.length-1?i+1:0;}return ni;}$('input[type=text],textarea').live('keydown',function(e){k=e.which;}).live('keypress',function(e){var $t=$(this);var l=$t.attr('lang').match(/^[a-zA-Z]{2}/)||'';if(!l){if(!langCycle.length) return true;l=lfc(0);}if (e.ctrlKey&&e.which==0x20&&langCycle&&langCycle.length>1){var nl=nli(l);if(nl>=0){sh(nl);$t.attr('lang',lfc(nl));$t.css('direction',dfc(nl));}e.preventDefault();return false;}var y=keyboardLayout[l];if((!y)||e.ctrlKey||e.altKey||e.metaKey||(k!=0x20&&k<0x30)||(e.which<0x20||e.which>0x7F))return true;var v=(e.which==0x20&&e.shiftKey&&y[0x5f])||(y[e.which-0x20]);v=typeof v=='string'?v:String.fromCharCode(v);var ds=document.selection,ss=this.selectionStart;if(typeof ss=='number'){var sl=this.scrollLeft,st=this.scrollTop;this.value=this.value.substring(0,ss)+v+this.value.substring(this.selectionEnd,this.value.length);var sr=ss+v.length;this.setSelectionRange(sr,sr);this.scrollLeft=sl;this.scrollTop=st;}else if(ds){var r=ds.createRange();r.text=v;r.setEndPoint('StartToEnd',r);r.select();}else{this.value+=v;}e.preventDefault();});})(jQuery);

keyboardLayout['fa'] = [
    0x20, 0x21, 0x61b, 0x66b, 0xfdfc, 0x66a, 0x60c, 0x6af, 0x29, 0x28, 0x2a, 0x2b, 0x648, 0x2d, 0x2e, 0x2f,
    0x6f0, 0x6f1, 0x6f2, 0x6f3, 0x6f4, 0x6f5, 0x6f6, 0x6f7, 0x6f8, 0x6f9, 0x3a, 0x6a9, 0x3e, 0x3d, 0x3c, 0x61f,
    0x66c, 0x624, 0x200c, 0x698, 0x64a, 0x64d, 0x625, 0x623, 0x622, 0x651, 0x629, 0xbb, 0xab, 0x621, 0x654, 0x5d,
    0x5b, 0x652, 0x64b, 0x626, 0x64f, 0x64e, 0x670, 0x64c, 0x653, 0x650, 0x643, 0x62c, 0x67e, 0x686, 0xd7, 0x640,
    0x67e, 0x634, 0x630, 0x632, 0x6cc, 0x62b, 0x628, 0x644, 0x627, 0x647, 0x62a, 0x646, 0x645, 0x67e, 0x62f, 0x62e,
    0x62d,0x636,0x642,0x633,0x641,0x639,0x631,0x635,0x637,0x63a,0x638,0x7d,0x7c,0x7b,0xf7,0x200C];
langCycle.push({lang:'fa',direction:'rtl'});

