$().ready(function(){
	
	$('.li-temp').click(function(){
		if($(this).text() == 'HOME'){
			$('.contact-temp').hide();
			$('.info-temp').hide();
			$('.li-temp').each(function(){
				$(this).removeClass('selectedl');
			});	
			$(this).addClass('selectedl');
			
			$('#shops_teaser_emailsubscriptionbox').fadeIn(300);		
			$('#home_eshop_button_teaser').fadeIn(300);
			$('#home_left img').fadeTo(300, 1);
		}else if($(this).text() == 'INFO'){
			$('#home_eshop_button_teaser').hide();
			$('.contact-temp').hide();
			$('.li-temp').each(function(){
				$(this).removeClass('selectedl');
			});
					
			
			$(this).addClass('selectedl');
			$('.info-temp').fadeIn(300);
			$('#home_left img').fadeTo(300, 0.3);
		}else if($(this).text() == 'CONTACT'){
			$('#home_eshop_button_teaser').hide();
			$('.info-temp').hide();
			$('.li-temp').each(function(){
				$(this).removeClass('selectedl');
			});		
			
			$(this).addClass('selectedl');
			$('.contact-temp').fadeIn(300);
			$('#home_left img').fadeTo(300, 0.3);
		}
	});
	
	$('#storepopup').hover(function(){
		$(this).hide();
	});
	$('#home_left').hover(function(){
		$('#storepopup').hide();
	});
	
	$('#saveForm').click(function(){
		var valid = true;
		
		var email = $('#email').val();
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   			
		if (reg.test(email) == true) {
			$('#email').removeClass('error');
		}else{
			$('#email').addClass('error');
			valid = false;
		}
		
		if($('#name').val() == ''){
			$('#name').addClass('error');
			valid = false;
		}
		if($('#firstname').val() == ''){
			$('#firstname').addClass('error');
			valid = false;
		}
		if($('#comment').val() == ''){
			$('#comment').addClass('error');
			valid = false;
		}				
		
		return valid;
	});
	
	if($('#formsend').val() == 'send'){
		$('#home_eshop_button_teaser').hide();
		$('.info-temp').hide();
		$('#teaser_email_box').hide();
		$('#shops_teaser_emailsubscriptionbox').hide();			
		
		$('.contact-temp').fadeIn(300);
		$('#home_left img').fadeTo(300, 0.1);
	}
	
	$('.homefadeimage').each(function(){
		
		$(this).show("fade", {}, 2000);
		
	});
	
	$('.homeslideleftimage').each(function(){
		
		$(this).show("slide", { direction: "left" }, 1000);
		
	});
	$('.homesliderightimage').each(function(){
		
		$(this).show("slide", { direction: "right" }, 1000);
		
	});
	$('.products_thumbnail').each(function(){
		
		$(this).show("fade", {}, 1000);
		
	}); 
	
	$('.saveaccount').click(function(){
		
		var error = "false";
		if($('#txt_naam').val().length === 0){error = "true1";};
		if($('#txt_voornaam').val().length === 0){error = "true2";};
		if($('#txt_straat').val().length === 0){error = "true3";};
		if($('#txt_nr').val().length === 0){error = "true4";};
		if($('#txt_postcode').val().length === 0){error = "true5";};
		if($('#txt_woonplaats').val().length === 0){error = "true6";};
		if($('#txt_email').val().length === 0){error = "true7";};
		if($('#txt_password').val().length === 0){error = "true10";};
		if($('#txt_password2').val().length === 0){error = "true11";};
		if($('#txt_password2').val() != $('#txt_password').val()){error = "true12";};
		
		var mail = $("#txt_email").val();
			
				var email = $('#txt_email').val();
				var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
				
				if (reg.test(email) != true) {
					error = "true7";
				}
			
			
			
		if(error=="false"){
			$('#frm_account').submit();
		return false;
		}
		else{
			$('.checkout2errors').css({visibility: "visible"})

			return false;
		}
		
		
	});
	
	
	
	$('.makezipbutton').click(function(){
		var select = $('#setselecting').val();
		$('#makezip').val(select);
		$('#zipform').submit();
	});
	
	 
	
	$('.addtosetbutton').click(function(){
		
		var foldername = $(this).attr('alt');
		var selectname = foldername+"select";
		
		var setid = $('#'+selectname).val();
		
		if(setid == "select"){
			alert("Please select a Set");
		}else{
			$('#savefoldername').val(foldername);
			$('#savesetid').val(setid);
			
			$('#SaveFolderSetForm').submit();
		}
	});
	
	$('.collectbutty').click(function(){
		var error = false;
		//check fields
		if($('#bevestignaam').val() == ""){
			error = true;
		}
		if($('#bevestignvoornaam').val() == ""){
			error = true;
		}
		if($('#bevestigemail').val() == ""){
			error = true;
		}
		if(!$('#confirmation').is(':checked')){
			error = true;
		}
		if(error){
			alert('Niet alle velden zijn ingevuld.');
		}else{
			
			$('#collectshop').submit();
			
		}
		return false;
	});

	$('.closex').click(function(){
		$('.collectitinshop').hide();
		
	});
	
	$('.closebuts').click(function(){
		$('#collectaddeddiv').hide();
		
	});
	
	$('.collectclick').click(function(){
		var maat = $('#maten').val();
    	$('#bevestigmaten').val(maat);
		$('.collectitinshop').show();
		return false;
	});
	
	
	
	$('.createthumbbut').click(function(){
		$('.createimagediv').show();
		$('#activefolder').val($(this).attr('alt'));
		$('#thumbform').submit();
	});
	
	$('#addnewset').click(function(){
		
		if($('#newsetname').val() == ""){
			alert('Please fill in New Set Name');
			return false;
		}
		
	});
	
	$('.passwordcheck').change(function(){
		var pwvalch = $(this).val();
		var pwval = $('.passtocheck').val();
		
		if(pwvalch != "" && pwvalch == pwval){
			//passwords match
			if($(this).hasClass('requiredinput')){
				$(this).removeClass('requiredinput');
				$(this).addClass('validinput');
			}
		}else{
			if($(this).hasClass('validinput')){
				$(this).removeClass('validinput');
				$(this).addClass('requiredinput');
			}
		}
	})
	
	$('.requiredemail').change(function(){
		
		//checkemailfield
		var myat = /@/;
			
		var email = $(this).val();
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   			
		if (reg.test(email) == true) {
		//ok this is an email address
			if($(this).hasClass('requiredinput')){
				$(this).removeClass('requiredinput');
				$(this).addClass('validinput');
			}
		}else{
			if($(this).hasClass('validinput')){
				$(this).removeClass('validinput');
				$(this).addClass('requiredinput');
			}
		}
		
	});
	
	$('.requiredinput').change(function(){
		if (!$(this).hasClass('requiredemail') && !$(this).hasClass('passwordcheck')) {
			if ($(this).val() != "") {
				if ($(this).hasClass('requiredinput')) {
					$(this).removeClass('requiredinput');
					$(this).addClass('validinput');
				}
			}
			else {
				if ($(this).hasClass('validinput')) {
					$(this).removeClass('validinput');
					$(this).addClass('requiredinput');
				}
			}
		}
	});
	
	$(".addtobasketgiftvoucher").click(function(){
		if($('#voucher-value').val().replace(/[0-9]/g, '') != ''){
			alert('Geef een goede waarde');
		}
		else if($('#voucher-value').val() == ''){
			alert('Geen waarde ingegeven');
		}
		else {
		
			//ADD VOUCHER TO THE BASKET
			var id_juweel = $('#id_product').val();
			var id_webgroep = $('#id_webgroep').val();
			var id_webgroep_level2 = $('#id_webgroep_level2').val();
			var prijs = $('#voucher-value').val();
			var beeld = $('#image-src').val();
			var bericht = $('#voucher-body').val();
			var deCFID = $('#CFID').val();
			var urls = "act_add_giftvoucher.cfm?giftvoucheradd=true&id_juweel="+id_juweel+"&id_webgroep="+id_webgroep+"&id_webgroep_level2="+id_webgroep_level2+"&prijs="+prijs+"&beeld="+beeld+"&bericht="+bericht+"&cfid="+deCFID;
			$.ajax({
				type: "POST",
				data: "session_set=true",
				url: urls,
				beforeSend: function(){
					
				},
				success: function(data){
					if(data == 1)
					{
					//ALLES BONNE
						$('.step3').fadeOut('slow', function(){
						$('.step4').fadeIn('slow');
						});
					}
					else
					{
						alert("Giftvoucher niet toegevoegd. Probeer opnieuw");
					}
				}
				
				
			});
			
		}
	});
	
	
	$('.perssubmit').click(function(){
		
		$('#form').submit();
		return false;
	});
	
	$('.loginadmin').click(function(){
		
		$('#frm_login_admin').submit();
		return false;
	});
	
	$('.navsub').click(function(){
		//SET SESSION FOR DISPLAYING WEBGROUP PICTURE
		$.ajax({
				type: "POST",
				data: "session_set=true",
				url: "act_set_webgroup_session.cfm?setsession=true",
				beforeSend: function(){
					/*$('.postcodeloader').show(); //show checking or loading image*/
				},
				success: function(data){
					if(data == 1)
					{
					//ALLES BONNE
					}
					else(data == 0)
					{
						//NIE GOE
					}
				}
				
			});
		
	});
	
	$('.closewebgroep').click(function(){
		$('#webgroup_full_pic').slideUp(500);
		
		//SET SESSION FOR NOT DISPLAYING WEBGROUP PICTURE
			$.ajax({
				type: "POST",
				data: "session_set=false",
				url: "act_set_webgroup_session.cfm?setsession=false",
				beforeSend: function(){
					/*$('.postcodeloader').show(); //show checking or loading image*/
				},
				success: function(data){
					if(data == 1)
					{
					//ALLES BONNE
					}
					else(data == 0)
					{
						//NIE GOE
					}
				}
				
			});
		
		return false;
	});
	
	$('.mailfriendbutton').click(function(){
		showEmailShare();
		return false;
	});
	
	$('.addtofacebook').click(function(){
		showFacebookLike();
		return false;
	});
	
	$('#message-tellafriend').each(function(){
		productname = $('.juweeltitel').html();
		$(this).html('Hey, ik wil het product ' + productname + ' van Twice As Nice met je delen : <a href="' + document.URL + '">' + productname + '</a>');
	});
	/*
	$('.infonav').hover(
		function () {

			if ($('#info_subnav').css('display') == 'none') {
				$('#info_subnav').slideDown(500);
			}
		}
	);*/
	/*
	$('#ctr_top, #ctr_content').hover(
		function () {

			if ($('#info_subnav').css('display') == 'block') {
				$('#info_subnav').slideUp(500);
			}
		}
	);
	
	$('.navmenu').hover(
		function () {
			if ($(this).hasClass('infonav')) {
			}
			else {
				if ($('#info_subnav').css('display') == 'block') {
					$('#info_subnav').slideUp(500);
				}
			}
		}
	);
	
	$('#info_subnav').hover(function(){
		$(this).show();
	}, function(){
		if ($('#info_subnav').css('display') == 'block') {
			$('#info_subnav').slideUp(500);
		}
	});*/
	
	setInterval ( "fadeimagehome3()", 3000 );


	$('.answer-button').click(function(){
		$('#message').each(function(){
		$(this).html('Hey, ik wil het product ' + productname + ' van Twice As Nice met je delen : <a href="' + document.URL + '">' + productname + '</a>');
	});
		return false;
	});
	
	$('.tocheckout2').click(function(){
		var error = "false";
		
			$('.privacytest').css('color', '#000000');
			if ($('#txt_naam').val() == "") {
				error = "true1";
			}
			if ($('#txt_voornaam').val() == "") {
				error = "true2";
			}
			if ($('#txt_straat').val() == "") {
				error = "true3";
			}
			if ($('#txt_nr').val() == "") {
				error = "true4";
			}
			if ($('#txt_postcode').val() == "") {
				error = "true5";
			}
			if ($('#txt_woonplaats').val() == "") {
				error = "true6";
			}
			
			
				var email = $('#txt_email').val();
				var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
				
				if (reg.test(email) != true) {
					error = "true7";
				}
			
			
				if($('#txt_password2').val() != $('#txt_password').val()){
					error = "true8";
				}
					
				
		

		if(error=="false"){
			$('#frm_gebruiker').submit()
			return false;
		}
		else{
			$('.checkout2errors').css('visibility','visible');
			return false;
		}
		
	});
	
		$('.tocheckout2_n').click(function(){
		var error = "false";
		if (!$('#txt_privacy').attr('checked')) {
			error = "true11";
			$('.privacytest').css('color', '#ff0000');
		}
		else {
			$('.privacytest').css('color', '#000000');
			if ($('#txt_naam').val() == "") {
				error = "true1";
			}
			if ($('#txt_voornaam').val() == "") {
				error = "true2";
			}
			if ($('#txt_straat').val() == "") {
				error = "true3";
			}
			if ($('#txt_nr').val() == "") {
				error = "true4";
			}
			if ($('#txt_postcode').val() == "") {
				error = "true5";
			}
			if ($('#txt_woonplaats').val() == "") {
				error = "true6";
			}
			
			var mail = $("#txt_email").val();
			if (typeof mail != 'undefined') {
			
				var email = $('#txt_email').val();
				var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
				
				if (reg.test(email) != true) {
					error = "true7";
				}
			}
			var pass2 = $('#txt_password2').val();
			if (typeof pass2 != 'undefined') {
				if($('#txt_password2').val() != $('#txt_password').val()){
					error = "true8";
				}
					
			}	
		
		}
		
		
		if(error=="false"){
			$('#frm_gebruiker').submit()
			return false;
		}
		else{
			$('.checkout2errors').css('visibility','visible');
			return false;
		}
		
	});
	
	
	$(".allowTextInput").keypress(function(event) {
		var charCode = (event.which) ? event.which : event.keyCode;
		if(!isValidText(charCode)){
			return false;
		}
    });
	
	$(".allowMailInput").keypress(function(event) {
		var charCode = (event.which) ? event.which : event.keyCode;
		if(!isValidEmail(charCode)){
			return false;
		}
    });

	$(".allowDateInput").keypress(function(event) {
		var charCode = (event.which) ? event.which : event.keyCode;
		if(!isValidDate(charCode)){
			return false;
		}
    });
	
	$('.registerbutton').click(function(){
		var error = "false";
		
		if (!$('#txt_privacy').attr('checked')) {
			error = "true11";
			$('.privacytest').css('color', '#ff0000');
		}
		else {
			$('.privacytest').css('color', '#000000');
			if ($('#txt_naam').hasClass('requiredinput')) {
				error = "true1";
			};
			if ($('#txt_voornaam').hasClass('requiredinput')) {
				error = "true2";
			};
			if ($('#txt_straat').hasClass('requiredinput')) {
				error = "true3";
			};
			if ($('#txt_nr').hasClass('requiredinput')) {
				error = "true4";
			};
			if ($('#txt_postcode').hasClass('requiredinput')) {
				error = "true5";
			};
			if ($('#txt_woonplaats').hasClass('requiredinput')) {
				error = "true6";
			};
			if ($('#txt_email').hasClass('requiredinput')) {
				error = "true7";
			};
			if ($('#txt_tel').hasClass('requiredinput')) {
				error = "true8";
			};
			if ($('#txt_verjaardag').hasClass('requiredinput')) {
				error = "true9";
			};
			if ($('#txt_password').hasClass('requiredinput')) {
				error = "true10";
			};
			if ($('#txt_password2').hasClass('requiredinput')) {
				error = "true11";
			};
		}
		
		if(error=="false"){
			$('#frm_registreer').submit()
			return false;
		}
		else{
			$('.checkout2errors').css('visibility','visible');
			return false;
		}
		
		
	});
	
	$('.langsel').click(function(){
		
		$('.overlangselect').html($(this).html);
		
	});
	
	$('.gosearchpostcode').click(function(){
		if($('#postcode').val() != ""){
			$('#search-shops').submit();
			return false;
		}
		else{
			alert($('#postcode').attr('alt'));
			return false;
		}
		
	});
	
	$('.tocheckout3').click(function(){
		$('#txt_lever_straat').attr('disabled', false);
			$('#txt_lever_nr').attr('disabled', false);
			$('#txt_lever_bus').attr('disabled', false);
			$('#txt_lever_postcode').attr('disabled', false);
			$('#txt_lever_woonplaats').attr('disabled', false);
			$('#txt_lever_land').attr('disabled', false);
		$('#frm_klant').submit();
		return false;
		
	});
	$('.tocheckout4').click(function(){
		if($('#accepted').attr('checked')){
			$('#frm_klant').submit();
		}else{
			$('.accepttext').css('border', '1px solid #ff0000');
		}
		return false;
		
	});	
	
	$('.gonewsletter').click(function(){
		if($('#email_newsletter').val() != "" && $('#email_newsletter').val() != "email adres"){
			if (isValidEmailAddress($('#email_newsletter').val())) {
				$('#emailnewsform').submit();
				$('#email_newsletter').css('background-color', '#ffffff');
			}else{
				$('#email_newsletter').css('background-color', '#f68c8c');
			}
			return false;
		}
		else{
			alert($('#email_newsletter').attr('alt'));
			return false;
		}
	});
	/*
	$('.logmeoff').click(function(){
		$('#logoutform').submit();
		return false;
	});*/
	
	$('.maten').change(function(){
		
		var id_juweel = $(this).val();
		
		$('.juweelidmaat').each(function(){
			$(this).val(id_juweel);
		});

		
	});
	
	$('#email_newsletter').focus(function(){
		$(this).val("");
	});
	$('#email_newsletter').blur(function(){
		if($(this).val() == ""){
			$(this).val("email adres");	
		}
	});
	$('.leveringchecker').click(function(){
		if($(this).attr('checked') == false){
			$('#txt_lever_straat').attr('disabled', false);
			$('#txt_lever_nr').attr('disabled', false);
			$('#txt_lever_bus').attr('disabled', false);
			$('#txt_lever_postcode').attr('disabled', false);
			$('#txt_lever_woonplaats').attr('disabled', false);
			$('#txt_lever_land').attr('disabled', false);
			$('#thuis_adres').val('0');

		}
		else{
			$('#txt_lever_straat').attr('disabled', true);
			$('#txt_lever_nr').attr('disabled', true);
			$('#txt_lever_bus').attr('disabled', true);
			$('#txt_lever_postcode').attr('disabled', true);
			$('#txt_lever_woonplaats').attr('disabled', true);
			$('#txt_lever_land').attr('disabled', true);
			$('#thuis_adres').val('1');
		}
		
	});
	
	$('#forgotpasswordform').hide();
	
	$('.checklogincust').click(function(){
		$('#frm_login').submit();
		return false;
	});
	
	$('.sendpass').click(function(){
		$('#frm_password').submit();
		return false;
	});
	
	$('.forgotpass').click(function(){
		$('#loginform').hide();
		$('#forgotpasswordform').fadeIn('slow');
		return false;
	});
	
	$('.backtologin').click(function(){
		$('#forgotpasswordform').hide();
		$('#loginform').fadeIn('slow');
		return false;
	});
	
	$("#productslider").slider({
			range: true,
			min: 0,
			max: 300,
			step: 5,
			values: [ $('#pricemin').val(), $('#pricemax').val() ],
			slide: function( event, ui ) {
				$("#amount").val("€" + (ui.values[0]) + " - €" + (ui.values[1]) );
			},
			change: function(event, ui) {
				$('#pricemin').val(ui.values[0]-1);
				$('#pricemax').val(ui.values[1]+1);
				$('#priceform').submit();
			 }
		});
	$("#amount").val("€" + $('#pricemin').val() + " - €" + $('#pricemax').val());
	
	$('.navsub ').click(function(){
		$.get("act_reset_priceslider.cfm");
		
		return true;
	});	
	
	$('.smallimg').click(function(){
		var newhref = 'images/juweel/large/'+$(this).attr('alt');
		//$('#img').attr('href')
		
		var newsrc = 'images/juweel/'+ $(this).attr('alt');
		var newdatazoom = 'images/juweel/800/' + $(this).attr('alt');
		$('#img_juweel').attr('data-zoomsrc', newdatazoom);
		$('.mojozoom_img').attr('src', newdatazoom);
		
		$('#img_juweel').hide("fade", {}, 500, function(){
			$('#img_juweel').attr('src', newsrc);
			$('#img_juweel').show("fade", {}, 800);
		});
		
		return false;
	});	
	
	
	$('#submitbasketlink').click(function(){
			/*var link = $(this).attr('href');
			link = link + "&aantal="+$('#aantal').val();
			$(this).attr('href', link);*/
			$('#addtobasketform').submit();
			return false;
	});

	$(".mouseover_up").click(function(){
	    var topVal = $("#contentscroller").scrollTop();
		var newVal = parseInt(topVal)-200;
		if(newVal<0){
			newVal = 0;
		}
		$("#contentscroller").animate({ scrollTop: newVal }, 500);
		return false;
  	});
	
	  $(".mouseover_down").click(function(){
	    var topVal = $("#contentscroller").scrollTop();
		var newVal = parseInt(topVal)+200;
		var theheight = $("#contentscroller").attr("scrollHeight");
		if(newVal>theheight){
			newVal = theheight;
		}
		$("#contentscroller").animate({ scrollTop: newVal }, 500);
		return false;
	  });
		
		$(".shopsmouseover_up").click(function(){
	    var topVal = $("#shopslist").scrollTop();
		var newVal = parseInt(topVal)-200;
		if(newVal<0){
			newVal = 0;
		}
		$("#shopslist").animate({ scrollTop: newVal }, 500);
		return false;
  	});
	
	  $(".shopsmouseover_down").click(function(){
	    var topVal = $("#shopslist").scrollTop();
		var newVal = parseInt(topVal)+200;
		var theheight = $("#shopslist").attr("scrollHeight");
		if(newVal>theheight){
			newVal = theheight;
		}
		$("#shopslist").animate({ scrollTop: newVal }, 500);
		return false;
	  });

		$(".teasermouseover_up").click(function(){
			
	    var topVal = $("#shopslist_teaser").scrollTop();
		var newVal = parseInt(topVal)-200;
		if(newVal<0){
			newVal = 0;
		}
		$("#shopslist_teaser").animate({ scrollTop: newVal+ 'px' }, 500);
		return false;
  	});
	
	$('.overshopslist').hover(function(e){
		var yval = (e.pageY - 90);
		$('#storepopup').css('top', yval);
		$('#storepopup').html("");
		var idverkooppunt = $(this).attr('alt');
		$.ajax({
				type: "POST",
				data: "id_verkooppunt="+idverkooppunt,
				url: "act_get_verkooppunt.cfm?id_verkooppunt="+idverkooppunt,
				beforeSend: function(){
					/*$('.postcodeloader').show(); //show checking or loading image*/
					
				},
				success: function(data){
					if(data != 0)
					{
					//ALLES BONNE
						$('#storepopup').html(data);
						$('#storepopup').show();
					}
					else(data == 0)
					{
						//NIE GOE
						
					}
				}
				
			});
		
	
		
	}, function(){
		
		$('#storepopup').hide();
		
	});
	
	  $(".teasermouseover_down").click(function(){
	  	
	    var topVal = $("#shopslist_teaser").scrollTop();
		var newVal = parseInt(topVal)+200;
		var theheight = $("#shopslist_teaser").attr("scrollHeight");
		if(newVal>theheight){
			newVal = theheight;
		}

		$("#shopslist_teaser").animate({ scrollTop: newVal+ 'px' }, 500);
		return false;
	  });

	$(".basketmouseover_up").click(function(){
	    var topVal = $("#baskettables").scrollTop();
		var newVal = parseInt(topVal)-112;
		if(newVal<0){
			newVal = 0;
		}
		$("#baskettables").animate({ scrollTop: newVal }, 500);
		return false;
  	});
	
	  $(".basketmouseover_down").click(function(){
	    var topVal = $("#baskettables").scrollTop();
		var newVal = parseInt(topVal)+112;
		var theheight = $("#baskettables").attr("scrollHeight");
		if(newVal>theheight){
			newVal = theheight;
		}
		$("#baskettables").animate({ scrollTop: newVal }, 500);
		return false;
	  });
	  
	  $('#search-shops').submit(function(e){
		searchShops(e);
		e.preventDefault();
		e.stopPropagation();
		return false;
	});
	  
	  $('.singlepostcode').click(function(){
	  
	  	$('#shopslist').hide("slide", { direction: "left" }, 500, function(){
		});
		
		var idverkooppunt = $(this).attr('alt');
		$.ajax({
				type: "POST",
				data: "id_verkooppunt="+idverkooppunt,
				url: "act_get_verkooppunt.cfm?id_verkooppunt="+idverkooppunt,
				beforeSend: function(){
					/*$('.postcodeloader').show(); //show checking or loading image*/
					
				},
				success: function(data){
					if(data != 0)
					{
					//ALLES BONNE
						$('#shops-info').html(data);
						$('#shops-info').delay(500).fadeIn(1000);
						$('#shops-back').fadeIn(1000);
						
					}
					else(data == 0)
					{
						//NIE GOE
						
					}
				}
				
			});
		
		
		return false;
	  });
	  
	  
	  
	  $('#infoback').css('opacity', '1');
	  

	  
	  $('#shops-back').click(function(){
	  		$('#shops-info').hide();
			$('#shops-back').hide();
			$('#shopslist').show("slide", { direction: "left" }, 500, function(){
		});
		
		return false;
	  });
	  
	  //GOOGLE MAPS
	  if (typeof GBrowserIsCompatible == "function") {
              
            var crossLayer = new GTileLayer(new GCopyrightCollection(""), 0, 15);
			
			 var myOptions = {
    			zoom: 6
  			};
  			var map = new google.maps.Map(document.getElementById("map"), myOptions);

            //map = new GMap2($("#map"));
            
            map.setCenter(new GLatLng(50.871845, 4.476929), 7);
            map.addControl(new GLargeMapControl());
            
            map.enableDoubleClickZoom();
            map.enableContinuousZoom();
            map.enableScrollWheelZoom();
            
            
         
            
            // Create a base icon for all of our markers that specifies the shadow, icon dimensions, etc.
            var baseIcon = new GIcon();
            //baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
            baseIcon.iconSize = new GSize(40, 40);
            //baseIcon.shadowSize = new GSize(37, 34);
            baseIcon.iconAnchor = new GPoint(22, 35);
            baseIcon.infoWindowAnchor = new GPoint(22, 2);
            baseIcon.image= "images/map_marker.png";
            
            // Create a lettered icon for this point using our icon class
            //var letter = String.fromCharCode("A".charCodeAt(0) + index);
            var letteredIcon = baseIcon; //new GIcon(baseIcon);
            //letteredIcon.image = "../images/map_point.png";
            
            
            var point;
            var markerOptions = { icon:letteredIcon, labelOffset: new GSize(-6, -32) };
            var marker;
            var ttr=[],tts=[];
            var i;
            
            var markers = [];
            for(i=0; i<s.length; i++){
                  
                  point = new GLatLng(s[i].lat, s[i].lon);
                  marker = new GMarker(point, markerOptions);
                  s[i].m = marker;
                  
                  /*tts.push({
                        id: s[i].id,
                        r: s[i].r,
                        w: new google.maps.InfoWindow({content: s[i].tt});
                  });*/
                  
                  GEvent.addListener(marker, "click", showTooltipShop);
                        //marker.onclick = onMapClick;
                  
                  markers.push(marker);
                  //map.addOverlay(marker);
                  
            }
            
            var mc = new MarkerClusterer(map,markers);
            /*var mgr = new MarkerManager(map);

			mgr.addMarkers(markers, 0, 15);
  			mgr.refresh();*/
			
			
            // Set up map type menu relationships
            var mapControl = new GHierarchicalMapTypeControl();
            mapControl.clearRelationships();
            mapControl.addRelationship(G_SATELLITE_MAP, G_HYBRID_MAP, "Labels", false);
            //mapControl.addRelationship(G_PHYSICAL_MAP, mtTerCross, "Crosshairs");
            
            // Add control after you've specified the relationships
            map.addControl(mapControl);
      }
			
	
	

});

