var loading = "<img src='"+rooturl+"/css/images/loading.gif' align='left' class='mr20 mb20' /><br />";
var progress = "<img src='"+rooturl+"/css/images/progress.gif' align='left' class='mr20 mb20' /><br />";
var pasop = "<img src='"+rooturl+"/css/images/alert.png' align='left' class='mr20 mb20' /> ";
var gereed = "<img src='"+rooturl+"/css/images/gereed.png' align='left' class='mr20 mb20' /><br />";
var foutje = "<img src='"+rooturl+"/css/images/fout.png' align='left' class='mr20 mb20' /><br />";
var scrollspeed = 400;
$(document).ready(function(){
	if(log == 0) {
		$.post(rooturl+"/webshop/php/order/orderqty.php",function(data){
			$("#cartcount").html(data);
		});
	}
	
	$("#searchbox").live("click",function(e){
		e.preventDefault();
		var term = $("#searchinput").val();
		$("#el231").fadeOut("Fast",function(){
			$.post(rooturl+"/searchengine/getFiltered.php",{filter:term},function(data){
				$("#el231").html(data);
				$("#el231").fadeIn();
			});
		});
		
	});
	
	$(".klantlogoff").live("click",function(e){
		e.preventDefault();
		$.post(rooturl+"/php/login/logoff.php",{gn:gnx, kn:knx},function(data){
			if(data) {
				window.location = rooturl+"/3572/mijncupoftwo.html";
			}
		});
	});
	
	$(".language").live("click",function(e){
		e.preventDefault();
		var langid = $(this).attr("langid");
		$.post(rooturl+"/php/setsessionlanguage.php", {sessionname:"langid",sessioncontent: langid}, function(data){
			location.reload(); return false;
		});
	});
	$(".sluitgrowl").live("click",function(e){
		e.preventDefault();
		$('.growl').fadeOut();
	});
	
	$(".setmeonblur").live("blur",function(){
		var naamx = $(this).attr("name");
		var valuex = $(this).val();
		$.post(rooturl+"/php/setses.php", {sessionname: naamx, sessioncontent: valuex});
	});
	$(".setmeonchange").live("change",function(){
		var naamx = $(this).attr("name");
		var valuex = $(this).val();
		$.post(rooturl+"/php/setses.php", {sessionname: naamx, sessioncontent: valuex});
	});
	$(".setmeoncheck").live("click",function(){
		var naamx = $(this).attr("name");
		if($(this).is(':checked')) {
			var valuex = 1;
		}
		else {
			var valuex = 0;
		}
		$.post(rooturl+"/php/setses.php", {sessionname: naamx, sessioncontent: valuex});
	});
	
	$(".setmeonradio").live("click",function(){
		var naamx = $(this).attr("name");
		var valuex = $(this).val();
		$.post(rooturl+"/php/setses.php", {sessionname: naamx, sessioncontent: valuex});
	});
	
	
	$(".scrubber").scrub();
	$(".scrubber").live("mouseout",function(){
		// move all other children to back
		$(".scrubdiv").css('z-index', 0);					
		// move selected child to front
		$(".scrubber").find('.master').css('z-index', 1);

	});
	
	
	$( "button" ).button();
	$( ".jbutton" ).button();
	$( "#addtoorder" ).button({ disabled: true });
	$( "#inorder" ).button({ disabled: true });
	
	$(".productfoto").live("click",function(e){
		e.preventDefault();
		$("#sizeselect").attr("disabled",true);
		$("#inorder").css("display","none");
		$("#inordernumber").html("");
		var productid = $(this).attr("productid");
		var moederidx = $(this).attr("moederid");
		$("#el242").load(rooturl+"/webshop/plugin/producten/loadproductfoto.php",{pid:productid,moederid:moederidx},function(){
			$('.cloud-zoom, .cloud-zoom-gallery').CloudZoom();
		});
		$(".p_omschrijving").load(rooturl+"/webshop/plugin/producten/loadproductomschrijving.php",{pid:productid});
		$("#sizeselect").load(rooturl+"/webshop/php/order/getsizes.php",{pid:productid},function(){
			$("#sizeselect").attr("disabled",false);
			$("#qtyselect option:first").attr('selected','selected');
			$("#qtyselect").attr("disabled",true);
			$( "#addtoorder" ).button({ disabled: true });
		});
		$("#selectedproductdata").load(rooturl+"/webshop/php/order/getdata.php",{pid:productid,moederid:moederidx},function(){
		});
	});
	
	
	$(".kleurproductfoto").live("click",function(e){
		e.preventDefault();
		$("#sizeselect").attr("disabled",true);
		$("#inorder").css("display","none");
		$("#inordernumber").html("");
		var productid = $(this).attr("productid");
		var moederidx = $(this).attr("moederid");
		$("#el242").load(rooturl+"/webshop/plugin/producten/loadproductfoto.php",{pid:productid,moederid:moederidx},function(){
			$('.cloud-zoom, .cloud-zoom-gallery').CloudZoom();
		});
		
		$("#sizeselect").load(rooturl+"/webshop/php/order/getsizes.php",{pid:productid},function(){
			$("#sizeselect").attr("disabled",false);
			$("#qtyselect option:first").attr('selected','selected');
			$("#qtyselect").attr("disabled",true);
			$( "#addtoorder" ).button({ disabled: true });
		});
		
		$(".productdatadiv").load(rooturl+"/webshop/plugin/producten/getdatapage.php",{pid:productid},function(){
			$('.cloud-zoom, .cloud-zoom-gallery').CloudZoom();
		});
		
	});
	
	$("#sizeselect").live("change",function(){
		var sizedatax = $(this).val();
		$("#qtyselect").load(rooturl+"/webshop/php/order/getstock.php",{sizedata:sizedatax},function(data){
			$("#qtyselect").attr("disabled",false);
			$.post(rooturl+"/webshop/php/order/inorder.php",{sizedata:sizedatax},function(inorder){
				if(inorder>0) {
					$("#inorder").css("display","block");
					$("#inordernumber").html(inorder);
					$( "#inorder" ).button({ disabled: false });
				}
			});
		});
	});
	
	$("#qtyselect").live("change",function(){
		var besteld = $(this).val();
		var actieaantal = $("#actieaantal").val();
		var productid = $("#masterproductid").val();
		var moederidx = $("#mastermoederid").val();
		if(besteld >= actieaantal) {
			$("#selectedproductdata").load(rooturl+"/webshop/php/order/getdata.php",{pid:productid,moederid:moederidx},function(){
			});
		}
		$( "#addtoorder" ).button({ disabled: false });
	});
	
	$("#addtoorder").live("click",function(){
		var sizedatax = $("#sizeselect").val();
		var stockdatax = $("#qtyselect").val();
		var pricedatax = $("#sellingprice").val();
		var oripricedatax = $("#oriprice").val();
		var orderdatax = sizedatax+"-"+stockdatax+"-"+pricedatax+"-"+oripricedatax;
		//alert(sizedatax);
		$("#inorder").css("display","block");
		$( "#inorder" ).button({ disabled: false });
		$.post(rooturl+"/webshop/php/order/addtoorder.php",{orderdata:orderdatax},function(data){
			$("#cartcount").html(data);
			$.post(rooturl+"/webshop/php/order/inorder.php",{sizedata:sizedatax},function(inorder){
				if(inorder>0) {
					$("#inorder").css("display","block");
					$("#inordernumber").html(inorder);
					$( "#inorder" ).button({ disabled: false });
				}
			});
		});
	});
	
	$(".orderqtyselect").live("change",function(){
		var sizedatax = $(this).attr("ordersize");
		var stockdatax = $(this).val();
		var pricedatax = $(this).attr("ordersellingprice");
		var oripricedatax = $(this).attr("oriprice");
		var orderdatax = sizedatax+"-"+stockdatax+"-"+pricedatax+"-"+oripricedatax;
		$.post(rooturl+"/webshop/php/order/addtoorder.php",{orderdata:orderdatax},function(data){
			$("#cartcount").html(data);
			$("#el229").load(rooturl+"/webshop/php/order/ordersheet.php",function(){
			});
		});
	});
	
	$(".couponcodecheck").live("click",function(e){
		e.preventDefault();
		$("#el229").load(rooturl+"/webshop/php/order/ordersheet.php",function(data){
			
		});
	});
	
	$(".clearcouponcode").live("click",function(e){
		e.preventDefault();
		$.post(rooturl+"/php/clearses.php", {sessionname: "couponcode"},function(){
			$("#el229").load(rooturl+"/webshop/php/order/ordersheet.php",function(data){});
		});
	});
	
	$(".delfromorder").live("click",function(e){
		e.preventDefault();
		var productid = $(this).attr("productid");
		var sizex = $(this).attr("size");
		var cupx = $(this).attr("cup");
		$.post(rooturl+"/webshop/php/order/delfromorder.php",{id:productid,size:sizex,cup:cupx},function(data){
			if(data==0) {
				$('#el229').slideToggle('fast', function() {
					$("#inorder").fadeOut();
				});
			}
			$.post(rooturl+"/webshop/php/order/orderqty.php",function(data){
				$("#cartcount").html(data);
			});
			$("#el229").load(rooturl+"/webshop/php/order/ordersheet.php",function(){});
		});
	});
	
	$(".cart").live("click",function(e){
		e.stopPropagation();
		e.preventDefault();
		var productid = $(this).attr("productid");
		$('#el243').hide();
		$('#el248').hide();
		$("#el229").html("<div style='margin:20px;'>even geduld a.u.b.</div>");
		$('#el229').slideToggle('fast', function() {
			if($('#el229').is(":visible")) {
				
				$("#el229").load(rooturl+"/webshop/php/order/ordersheet.php",{id:productid},function(){
					$("body").css("overflow","hidden");
				});
			}
			else {
				$("#el229").html("");
				
				$("body").css("overflow","visible");
			}
		});
	});
	
	$(".emaillink").live("click",function(e){
		e.stopPropagation();
		e.preventDefault();
		$('#el229').hide();
		$('#el248').hide();
		$('#el243').hide();
		$("#el243").load(rooturl+"/php/newsletter/regform.php",function(){
			$('#el243').slideToggle('fast', function() {});
		});
	});
	$(".inloglink").live("click",function(e){
		e.stopPropagation();
		e.preventDefault();
		$('#el229').hide();
		$('#el248').hide();
		$('#el243').hide();
		$("#el243").load(rooturl+"/php/login/loginform.php",function(){
			$('#el243').slideToggle('fast', function() {
			});
		});
	});
	
	$(".popconditions").live("click",function(e){
		e.stopPropagation();
		e.preventDefault();
		$('#el229').hide();
		$('#el243').hide();
		$('#el248').slideToggle('fast', function() {
			$("#el248").load(rooturl+"/webshop/plugin/conditions-load.php",function(){
			});
		});
	});
	
	$(".wwvergeten").live("click",function(e){
		e.stopPropagation();
		e.preventDefault();
		$('#el229').hide();
		$('#el248').hide();
		$('#el243').hide();
		$("#el243").load(rooturl+"/php/login/knvform.php",function(){
			$('#el243').slideToggle('fast', function() {
			});
		});
	});
	
	$(".getkn").live("click",function(){
		if(validateform("#knvf","text","Verplicht veld","E-mailadres klopt niet.","")) {
			var emailx = $("#wwvemailveld").val();
			alert(emailx);
			$.post(rooturl+"/php/wachtwoordvergeten.php",{email:emailx},function(gegevens){
				if(gegevens==0) {
					$(".growl").fadeIn("normal");
					$(".grtxt").html(pasop + "Het e-mailadres is onbekend.");
				}
				else {
					$(".growl").fadeIn("normal");
					$(".grtxt").html("Je wachtwoord is verstuurd.");
				}
			});
		}
	});
	
	
	$(".reload").live("click",function(e){
		$("#el229").load(rooturl+"/webshop/php/order/ordersheet.php");
	});
	
	$(".closepop").live("click",function(){
		$("body").css("overflow","visible");
		$(this).parent().slideToggle('fast',function(){$('#el229').html("");});
	});
	$(".conditionsclosepop, .akkoordmetconditions").live("click",function(){
		$(this).parent().slideToggle('fast');
		$('#el229').slideToggle('fast', function() {
			$("#el229").load(rooturl+"/webshop/php/order/ordersheet.php",function(){
		   });
		});
	});
	
	$(".filterknop").live("change",function(e){
		$(".filtercupsize").val("All");
		var soort = $(this).val();
		$("#el231").fadeOut("Fast",function(){
			$("#el231").load(rooturl+"/webshop/plugin/producten/filterlijst.php?soort="+soort,function(){
				$("#el231").fadeIn();
			});
			
		});
	});
	
	
	$(".filtercupsize").live("change",function(e){
		var size = $("#filtersize").val();
		var cup = $("#filtercup").val();
		$("#el231").fadeOut("Fast",function(){
			$("#el231").load(rooturl+"/webshop/plugin/producten/filtercupsizelijst.php?size="+size+"&cup="+cup,function(){
				$("#el231").fadeIn();
			});
		});
	});
	$("#filtersize").live("change",function(e){
		var size = $(this).val();
		$("#filtercup").load(rooturl+"/webshop/plugin/producten/getfiltercuplijst.php?size="+size);
	});
//	$("#filtercup").live("change",function(e){
//		var cup = $(this).val();
//		$("#filtersize").load(rooturl+"/webshop/plugin/producten/getfiltersizelijst.php?cup="+cup);
//	});
});

function submitenter(myfield,e)
{
	var keycode;
	if (window.event) 
		keycode = window.event.keyCode;
	else if (e) 
		keycode = e.which;
	else 
		return true;
	
	if (keycode == 13)
	{
		var namex = $("#username").val();
		var passwordx = $("#password").val();
		$.post(rooturl+"/php/login/checkuser.php",{name:namex,password:passwordx},function(data){
			if(data) {
				window.location = rooturl;
			}
		});
		return false;
	}
	else
		return true;
}
