﻿$(function() {
	tabs();
	edit();
	sort();
});

// recharge n importe quel element en ajax
function filter(type,get,url)
{
	$('.loading').show();
	var form_fields = "";
	var form_ok = true;
	if(get.match('serialize=yes')) { var new_serialize = get.split('&id_form='); var new_serialize2 = new_serialize[1].split('&'); form_fields += '&'+$('form#'+new_serialize2[0]).serialize(); }
	if(get!='') { form_fields += '&'+get; }
	if(form_ok)
	{
		$('#'+type+'_view').load(url+'?'+form_fields,function() {
			$('.loading').hide();
		});
	}
	return false;
}

// charge les tabulations
function tabs()
{
	$("#tabs").tabs({
		ajaxOptions: {
			error: function(xhr, status, index, anchor) {
				$(anchor.hash).html("<div class='error'>Couldn't load this tab. We'll try to fix this as soon as possible.</div>");
			}
		},
		select: function(event, ui) { $('.loading').show(); },
		load: function(event, ui, anchor) { $('.loading').hide(); }
	});
}

// modifie les donnees
function edit()
{
	$('.editable').editable('datas_edit.php', { 
		type : 'text',
		loadtype : 'POST',
		width : '100%',
		cancel : 'annuler',
		submit : 'ok',
		onblur : 'ignore',
		event : 'dblclick'
	});
}

// modifie les donnees avec textarea
function edit_textarea()
{
	$('.editable_textarea').editable('datas_edit.php', { 
		type : 'textarea',
		loadtype : 'POST',
		cols : 150,
		rows : 3,
		cancel : 'annuler',
		submit : 'ok',
		onblur : 'ignore',
		event : 'dblclick'
	});
}

// modifie les donnees avec menu deroulant
function edit_select()
{
	$('.editable_select').editable('datas_edit.php', { 
		loadurl : 'datas_edit_select.php',
		type : 'select',
		loadtype : 'POST',
		cancel : 'annuler',
		submit : 'ok',
		onblur : 'ignore',
		event : 'dblclick'
	});
}

// drag
function sort()
{
	$(".sortable").sortable({
		handle: '.dragme',
		cursor : 'move',
		stop : function() {
			serial = $(".sortable").sortable('serialize');
			$.ajax ({ type: "POST",dataType: "html", url: "datas_sortable.php", data: serial});
		}
	});
}