function isValidText(code){
	var isValid = true;
	if (code == 46 || code == 8 || code == 9 || code == 37 || code == 39 || code == 109 || code == 110 || code == 190 || code == 32) {
	 	//ok
	}
	else {
		// Ensure that it is a number and stop the keypress
		if ((code < 65 || code > 90) && (code < 96 || code > 122) && (code < 48 || code > 57) && (code < 192 || code > 255)) {
			isValid = false;
		}
	}
	return isValid;
}


function isValidEmailAddress(email){
	
		var isValid = true;
		var myat = /@/;
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   			
		if (reg.test(email) == true) {
		//ok this is an email address
			
			isValid = true;
			
		}else{
			isValid = false;
		}
		
		return isValid;
}

 function isValidEmail(code){
	var isValid = true;
	if (code == 46 || code == 8 || code == 9 || code == 37 || code == 39 || code == 109 || code == 110 || code == 190 || code == 32 || code == 64 || code == 45 || code == 95) {
	 	//ok
	}
	else {
		// Ensure that it is a number and stop the keypress
		if ((code < 48 || code >57 ) && (code < 65 || code > 90) && (code < 96 || code > 122) && (code < 192 || code > 255)) {
			isValid = false;
		}
	}
	return isValid;
}



function isValidDate(code){
	var isValid = true;
	if (code == 46 || code == 8 || code == 37 || code == 39 || code == 45) {
	 	//ok
	}
	else {
		// Ensure that it is a number and stop the keypress
		if (code > 31 && (code < 48 || code > 57)){
			isValid = false;
		}
	}
	return isValid;
}


