function editComment(idCommento) {
//	$('delete-commento-'+idCommento).update("<textarea  id=\"comment-text-"+idCommento+"\">"+$('delete-commento-'+idCommento).innerHTML.stripTags().strip()+"</textarea><input type=\"button\" value=\"Modifica Commento\" onclick=\"doEditComment("+idCommento+")\" />");
	$('delete-commento-'+idCommento).update("<textarea  id=\"comment-text-"+idCommento+"\">"+$('delete-commento-orig-'+idCommento).innerHTML.strip()+"</textarea><input type=\"button\" value=\"Modifica Commento\" onclick=\"doEditComment("+idCommento+")\" />");
	$('comment-text-'+idCommento).addClassName('edit-comment');
}

function doEditComment(idCommento) {
	newTxtCommento = $('comment-text-'+idCommento).value;
	new Ajax.Request('/editCommento.php',{
		method:'post',
		onSuccess: function(transport) {
				window.alert('Commento Aggiornato');
				$('delete-commento-'+idCommento).update(newTxtCommento);
		},
		parameters: {
			id: idCommento,
			txtCommento: newTxtCommento
		}
	});
}

function delComment(idCommento) {
	if((motivazione = window.prompt('Specifica una motivazione per l\'eliminazione o annulla.')) != null)
	{
		new Ajax.Request('/delCommento.php',{
			method:'post',
			onSuccess: function(transport) {
					window.alert('Commento Eliminato');
					$('delete-commento-'+idCommento).update("Il commento &egrave; stato eliminato con motivazione: "+motivazione);
			},
			parameters: {
				id: idCommento,
				motivo: motivazione
			}
		});
	}
}

function removeComment(idCommento) {
	if(confirm("Sei sicuro di voler rimuovere il commento?"))
	{
		new Ajax.Request('/delCommento.php',{
			method:'post',
			onSuccess: function(transport) {
					window.alert('Commento Eliminato');
					$('delete-commento-'+idCommento).update("Il commento &egrave; stato rimosso");
			},
			parameters: {
				id: idCommento,
				del: '1'
			}
		});
	}
}

function removeVoto(idVoto) {
	if(confirm("Sei sicuro di voler rimuovere il voto?"))
	{
		new Ajax.Request('/delVoto.php',{
			method:'post',
			onSuccess: function(transport) {
					window.alert('Voto Eliminato');
					$('delete-voto-'+idVoto).update("Il Voto &egrave; stato rimosso");
			},
			parameters: {
				id: idVoto
			}
		});
	}
}

function compraOggetto(objID) {
	if(window.confirm('Sara\' inviata una mail di conferma dell\'acquisto,e l\'oggetto verra\' rimosso dal mercatino,confermi l\'azione?'))
	{
		new Ajax.Request('/compraOggetto.php',{
			method:'post',
			onSuccess: function(transport) {
					window.alert('Hai acquistato questo oggetto,ricorda che a termine della transazione potrai assegnare un feedback al venditore.');
					$('compra-oggetto').update("Hai acquistato l'oggetto");
			},
			parameters: {
				id: objID
			},
			asynchronous:false
		});
	}
}

function addGiocoPreferito(event) {
	new Ajax.Request('/addGiocoPreferito.php',{
		method:'post',
		onSuccess: function(transport) {
			if(transport.responseText.length == 0)
			{
				window.alert('Hai aggiunto questo gioco ai tuoi preferiti!');
				$('container-add-preferito').update("Hai aggiunto il gioco ai preferiti");
				Event.stop(event);
			}
		},
		parameters: {
			gameID: $('gioco-id').value,
			piattaforma: $('piattaforma-preferita').value
		},
		asynchronous:false
	});

}

function delGiocoPreferito(event) {
	new Ajax.Request('/addGiocoPreferito.php',{
		method:'post',
		onSuccess: function(transport) {
			if(transport.responseText.length == 0)
			{
				window.alert('Hai rimosso questo gioco dai tuoi preferiti!');
				$('container-del-preferito').update("Hai rimosso il gioco dai preferiti");
				Event.stop(event);
			}
		},
		parameters: {
			del: $('id-preferito').value
		},
		asynchronous:false
	});

}

