
function de_urlcheck() {
  if (document.getElementById("target_url").value == "") {
    window.alert("Please enter the web address of an article, text, manual, etc.");
    return false;
  }
  if (!document.getElementById("target_url").value.match(".*[.].*")) {
    window.alert("Please enter a valid web address.");
    return false;
  }
}

function de_check() {
  if (document.getElementById("user_name").value == "") {
    window.alert("Please enter a user name.");
    return false;
  }
  if (!document.getElementById("email_1").value.match(".*@.*\..*")) {
    window.alert("Please enter a valid email address.");
    return false;
  }
  if (document.getElementById("password_1").value == "") {
    window.alert("Please enter a password.");
    return false;
  }
  if (document.getElementById("email_1").value != document.getElementById("email_2").value) {
    window.alert("Email addresses don't match!");
    return false;
  }
  if (document.getElementById("password_1").value != document.getElementById("password_2").value) {
    window.alert("Passwords don't match!");
    return false;
  }
  return true;
}

function de_hide(deindex, url_id, de_server) {
  de_html  = '&nbsp;&nbsp;<font color=red><b>Are you sure?</b></font>&nbsp;';
  de_html += '<button style="font-size:8pt;padding-left:0;text-align:left;height:18px;width:23px;" type=button onClick=javascript:de_nohide('+url_id+')>no</button>';
  de_html += '&nbsp;';
//  de_html += '<form style="display:inline" method=post action='+de_server+'index.php>';
  de_html += '<form style="display:inline" method=post onsubmit="return yes_hide(\''+deindex+'\', '+url_id+');" action="javascript:void();">';
//  de_html += '<input type=hidden name=hide value=1>';
//  de_html += '<input type=hidden name=ui value='+url_id+'>';
  de_html += '<button style="font-size:8pt;padding-left:0;text-align:left;height:18px;width:29px;" type=submit>yes</button>';
  de_html += '</form>';

  document.getElementById('de_del_label_'+url_id).style.display = 'none';
  document.getElementById('de_hide_'+url_id).innerHTML = de_html;

}

function yes_hide(deindex, url_id) {
  if (typeof yes_hide.xmlhttp == 'undefined') {
    yes_hide.xmlhttp = de_xmlinit();
  }
  var url = "actions.php";
  var params = "action=h&uid="+url_id;

  yes_hide.xmlhttp.open('POST', url, true);

  // send required header info
  yes_hide.xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//  yes_hide.xmlhttp.setRequestHeader("Content-length", params.length);
//  yes_hide.xmlhttp.setRequestHeader("Connection", "close");

  yes_hide.xmlhttp.onreadystatechange = function() {
    if(yes_hide.xmlhttp.readyState == 1) {
      // nothing
    } else if(yes_hide.xmlhttp.readyState == 4 && yes_hide.xmlhttp.status == 200) {
      if (yes_hide.xmlhttp.responseText == 0) {
        // remove this item from the DOM tree
        document.getElementById(deindex).style.display = "none";
      } else {
//        window.alert(yes_hide.xmlhttp.responseText);
        window.alert("Error: Could not hide this entry.");
      }
    }
  };
  yes_hide.xmlhttp.send(params);  
  return false;
}

function de_nohide(url_id) {
  document.getElementById('de_hide_'+url_id).innerHTML = '&nbsp;';
  document.getElementById('de_del_label_'+url_id).style.display = 'inline';
}

//function de_delete(url_id, de_server, in_history) {
function de_delete(deindex, url_id, de_server) {

  de_html  = '&nbsp;&nbsp;<font color=red><b>Are you sure?</b></font>&nbsp;';
  de_html += '<button style="font-size:8pt;padding-left:0;text-align:left;height:18px;width:23px;" type=button onClick=javascript:de_nodelete('+url_id+')>no</button>';
  de_html += '&nbsp;';
  de_html += '<form style="display:inline" method=post onsubmit="return yes_delete(\''+deindex+'\', '+url_id+');" action="javascript:void();">';
//  if (in_history == 1) {
//    de_html += '<input type=hidden name=hist value=1>';
//  }
//  de_html += '<input type=hidden name=del value=1>';
//  de_html += '<input type=hidden name=ui value='+url_id+'>';
  de_html += '<button style="font-size:8pt;padding-left:0;text-align:left;height:18px;width:29px;" type=submit>yes</button>';
  de_html += '</form>';

  if (document.getElementById('de_delsamples_label_'+url_id)) {
    document.getElementById('de_delsamples_label_'+url_id).style.display = 'none';
  }
  if (document.getElementById('de_delnews_label_'+url_id)) {
    document.getElementById('de_delnews_label_'+url_id).style.display = 'none';
  }
  document.getElementById('de_delete_'+url_id).innerHTML = de_html;
}

