$(document).ready(function(){
						   
	$('.greenButton').click(function(){
									 
		register();
		
	});
	
	$('#regForm').submit(function(e) {

		register();
		e.preventDefault();
		
	});
	
});

$(document).ready(function(){
	$('.greenButton2').click(function(){
									 
		register2();
		
	});
	
	$('#regFormAlta').submit(function(e) {

		register2();
		e.preventDefault();
		
	});
	
});

$(document).ready(function(){
	$('.greenButton3').click(function(){
									 
		register3();
		
	});
	
	$('#regFormDist').submit(function(e) {

		register3();
		e.preventDefault();
		
	});
	
});

$(document).ready(function(){
	$('.greenButton4').click(function(){
									 
		register4();
		
	});
	
	$('#regFormPreciosEsp').submit(function(e) {

		register4();
		e.preventDefault();
		
	});
	
});


function register()
{
	hideshow('loading',1);
	error(0);
	
	$.ajax({
		type: "POST",
		url: "submit.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);
			}
			
			hideshow('loading',0);
		}
	});

}


function register2()
{
	hideshow('loading',1);
	error(0);
	
	$.ajax({
		type: "POST",
		url: "submitalta.php",
		data: $('#regFormAlta').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);
			}
			
			hideshow('loading',0);
		}
	});

}

function register3()
{
	hideshow('loading',1);
	error(0);
	
	$.ajax({
		type: "POST",
		url: "submitdist.php",
		data: $('#regFormDist').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);
			}
			
			hideshow('loading',0);
		}
	});

}

function register4()
{
	hideshow('loading',1);
	error(0);
	
	$.ajax({
		type: "POST",
		url: "submitPE.php",
		data: $('#regFormPreciosEsp').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);
			}
			
			hideshow('loading',0);
		}
	});

}


function hideshow(el,act)
{
	if(act) $('#'+el).css('visibility','visible');
	else $('#'+el).css('visibility','hidden');
}

function error(act,txt)
{
	hideshow('error',act);
	if(txt) $('#error').html(txt);
}
