 var http_request = false;
   
   function makePOSTRequest(url, parameters) 
   {
      	http_request = false;
   		if (window.XMLHttpRequest) 
		{ // Mozilla, Safari,...
			 http_request = new XMLHttpRequest();
			 if (http_request.overrideMimeType) {
				// set type accordingly to anticipated content type
				//http_request.overrideMimeType('text/xml');
				http_request.overrideMimeType('text/html');
				
			 }
		} else if (window.ActiveXObject) { // IE
			 try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			 } catch (e) {
				try {
				   http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			 }
		  }
		  if (!http_request) {
			 alert('Cannot create XMLHTTP instance');
			 return false;
		  }
		  
		  var parameters = parameters.split("|");
		 
		  http_request.onreadystatechange = function()
		  {
			 if (http_request.readyState == 4) 
			  {
				 if (http_request.status == 200) 
				 {
					data = http_request.responseText.split ( "[BRK]" );
					parent.document.getElementById(parameters[1]).innerHTML=data[0];
					if((parameters[1]=='account_menu'))
					{
						window.location = "login.php";
					}
					if((parameters[2]=='overzicht_items'))
					{
						initSelectAdres();
					}
					if(parameters[2])
					{
						parent.document.getElementById(parameters[2]).innerHTML=data[1];
					}
					if(parameters[3])
					{
						parent.document.getElementById(parameters[3]).innerHTML=data[2];
					}
					if(parameters[4])
					{
						parent.document.getElementById(parameters[4]).innerHTML=data[3];
					}
					
					parent.$.fancybox.close();
					
					if((parameters[3]=='bestellen'))
					{
						initAddPB();
						
					}
					init();
					initAddPB();
					initSelectAdres();
				 } 
				 else 
				 {
					//alert('Bestelling is aangepast.');
				 }
			  }
		  }
		  http_request.open('POST', url, true);
		  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		  http_request.setRequestHeader("Content-length", parameters[0].length);
		  http_request.setRequestHeader("Connection", "close");
		  http_request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
		  http_request.send(parameters[0]);
   }

   
//#############################################

/*********************************************************************
 * Get an object, this function is cross browser
 * *** Please do not remove this header. ***
 * This code is working on my IE7, IE6, FireFox, Opera and Safari
 * 
 * Usage: 
 * var object = get_object(element_id);
 *
 * @Author Hamid Alipour Codehead @ webmaster-forums.code-head.com		
**/

function get_object(id) {
	var object = null;
	if( document.layers )	{			
		object = document.layers[id];
	} else if( document.all ) {
		object = document.all[id];
	} else if( document.getElementById ) {
		object = document.getElementById(id);
	}
	return object;
}
/*********************************************************************/

/*********************************************************************
 * No onMouseOut event if the mouse pointer hovers a child element 
 * *** Please do not remove this header. ***
 * This code is working on my IE7, IE6, FireFox, Opera and Safari
 * 
 * Usage: 
 * <div onMouseOut="fixOnMouseOut(this, event, 'JavaScript Code');"> 
 *		So many childs 
 *	</div>
 *
 * @Author Hamid Alipour Codehead @ webmaster-forums.code-head.com		
**/
function is_child_of(parent, child) {
	if( child != null ) {			
		while( child.parentNode ) {
			if( (child = child.parentNode) == parent ) {
				return true;
			}
		}
	}
	return false;
}
function fixOnMouseOut(element, event, JavaScript_code) {
	var current_mouse_target = null;
	if( event.toElement ) {				
		current_mouse_target 			 = event.toElement;
	} else if( event.relatedTarget ) {				
		current_mouse_target 			 = event.relatedTarget;
	}
	if( !is_child_of(element, current_mouse_target) && element != current_mouse_target ) {
		eval(JavaScript_code);
	}
}
/*********************************************************************/

function limitText(limitField, limitCount, limitNum) {
			if (limitField.value.length > limitNum) {
				limitField.value = limitField.value.substring(0, limitNum);
			} else {
				limitCount.value = limitNum - limitField.value.length;
			}
		}

//#############################################

function removeBoxConfirm(id)
{
$('#box_'+id).fastConfirm({
	position: "right",
	questionText: "Verwijderen?",
	proceedText: "Ja",
	cancelText: "Nee",
	onProceed: function(trigger) {
		removeBox(id)
		$(trigger).fastConfirm('close');
	},
	onCancel: function(trigger) {
		$(trigger).fastConfirm('close');
	}
});
}

//#############################################

