var ck = "";
var ID = "";
var xmlhttp = null;

function chkCookie(iQaID) {
               
  //XMLHttpRequestを生成する
  if (!xmlhttp) {
    xmlhttp = createXMLHttp();
  }
  if (!xmlhttp || xmlhttp.readyState == 1 
               || xmlhttp.readyState == 2 
               || xmlhttp.readyState == 3) {
    return; 
  }
  
  ck = getCookie();
  ID = iQaID;
//  alert(ck);


  if (iQaID != "" && ck != "") {
    xmlhttp.open("GET", "/jts/chkCookie?cookie=" + ck + "&qaid=" + ID, true);
    xmlhttp.setRequestHeader("If-Modified-Since", "Thu, 01 Jun 1970 00:00:00 GMT");
    xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        if(xmlhttp.responseText != ""){
          document.getElementById("del-question").innerHTML = xmlhttp.responseText;
        }
      }
    }
    xmlhttp.send(null);
  }
}


function getCookie(){
  var chkArray = new Array();
  chkArray = document.cookie.split("; ");
//  alert(document.cookie);
  var i = 0;
  while (chkArray[i]) {
//  alert(chkArray[i]);
    if(chkArray[i].indexOf("regqs=") == 0){
      return chkArray[i].substring(6, chkArray[i].length);
//      alert(ck);
    }
    i++;
  }
}

function deleteQA(bChk){
  if (bChk == true) {
    xmlhttp = null;
    var check = "";
    if (!xmlhttp) {
      xmlhttp = createXMLHttp();
    }
    if (!xmlhttp || xmlhttp.readyState == 1 
                 || xmlhttp.readyState == 2 
                 || xmlhttp.readyState == 3){
      return; 
    }
    xmlhttp.open("GET", "/jts/chkCookie?cookie=" + ck + "&qaid=" + ID + "&type=del", true);
    xmlhttp.send(null);
//    xmlhttp.onreadystatechange = function() {
//      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
//        check = xmlhttp.responseText;
//      }
//    }
//    if(check.indexOf("true") != -1) {
      alert("現在削除中です。もうしばらくお待ち下さい。");
      window.location.href = '/';
//    } else {
//      alert("削除に失敗しました");
//    }
  }
}