function showTooltipRegion() {
      var ri = -1;
      if(this.Fo){
            ri = parseInt(this.Fo.replace('marker','')) - 1;
      }
      else if(this.qo){
            ri = parseInt(this.qo.replace('marker','')) - 1;
      }
      this.openInfoWindowHtml(r[ri].tt);
}
function fadeimagehome3(){
		var maximg = $('#home3max').val();
		var activeimg = $('#home3fader').val();
		$('.home3image'+activeimg).fadeOut(1000, function(){
			activeimg++;
			if(activeimg > maximg){
				activeimg = 1;
			}
			$('#home3fader').val(activeimg);
			$('.home3image'+activeimg).fadeIn(800);
			
			
		});
}
function showTooltipShop() {
      var si = -1;
      
      for(var gp in this){    
            if((typeof this[gp]  == 'string') && (this[gp].indexOf('marker') == 0 )){
                  si = parseInt(this[gp].replace('marker','')) - 1;
            }
      }
      
      this.openInfoWindowHtml(s[si].tt);
      //var w = new google.maps.InfoWindow({content: s[si].tt});
      //w.open(map, s[si].m);
}

function setRegionShops(){
      map.setCenter(new GLatLng(55, -3.5), 6); // region center, zoom: 6? 7? (init: 5)
      // hide region markers => how? how to return?
      // add shop markers
}

