// JavaScript Document

function isUrl(s) {
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}

function updateField(field,value) {
	$(field).val(value);
}

$(document).ready(function(){
			$('h1').phpsifr({ttf: 'tcb_____',colors: "734143:eae7e7",size:34, opacity: true});
			$("h2").phpsifr({colors: "734143:eae7e7",size:16, opacity: true});
			$('#bannerContent span').phpsifr({colors: "734143:eae7e7",size:16, opacity: true});
			$('div#menu ul li').click( function (e) {
				document.location = $(e.target).find('a').attr('href');
			});

			if($('input[name=sameaddress]').attr('checked') == false) {
				$('div#bezorgadres').hide();
			}
			$('.options').hide();
			$('input[name=submit]').click( function (e) {
				e.stopPropagation();
				$('form').submit();
				//return false;
			});

			$('.item a.more').toggle(
					function(e) {
						e.stopPropagation();
						$this = $(e.target);
						$this.parent().next().show();
						$this.text('Verwijder keuze');
						return false;
					},
					function(e) {
						e.stopPropagation();
						$this = $(e.target);
						$this.parent().next().hide();
						$this.parent().next().find(':radio').removeAttr('checked');
						$this.text('Kies...');
						return false;
					}
				);
			$('div.item img').click(
				function(e) {
					$(e.target).parent().prev().children('input').attr('checked', true);
			});

			$('div.item td.thumb').click( function(e) {
				//this.is('img').parent().prevSibling().find('input').attr('checked',true);
				$(this).prev().children('input').attr('checked',true);
				var url = $(this).next().find('a').attr('href');
				if(url!=undefined)
				{
					tb_show('', url);
				}
			});

			$('.optionConfig input:checked').parent().parent().show();

			$('#overzicht .amountSelect').change(function(e) {
					$('form[name=overview]').submit();
			});

			$('#cart .order a.delete').click(function(e) {
				e.stopPropagation();
				var val = $(e.target).parent().next().val();
				$('input[name=deleteItem]').val(val);
				$('form[name=cart]').submit();

				return false;
			});

			$('#cart select.amountSelect').change(function(e) {
				$('input[name=mutateItem]').val($(e.target).next().next().next().val());
				$('form[name=cart]').submit();
			});

			//$('#cart table.configuration').hide();

			$('table.order tr.attr').hide();
			$('table.order tr.attr + tr').hide();

			$('a.showConfig').toggle(
				function(e) {
					e.stopPropagation();
					var oclass = $(e.target).attr('href');
					$(e.target).parent().parent().parent().find('tr.'+oclass).show().next().show();
					$(e.target).html('Verberg configuratie')
					return false;
				},
				function(e) {
					e.stopPropagation();
					var oclass = $(e.target).attr('href');
					$(e.target).parent().parent().parent().find('tr.'+oclass).hide().next().hide();
					$(e.target).html('Toon configuratie')
					return false;
				}
				);

			$('input[name=sameaddress]').click(

				function(e) {
					if($('input[name=sameaddress]').attr('checked') == true) {
						$('div#bezorgadres').show();
					} else {
						$('div#bezorgadres').hide();
					}
				});

			$('#step form').bind('keypress', function(e) {
				if(e.keyCode == 13) { return false; }
			});
			
			// Update description
			$('.updateOpmerkingen').click(function()
			{
				$.ajax(
				{
					type: 'POST',
					url: '/opmerkingen.php',
					data: { opmerkingen: $('.textareaOpmerkingen').val() },
					success: function(data) { return true; }
				});
			});


	// Select product by label
	$('.brandselector').click(function()
	{
		var id = $(this).attr('id').replace('brand', '');
		$('input#radio' + id).attr('checked', 'checked');
	});

});

function ShowMovieTrans(naam, breedte, hoogte, kleur)
{
   document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="'+breedte+'" HEIGHT="'+hoogte+'" id="toscanifix" ALIGN="">\n');
   document.write('<PARAM NAME=movie VALUE="'+naam+'"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE="'+kleur+'"><PARAM NAME=wmode VALUE="transparent">\n');
   document.write('<EMBED wmode="transparent" src="'+naam+'" quality=high bgcolor="'+kleur+'" WIDTH="'+breedte+'" HEIGHT="'+hoogte+'" NAME="toscanifix" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>\n');
   document.write('</object>\n');
}