function o_removeBoxConfirm(id)
{
$('#o_box_'+id).fastConfirm({
	position: "right",
	questionText: "Verwijderen?",
	proceedText: "Ja",
	cancelText: "Nee",
	onProceed: function(trigger) {
		o_removeBox(id)
		$(trigger).fastConfirm('close');
	},
	onCancel: function(trigger) {
		$(trigger).fastConfirm('close');
	}
});
}

//#############################################

function removeAdresConfirm(adres_id)
{

$('#adres_'+adres_id).fastConfirm({
	position: "right",
	questionText: "Verwijderen?",
	proceedText: "Ja",
	cancelText: "Nee",
	onProceed: function(trigger) {
		removeAdres(adres_id)
		$(trigger).fastConfirm('close');
	},
	onCancel: function(trigger) {
		$(trigger).fastConfirm('close');
	}
});
}

//#############################################

function initTool() 
{
	for (i=0;i<=15;i++)
	{
	$('#bonbon_'+i).tooltip({
		track: false,
		delay: 300,
		showURL: false,
		fade: true,
		showBody: " - ",
		extraClass: "",
		fixPNG: false,
		left: -78,
		top: -130	
	});
	}
}
//#############################################

function initAddPB() 
{
	$("#addPB").fancybox({
	'width'				: 400,
	'height'			: 350,
	'autoScale'			: true,
	'transitionIn'		: 'fade',
	'transitionOut'		: 'fade',
	'type'				: 'iframe',
	'onClosed': function() { 
   initAddPB();
  } 
});
}

//#############################################

function initSelectAdres()
{
	$(document).ready(function() 
	{
		for (i=0;i<=15;i++)
		{
			$("#selectAdres_"+i).fancybox({
			'width'				: 600,
			'height'			: 800,
			'autoScale'			: true,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'type'				: 'iframe',
			'onClosed': function() 
						{ 
							initSelectAdres();
						} 
			});
		}
		}
	);
}

//#############################################

function submitPB(shop_box_id)
{
	message = document.getElementById('message').value;
	var poststr = "f=submitPB&message="+message+"&shop_box_id="+shop_box_id+"|"+"pb|overzicht_pre_order";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
	
}

//#############################################

function removePB(shop_box_id)
{
	var poststr = "f=removePB&shop_box_id="+shop_box_id+"|"+"pb|overzicht_pre_order";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
	
}

//#############################################

function getBox(shop_box_id)
{
	document.getElementById('shop_box_id').value = shop_box_id;
	var poststr = "f=getCurrentBox&shop_box_id="+shop_box_id+"|"+"allboxes|current-box|bestellen";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
}

//#############################################

function showRemoveBox(id)
{
	$('#removeBox_'+id).show('slow');
	$('#boxIMG_'+id).css("background-image", "url(../images/boxbg.jpg)");
	$('#boxIMG_'+id).animate({ opacity: 0.6 }, 300, function() {
    // Animation complete.
  });
}

//#############################################

function showItemTool(id)
{
	$('#tool_'+id).css("display", "block");
}

//#############################################

function hideItemTool(id)
{
	$('#tool_'+id).css("display", "none");
}

//#############################################

function hideItemTools()
{
	for (i=0;i<=15;i++)
	{
		$('#tool_'+i).css("display", "none");
	}
}

//#############################################


function showContent(id)
{
	$('#content_'+id).css("display", "block");
}

//#############################################

function hideContent(id)
{
	$('#content_'+id).css("display", "none");
}

//#############################################

function showContent2(id)
{
	$('#content2_'+id).css("display", "block");
}

//#############################################

function hideContent2(id)
{
	$('#content2_'+id).css("display", "none");
}

//#############################################

function hideRemoveBox(id)
{
	$('#removeBox_'+id).hide('slow');
	$('#boxIMG_'+id).css("background-image", "url(../images/boxwit.jpg)")
	$('#boxIMG_'+id).animate({ opacity: 1.0 }, 300, function() {
    // Animation complete.
  });
}

//#############################################

function showRemoveBonbon(id)
{
	$('#removeBonbon_'+id).show('slow');
}

//#############################################


function hideRemoveBonbon(id)
{
	$('#removeBonbon_'+id).hide('slow');
}

//#############################################

function removeBox(ID)
{
	var poststr = "f=removeBox&ID="+ID+"|"+"allboxes|current-box|bestellen|overzicht_pre_order";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
}

//#############################################

function removeFromBox(ID)
{
	var shop_box_id = document.getElementById('shop_box_id').value;
	var poststr = "f=removeFromBox&ID="+ID+"&shop_box_id="+shop_box_id+"|"+"current-box";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
}

