/*Header slideshow - start*/
function slideShow() {

	//Set the opacity of all images to 0
	$('#showcase a').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('#showcase a:first').css({opacity: 1.0});
	
	//Set the caption background to semi-transparent
	$('#showcase .caption').css({opacity: 0.8});

	//Resize the width of the caption according to the image width
	$('#showcase .caption').css({width: $('#showcase a').find('img').css('width')});
	
	//Get the caption of the first image from REL attribute and display it
	$('#showcase .content').html($('#showcase a:first').find('img').attr('rel'))
	.animate({opacity: 0.8}, 400);
	
	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('gallery()',12000);
	
}

function gallery() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#showcase a.show')?  $('#showcase a.show') : $('#showcase a:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#showcase a:first') :current.next()) : $('#showcase a:first'));	
	
	//Get next image caption
	var caption = next.find('img').attr('rel');	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
	//Set the opacity to 0 and height to 1px
	$('#showcase .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });	
	
	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('#showcase .caption').animate({opacity: 0.8},100 ).animate({height: '80px'},500 );
	
	//Display the content
	$('#showcase .content').html(caption);
	
	
}
/*Header slideshow - end*/


/*NEWSLETTER - START */
function checknewsletter()
{
	var error = true;
	var error_email = false;
	if($("#nlperiod").val() == '0')
	{
		$('#nlperiod').css({'background-color': 'red'});
		error = false;
	}
	else
	{
		$('#nlperiod').css({'background-color': 'white'});
	}
	
	if($("#nlformat").val() == '0')
	{
		$('#nlformat').css({'background-color': 'red'});
		error = false;
	}
	else
	{
		$('#nlformat').css({'background-color': 'white'});
	}
	
	if($("#nlcontent").val() == '0')
	{
		$('#nlcontent').css({'background-color': 'red'});
		error = false;
	}
	else
	{
		$('#nlcontent').css({'background-color': 'white'});
	}
	
	if($("#nlemailaddress").val() != '')
	{
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
 
    var emailaddressVal = $("#nlemailaddress").val();
		
		if(!emailReg.test(emailaddressVal)) {
				/*$("#nlemailaddress").after('<span class="error">Enter a valid email address.</span>');*/
				$('#nlemailaddress').css({'background-color': 'red'});
				error = false;
				error_email = true;
		}
		else
		{
			$('#nlemailaddress').css({'background-color': 'white'});
		}
	}
	else
	{
		$('#nlemailaddress').css({'background-color': 'red'});
		error = false;
	}
	
	if($('#nlnewproduct').is(':checked') || $('#nlsale').is(':checked') || $('#nlfresnews').is(':checked') || $('#nltouroffer').is(':checked') || $('#nlpracticeplan').is(':checked'))
	{
		$('#tnlnewproduct').css({'color': 'black'});
		$('#tnlsale').css({'color': 'black'});
		$('#tnlfresnews').css({'color': 'black'});
		$('#tnltouroffer').css({'color': 'black'});
		$('#tnlpracticeplan').css({'color': 'black'});
	}
	else
	{
		$('#tnlnewproduct').css({'color': 'red'});
		$('#tnlsale').css({'color': 'red'});
		$('#tnlfresnews').css({'color': 'red'});
		$('#tnltouroffer').css({'color': 'red'});
		$('#tnlpracticeplan').css({'color': 'red'});	
	}
	
	if(!error)
	{
		if(error_email)
		{
			alert("A kijelölt mezők kitöltése, kiválasztása kötelező! Hibás a megadott email cím!");
		}
		else
		{
			alert("A kijelölt mezők kitöltése, kiválasztása kötelező!");
		}
		return error;
	}
	else
	{
		return error;
	}	
}
/*NEWSLETTER - END */

/*Change newsletter on registration page - start*/
function change_newsletter(nlval)
{
	if(nlval == 1 || nlval == 2 || nlval == 3 || nlval == 4)
	{
		$('#newsletter-div').show();
	}
	else
	{
		$('#nlformat').val('0');
		$('#nlcontent').val('0');
		$('#newsletter-div').hide();
	}
}
/*Change newsletter on registration page - end*/

function checkunsubscribe()
{
	var error = true;
	
	if($("#unsubscribeemail").val() != '')
	{
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
 
    var emailaddressVal = $("#unsubscribeemail").val();
		
		if(!emailReg.test(emailaddressVal)) {
				/*$("#nlemailaddress").after('<span class="error">Enter a valid email address.</span>');*/
				$('#unsubscribeemail').css({'background-color': 'red'});
				error = false;
		}
		else
		{
			$('#unsubscribeemail').css({'background-color': 'white'});
		}
	}
	else
	{
		$('#unsubscribeemail').css({'background-color': 'red'});
		error = false;
	}
	
	if(!error)
	{
		alert("Hibás a megadott email cím!");
		return error;
	}
	else
	{
		return error;
	}	
}

/*Basket - del item*/
function delitem(id, redirect_url)
{
	if(id != '')  
	{
		$.ajax({
							type 				: 'POST',
							url 				: '/php/ajax/ajax_basket.php',
							dataType		: 'html',
							data				: 'op=delitem&id='+id,
							success		 	: function(msg){
								//$('#'+divname).html(msg);
								//window.location.reload();
								window.location = '/'+redirect_url+'.html';

							},
							error 			: function() {
							}
						});
	}
}

/*Basket - change item pieces*/
function changePiece(pieces, id, redirect_url)
{
	if(!isNaN(id) && !isNaN(pieces) && redirect_url != '')  
	{
		$.ajax({
							type 				: 'POST',
							url 				: '/php/ajax/ajax_basket.php',
							dataType		: 'html',
							data				: 'op=setpiece&id='+id+'&pieces='+pieces,
							success		 	: function(msg){
								//$('#'+divname).html(msg);
								//window.location.reload();
								window.location = '/'+redirect_url+'.html';
							},
							error 			: function() {
							}
						});
	}
}
