$(document).ready(function()
{
	hideshow('loading',0);
	$('#loginForm').submit(function(e)
	{
		register("ajax/login","#loginForm","./");
		e.preventDefault();	
		return false;
	});
	$('#voteFormPhoto').submit(function(e)
	{
		var id = $('#id').val();
		register("ajax/vote_photo","#voteFormPhoto","photo/detail/item/"+id+"/status/ok");
		e.preventDefault();	
		return false;
	});
	$('#voteFormDesign').submit(function(e)
	{
		var id = $('#id').val();
		register("ajax/vote_design","#voteFormDesign","design/detail/item/"+id+"/status/ok");
		e.preventDefault();	
		return false;
	});
});


function register(urlAction,formId,redirect)
{
	hideshow('loading',1);
	error(0);
	
	$.ajax({
		type: "POST",
		url: urlAction,
		data: $(formId).serialize(),
		dataType: "json",
		success: function(msg){
			
			if(parseInt(msg.status)==1)
			{
				error(1,msg.txt);
				/*$("#star-rating").stars({
					disabled: true
				});
				$("#submit-rating").attr('disabled','disabled');*/
				window.location=redirect;
			}
			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);
}