function segnalaVideo(event) {
	new Ajax.Request('/segnalaVideo.php',{
		method:'post',
		onSuccess: function(transport) {
			if(transport.responseText.length == 0)
			{
				window.alert('Grazie per la segnalazione,il video verra\' preso in visione quanto prima per permetterne l\'inserimento');
				Event.stop(event);
			}
		},
		parameters: {
			videoURL: $('url-video').value
		},
		asynchronous:false
	});

}

function checkRegistrazione() {


	
	if($('username').value == '')
	{
		alertThis('username');
		return false;
	}
	else nascondi('username');
	if($('id_game').value == '' || $('console_game').value == '')
	{
		alertThis('id_game');
		return false;
	}
	else nascondi('id_game');
	if($('password').value == '')
	{
		alertThis('password');
		return false;
	}
	else nascondi('password');
	if($('cpassword').value != $('password').value)
	{
		alertThis('cpassword');
		return false;
	}
	else nascondi('cpassword');
	if($('email').value == '')
	{
		alertThis('email');
		return false;
	}
	else nascondi('email');
	if($('email').value != $('cemail').value)
	{
		alertThis('cemail');
		return false;
	}
	else nascondi('cemail');
	if($('field5').value == '')
	{
		alertThis('field5');
		return false;
	}
	else nascondi('field5');
	if($('field6').value == '')
	{
		alertThis('field6');
		return false;
	}
	else nascondi('field6');
	if($('birthday_month').value == '' || $('birthday_year').value == '' || $('birthday_day').value == '')
	{
		alertThis('nascita');
		return false;
	}
	else nascondi('nascita');
	if($('regione').value == '')
	{
		alertThis('regione');
		return false;
	}
	else nascondi('regione');
	
	if(document.getElementById('f_privacy').checked == false)
	{	
		alert("Devi accettare le condizioni della privacy per proseguire")
		return false;
	}
	

}

function alertThis(id_o) {
		new Effect.Highlight(id_o,{startcolor: '#ff0000',endcolor:'#ffcccc'});
		$(id_o+'_error').appear();
}
function nascondi(id_o) {
	$(id_o+'_error').style.display = 'none';
}

function sfidaUtente(userID,sfidaID) {
	if(window.confirm('Confermi la sfida?'))
	{
		new Ajax.Request('/sfidaUtente.php',{
			method:'get',
			onSuccess: function(transport) {
				alert('Sono state inviate due mail di riepilogo a te e all\'utente sfidato per la sfida');
			},
			parameters: {
				uid: userID,
				sid: sfidaID
			}
		});
		$('challenge_'+sfidaID).update('<div style="color:#666;">ACCETTATA</div>');
	}
	return false;
}

function checkGameID(event) {
	new Ajax.Request('/checkGameID.php',{
		method:'get',
		onSuccess: function(transport) {
			if(transport.responseText.length == 0)
			{
				alert('Devi inserire un GamerID per la piattaforma selezionata prima di poter inserire sfide');
				Event.stop(event);
			}
		},
		parameters: {
			piattaforma: $('piattaforma').value
		},
		asynchronous:false
	});
}

function updateStatus() {
	string = '<form action="" method="post">Testo: <input type="text" name="status" style="width:70%;" />';
	string += '<span id="allegato" style="display:none">';
	string += '<br/><span id="titolo_allegato"></span>';
	string += '<input type="hidden" id="tipo_allegato" name="tipo_allegato" value="0"/>';
	string += '<input type="text" id="link_allegato" name="link_allegato" style="width:60%;"/>';
	string += '</span><input type="submit" name="update_status" value="Invia" /></form>';

	$('status-c').update(string);
}

function showAllegato(tipo) {
	updateStatus();
	jqcc("#allegato").show();
	if (tipo == 'foto') {
		$('titolo_allegato').update("Link della foto: ");	
		jqcc('#tipo_allegato').val('1');
	} else {
		$('titolo_allegato').update("Link del video: ");			
		jqcc('#tipo_allegato').val('2');
	}
}


