function crea_gruppo(){
document.getElementById('nome-gruppo-v').style.display = "none";
document.getElementById('desc-gruppo-v').style.display = "none";
var nome_g = document.getElementById('titolo').value;
var desc_g = document.getElementById('descrizione').value;
if(nome_g !== '' && desc_g !== ''){
document.form2.method = "post";
document.form2.action = "panel.php?module=crea_gruppo";
document.form2.target = "";
document.form2.enctype = "";
document.form2.submit();
}
else{
if(nome_g == ''){document.getElementById('nome-gruppo-v').style.display = "block";}
if(desc_g == ''){document.getElementById('desc-gruppo-v').style.display = "block";}
}
}
function aggiorna_gruppo(){
document.getElementById('nome-gruppo-v').style.display = "none";
document.getElementById('desc-gruppo-v').style.display = "none";
var nome_g = document.getElementById('titolo').value;
var desc_g = document.getElementById('descrizione').value;
if(nome_g !== '' && desc_g !== ''){
document.form2.method = "post";
document.form2.action = "panel.php?module=aggiorna_gruppo";
document.form2.target = "";
document.form2.enctype = "";
document.form2.submit();
}
else{
if(nome_g == ''){document.getElementById('nome-gruppo-v').style.display = "block";}
if(desc_g == ''){document.getElementById('desc-gruppo-v').style.display = "block";}
}
}
function lol_s(){ 
document.getElementById("error-upload").innerHTML = '<img alt="loading" align=center width="16" height="16" src="images/loading.gif" id="loading">';
document.form2.method = "post";
document.form2.action = "upload_process.php";
document.form2.target = "upload_frame";
document.form2.enctype = "multipart/form-data";
document.form2.submit();
init_s();
}
function init_s()
{
var myIFrame = document.getElementById('upload_frame');  
var contenuto = myIFrame.contentWindow.document.body.innerHTML;
if (contenuto !== '' && contenuto !== document.getElementById('nome-upload').value) {
if(contenuto == 'error1'){
document.getElementById("error-upload").innerHTML = '<img alt="cross" align=center src="images/cross1.png" width="16" height="16" id="cross"> Controlla l\'estensione';
}
else {
document.getElementById('nome-upload').value = contenuto;
document.getElementById("error-upload").innerHTML = '<img alt="tick" align=center  width="16" height="16"src="images/tick.png" id="tick">';
}
}
else { 

setTimeout("init_s()", 400);
return;
}
}

function lol_y(){ 
document.getElementById("error-upload").innerHTML = '<img alt="loading" align=center width="16" height="16" src="images/loading.gif" id="loading">';
document.form2.method = "post";
document.form2.action = "upload_processy.php";
document.form2.target = "upload_frame";
document.form2.enctype = "multipart/form-data";
document.form2.submit();
init_y();
}
function init_y()
{
var myIFrame = document.getElementById('upload_frame');  
var contenuto = myIFrame.contentWindow.document.body.innerHTML;
if (contenuto !== '' && contenuto !== document.getElementById('nome-upload').value) {
if(contenuto == 'error1'){
document.getElementById("error-upload").innerHTML = '<img alt="cross" align=center src="images/cross1.png" width="16" height="16" id="cross"> Controlla l\'estensione';
}
else {
document.getElementById('nome-upload').value = contenuto;
document.form2.method = "post";
document.form2.action = "panel.php?module=impostazioni_aggiorna";
document.form2.target = "";
document.form2.enctype = "";
document.getElementById("error-upload").innerHTML = '<img alt="tick" align=center  width="16" height="16"src="images/tick.png" id="tick">';
}
}
else { 

setTimeout("init_y()", 400);
return;
}
}
function rendi_inattiva_stanza(id_stanza){
document.getElementById('chat-input-'+id_stanza).disabled=true;

}
function open_drop_menu(){
document.getElementById('arrow-drop').className='tuo-account-2-hover';
document.getElementById('drop-menu-top').style.display = 'block';
}
function open_drop_menu_h(){
var display = document.getElementById('drop-menu-top').style.display;
if(display == 'block'){
document.getElementById('arrow-drop').className='tuo-account-2-hover';
document.getElementById('drop-menu-top').style.display = 'block';
}
}
function close_drop_menu(){
document.getElementById('arrow-drop').className='tuo-account-2';
document.getElementById('drop-menu-top').style.display = 'none';
}
function controlla_username(nome){
var check = eval("document.forms['registrazione']."+nome+".value");
var pars = "username="+escape(check);
new Ajax.Request('controlla-username.php',
{
method:'post',
parameters: pars,
onSuccess: function(data){
var risp = data.responseText || "no response text";
if(risp == 'ok') {
new Effect.Morph(nome,{
style:'border: 1px solid #b1ff9c',
duration:1.0
});
document.getElementById('check-user').innerHTML = '<img alt="s-tick" src="images/s-tick.png">';
document.getElementById('check-loading').innerHTML = 'Username valido';
} else {
new Effect.Morph(nome,{
style:'border: 1px solid #ff9292',
duration:1.0
});
document.getElementById('check-user').innerHTML = '<img alt="s-error" src="images/s-error.png">';
document.getElementById('check-loading').innerHTML = risp;
}

},
onLoading: function(){
document.getElementById('error-bar-username').style.display = 'block';
document.getElementById('check-loading').innerHTML = '<img alt="s-spinner" src="images/spinner-m.gif">';

},
onFailure: function(){ alert('Errore') }
});

}

