function update_img(image) {
  var img = document.getElementById('article_big');
  var a = document.getElementById('article_big_link');
  img.src = image;
  img.alt = image;
  a.href = image;
}

function showAddArticleForm(where) {
  var xmlHttp = GetXmlHttpObject();
  if(xmlHttp == null)
  {
    alert("Your browser does not support AJAX!");
  }
  xmlHttp.onreadystatechange=function()
  {
    if(xmlHttp.readyState==4)
    {
      var div = document.getElementById('addArticleFormDiv');
      div.innerHTML = xmlHttp.responseText;
    }
  }
  var url = "ajax.php?action=showAddArticleForm&where=" + where;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function hideAddArticleForm(page) {
  var div = document.getElementById('addArticleFormDiv');
  div.innerHTML = "<div class='header_button'><div class='header_button_left'></div><a href='#' onclick='showAddArticleForm("+page+")' class='header_button_middle'>L&auml;gg till ny artikel</a><div class='header_button_right'></div></div>";
}

function addManufacturer() {
  var xmlHttp = GetXmlHttpObject();
  if(xmlHttp == null)
  {
    alert("Your browser does not support AJAX!");
  }
  xmlHttp.onreadystatechange=function()
  {
    if(xmlHttp.readyState==4)
    {
      var select = document.getElementById('manufacturers');
      select.innerHTML = xmlHttp.responseText;
    }
  }
  var manufacturer = document.getElementById("newManufacturer");
  var url = "ajax.php?action=addManufacturer&name=" + manufacturer.value;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function addCategory() {
  var xmlHttp = GetXmlHttpObject();
  if(xmlHttp == null)
  {
    alert("Your browser does not support AJAX!");
  }
  xmlHttp.onreadystatechange=function()
  {
    if(xmlHttp.readyState==4)
    {
      var select = document.getElementById('categories');
      select.innerHTML = xmlHttp.responseText;
    }
  }
  var category = document.getElementById("newCategory");
  var url = "ajax.php?action=addCategory&name=" + category.value;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function setThumb(image) {
  var xmlHttp = GetXmlHttpObject();
  if(xmlHttp == null)
  {
    alert("Your browser does not support AJAX!");
  }
  xmlHttp.onreadystatechange=function()
  {
    if(xmlHttp.readyState==4)
    {
      var span = document.getElementById('addedImages');
      span.innerHTML = xmlHttp.responseText;
    }
  }
  var url = "ajax.php?action=setThumb&image=" + image;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function deleteImage(image) {
  var xmlHttp = GetXmlHttpObject();
  if(xmlHttp == null)
  {
    alert("Your browser does not support AJAX!");
  }
  xmlHttp.onreadystatechange=function()
  {
    if(xmlHttp.readyState==4)
    {
      var span = document.getElementById('addedImages');
      span.innerHTML = xmlHttp.responseText;
    }
  }
  var url = "ajax.php?action=deleteImage&image=" + image;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function sendOrder() {
  var xmlHttp = GetXmlHttpObject();
  if(xmlHttp == null)
  {
    alert("Your browser does not support AJAX!");
  }
  xmlHttp.onreadystatechange=function()
  {
    if(xmlHttp.readyState==4)
    {
      self.location.href = 'min_sida.php';
    }
  }
  var msg = encodeURI(document.getElementById("ordermsg").value);
  var url = "sendOrder.php?msg=" + msg;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function GetXmlHttpObject() {
  var xmlHttp=null;
  try
  {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  {
    // Internet Explorer
    try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  ie = true;
    }
    catch (e)
    {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  ie = false;
    }
  }
  return xmlHttp;
}
