(function($){var locationWrapper={put:function(hash,win){(win||window).location.hash=this.encoder(hash);},get:function(win){return(win||window).location.toString().split('#',2)[1]||'';},encoder:encodeURIComponent};var iframeWrapper={id:"__jQuery_history",init:function(){var html='<iframe id="'+this.id+'" style="display:none" src="javascript:false;" />';$("body").prepend(html);return this;},_document:function(){return $("#"+this.id)[0].contentWindow.document;},put:function(hash){var doc=this._document();doc.open();doc.close();locationWrapper.put(hash,doc);},get:function(){return locationWrapper.get(this._document());}};function initObjects(options){options=$.extend({unescape:false},options||{});locationWrapper.encoder=encoder(options.unescape);function encoder(unescape_){if(unescape_===true){return function(hash){return hash;};}
if(typeof unescape_=="string"&&(unescape_=partialDecoder(unescape_.split("")))||typeof unescape_=="function"){return function(hash){return unescape_(encodeURIComponent(hash));};}
return encodeURIComponent;}
function partialDecoder(chars){var re=new RegExp($.map(chars,encodeURIComponent).join("|"),"ig");return function(enc){return enc.replace(re,decodeURIComponent);};}}
var implementations={};implementations.base={callback:undefined,type:undefined,check:function(){},load:function(hash){},init:function(callback,options){initObjects(options);self.callback=callback;self._options=options;self._init();},_init:function(){},_options:{}};implementations.timer={_appState:undefined,_init:function(){var current_hash=locationWrapper.get();self._appState=current_hash;self.callback(current_hash);setInterval(self.check,100);},check:function(){var current_hash=locationWrapper.get();if(current_hash!=self._appState){self._appState=current_hash;self.callback(current_hash);}},load:function(hash){if(hash!=self._appState){locationWrapper.put(hash);self._appState=hash;self.callback(hash);}}};implementations.iframeTimer={_appState:undefined,_init:function(){var current_hash=locationWrapper.get();self._appState=current_hash;iframeWrapper.init().put(current_hash);self.callback(current_hash);setInterval(self.check,100);},check:function(){var iframe_hash=iframeWrapper.get(),location_hash=locationWrapper.get();if(location_hash!=iframe_hash){if(location_hash==self._appState){self._appState=iframe_hash;locationWrapper.put(iframe_hash);self.callback(iframe_hash);}else{self._appState=location_hash;iframeWrapper.put(location_hash);self.callback(location_hash);}}},load:function(hash){if(hash!=self._appState){locationWrapper.put(hash);iframeWrapper.put(hash);self._appState=hash;self.callback(hash);}}};implementations.hashchangeEvent={_init:function(){self.callback(locationWrapper.get());$(window).bind('hashchange',self.check);},check:function(){self.callback(locationWrapper.get());},load:function(hash){locationWrapper.put(hash);}};var self=$.extend({},implementations.base);if($.browser.msie&&($.browser.version<8||document.documentMode<8)){self.type='iframeTimer';}else if("onhashchange"in window){self.type='hashchangeEvent';}else{self.type='timer';}
$.extend(self,implementations[self.type]);$.history=self;})(jQuery);(function(jQuery,undefined){var oldManip=jQuery.fn.domManip,tmplItmAtt="_tmplitem",htmlExpr=/^[^<]*(<[\w\W]+>)[^>]*$|\{\{\! /,newTmplItems={},wrappedItems={},appendToTmplItems,topTmplItem={key:0,data:{}},itemKey=0,cloneIndex=0,stack=[];function newTmplItem(options,parentItem,fn,data){var newItem={data:data||(parentItem?parentItem.data:{}),_wrap:parentItem?parentItem._wrap:null,tmpl:null,parent:parentItem||null,nodes:[],calls:tiCalls,nest:tiNest,wrap:tiWrap,html:tiHtml,update:tiUpdate};if(options){jQuery.extend(newItem,options,{nodes:[],parent:parentItem});}
if(fn){newItem.tmpl=fn;newItem._ctnt=newItem._ctnt||newItem.tmpl(jQuery,newItem);newItem.key=++itemKey;(stack.length?wrappedItems:newTmplItems)[itemKey]=newItem;}
return newItem;}
jQuery.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(name,original){jQuery.fn[name]=function(selector){var ret=[],insert=jQuery(selector),elems,i,l,tmplItems,parent=this.length===1&&this[0].parentNode;appendToTmplItems=newTmplItems||{};if(parent&&parent.nodeType===11&&parent.childNodes.length===1&&insert.length===1){insert[original](this[0]);ret=this;}else{for(i=0,l=insert.length;i<l;i++){cloneIndex=i;elems=(i>0?this.clone(true):this).get();jQuery.fn[original].apply(jQuery(insert[i]),elems);ret=ret.concat(elems);}
cloneIndex=0;ret=this.pushStack(ret,name,insert.selector);}
tmplItems=appendToTmplItems;appendToTmplItems=null;jQuery.tmpl.complete(tmplItems);return ret;};});jQuery.fn.extend({tmpl:function(data,options,parentItem){return jQuery.tmpl(this[0],data,options,parentItem);},tmplItem:function(){return jQuery.tmplItem(this[0]);},template:function(name){return jQuery.template(name,this[0]);},domManip:function(args,table,callback,options){if(args[0]&&args[0].nodeType){var dmArgs=jQuery.makeArray(arguments),argsLength=args.length,i=0,tmplItem;while(i<argsLength&&!(tmplItem=jQuery.data(args[i++],"tmplItem"))){}
if(argsLength>1){dmArgs[0]=[jQuery.makeArray(args)];}
if(tmplItem&&cloneIndex){dmArgs[2]=function(fragClone){jQuery.tmpl.afterManip(this,fragClone,callback);};}
oldManip.apply(this,dmArgs);}else{oldManip.apply(this,arguments);}
cloneIndex=0;if(!appendToTmplItems){jQuery.tmpl.complete(newTmplItems);}
return this;}});jQuery.extend({tmpl:function(tmpl,data,options,parentItem){var ret,topLevel=!parentItem;if(topLevel){parentItem=topTmplItem;tmpl=jQuery.template[tmpl]||jQuery.template(null,tmpl);wrappedItems={};}else if(!tmpl){tmpl=parentItem.tmpl;newTmplItems[parentItem.key]=parentItem;parentItem.nodes=[];if(parentItem.wrapped){updateWrapped(parentItem,parentItem.wrapped);}
return jQuery(build(parentItem,null,parentItem.tmpl(jQuery,parentItem)));}
if(!tmpl){return[];}
if(typeof data==="function"){data=data.call(parentItem||{});}
if(options&&options.wrapped){updateWrapped(options,options.wrapped);}
ret=jQuery.isArray(data)?jQuery.map(data,function(dataItem){return dataItem?newTmplItem(options,parentItem,tmpl,dataItem):null;}):[newTmplItem(options,parentItem,tmpl,data)];return topLevel?jQuery(build(parentItem,null,ret)):ret;},tmplItem:function(elem){var tmplItem;if(elem instanceof jQuery){elem=elem[0];}
while(elem&&elem.nodeType===1&&!(tmplItem=jQuery.data(elem,"tmplItem"))&&(elem=elem.parentNode)){}
return tmplItem||topTmplItem;},template:function(name,tmpl){if(tmpl){if(typeof tmpl==="string"){tmpl=buildTmplFn(tmpl)}else if(tmpl instanceof jQuery){tmpl=tmpl[0]||{};}
if(tmpl.nodeType){tmpl=jQuery.data(tmpl,"tmpl")||jQuery.data(tmpl,"tmpl",buildTmplFn(tmpl.innerHTML));}
return typeof name==="string"?(jQuery.template[name]=tmpl):tmpl;}
return name?(typeof name!=="string"?jQuery.template(null,name):(jQuery.template[name]||jQuery.template(null,htmlExpr.test(name)?name:jQuery(name)))):null;},encode:function(text){return(""+text).split("<").join("&lt;").split(">").join("&gt;").split('"').join("&#34;").split("'").join("&#39;");}});jQuery.extend(jQuery.tmpl,{tag:{"tmpl":{_default:{$2:"null"},open:"if($notnull_1){_=_.concat($item.nest($1,$2));}"},"wrap":{_default:{$2:"null"},open:"$item.calls(_,$1,$2);_=[];",close:"call=$item.calls();_=call._.concat($item.wrap(call,_));"},"each":{_default:{$2:"$index, $value"},open:"if($notnull_1){$.each($1a,function($2){with(this){",close:"}});}"},"if":{open:"if(($notnull_1) && $1a){",close:"}"},"else":{_default:{$1:"true"},open:"}else if(($notnull_1) && $1a){"},"html":{open:"if($notnull_1){_.push($1a);}"},"=":{_default:{$1:"$data"},open:"if($notnull_1){_.push($.encode($1a));}"},"!":{open:""}},complete:function(items){newTmplItems={};},afterManip:function afterManip(elem,fragClone,callback){var content=fragClone.nodeType===11?jQuery.makeArray(fragClone.childNodes):fragClone.nodeType===1?[fragClone]:[];callback.call(elem,fragClone);storeTmplItems(content);cloneIndex++;}});function build(tmplItem,nested,content){var frag,ret=content?jQuery.map(content,function(item){return(typeof item==="string")?(tmplItem.key?item.replace(/(<\w+)(?=[\s>])(?![^>]*_tmplitem)([^>]*)/g,"$1 "+tmplItmAtt+"=\""+tmplItem.key+"\" $2"):item):build(item,tmplItem,item._ctnt);}):tmplItem;if(nested){return ret;}
ret=ret.join("");ret.replace(/^\s*([^<\s][^<]*)?(<[\w\W]+>)([^>]*[^>\s])?\s*$/,function(all,before,middle,after){frag=jQuery(middle).get();storeTmplItems(frag);if(before){frag=unencode(before).concat(frag);}
if(after){frag=frag.concat(unencode(after));}});return frag?frag:unencode(ret);}
function unencode(text){var el=document.createElement("div");el.innerHTML=text;return jQuery.makeArray(el.childNodes);}
function buildTmplFn(markup){return new Function("jQuery","$item","var $=jQuery,call,_=[],$data=$item.data;"+"with($data){_.push('"+
jQuery.trim(markup).replace(/([\\'])/g,"\\$1").replace(/[\r\t\n]/g," ").replace(/\$\{([^\}]*)\}/g,"{{= $1}}").replace(/\{\{(\/?)(\w+|.)(?:\(((?:[^\}]|\}(?!\}))*?)?\))?(?:\s+(.*?)?)?(\(((?:[^\}]|\}(?!\}))*?)\))?\s*\}\}/g,function(all,slash,type,fnargs,target,parens,args){var tag=jQuery.tmpl.tag[type],def,expr,exprAutoFnDetect;if(!tag){throw"Template command not found: "+type;}
def=tag._default||[];if(parens&&!/\w$/.test(target)){target+=parens;parens="";}
if(target){target=unescape(target);args=args?(","+unescape(args)+")"):(parens?")":"");expr=parens?(target.indexOf(".")>-1?target+parens:("("+target+").call($item"+args)):target;exprAutoFnDetect=parens?expr:"(typeof("+target+")==='function'?("+target+").call($item):("+target+"))";}else{exprAutoFnDetect=expr=def.$1||"null";}
fnargs=unescape(fnargs);return"');"+
tag[slash?"close":"open"].split("$notnull_1").join(target?"typeof("+target+")!=='undefined' && ("+target+")!=null":"true").split("$1a").join(exprAutoFnDetect).split("$1").join(expr).split("$2").join(fnargs?fnargs.replace(/\s*([^\(]+)\s*(\((.*?)\))?/g,function(all,name,parens,params){params=params?(","+params+")"):(parens?")":"");return params?("("+name+").call($item"+params):all;}):(def.$2||""))+"_.push('";})+"');}return _;");}
function updateWrapped(options,wrapped){options._wrap=build(options,true,jQuery.isArray(wrapped)?wrapped:[htmlExpr.test(wrapped)?wrapped:jQuery(wrapped).html()]).join("");}
function unescape(args){return args?args.replace(/\\'/g,"'").replace(/\\\\/g,"\\"):null;}
function outerHtml(elem){var div=document.createElement("div");div.appendChild(elem.cloneNode(true));return div.innerHTML;}
function storeTmplItems(content){var keySuffix="_"+cloneIndex,elem,elems,newClonedItems={},i,l,m;for(i=0,l=content.length;i<l;i++){if((elem=content[i]).nodeType!==1){continue;}
elems=elem.getElementsByTagName("*");for(m=elems.length-1;m>=0;m--){processItemKey(elems[m]);}
processItemKey(elem);}
function processItemKey(el){var pntKey,pntNode=el,pntItem,tmplItem,key;if((key=el.getAttribute(tmplItmAtt))){while(pntNode.parentNode&&(pntNode=pntNode.parentNode).nodeType===1&&!(pntKey=pntNode.getAttribute(tmplItmAtt))){}
if(pntKey!==key){pntNode=pntNode.parentNode?(pntNode.nodeType===11?0:(pntNode.getAttribute(tmplItmAtt)||0)):0;if(!(tmplItem=newTmplItems[key])){tmplItem=wrappedItems[key];tmplItem=newTmplItem(tmplItem,newTmplItems[pntNode]||wrappedItems[pntNode],null,true);tmplItem.key=++itemKey;newTmplItems[itemKey]=tmplItem;}
if(cloneIndex){cloneTmplItem(key);}}
el.removeAttribute(tmplItmAtt);}else if(cloneIndex&&(tmplItem=jQuery.data(el,"tmplItem"))){cloneTmplItem(tmplItem.key);newTmplItems[tmplItem.key]=tmplItem;pntNode=jQuery.data(el.parentNode,"tmplItem");pntNode=pntNode?pntNode.key:0;}
if(tmplItem){pntItem=tmplItem;while(pntItem&&pntItem.key!=pntNode){pntItem.nodes.push(el);pntItem=pntItem.parent;}
delete tmplItem._ctnt;delete tmplItem._wrap;jQuery.data(el,"tmplItem",tmplItem);}
function cloneTmplItem(key){key=key+keySuffix;tmplItem=newClonedItems[key]=(newClonedItems[key]||newTmplItem(tmplItem,newTmplItems[tmplItem.parent.key+keySuffix]||tmplItem.parent,null,true));}}}
function tiCalls(content,tmpl,data,options){if(!content){return stack.pop();}
stack.push({_:content,tmpl:tmpl,item:this,data:data,options:options});}
function tiNest(tmpl,data,options){return jQuery.tmpl(jQuery.template(tmpl),data,options,this);}
function tiWrap(call,wrapped){var options=call.options||{};options.wrapped=wrapped;return jQuery.tmpl(jQuery.template(call.tmpl),call.data,options,call.item);}
function tiHtml(filter,textOnly){var wrapped=this._wrap;return jQuery.map(jQuery(jQuery.isArray(wrapped)?wrapped.join(""):wrapped).filter(filter||"*"),function(e){return textOnly?e.innerText||e.textContent:e.outerHTML||outerHtml(e);});}
function tiUpdate(){var coll=this.nodes;jQuery.tmpl(null,null,null,this).insertBefore(coll[0]);jQuery(coll).remove();}})(jQuery);(function($){$.fn.TextAreaExpander=function(minHeight,maxHeight){var hCheck=!($.browser.msie||$.browser.opera);function ResizeTextarea(e){e=e.target||e;var vlen=e.value.length,ewidth=e.offsetWidth;if(vlen!=e.valLength||ewidth!=e.boxWidth){if(hCheck&&(vlen<e.valLength||ewidth!=e.boxWidth))e.style.height="0px";var h=Math.max(e.expandMin,Math.min(e.scrollHeight,e.expandMax));e.style.overflow=(e.scrollHeight>h?"auto":"hidden");e.style.height=h+"px";e.valLength=vlen;e.boxWidth=ewidth;}
return true;};this.each(function(){if(this.nodeName.toLowerCase()!="textarea")return;var p=this.className.match(/expand(\d+)\-*(\d+)*/i);this.expandMin=minHeight||(p?parseInt('0'+p[1],10):0);this.expandMax=maxHeight||(p?parseInt('0'+p[2],10):99999);ResizeTextarea(this);if(!this.Initialized){this.Initialized=true;$(this).css("padding-top",0).css("padding-bottom",0);$(this).bind("keyup",ResizeTextarea).bind("focus",ResizeTextarea);}});return this;};})(jQuery);$(document).ready(function(){$("textarea[class*=expand]").TextAreaExpander();});function diff_match_patch(){this.Diff_Timeout=1.0;this.Diff_EditCost=4;this.Match_Threshold=0.5;this.Match_Distance=1000;this.Patch_DeleteThreshold=0.5;this.Patch_Margin=4;this.Match_MaxBits=32;}
var DIFF_DELETE=-1;var DIFF_INSERT=1;var DIFF_EQUAL=0;diff_match_patch.Diff;diff_match_patch.prototype.diff_main=function(text1,text2,opt_checklines,opt_deadline){if(typeof opt_deadline=='undefined'){if(this.Diff_Timeout<=0){opt_deadline=Number.MAX_VALUE;}else{opt_deadline=(new Date).getTime()+this.Diff_Timeout*1000;}}
var deadline=opt_deadline;if(text1==null||text2==null){throw new Error('Null input. (diff_main)');}
if(text1==text2){if(text1){return[[DIFF_EQUAL,text1]];}
return[];}
if(typeof opt_checklines=='undefined'){opt_checklines=true;}
var checklines=opt_checklines;var commonlength=this.diff_commonPrefix(text1,text2);var commonprefix=text1.substring(0,commonlength);text1=text1.substring(commonlength);text2=text2.substring(commonlength);commonlength=this.diff_commonSuffix(text1,text2);var commonsuffix=text1.substring(text1.length-commonlength);text1=text1.substring(0,text1.length-commonlength);text2=text2.substring(0,text2.length-commonlength);var diffs=this.diff_compute_(text1,text2,checklines,deadline);if(commonprefix){diffs.unshift([DIFF_EQUAL,commonprefix]);}
if(commonsuffix){diffs.push([DIFF_EQUAL,commonsuffix]);}
this.diff_cleanupMerge(diffs);return diffs;};diff_match_patch.prototype.diff_compute_=function(text1,text2,checklines,deadline){var diffs;if(!text1){return[[DIFF_INSERT,text2]];}
if(!text2){return[[DIFF_DELETE,text1]];}
var longtext=text1.length>text2.length?text1:text2;var shorttext=text1.length>text2.length?text2:text1;var i=longtext.indexOf(shorttext);if(i!=-1){diffs=[[DIFF_INSERT,longtext.substring(0,i)],[DIFF_EQUAL,shorttext],[DIFF_INSERT,longtext.substring(i+shorttext.length)]];if(text1.length>text2.length){diffs[0][0]=diffs[2][0]=DIFF_DELETE;}
return diffs;}
if(shorttext.length==1){return[[DIFF_DELETE,text1],[DIFF_INSERT,text2]];}
longtext=shorttext=null;var hm=this.diff_halfMatch_(text1,text2);if(hm){var text1_a=hm[0];var text1_b=hm[1];var text2_a=hm[2];var text2_b=hm[3];var mid_common=hm[4];var diffs_a=this.diff_main(text1_a,text2_a,checklines,deadline);var diffs_b=this.diff_main(text1_b,text2_b,checklines,deadline);return diffs_a.concat([[DIFF_EQUAL,mid_common]],diffs_b);}
if(checklines&&text1.length>100&&text2.length>100){return this.diff_lineMode_(text1,text2,deadline);}
return this.diff_bisect_(text1,text2,deadline);};diff_match_patch.prototype.diff_lineMode_=function(text1,text2,deadline){var a=this.diff_linesToChars_(text1,text2);text1=a.chars1;text2=a.chars2;var linearray=a.lineArray;var diffs=this.diff_main(text1,text2,false,deadline);this.diff_charsToLines_(diffs,linearray);this.diff_cleanupSemantic(diffs);diffs.push([DIFF_EQUAL,'']);var pointer=0;var count_delete=0;var count_insert=0;var text_delete='';var text_insert='';while(pointer<diffs.length){switch(diffs[pointer][0]){case DIFF_INSERT:count_insert++;text_insert+=diffs[pointer][1];break;case DIFF_DELETE:count_delete++;text_delete+=diffs[pointer][1];break;case DIFF_EQUAL:if(count_delete>=1&&count_insert>=1){diffs.splice(pointer-count_delete-count_insert,count_delete+count_insert);pointer=pointer-count_delete-count_insert;var a=this.diff_main(text_delete,text_insert,false,deadline);for(var j=a.length-1;j>=0;j--){diffs.splice(pointer,0,a[j]);}
pointer=pointer+a.length;}
count_insert=0;count_delete=0;text_delete='';text_insert='';break;}
pointer++;}
diffs.pop();return diffs;};diff_match_patch.prototype.diff_bisect_=function(text1,text2,deadline){var text1_length=text1.length;var text2_length=text2.length;var max_d=Math.ceil((text1_length+text2_length)/2);var v_offset=max_d;var v_length=2*max_d;var v1=new Array(v_length);var v2=new Array(v_length);for(var x=0;x<v_length;x++){v1[x]=-1;v2[x]=-1;}
v1[v_offset+1]=0;v2[v_offset+1]=0;var delta=text1_length-text2_length;var front=(delta%2!=0);var k1start=0;var k1end=0;var k2start=0;var k2end=0;for(var d=0;d<max_d;d++){if((new Date()).getTime()>deadline){break;}
for(var k1=-d+k1start;k1<=d-k1end;k1+=2){var k1_offset=v_offset+k1;var x1;if(k1==-d||(k1!=d&&v1[k1_offset-1]<v1[k1_offset+1])){x1=v1[k1_offset+1];}else{x1=v1[k1_offset-1]+1;}
var y1=x1-k1;while(x1<text1_length&&y1<text2_length&&text1.charAt(x1)==text2.charAt(y1)){x1++;y1++;}
v1[k1_offset]=x1;if(x1>text1_length){k1end+=2;}else if(y1>text2_length){k1start+=2;}else if(front){var k2_offset=v_offset+delta-k1;if(k2_offset>=0&&k2_offset<v_length&&v2[k2_offset]!=-1){var x2=text1_length-v2[k2_offset];if(x1>=x2){return this.diff_bisectSplit_(text1,text2,x1,y1,deadline);}}}}
for(var k2=-d+k2start;k2<=d-k2end;k2+=2){var k2_offset=v_offset+k2;var x2;if(k2==-d||(k2!=d&&v2[k2_offset-1]<v2[k2_offset+1])){x2=v2[k2_offset+1];}else{x2=v2[k2_offset-1]+1;}
var y2=x2-k2;while(x2<text1_length&&y2<text2_length&&text1.charAt(text1_length-x2-1)==text2.charAt(text2_length-y2-1)){x2++;y2++;}
v2[k2_offset]=x2;if(x2>text1_length){k2end+=2;}else if(y2>text2_length){k2start+=2;}else if(!front){var k1_offset=v_offset+delta-k2;if(k1_offset>=0&&k1_offset<v_length&&v1[k1_offset]!=-1){var x1=v1[k1_offset];var y1=v_offset+x1-k1_offset;x2=text1_length-x2;if(x1>=x2){return this.diff_bisectSplit_(text1,text2,x1,y1,deadline);}}}}}
return[[DIFF_DELETE,text1],[DIFF_INSERT,text2]];};diff_match_patch.prototype.diff_bisectSplit_=function(text1,text2,x,y,deadline){var text1a=text1.substring(0,x);var text2a=text2.substring(0,y);var text1b=text1.substring(x);var text2b=text2.substring(y);var diffs=this.diff_main(text1a,text2a,false,deadline);var diffsb=this.diff_main(text1b,text2b,false,deadline);return diffs.concat(diffsb);};diff_match_patch.prototype.diff_linesToChars_=function(text1,text2){var lineArray=[];var lineHash={};lineArray[0]='';function diff_linesToCharsMunge_(text){var chars='';var lineStart=0;var lineEnd=-1;var lineArrayLength=lineArray.length;while(lineEnd<text.length-1){lineEnd=text.indexOf('\n',lineStart);if(lineEnd==-1){lineEnd=text.length-1;}
var line=text.substring(lineStart,lineEnd+1);lineStart=lineEnd+1;if(lineHash.hasOwnProperty?lineHash.hasOwnProperty(line):(lineHash[line]!==undefined)){chars+=String.fromCharCode(lineHash[line]);}else{chars+=String.fromCharCode(lineArrayLength);lineHash[line]=lineArrayLength;lineArray[lineArrayLength++]=line;}}
return chars;}
var chars1=diff_linesToCharsMunge_(text1);var chars2=diff_linesToCharsMunge_(text2);return{chars1:chars1,chars2:chars2,lineArray:lineArray};};diff_match_patch.prototype.diff_charsToLines_=function(diffs,lineArray){for(var x=0;x<diffs.length;x++){var chars=diffs[x][1];var text=[];for(var y=0;y<chars.length;y++){text[y]=lineArray[chars.charCodeAt(y)];}
diffs[x][1]=text.join('');}};diff_match_patch.prototype.diff_commonPrefix=function(text1,text2){if(!text1||!text2||text1.charAt(0)!=text2.charAt(0)){return 0;}
var pointermin=0;var pointermax=Math.min(text1.length,text2.length);var pointermid=pointermax;var pointerstart=0;while(pointermin<pointermid){if(text1.substring(pointerstart,pointermid)==text2.substring(pointerstart,pointermid)){pointermin=pointermid;pointerstart=pointermin;}else{pointermax=pointermid;}
pointermid=Math.floor((pointermax-pointermin)/2+pointermin);}
return pointermid;};diff_match_patch.prototype.diff_commonSuffix=function(text1,text2){if(!text1||!text2||text1.charAt(text1.length-1)!=text2.charAt(text2.length-1)){return 0;}
var pointermin=0;var pointermax=Math.min(text1.length,text2.length);var pointermid=pointermax;var pointerend=0;while(pointermin<pointermid){if(text1.substring(text1.length-pointermid,text1.length-pointerend)==text2.substring(text2.length-pointermid,text2.length-pointerend)){pointermin=pointermid;pointerend=pointermin;}else{pointermax=pointermid;}
pointermid=Math.floor((pointermax-pointermin)/2+pointermin);}
return pointermid;};diff_match_patch.prototype.diff_commonOverlap_=function(text1,text2){var text1_length=text1.length;var text2_length=text2.length;if(text1_length==0||text2_length==0){return 0;}
if(text1_length>text2_length){text1=text1.substring(text1_length-text2_length);}else if(text1_length<text2_length){text2=text2.substring(0,text1_length);}
var text_length=Math.min(text1_length,text2_length);if(text1==text2){return text_length;}
var best=0;var length=1;while(true){var pattern=text1.substring(text_length-length);var found=text2.indexOf(pattern);if(found==-1){return best;}
length+=found;if(found==0||text1.substring(text_length-length)==text2.substring(0,length)){best=length;length++;}}};diff_match_patch.prototype.diff_halfMatch_=function(text1,text2){if(this.Diff_Timeout<=0){return null;}
var longtext=text1.length>text2.length?text1:text2;var shorttext=text1.length>text2.length?text2:text1;if(longtext.length<4||shorttext.length*2<longtext.length){return null;}
var dmp=this;function diff_halfMatchI_(longtext,shorttext,i){var seed=longtext.substring(i,i+Math.floor(longtext.length/4));var j=-1;var best_common='';var best_longtext_a,best_longtext_b,best_shorttext_a,best_shorttext_b;while((j=shorttext.indexOf(seed,j+1))!=-1){var prefixLength=dmp.diff_commonPrefix(longtext.substring(i),shorttext.substring(j));var suffixLength=dmp.diff_commonSuffix(longtext.substring(0,i),shorttext.substring(0,j));if(best_common.length<suffixLength+prefixLength){best_common=shorttext.substring(j-suffixLength,j)+
shorttext.substring(j,j+prefixLength);best_longtext_a=longtext.substring(0,i-suffixLength);best_longtext_b=longtext.substring(i+prefixLength);best_shorttext_a=shorttext.substring(0,j-suffixLength);best_shorttext_b=shorttext.substring(j+prefixLength);}}
if(best_common.length*2>=longtext.length){return[best_longtext_a,best_longtext_b,best_shorttext_a,best_shorttext_b,best_common];}else{return null;}}
var hm1=diff_halfMatchI_(longtext,shorttext,Math.ceil(longtext.length/4));var hm2=diff_halfMatchI_(longtext,shorttext,Math.ceil(longtext.length/2));var hm;if(!hm1&&!hm2){return null;}else if(!hm2){hm=hm1;}else if(!hm1){hm=hm2;}else{hm=hm1[4].length>hm2[4].length?hm1:hm2;}
var text1_a,text1_b,text2_a,text2_b;if(text1.length>text2.length){text1_a=hm[0];text1_b=hm[1];text2_a=hm[2];text2_b=hm[3];}else{text2_a=hm[0];text2_b=hm[1];text1_a=hm[2];text1_b=hm[3];}
var mid_common=hm[4];return[text1_a,text1_b,text2_a,text2_b,mid_common];};diff_match_patch.prototype.diff_cleanupSemantic=function(diffs){var changes=false;var equalities=[];var equalitiesLength=0;var lastequality=null;var pointer=0;var length_insertions1=0;var length_deletions1=0;var length_insertions2=0;var length_deletions2=0;while(pointer<diffs.length){if(diffs[pointer][0]==DIFF_EQUAL){equalities[equalitiesLength++]=pointer;length_insertions1=length_insertions2;length_deletions1=length_deletions2;length_insertions2=0;length_deletions2=0;lastequality=diffs[pointer][1];}else{if(diffs[pointer][0]==DIFF_INSERT){length_insertions2+=diffs[pointer][1].length;}else{length_deletions2+=diffs[pointer][1].length;}
if(lastequality&&(lastequality.length<=Math.max(length_insertions1,length_deletions1))&&(lastequality.length<=Math.max(length_insertions2,length_deletions2))){diffs.splice(equalities[equalitiesLength-1],0,[DIFF_DELETE,lastequality]);diffs[equalities[equalitiesLength-1]+1][0]=DIFF_INSERT;equalitiesLength--;equalitiesLength--;pointer=equalitiesLength>0?equalities[equalitiesLength-1]:-1;length_insertions1=0;length_deletions1=0;length_insertions2=0;length_deletions2=0;lastequality=null;changes=true;}}
pointer++;}
if(changes){this.diff_cleanupMerge(diffs);}
this.diff_cleanupSemanticLossless(diffs);pointer=1;while(pointer<diffs.length){if(diffs[pointer-1][0]==DIFF_DELETE&&diffs[pointer][0]==DIFF_INSERT){var deletion=diffs[pointer-1][1];var insertion=diffs[pointer][1];var overlap_length1=this.diff_commonOverlap_(deletion,insertion);var overlap_length2=this.diff_commonOverlap_(insertion,deletion);if(overlap_length1>=overlap_length2){if(overlap_length1>=deletion.length/2||overlap_length1>=insertion.length/2){diffs.splice(pointer,0,[DIFF_EQUAL,insertion.substring(0,overlap_length1)]);diffs[pointer-1][1]=deletion.substring(0,deletion.length-overlap_length1);diffs[pointer+1][1]=insertion.substring(overlap_length1);pointer++;}}else{if(overlap_length2>=deletion.length/2||overlap_length2>=insertion.length/2){diffs.splice(pointer,0,[DIFF_EQUAL,deletion.substring(0,overlap_length2)]);diffs[pointer-1][0]=DIFF_INSERT;diffs[pointer-1][1]=insertion.substring(0,insertion.length-overlap_length2);diffs[pointer+1][0]=DIFF_DELETE;diffs[pointer+1][1]=deletion.substring(overlap_length2);pointer++;}}
pointer++;}
pointer++;}};diff_match_patch.prototype.diff_cleanupSemanticLossless=function(diffs){function diff_cleanupSemanticScore_(one,two){if(!one||!two){return 6;}
var char1=one.charAt(one.length-1);var char2=two.charAt(0);var nonAlphaNumeric1=char1.match(diff_match_patch.nonAlphaNumericRegex_);var nonAlphaNumeric2=char2.match(diff_match_patch.nonAlphaNumericRegex_);var whitespace1=nonAlphaNumeric1&&char1.match(diff_match_patch.whitespaceRegex_);var whitespace2=nonAlphaNumeric2&&char2.match(diff_match_patch.whitespaceRegex_);var lineBreak1=whitespace1&&char1.match(diff_match_patch.linebreakRegex_);var lineBreak2=whitespace2&&char2.match(diff_match_patch.linebreakRegex_);var blankLine1=lineBreak1&&one.match(diff_match_patch.blanklineEndRegex_);var blankLine2=lineBreak2&&two.match(diff_match_patch.blanklineStartRegex_);if(blankLine1||blankLine2){return 5;}else if(lineBreak1||lineBreak2){return 4;}else if(nonAlphaNumeric1&&!whitespace1&&whitespace2){return 3;}else if(whitespace1||whitespace2){return 2;}else if(nonAlphaNumeric1||nonAlphaNumeric2){return 1;}
return 0;}
var pointer=1;while(pointer<diffs.length-1){if(diffs[pointer-1][0]==DIFF_EQUAL&&diffs[pointer+1][0]==DIFF_EQUAL){var equality1=diffs[pointer-1][1];var edit=diffs[pointer][1];var equality2=diffs[pointer+1][1];var commonOffset=this.diff_commonSuffix(equality1,edit);if(commonOffset){var commonString=edit.substring(edit.length-commonOffset);equality1=equality1.substring(0,equality1.length-commonOffset);edit=commonString+edit.substring(0,edit.length-commonOffset);equality2=commonString+equality2;}
var bestEquality1=equality1;var bestEdit=edit;var bestEquality2=equality2;var bestScore=diff_cleanupSemanticScore_(equality1,edit)+
diff_cleanupSemanticScore_(edit,equality2);while(edit.charAt(0)===equality2.charAt(0)){equality1+=edit.charAt(0);edit=edit.substring(1)+equality2.charAt(0);equality2=equality2.substring(1);var score=diff_cleanupSemanticScore_(equality1,edit)+
diff_cleanupSemanticScore_(edit,equality2);if(score>=bestScore){bestScore=score;bestEquality1=equality1;bestEdit=edit;bestEquality2=equality2;}}
if(diffs[pointer-1][1]!=bestEquality1){if(bestEquality1){diffs[pointer-1][1]=bestEquality1;}else{diffs.splice(pointer-1,1);pointer--;}
diffs[pointer][1]=bestEdit;if(bestEquality2){diffs[pointer+1][1]=bestEquality2;}else{diffs.splice(pointer+1,1);pointer--;}}}
pointer++;}};diff_match_patch.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/;diff_match_patch.whitespaceRegex_=/\s/;diff_match_patch.linebreakRegex_=/[\r\n]/;diff_match_patch.blanklineEndRegex_=/\n\r?\n$/;diff_match_patch.blanklineStartRegex_=/^\r?\n\r?\n/;diff_match_patch.prototype.diff_cleanupEfficiency=function(diffs){var changes=false;var equalities=[];var equalitiesLength=0;var lastequality=null;var pointer=0;var pre_ins=false;var pre_del=false;var post_ins=false;var post_del=false;while(pointer<diffs.length){if(diffs[pointer][0]==DIFF_EQUAL){if(diffs[pointer][1].length<this.Diff_EditCost&&(post_ins||post_del)){equalities[equalitiesLength++]=pointer;pre_ins=post_ins;pre_del=post_del;lastequality=diffs[pointer][1];}else{equalitiesLength=0;lastequality=null;}
post_ins=post_del=false;}else{if(diffs[pointer][0]==DIFF_DELETE){post_del=true;}else{post_ins=true;}
if(lastequality&&((pre_ins&&pre_del&&post_ins&&post_del)||((lastequality.length<this.Diff_EditCost/2)&&(pre_ins+pre_del+post_ins+post_del)==3))){diffs.splice(equalities[equalitiesLength-1],0,[DIFF_DELETE,lastequality]);diffs[equalities[equalitiesLength-1]+1][0]=DIFF_INSERT;equalitiesLength--;lastequality=null;if(pre_ins&&pre_del){post_ins=post_del=true;equalitiesLength=0;}else{equalitiesLength--;pointer=equalitiesLength>0?equalities[equalitiesLength-1]:-1;post_ins=post_del=false;}
changes=true;}}
pointer++;}
if(changes){this.diff_cleanupMerge(diffs);}};diff_match_patch.prototype.diff_cleanupMerge=function(diffs){diffs.push([DIFF_EQUAL,'']);var pointer=0;var count_delete=0;var count_insert=0;var text_delete='';var text_insert='';var commonlength;while(pointer<diffs.length){switch(diffs[pointer][0]){case DIFF_INSERT:count_insert++;text_insert+=diffs[pointer][1];pointer++;break;case DIFF_DELETE:count_delete++;text_delete+=diffs[pointer][1];pointer++;break;case DIFF_EQUAL:if(count_delete+count_insert>1){if(count_delete!==0&&count_insert!==0){commonlength=this.diff_commonPrefix(text_insert,text_delete);if(commonlength!==0){if((pointer-count_delete-count_insert)>0&&diffs[pointer-count_delete-count_insert-1][0]==DIFF_EQUAL){diffs[pointer-count_delete-count_insert-1][1]+=text_insert.substring(0,commonlength);}else{diffs.splice(0,0,[DIFF_EQUAL,text_insert.substring(0,commonlength)]);pointer++;}
text_insert=text_insert.substring(commonlength);text_delete=text_delete.substring(commonlength);}
commonlength=this.diff_commonSuffix(text_insert,text_delete);if(commonlength!==0){diffs[pointer][1]=text_insert.substring(text_insert.length-
commonlength)+diffs[pointer][1];text_insert=text_insert.substring(0,text_insert.length-
commonlength);text_delete=text_delete.substring(0,text_delete.length-
commonlength);}}
if(count_delete===0){diffs.splice(pointer-count_insert,count_delete+count_insert,[DIFF_INSERT,text_insert]);}else if(count_insert===0){diffs.splice(pointer-count_delete,count_delete+count_insert,[DIFF_DELETE,text_delete]);}else{diffs.splice(pointer-count_delete-count_insert,count_delete+count_insert,[DIFF_DELETE,text_delete],[DIFF_INSERT,text_insert]);}
pointer=pointer-count_delete-count_insert+
(count_delete?1:0)+(count_insert?1:0)+1;}else if(pointer!==0&&diffs[pointer-1][0]==DIFF_EQUAL){diffs[pointer-1][1]+=diffs[pointer][1];diffs.splice(pointer,1);}else{pointer++;}
count_insert=0;count_delete=0;text_delete='';text_insert='';break;}}
if(diffs[diffs.length-1][1]===''){diffs.pop();}
var changes=false;pointer=1;while(pointer<diffs.length-1){if(diffs[pointer-1][0]==DIFF_EQUAL&&diffs[pointer+1][0]==DIFF_EQUAL){if(diffs[pointer][1].substring(diffs[pointer][1].length-
diffs[pointer-1][1].length)==diffs[pointer-1][1]){diffs[pointer][1]=diffs[pointer-1][1]+
diffs[pointer][1].substring(0,diffs[pointer][1].length-
diffs[pointer-1][1].length);diffs[pointer+1][1]=diffs[pointer-1][1]+diffs[pointer+1][1];diffs.splice(pointer-1,1);changes=true;}else if(diffs[pointer][1].substring(0,diffs[pointer+1][1].length)==diffs[pointer+1][1]){diffs[pointer-1][1]+=diffs[pointer+1][1];diffs[pointer][1]=diffs[pointer][1].substring(diffs[pointer+1][1].length)+
diffs[pointer+1][1];diffs.splice(pointer+1,1);changes=true;}}
pointer++;}
if(changes){this.diff_cleanupMerge(diffs);}};diff_match_patch.prototype.diff_xIndex=function(diffs,loc){var chars1=0;var chars2=0;var last_chars1=0;var last_chars2=0;var x;for(x=0;x<diffs.length;x++){if(diffs[x][0]!==DIFF_INSERT){chars1+=diffs[x][1].length;}
if(diffs[x][0]!==DIFF_DELETE){chars2+=diffs[x][1].length;}
if(chars1>loc){break;}
last_chars1=chars1;last_chars2=chars2;}
if(diffs.length!=x&&diffs[x][0]===DIFF_DELETE){return last_chars2;}
return last_chars2+(loc-last_chars1);};diff_match_patch.prototype.diff_prettyHtml=function(diffs){var html=[];var pattern_amp=/&/g;var pattern_lt=/</g;var pattern_gt=/>/g;var pattern_para=/\n/g;for(var x=0;x<diffs.length;x++){var op=diffs[x][0];var data=diffs[x][1];var text=data.replace(pattern_amp,'&amp;').replace(pattern_lt,'&lt;').replace(pattern_gt,'&gt;').replace(pattern_para,'&para;<br>');switch(op){case DIFF_INSERT:html[x]='<ins style="background:#e6ffe6;">'+text+'</ins>';break;case DIFF_DELETE:html[x]='<del style="background:#ffe6e6;">'+text+'</del>';break;case DIFF_EQUAL:html[x]='<span>'+text+'</span>';break;}}
return html.join('');};diff_match_patch.prototype.diff_text1=function(diffs){var text=[];for(var x=0;x<diffs.length;x++){if(diffs[x][0]!==DIFF_INSERT){text[x]=diffs[x][1];}}
return text.join('');};diff_match_patch.prototype.diff_text2=function(diffs){var text=[];for(var x=0;x<diffs.length;x++){if(diffs[x][0]!==DIFF_DELETE){text[x]=diffs[x][1];}}
return text.join('');};diff_match_patch.prototype.diff_levenshtein=function(diffs){var levenshtein=0;var insertions=0;var deletions=0;for(var x=0;x<diffs.length;x++){var op=diffs[x][0];var data=diffs[x][1];switch(op){case DIFF_INSERT:insertions+=data.length;break;case DIFF_DELETE:deletions+=data.length;break;case DIFF_EQUAL:levenshtein+=Math.max(insertions,deletions);insertions=0;deletions=0;break;}}
levenshtein+=Math.max(insertions,deletions);return levenshtein;};diff_match_patch.prototype.diff_toDelta=function(diffs){var text=[];for(var x=0;x<diffs.length;x++){switch(diffs[x][0]){case DIFF_INSERT:text[x]='+'+encodeURI(diffs[x][1]);break;case DIFF_DELETE:text[x]='-'+diffs[x][1].length;break;case DIFF_EQUAL:text[x]='='+diffs[x][1].length;break;}}
return text.join('\t').replace(/%20/g,' ');};diff_match_patch.prototype.diff_fromDelta=function(text1,delta){var diffs=[];var diffsLength=0;var pointer=0;var tokens=delta.split(/\t/g);for(var x=0;x<tokens.length;x++){var param=tokens[x].substring(1);switch(tokens[x].charAt(0)){case'+':try{diffs[diffsLength++]=[DIFF_INSERT,decodeURI(param)];}catch(ex){throw new Error('Illegal escape in diff_fromDelta: '+param);}
break;case'-':case'=':var n=parseInt(param,10);if(isNaN(n)||n<0){throw new Error('Invalid number in diff_fromDelta: '+param);}
var text=text1.substring(pointer,pointer+=n);if(tokens[x].charAt(0)=='='){diffs[diffsLength++]=[DIFF_EQUAL,text];}else{diffs[diffsLength++]=[DIFF_DELETE,text];}
break;default:if(tokens[x]){throw new Error('Invalid diff operation in diff_fromDelta: '+
tokens[x]);}}}
if(pointer!=text1.length){throw new Error('Delta length ('+pointer+') does not equal source text length ('+text1.length+').');}
return diffs;};diff_match_patch.prototype.match_main=function(text,pattern,loc){if(text==null||pattern==null||loc==null){throw new Error('Null input. (match_main)');}
loc=Math.max(0,Math.min(loc,text.length));if(text==pattern){return 0;}else if(!text.length){return-1;}else if(text.substring(loc,loc+pattern.length)==pattern){return loc;}else{return this.match_bitap_(text,pattern,loc);}};diff_match_patch.prototype.match_bitap_=function(text,pattern,loc){if(pattern.length>this.Match_MaxBits){throw new Error('Pattern too long for this browser.');}
var s=this.match_alphabet_(pattern);var dmp=this;function match_bitapScore_(e,x){var accuracy=e/pattern.length;var proximity=Math.abs(loc-x);if(!dmp.Match_Distance){return proximity?1.0:accuracy;}
return accuracy+(proximity/dmp.Match_Distance);}
var score_threshold=this.Match_Threshold;var best_loc=text.indexOf(pattern,loc);if(best_loc!=-1){score_threshold=Math.min(match_bitapScore_(0,best_loc),score_threshold);best_loc=text.lastIndexOf(pattern,loc+pattern.length);if(best_loc!=-1){score_threshold=Math.min(match_bitapScore_(0,best_loc),score_threshold);}}
var matchmask=1<<(pattern.length-1);best_loc=-1;var bin_min,bin_mid;var bin_max=pattern.length+text.length;var last_rd;for(var d=0;d<pattern.length;d++){bin_min=0;bin_mid=bin_max;while(bin_min<bin_mid){if(match_bitapScore_(d,loc+bin_mid)<=score_threshold){bin_min=bin_mid;}else{bin_max=bin_mid;}
bin_mid=Math.floor((bin_max-bin_min)/2+bin_min);}
bin_max=bin_mid;var start=Math.max(1,loc-bin_mid+1);var finish=Math.min(loc+bin_mid,text.length)+pattern.length;var rd=Array(finish+2);rd[finish+1]=(1<<d)-1;for(var j=finish;j>=start;j--){var charMatch=s[text.charAt(j-1)];if(d===0){rd[j]=((rd[j+1]<<1)|1)&charMatch;}else{rd[j]=(((rd[j+1]<<1)|1)&charMatch)|(((last_rd[j+1]|last_rd[j])<<1)|1)|last_rd[j+1];}
if(rd[j]&matchmask){var score=match_bitapScore_(d,j-1);if(score<=score_threshold){score_threshold=score;best_loc=j-1;if(best_loc>loc){start=Math.max(1,2*loc-best_loc);}else{break;}}}}
if(match_bitapScore_(d+1,loc)>score_threshold){break;}
last_rd=rd;}
return best_loc;};diff_match_patch.prototype.match_alphabet_=function(pattern){var s={};for(var i=0;i<pattern.length;i++){s[pattern.charAt(i)]=0;}
for(var i=0;i<pattern.length;i++){s[pattern.charAt(i)]|=1<<(pattern.length-i-1);}
return s;};diff_match_patch.prototype.patch_addContext_=function(patch,text){if(text.length==0){return;}
var pattern=text.substring(patch.start2,patch.start2+patch.length1);var padding=0;while(text.indexOf(pattern)!=text.lastIndexOf(pattern)&&pattern.length<this.Match_MaxBits-this.Patch_Margin-
this.Patch_Margin){padding+=this.Patch_Margin;pattern=text.substring(patch.start2-padding,patch.start2+patch.length1+padding);}
padding+=this.Patch_Margin;var prefix=text.substring(patch.start2-padding,patch.start2);if(prefix){patch.diffs.unshift([DIFF_EQUAL,prefix]);}
var suffix=text.substring(patch.start2+patch.length1,patch.start2+patch.length1+padding);if(suffix){patch.diffs.push([DIFF_EQUAL,suffix]);}
patch.start1-=prefix.length;patch.start2-=prefix.length;patch.length1+=prefix.length+suffix.length;patch.length2+=prefix.length+suffix.length;};diff_match_patch.prototype.patch_make=function(a,opt_b,opt_c){var text1,diffs;if(typeof a=='string'&&typeof opt_b=='string'&&typeof opt_c=='undefined'){text1=(a);diffs=this.diff_main(text1,(opt_b),true);if(diffs.length>2){this.diff_cleanupSemantic(diffs);this.diff_cleanupEfficiency(diffs);}}else if(a&&typeof a=='object'&&typeof opt_b=='undefined'&&typeof opt_c=='undefined'){diffs=(a);text1=this.diff_text1(diffs);}else if(typeof a=='string'&&opt_b&&typeof opt_b=='object'&&typeof opt_c=='undefined'){text1=(a);diffs=(opt_b);}else if(typeof a=='string'&&typeof opt_b=='string'&&opt_c&&typeof opt_c=='object'){text1=(a);diffs=(opt_c);}else{throw new Error('Unknown call format to patch_make.');}
if(diffs.length===0){return[];}
var patches=[];var patch=new diff_match_patch.patch_obj();var patchDiffLength=0;var char_count1=0;var char_count2=0;var prepatch_text=text1;var postpatch_text=text1;for(var x=0;x<diffs.length;x++){var diff_type=diffs[x][0];var diff_text=diffs[x][1];if(!patchDiffLength&&diff_type!==DIFF_EQUAL){patch.start1=char_count1;patch.start2=char_count2;}
switch(diff_type){case DIFF_INSERT:patch.diffs[patchDiffLength++]=diffs[x];patch.length2+=diff_text.length;postpatch_text=postpatch_text.substring(0,char_count2)+diff_text+
postpatch_text.substring(char_count2);break;case DIFF_DELETE:patch.length1+=diff_text.length;patch.diffs[patchDiffLength++]=diffs[x];postpatch_text=postpatch_text.substring(0,char_count2)+
postpatch_text.substring(char_count2+
diff_text.length);break;case DIFF_EQUAL:if(diff_text.length<=2*this.Patch_Margin&&patchDiffLength&&diffs.length!=x+1){patch.diffs[patchDiffLength++]=diffs[x];patch.length1+=diff_text.length;patch.length2+=diff_text.length;}else if(diff_text.length>=2*this.Patch_Margin){if(patchDiffLength){this.patch_addContext_(patch,prepatch_text);patches.push(patch);patch=new diff_match_patch.patch_obj();patchDiffLength=0;prepatch_text=postpatch_text;char_count1=char_count2;}}
break;}
if(diff_type!==DIFF_INSERT){char_count1+=diff_text.length;}
if(diff_type!==DIFF_DELETE){char_count2+=diff_text.length;}}
if(patchDiffLength){this.patch_addContext_(patch,prepatch_text);patches.push(patch);}
return patches;};diff_match_patch.prototype.patch_deepCopy=function(patches){var patchesCopy=[];for(var x=0;x<patches.length;x++){var patch=patches[x];var patchCopy=new diff_match_patch.patch_obj();patchCopy.diffs=[];for(var y=0;y<patch.diffs.length;y++){patchCopy.diffs[y]=patch.diffs[y].slice();}
patchCopy.start1=patch.start1;patchCopy.start2=patch.start2;patchCopy.length1=patch.length1;patchCopy.length2=patch.length2;patchesCopy[x]=patchCopy;}
return patchesCopy;};diff_match_patch.prototype.patch_apply=function(patches,text){if(patches.length==0){return[text,[]];}
patches=this.patch_deepCopy(patches);var nullPadding=this.patch_addPadding(patches);text=nullPadding+text+nullPadding;this.patch_splitMax(patches);var delta=0;var results=[];for(var x=0;x<patches.length;x++){var expected_loc=patches[x].start2+delta;var text1=this.diff_text1(patches[x].diffs);var start_loc;var end_loc=-1;if(text1.length>this.Match_MaxBits){start_loc=this.match_main(text,text1.substring(0,this.Match_MaxBits),expected_loc);if(start_loc!=-1){end_loc=this.match_main(text,text1.substring(text1.length-this.Match_MaxBits),expected_loc+text1.length-this.Match_MaxBits);if(end_loc==-1||start_loc>=end_loc){start_loc=-1;}}}else{start_loc=this.match_main(text,text1,expected_loc);}
if(start_loc==-1){results[x]=false;delta-=patches[x].length2-patches[x].length1;}else{results[x]=true;delta=start_loc-expected_loc;var text2;if(end_loc==-1){text2=text.substring(start_loc,start_loc+text1.length);}else{text2=text.substring(start_loc,end_loc+this.Match_MaxBits);}
if(text1==text2){text=text.substring(0,start_loc)+
this.diff_text2(patches[x].diffs)+
text.substring(start_loc+text1.length);}else{var diffs=this.diff_main(text1,text2,false);if(text1.length>this.Match_MaxBits&&this.diff_levenshtein(diffs)/text1.length>this.Patch_DeleteThreshold){results[x]=false;}else{this.diff_cleanupSemanticLossless(diffs);var index1=0;var index2;for(var y=0;y<patches[x].diffs.length;y++){var mod=patches[x].diffs[y];if(mod[0]!==DIFF_EQUAL){index2=this.diff_xIndex(diffs,index1);}
if(mod[0]===DIFF_INSERT){text=text.substring(0,start_loc+index2)+mod[1]+
text.substring(start_loc+index2);}else if(mod[0]===DIFF_DELETE){text=text.substring(0,start_loc+index2)+
text.substring(start_loc+this.diff_xIndex(diffs,index1+mod[1].length));}
if(mod[0]!==DIFF_DELETE){index1+=mod[1].length;}}}}}}
text=text.substring(nullPadding.length,text.length-nullPadding.length);return[text,results];};diff_match_patch.prototype.patch_addPadding=function(patches){var paddingLength=this.Patch_Margin;var nullPadding='';for(var x=1;x<=paddingLength;x++){nullPadding+=String.fromCharCode(x);}
for(var x=0;x<patches.length;x++){patches[x].start1+=paddingLength;patches[x].start2+=paddingLength;}
var patch=patches[0];var diffs=patch.diffs;if(diffs.length==0||diffs[0][0]!=DIFF_EQUAL){diffs.unshift([DIFF_EQUAL,nullPadding]);patch.start1-=paddingLength;patch.start2-=paddingLength;patch.length1+=paddingLength;patch.length2+=paddingLength;}else if(paddingLength>diffs[0][1].length){var extraLength=paddingLength-diffs[0][1].length;diffs[0][1]=nullPadding.substring(diffs[0][1].length)+diffs[0][1];patch.start1-=extraLength;patch.start2-=extraLength;patch.length1+=extraLength;patch.length2+=extraLength;}
patch=patches[patches.length-1];diffs=patch.diffs;if(diffs.length==0||diffs[diffs.length-1][0]!=DIFF_EQUAL){diffs.push([DIFF_EQUAL,nullPadding]);patch.length1+=paddingLength;patch.length2+=paddingLength;}else if(paddingLength>diffs[diffs.length-1][1].length){var extraLength=paddingLength-diffs[diffs.length-1][1].length;diffs[diffs.length-1][1]+=nullPadding.substring(0,extraLength);patch.length1+=extraLength;patch.length2+=extraLength;}
return nullPadding;};diff_match_patch.prototype.patch_splitMax=function(patches){var patch_size=this.Match_MaxBits;for(var x=0;x<patches.length;x++){if(patches[x].length1<=patch_size){continue;}
var bigpatch=patches[x];patches.splice(x--,1);var start1=bigpatch.start1;var start2=bigpatch.start2;var precontext='';while(bigpatch.diffs.length!==0){var patch=new diff_match_patch.patch_obj();var empty=true;patch.start1=start1-precontext.length;patch.start2=start2-precontext.length;if(precontext!==''){patch.length1=patch.length2=precontext.length;patch.diffs.push([DIFF_EQUAL,precontext]);}
while(bigpatch.diffs.length!==0&&patch.length1<patch_size-this.Patch_Margin){var diff_type=bigpatch.diffs[0][0];var diff_text=bigpatch.diffs[0][1];if(diff_type===DIFF_INSERT){patch.length2+=diff_text.length;start2+=diff_text.length;patch.diffs.push(bigpatch.diffs.shift());empty=false;}else if(diff_type===DIFF_DELETE&&patch.diffs.length==1&&patch.diffs[0][0]==DIFF_EQUAL&&diff_text.length>2*patch_size){patch.length1+=diff_text.length;start1+=diff_text.length;empty=false;patch.diffs.push([diff_type,diff_text]);bigpatch.diffs.shift();}else{diff_text=diff_text.substring(0,patch_size-patch.length1-this.Patch_Margin);patch.length1+=diff_text.length;start1+=diff_text.length;if(diff_type===DIFF_EQUAL){patch.length2+=diff_text.length;start2+=diff_text.length;}else{empty=false;}
patch.diffs.push([diff_type,diff_text]);if(diff_text==bigpatch.diffs[0][1]){bigpatch.diffs.shift();}else{bigpatch.diffs[0][1]=bigpatch.diffs[0][1].substring(diff_text.length);}}}
precontext=this.diff_text2(patch.diffs);precontext=precontext.substring(precontext.length-this.Patch_Margin);var postcontext=this.diff_text1(bigpatch.diffs).substring(0,this.Patch_Margin);if(postcontext!==''){patch.length1+=postcontext.length;patch.length2+=postcontext.length;if(patch.diffs.length!==0&&patch.diffs[patch.diffs.length-1][0]===DIFF_EQUAL){patch.diffs[patch.diffs.length-1][1]+=postcontext;}else{patch.diffs.push([DIFF_EQUAL,postcontext]);}}
if(!empty){patches.splice(++x,0,patch);}}}};diff_match_patch.prototype.patch_toText=function(patches){var text=[];for(var x=0;x<patches.length;x++){text[x]=patches[x];}
return text.join('');};diff_match_patch.prototype.patch_fromText=function(textline){var patches=[];if(!textline){return patches;}
var text=textline.split('\n');var textPointer=0;var patchHeader=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;while(textPointer<text.length){var m=text[textPointer].match(patchHeader);if(!m){throw new Error('Invalid patch string: '+text[textPointer]);}
var patch=new diff_match_patch.patch_obj();patches.push(patch);patch.start1=parseInt(m[1],10);if(m[2]===''){patch.start1--;patch.length1=1;}else if(m[2]=='0'){patch.length1=0;}else{patch.start1--;patch.length1=parseInt(m[2],10);}
patch.start2=parseInt(m[3],10);if(m[4]===''){patch.start2--;patch.length2=1;}else if(m[4]=='0'){patch.length2=0;}else{patch.start2--;patch.length2=parseInt(m[4],10);}
textPointer++;while(textPointer<text.length){var sign=text[textPointer].charAt(0);try{var line=decodeURI(text[textPointer].substring(1));}catch(ex){throw new Error('Illegal escape in patch_fromText: '+line);}
if(sign=='-'){patch.diffs.push([DIFF_DELETE,line]);}else if(sign=='+'){patch.diffs.push([DIFF_INSERT,line]);}else if(sign==' '){patch.diffs.push([DIFF_EQUAL,line]);}else if(sign=='@'){break;}else if(sign===''){}else{throw new Error('Invalid patch mode "'+sign+'" in: '+line);}
textPointer++;}}
return patches;};diff_match_patch.patch_obj=function(){this.diffs=[];this.start1=null;this.start2=null;this.length1=0;this.length2=0;};diff_match_patch.patch_obj.prototype.toString=function(){var coords1,coords2;if(this.length1===0){coords1=this.start1+',0';}else if(this.length1==1){coords1=this.start1+1;}else{coords1=(this.start1+1)+','+this.length1;}
if(this.length2===0){coords2=this.start2+',0';}else if(this.length2==1){coords2=this.start2+1;}else{coords2=(this.start2+1)+','+this.length2;}
var text=['@@ -'+coords1+' +'+coords2+' @@\n'];var op;for(var x=0;x<this.diffs.length;x++){switch(this.diffs[x][0]){case DIFF_INSERT:op='+';break;case DIFF_DELETE:op='-';break;case DIFF_EQUAL:op=' ';break;}
text[x+1]=op+encodeURI(this.diffs[x][1])+'\n';}
return text.join('').replace(/%20/g,' ');};this['diff_match_patch']=diff_match_patch;this['DIFF_DELETE']=DIFF_DELETE;this['DIFF_INSERT']=DIFF_INSERT;this['DIFF_EQUAL']=DIFF_EQUAL;(function(){var fieldSelection={getSelection:function(){var e=this.jquery?this[0]:this;return(('selectionStart'in e&&function(){var l=e.selectionEnd-e.selectionStart;return{start:e.selectionStart,end:e.selectionEnd,length:l,text:e.value.substr(e.selectionStart,l)};})||(document.selection&&function(){e.focus();var r=document.selection.createRange();if(r==null){return{start:0,end:e.value.length,length:0}}
var re=e.createTextRange();var rc=re.duplicate();re.moveToBookmark(r.getBookmark());rc.setEndPoint('EndToStart',re);return{start:rc.text.length,end:rc.text.length+r.text.length,length:r.text.length,text:r.text};})||function(){return{start:0,end:e.value.length,length:0};})();},replaceSelection:function(){var e=this.jquery?this[0]:this;var text=arguments[0]||'';return(('selectionStart'in e&&function(){e.value=e.value.substr(0,e.selectionStart)+text+e.value.substr(e.selectionEnd,e.value.length);return this;})||(document.selection&&function(){e.focus();document.selection.createRange().text=text;return this;})||function(){e.value+=text;return this;})();}};jQuery.each(fieldSelection,function(i){jQuery.fn[i]=this;});})();﻿(function($,len,createRange,duplicate){$.fn.caret=function(options,opt2){var start,end,t=this[0],browser=$.browser.msie;if(typeof options==="object"&&typeof options.start==="number"&&typeof options.end==="number"){start=options.start;end=options.end;}else if(typeof options==="number"&&typeof opt2==="number"){start=options;end=opt2;}else if(typeof options==="string"){if((start=t.value.indexOf(options))>-1)end=start+options[len];else start=null;}else if(Object.prototype.toString.call(options)==="[object RegExp]"){var re=options.exec(t.value);if(re!=null){start=re.index;end=start+re[0][len];}}
if(typeof start!="undefined"){if(browser){var selRange=this[0].createTextRange();selRange.collapse(true);selRange.moveStart('character',start);selRange.moveEnd('character',end-start);selRange.select();}else{this[0].selectionStart=start;this[0].selectionEnd=end;}
this[0].focus();return this}else{if(browser){var selection=document.selection;if(this[0].tagName.toLowerCase()!="textarea"){var val=this.val(),range=selection[createRange]()[duplicate]();range.moveEnd("character",val[len]);var s=(range.text==""?val[len]:val.lastIndexOf(range.text));range=selection[createRange]()[duplicate]();range.moveStart("character",-val[len]);var e=range.text[len];}else{var range=selection[createRange](),stored_range=range[duplicate]();stored_range.moveToElementText(this[0]);stored_range.setEndPoint('EndToEnd',range);var s=stored_range.text[len]-range.text[len],e=s+range.text[len]}}else{var s=t.selectionStart,e=t.selectionEnd;}
var te=t.value.substring(s,e);return{start:s,end:e,text:te,replace:function(st){return t.value.substring(0,s)+st+t.value.substring(e,t.value[len])}}}}})(jQuery,"length","createRange","duplicate");(function($){$.fn.highlightRegex=function(regex){if(regex==undefined||regex.source==''){$(this).find('span.highlight').each(function(){$(this).replaceWith($(this).text());$(this).parent().each(function(){node=$(this).get(0);if(node.normalize)node.normalize();});});}else{$(this).each(function(){elt=$(this).get(0)
elt.normalize();$.each($.makeArray(elt.childNodes),function(i,node){if(node.nodeType==3){var searchnode=node
while((pos=searchnode.data.search(regex))>=0){match=searchnode.data.slice(pos).match(regex)[0];if(match.length==0)break;var spannode=document.createElement('span');spannode.className='highlight';var middlebit=searchnode.splitText(pos);var searchnode=middlebit.splitText(match.length);var middleclone=middlebit.cloneNode(true);spannode.appendChild(middleclone);searchnode.parentNode.replaceChild(spannode,middlebit);}}else{$(node).highlightRegex(regex);}})})}
return $(this);}})(jQuery);(function($){function noop(){}
function genericCallback(data){lastValue=[data];}
function callIfDefined(method,object,parameters){return method&&method.apply&&method.apply(object.context||object,parameters);}
function qMarkOrAmp(url){return/\?/.test(url)?"&":"?";}
var
STR_ASYNC="async",STR_CHARSET="charset",STR_EMPTY="",STR_ERROR="error",STR_INSERT_BEFORE="insertBefore",STR_JQUERY_JSONP="_jqjsp",STR_ON="on",STR_ON_CLICK=STR_ON+"click",STR_ON_ERROR=STR_ON+STR_ERROR,STR_ON_LOAD=STR_ON+"load",STR_ON_READY_STATE_CHANGE=STR_ON+"readystatechange",STR_READY_STATE="readyState",STR_REMOVE_CHILD="removeChild",STR_SCRIPT_TAG="<script>",STR_SUCCESS="success",STR_TIMEOUT="timeout",win=window,Deferred=$.Deferred,head=$("head")[0]||document.documentElement,pageCache={},count=0,lastValue,xOptionsDefaults={callback:STR_JQUERY_JSONP,url:location.href},opera=win.opera,oldIE=!!$("<div>").html("<!--[if IE]><i><![endif]-->").find("i").length;function jsonp(xOptions){xOptions=$.extend({},xOptionsDefaults,xOptions);var successCallback=xOptions.success,errorCallback=xOptions.error,completeCallback=xOptions.complete,dataFilter=xOptions.dataFilter,callbackParameter=xOptions.callbackParameter,successCallbackName=xOptions.callback,cacheFlag=xOptions.cache,pageCacheFlag=xOptions.pageCache,charset=xOptions.charset,url=xOptions.url,data=xOptions.data,timeout=xOptions.timeout,pageCached,done=0,cleanUp=noop,supportOnload,supportOnreadystatechange,firstChild,script,scriptAfter,timeoutTimer;Deferred&&Deferred(function(defer){defer.done(successCallback).fail(errorCallback);successCallback=defer.resolve;errorCallback=defer.reject;}).promise(xOptions);xOptions.abort=function(){!(done++)&&cleanUp();};if(callIfDefined(xOptions.beforeSend,xOptions,[xOptions])===!1||done){return xOptions;}
url=url||STR_EMPTY;data=data?((typeof data)=="string"?data:$.param(data,xOptions.traditional)):STR_EMPTY;url+=data?(qMarkOrAmp(url)+data):STR_EMPTY;callbackParameter&&(url+=qMarkOrAmp(url)+encodeURIComponent(callbackParameter)+"=?");!cacheFlag&&!pageCacheFlag&&(url+=qMarkOrAmp(url)+"_"+(new Date()).getTime()+"=");url=url.replace(/=\?(&|$)/,"="+successCallbackName+"$1");function notifySuccess(json){if(!(done++)){cleanUp();pageCacheFlag&&(pageCache[url]={s:[json]});dataFilter&&(json=dataFilter.apply(xOptions,[json]));callIfDefined(successCallback,xOptions,[json,STR_SUCCESS,xOptions]);callIfDefined(completeCallback,xOptions,[xOptions,STR_SUCCESS]);}}
function notifyError(type){if(!(done++)){cleanUp();pageCacheFlag&&type!=STR_TIMEOUT&&(pageCache[url]=type);callIfDefined(errorCallback,xOptions,[xOptions,type]);callIfDefined(completeCallback,xOptions,[xOptions,type]);}}
if(pageCacheFlag&&(pageCached=pageCache[url])){pageCached.s?notifySuccess(pageCached.s[0]):notifyError(pageCached);}else{win[successCallbackName]=genericCallback;script=$(STR_SCRIPT_TAG)[0];script.id=STR_JQUERY_JSONP+count++;if(charset){script[STR_CHARSET]=charset;}
opera&&opera.version()<11.60?((scriptAfter=$(STR_SCRIPT_TAG)[0]).text="document.getElementById('"+script.id+"')."+STR_ON_ERROR+"()"):(script[STR_ASYNC]=STR_ASYNC);if(oldIE){script.htmlFor=script.id;script.event=STR_ON_CLICK;}
script[STR_ON_LOAD]=script[STR_ON_ERROR]=script[STR_ON_READY_STATE_CHANGE]=function(result){if(!script[STR_READY_STATE]||!/i/.test(script[STR_READY_STATE])){try{script[STR_ON_CLICK]&&script[STR_ON_CLICK]();}catch(_){}
result=lastValue;lastValue=0;result?notifySuccess(result[0]):notifyError(STR_ERROR);}};script.src=url;cleanUp=function(i){timeoutTimer&&clearTimeout(timeoutTimer);script[STR_ON_READY_STATE_CHANGE]=script[STR_ON_LOAD]=script[STR_ON_ERROR]=null;head[STR_REMOVE_CHILD](script);scriptAfter&&head[STR_REMOVE_CHILD](scriptAfter);};head[STR_INSERT_BEFORE](script,(firstChild=head.firstChild));scriptAfter&&head[STR_INSERT_BEFORE](scriptAfter,firstChild);timeoutTimer=timeout>0&&setTimeout(function(){notifyError(STR_TIMEOUT);},timeout);}
return xOptions;}
jsonp.setup=function(xOptions){$.extend(xOptionsDefaults,xOptions);};$.jsonp=jsonp;})(jQuery);(function(Date,undefined){var origParse=Date.parse,numericKeys=[1,4,5,6,7,10,11];Date.parse=function(date){var timestamp,struct,minutesOffset=0;if((struct=/^(\d{4}|[+\-]\d{6})(?:-(\d{2})(?:-(\d{2}))?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?(?:(Z)|([+\-])(\d{2})(?::(\d{2}))?)?)?$/.exec(date))){for(var i=0,k;(k=numericKeys[i]);++i){struct[k]=+struct[k]||0;}
struct[2]=(+struct[2]||1)-1;struct[3]=+struct[3]||1;if(struct[8]!=='Z'&&struct[9]!==undefined){minutesOffset=struct[10]*60+struct[11];if(struct[9]==='+'){minutesOffset=0-minutesOffset;}}
timestamp=Date.UTC(struct[1],struct[2],struct[3],struct[4],struct[5]+minutesOffset,struct[6],struct[7]);}
else{timestamp=origParse?origParse(date):NaN;}
return timestamp;};}(Date));(function($){window.PTL=window.PTL||{};PTL.editor={init:function(options){this.settings={secure:false,mt:[]};if(options){$.extend(this.settings,options);}
this.units={};this.store=$("#editor").data("pootle-path");this.directory=$("#editor").data("directory");this.currentPage=1;this.currentNumPages=0;this.pagesGot={};this.filter="all";this.checks=[];this.ctxGap=0;this.ctxQty=parseInt($.cookie('ctxQty'))||1;this.ctxStep=1;this.keepState=false;this.preventNavigation=false;this.isLoading=true;this.showActivity();this.searchFields=[];this.cpRE=/^(<[^>]+>|\[n\|t]|\W$^\n)*(\b|$)/gm;this.escapeRE=/<[^<]*?>|\r\n|[\r\n\t&<>]/gm;this.whitespaceRE=/^ +| +$|[\r\n\t] +| {2,}/gm;this.timelineReq=null;this.tmReq=null;this.differencer=new diff_match_patch();this.tmpl={vUnit:$.template($("#view_unit").html()),tm:$.template($("#tm_suggestions").html()),editCtx:$.template($("#editCtx").html())}
PTL.search.init();$(document).on("keyup blur","textarea.translation",function(){if(!PTL.editor.keepState&&$(this).prop("defaultValue")!=$(this).val()){PTL.editor.ungoFuzzy();}});$(document).on("click","input.fuzzycheck",function(){if(PTL.editor.isFuzzy()){PTL.editor.doFuzzyArea();}else{PTL.editor.undoFuzzyArea();}});$(document).on("click",".switch-suggest-mode a",function(){PTL.editor.toggleSuggestMode();return false;});$(document).on("focus",".focusthis",function(e){PTL.editor.focused=e.target;});$(document).on("click",".js-editor-copytext",this.copyText);$(document).on("click",".js-copyoriginal",function(){var sources=$(".translation-text",$(this).parent().parent().parent());PTL.editor.copyOriginal(sources);});$(document).on("click","div.suggestion",function(){if(PTL.editor.getSelectedText()!=""){return;}
if($("#id_target_f_0").attr("disabled")){return;}
var sources=$(".suggestion-translation",this);PTL.editor.copyOriginal(sources);});$(document).on("editor_ready","table.translate-table",this.ready);$(document).on("noResults","table.translate-table",this.noResults);$(document).on("mouseup","tr.view-row, tr.ctx-row",this.gotoUnit);$(document).on("keypress","#item-number",function(e){if(e.which===13){PTL.editor.gotoPage(parseInt($("#item-number").val()));}});$(document).on("click","input.submit",this.submit);$(document).on("click","input.suggest",this.suggest);$(document).on("click","#js-nav-prev, #js-nav-next",this.gotoPrevNext);$(document).on("click",".js-suggestion-reject",this.rejectSuggestion);$(document).on("click",".js-suggestion-accept",this.acceptSuggestion);$(document).on("click",".js-vote-clear",this.clearVote);$(document).on("click",".js-vote-up",this.voteUp);$(document).on("click","#js-show-timeline",this.showTimeline);$(document).on("click","#js-hide-timeline",this.hideTimeline);$(document).on("click","#translate-checks-block .js-reject-check",this.rejectCheck);$(document).on("change","#filter-status select",this.filterStatus);$(document).on("change","#filter-checks select",this.filterChecks);$(document).on("click",".js-more-ctx",function(){PTL.editor.moreContext(false)});$(document).on("click",".js-less-ctx",this.lessContext);$(document).on("click",".js-show-ctx",this.showContext);$(document).on("click",".js-hide-ctx",this.hideContext);$(document).on("click",".js-editor-comment",function(e){e.preventDefault();$("#editor-comment").slideToggle("fast");});$(document).on("submit","#comment-form",this.comment);$(document).on("submit","#search-form",function(e){e.preventDefault();PTL.editor.search()});$(document).on("keypress","#id_search",function(e){if(e.which===13){e.preventDefault();PTL.editor.search();}});$(document).on("click",".js-editor-msg-hide",this.hideMsg);shortcut.add('ctrl+return',function(){if(PTL.editor.isSuggestMode()){$("input.suggest").trigger("click");}else{$("input.submit").trigger("click");}});shortcut.add('ctrl+space',function(e){if(e&&e.preventDefault){e.preventDefault();}
PTL.editor.keepState=true;if(PTL.editor.isFuzzy()){PTL.editor.ungoFuzzy();}else{PTL.editor.goFuzzy();}});shortcut.add('ctrl+shift+space',function(){PTL.editor.toggleSuggestMode();});shortcut.add('ctrl+up',function(){$("#js-nav-prev").trigger("click");});shortcut.add('ctrl+down',function(){$("#js-nav-next").trigger("click");});shortcut.add('ctrl+shift+home',function(){PTL.editor.gotoFirstPage();});shortcut.add('ctrl+shift+end',function(){PTL.editor.gotoLastPage();});shortcut.add('ctrl+shift+pageup',function(){PTL.editor.gotoPrevPage();});shortcut.add('ctrl+shift+pagedown',function(){PTL.editor.gotoNextPage();});shortcut.add('ctrl+shift+n',function(){$("#item-number").focus().select();});$(document).ajaxStart(function(){clearTimeout(PTL.editor.delayedActivityTimer);PTL.editor.delayedActivityTimer=setTimeout(function(){PTL.editor.showActivity();},3000);});$(document).ajaxStop(function(){clearTimeout(PTL.editor.delayedActivityTimer);if(!PTL.editor.isLoading){PTL.editor.hideActivity();}});$.each(this.settings.mt,function(){var backend=this.name;var key=this.key;$.ajax({url:s('js/mt/'+backend+'.js'),async:false,dataType:'script',success:function(){setTimeout(function(){PTL.editor.mt[backend].init(key);},0);$(document).on("mt_ready","table.translate-table",PTL.editor.mt[backend].ready);}});});$.each(this.settings.lookup,function(){var backend=this;$.ajax({url:s('js/lookup/'+backend+'.js'),async:false,dataType:'script',success:function(){setTimeout(function(){PTL.editor.lookup[backend].init();},0);$(document).on("lookup_ready","table.translate-table",PTL.editor.lookup[backend].ready);}});});setInterval(PTL.editor.updateRelativeDates,6e4);setTimeout(function(){$.history.init(function(hash){var params=PTL.utils.getParsedHash(hash);var withUid=false;var pageNumber=undefined;if('unit'in params){var uid=parseInt(params['unit']);if(uid&&!isNaN(uid)){if(PTL.editor.activeUid!=uid&&PTL.editor.units[uid]==undefined){PTL.editor.activeUid=uid;withUid=true;}else{PTL.editor.activeUid=uid;PTL.editor.displayEditUnit(uid);return;}}}else if('page'in params){var p=parseInt(params['page']);if(p&&!isNaN(p)&&p>0){pageNumber=p;}}
if('filter'in params){var a=params['filter'].split(',');PTL.editor.filter=a.shift();PTL.editor.checks=(PTL.editor.filter=="checks")?a:[];}
if('search'in params){PTL.editor.filter="search";PTL.editor.searchText=params['search'];if('sfields'in params){PTL.editor.searchFields=params['sfields'].split(',');}}
PTL.editor.preventNavigation=true;$("#filter-status select [value='"+PTL.editor.filter+"']").attr("selected","selected");if(PTL.editor.filter=="checks"){if(!$("#filter-checks").length){PTL.editor.filterStatus();}
$("#filter-checks select [value='"+PTL.editor.checks[0]+"']").attr("selected","selected");}
if(PTL.editor.filter=="search"){$("#id_search").val(PTL.editor.searchText);$("#id_search").trigger('focus');if(!PTL.editor.searchFields.length){PTL.editor.searchFields=["source","target"];}
$(".js-search-fields input").each(function(){if($.inArray($(this).val(),PTL.editor.searchFields)>=0){$(this).attr("checked","checked");}else{$(this).removeAttr("checked");}});}
PTL.editor.preventNavigation=false;PTL.editor.getViewUnits({pager:true,page:pageNumber,withUid:withUid});if(PTL.editor.hasResults){PTL.editor.fetchPages(false);PTL.editor.displayEditUnit(PTL.editor.activeUid);}},{'unescape':true});},1);},ready:function(){var maxheight=$(window).height()*0.3;$('textarea.expanding').TextAreaExpander('10',maxheight);$('.extra-item-comment').filter(':not([dir])').bidi();$('.suggestion-translation-body').filter(':not([dir])').bidi();if($(".focusthis").get(0)){$(".focusthis").get(0).focus();}
PTL.editor.hlSearch();if(PTL.editor.settings.tmUrl!=''){PTL.editor.getTMUnits();}
$("table.translate-table").trigger("mt_ready");$("table.translate-table").trigger("lookup_ready");PTL.editor.isLoading=false;PTL.editor.hideActivity();PTL.editor.updatePermalink();PTL.editor.updateRelativeDates();clearTimeout(PTL.editor.delayedActivityTimer);},noResults:function(){PTL.editor.displayMsg(gettext("No results."));PTL.editor.reDraw(false);PTL.editor.updatePermalink(false);},escapeUnsafeRegexSymbols:function(s){var i,r="\\.+*?[^]$(){}=!<>¦:";for(i=0;i<r.length;i++){s=s.replace(new RegExp("\\"+r.charAt(i),"g"),"\\"+r.charAt(i));}
return s;},makeRegexForMultipleWords:function(s){var i,w=s.split(' ');for(i=0;i<w.length;i++){w[i]=this.escapeUnsafeRegexSymbols(w[i]);}
return'('+w.join("|")+')';},hlSearch:function(){var hl=PTL.editor.filter=="search"?PTL.editor.searchText:"",sel=[],selMap={notes:"div.developer-comments",locations:"div.translate-locations",source:"td.translate-original, div.original div.translation-text",target:"td.translate-translation"};$.each(PTL.editor.searchFields,function(i,field){sel.push("tr.edit-row "+selMap[field]);sel.push("tr.view-row "+selMap[field]);});$(sel.join(", ")).highlightRegex(new RegExp(PTL.editor.makeRegexForMultipleWords(hl),"i"));},hlTerms:function(){var term;$(".tm-original").each(function(){term=$(this).text();$("div.original .translation-text").highlightRegex(new RegExp(PTL.editor.escapeUnsafeRegexSymbols(term),"g"));});},copyText:function(e){var selector,text,element,start,action=$(this).data('action');selector=$(".tm-translation",this).ifExists()||$(".suggestion-translation",this).ifExists()||$(this);text=selector.data('entity')||selector.text();element=$(PTL.editor.focused);if(action==="overwrite"){element.val(text);start=text.length;}else{start=element.caret().start+text.length;element.val(element.caret().replace(text));}
element.caret(start,start);},copyOriginal:function(sources){var cleanSources=[];$.each(sources,function(i){cleanSources[i]=$(this).text();});var targets=$("[id^=id_target_f_]");if(targets.length){var i,active,max=cleanSources.length-1;for(var i=0;i<targets.length;i++){var newval=cleanSources[i]||cleanSources[max];$(targets.get(i)).val(newval);}
active=$(targets).get(0);active.focus();PTL.editor.goFuzzy();PTL.editor.cpRE.exec($(active).val());i=PTL.editor.cpRE.lastIndex;$(active).caret(i,i);PTL.editor.cpRE.lastIndex=0;}},getSelectedText:function(){var t='';if(window.getSelection){t=window.getSelection();}else if(document.getSelection){t=document.getSelection();}else if(document.selection){t=document.selection.createRange().text;}
return t;},cleanEscape:function(s){return s.replace(/\\t/g,"\t").replace(/\\n/g,"");},fancyEscape:function(text){function replace(match){var replaced,escapeHl='<span class="highlight-escape">%s</span>',htmlHl='<span class="highlight-html">&lt;%s&gt;</span>',submap={'\r\n':escapeHl.replace(/%s/,'\\r\\n')+'<br/>\n','\r':escapeHl.replace(/%s/,'\\r')+'<br/>\n','\n':escapeHl.replace(/%s/,'\\n')+'<br/>\n','\t':escapeHl.replace(/%s/,'\\t'),'&':'&amp;','<':'&lt;','>':'&gt;'};replaced=submap[match];if(replaced==undefined){replaced=htmlHl.replace(/%s/,PTL.editor.fancyEscape(match.slice(1,match.length-1)));}
return replaced;}
return text.replace(this.escapeRE,replace);},fancySpaces:function(text){function replace(match){var spaceHl='<span class="translation-space"> </span>';return Array(match.length+1).join(spaceHl);}
return text.replace(this.whitespaceRE,replace);},fancyHl:function(text){return this.fancySpaces(this.fancyEscape(text));},doDiff:function(a,b){var d,op,text,textDiff="",removed="",diff=this.differencer.diff_main(a,b);this.differencer.diff_cleanupSemantic(diff);$.each(diff,function(k,v){op=v[0];text=v[1];if(op==0){if(removed){textDiff+='<span class="diff-delete">'+PTL.editor.fancyEscape(removed)+'</span>'
removed="";}
textDiff+=PTL.editor.fancyEscape(text);}else if(op==1){if(removed){textDiff+='<span class="diff-replace">'+PTL.editor.fancyEscape(text)+'</span>';removed="";}else{textDiff+='<span class="diff-insert">'+PTL.editor.fancyEscape(text)+'</span>';}}else if(op==-1){removed=text;}});if(removed){textDiff+='<span class="diff-delete">'+PTL.editor.fancyEscape(removed)+'</span>';}
return textDiff;},doFuzzyArea:function(){$("tr.edit-row").addClass("fuzzy-unit");},undoFuzzyArea:function(){$("tr.edit-row").removeClass("fuzzy-unit");},doFuzzyBox:function(){$("input.fuzzycheck").attr("checked","checked");},undoFuzzyBox:function(){$("input.fuzzycheck").removeAttr("checked");},goFuzzy:function(){if(!this.isFuzzy()){this.keepState=true;this.doFuzzyArea();this.doFuzzyBox();}},ungoFuzzy:function(){if(this.isFuzzy()){this.keepState=true;this.undoFuzzyArea();this.undoFuzzyBox();}},isFuzzy:function(){return $("input.fuzzycheck").attr("checked");},doSuggestMode:function(){$("table.translate-table").addClass("suggest-mode");},undoSuggestMode:function(){$("table.translate-table").removeClass("suggest-mode");},isSuggestMode:function(){return $("table.translate-table").hasClass("suggest-mode");},toggleSuggestMode:function(){if(this.isSuggestMode()){this.undoSuggestMode();}else{this.doSuggestMode();}},updatePermalink:function(opts){if(opts!==false){var urlStr=this.store?this.store+'/translate/#unit=':this.directory+'translate.html#unit=';var thePermalink=interpolate(gettext('<a href="%s">String %s</a>'),[l(urlStr+PTL.editor.activeUid),PTL.editor.activeUid]);}else{var thePermalink='';}
$("#editor-permalink").html(thePermalink);},updateRelativeDates:function(){$('.js-relative-date').each(function(i,e){$(e).text(PTL.utils.relativeDate(Date.parse($(e).attr('datetime'))));});},showActivity:function(force){this.hideMsg();$("#js-editor-act").spin().fadeIn(300);},hideActivity:function(){$("#js-editor-act").spin(false).fadeOut(300);},displayMsg:function(msg){this.hideActivity();$("#js-editor-msg").show().find("span").html(msg).fadeIn(300);},hideMsg:function(msg){if($("#js-editor-msg").is(":visible")){$("#js-editor-msg").fadeOut(300);}},displayError:function(msg){if(msg){this.hideActivity();$("#js-editor-error span").text(msg).parent().parent().stop(true,true).fadeIn(300).delay(2000).fadeOut(3500);}},error:function(xhr,s){var msg="";if(s=="abort"){return;}
if(xhr.status==0){msg=gettext("Error while connecting to the server");}else if(xhr.status==500){msg=gettext("Server error");}else if(s=="timeout"){msg=gettext("The server seems down. Try again later.");}else{if(xhr instanceof XMLHttpRequest){msg=$.parseJSON(xhr.responseText).msg;}else{msg=gettext("Unknown error");}}
PTL.editor.displayError(msg);},getReqData:function(){var reqData={};switch(this.filter){case"checks":if(this.checks.length){reqData.checks=this.checks.join(",");}
break;case"search":reqData.search=this.searchText;reqData.sfields=this.searchFields;break;case"suggestions":reqData.matchnames='hassuggestion';break;case"mysuggestions":reqData.matchnames='ownsuggestion';break;case"mysubmissions":reqData.matchnames='ownsubmission';break;case"submissionsafterme":reqData.matchnames='hassubmissionafterme';break;case"all":break;case"incomplete":reqData.unitstates="untranslated,fuzzy";break;default:reqData.unitstates=this.filter;break;}
return reqData;},getViewUnits:function(opts){var extraData,reqData,viewUrl,defaults={async:false,limit:0,page:this.currentPage,pager:false,withUid:false},urlStr=this.store?'/view'+this.store:this.directory+'view.html';opts=$.extend({},defaults,opts);if(opts.limit!=0&&this.store){urlStr=urlStr.replace('/view','/view/'+limit);}
viewUrl=l(urlStr);extraData={page:opts.page};if(Object.size(this.meta)==0){extraData.meta=true;}
if(opts.pager){extraData.pager=opts.pager;}
if(opts.withUid){extraData.uid=this.activeUid;delete extraData.page}
reqData=$.extend(extraData,this.getReqData());$.ajax({url:viewUrl,data:reqData,dataType:'json',async:opts.async,success:function(data){if(Object.size(PTL.editor.meta)==0&&data.meta){PTL.editor.meta=data.meta;}
if(opts.pager){if(data.pager){PTL.editor.hasResults=true;PTL.editor.pagesGot={};PTL.editor.units={};PTL.editor.updatePager(data.pager);if(data.uid){PTL.editor.activeUid=data.uid;}}}
if(data.units.length){if(opts.withUid&&data.pager){var page=data.pager.number;}else{var page=opts.page;}
PTL.editor.pagesGot[page]=[];var urlStr=PTL.editor.store?PTL.editor.store+'/translate/#unit=':PTL.editor.directory+'translate.html#unit=';$.each(data.units,function(){PTL.editor.units[this.id]=this;PTL.editor.units[this.id]['url']=l(urlStr+this.id);PTL.editor.pagesGot[page].push(this.id);});PTL.editor.hasResults=true;}else{PTL.editor.hasResults=false;$("table.translate-table").trigger("noResults");}},error:PTL.editor.error});},buildRows:function(uids){var _this,i,unit,cls="even",even=true,rows="";for(i=0;i<uids.length;i++){_this=uids[i].id||uids[i];unit=this.units[_this];rows+='<tr id="row'+_this+'" class="view-row '+cls+'">';rows+=this.tmpl.vUnit($,{data:{meta:this.meta,unit:unit}}).join("");rows+='</tr>';cls=even?"odd":"even";even=!even;}
return rows;},buildCtxRows:function(units,extraCls){var i,unit,cls="even",even=true,rows="";urlStr=PTL.editor.store?PTL.editor.store+'/translate/#unit=':PTL.editor.directory+'translate.html#unit=';for(i=0;i<units.length;i++){unit=units[i];unit['url']=l(urlStr+unit.id);rows+='<tr id="ctx'+unit.id+'" class="ctx-row '+extraCls+' '+cls+'">';rows+=this.tmpl.vUnit($,{data:{meta:this.meta,unit:unit}}).join("");rows+='</tr>';cls=even?"odd":"even";even=!even;}
return rows;},getUidsBeforeAfter:function(uid){var howMuch,i,m,prevNextL,tu,uids={before:[],after:[]},limit=parseInt((this.pager.per_page-1)/2),current=this.units[uid],prevNext={prev:"before",next:"after"};for(m in prevNext){tu=current;for(i=0;i<limit;i++){if(tu[m]!=undefined&&tu[m]in this.units){var tu=this.units[tu[m]];uids[prevNext[m]].push(tu.id);}}}
if(Object.size(this.units)>limit){prevNextL={prev:"after",next:"before"};for(m in prevNext){if(uids[prevNextL[m]].length<limit){howMuch=limit-uids[prevNextL[m]].length;tu=this.units[uids[prevNext[m]][uids[prevNext[m]].length-1]];for(i=0;i<howMuch;i++){if(tu[m]!=undefined){var tu=this.units[tu[m]];uids[prevNext[m]].push(tu.id);}}}}}
uids.before.reverse();return uids;},checkUnitsLinking:function(){var first,last,lastInPrevPage,p,pnP;for(p in this.pagesGot){p=parseInt(p);first=this.pagesGot[p][0];last=this.pagesGot[p][this.pagesGot[p].length-1];if(p>1&&(!this.units[first].hasOwnProperty('prev')||this.units[first].prev==null)){pnP=p-1;if(pnP in this.pagesGot){lastInPrevPage=this.pagesGot[pnP][this.pagesGot[pnP].length-1];$.extend(this.units[first],{prev:lastInPrevPage});}}
if(p<this.pager.num_pages&&(!this.units[last].hasOwnProperty('next')||this.units[last].next==null)){pnP=p+1;if(pnP in this.pagesGot){$.extend(this.units[last],{next:this.pagesGot[pnP][0]});}}}},displayEditUnit:function(uid){var uids,newTbody;this.checkUnitsLinking();if(PTL.editor.hasResults){this.fetchPages(true);uids=this.getUidsBeforeAfter(uid);newTbody=this.buildRows(uids.before)+
this.getEditUnit(uid)+
this.buildRows(uids.after);this.hideMsg();this.reDraw(newTbody);this.updateNavButtons(uids.before.length,uids.after.length);}},reDraw:function(newTbody){var tTable=$("table.translate-table"),where=$("tbody",tTable),oldRows=$("tr",where);oldRows.remove();$('.tipsy').remove();if(newTbody!==false){where.append(newTbody);$(tTable).trigger("editor_ready");}},updateNavButtons:function(hasBefore,hasAfter){$('#js-nav-prev').prop('disabled',!hasBefore);$('#js-nav-next').prop('disabled',!hasAfter);},fetchPages:function(async){var i,current=this.currentPage,candidates=[current,current+1,current-1],pages=[];for(i=0;i<candidates.length;i++){if(candidates[i]<=this.pager.num_pages&&candidates[i]>0&&!(candidates[i]in this.pagesGot)){pages.push(candidates[i]);}}
for(i=0;i<pages.length;i++){this.getViewUnits({async:async,page:pages[i]});}},updatePager:function(pager){this.pager=pager;if(this.currentPage!=pager.number||this.currentNumPages!=pager.num_pages){this.currentPage=pager.number;this.currentNumPages=pager.num_pages;$("#item-number").val(pager.number);$("#items-count").text(pager.num_pages);}},createPager:function(uid){var newPager=this.pager;if($.inArray(uid,this.pagesGot[this.currentPage])==-1){var newPageNumber,i=this.currentPage,j=this.currentPage+1,found=false;while(!found&&(i>0||j<=this.pager.num_pages)){if(i>0&&$.inArray(uid,this.pagesGot[i])!=-1){newPageNumber=i;found=true;}else if($.inArray(uid,this.pagesGot[j])!=-1){newPageNumber=j;found=true;}
i--;j++;}
if(found){newPager.number=newPageNumber;}}
return newPager;},getEditUnit:function(uid){var editor,editCtxRowBefore,editCtxRowAfter,editCtxWidgets,hasData,eClass="edit-row",editUrl=l('/unit/edit/'+uid),reqData=this.getReqData(),widget='',ctx={before:[],after:[]};$.ajax({url:editUrl,async:false,data:reqData,dataType:'json',success:function(data){widget=data['editor'];PTL.editor.updatePager(PTL.editor.createPager(uid));if(data.ctx){PTL.editor.ctxGap=Math.max(data.ctx.before.length,data.ctx.after.length);ctx.before=data.ctx.before;ctx.after=data.ctx.after;}},error:PTL.editor.error});eClass+=this.units[uid].isfuzzy?" fuzzy-unit":"";hasData=ctx.before.length||ctx.after.length;editCtxWidgets=this.editCtxUI({hasData:hasData});editCtxRowBefore=editCtxWidgets[0];editCtxRowAfter=editCtxWidgets[1];editor=(PTL.editor.filter!=='all'?editCtxRowBefore+this.buildCtxRows(ctx.before,"before"):'')+'<tr id="row'+uid+'" class="'+eClass+'">'+
widget+'</tr>'+
(PTL.editor.filter!=='all'?this.buildCtxRows(ctx.after,"after")+editCtxRowAfter:'');this.activeUid=uid;return editor;},submit:function(e){e.preventDefault();var reqData,submitUrl,uid=PTL.editor.activeUid,form=$("#captcha").ifExists()||$("#translate");submitUrl=l('/unit/submit/'+uid);reqData=form.serializeObject();$.extend(reqData,PTL.editor.getReqData());$.ajax({url:submitUrl,type:'POST',data:reqData,dataType:'json',async:false,success:function(data){if(data.captcha){$.fancybox(data.captcha);$("#id_captcha_answer").focus();}else{PTL.editor.units[uid].isfuzzy=PTL.editor.isFuzzy();$("textarea[id^=id_target_f_]").each(function(i){PTL.editor.units[uid].target[i].text=PTL.editor.cleanEscape($(this).val());});PTL.editor.loadNext(uid);}},error:PTL.editor.error});},suggest:function(e){e.preventDefault();var reqData,suggestUrl,uid=PTL.editor.activeUid,form=$("#captcha").ifExists()||$("#translate");suggestUrl=l('/unit/suggest/'+uid);reqData=form.serializeObject();$.extend(reqData,PTL.editor.getReqData());$.ajax({url:suggestUrl,type:'POST',data:reqData,dataType:'json',async:false,success:function(data){if(data.captcha){$.fancybox(data.captcha);$("#id_captcha_answer").focus();}else{PTL.editor.loadNext(uid);}},error:PTL.editor.error});},loadNext:function(uid){var newUid=parseInt(PTL.editor.units[uid].next);if(newUid){var newHash=PTL.utils.updateHashPart("unit",newUid,["page"]);$.history.load(newHash);}else{PTL.editor.displayMsg([gettext("Congratulations, you walked through all strings."),'<br /><a href="',l(PTL.editor.directory),'">',gettext('Return to the overview page.'),'</a>'].join(""));}},gotoPrevNext:function(e){e.preventDefault();var current=PTL.editor.units[PTL.editor.activeUid],prevNextMap={'js-nav-prev':current.prev,'js-nav-next':current.next},newUid=prevNextMap[$(e.target).attr("id")];if(newUid!=null){var newHash=PTL.utils.updateHashPart("unit",parseInt(newUid),["page"]);$.history.load(newHash);}else{if($(e.target).attr("id")=='js-nav-prev'){PTL.editor.displayMsg(gettext("You reached the beginning of the list"));}else{PTL.editor.displayMsg([gettext("You reached the end of the list."),'<br /><a href="',l(PTL.editor.directory),'">',gettext('Return to the overview page.'),'</a>'].join(""));}}},gotoUnit:function(e){e.preventDefault();if(e.ctrlKey||e.altKey||e.metaKey||e.which===2){var $el=e.target.nodeName!=='TD'?$(e.target).parents('td'):$(e.target);window.open($el.data('target'),'_blank');return;}
if(PTL.editor.getSelectedText()!=""){return;}
var m=$(this).attr("id").match(/(row|ctx)([0-9]+)/);if(m){var uid=parseInt(m[2]);var newHash=PTL.utils.updateHashPart("unit",uid,["page"]);$.history.load(newHash);}},gotoPage:function(page){if(page&&!isNaN(page)&&page>0&&page<=PTL.editor.pager.num_pages){var newHash=PTL.utils.updateHashPart("page",page,["unit"]);$.history.load(newHash);}},gotoFirstPage:function(){if(PTL.editor.currentNumPages>0){this.gotoPage(1);}},gotoLastPage:function(){if(PTL.editor.currentNumPages>0){this.gotoPage(PTL.editor.currentNumPages);}},gotoPrevPage:function(){if((PTL.editor.currentNumPages>0)&&(this.currentPage>1)){this.gotoPage(this.currentPage-1);}},gotoNextPage:function(){if((PTL.editor.currentNumPages>0)&&(this.currentPage<PTL.editor.currentNumPages)){this.gotoPage(this.currentPage+1);}},getCheckOptions:function(){var opts,checksUrl=this.store?l('/checks'+this.store):l(this.directory+"checks.html");$.ajax({url:checksUrl,async:false,dataType:'json',success:function(data){opts=data;},error:PTL.editor.error});return opts;},filterChecks:function(){if(PTL.editor.preventNavigation){return;}
var filterBy=$("option:selected",this).val();if(filterBy!="none"){var newHash="filter=checks,"+filterBy;$.history.load(newHash);}},filterStatus:function(){var filterBy=$("#filter-status option:selected").val();if(filterBy=="checks"){var optGroups=PTL.editor.getCheckOptions();if(optGroups.length){var dropdown='<div id="filter-checks">';dropdown+='<select name="filter-checks">';dropdown+='<option selected="selected" value="none">------</option>';$.each(optGroups,function(){dropdown+='<optgroup label="'+this.display_name+'">';$.each(this.checks,function(){dropdown+='<option value="'+this.name+'">'+this.display_name+' ('+this.count+')</option>';});dropdown+='</optgroup>';});dropdown+='</select></div>';$("#filter-status").first().after(dropdown);}else{PTL.editor.displayMsg(gettext("No results."));$("#filter-status option[value="+PTL.editor.filter+"]").attr("selected","selected");}}else{$("#filter-checks").remove();if(!PTL.editor.preventNavigation){var newHash="filter="+filterBy;$.history.load(newHash);}}},editCtxUI:function(opts){var defaults={hasData:false,replace:false};opts=$.extend({},defaults,opts);editCtxRowBefore=PTL.editor.tmpl.editCtx($,{data:{hasData:opts.hasData,extraCls:'before'}}).join("");editCtxRowAfter=PTL.editor.tmpl.editCtx($,{data:{hasData:opts.hasData,extraCls:'after'}}).join("");if(opts.replace){$("tr.edit-ctx.before").replaceWith(editCtxRowBefore);$("tr.edit-ctx.after").replaceWith(editCtxRowAfter);}
return[editCtxRowBefore,editCtxRowAfter];},moreContext:function(initial){var ctxUrl=l('/unit/context/'+PTL.editor.activeUid),reqData={gap:PTL.editor.ctxGap};reqData.qty=initial?PTL.editor.ctxQty:PTL.editor.ctxStep;if(initial&&reqData.qty===0){return;}
$.ajax({url:ctxUrl,async:false,dataType:'json',data:reqData,success:function(data){if(data.ctx.before.length||data.ctx.after.length){if(initial){PTL.editor.ctxGap=Math.max(data.ctx.before.length,data.ctx.after.length);}else{PTL.editor.ctxGap+=Math.max(data.ctx.before.length,data.ctx.after.length);}
$.cookie('ctxQty',PTL.editor.ctxGap,{path:'/'});var before=PTL.editor.buildCtxRows(data.ctx.before,"before"),after=PTL.editor.buildCtxRows(data.ctx.after,"after");var editCtxRows=$("tr.edit-ctx");editCtxRows.first().after(before);editCtxRows.last().before(after);}},error:PTL.editor.error});},lessContext:function(){var before=$(".ctx-row.before"),after=$(".ctx-row.after");if(before.length||after.length){if(before.length===PTL.editor.ctxGap){before.slice(0,PTL.editor.ctxStep).remove();}
if(after.length===PTL.editor.ctxGap){after.slice(-PTL.editor.ctxStep).remove();}
PTL.editor.ctxGap-=PTL.editor.ctxStep;if(PTL.editor.ctxGap>=0){if(PTL.editor.ctxGap==0){PTL.editor.editCtxUI({hasData:false,replace:true});$.cookie('ctxShow',false,{path:'/'});}
$.cookie('ctxQty',PTL.editor.ctxGap,{path:'/'});}}},showContext:function(){var editCtxRowBefore,editCtxRowAfter,before=$(".ctx-row.before"),after=$(".ctx-row.after");if(before.length||after.length){before.show();after.show();}else{PTL.editor.moreContext(true);}
PTL.editor.editCtxUI({hasData:true,replace:true});$.cookie('ctxShow',true,{path:'/'});},hideContext:function(){var editCtxRowBefore,editCtxRowAfter,before=$(".ctx-row.before"),after=$(".ctx-row.after");before.hide();after.hide();PTL.editor.editCtxUI({hasData:false,replace:true});$.cookie('ctxShow',false,{path:'/'});},search:function(){var newHash,text=$("#id_search").val();if(text){var remember=true,parsed=PTL.search.parse(text,remember);newHash="search="+parsed;}else{newHash=PTL.utils.updateHashPart("filter","all",["search","sfields"]);}
$.history.load(newHash);},comment:function(e){e.preventDefault();var url=$(this).attr('action'),reqData=$(this).serializeObject();$.ajax({url:url,type:'POST',data:reqData,success:function(data){$("#editor-comment").fadeOut(200);if($("#translator-comment").length){$(data.comment).hide().prependTo("#translator-comment").delay(200).animate({height:'show'},1000,'easeOutQuad');}else{var commentHtml='<div id="translator-comment">'+data.comment
+'</div>';$(commentHtml).prependTo("#extras-container").delay(200).hide().animate({height:'show'},1000,'easeOutQuad');}
PTL.editor.updateRelativeDates();},error:PTL.editor.error});return false;},showTimeline:function(e){e.preventDefault();if($("#timeline-results").length){$("#js-hide-timeline").show();$("#timeline-results").slideDown(1000,'easeOutQuad');$("#js-show-timeline").hide();return;}
var uid=PTL.editor.activeUid,node=$("#extras-container"),timelineUrl=l("/unit/timeline/"+uid);if(PTL.editor.timelineReq!=null){PTL.editor.timelineReq.abort();}
PTL.editor.timelineReq=$.ajax({url:timelineUrl,dataType:'json',success:function(data){var uid=data.uid;if(data.timeline&&uid===PTL.editor.activeUid){if($("#translator-comment").length){$(data.timeline).hide().insertAfter("#translator-comment").slideDown(1000,'easeOutQuad');}else{$(data.timeline).hide().prependTo("#extras-container").slideDown(1000,'easeOutQuad');}
PTL.editor.updateRelativeDates();$('.timeline-field-body').filter(':not([dir])').bidi();$("#js-show-timeline").hide();$("#js-hide-timeline").show();}},beforeSend:function(){node.spin();},complete:function(){node.spin(false);},error:PTL.editor.error});},hideTimeline:function(e){$("#js-hide-timeline").hide();$("#timeline-results").slideUp(1000,'easeOutQuad');$("#js-show-timeline").show();},filterTMResults:function(results){var source=$("[id^=id_source_f_]").first().val(),filtered=[],quality;for(var i=0;i<results.length&&i<3;i++){results[i].source=this.doDiff(source,results[i].source);results[i].target=this.fancyHl(results[i].target);quality=Math.round(results[i].quality);results[i].qTitle=interpolate(gettext('%s% match'),[quality]);filtered.push(results[i]);}
return filtered;},getTMUnits:function(){var src=this.meta.source_lang,tgt=this.meta.target_lang,sText=$($("input[id^=id_source_f_]").get(0)).val(),pStyle=this.meta.project_style,tmUrl=this.settings.tmUrl+src+"/"+tgt+"/unit/?source="+encodeURIComponent(sText)+"&jsoncallback=?";if(!sText.length){return;}
if(pStyle.length&&pStyle!="standard"){tmUrl+='&style='+this.meta.project_style;}
if(this.tmReq!=null){this.tmReq.abort();}
this.tmReq=$.jsonp({url:tmUrl,callback:'_jsonp'+PTL.editor.activeUid,dataType:'jsonp',cache:true,success:function(data){var uid=this.callback.slice(6);if(uid==PTL.editor.activeUid&&data.length){var filtered=PTL.editor.filterTMResults(data),name=gettext("Similar translations"),tm=PTL.editor.tmpl.tm($,{data:{meta:PTL.editor.meta,suggs:filtered,name:name}}).join("");$(tm).hide().appendTo("#extras-container").slideDown(1000,'easeOutQuad');}},error:PTL.editor.error});},rejectSuggestion:function(e){e.stopPropagation();var suggId=$(this).data("sugg-id"),element=$("#suggestion-"+suggId);uid=$('.translate-container #id_id').val(),url=l('/suggestion/reject/')+uid+'/'+suggId;$.post(url,{'reject':1},function(data){element.fadeOut(200,function(){$(this).remove();if(!$("#suggestions div[id^=suggestion]").length){PTL.editor.gotoPrevNext($.Event('click',{target:'#js-nav-next'}));}});},"json");},acceptSuggestion:function(e){e.stopPropagation();var suggId=$(this).data("sugg-id"),element=$("#suggestion-"+suggId);uid=$('.translate-container #id_id').val(),url=l('/suggestion/accept/')+uid+'/'+suggId;$.post(url,{'accept':1},function(data){$.each(data.newtargets,function(i,target){$("#id_target_f_"+i).val(target).focus();});$.each(data.newdiffs,function(suggId,sugg){$.each(sugg,function(i,target){$("#suggdiff-"+suggId+"-"+i).html(target);});});$("textarea[id^=id_target_f_]").each(function(i){PTL.editor.units[uid].target[i].text=PTL.editor.cleanEscape($(this).val());});PTL.editor.units[uid].isfuzzy=false;element.fadeOut(200,function(){$(this).remove();if(!$("#suggestions div[id^=suggestion]").length){PTL.editor.gotoPrevNext($.Event('click',{target:'#js-nav-next'}));}});},"json");},clearVote:function(e){e.stopPropagation();var element=$(this),voteId=element.data("vote-id"),url=l('/vote/clear/')+voteId;element.fadeTo(200,0.01);$.ajax({url:url,type:'POST',data:{'clear':1},dataType:'json',success:function(data){element.hide();element.siblings(".js-vote-up").fadeTo(200,1);},error:function(xhr,s){PTL.editor.error(xhr,s);element.delay(3000).fadeTo(2000,1);}});},voteUp:function(e){e.stopPropagation();var element=$(this),suggId=element.siblings("[data-sugg-id]").data("sugg-id"),url=l('/vote/up/')+PTL.editor.activeUid+'/'+suggId;element.fadeTo(200,0.01);$.ajax({url:url,type:'POST',data:{'up':1},dataType:'json',success:function(data){element.siblings("[data-vote-id]").data("vote-id",data.voteid);element.hide();element.siblings(".js-vote-clear").fadeTo(200,1);},error:function(xhr,s){PTL.editor.error(xhr,s);element.delay(3000).fadeTo(2000,1);}});},rejectCheck:function(){var element=$(this).parent(),checkId=$(this).data("check-id"),uid=$('.translate-container #id_id').val(),url=l('/qualitycheck/reject/')+uid+'/'+checkId;$.post(url,{'reject':1},function(data){if(element.siblings().size()==0){element=$('#translate-checks-block');}
element.fadeOut(200,function(){$(this).remove();$('.tipsy').remove();});},"json");},isSupportedSource:function(pairs,source){for(var i in pairs){if(source==pairs[i].source){return true;}}
return false;},isSupportedTarget:function(pairs,target){for(var i in pairs){if(target==pairs[i].target){return true;}}
return false;},isSupportedPair:function(pairs,source,target){for(var i in pairs){if(source==pairs[i].source&&target==pairs[i].target){return true;}}
return false;},addMTButton:function(container,aClass,tooltip){var btn='<a class="translate-mt '+aClass+'">';btn+='<i class="icon-'+aClass+'" title="'+tooltip+'"><i/></a>';$(container).first().prepend(btn);},addMTButtons:function(provider){if(this.isSupportedTarget(provider.pairs,provider.targetLang)){var _this=this;var sources=$(".translate-toolbar");$(sources).each(function(){var source=_this.normalizeCode($(this).parent().parent().find('.translation-text').attr("lang"));var ok;if(provider.validatePairs){ok=_this.isSupportedPair(provider.pairs,source,provider.targetLang);}else{ok=_this.isSupportedSource(provider.pairs,source);}
if(ok){_this.addMTButton(this,provider.buttonClassName,provider.hint+' ('+source.toUpperCase()+'&rarr;'+provider.targetLang.toUpperCase()+')');}});}},normalizeCode:function(locale){var clean=locale.replace('_','-')
var atIndex=locale.indexOf("@");if(atIndex!=-1){clean=clean.slice(0,atIndex);}
return clean;},collectArguments:function(s){this.argSubs[this.argPos]=s;return"["+(this.argPos++)+"]";},translate:function(linkObject,providerCallback){var areas=$("[id^=id_target_f_]");var sources=$(linkObject).parent().parent().parent().find('.translation-text');var langFrom=PTL.editor.normalizeCode(sources.eq(0).attr("lang"));var langTo=PTL.editor.normalizeCode(areas.eq(0).attr("lang"));var htmlPat=/<[\/]?\w+.*?>/g;var cPrintfPat=/%%|%(\d+\$)?([-+\'#0 ]*)(\*\d+\$|\*|\d+)?(\.(\*\d+\$|\*|\d+))?([scboxXuidfegEG])/g;var csharpStrPat=/{\d+(,\d+)?(:[a-zA-Z ]+)?}/g;var percentNumberPat=/%\d+/g;var pos=0;var _this=this;$(sources).each(function(j){var sourceText=$(this).text();_this.argSubs=new Array();_this.argPos=0;sourceText=sourceText.replace(htmlPat,function(s){return _this.collectArguments(s)});sourceText=sourceText.replace(cPrintfPat,function(s){return _this.collectArguments(s)});sourceText=sourceText.replace(csharpStrPat,function(s){return _this.collectArguments(s)});sourceText=sourceText.replace(percentNumberPat,function(s){return _this.collectArguments(s)});var result=providerCallback(sourceText,langFrom,langTo,function(translation,message){if(translation===false){PTL.editor.displayError(message);return;}
for(var i=0;i<_this.argSubs.length;i++){if(sourceText.match(new RegExp("\\["+i+"\\][^\\s]"))){translation=translation.replace(new RegExp("\\["+i+"\\]\\s+"),"["+i+"]");}
if(sourceText.match(new RegExp("[^\\s]\\["+i+"\\]"))){translation=translation.replace(new RegExp("\\s+\\["+i+"\\]"),"["+i+"]");}}
for(var i=0;i<_this.argSubs.length;i++){var value=_this.argSubs[i].replace(/\&/g,"&amp;").replace(/\</g,"&lt;").replace(/\>/g,"&gt;");translation=translation.replace("["+i+"]",value);}
areas.eq(j).val($("<div />").html(translation).text());areas.eq(j).focus();});});PTL.editor.goFuzzy();return false;},addLookupButton:function(container,aClass,tooltip){var btn='<a class="translate-lookup iframe '+aClass+'">';btn+='<i class="icon-'+aClass+'" title="'+tooltip+'"></i></a>';$(container).first().prepend(btn);},addLookupButtons:function(provider){var _this=this;var sources=$(".translate-toolbar");$(sources).each(function(){var source=_this.normalizeCode($(this).parent().parent().find('.translation-text').attr("lang"));_this.addLookupButton(this,provider.buttonClassName,provider.hint+' ('+source.toUpperCase()+')');});},lookup:function(linkObject,providerCallback){var areas=$("[id^=id_target_f_]");var sources=$(linkObject).parent().parent().parent().find('.translation-text');var langFrom=PTL.editor.normalizeCode(sources.eq(0).attr("lang"));var langTo=PTL.editor.normalizeCode(areas.eq(0).attr("lang"));var lookupText=PTL.editor.getSelectedText().toString();if(!lookupText){lookupText=sources.eq(0).text();}
var url=providerCallback(lookupText,langFrom,langTo);$.fancybox({"href":url,"type":"iframe","autoScale":false,"transitionIn":'none',"transitionOut":'fade',"width":'75%',"height":'75%'});$("#fancybox-frame").css({'width':'100%','height':'100%'});linkObject.href=url;return false;}};})(jQuery);if(!this.JSON){this.JSON={};}
(function(){"use strict";function f(n){return n<10?'0'+n:n;}
if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+
f(this.getUTCMonth()+1)+'-'+
f(this.getUTCDate())+'T'+
f(this.getUTCHours())+':'+
f(this.getUTCMinutes())+':'+
f(this.getUTCSeconds())+'Z':null;};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};}
var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4);})+'"':'"'+string+'"';}
function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key);}
if(typeof rep==='function'){value=rep.call(holder,key,value);}
switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';}
gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||'null';}
v=partial.length===0?'[]':gap?'[\n'+gap+
partial.join(',\n'+gap)+'\n'+
mind+']':'['+partial.join(',')+']';gap=mind;return v;}
if(rep&&typeof rep==='object'){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==='string'){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}
v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+
mind+'}':'{'+partial.join(',')+'}';gap=mind;return v;}}
if(typeof JSON.stringify!=='function'){JSON.stringify=function(value,replacer,space){var i;gap='';indent='';if(typeof space==='number'){for(i=0;i<space;i+=1){indent+=' ';}}else if(typeof space==='string'){indent=space;}
rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');}
return str('',{'':value});};}
if(typeof JSON.parse!=='function'){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v;}else{delete value[k];}}}}
return reviver.call(holder,key,value);}
text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+
('0000'+a.charCodeAt(0).toString(16)).slice(-4);});}
if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j;}
throw new SyntaxError('JSON.parse');};}}());