function mostra_conferma_elimina(el, id){
var el = el+"-"+id;
var obj = document.getElementById('tol');
var element = document.getElementById(el);
var coords = {x: 0, y: 0};
while (element) {
coords.x += element.offsetLeft;
coords.y += element.offsetTop;
element = element.offsetParent;
}
obj.style.left = coords.x-90 + 'px';
obj.style.top = coords.y-65 + 'px';
document.getElementById('tol-inner').innerHTML = '<div class="sic">Sei sicuro?</div><div><a href="panel.php?module=elimina_messaggio&id='+id+'" class="confirm-b">Si</a> <a href="javascript:nascondi_conferma_elimina(\''+el+'\',\''+id+'\')" class="confirm-b">No</a></div>';
obj.style.display = 'block';
}

function mostra_conferma_elimina_2(el, id){
var el = el+"-"+id;
var obj = document.getElementById('tol');
var element = document.getElementById(el);
var coords = {x: 0, y: 0};
while (element) {
coords.x += element.offsetLeft;
coords.y += element.offsetTop;
element = element.offsetParent;
}
obj.style.left = coords.x-26 + 'px';
obj.style.top = coords.y-55 + 'px';
document.getElementById('tol-inner').innerHTML = '<div class="sic">Sei sicuro?</div><div><a href="panel.php?module=elimina_messaggio&id='+id+'" class="confirm-b">Si</a> <a href="javascript:nascondi_conferma_elimina(\''+el+'\',\''+id+'\')" class="confirm-b">No</a></div>';
obj.style.display = 'block';
}
function mostra_conferma_elimina_3(el, id){
var el = el+"-"+id;
var obj = document.getElementById('tol');
var element = document.getElementById(el);
var coords = {x: 0, y: 0};
while (element) {
coords.x += element.offsetLeft;
coords.y += element.offsetTop;
element = element.offsetParent;
}
obj.style.left = coords.x-90 + 'px';
obj.style.top = coords.y-55 + 'px';
document.getElementById('tol-inner').innerHTML = '<div class="sic">Sei sicuro?</div><div><a href="panel.php?module=elimina_richiesta&id='+id+'" class="confirm-b">Si</a> <a href="javascript:nascondi_conferma_elimina(\''+el+'\',\''+id+'\')" class="confirm-b">No</a></div>';
obj.style.display = 'block';
}


function nascondi_conferma_elimina(el, id){
var obj = document.getElementById('tol');
document.getElementById('tol-inner').innerHTML
obj.style.display = 'none';
}
function page(num){
document.getElementById('tol').style.display="none";
var pars = "page="+escape(num);
new Ajax.Request('page.php',
{
method:'get',
parameters: pars,
onSuccess: function(data){
var response = data.responseText || "no response text";
document.getElementById('div-messaggi').innerHTML = response;
},
onLoading: function(){

},
onFailure: function(){ alert('Errore') }
});


}
function page_i(num){

var pars = "page="+escape(num);
new Ajax.Request('page-i.php',
{
method:'get',
parameters: pars,
onSuccess: function(data){
var response = data.responseText || "no response text";
document.getElementById('messaggi-inviati-div').innerHTML = response;
},
onLoading: function(){

},
onFailure: function(){ alert('Errore') }
});


}
function page_r(num){

var pars = "page="+escape(num);
new Ajax.Request('page-richieste.php',
{
method:'get',
parameters: pars,
onSuccess: function(data){
var response = data.responseText || "no response text";
document.getElementById('div-richieste').innerHTML = response;
},
onLoading: function(){

},
onFailure: function(){ alert('Errore') }
});


}


