// HTTP通信用、共通関数

function $(tagId)
{
return document.getElementById(tagId);
}

function createXMLHttpRequest(cbFunc)
{
var XMLhttpObject = null;
try{
XMLhttpObject = new XMLHttpRequest();
}catch(e){
try{
XMLhttpObject = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
XMLhttpObject = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
return null;
}
}
}
if (XMLhttpObject) XMLhttpObject.onreadystatechange = cbFunc;
return XMLhttpObject;
}

function requestAppendTangocho( no, word, jp )
{
httpObj = createXMLHttpRequest(displayTangocho);
if (httpObj)
{
httpObj.open("GET","?action=add_tangocho&no="+no,true);
httpObj.send(null);
}

function displayTangocho()
{

if ((httpObj.readyState == 4) && (httpObj.status == 200))
{

if(httpObj.responseText == 'append' ){

//ガイドを消す
if($('tangocho_guide')){
$('tangocho_guide').style.display = 'none';
}
newword = word + '　' + jp;

//単語の行を後ろ送り
  for (i=0; i< $('tangocho').childNodes.length; i++)
  {
  if (($('tangocho').childNodes[i].nodeType == 1) && ($('tangocho').childNodes[i].tagName == "P"))
  {
  next = $('tangocho').childNodes[i].childNodes[0].nodeValue;
  $('tangocho').childNodes[i].childNodes[0].nodeValue = newword;
  newword = next;
  }
  }

  //一行を追加
  newObj = document.createElement("p");
  newObj.innerHTML = newword;
  $('tangocho').appendChild(newObj);

  $('tangocho_message').innerHTML = word + ' を追加しました。';

}else {
  $('tangocho_message').innerHTML = decodeURI( httpObj.responseText );
}

}

}
}

function requestRemoveTangocho( no, word, jp )
{
httpObj = createXMLHttpRequest(displayTangochoDelete);
if (httpObj)
{
httpObj.open("GET","?action=del_tangocho&word="+word,true);
httpObj.send(null);
}

function displayTangochoDelete()
{

if ((httpObj.readyState == 4) && (httpObj.status == 200))
{

if(httpObj.responseText == 'remove' ){

//ガイドを消す
if($('tangocho_guide')){
$('tangocho_guide').style.display = 'none';
}
delword = word + '　' + decodeURI( jp );

//単語の行を後ろ送り
  for (i=0; i< $('tangocho').childNodes.length; i++)
  {
  if (($('tangocho').childNodes[i].nodeType == 1) && ($('tangocho').childNodes[i].tagName == "P"))
  {

  if( $('tangocho').childNodes[i].childNodes[0].nodeValue == delword ){
      $('tangocho').removeChild($('tangocho').childNodes[i]);
  }
  }
  }

  $('tangocho_message').innerHTML = word + ' を削除しました。';

}else {
  $('tangocho_message').innerHTML = decodeURI( httpObj.responseText );
}

}

}
}

function displayData()
{
if ((httpObj.readyState == 4) && (httpObj.status == 200))
{
window.status = httpObj.responseText;
document.getElementById("chk"+no).setAttribute("onclick", "requestMask('" +no+ "', '" + newoption + "')");
}else{
window.status = "Updating ...";
}
}


