$(document).ready(function(){
						   
	$('.bt_register').click(function(){
		register();
		
	});

	
	$('#regForm').submit(function(e) {
		register();
		e.preventDefault();
	});
	
	
	
	
	$('.bt_login').click(function(){
		login();
		
	});
	
		$('#logForm').submit(function(e) {
		login();
		e.preventDefault();
	});
	
});


function register()
{
	hideshow('loading_reg',1);
	error(0);
	
	$.ajax({
		type: "POST",
		url: "/submit_reg.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_reg',0);
		}
	});

}

function login()
{
	hideshow('loading_log',1);
	error(0);
	
	$.ajax({
		type: "POST",
		url: "/submit_login.php",
		data: $('#logForm').serialize(),
		dataType: "json",
		success: function(msg){
			
			if(parseInt(msg.status)==1)
			{
				window.location=msg.txt;
			}
			else if(parseInt(msg.status)==0)
			{
				error_log(1,msg.txt);
			}
			
			hideshow('loading_log',0);
		}
	});

}

function hideshow(el,act)
{
	if(act) $('#'+el).css('visibility','visible');
	else $('#'+el).css('visibility','hidden');
}

function error(act,txt)
{
	hideshow('error_reg',act);
	if(txt) $('#error_reg').html(txt);
}

function error_log(act,txt)
{
	hideshow('error_log',act);
	if(txt) $('#error_log').html(txt);
}
