function clearBasketItems(){
	jQuery('.checkProd:checked').each(function(){
		jQuery(this).parent().parent().find('.quantity').val(0);
	});
}
function numbersonly(e){
	var unicode = e.keyCode;
	if ((unicode!=13)&&(unicode!=8)&&(unicode!=9)&&(unicode!=46)&&(unicode!=35)&&(unicode!=36)&&(unicode!=37)&&(unicode!=38)&&(unicode!=39)&&(unicode!=40)&&(unicode!=43)){ 
		if (unicode<48||unicode>57){
		return false;
		}
	}
	return true;
}
function addCommas(nStr){
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? ',' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + '.' + '$2');
	}
	return x1 + x2;
}
function replaceCommas(nStr){
	nStr += '';
	//nStr = nStr.replace(',','|');
	nStr = nStr.replace('.','');
	nStr = nStr.replace(',','.');
	return nStr;
}
function CheckPriceWithAjax(elem,uid,amount){
	$.ajax({
	   type: "POST",
	   url: "fileadmin/ajax/functions.php",
	   data: "func=checkPrice&uid="+uid+"&amount="+amount,
	   success: function(msg){
		   if(msg>0){
			elem.text(addCommas(msg));
			total = 0;
			jQuery('.quantity').each(function(){
				total = parseFloat(total) + parseFloat(replaceCommas(jQuery(this).parent().parent().find('.cart-price').text()));
			});
			jQuery('#cart-total-price').text(addCommas(total.toFixed(2)));
			//jQuery('#cart-goods-total').text(addCommas(total.toFixed(2)));
			//jQuery('.buy-link input').removeAttr('disabled');
		   } else {
			   if(amount!=''){
				alert('De minimum afname van dit product bedraagt '+(parseInt(msg)*-1)+'!');
				//jQuery('.buy-link input').attr('disabled','disabled');
			   }
		   }
	   }
	 });
}
function AddMinAmount(elem,uid){
	$.ajax({
	   type: "POST",
	   url: "fileadmin/ajax/functions.php",
	   data: "func=minAmount&uid="+uid,
	   success: function(msg){
			elem.attr('title',msg);
		}
	 });
}
function CheckInputValue(){
	var submit = true;
	jQuery('.quantity').each(function(){
		if(parseInt(jQuery(this).val())<parseInt(jQuery(this).attr('title'))){
			submit = false;
		}
	});
	return submit;
}
jQuery(function() {
	
	//Hints
	jQuery('#account input').hint();
	
	//Numeric
	jQuery('#options .quantity, #grid .quantity').numeric();
	
	//Grid
	jQuery('#grid tbody tr:odd').addClass('odd');
	
	//List
	jQuery('#list .item:nth-child(3n+3)').after('<hr class="clear" />');
	
	/*
	//Cart Auto-Update Single
	//Init variables
	var $quantity = $('#single-quantity');
	var $totalPrice = $('#single-total-price');
	
	//Getting the Amount / Price ratios
	var $pricesTable = $('#prices');
	var _quantities = [];
	var _prices = [];
	var $row1 = $('tbody tr:first td',$pricesTable);
	var $row2 = $('tbody tr:last-child td',$pricesTable);
	
	$row1.each(function(index){
		_quantities[index] = parseInt($(this).text());
		var price = $row2.eq(index).text();
		price = parseFloat(price.substr(2).replace(',','.'));
		_prices[index] = price;
	});
	
	//Attaching the event
	$quantity.bind('change keyup blur', function(){
		quantity =  $quantity.val();
		for (index=0;index<_quantities.length;index++){
			if (quantity >= _quantities[index]){
				singlePrice = _prices[index];
			}
		}
		totalPrice = singlePrice * $quantity.val();
		$totalPrice.text(totalPrice.toFixed(2)); 
	});
		
	//Cart Auto-Update Basket
	$grid = ('#grid');
	$cartTotalPrice = $('#cart-total-price');
	$gridQuantities = $('.quantity', $grid);
	_gridQuantities = [];
	_gridPrices = [];
	$gridQuantities.each(function(index){
		_gridQuantities[index] = parseInt(this.value);
		var localPrice = $(this).parent().prev().find('.cart-price').text();
		_gridPrices[index] = parseFloat(localPrice);
		$(this).bind('change keyup blur', function(){
			_gridQuantities[index] = parseInt(this.value);
			var totalPrice = 0;
			for (var i=0;i<_gridQuantities.length;i++){
				totalPrice += _gridQuantities[i] * _gridPrices[i];
			}
			$cartTotalPrice.text(totalPrice);
		});
	});
	*/
});

jQuery(document).ready(function(){
	/*Single products*/
	jQuery(function() {
		jQuery('.image a:has(img)').lightBox();
	});
	
});

function favouritesnull(){
	var str = document.getElementById("allProdsId").value;
	var myarr = str.split(",");
	var err=0;
	var check = false;
	for (i=0;i<myarr.length;i++) {
		if (myarr[i]!="") {
			if (document.getElementById("quantity"+myarr[i]).value=="") {
				err=err+0;
			} else {
				err=err+1;
			}
			if (document.getElementById("prod_"+myarr[i]).checked===true) {
				check = true;
			}
			
		}
	}
	if (err>0) {
		document.getElementById("formProds").submit();
	}else if (check==true){
		document.getElementById("formProds").action = '';
		document.getElementById("formProds").submit();
	}else {
		document.getElementById('favourites_update_status').innerHTML = '<b>Please enter a value for a product to add to request</b>';
		return false;
	}
}