function page_m(username_id, num){

var pars = "page="+escape(num)+"&username_id="+escape(username_id);
new Ajax.Request("http://"+document.domain+'/bitprofile/page-m.php',
{
method:'get',
parameters: pars,
onSuccess: function(data){
var response = data.responseText || "no response text";
document.getElementById('messaggi-brevi-content').innerHTML = response;
},
onLoading: function(){

},
onFailure: function(){ alert('Errore') }
});


}
function page_a(username_id, num){

var pars = "page="+escape(num)+"&username_id="+escape(username_id);
new Ajax.Request("http://"+document.domain+'/bitprofile/page-a.php',
{
method:'get',
parameters: pars,
onSuccess: function(data){
var response = data.responseText || "no response text";
document.getElementById('amici-content').innerHTML = response;
},
onLoading: function(){

},
onFailure: function(){ alert('Errore') }
});


}
function page_grup(grup_id, num){

var pars = "page="+escape(num)+"&gruppo_id="+escape(grup_id);
new Ajax.Request("http://"+document.domain+'/bitprofile/page-grup.php',
{
method:'get',
parameters: pars,
onSuccess: function(data){
var response = data.responseText || "no response text";
document.getElementById('iscritti-gruppo-content-content').innerHTML = response;
},
onLoading: function(){

},
onFailure: function(){ alert('Errore') }
});


}

function page_richieste(num){

var pars = "page="+escape(num);
new Ajax.Request('page-richieste.php',
{
method:'get',
parameters: pars,
onSuccess: function(data){
var response = data.responseText || "no response text";
document.getElementById('messaggi-inviati-div').innerHTML = response;
},
onLoading: function(){

},
onFailure: function(){ alert('Errore') }
});


}