function aggiornaSubCat() {
	new Ajax.Updater('sottocategoria', '/updateSottoCategorie.php',{
		method: 'get',
		parameters: {
				id_categoria: $('categoria').value
		},
		asynchronous:false
	});
}

function makeStelle(percent) {
	$('stelle-y').style.width = percent+"%";
}
function votaUtente(voto,userID) {
	new Ajax.Request('/votaUtente.php',{
		method: 'get',
		onSuccess: function (transport) {
			$('vote-wrap').update("Il voto &egrave; stato inoltrato");
		},
		parameters: {
			votazione: voto,
			frase: $('votazione-frasi').value,
			uid: userID, method: 'ajax'
		}
	});
}
function assegnaFeed(feed,objID) {
	new Ajax.Request('/feedUtente.php',{
		method: 'post',
		onSuccess: function (transport) {
			$('feed-wrap').update("Il feedback &egrave; stato inoltrato");
		},
		parameters: {
			feedValue: feed,
			feedComment: $('commento-feed').value,
			idObj: objID,
			method: 'ajax'
		}
	});
}

function assegnaFeed2(feed,objID) {
	new Ajax.Request('/feedUtente.php',{
		method: 'post',
		onSuccess: function (transport) {
			$('feed-wrap'+objID).update("Il feedback &egrave; stato inoltrato");
		},
		parameters: {
			feedValue: feed,
			feedComment: $('commento-feed'+objID).value,
			idObj: objID,
			method: 'ajax'
		}
	});
}


function checkMulti(multi) {
	if(multi == 'multi')
		$('platform').style.display = 'block';
	else
		$('platform').style.display = 'none';
}
function votaGioco(voto,gameID) {

	if($('commento').value == '') {
		alert('Il commento è obbligatorio.');
		return;
	}
	
	if(window.confirm("Controlla il voto e conferma\nIl tuo voto: "+voto))
		new Ajax.Request('/votaGioco.php',{
			method: 'get',
			onSuccess: function (transport) {
				$('vote-wrap').update("Il voto &egrave; stato inoltrato");
			},
			parameters: {
				votazione: voto,
				componente: $('votazione-what').value,
				piattaforma: $('piattaforma').value,
				commento: $('commento').value,
				gid: gameID,
				method: 'ajax'
			}
		});
}
function updateElencoNews() {
	new Ajax.Updater('container-news-home', '/updateElencoNews.php',{
		parameters: {
				k: $('txt-box-news').value,
				categoria: $('categoria-box-news').value,
				gioco: $('gioco-box-news').value
		},
		asynchronous:false
	});
}
function aggiornaMatch() {
	new Ajax.Updater('contenitore-match', '/updateElencoMatch.php',{
		method: 'get',
		parameters: {
				id_game: $('gioco-match').value,
				quando: $('quando-match').value
		},
		asynchronous:false
	});
}



function get_tipo_value(form)
{
for (var i=0; i < form.tipo.length; i++)
   {
   if (form.tipo[i].checked)
      {
      return form.tipo[i].value;
      }
   }
}
function get_sesso_value(form)
{
for (var i=0; i < form.sesso.length; i++)
   {
   if (form.sesso[i].checked)
      {
      return form.sesso[i].value;
      }
   }
}


function updateGamingMarketPage(str) {
	// trovo la pagina
	// ottengo il numero di pagina
	//alert(str);
	var inizio = str.indexOf('/p');
	var fine = str.indexOf('?gioco');
	var pagina = str.substring(inizio+2,fine);
	updateGamingMarket(pagina);
}


function updateGamingMarket(numpagina) {
	var tipo = get_tipo_value(document.getElementById('gm_form'));
	var sesso = get_sesso_value(document.getElementById('gm_form'));
	if (!numpagina) numpagina =1;
	new Ajax.Updater('gamingmarket-risultati', '/lista-gamingmarket.php',{
		method: 'get',
		parameters: {
				gioco: $('gioco').value,
				tipo: tipo,
				livello_gioco: $('livello_gioco').value,
				nickname: $('nickname').value,
				piattaforma: $('piattaforma').value,
				dispo_tempo: $('dispo_tempo').value,
				nome: $('nome').value,
				regione: $('regione').value,
				anni_exp: $('anni_exp').value,
				eta: $('eta').value,
				sesso: sesso,
				numpagina: numpagina,
				close: 'close'
				
		},
		asynchronous:false
	});
	facebox = new Facebox();
}

