var xmlHttp;
var url;
var wait = 0;

function hyphenate(){ 
  if (wait==1){ return false; }
  wait = 1;
  setTimeout("wait=0",3000);
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null){
     alert ("Browser does not support HTTP Request");
     return false;
  } 
  var word=encodeURIComponent(document.forms[0].word.value.replace(/^\s\s*/, '').replace(/\s\s*$/, ''));
  var lang=encodeURIComponent(document.forms[0].lang.value);
  url="hyphenate.php";
  url=url+"?word="+word+"&lang="+lang;
  if (!cookieEnabled && sid!=''){
     url=url+"&"+sid;
  }
  xmlHttp.onreadystatechange=updatePage;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function updatePage(){ 
  document.getElementById("button_div").style.backgroundImage="url(loader.gif)";  
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
     result = xmlHttp.responseText;
     document.getElementById("hyph").innerHTML=result;
     document.forms[0].word.select();
     document.getElementById("button_div").style.backgroundImage="none"; 
     _gaq.push(['_trackPageview', '/hyphen/'+url]);
  } 
}

function showInfo(){
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null){
     alert ("Browser does not support HTTP Request");
     return false;
  }
  var lang=encodeURIComponent(document.forms[0].lang.value);
  url="showinfo.php";
  url=url+"?ln="+ln+"&lang="+lang;
  xmlHttp.onreadystatechange=updateInfo;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function updateInfo(){
  document.getElementById("button_div").style.backgroundImage="url(loader.gif)";
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
     result = xmlHttp.responseText;
     document.getElementById("info").innerHTML=result;
     showDiv();
     document.getElementById("button_div").style.backgroundImage="none";
     _gaq.push(['_trackPageview', '/hyphen/'+url]);
  }
}

function hideDiv(){ 
  if (document.getElementById){ 
     // DOM3 = IE5, NS6 
     document.getElementById('hideshow').style.visibility = 'hidden'; 
  } 
  else { 
     if (document.layers){ 
        // Netscape 4 
        document.hideshow.visibility = 'hidden'; 
     } 
     else{ 
        // IE 4 
        document.all.hideshow.style.visibility = 'hidden'; 
     } 
  } 
}
 
function showDiv(){ 
  if (document.getElementById){ 
     // DOM3 = IE5, NS6 
     document.getElementById('hideshow').style.visibility = 'visible'; 
  } 
  else { 
     if (document.layers){ 
        // Netscape 4 
        document.hideshow.visibility = 'visible'; 
     } 
     else{ 
        // IE 4 
        document.all.hideshow.style.visibility = 'visible'; 
     } 
  } 
}
 
function GetXmlHttpObject(){
  var xmlHttp=null;
  try{
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  catch (e){
    //Internet Explorer
    try{
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e){
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}

