$(function () {
	rootLoc = "http://www.restaurantivy.nl/";
	
	$('body #bun').prepend('<div id="geo-shop-holder" style="zoom:1;"><img id="geoShopLdImgIframe" src="'+rootLoc+'geo-shop/images/loader_icon.gif"/></div>').find("#geo-shop-holder")
	.append('<iframe src="'+rootLoc+'geo-shop/" id="geo-shop-frame" frameborder="0" ></iframe>').hide();

	
	$(".add_to_cart").click(function () {
		alert("Een moment geduld s.v.p.");
		var ids = $(this).parent().attr('id').replace('shop_','');
		var names = $(this).parent().find('b').text();
		var prices = Number($(this).parent().find('em span').text());
		$('#geo-bieden-holder').hide();
		$('#geo-shop-holder').hide();
		$('#messHolder').hide();
		$.post(rootLoc+'geo-shop/ajax/geo-shop-insert_prod.php', {id:ids, name:names, price:prices}, function () {
		
			$('html, body').animate({scrollTop: 0}, 1000, function(){ $("#geo-shop-holder").css({'zoom':'1'}); $("#geo-shop-holder").slideDown('slow')});	
			$("iframe#geo-shop-frame").ready(function () {
				$("img#geoShopLdImgIframe").hide();
				var srcFr = $("iframe#geo-shop-frame").attr("src");
				 $("iframe#geo-shop-frame").attr('src' , srcFr);
			});
			
		});
		
		return false;
	});

	//--------------Cart function delete product from list
	var emData = "";

	$('.geoShopDelete').click(function (){
		var id = $(this).attr('id').replace('del_','');
		$.post('ajax/remove-article.php', {id:id}, function (data){
			window.location.reload();
		});
		return false;
	});
	$('#geoShopAmount').focus(function(){
		alert("Klik op de button bedrag vernieuwen om het bedrag te vernieuwen");
	});

	
	$("#geo-shop-verz").click(function (){
		if ($(this).is(':checked')) {
			$('#geo-shop-other-adress').show();
		}else{
			$('#geo-shop-other-adress').hide();
		}
	});
	$('#geoShopclientLogin').submit(function () {
					$("#geoLoadingElem").show();
					$.post(rootLoc+"geo-shop/ajax/find-client.php",{email:$('#geoShopEmail').val(), t:$('#geoShopTok').val(), pass:$("#geoshoppass input").val()}, function (data) {
						var d = data.replace(/^\s*|\s*$/g,'');
						if (d == "oke") {
							$("#geoshoppass").show();
							$("#geoShopMessage").hide();
							$("#geoShopClientDetails").hide();
							$("#geoShopclientLogin").attr('action', '?steps=logindetails&m='+$('#geoShopEmail').val());
						}else{
							$('#geoShopclientLogin').append(d).show();
						}
						$("#geoLoadingElem").hide('slow');
					});
				});
	
	
	$("#geoShopSndWacht").click(function () {
		if ($("#geoShopEmail").val() == "") {
			alert($("#geoShopAlert").text());
		}else{
			$.post(rootLoc+"geo-shop/ajax/snd-client.php",{email:$('#geoShopEmail').val(), t:$('#geoShopTok').val()}, function (data) {alert("Uw nieuwe wachtwoord is verstuurd naar het door u opgegeven e-mail-adres.");});
		}
	});	
	
	
	function isArray(obj) {
		if (obj.constructor.toString().indexOf("Array") == -1)
			return false;
		else
			return true;
	}
	
	
	//-------------------Validate FORM
	
		$("#geoShopClientDetailsFrom").validateform
	({
		onComplete: function (){ $("#geoShopClientDetailsFrom").submit();},
		btn: '#geoShopClientDetailsFrom .btnShop',
		normMessage: 'Veld is verplicht',
		emailMessage: 'E-mail is niet correct',
		radioMessage: 'Kies een optie',
		passMessage:'Wachtwoord moet hetzelfde zijn',
		selectMessage: 'Kies een veld'
	});
	
	
	
	//-----------Make buttons small
	$(".btnShop, .geoShopBtnHolder a").each(function () {
		//alert($(this).text().length);
		if ($(this).is('input'))
			$(this).width(($(this).val().length) * 10);
		else
			$(this).width(($(this).text().length) * 10);
	});
	
	$('.pss').val('');
	
	//---Add items to form
	
	$("form span").prepend("<b>* </b>");
	
	//-----FINISH
	
	$("#geoShopSuccesShopping .btnShop, #geoShopSuccesShopping .geoShopCloseBtn").click(function () {
		window.parent.location.reload();
	})

});