function inviaMessaggioVeloce(id_destinatario) {
	bDoNotClose = true;
	new Ajax.Updater('invia-messaggio', '/pop-messaggio-veloce.php?userid='+id_destinatario,{
		method: 'post',
		parameters: {
				messaggio: $('messaggio').value
				
		},
		asynchronous:false
	});
	setTimeout("resetClosureFacebox()", 1000);
	
}
function resetClosureFacebox() {
	bDoNotClose = false;	
}


function inviaMessaggioMultiplo() {
	if($('titolo').value == '')
	{
		alert('Devi inserire un titolo');
		return;
	}
	
	if($('messaggio').value == '')
	{
		alert('Devi inserire un messaggio');
		return;
	}
	
	
	tlist2.update(); 
	if ($F('facebook-demo') == '') {
		alert("Seleziona almeno un destinatario");
	}
	
	$('destinatari').value = $F('facebook-demo');
	
	$('form_messaggio').submit();
}

function inviaMessaggioAssistenza() {
	if($('titolo').value == '')
	{
		alert('Devi inserire un titolo');
		return;
	}
	
	if($('messaggio').value == '')
	{
		alert('Devi inserire un messaggio');
		return;
	}
	
	$('form_messaggio').submit();
}


function votaSfida(voto,sfidaID,sfidanteID) {


		new Ajax.Request('/vota-sfida.php',{
			method: 'get',
			onSuccess: function (transport) {
				$('vote-wrap').update("Il voto &egrave; stato inoltrato");
			},
			parameters: {
				votazione: voto,
				id: sfidaID,
				user: sfidanteID,
				method: 'ajax'
			}
		});
}


function sendMipiace(tipo,objID,statoAttuale) {

	new Ajax.Request('/vota-mipiace.php',{
		method: 'get',
		onSuccess: function (transport) {
			if (statoAttuale == 0)
				$('vote-wrap').update("Hai aggiunto il tuo 'mi piace'");
			else 
				$('vote-wrap').update("Hai eliminato il tuo 'mi piace'");
				
		},
		parameters: {
			tipo: tipo,
			id_obj: objID,
			statoAttuale: statoAttuale,
			method: 'ajax'
		}
	});
}
function sendMipiace2(tipo,objID,statoAttuale,titolo) {
	new Ajax.Request('/vota-mipiace.php',{
		method: 'get',
		onSuccess: function (transport) {
			if (statoAttuale == 0)
				$('vote-wrap').update("Hai aggiunto il tuo 'mi piace'");
			else 
				$('vote-wrap').update("Hai eliminato il tuo 'mi piace'");
				
		},
		parameters: {
			tipo: tipo,
			id_obj: objID,
			titolo: titolo,
			statoAttuale: statoAttuale,
			method: 'ajax'
		}
	});
}

function sendCondividi(tipo,objID) {

	new Ajax.Request('/vota-mipiace.php',{
		method: 'get',
		onSuccess: function (transport) {
				$('condividi-wrap').update("Hai condiviso la news");				
		},
		parameters: {
			tipo: tipo,
			id_obj: objID,
			method: 'ajax'
		}
	});
}
function sendCondividi2(tipo,objID,titolo) {
	new Ajax.Request('/vota-mipiace.php',{
		method: 'get',
		onSuccess: function (transport) {
			$('condividi-wrap').update("Hai condiviso la news");				
				
		},
		parameters: {
			tipo: tipo,
			id_obj: objID,
			titolo: titolo,
			method: 'ajax'
		}
	});
}


function sendPartecipa(tipo,objID,statoAttuale) {


	new Ajax.Request('/vota-mipiace.php',{
		method: 'get',
		onSuccess: function (transport) {
			if (statoAttuale == 0)
				$('partecipa-wrap').update("Hai aggiunto il tuo 'parteciperò'");
			else 
				$('partecipa-wrap').update("Hai eliminato il tuo 'parteciperò'");
				
		},
		parameters: {
			tipo: tipo,
			id_obj: objID,
			statoAttuale: statoAttuale,
			method: 'ajax'
		}
	});
}



