function calcolaFormazione(id, urlSendPri, urlSendSec){
	aId = id.split("_");
	idPlayer = aId[0];
	pos = aId[1];
	$('#'+id).addClass('loader');
	$.ajax({
		type: "GET",
		url: urlSendPri+urlSendSec+"ajax/inform.php",
	    data:{idPast: idPlayer},
	    success : function (mRet) {
	    	if(mRet == 'error'){
	    		$('#'+id).removeClass('loader');
	    		$("#error_msg").addClass('ui-state-error');
	    		$("#error_msg").addClass('ui-corner-all');
	    		$("#error_msg").addClass('show');
	    		$("#error_msg").html('Giocatore non consentito nel modulo');
	    		$("#dialogError").dialog('open');
	    	} else {
	    		$('#formazione').html('');
				$('#formazione').html(mRet);
				$(function(){
					if(pos == 'tribuna'){
						$('#'+id).removeClass('loader');
						$('#'+id).addClass('hide');
					} else {
						$('#'+idPlayer+'_tribuna').removeClass('hide');
					}
				});
	    	}
	    },
	    error : function (richiesta,stato,errori) {
	    	alert("E' evvenuto un errore. Il stato della chiamata: "+stato);
	    }
	});
}

function resetFormazione(squadreId, urlSendPri, urlSendSec){
	$.ajax({
		type: "GET",
		url: urlSendPri+urlSendSec+"ajax/inform.php",
	    data:{reset: 1, squadreId: squadreId},
	    success : function (mRet) {
	    	if(mRet == 'error'){
	    		$('#'+id).removeClass('loader');
	    		$("#error_msg").addClass('ui-state-error');
	    		$("#error_msg").addClass('ui-corner-all');
	    		$("#error_msg").addClass('show');
	    		$("#error_msg").html('Giocatore non consentito nel modulo');
	    		$("#dialogError").dialog('open');
	    	} else {
	    		$('#formazione').html('');
				$('#formazione').html(mRet);
				
				$('#panchinaTable tr').each(function(){
					var id = $(this).attr('id');
					if(id != ''){
						$("#"+id).removeClass("hide");
					}
	    		});
	    	}
	    },
	    error : function (richiesta,stato,errori) {
	    	alert("E' evvenuto un errore. Il stato della chiamata: "+stato);
	    }
	});
}

function calcolaAuto(id, urlSendPri, urlSendSec){
	$('#dialogFormations').dialog("option", 'margin-top', '20px;');
	$('#dialogFormations').html(
			'<div id="calcFormAuto" style="display: block; margin-left: 240px;">'
				+'<div class="bold center" style="width: 300px; margin-left: -140px; padding-top: 20px;">Attendere il calcolo della formazione</div>'
			+'</div>');
	$('#calcFormAuto').addClass('loader');
	$.ajax({
		type: "GET",
		url: urlSendPri+urlSendSec+"ajax/informCalc.php",
	    data:{id: id},
	    success : function (mRet) {
	    	$('#calcFormAuto').removeClass('loader');
	    	$('#calcFormAuto').hide();
	    	
	    	$('#dialogFormations').html(mRet);
	    },
	    error : function (richiesta,stato,errori) {
	    	alert("E' evvenuto un errore. Il stato della chiamata: "+stato);
	    }
	});
}

function calculateButtonAuto(){
	$("#calculateButtonLoader").show();
	$("#insertCalcForm").hide();
}

$(function(){
	
	overOutButton('insertCalcForm');
	// Dialog			
	$('#dialogError').dialog({
		autoOpen: false,
		width: 300,
		height: 100,
		modal: true,
		draggable: false,
		position: ['top','center'],
		resizable: false
	});
	
	$('#dialogFormations').dialog({
		autoOpen: false,
		width: 550,
		height: 600,
		modal: true,
		draggable: false,
		position: ['top','center'],
		resizable: false
	});
});