function yes_delete(deindex, url_id) {
  if (typeof yes_delete.xmlhttp == 'undefined') {
    yes_delete.xmlhttp = de_xmlinit();
  }
  var url = "actions.php";
  var params = "action=d&uid="+url_id;

  yes_delete.xmlhttp.open('POST', url, true);

  // send required header info
  yes_delete.xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//  yes_delete.xmlhttp.setRequestHeader("Content-length", params.length);
//  yes_delete.xmlhttp.setRequestHeader("Connection", "close");

  yes_delete.xmlhttp.onreadystatechange = function() {
    if(yes_delete.xmlhttp.readyState == 1) {
      // nothing
    } else if(yes_delete.xmlhttp.readyState == 4 && yes_delete.xmlhttp.status == 200) {
      if (yes_delete.xmlhttp.responseText == 0) {
        // remove this item from the DOM tree
        document.getElementById(deindex).style.display = "none";
      } else {
//        window.alert(yes_delete.xmlhttp.responseText);
        window.alert("Error: Could not delete this entry.");
      }
    }
  };
  yes_delete.xmlhttp.send(params);  
  return false;

}

function de_xmlinit() {
  if (typeof XMLHttpRequest != "undefined") {
    xmlhttp = new XMLHttpRequest();
    return xmlhttp;
  } else if (typeof ActiveXObject != "undefined") {
    return new ActiveXObject("Microsoft.XMLHTTP");
  } else {
    throw new Error("XMLHttpRequest not supported");
  }
}

function de_nodelete(url_id) {
  document.getElementById('de_delete_'+url_id).innerHTML = '&nbsp;';
  if (document.getElementById('de_delsamples_label_'+url_id)) {
    document.getElementById('de_delsamples_label_'+url_id).style.display = 'inline';
  }
  if (document.getElementById('de_delnews_label_'+url_id)) {
    document.getElementById('de_delnews_label_'+url_id).style.display = 'inline';
  }
}

function de_delete_samples(url_id, de_server, in_history) {
//  var yes_delete_samples;

//  yes_delete_samples = de_server+"index.php?";
//  if (in_history == 1) {
//    yes_delete_samples += "hist=1&";
//  }
//  yes_delete_samples += "del_s=1";

  de_html  = '&nbsp;&nbsp;<font color=red><b>Are you sure?</b></font>&nbsp;';
  de_html += '<button style="font-size:8pt;padding-left:0;text-align:left;height:18px;width:23px;" type=button onClick=javascript:de_nodelete_samples('+url_id+')>no</button>';
  de_html += '&nbsp;';
  de_html += '<form style="display:inline" method=post action='+de_server+'index.php>';
  if (in_history == 1) {
    de_html += '<input type=hidden name=hist value=1>';
  }
  de_html += '<input type=hidden name=del_s value=1>';
  de_html += '<button style="font-size:8pt;padding-left:0;text-align:left;height:18px;width:29px;" type=submit>yes</button>';
  de_html += '</form>';

  document.getElementById('de_delete_samples_'+url_id).innerHTML = de_html;

//  document.getElementById('de_delete_samples_'+url_id).innerHTML = '<font color=red>&nbsp;are you sure? <a style=color:red href=javascript:de_nodelete_samples('+url_id+')>no</a>&nbsp;<a style=color:red href='+yes_delete_samples+'>yes</a></font>';
}

function de_delete_news(url_id, de_server, in_history) {

  de_html  = '&nbsp;&nbsp;<font color=red><b>Are you sure?</b></font>&nbsp;';
  de_html += '<button style="font-size:8pt;padding-left:0;text-align:left;height:18px;width:23px;" type=button onClick=javascript:de_nodelete_news('+url_id+')>no</button>';
  de_html += '&nbsp;';
  de_html += '<form style="display:inline" method=post action='+de_server+'index.php>';
  if (in_history == 1) {
    de_html += '<input type=hidden name=hist value=1>';
  }
  de_html += '<input type=hidden name=del_n value=1>';
  de_html += '<button style="font-size:8pt;padding-left:0;text-align:left;height:18px;width:29px;" type=submit>yes</button>';
  de_html += '</form>';

  document.getElementById('de_delete_news_'+url_id).innerHTML = de_html;

//  document.getElementById('de_delete_news_'+url_id).innerHTML = '<font color=red>&nbsp;are you sure? <a style=color:red href=javascript:de_nodelete_news('+url_id+')>no</a>&nbsp;<a style=color:red href='+yes_delete_news+'>yes</a></font>';
}

function de_nodelete_samples(url_id) {
  document.getElementById('de_delete_samples_'+url_id).innerHTML = '&nbsp;';
}

function de_nodelete_news(url_id) {
  document.getElementById('de_delete_news_'+url_id).innerHTML = '&nbsp;';
}
