jQuery(document).ready(function($) {
	
	$('#loginForm').submit(function(e) {
		login();
		e.preventDefault();
		
	});
	
	$('#regForm').submit(function(e) {

		register();
		e.preventDefault();
		
	});
	
});


function login()
{
	hideshow('loading',1);
	error(0);
	$.ajax({
		type: "POST",
		url: Enx_base_url+"controller/signin.php",
		data: $('#loginForm').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 register()
{
	
	hideshow('loading',1);
	error(0);
	$.ajax({
		type: "POST",
		url: Enx_base_url+"controller/signup.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);
				alert(msg.txt);
			}
			
			hideshow('loading',0);
		}
	});

}



function hideshow(el,act)
{
	if(act) $('#'+el).css('display','block');
	else $('#'+el).css('display','none');
}

function error(act,txt)
{
	hideshow('error',act);
	if(txt) $('#error').html(txt);
}