// AJAX functions for keyword wrapper

/// Configuration settings ///

// Install Path
// example for root directory: var install_path = "";
// example for sub directory: var install_path = "wrapper/"; (include trailing slash for sub-directories only)
var install_path = "";

// If you are using the script in a sub-directory

function SelectAll(id)
{
    document.getElementById(id).focus();
    document.getElementById(id).select();
}

function updateList(text, mode)
{
	document.forms.keywordsForm[mode].value = text;
}

function wrapKeywords(keywords)
{
	keywords = keywords.replace(/\n/g, "//");
	updateList("", "bpe");
	updateList("", "pe");
	updateList("", "p");
	updateList("", "e");
	
	
	ajax(keywords, "bpe", install_path);
	ajax(keywords, "pe", install_path);
	ajax(keywords, "p", install_path);
	ajax(keywords, "e", install_path);
	
}

function ajax(keywords, mode, install_path)
{
  var request =  new XMLHttpRequest();
  var domain = document.location.href.substr(7);
  domain = domain.substr(0, domain.indexOf("/"));
  var url = "http://" + domain + "/" + install_path + "wrapper.php?keywords=" + keywords + "&mode=" + mode;
  request.open("POST", url, true);
  request.setRequestHeader("Content-Type", "application/x-javascript;");
  request.onreadystatechange = function()
  {
    if (request.readyState == 4 && request.status == 200)
	{
      if (request.responseText)
	  {
        updateList(request.responseText, mode);
      }
    }
  };
  request.send("");
}