
function init()
{
  document.onmousemove = update; // update(event) implied on NS, update(null) implied on IE
  update();
}

function update(e)
{
  getMouseXY(e); // NS is passing (event), while IE is passing (null)
}

function getMouseXY(e) // works on IE6,FF,Moz,Opera7
{ 
  if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)
 
  if (e)
  { 
if (e.clientX || e.clientY)
    { // works on IE6,FF,Moz,Opera7
      // Note: I am adding together both the "body" and "documentElement" scroll positions
      //       this lets me cover for the quirks that happen based on the "doctype" of the html page.
      //         (example: IE6 in compatibility mode or strict)
      //       Based on the different ways that IE,FF,Moz,Opera use these ScrollValues for body and documentElement
      //       it looks like they will fill EITHER ONE SCROLL VALUE OR THE OTHER, NOT BOTH 
      //         (from info at http://www.quirksmode.org/js/doctypes.html)
      mousex = e.clientX;
      mousey = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
    }
  }
  /*
  if((e.clientY+30) > getInnerHeight(self))
	{
	  pageScroll('down', 0, ((e.clientY+50) - getInnerHeight(self)));
	  //window.scrollBy(0,((e.clientY+50) - getInnerHeight(self)));
	}
 else if((e.clientY - 30) < 0)
	{
	  pageScroll('up', 0, ((e.clientY - 50) * -1));
	  //window.scrollBy(0,(e.clientY - 50));
	}
	*/

}

/*
function pageScroll(direction, count, max) {
	if(direction == 'up') window.scrollBy(0,-1); // horizontal and vertical scroll increments
	if(direction == 'down') window.scrollBy(0,1); // horizontal and vertical scroll increments
	count++;
	if(count < max) setTimeout('pageScroll("'+direction+'",'+count+','+max+')',100); // scrolls every 100 milliseconds
}
*/


function trackit(layer)
{
	if (!e) var e = window.event||window.Event;
	getMouseXY(e);
	laag = document.getElementById(layer);
	contentPos = getPos(document.getElementById('main'));
	laag.style.left = (mousex  + 30 - contentPos.x) + 'px';
	laag.style.top = (mousey  + 20 - contentPos.y) + 'px';
}

function getPos(theObj){
  x = y = 0;
  h = theObj.offsetHeight;
  w = theObj.offsetWidth;
  while(theObj){
    x += theObj.offsetLeft;
    y += theObj.offsetTop;
    theObj = theObj.offsetParent;
  }
  return {height:h,width:w,x:x,y:y}
}

function getInnerWidth(win) {
  var winWidth;
  if (win.innerWidth) {
    winWidth = win.innerWidth;
  }
  else if (win.document.documentElement && win.document.documentElement.clientWidth) {
    winWidth = win.document.documentElement.clientWidth;
  }
  else if (document.body) {
    winWidth = win.document.body.clientWidth;
  }
  return winWidth;
}

function getInnerHeight(win) {
  var winHeight;
  if (win.innerHeight) {
    winHeight = win.innerHeight;
  }
  else if (win.document.documentElement && win.document.documentElement.clientHeight) {
    winHeight = win.document.documentElement.clientHeight;
  }
  else if (win.document.body) {
    winHeight = win.document.body.clientHeight;
  }
  return winHeight;
}

function openVenster(breedte, hoogte, hor_pos, vert_pos, url, naam)
{
	var opties =  "toolbar=no,status=no,menubar=no,scrollbars=0,resizable=no,width="+breedte+",height="+hoogte+",top="+vert_pos+",left="+hor_pos+";"
	newWindow = window.open(url , naam , opties);
}

function getRadioValue(field)
{
	for (var i = 0; i < field.length; i++)
	{
		if (field[i].checked)
		{
			return i;
		}
	}
	return null;
}

function checkMandatoryField(mandatory, field)
{
	if(field.value == "" && mandatory == true)
		field.className = "fieldError";
	else if(field.value != "")
		field.className = "fieldOk";
	else
		field.className = "orderField";
	return true;
}

function updateCartValues(object_name, object_id, new_value, country_id, elem_id) 
{
	url = "ajax_handler.php?action=update&object="+object_name+"&object_id="+object_id+"&new_value="+new_value+"&rdm="+Math.floor(Math.random()*10000000000000000);
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport){
		  handleValueUpdate(elem_id, transport.responseText);
		  if(object_name == "orderline_temp")
		  {
			  updateTempOrderTotal(country_id);
			  updateTempShippingCost(country_id);
		  }
	  }
	});
}

function updateTempOrderTotal(country_id)
{
	url = "ajax_handler.php?action=get&item=orderlines_total&country_id="+country_id+"&rdm="+Math.floor(Math.random()*10000000000000000);
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport){
		  handleValueUpdate("orderlines_total", transport.responseText);
	  }
	});
}
function updateTempShippingCost(country_id)
{
	url = "ajax_handler.php?action=get&item=shipment_rate&country_id="+country_id+"&rdm="+Math.floor(Math.random()*10000000000000000);
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport){
		  handleValueUpdate("shipment_rate", transport.responseText);
	  }
	});
}

function getNewValue(item, item_id, elem_id) 
{
	url = "ajax_handler.php?action=get&item="+item+"&item_id="+item_id+"";
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport){
		  handleValueUpdate(elem_id, transport.responseText);
	  }
	});
}

function handleValueUpdate(elem_id, responseText) 
{
	document.getElementById(elem_id).innerHTML = responseText;
	//Effect.Highlight($(elem_id).up('.cart_cell2'));
}