function CreateAjaxPopup (div_id,parent_div_id) {
  var ParentDiv = document.getElementById(parent_div_id);
  var AjaxPopupDiv = document.createElement("div");

  var curleft = curtop = 0;
  obj=ParentDiv;
  if (obj.offsetParent) {
    do {
      curleft += obj.offsetLeft;
      curtop += obj.offsetTop;
    } while (obj = obj.offsetParent);
  }

  AjaxPopupDiv.id = div_id;
  AjaxPopupDiv.className= "ajax_popup";
  AjaxPopupDiv.style.top = curtop + ParentDiv.offsetTop;
  AjaxPopupDiv.style.left = curleft + ParentDiv.offsetLeft;
  AjaxPopupDiv.style.width = ParentDiv.offsetWidth+"px";
  AjaxPopupDiv.style.height = ParentDiv.offsetHeight+"px";
  AjaxPopupDiv.style.visibility = "visible";
  ParentDiv.appendChild(AjaxPopupDiv);
}

function ShowAjaxLoading (div_id) {
  var MainDiv = document.getElementById(div_id);
  var AjaxLoadingDiv = document.createElement("div");

  var curleft = curtop = 0;
  obj=MainDiv;
  if (obj.offsetParent) {
    do {
      curleft += obj.offsetLeft;
      curtop += obj.offsetTop;
    } while (obj = obj.offsetParent);
  }

  AjaxLoadingDiv.id = "ajax_loading_div";
  AjaxLoadingDiv.className= "ajax_loading";
  //AjaxLoadingDiv.style.top = curtop + MainDiv.offsetTop;
  //AjaxLoadingDiv.style.left = curleft + MainDiv.offsetLeft;
  AjaxLoadingDiv.style.width = MainDiv.offsetWidth+"px";
  AjaxLoadingDiv.style.height = MainDiv.offsetHeight+"px";
  AjaxLoadingDiv.style.visibility = "visible";
  var MainDivParent = MainDiv.parentNode;
  MainDivParent.appendChild(AjaxLoadingDiv);
}

function HideAjaxLoading (div_id) {
  var MainDiv = document.getElementById(div_id);
  var AjaxLoadingDiv = document.getElementById("ajax_loading_div");
  var MainDivParent = MainDiv.parentNode;
  MainDivParent.removeChild(AjaxLoadingDiv);
}


function ajaxFunction(scripttocall,div_id){
  var ajaxRequest;  // The variable that makes Ajax possible!
  var AjaxLoadingDivIsShown=false;
	
  try{
    // Opera 8.0+, Firefox, Safari
    ajaxRequest = new XMLHttpRequest();
  } catch (e){
    // Internet Explorer Browsers
    try{
      ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try{
	ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e){
	// Something went wrong
	alert("Your browser broke!");
	return false;
      }
    }
  }

  // Create a function that will receive data sent from the server
  ajaxRequest.onreadystatechange = function(){
    if (ajaxRequest.readyState==4 && ajaxRequest.status==200) {
      var response = ajaxRequest.responseText;
      if (response == '$command=window.reload;') {
        window.location.reload();
      } else {
        var ajaxDisplay = document.getElementById(div_id);
        ajaxDisplay.innerHTML = response;
        HideAjaxLoading(div_id);
      }
    } else {
      if (ajaxRequest.readyState==1 && AjaxLoadingDivIsShown==false) {
        var ajaxDisplay = document.getElementById(div_id);
        ShowAjaxLoading(div_id);
        AjaxLoadingDivIsShown=true;
      }
    }
  }

  ajaxRequest.open("GET", scripttocall, true);
  ajaxRequest.send(null); 
}


function ajaxSubmitPostForm(input_form,scripttocall,div_id){
  var ajaxRequest;  // The variable that makes Ajax possible!
  var AjaxLoadingDivIsShown=false;

  try{
    // Opera 8.0+, Firefox, Safari
    ajaxRequest = new XMLHttpRequest();
  } catch (e){
    // Internet Explorer Browsers
    try{
      ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try{
        ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e){
	// Something went wrong
	alert("Your browser broke!");
	return false;
      }
    }
  }
	
  var num_elements = document.getElementById(input_form).elements.length;
  input_string= "";
  for(var i = 0; i < num_elements; i++){
    if(i < num_elements-1){
      input_string += document.getElementById(input_form).elements[i].name+"="+encodeURIComponent(document.getElementById(input_form).elements[i].value)+"&";
    } else  {
      input_string += document.getElementById(input_form).elements[i].name+"="+encodeURIComponent(document.getElementById(input_form).elements[i].value);
    } 
  }

  // Create a function that will receive data sent from the server
  ajaxRequest.onreadystatechange = function(){
    var response = ajaxRequest.responseText;
    if (ajaxRequest.readyState==4 && ajaxRequest.status==200) {
      if (response == '$command=window.reload;') {
        window.location.reload();
      } else {
        var ajaxDisplay = document.getElementById(div_id);
        ajaxDisplay.innerHTML = response;
        HideAjaxLoading(div_id);
      }
    } else {
      if (ajaxRequest.readyState==1 && AjaxLoadingDivIsShown==false) {
        var ajaxDisplay = document.getElementById(div_id);
        ShowAjaxLoading(div_id);
        AjaxLoadingDivIsShown=true;
      }
    }
  }
  
  ajaxRequest.open("POST",scripttocall,true);
  ajaxRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
  ajaxRequest.send(input_string);
}


	   