var ajaxOptions = {
	dataType: "json"
};

fetch = function(url) {
	var result;

    ajaxOptions.url = url;
    ajaxOptions.async = false;
    ajaxOptions.success = function(response) {
		result = response;
		
		if (response.redirect != undefined)
		{
			window.location = response.redirect;
		}
		else if (response.modal != undefined)
		{
			$("#modal").html('');	
			$("#modal").jqm({ajax: response.modal});
			$("#modal").jqmShow();		
		}
    };

    $.ajax(ajaxOptions);
	return result;
}

showLogin = function() {
	if (fetch('/user/ajax?get=logged').result == false)
	{
		$("#modal").jqm({
		    ajax: "/acces-parents/"
		});
		$("#modal").jqmShow();		
	}
}

doLogin = function(form) {
	form = $(form);
	
    ajaxOptions.url = "/acces-parents/"; form.attr('action');
    ajaxOptions.type = "POST";
    ajaxOptions.async = false;
    ajaxOptions.data = form.serialize() + "&submit=" + form.attr('id');
	ajaxOptions.dataType = "html";
    ajaxOptions.success = function(response) {
		$('#modal').html(response);
    };

    $.ajax(ajaxOptions);
	return false;
}