function edita_campi(nome, numero){
/* elenco stringhe */
var campo2 = "invalue-"+numero;
var nome2 = nome;
var tick = "editing-tick-"+numero;
var loading = "status-loading-"+numero;
/* Fine elenco stringhe */
document.getElementById(tick).innerHTML = '<a href="javascript:aggiorna_campi(\''+nome+'\',\''+numero+'\')"><img src="images/tick.png" border=0></a>';
var contenuto2 = document.getElementById(campo2).innerHTML;
var nohtml = contenuto2.replace(/(<([^>]+)>)/ig,""); 
if(nohtml !== ''){
document.getElementById(campo2).innerHTML = '<input id="'+campo2+'-input" type="text" name="'+nome2+'" class="edita-campo" value="'+contenuto2+'"></input>';
}
}
function edita_idea(count, id){
campo2 = "idea-"+count;
var contenuto2 = document.getElementById(campo2).innerHTML;
var contenuto2 = contenuto2.replace(/(<([^>]+)>)/ig,""); 
document.getElementById(campo2).innerHTML = '<textarea id="'+campo2+'-input" name="idea-'+count+'" class="edita-idea" onkeyup="limite_dinamico(\''+campo2+'\', \''+count+'\');" value="'+contenuto2+'">'+contenuto2+'</textarea><div id="info-idea-'+count+'"></div>';
var tick = "tick-idea-"+count;
document.getElementById(tick).innerHTML = '<a href="javascript:aggiorna_idea(\''+id+'\',\''+count+'\')"><img src="images/tick.png" border=0></a>';

}
function aggiorna_idea(id, count){
var testo = document.getElementById('idea-'+count+'-input').value;
if(testo !== ''){
var testo2  = encodeURIComponent(testo);
var pars = "id="+escape(id)+"&testo="+testo2;
new Ajax.Request('edita-idea.php',
{
method:'post',
parameters: pars,
requestHeaders: {Accept: 'text/plain'},

onSuccess: function(data){
var response = data.responseText || "no response text";
document.getElementById('tick-idea-'+count).innerHTML = '';
document.getElementById('loader-idea-'+count).innerHTML = '';
document.getElementById('idea-'+count).innerHTML = testo;
},
onLoading: function(){
document.getElementById('loader-idea-'+count).innerHTML = '<img src="images/spinner-m.gif" width="16" height="16">';
},
onFailure: function(){ alert('Errore') }
});
}
}
"Content-Type","application/x-www-form-urlencoded; charset=UTF-8"
function submit_idea(){
var testo = document.getElementById('submit_idea').value;
var testo = encodeURIComponent(testo);
var pars = "testo="+testo;
new Ajax.Request('submit-idea.php',
{
method:'post',
parameters: pars,
requestHeaders: {Accept: 'text/plain'},
onSuccess: function(data){
var response = data.responseText || "no response text";
if(response == 'time'){ document.getElementById('loader-idea').innerHTML = '<img src="images/cross1.png" width="16" height="16">';
document.getElementById('error-idea').innerHTML ='Attendi 2 minuti per un nuovo messaggio';}
else if(response == 'vuoto'){
document.getElementById('loader-idea').innerHTML = '<img src="images/cross1.png" width="16" height="16">';
document.getElementById('error-idea').innerHTML ='Campo testo vuoto';}
else{
document.getElementById('loader-idea').innerHTML = '<img src="images/tick.png" width="16" height="16">';
aggiorna_idee();
}
},
onLoading: function(){
document.getElementById('error-idea').innerHTML = '';
document.getElementById('loader-idea').innerHTML = '<img src="images/spinner-m.gif" width="16" height="16">';
},
onFailure: function(){ alert('Errore') }
});
}
function aggiorna_idee(){

new Ajax.Request('elenco-idee.php',
{
method:'get',
parameters: '',
onSuccess: function(data){
var response = data.responseText || "no response text";
document.getElementById('elenco-idee').innerHTML = response;

},
onLoading: function(){
document.getElementById('elenco-idee').innerHTML = '<img src="images/loading.gif" width="16" height="16">';
},
onFailure: function(){ alert('Errore') }
});
}

function aggiorna_campi(valore, numero){
/* elenco stringhe */
var campo2 = "invalue-"+numero;
var tick = "editing-tick-"+numero;
var loading = "status-loading-"+numero;
/* Fine elenco stringhe */
var nuovo_c = document.getElementById(campo2+'-input').value;
var nuovo_c_post = encodeURIComponent(nuovo_c);
var pars = "id="+escape(valore)+"&valore="+nuovo_c_post;
if(nuovo_c !==''){
new Ajax.Request('modifica-value.php',
{
method:'post',
parameters: pars,
requestHeaders: {Accept: 'text/plain'},

onSuccess: function(data){
var response = data.responseText || "no response text";
document.getElementById(loading).innerHTML = '';
document.getElementById(tick).innerHTML = '';

document.getElementById(campo2).innerHTML = nuovo_c;
},
onLoading: function(){
document.getElementById(loading).innerHTML = '<img src="images/spinner-m.gif" width="16" height="16">';
},
onFailure: function(){ alert('Errore') }
});
}
}
function cancella_campi(nome, id){
var tr = "intr-"+nome;
var pars = "id="+escape(id);
new Ajax.Request('cancella-value.php',
{
method:'post',
parameters: pars,
onSuccess: function(data){
var response = data.responseText || "no response text";
document.getElementById(tr).remove();
},
onLoading: function(){
},
onFailure: function(){ alert('Errore') }
});

}
function cancella_idea(nome, numero){
var tr = "idea-n-"+nome;
var pars = "id="+escape(numero);
new Ajax.Request('cancella-idea.php',
{
method:'post',
parameters: pars,
onSuccess: function(data){
var response = data.responseText || "no response text";
aggiorna_idee();
},
onLoading: function(){
},
onFailure: function(){ alert('Errore') }
});
}
function controlla_campi(nome){
var check = eval("document.forms['registrazione']."+nome+".value");

if(check==''){
new Effect.Morph(nome,{
style:'border: 1px solid #ff9292',
duration:1.0
});
}
else {
new Effect.Morph(nome,{
style:'border: 1px solid #b1ff9c',
duration:1.0
});
}
}
function controlla_password(nome){
var check = eval("document.forms['registrazione']."+nome+".value");

if(check!==''){
if(check.length > 4){
document.getElementById('error-bar-password').style.display = 'none';
document.getElementById('check-password').innerHTML = '';
document.getElementById('check-password-loading').innerHTML = '';
new Effect.Morph(nome,{
style:'border: 1px solid #b1ff9c',
duration:1.0
});
}
else{
new Effect.Morph(nome,{
style:'border: 1px solid #ff9292',
duration:1.0
});
document.getElementById('error-bar-password').style.display = 'block';
document.getElementById('check-password').innerHTML = '<img alt="s-error" src="images/s-error.png">';
document.getElementById('check-password-loading').innerHTML = 'Deve essere maggiore di 4 caratteri.';
}}
else {
document.getElementById('error-bar-password').style.display = 'block';
document.getElementById('check-password').innerHTML = '<img alt="s-error" src="images/s-error.png">';
document.getElementById('check-password-loading').innerHTML = 'Campo vuoto';
new Effect.Morph(nome,{
style:'border: 1px solid #ff9292',
duration:1.0
});
}
}
function controlla_form(){
var password = document.getElementById('password').value;
var nome = document.getElementById('nome').value;
var cognome = document.getElementById('cognome').value;
var email = document.getElementById('email').value;
var username = document.getElementById('username').value;

if(nome !== '' && cognome !=='' && email !=='' && password !=='' && username !=='' && password.length > 4 && username.length > 3){
document.forms['registrazione'].submit();
} else { 
new Effect.Appear('error'); }

controlla_campi('nome');
controlla_campi('cognome');
controlla_password('password');
controlla_campi('email');
controlla_username('username');

}
function we(){
document.getElementById('click').innerHTML = '<a href="#" style="text-decoration:none" onClick="aggiungi()"><span style="padding: 4px;color:#fff;background-color:#b8b8b8;">Aggiungi</span></a>';
}

