function addtocart(e){
	$(document).ready(function(){
		
		//Init the Quicktips
	
		//Get the result element
		//var el = Ext.get('result');
		
		//el.select('input').hide();
		//Als we geen el hebben stop dan...
		//if(!el){
		//	return false;	
		//}
		//el.select('input').on('click', function(e) {
	   		//alert("lalalalalal");
	   		//console.log(this.id);
	   		var normal_img = e.src;
	   		var load_img = '/img/add_to_cart_ajaxloader.gif';
	   		e.src = load_img;	//Verander plaatsje
	   		var products_id = e.id;
	   		//Ext.get(products_id).highlight();
	   		var aantal = $("#aantal").val();
	   		
	   		if(!aantal){
	   			var aantal = 1;	
	   		}
	   		if(products_id){
	   			//We halen de askcheckout niet meer uit /orders/askcheckout, maar meteen uit addtocart..
	   			//Dit om een extra ajax post te voorkomen
	   			/*
	   			//Check if we must show the checkout windows
	   			var conn = new Ext.data.Connection();
								conn.request({
								url: '/orders/askcheckout',
								method: 'POST',
								params: {"check": "true", "type" : 'read'},
								success: function(responseObject) {
									        //showHistoryDialog(responseObject.responseText);
									        //console.log(responseObject.responseText);
									        var data = Ext.util.JSON.decode(responseObject.responseText);
											var dontaskagain = data.dontaskagain;
											AddToCart(dontaskagain);
								},
								failure: function() {
									         Ext.Msg.alert('Status', 'Unable error #45464. Please try again later.');
								}
							});
					*/
	   			$.ajax({ 
		                url: '/products/addtocart', 
		                type: 'POST', 
		                data: "product_id="+products_id+"&quantity="+aantal,
		                dataType: 'json',
		                beforeSend: function() {  }, 
		                success: function(result) { 
		                	e.src = normal_img;	//Zet plaatje terug
		                    //alert(result.result); 
		                    //$("#saveStatus").html(result.Result).show(); 
		                    //Show the info box
		                    var totall_items = result.totall_items;
		                    //$("#w_aantal").text(totall_items);
		                    // Show a dialog using config options:
		                    //alert(dontaskagain);
		                    //console.log(result.dontaskagain);
							if(result.dontaskagain == 'false'){
							//Set the buttons
							Ext.Msg.buttonText.yes = "Nu afrekenen"
							Ext.Msg.buttonText.no = "Verder winkelen"
		                    Ext.Msg.show({
							   title:'Afrekenen',
							   //msg: 'Wilt u meteen afrekenen? <Br><br> ', //<label><input type="checkbox" id="dontaskagain" name="dontaskagain" value="false" onclick="togglecheckbox(this);"> Vraag niet opnieuw</label>
							   msg: 'Het product is toegevoegd aan uw winkelmandje. ', //<label><input type="checkbox" id="dontaskagain" name="dontaskagain" value="false" onclick="togglecheckbox(this);"> Vraag niet opnieuw</label>
							   buttons: Ext.Msg.YESNO,
							   fn: function(btn){    
							   	var askagain = $("#dontaskagain").val();
							   		
							   	if(askagain == 'true' && btn != 'yes'){
							   		//Do the session post
								   	var conn = new Ext.data.Connection();
									conn.request({
									    url: '/orders/askcheckout',
									    method: 'POST',
									    params: {"dontaskagain": 'true', "type" : 'set'},
									    success: function(responseObject) {
									        //showHistoryDialog(responseObject.responseText);
									    },
									     failure: function() {
									         Ext.Msg.alert('Status', 'Unable error #45464. Please try again later.');
									     }
									});
							   	}
							   	if (btn == 'no' || btn == 'cancel'){               
							   		//Show the info box
									ShowTHeinfoBox(result,aantal);
							   	}else if(btn == 'yes'){
							   		window.location = '/orders/show';
							   	}   
							   },
							   animEl: 'elId',
							   icon: Ext.MessageBox.QUESTION
							});
		                }else{
		                	ShowTHeinfoBox(result,aantal);	
		                }	
		                }
		            });
			
	   		}else{
	   			alert("Fout we kunnen het product niet toevoegen, neem aub contact met ons op. Fout id: 53232");	
	   		}
	   		 //Return false zodat we geen page refresh hebben
			return false;
		//});
			Ext.QuickTips.init();
	
	});
}
/*
function addtocart(e){
	alert("boehoeoe");	
	
	 var products_id = e.id;
   	//Ext.get(products_id).highlight();
   	var aantal = $("#aantal").val();
   	
   	alert(aantal);
}
*/
//Extjs function info
function info(msg, title) {
		new Ext.ux.window.MessageWindow({
			 title:title 
			,html:msg || 'No information available' 
			,origin:{offY:-5,offX:-25}
			,autoHeight:true
			,iconCls:'icon-info'
			,help:false
			,hideFx:{delay:3500, duration: 0.50}
			,showFx: { delay: 0, duration: 0.5 }
			,minHeight: 100
			,minWidth: 250
			,listeners:{
				render:function(){
					//Ext.ux.Sound.play('/js/cart/generic.wav');
				}
			}
		}).show(Ext.getDoc());
}

function ShowTHeinfoBox(result, aantal){
	info('<img width="35" height="35" src="'+ result.thumb_pic +'">'+ aantal +'x '+ result.product_name +'', "Product toegevoegd");
								
						   		//We krijgen json result terug update de winkelwagen gegevens
			                	//Fadeout aantal
								$("#w_aantal").fadeOut(5, function() {
									
									//Set the color to red
									$("#w_aantal").css({'color' : 'green'});
									
									//Fade in the new aantal
									$("#w_aantal").fadeIn(200, function() {
										$("#w_aantal").css({'color' : 'black'});
									}).text(result.totall_items);	//Set the new totall items aantal
									
								});	
								
								
								//Fadeout price
								$("#w_price").fadeOut(5, function() {
									
									//Set the color to red
									$("#w_price").css({'color' : 'green'});
									
									//Fade in the new aantal
									$("#w_price").fadeIn(200, function() {
										$("#w_price").css({'color' : 'black'});
									}).text(result.totall_price);	//Set the new totall items aantal
									
								});	
}