function bid_box(action, id, maxAmount) {
	document.getElementById('box_bids').style.display=action;
	document.getElementById('box_bids_content').style.display=action;

	// Clear error message if errorMssg object exists
	if (document.getElementById('errorMssg')) document.getElementById('errorMssg').innerHTML = "";

	if (id) {
		document.getElementById('hiddenValues').innerHTML = '<input type="hidden" name="productid" id="productid" value="'+id+'" />';
		document.getElementById('hiddenValues').innerHTML += '<input type="hidden" name="maxAmount" id="maxAmount" value="'+parseFloat(maxAmount)+'" />';
	}
	
	// If the close button is pressed, reset the content of the DIV. If not, the message that an email was send still appears
	if (action=='none') {
		new Ajax.Updater('box_bids_content', 
  									'/site/kringloop/kringloop_bid.php');
	}
}

function validateEmail(mail) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(mail) == false) {
	  return false;	
  } else {
  	return true;
	}
}

function bid_boxSend() {
	amount		= document.getElementById('amount').value;
	amount		= amount.replace(",", ".");
	amount		= parseFloat(amount);


	maxAmount	= parseFloat(document.getElementById('maxAmount').value);
	mail			= document.getElementById('email').value;

	if (amount>maxAmount && validateEmail(mail)) {
	new Ajax.Updater('box_bids_content', 
  									'/site/kringloop/kringloop_bidSend.php', 
                    { 
                    	method: 'post',
					            parameters: {
                      	email: document.getElementById('email').value,
					              amount: amount,
          					    productid: document.getElementById('productid').value,
												maxAmount: maxAmount
                    	}
										}
                   );
	} else {
		document.getElementById('errorMssg').innerHTML	= "Uw bod moet hoger zijn dan het vorige bod: &euro; "+ maxAmount +".<br /> Controlleer ook uw mailadres.";
	}
}

function openInfo(id,mess,lang){
	if(this.infobusy==1){}
	else{
		this.infobusy=1;
		var div = document.getElementById("infomessage");
		var bod = document.getElementsByTagName("body")[0];
		if(div) bod.removeChild(div);
		getMess(mess,lang,id);
	}
}

function closeInfo(){
	var div = document.getElementById("infomessage");
	var bod = document.getElementsByTagName("body")[0];
	if(div) bod.removeChild(div);
}

function findPos(obj) {
	var pos = new Array();
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} 
		while (obj = obj.offsetParent);
		pos["x"] = curleft+18;
		pos["y"] = curtop-41;
		return pos;
	}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function getMess(mess,lang,id){ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/site/modules/getMess.php";
url=url+"?mess="+mess;
url=url+"&lang="+lang;
xmlHttp.onreadystatechange=function(){setInfo(xmlHttp,id)};
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


function setInfo(xmlHttp,id) 
{ 
if (xmlHttp.readyState==4)
{
var mess = xmlHttp.responseText;
var pos = findPos(document.getElementById(id));
var bod = document.getElementsByTagName("body")[0];
div = document.createElement("div");
div.style.top = pos["y"]+"px";
div.style.left = pos["x"]+"px";
div.innerHTML = mess;
div.id = "infomessage";
bod.appendChild(div);
this.infobusy = 0;
}
}