function we_e(el){

document.getElementById('click').innerHTML = '<a href="#" style="text-decoration:none" onClick="aggiungi()"><span style="padding: 4px;color:#fff;background-color:#b8b8b8;">Aggiungi</span></a>';
document.getElementById(el).remove();
}

function aggiorna_cp(fine, fine_d){
value = document.getElementById('campo-agg-'+fine).value;
document.getElementById(fine_d).innerHTML= fine+' <input class="campo-ex" type="text" id="campo-agg-'+fine+'" name="'+fine+'" value="'+value+'" onkeyup="aggiorna_cp(\''+fine+'\', \''+fine_d+'\')"> <a href="javascript:elimina(\''+fine_d+'\')"><img src="images/cross.png" border="0"></a>';
document.getElementById('campo-agg-'+fine).focus();
setCursorAtEnd('campo-agg-'+fine);
}
function setCursorAtEnd(sTextboxID) {
    var oTextbox = document.all.item(sTextboxID);
    if (oTextbox .createTextRange) {
        var r = (oTextbox.createTextRange());
        r.moveStart('character', (oTextbox.value.length));
        r.collapse();
        r.select();
    }
}
var arrInput = new Array(0);
var arrInputValue = new Array(0);
var arrTipo = new Array(0);

function display(tipo){
document.getElementById('lista-testo').innerHTML='';
 for (intI=0;intI<arrInput.length;intI++) {
    document.getElementById('lista-testo').innerHTML+=createInput(arrInput[intI], arrInputValue[intI], intI, arrTipo[intI]);
}
}
function elimina(el, id, n){
if (arrInput.length > 0) { 
     arrInput.splice(id, 1); 
     arrInputValue.splice(id, 1);
	 arrTipo.splice(id, 1);
  }

var tipo ="default";
display(tipo);
}
function arrayIndexOf(array, search) {
var esiste = 0;
	var indice; //contatore
	for (indice in array) {
		if (array[indice] == search){var esiste= 1;}
	}	
	return esiste;
}
function cerca_array(array, search) {
var indice; //contatore
	for (indice in array) {
		if (array[indice] == search)
			return indice;
	}	
	return indice;

}
function aggiungi2(){
var fine = document.getElementById('campo').value;
var fine = fine.replace(/(<([^>]+)>)/ig,""); 
var fine_d = fine+'_el';
if(document.getElementById(fine_d) == null && fine != ''){
var news = '<div style="padding:4px;" id="'+fine_d+'">'+fine+' <input class="campo-ex" type="text" id="campo-agg-'+fine+'" name="'+fine+'" value="" onkeyup="aggiorna_cp(\''+fine+'\', \''+fine_d+'\')"> <a href="javascript:elimina(\''+fine_d+'\')"><img src="images/cross.png" border="0"></a></div>';
var past = document.getElementById('lista-testo').innerHTML;
document.getElementById('lista-testo').innerHTML = past+news;
}
}
function aggiungi_predefiniti(campo){
var controllo_presenza = arrayIndexOf(arrInput, campo);
if(controllo_presenza == 0){
arrInput.push(campo);
arrInputValue.push("");
arrTipo.push("default");
var tipo = 'default';
display(tipo);
}
}
function aggiungi_entertainment(campo){
var controllo_presenza = arrayIndexOf(arrInput, campo);
if(controllo_presenza == 0){
arrInput.push(campo);
arrInputValue.push("");
arrTipo.push("entertainment");
var tipo = 'entertainment';
display(tipo);
}
}
function aggiungi_forum(campo){
campo = document.getElementById('forum-1').value;
var controllo_presenza = arrayIndexOf(arrInput, campo);
if(controllo_presenza == 0){
arrInput.push(campo);
arrInputValue.push("");
arrTipo.push("forum");
var tipo = 'forum';
display(tipo);
}
}
function aggiungi(){
var fine = document.getElementById('campo').value;
var controllo_presenza = arrayIndexOf(arrInput, fine);
if(controllo_presenza == 0){
arrInput.push(fine);
arrInputValue.push("");
arrTipo.push("default");

var tipo='default';
display(tipo);
}
}
function saveValue(intId,strValue) {
  arrInputValue[intId]=strValue;
 
} 
function createInput(id,value,intI, tipo) {
if(intI == arrInput.length){
var fine = document.getElementById('campo').value;
var fine = fine.replace('_', ' ', fine);
var fine = fine.replace(' ', '-', fine);
}
else {
var fine = id;
}
var fine = fine.replace(/(<([^>]+)>)/ig,""); 
var fine_d = fine+'_el';
if(document.getElementById(fine_d) == null && fine != '' && tipo == 'default'){
  return '<div style="padding:4px;" id="'+fine_d+'">'+fine+' <input class="campo-ex" type="text" id="campo-agg-'+fine+'" name="'+fine+'" value="'+value+'" onkeyup="javascript:saveValue(\''+intI+'\', this.value)"> <a href="javascript:elimina(\''+fine_d+'\', \''+intI+'\', \''+fine+'\')"><img src="images/cross.png" border="0"></a></div>';
} 
else if(document.getElementById(fine_d) == null && fine != '' && tipo == 'forum'){
  return '<div style="padding:4px;" id="'+fine_d+'">'+fine+' <input class="campo-ex" type="text" id="campo-agg-'+fine+'" name="forum-'+fine+'" value="'+value+'" onkeyup="javascript:saveValue(\''+intI+'\', this.value)"> <a href="javascript:elimina(\''+fine_d+'\', \''+intI+'\', \''+fine +'\')"><img src="images/cross.png" border="0"></a></div>';
}
else if(document.getElementById(fine_d) == null && fine != '' && tipo == 'entertainment'){
  return '<div style="padding:4px;" id="'+fine_d+'">'+fine+' <input class="campo-ex" type="text" id="campo-agg-'+fine+'" name="entertainment-'+fine+'" value="'+value+'" onkeyup="javascript:saveValue(\''+intI+'\', this.value)"> <a href="javascript:elimina(\''+fine_d+'\', \''+intI+'\', \''+fine +'\')"><img src="images/cross.png" border="0"></a></div>';
}
  else { return '';}
}
function elimina_sfondo(){
var pars ="";
new Ajax.Request('elimina-sfondo.php',
{
method:'get',
parameters: pars,
onSuccess: function(data){
var response = data.responseText || "no response text";
document.getElementById("sfondo-attuale-img").src = "images/user-intro.png";
document.getElementById("elimina-s-c").innerHTML ="";
},
onLoading: function(){
document.getElementById("sfondo-attuale-img").src = "images/loading.gif";

},
onFailure: function(){ alert('Errore') }
});

}






