$(document).ready(function(){
	
	$('#regForm').submit(function(e) {

		register();
		e.preventDefault();
		
	});
	
});


function register()
{
	registerhideshow('loading',1);
	error(0);
	
	$.ajax({
		type: "POST",
		url: "scripts/js_newsletter_form.php",
		data: $('#regForm').serialize(),
		dataType: "json",
		success: function(msg){
			
			if(parseInt(msg.status)==1)
			{
				window.location=msg.txt;
			}
			else if(parseInt(msg.status)==0)
			{
				error(1,msg.txt);
			}
			
			registerhideshow('loading',0);
		}
	});

}


function registerhideshow(el,act)
{
	if(act) $('#'+el).css('visibility','visible');
	else $('#'+el).css('visibility','hidden');
}

function error(act,txt)
{
	registerhideshow('newsletter-error',act);
	if(txt) $('#newsletter-error').html(txt);
}