function gtransl(from, to, msb, field,  if_brand){
    var text = document.getElementById(msb).value;
    google_help(from, to,text,  field,  if_brand, 1)
}

function other_letter_tr(from, to, msb, field, if_brand) {
    var text = document.getElementById(msb).innerHTML;
    google_help(from, to,text,  field, if_brand, 0)
}


function google_help(from, to, text, field, if_brand, if_to_hidden){
   var res="";
   var re = /(\.|\!|\?)([^\ ])/g;
   text = text.replace(re, "$1 $2");
  if(from == 'en') {var maxchars = 1000;} else {var maxchars = 300;}
    if(text.length < maxchars){
        google.language.translate(text, from, to,
             function(result) {
                if (!result.error) {res = result.translation; document.getElementById(field).innerHTML =res}
            }
        );
      if (if_brand==1) {google.language.getBranding('br'+field);};
      if (if_to_hidden==1) {window.setTimeout(function() { document.getElementById(field+"_h").value=res; }, 3000) };
      return true;
    }
    chunk = text.substr(0, maxchars);
    while(chunk.length)
    {
        dotpos = chunk.lastIndexOf('.');
        if(dotpos != -1) chunk = chunk.substr(0, dotpos+1);
            else if(chunk.lastIndexOf(',') != -1) chunk = chunk.substr(0, chunk.lastIndexOf(',')+1);
            else if(chunk.lastIndexOf(' ') != -1) chunk = chunk.substr(0, chunk.lastIndexOf(' ')+1);
        google.language.translate(chunk, from, to,
            function(result)
            {
                if (!result.error)  { document.getElementById(field).innerHTML = document.getElementById(field).innerHTML+ result.translation;
                    res=res+result.translation; }
            }
        );
        text = text.substr(chunk.length);
        chunk = text.substr(0, maxchars);
    };
   if (if_brand==1) {google.language.getBranding('br'+field);};
   if (if_to_hidden==1) {window.setTimeout(function() { document.getElementById(field+"_h").value=res; }, 3000) };
    return true;
}