function youtubeFetchData( tempvar )
{
  var videoid = '';
  //var tempvar = jqcc( '#youtubeDataFetcherInput' ).attr( 'value' );
  if ( /^https?\:\/\/.+/i.test( tempvar ) )
  {
    tempvar = /[\?\&]v=([^\?\&]+)/.exec( tempvar );
    if ( ! tempvar )
    {
      alert( 'YouTube video URL has a problem!' );
      return;
    }
    videoid = tempvar[ 1 ];
  }
  else
  {
    if ( /^[A-Za-z0-9_\-]{8,32}$/.test( tempvar ) == false )
    {
      alert( 'YouTube video ID has a problem!' );
      return;
    }
    videoid = tempvar;
  }
  alert (videoid);
  jqcc.getScript( 'http://gdata.youtube.com/feeds/api/videos/' + encodeURIComponent( videoid ) + '?v=2&alt=json-in-script&callback=youtubeFetchDataCallback' );
}
function youtubeFetchDataCallback( data )
{
	alert(www);
  var s = '';
  s += '<img src="' + data.entry[ "media$group" ][ "media$thumbnail" ][ 0 ].url + '" width="' + data.entry[ "media$group" ][ "media$thumbnail" ][ 0 ].width + '" height="' + data.entry[ "media$group" ][ "media$thumbnail" ][ 0 ].height + '" alt="Default Thumbnail" align="right"/>';
  s += '<b>Title:</b> ' + data.entry[ "title" ].$t + '<br/>';
  s += '<b>Author:</b> ' + data.entry[ "author" ][ 0 ].name.$t + '<br/>';
  s += '<b>Published:</b> ' + new Date( data.entry[ "published" ].$t.substr( 0, 4 ), data.entry[ "published" ].$t.substr( 5, 2 ) - 1, data.entry[ "published" ].$t.substr( 8, 2 ) ).toLocaleDateString( ) + '<br/>';
  s += '<b>Duration:</b> ' + Math.floor( data.entry[ "media$group" ][ "yt$duration" ].seconds / 60 ) + ':' + ( data.entry[ "media$group" ][ "yt$duration" ].seconds % 60 ) + ' (' + data.entry[ "media$group" ][ "yt$duration" ].seconds + ' seconds)<br/>';
  s += '<b>Rating:</b> ' + new Number( data.entry[ "gd$rating" ].average ).toFixed( 1 ) + ' out of ' + data.entry[ "gd$rating" ].max + '; ' + data.entry[ "gd$rating" ].numRaters + ' rating(s)' + '<br/>';
  s += '<b>Statistics:</b> ' + data.entry[ "yt$statistics" ].favoriteCount + ' favorite(s); ' + data.entry[ "yt$statistics" ].viewCount + ' view(s)' + '<br/>';
  s += '<br/>' + data.entry[ "media$group" ][ "media$description" ].$t.replace( /\n/g, '<br/>' ) + '<br/>';
  s += '<br/><a href="' + data.entry[ "media$group" ][ "media$player" ].url + '" target="_blank">Watch on YouTube</a>';
  jqcc( '#youtubeDataFetcherOutput' ).html( s );
  alert(s);
}



function businessNuovoTopevent() {
	
	if($('nome').value == ''
		|| $('dominio').value == ''
		|| $('contatto_nome').value == ''
		|| $('contatto_cognome').value == ''
		|| $('contatto_email').value == ''
		|| $('contatto_telefono').value == ''
		|| $('messaggio').value == ''
	)
	{
		alert('Devi inserire tutti i campi');
		return;
	}
	$('fotmtopevent').submit();
}

function businessBanner(tipo) {
	if($('nome').value == '')
	{
		alert('Devi inserire tutti i campi');
		return;
	}
	jqcc('#invia').val(tipo);
	if (jqcc('#id').val() == '')
		jqcc('#id').val('0'); 

	$('formbanner').submit();
}