//#############################################


function getBoxes()
{
	var poststr = "f=getBoxes&shop_box_id="+shop_box_id+"|"+"current-box";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
}


//#############################################

function addToBox(ID)
{
	//alert(ID);
	var shop_box_id = document.getElementById('shop_box_id').value;
	var poststr = "f=addToBox&ID="+ID+"&shop_box_id="+shop_box_id+"|"+"current-box";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
}

//#############################################

/*function addBox(ID)
{
	document.getElementById('divName').value = 'allboxes';
	var poststr = "f=addBox&ID="+ID;
	makePOSTRequest('../inc/ajax.functions.php', poststr);
}
*/
//#############################################

function enlargeBox()
{
	var shop_box_id = document.getElementById('shop_box_id').value;
	var poststr = "f=enlargeBox&shop_box_id="+shop_box_id+"|"+"allboxes|current-box|overzicht_pre_order";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
}

//#############################################

function decreaseBox()
{
	var shop_box_id = document.getElementById('shop_box_id').value;
	var poststr = "f=decreaseBox&shop_box_id="+shop_box_id+"|"+"allboxes|current-box|overzicht_pre_order";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
}

//#############################################

function addBox(ID,custom)
{
	parent.document.getElementById('shop_box_id').value = '';
	var poststr = "f=addBox&ID="+ID+"&custom="+custom+"|"+"allboxes|current-box|bestellen|overzicht_pre_order";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
}

//#############################################

function closeBox()
{
	//alert("close");
	//parent.$.fancybox.close();
}

//############################################# OVERZICHT FUNCTIONS

function o_removePB(shop_box_id)
{
	var poststr = "f=o_removePB&shop_box_id="+shop_box_id+"|overzicht_items|total_price";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
	
}

//#############################################

function o_removeBox(ID)
{
	var poststr = "f=o_removeBox&ID="+ID+"|overzicht_items|total_price";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
}

//#############################################

function selectFactuurAdresItem(shop_box_id)
{
	var poststr = "f=selectFactuurAdresItem&shop_box_id="+shop_box_id+"|total_price|overzicht_items";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
}

//#############################################

function selectAnderAdresItem(shop_box_id)
{
	var poststr = "f=selectAnderAdresItem&shop_box_id="+shop_box_id+"|overzicht_items|total_price";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
}

//#############################################

function addAdres(adres_id,shop_box_id)
{
	//alert(adres_id);
	var poststr = "f=addAdres&adres_id="+adres_id+"&shop_box_id="+shop_box_id+"|overzicht_items|total_price";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
}

//#############################################

function addAdresTotaal(adres_id)
{
	var poststr = "f=addAdresTotaal&adres_id="+adres_id+"|bezorg_totaal|total_price";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
}

//#############################################

function selectBezorgAdresTotaal()
{
	var poststr = "f=selectBezorgAdresTotaal|bezorg_totaal|total_price";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
}

//#############################################

function selectOphalen()
{
	var poststr = "f=selectOphalen|bezorg_totaal|total_price";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
}

//#############################################

function addAdres2()
{
	var poststr = "f=addAdres2|sa";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
}

//#############################################

function setPaymentMethodOverboeken()
{
	var poststr = "f=setPaymentMethodOverboeken|paymentMethod|total_price";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
}

//#############################################

function setPaymentMethodIDEAL()
{
	var poststr = "f=setPaymentMethodIDEAL|paymentMethod|total_price";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
}

//#############################################


function endSession()
{
	var poststr = "f=endSession|account_menu";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
}

//#############################################

function removeAdres(adres_id)
{
	var poststr = "f=removeAdres&adres_id="+adres_id+"|adressen";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
}


//#############################################

function editAdres(adres_id)
{
	var poststr = "f=editAdres&adres_id="+adres_id+"|editAdres";
	makePOSTRequest('../inc/ajax.functions.php', poststr);
}

//#############################################

function submitAdresForm(adres_id)
{
	name = $('#editAdresForm').elements["voornaam"].value;
	alert(name);
}

//#############################################

function showBetalen()
{
	if(document.getElementById('selectBetalen').checked == true)
	{
		$('#betalen').css("display", "block");
	}
	else
	{
		$('#betalen').css("display", "none");
	}
}

//#############################################

function naarKassa()
{
	var opmerking = document.getElementById('opmerking').value;
	alert(opmerking);
	var poststr = "f=checkOut&opmerking="+opmerking;
	makePOSTRequest('../inc/ajax.functions.php', poststr);
}
