var LP = "en|fr";//EDIT HERE to Default Language Pair
const URL = "translate.php";//EDIT HERE to file URL

var tag = document.getElementsByTagName("span");
var AJAX = false;
if(window.XMLHttpRequest){AJAX = new XMLHttpRequest();}
else if(window.ActiveXObject){AJAX = new ActiveXObject("Microsoft.XMLHTTP");}

function e(){
for(i=0;i < tag.length;i++){
 if(tag[i].getAttribute("class") == "t"){
  tag[i].setAttribute('onclick', 'g("'+tag[i].innerHTML+'",'+i+')');
 }
}
}
function r(m, id, s){
 tag[id].innerHTML = m;
 tag[id].setAttribute('onclick', 'r("'+s+'", '+id+', "'+m+'")');
}

function g(t, id){
 if(AJAX){
  AJAX.open("GET", URL+"?lp="+LP+"&text="+t);
  AJAX.onreadystatechange = function(){
   if(AJAX.readyState == 4 && AJAX.status == 200){
    tag[id].innerHTML = AJAX.responseText;
    tag[id].setAttribute('onclick', 'r("'+t+'", '+id+', "'+AJAX.responseText+'")');
   }
  }
   AJAX.send(null);
 }
}
window.addEventListener("load", e, false);