google.load("language", "1");
/**
The translate function, which does the translation using Google Ajax Language API, when the user
clicks the Translate Now button
*/
function translate()
{
  // get textarea that contains the text needs to be translated
  var text2bt = document.getElementById('text2bt');
  // get the drop-down that shows the chosen language to be translated from
  var frl = document.getElementById('frl');
  // get the drop-down that shows the chosen language to be translated to
  var tol = document.getElementById('tol');
  // then call the google translate method
  google.language.translate(text2bt.value, frl.value, tol.value,function(result) {
    if (!result.error) {
      // assign the translated text to the textarea
      var container = document.getElementById("textt");
      container.value = result.translation;
    }
  });
}

/**
The showLanguageDropDown function that dynamically generates the OPTIONS for the specified SELECT,
when the user first clicks on the specified SELECT
*/

function showLanguageDropDown(wsel,se){
  // Get the SELECT specified by ID in parameter wsel
  var frl=document.getElementById(wsel);
  // If the SELECT is NOT zero-length, then do nothing and return
  if (frl.length>0) return;
  // Else continue, and obtain the supported language Enumeration
  var a=google.language.Languages;
  var r=0;
  // Loop thru the Enumeration to assign the Option objects to the specified SELECT
  for(var key in a){
    var lan= key.toUpperCase();
    var lcode=a[key];
    if (google.language.isTranslatable(lcode)) {
        if(lcode==se)
        // mark "selected" for the default selection
          frl.options[r]= new Option (lan,lcode,true,true);
        else
          frl.options[r]=new Option (lan,lcode,false,false);
    }
    r++;
  }
}