function searchShops(e){
		
			searchtoshops(e);
		
      
}

function showFacebookLike(){ 

      var image = 'http://www.twiceasnice.be/images/juweel/thumb/' + $('#img_juweel').attr('alt');
	 
      image = image.replace('https','http');
      var description = $('.juweeltitel').html();
      var inputtext = 'Dit artikel van Twice As Nice vind ik interessant.';
      FB.ui(
   {
     method: 'feed',
     name: inputtext,
     link: document.URL,
     picture: image,
      source: image,
     caption: 'Twice As Nice',
     description: description,
     message: 'Your text...'
   },
   function(response) {
   }
);
}
	
function showEmailShare(){
	
	productname = $('.juweeltitel').html();
	var h = $(window).height() - 110, u = $('#tellafriendform').html();
	
		Boxy.alert('<div class="datahtml-container" style="height:"80px;">'+u+'</div>', null, {title: '<span class="tittit">'+$('#tellafriend-title').text()+'</span>', width:600
	});
	
	
	
	
	return false;
}

function searchtoshops(e){
	var gc = new GClientGeocoder(); 
      addr = $('.postcodesearchinput').val() + ', ' + 'BELGIUM';
      //$('.ourstoresicons').hide();
      gc.getLatLng(addr, function(p) {   // p = point
            if (!p) {
                  error("Search shops", '"' + addr + '" could not be found');
            }
            else {
                  var ajax_load = '<div class="loader"><img src="images/loading.gif" width="32" height="32" alt="" border="0"/><br/><span>loading...</span></div>',
                        loadUrl = 'dsp_shops_search.cfm?lat=' + p.lat() + '&long=' + p.lng();
                  
                  $.ajaxSetup({ cache: false });
               		
					
                  $('#shopslist').html(ajax_load).load(loadUrl, null, function(){
                        
						
						$('#shopslist').show();
							$('#shops-info').hide();
			$('#shops-back').hide();
			$('#shopslist').show("slide", { direction: "left" }, 500, function(){
		});
							
								
							
	
							
					
						// set search value in title
						
						
                       // $('#shops-search').html(addr.replace(', BE',''));

                        // map 'back'-button
                        //$('#shops-search-back').removeAttr('href').css('cursor', 'pointer').click(function(){ $('#shops-map').show(); $('#shops-search').hide();   });
                        
						/*$('#shops-search-back').fakeClick(function(){  
                        
                        if($('.content-shops-az').css('display') == 'list-item' ){
                             $('.search-list').show();
                             $('#shops-search').hide();
                        }
                        else if($('.content-shops-map').css('display') == 'list-item' ){
                             $('#shops-map').show();
                             $('#shops-search').hide();
                        }
                        else{
                             window.location = 'index.cfm/fuseaction/main.shops'
                        }
                        });*/
						
						
                        /*
                        $('.shops-az').fakeClick(function(){     
                             $('.search-list').show();
                             $('#shops-search').hide();
                        });
                        
                        */
                        
                        
                        
                  });
                  //$('#shops-search-param').html(addr);
    		}
		});
}
