/*
   Global site javascript.
*/

var objMovedOver = null;

function addArea(obj)
{
  theForm = document.createElement("form");
  area_nr = document.createElement("input");
  
  area_nr.value = obj.name;
  area_nr.type = "hidden";
  area_nr.name = "add_area_nr";
  
  theForm.method = "post";
  theForm.action = "";
  theForm.name = "add_area_nr";
  theForm.appendChild(area_nr);
  
  document.body.appendChild(theForm);
  
  theForm.submit();
}

function deleteArea(obj)
{
  theForm = document.createElement("form");
  area_nr = document.createElement("input");
  
  area_nr.value = obj.name;
  area_nr.type = "hidden";
  area_nr.name = "delete_area_nr";
  
  theForm.method = "post";
  theForm.action = "";
  theForm.name = "delete_area_nr";
  theForm.appendChild(area_nr);
  
  document.body.appendChild(theForm);
  
  theForm.submit();
}

function changeProvince(obj)
{
  if (obj != "")
  {
    theForm = document.createElement("form");
    province = document.createElement("input");
    
    province.value = obj;
    province.type = "hidden";
    province.name = "province_change";
    
    theForm.method = "post";
    theForm.action = "";
    theForm.name = "province_change";
    theForm.appendChild(province);
    
    document.body.appendChild(theForm);
    
    theForm.submit();
  }
}

function show(type, nr, obj)
{
  var moveableDiv = document.getElementById("moveableDiv");
  moveableDiv.style.display = "block";
  
  moveableDiv.innerHTML = document.getElementById(type+"_"+nr).innerHTML;
  
  objMovedOver = obj;
  objMovedOver.onmousemove = moveThis;
}

function stopShow(obj)
{
  var moveableDiv = document.getElementById("moveableDiv");

  moveableDiv.style.display = "none";
  moveableDiv.innerHTML = "";
  
  objMovedOver.onmousemove = null;
  objMovedOver = null;
}

function findPos(obj)
{
	var curleft = curtop = 0;
	
	if (obj.offsetParent)
	{
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		
		while (obj = obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	
	return [curleft,curtop];
}

function moveThis(e)
{
  if (objMovedOver != null)
  {
    var posx = 0;
    var posy = 0;
  
    if (!e)
    {
      e = window.event;
    }

    if (e.pageX || e.pageY)
    {
      posx = e.pageX;
      posy = e.pageY;
    }
    else if (e.clientX || e.clientY)
    {
      var theDiv = document.getElementById("scrollDiv");
      var pos = findPos(theDiv);
      posx = e.clientX + theDiv.scrollLeft - pos[0];
      posy = e.clientY + theDiv.scrollTop - pos[1];
    }

    var moveableDiv = document.getElementById("moveableDiv");

    moveableDiv.style.left = posx + 10;
    moveableDiv.style.top  = posy + 10;
  }
}

function sortCol(column, direction)
{
  theForm = document.createElement("form");
  col     = document.createElement("input");
  dir     = document.createElement("input");
  
  col.value = column;
  col.type = "hidden";
  col.name = "sort";
  
  dir.value = direction;
  dir.type  = "hidden";
  dir.name  = "sortdirection";
  
  theForm.method = "post";
  theForm.action = "";
  theForm.name = "sort_column";
  theForm.appendChild(col);
  theForm.appendChild(dir);
  
  document.body.appendChild(theForm);
  
  theForm.submit();
}