function scriviTendina(id,data)
{
	for(var i=0; i<data.length; i++)
		$(id).insert(new Element('option',{'value' : data[i].value}).update(data[i].text));
}


function scriviresult(transport){

	var json = transport.responseJSON;
	$(json.idres).innerHTML = "";
	$(json.idres).innerHTML = json.text;
}
function alertresult(transport){

	var json = transport.responseJSON;
	
	alert(json.text);
}

function messaggio(transport){
	var json = transport.responseJSON;
	
}


function compramas2(id)
{
	var options = {
        parameters : 'id='+id,
        onSuccess  : messaggio
    };
    new Ajax.Request('mascotte/async/compramasc.php', options);
}

function mostramascotte(id){
	var options = {
        parameters : 'action=detail&id='+id,
        onSuccess  : scriviresult
    };
    new Ajax.Request('mascotte/execute.php', options);
	
}

function startcombat(p1,p2,tipo){
	
	var options = {
        parameters : 'action=combat&id1='+p1+'&id2='+p2+'&tipo='+tipo,
        onSuccess  : messaggio
    };
    new Ajax.Request('mascotte/execute.php', options);	
	
}
function heal(type){
	if(confirm("Curare la mascotte?")){
	var options = {
        parameters : 'action=heal&type='+type,
        onSuccess  : alertresult
    };
    new Ajax.Request('mascotte/execute.php', options);	
	}
}

function turncombat(idcom,tipo,dmgbase,defbase){
	var options = {
        parameters : 'action=turn&idcom='+idcom
        +'&dmgbase='+dmgbase
        +'&defbase='+defbase
        +'&tipo='+tipo,
        
        
        onSuccess  : scriviresult
    };
    new Ajax.Request('mascotte/execute.php', options);	
	
}

function addstat(stat,id){
	var val =$('mas_statpt').innerHTML
	$('mas_statpt').innerHTML = val-1;
	if((val-1)<=0){
		location.reload(true);
	}
	var options = {
        parameters : 'action=stat&stat='+stat+'&id='+id,
        onSuccess  : scriviresult
    };
    new Ajax.Request('mascotte/execute.php', options);		
}

// Mostra o nasconde un elemento
function ShowHide(id){
elem = document.getElementById(id);
if(elem){
  if(elem.style.display == 'none')
    elem.style.display = 'block';
   else
    elem.style.display = 'none';    
}
return;
}
