var info = {
	show: function (divId, response)
	{
		$("#"+divId).empty();
		$.each(response, function(i, v) {
			if(v.msg != undefined) $("#"+divId).append("<div class=\""+ v.type +"\">"+v.msg+"</div>");
			if(v.redirect != undefined) window.location = v.redirect;
			if(v.javascript != undefined) eval(v.javascript);
		});
		return false;
	}
};

var core = {
	events: function ()
	{

	}
};

$(document).ready(function () {
	
    $('#formUpload').submit(function() {
		$(this).ajaxSubmit({
			beforeSubmit:	beforeSubmit,
			success:		submitSuccess,
			dataType:		'json'
		});
        return false; 
    });
	core.events();
});

function FBinit() {
	FB.init({
		appId: appId,
        status     : true, // check login status
        cookie     : true, // enable cookies to allow the server to access the session
        oauth      : true, // enable OAuth 2.0
        xfbml      : true  // parse XFBML
	});
}

function logout () {
	FB.getLoginStatus(function(response) {
		if (response.session) {
			FB.logout(function() { window.location='/user/logout'; });
		} else {
			window.location='/user/logout';
		}
	});
	return false;
}

function beforeSubmit (arr, form, options)
{
	var submitButton = $(form).children(':submit');
	var fieldName = $(submitButton).attr('value');
	$(submitButton)
		.attr('disabled', true)
		.attr('value', t_pleaseWait)
		.attr('alt', fieldName);
}

function submitSuccess(response, status, x, form)
{
	var submitButton = $(form).children(':submit');
	var fieldName = $(submitButton).attr('alt');
	$(submitButton)
		.attr('disabled', false)
		.attr('value', fieldName);

	info.show('response', response);
	return false;
}
