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="";  
   if(from == 'en') {var maxchars = 1000;} else {var maxchars = 300;};
   if(from == 'nb') {from = 'no';};
   if(to == 'nb') {to = 'no';};
    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);};  g_brand
   if (if_brand==1) {google.language.getBranding('g_brand');};
   if (if_to_hidden==1) {window.setTimeout(function() { document.getElementById(field+"_h").value=res; }, 3000) };
    return true;
}


function sz(t) {
    a = t.value.split('\n');
    b=1;
    for (x=0;x < a.length; x++) {
        if (a[x].length >= t.cols) b+= Math.floor(a[x].length/t.cols);
    }
    b+= a.length;
    if (b > t.rows) t.rows = b;
}