// Google Chrome Extensions Localizer, MIT, <http://www.mixesoft.com/localizer.html/> Copyright Mixesoft(c)Project 2004-2010 <http://www.mixesoft.com/>
window.onload=function(){try{localStorage&&JSON&&Loc.init()}catch(a){$("step1").innerHTML='<h3 class="box">This service is designed for browsers that support Local Storage and client side JSON.<br />Please Update Your Browser to the latest Version:<p><a href="http://www.google.com/chrome">Chrome</a></p><p><a href="http://www.opera.com/browser/">Opera 10.51+</a></p><p><a href="http://www.microsoft.com/windows/internet-explorer/default.aspx">Internet Explorer 8</a></p><p><a href="http://www.mozilla.com/firefox/firefox.html">Firefox 3.6+</a></p><p><a href="http://www.apple.com/safari/download/">Safari 4+</a></h3><br /></p>'}};
window.onbeforeunload=function(){if(Loc.parsed)return"All unsaved data will be lost!\nAre you sure you want to close current project?"};
var Loc={engine:0,detectedSourceLanguage:"unk.",translate_from_lang:"",translate_to_lang:"ja",parsed:0,tab:0,first_row:-1,second_row:-1,init:function(){google.language.getBranding("branding");var a=navigator.userAgent;if(a.indexOf("WebKit")>-1)Loc.engine=20;else if(a.indexOf("MSIE")>-1)Loc.engine=0;else if(a.indexOf("Gecko")>-1)Loc.engine=30;else if(a.indexOf("Presto")>-1)Loc.engine=10;Loc.fillLang("fromlang");Loc.fillLang("tolang");a=navigator.language?navigator.language:navigator.browserLanguage?
navigator.browserLanguage:"en";a=a.slice(0,2);Loc.setCurLang("tolang",a=="en"?"ja":a);$("templates").selectedIndex=-1;Loc.fillProjects()},storDel:function(){var a=$("projects");if(a.selectedIndex>-1){var b=a.options[a.selectedIndex];if(confirm("Are you sure you want to delete\nselected project from local storage?"))try{localStorage.removeItem(b.value);a.removeChild(b)}catch(c){alert("Failed : "+c)}}},storSave:function(a){if(Loc.stringify())try{localStorage.setItem(a,$("dst").value)}catch(b){alert("Saving "+
a+" to local storage failed: "+b)}},promptSave:function(){if(Loc.parsed){var a=prompt("Do you want to save the current project to local storage?\n\nProject Name:",$("pname").value);if(a){a+=".loc";if(localStorage.getItem(a)==undefined)Loc.storSave(a);else confirm(a+" already exists.\nDo you want to replace it?")?Loc.storSave(a):Loc.promptSave()}}},fillProjects:function(){for(var a=$("projects"),b,c=localStorage.length,d,e=0;e<c;e++){d=localStorage.key(e);var f=d.indexOf(".loc");if(f>0){b=document.createElement("OPTION");
b.value=d;if(Loc.engine>9)b.textContent=d.slice(0,f);else b.innerText=d.slice(0,f);a.appendChild(b)}}a.selectedIndex=-1},fillLang:function(a){a=$(a);var b=google.language.Languages,c;for(var d in b){c=document.createElement("OPTION");c.value=b[d];if(Loc.engine>9)c.textContent=d+" ("+b[d]+")";else c.innerText=d+" ("+b[d]+")";a.appendChild(c)}},setCurLang:function(a,b){for(var c=$(a),d=c.options.length,e=0;e<d;e++)if(b==c.options[e].value)c.selectedIndex=c.options[e].index},translate:function(a){google.language.translate(a.value,
Loc.translate_from_lang,Loc.translate_to_lang,function(b){if(b.error)a.value="error code: "+b.error.code+" "+b.error.message;else{a.value=b.translation;if(b.detectedSourceLanguage)Loc.detectedSourceLanguage=b.detectedSourceLanguage}})},download:function(a,b){$("src").value="Loading...";setTimeout(function(){var c=new XMLHttpRequest;c.onreadystatechange=function(){if(c.readyState==4)if(c.responseText){var d=c.responseText;d=unescape(d.replace(/\\u/g,"%u"));b(d)}else b('Loading "'+a+'" failed. Status code: '+
c.status)};c.open("GET",a,true);c.send()},500,0)},onTemplate:function(a){$("src").value=a;a=$("templates").options[tmps.selectedIndex].text;$("pname").value=unescape(a.replace(/\\u/g,"%u"))},onProject:function(){var a=$("projects").value;try{$("src").value=localStorage.getItem(a);var b=$("projects");$("pname").value=b.options[b.selectedIndex].text}catch(c){alert("Loading the "+a+" failed: "+c)}},lineNum:function(){for(var a=Loc.tab.rows,b=2;b<a.length;b+=2)a[b].cells[0].firstChild.value=a[b].rowIndex/
2},lineAdd:function(){window.scrollBy(0,150);Loc.first_row>0&&Loc.lineColor(Loc.first_row,"#DEDEDE");Loc.rowAdd(Loc.first_row+2,0,{},true);Loc.rowAdd(Loc.second_row+2,0,{},false);Loc.lineColor(Loc.first_row,"#C0DEED");Loc.lineNum()},lineDel:function(){if(!(Loc.first_row<1)){var a=Loc.tab.rows;Loc.tab.deleteRow(Loc.first_row);Loc.tab.deleteRow(Loc.first_row);if(a.length==1)Loc.first_row=Loc.second_row=-1;else{if(Loc.first_row==a.length){Loc.first_row-=2;Loc.second_row-=2}Loc.lineColor(Loc.first_row,
"#C0DEED")}Loc.lineNum()}},lineMove:function(a){function b(i,h){for(var g=1;g<5;++g){f=h[g].firstChild.value;h[g].firstChild.value=i[g].firstChild.value;i[g].firstChild.value=f}}if(!(Loc.first_row<0)){var c=Loc.tab.rows;if(!(Loc.first_row+a<1||Loc.second_row+a>c.length-1)){Loc.lineColor(Loc.first_row,"#DEDEDE");var d=c[Loc.first_row].cells,e=c[Loc.first_row+=a].cells,f;b(d,e);$("panel").style.top=viewY(e[0])+"px";d=c[Loc.second_row].cells;e=c[Loc.second_row+=a].cells;b(d,e);Loc.lineColor(Loc.first_row,
"#C0DEED")}}},lineColor:function(a,b){var c=Loc.tab.rows,d=c[a].cells[0];d.firstChild.style.backgroundColor=d.style.backgroundColor=b;$("panel").style.top=viewY(d)+"px";d=c[a+1].cells[0];d.firstChild.style.backgroundColor=d.style.backgroundColor=b},lineClick:function(a){Loc.first_row>0&&Loc.lineColor(Loc.first_row,"#DEDEDE");if(a%2){Loc.first_row=a;Loc.second_row=a+1}else{Loc.first_row=a-1;Loc.second_row=a}Loc.lineColor(Loc.first_row,"#C0DEED")},rowAdd:function(a,b,c,d){if(a<0||a==Loc.tab.rows.length-
1)a=-1;var e=Loc.tab.insertRow(a);if(d){e.className="rows";Loc.first_row=e.rowIndex}else{e.className="erows";Loc.second_row=e.rowIndex}e.onclick=function(){Loc.lineClick(e.rowIndex)};a=e.insertCell(-1);var f=document.createElement("TEXTAREA");if(d)a.className="c0";else{a.className="ec0";f.value=e.rowIndex/2}f.className="harea";f.readOnly=true;a.appendChild(f);a=e.insertCell(-1);f=document.createElement("TEXTAREA");if(d){a.className="c1";f.className="area";f.readOnly=true}else{a.className="ec1";f.className=
"earea"}if(b)f.value=b;a.appendChild(f);ev(f,"mousedown",onArea,0);a=e.insertCell(-1);f=document.createElement("TEXTAREA");if(d){a.className="c2";f.className="area";f.readOnly=true}else{a.className="ec2";f.className="earea"}if(c.description){f.value=c.description;d||Loc.translate(f)}a.appendChild(f);ev(f,"mousedown",onArea,0);a=e.insertCell(-1);f=document.createElement("TEXTAREA");if(d){a.className="c3";f.className="area";f.readOnly=true}else{a.className="ec3";f.className="earea"}if(c.message){f.value=
c.message;d||Loc.translate(f)}a.appendChild(f);ev(f,"mousedown",onArea,0);a=e.insertCell(-1);f=document.createElement("TEXTAREA");if(d){a.className="c4";f.className="area";f.readOnly=true}else{a.className="ec4";f.className="earea"}if(c.placeholders)f.value=JSON.stringify(c.placeholders);a.appendChild(f);ev(f,"mousedown",onArea,0)},parse:function(){var a;try{a=JSON.parse($("src").value)}catch(b){alert("JSON syntax error: "+b);return}$("step1").style.display="none";$("step2").style.display="block";
Loc.tab=$("tab");var c=$("fromlang"),d=$("tolang");Loc.translate_from_lang=c.value;Loc.translate_to_lang=d.value;for(var e in a)if(!(e=="_inf"||e=="_gen")){Loc.rowAdd(-1,e,a[e],true);Loc.rowAdd(-1,e,a[e],false)}Loc.parsed=1;Loc.first_row>0&&Loc.lineClick(1);$("plang").value=d.options[d.selectedIndex].text;$("panel").style.top=viewY(Loc.tab)+"px";$("panel").style.left=viewX(Loc.tab)-34+"px";$("panel").style.display="block"},stringify:function(){for(var a={},b=Loc.tab.getElementsByTagName("TEXTAREA"),
c,d=6;d<b.length;d+=10)if(b[d].value){c=b[d].value;a[c]={};if(b[d+2].value)a[c].message=b[d+2].value;if(b[d+1].value)a[c].description=b[d+1].value;if(b[d+3].value)a[c].placeholders=JSON.parse(b[d+3].value)}a._inf={};a._inf.message=$("pauthor").value;a._inf.description="Author";a._gen={};a._gen.message="Localizer, http://www.mixesoft.com/localizer.html";a._gen.description="Editor";try{$("dst").value=JSON.stringify(a,null,"\t");$("enc").checked&&Loc.stringify2()}catch(e){alert("JSON.stringify failed: "+
e);return 0}return 1},stringify2:function(){for(var a="{",b=Loc.tab.getElementsByTagName("TEXTAREA"),c=6;c<b.length;c+=10)if(b[c].value){a+='\n\t"'+b[c].value+'": {';if(b[c+2].value)a+='\n\t\t"message": "'+b[c+2].value+'"';if(b[c+1].value)a+=',\n\t\t"description": "'+b[c+1].value+'"';if(b[c+3].value)a+=',\n\t\t"placeholders": '+b[c+3].value;a+="\n\t},"}a+='\n\t"_inf": {\n\t\t"message": "'+$("pauthor").value+'",\n\t\t"description": "Author"\n\t},';a+='\n\t"_gen": {\n\t\t"message": "Localizer, http://www.mixesoft.com/localizer.html",\n\t\t"description": "Editor"\n\t}\n}';
$("dst").value=a}};function scrX(){return window.scrollX?scrollX:document.documentElement.scrollLeft}function scrY(){return window.scrollY?scrollY:document.documentElement.scrollTop}function viewX(a){for(var b=0;a.offsetParent;){b+=a.offsetLeft;a=a.offsetParent}return b+a.offsetLeft}function viewY(a){for(var b=0;a.offsetParent;){b+=a.offsetTop;a=a.offsetParent}return b+a.offsetTop}
function ev(a,b,c,d){if(d)if(a.removeEventListener){a.removeEventListener(b,c,0);a.removeEventListener(b,c,0)}else{a.detachEvent("on"+b,c,0);a.detachEvent("on"+b,c,0)}else if(a.addEventListener){a.addEventListener(b,c,0);a.addEventListener(b,c,0)}else{a.attachEvent("on"+b,c,0);a.attachEvent("on"+b,c,0)}}
function onArea(a){function b(j){for(var l=Loc.tab.rows,k=l.length,p=[],m=1;m<k;++m)p[m]=l[m].cells[j].firstChild;return p}function c(j){h=j.clientX+scrX()-f;g=j.clientY+scrY()-i;if(h<48)h="48px";else e.style.width=h+="px";if(g<8)g="8px";else e.style.height=g+="px";for(var l=n.length,k=0;k<l;++k)n[k].style.height=g;for(area in o)o[area].style.width=h;j.returnValue=false}function d(){ev(document,"mousemove",c,1);ev(document,"mouseup",d,1)}var e,f,i,h,g,q,n,o;if(a.target)e=a.target;else if(a.srcElement)e=
a.srcElement;f=viewX(e);i=viewY(e);if(a.clientX+scrX()>f+e.offsetWidth-20&&a.clientY+scrY()>i+e.offsetHeight-20){a=e.parentNode.parentNode;q=e.parentNode.cellIndex;n=a.getElementsByTagName("TEXTAREA");o=b(q);ev(document,"mousemove",c,0);ev(document,"mouseup",d,0)}}function $(a){return document.getElementById(a)};
