var language = "it";


function handleEnter(inField, e, fun) {
    var charCode;
    
    if(e && e.which){
        charCode = e.which;
    }else if(window.event){
        e = window.event;
        charCode = e.keyCode;
    }

    if(charCode == 13) {
        login();
    }
}

function replaceT(obj){
var newO=document.createElement('input');
newO.setAttribute('type','password');
newO.setAttribute('name',obj.getAttribute('name'));
newO.setAttribute('id',obj.getAttribute('id'));
newO.setAttribute('style',obj.getAttribute('style'));
newO.setAttribute('size',obj.getAttribute('size'));
newO.setAttribute('onkeypress',obj.getAttribute('onkeypress'));
obj.parentNode.replaceChild(newO,obj);
newO.focus();
} 

function handleEnterRicerca_Home(inField, e, fun) {
    var charCode;
    
    if(e && e.which){
        charCode = e.which;
    }else if(window.event){
        e = window.event;
        charCode = e.keyCode;
    }

    if(charCode == 13) {
     ricerca_home();
    }
}


function handleEnterRicercaEnter(inField, e, fun) {
    var charCode;
    
    if(e && e.which){
        charCode = e.which;
    }else if(window.event){
        e = window.event;
        charCode = e.keyCode;
    }

    if(charCode == 13) {
     ricerca();
    }
}

function utf8_encode ( argString ) {


    var string = (argString+''); 
    var utftext = "";
    var start, end;
    var stringl = 0;
    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;

        if (c1 < 128) {
            end++;
        } else if (c1 > 127 && c1 < 2048) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc !== null) {
            if (end > start) {
                utftext += string.substring(start, end);
            }
            utftext += enc;
            start = end = n+1;
        }
    }

    if (end > start) {
        utftext += string.substring(start, string.length);
    }

    return utftext;
}

function trim(txt)
{
return txt.replace(/\s+$|^\s+/g,"");
}

    function ChangeColor(tableRow, highLight)
    {
    if (highLight)
    {
      tableRow.style.backgroundColor = 'yellow';
    }
    else
    {
      tableRow.style.backgroundColor = 'white';
    }
  }

  function DoNav(theUrl)
  {
  document.location.href = theUrl;
  }


  
  function hides(target) {
    var e = document.getElementById(target);
    e.style.visibility = 'hidden';
    e.style.display = 'none';
}
  function shows(target) {
    var e = document.getElementById(target);
    e.style.visibility = 'visible';
    e.style.display = 'block';
}
  
function hide(target) {
    var e = document.getElementById(target);
    if (e.style.visibility == 'hidden') {
        e.style.visibility = 'visible';
        e.style.display = 'block';
    } else {
        e.style.visibility = 'hidden';
        e.style.display = 'none';
    }
}

function $(id) {
    return document.getElementById(id);
}


function get_value(id)
{
if(document.getElementById(id))
return document.getElementById(id).value;
else
return 0;
}

function set_value(id,newval)
{
document.getElementById(id).value = newval;
}

function $html(id) {
    return document.getElementById(id).innerHTML;
	
}

function $sethtml(id,html) {
    document.getElementById(id).innerHTML = html;
}

function $apphtml(id,html) {
    document.getElementById(id).innerHTML += html;
}

function $rapphtml(id,html) {
    document.getElementById(id).innerHTML = html + document.getElementById(id).innerHTML;
}
//Funzione per modificare il contenuto di un elemento nella pagina, accetta i parametri target e text
function set_text(target, text) {
    var e = document.getElementById(target);
    e.innerHTML = text;
}

//Funzione per modificare il contenuto di un elemento nella pagina, accetta i parametri target e text
function timed_set_text(target, text, delay) {
var tim = setTimeout('set_text("'+target+'","'+text+'")', 100);

}

//Funzione per prelevare il contenuto di un elemento
function get_text(target, text) {
    var e = document.getElementById(target);
   return e.innerHTML;
}

function $upd_div(content,elementid) {
    var e = document.getElementById(elementid);
    e.innerHTML = content;
}//function myHandler(content) {$sethtml('d1',content);}




function make_upd ()
{
var upd_div = function $upd_div(content,elementid) {var e = document.getElementById(elementid); e.innerHTML = content;};
return upd_div;
}

var htmlt = '<input type="submit" value="Ciao!">';





function getCookie(NameOfCookie)
{ if (document.cookie.length > 0)
{ begin = document.cookie.indexOf(NameOfCookie+"=");
if (begin != -1)
begin += NameOfCookie.length+1;
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end)); }
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function setCookie(NameOfCookie, value, expiremin)
{ var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiremin * 60 * 1000));
document.cookie = NameOfCookie + "=" + escape(value) +
((expiremin == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}



function delCookie (NameOfCookie)
{ if (getCookie(NameOfCookie)) {
document.cookie = NameOfCookie + "=" +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

}




function 
bgImage(id,image)
{
document.getElementById(id).style.backgroundImage = 'url('+image+')'; 
}
	
	
	
//GESTIONE DELL'EVENTO ENTER NEI CAMPI DELLE VARIE FORM........
function onEnter( evt, frm ) {
var keyCode = null;

if( evt.which ) {
keyCode = evt.which;
} else if( evt.keyCode ) {
keyCode = evt.keyCode;
}
if( 13 == keyCode ) {
frm.btnEnter.click();
return false;
}
return true;
}


function getCookie(NameOfCookie)
{ if (document.cookie.length > 0)
{ begin = document.cookie.indexOf(NameOfCookie+"=");
if (begin != -1)
begin += NameOfCookie.length+1;
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end)); }
}


function setCookie(NameOfCookie, value, expiredays)
{ var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
document.cookie = NameOfCookie + "=" + escape(value) +
((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}



function delCookie (NameOfCookie)
{ if (getCookie(NameOfCookie)) {
document.cookie = NameOfCookie + "=" +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

}





function poptastic(url, w, h)
{
	var newwindow;
	newwindow=window.open(url,'name','height='+h+',width='+w+'');
	if (window.focus) {newwindow.focus()}
}



function add_history(hhh)
{

$sethtml('history', '&nbsp; ' + get_value('last_h') );

set_value('last_h', hhh);

}


function reload_profile()
{
$.post('php_ajax/profilo.php',{ test:'test'}, function(data){ $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { show_profile_gallery_p_load(); show_profile_gallery_load(); }); });    });
}

function logout()
{
$.post('php_ajax/logout.php',{ start: ''  }, function(data){  window.location = 'index.php'; });
}

function reload_home(startv)
{
$.post('php_ajax/home-ax.php',{ start: startv  }, function(data){ $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); });  reload_menu(); });
}

function reload_ricerca()
{
$.post('php_ajax/ricerca.php',{ test: 'test'  }, function(data){ $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); }); });
}

function ricerca()
{
$.post('php_ajax/ricerca-ris.php',{ fullname: get_value('fullname'),username: get_value('username'),localita: get_value('localita'),sesso: get_value('sesso_id'),eta_start: get_value('eta_start_id'),eta_end: get_value('eta_end_id'), citta: get_value('citta'), regione: get_value('regione'), start: get_value('start'), preferenze_sesso: get_value('preferenze_sesso'), foto: is_checked('foto'), online: is_checked('online'), status: get_value('status')}, function(data){ $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); }); });


var hname = "";
if ( language == "it" )
{
hname = "Ultima ricerca effettuata";
}
if ( language == "us" )
{
hname = "Last user search";
}

add_history('<a href="#" onclick="ricerca_c(\''+get_value('username')+'\', \''+get_value('fullname')+'\', \''+get_value('localita')+'\', \''+get_value('sesso_id')+'\', \''+get_value('eta_start_id')+'\', \''+get_value('eta_end_id')+'\', \''+get_value('citta')+'\',\''+get_value('regione')+'\', \''+get_value('start')+'\', \'' + get_value('preferenze_sesso') + '\',\'' + is_checked('foto') + '\', \'' + is_checked('online') + '\', \'' + get_value('status') + '\' );"> <img src="media/backl.png" alt="Back" />  '+hname+' </a>');
}


function ricerca_home()
{
$.post('php_ajax/ricerca-ris.php',{ fullname: get_value('fullnametop'),username: '%',localita: '%',sesso: '%',eta_start: '%',eta_end: '%', citta: '%', regione: '%', start: '0', preferenze_sesso: '%', foto: '%', online: '%', status: '%'}, function(data){ $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); }); });


var hname = "";
if ( language == "it" )
{
hname = "Ultima ricerca effettuata";
}
if ( language == "us" )
{
hname = "Last user search";
}

add_history('<a href="#" onclick="ricerca_c(\''+'%'+'\', \''+get_value('fullnametop')+'\', \''+'%'+'\', \''+'%'+'\', \''+'%'+'\', \''+'0'+'\', \''+'%'+'\',\''+'%'+'\', \''+'%'+'\', \'' + '%' + '\',\'' + '%' + '\', \'' + '%' + '\', \'' + '%' + '\' );"> <img src="media/backl.png" alt="Back" />  '+hname+' </a>');
}

function ricerca_c(username, fullname, localita, sesso_id, eta_start_id, eta_end_id, citta_id,regione_id, start_id, preferenze_sesso_id, foto_id, online_id, status_id )
{

$.post('php_ajax/ricerca-ris.php',{username: username, fullname: fullname, localita: localita, sesso: sesso_id, eta_start: eta_start_id,eta_end: eta_end_id, citta: citta_id, regione: regione_id, start: start_id, preferenze_sesso: preferenze_sesso_id, foto: foto_id, online: online_id, status: status_id   }, function(data){ $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); }); });


var hname = "";
if ( language == "it" )
{
hname = "Ultima ricerca effettuata";
}
if ( language == "us" )
{
hname = "Last user search";
}

add_history('<a href="#" onclick="ricerca_c(\''+username+'\', \''+fullname+'\', \''+localita+'\', \''+sesso_id+'\', \''+eta_start_id+'\', \''+eta_end_id+'\', \''+citta_id+'\',\''+regione_id+'\', \''+start_id + '\', \'' +preferenze_sesso_id + '\', \'' + foto_id + '\', \'' +online_id + '\', \'' +status_id + '\' );"> <img src="media/backl.png" alt="Back" />  '+hname+' </a>');
}


// Don't call ajax request function directly, as it will
//   be terminated when the popup is closed.
// Instead call the ajax function with settimeout:
//   The settimeout function will be scheduled before
//   the popup is closed and will be executed after the
//   popup was closed
// Without that settimeout in the parent window, the ajax
//    request will be terminated when the popup is closed
//    and the ajax callback function (http_request.onreadystatechange)
//    will fail (see error above)
function reload_profile_timed() {
	window.setTimeout('reload_profile()', 30);
}

function reload_album_timed() {
	window.setTimeout('show_profile_gallery(0)', 30);
}



function reload_album_p_timed() {
	window.setTimeout('show_profile_gallery_p(0)', 30);
}

function hide_loading_timed(tmp)
{
window.setTimeout('\$(\'#loading_id\').hide(\'600\'); \$sethtml(\'loading_text_id\',\'Loading..\');', tmp);

}

function show_profile(id)
{

$.post('php_ajax/vedi-profilo.php',{ id: id  }, function(data){ $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data);   $('#mainc_idR').fadeIn('fast', function() { show_gallery_load_p(id); }); });   });



var hname = "";
if ( language == "it" )
{
hname = "Ultimo profilo visualizzato";
}
if ( language == "us" )
{
hname = "Last profile seen";
}


add_history('<a href="#" onclick="show_profile('+id+');"> <img src="media/backl.png" alt="Back" />  '+hname+'  </a>');
}

function show_profile_nl(id)
{

$.post('php_ajax/vedi-profilo.php',{ id: id  }, function(data){ $sethtml('mainc_idR', data);});

}


function scrivi_messaggio(id)
{

$.post('php_ajax/scrivi-messaggio.php',{ id: id  }, function(data){ $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); }); });
}

function invia_messaggio(id)
{

var Messages = "";
if ( language == "it" )
{
Messages = 'Prima di inviare un messaggio bisogna compilare tutti i campi!';
}
if ( language == "us" )
{
Messages = 'Please fill all fields!';
}

if ( get_value('mail_subject') != "" && get_value('text_id') != "" )
{
$('#loading_id').show('fast'); 
$.post('php_ajax/invia_messaggio.php',{ id: id, subject: get_value('mail_subject'), text: get_value('text_id')  }, function(data){ $sethtml('loading_text_id',data); hide_loading_timed(600); show_profile_nl(id)});
}
else
alert(Message);

}

function show_mails(start)
{

$.post('php_ajax/mail-reader.php',{ start: start  }, function(data){ $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); }); });

var hname = "";
if ( language == "it" )
{
hname = "Messaggi ricevuti";
}
if ( language == "us" )
{
hname = "Incoming Messages";
}


add_history('<a href="#" onclick="show_mails('+start+');"> <img src="media/backl.png" alt="Back" />  '+hname+'  </a>');
}


function show_mails_sent(start)
{

$.post('php_ajax/mail-reader-sent.php',{ start: start  }, function(data){ $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); });});

var hname = "";
if ( language == "it" )
{
hname = "Messaggi inviati";
}
if ( language == "us" )
{
hname = "Sent Messages";
}

add_history('<a href="#" onclick="show_mails_sent('+start+');"> <img src="media/backl.png" alt="Back" />  '+hname+'  </a>');
}


function leggi_mail(id)
{

var hname = "";
if ( language == "it" )
{
hname = "Messaggio letto";
}
if ( language == "us" )
{
hname = "Message received";
}



$.post('php_ajax/leggi-mail.php',{ id: id  }, function(data){ $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); }); reload_menu(); });
add_history('<a href="#" onclick="leggi_mail('+id+');"> <img src="media/backl.png" alt="Back" />  '+hname+'  </a>');
}

function leggi_mail_s(id)
{

$.post('php_ajax/leggi-mail_s.php',{ id: id  }, function(data){ $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); }); });

var hname = "";
if ( language == "it" )
{
hname = "Messaggio inviato";
}
if ( language == "us" )
{
hname = "Sent Message";
}

add_history('<a href="#" onclick="leggi_mail_s('+id+');"> <img src="media/backl.png" alt="Back" />  '+hname+'  </a>');
}

function is_checked (idc)
{
if ( document.getElementById(idc).checked == true )
return true;
else
return false;

}

function delete_mails(count)
{
var cmd = '';
var c = 0;
var i = 0;

try
{


for ( c = 0; c< count; c++ )
{
var idc = 'delete'+c;

if ( document.getElementById(idc).checked == true )
{


if ( i > 0 )
cmd = cmd + '.' + get_value(idc) ;
else
cmd = cmd + ':' + get_value(idc) ;


i=i+1;

}

}


//alert(cmd);
if ( i > 0 )
$.post('php_ajax/cancella_mails.php',{ cmd: cmd  }, function(data){ show_mails(0); });
}

catch(err){

//alert(cmd);
if ( i > 0 )
$.post('php_ajax/cancella_mails.php',{ cmd: cmd  }, function(data){  show_mails(0); });

}

}

function aggiungi_ai_preferiti(id)
{
$('#loading_id').show('fast'); 
$.post('php_ajax/aggiungi_ai_preferiti.php',{ prefid: id }, function(data){ $sethtml('loading_text_id',data); hide_loading_timed(2000); });
}

function aggiungi_gruppo_ai_preferiti(id)
{
$('#loading_id').show('fast'); 
$.post('php_ajax/aggiungi_gruppo_ai_preferiti.php',{ id: id }, function(data){ $sethtml('loading_text_id',data); 
hide_loading_timed(600); });
}

function rimuovi_gruppo_dai_preferiti(id)
{
$('#loading_id').show('fast'); 
$.post('php_ajax/rimuovi_gruppo_dai_preferiti.php',{ id: id }, function(data){ $sethtml('loading_text_id',data); hide_loading_timed(2000); });
}


function rimuovi_dai_preferiti(id)
{
$('#loading_id').show('fast'); 
$.post('php_ajax/rimuovi_dai_preferiti.php',{ prefid: id }, function(data){ $sethtml('loading_text_id',data); hide_loading_timed(2000); });
}

function sbanda(id)
{
$('#loading_id').show('fast'); 
$.post('php_ajax/sbanda.php',{ sbanda_id: id }, function(data){ $sethtml('loading_text_id',data); hide_loading_timed(2000); });

}


function richiedi_accesso_prive(id)
{
$('#loading_id').show('fast'); 
$.post('php_ajax/richiesta_prive.php',{ richiesta_id: id }, function(data){ $sethtml('loading_text_id',data); hide_loading_timed(2000); });
}

function delete_mails_s(count)
{
var cmd = '';
var c = 0;
var i = 0;

try
{


for ( c = 0; c< count; c++ )
{
var idc = 'delete'+c;

if ( document.getElementById(idc).checked == true )
{


if ( i > 0 )
cmd = cmd + '.' + get_value(idc) ;
else
cmd = cmd + ':' + get_value(idc) ;


i=i+1;

}

}


//alert(cmd);
if ( i > 0 )
$.post('php_ajax/cancella_mails_s.php',{ cmd: cmd  }, function(data){  show_mails_sent(0); });
}

catch(err){
//alert(cmd);
if ( i > 0 )
$.post('php_ajax/cancella_mails_s.php',{ cmd: cmd  }, function(data){ show_mails_sent(0); });
}

}


function sbandate_ricevute(starts)
{

$.post('php_ajax/sband-recv.php',{ start: starts }, function(data){ $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); }); reload_menu(); });

var hname = "";
if ( language == "it" )
{
hname = "Attenzioni ricevute";
}
if ( language == "us" )
{
hname = "Received attentions";
}

add_history('<a href="#" onclick="sbandate_ricevute('+starts+');"> <img src="media/backl.png" alt="Back" />  '+hname+'  </a>');
}


function richieste_prive_accettate(starts)
{

$.post('php_ajax/prive_autorizzati.php',{ start: starts }, function(data){ $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); }); reload_menu(); });


var hname = "";
if ( language == "it" )
{
hname = "Prive accessibili";
}
if ( language == "us" )
{
hname = "Prive available";
}


add_history('<a href="#" onclick="richieste_prive_accettate('+starts+');"> <img src="media/backl.png" alt="Back" />  '+hname+' </a>');
}

function richieste_prive(starts)
{

$.post('php_ajax/richieste_prive.php',{ start: starts }, function(data){ $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); }); });

var hname = "";
if ( language == "it" )
{
hname = "Richieste Prive";
}
if ( language == "us" )
{
hname = "Prive requests";
}

add_history('<a href="#" onclick="richieste_prive('+starts+');"> <img src="media/backl.png" alt="Back" />  '+hname+'  </a>');
}



function sbandate_manifestate(starts)
{

$.post('php_ajax/sband-manif.php',{ start: starts }, function(data){ $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); }); });

var hname = "";
if ( language == "it" )
{
hname = "Attenzioni manifestate";
}
if ( language == "us" )
{
hname = "Revealed attentions";
}

add_history('<a href="#" onclick="sbandate_manifestate('+starts+');"> <img src="media/backl.png" alt="Back" />  '+hname+'   </a>');
}

function preferiti(starts)
{

$.post('php_ajax/preferiti.php',{ start: starts }, function(data){ $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); }); });


var hname = "";
if ( language == "it" )
{
hname = "Utenti preferiti";
}
if ( language == "us" )
{
hname = "Favorites users";
}


add_history('<a href="#" onclick="preferiti('+starts+');"> <img src="media/backl.png" alt="Back" />  '+hname+'  </a>');
}



function sono_preferito(starts)
{

$.post('php_ajax/mi_preferiscono.php',{ start: starts }, function(data){ $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); });});


var hname = "";
if ( language == "it" )
{
hname = "Mi preferiscono";
}
if ( language == "us" )
{
hname = "They prefer me";
}


add_history('<a href="#" onclick="sono_preferito('+starts+');"> <img src="media/backl.png" alt="Back" />  '+hname+' </a>');
}


function visite(starts)
{

$.post('php_ajax/visite.php',{ start: starts }, function(data){ $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); }); reload_menu(); });



var hname = "";
if ( language == "it" )
{
hname = "Visite ricevute";
}
if ( language == "us" )
{
hname = "My visitors";
}

add_history('<a href="#" onclick="visite('+starts+');"> <img src="media/backl.png" alt="Back" />  '+hname+'  </a>');
}


function reload_menu()
{
$.post('php_ajax/reload_menu.php',{  }, function(data){ $sethtml('menu_r', data); });
}


function show_profile_gallery(stst)
{
$('#loading_id').show('fast'); 
$.post('php_ajax/show_profile_gallery.php',{start: stst }, function(data){ $sethtml('profile_pics', data); setTimeout('$(\'#loading_id\').hide(\'slow\')', 100); });
}


function show_profile_gallery_p(stst)
{
$('#loading_id').show('fast'); 
$.post('php_ajax/show_profile_gallery_p.php',{start: stst }, function(data){ $sethtml('profile_picsp', data); setTimeout('$(\'#loading_id\').hide(\'slow\')', 100); });
}

function show_profile_gallery_load()
{
$.post('php_ajax/show_profile_gallery.php',{  }, function(data){ $sethtml('profile_pics', data); setTimeout('$(\'#loading_id\').hide(\'fast\')', 1); });
}

function show_profile_gallery_p_load()
{
$.post('php_ajax/show_profile_gallery_p.php',{  }, function(data){ $sethtml('profile_picsp', data);  });
}


function show_gallery(stst, uid)
{
$('#loading_id').show('fast'); 
$.post('php_ajax/show_gallery.php',{start: stst, id: uid }, function(data){ $sethtml('profile_pics', data); setTimeout('$(\'#loading_id\').hide(\'slow\')', 100); });
}

function show_gallery_p(stst, uid)
{
$('#loading_id').show('fast'); 
$.post('php_ajax/show_gallery_p.php',{start: stst, id: uid }, function(data){ $sethtml('profile_picsp', data); setTimeout('$(\'#loading_id\').hide(\'slow\')', 100); });
}


function show_gallery_load_p(uid)
{
$.post('php_ajax/show_gallery_p.php',{ id: uid }, function(data){ $sethtml('profile_picsp', data); show_gallery_load(uid); });
}

function show_gallery_load(uid)
{
$.post('php_ajax/show_gallery.php',{ id: uid }, function(data){ $sethtml('profile_pics', data); setTimeout('$(\'#loading_id\').hide(\'slow\')', 100); });
}



function delete_picsp(count)
{
var cmd = '';
var c = 0;
var i = 0;

try
{


for ( c = 0; c< count; c++ )
{
var idc = 'delete_p'+c;
if ( document.getElementById(idc).checked == true )
{
if ( i > 0 )
cmd = cmd + '.' + get_value(idc) ;
else
cmd = cmd + ':' + get_value(idc) ;
i=i+1;
}
}

//(alert(cmd);
if ( i > 0 )
$.post('php_ajax/delete_picsp.php',{ cmd: cmd  }, function(data){ show_profile_gallery_p(0); });
}

catch(err){
//alert(cmd);
if ( i > 0 )
$.post('php_ajax/delete_picsp.php',{ cmd: cmd  }, function(data){ show_profile_gallery_p(0); });
}

}


function delete_pics(count)
{
var cmd = '';
var c = 0;
var i = 0;

try
{


for ( c = 0; c< count; c++ )
{
var idc = 'delete'+c;
if ( document.getElementById(idc).checked == true )
{
if ( i > 0 )
cmd = cmd + '.' + get_value(idc) ;
else
cmd = cmd + ':' + get_value(idc) ;
i=i+1;
}
}

//(alert(cmd);
if ( i > 0 )
$.post('php_ajax/delete_pics.php',{ cmd: cmd  }, function(data){ show_profile_gallery(0); });
}

catch(err){
//alert(cmd);
if ( i > 0 )
$.post('php_ajax/delete_pics.php',{ cmd: cmd  }, function(data){ show_profile_gallery(0); });
}

}

function update_chat(id)
{
try
{

$.post('class/chat.php',{ update: 'update', usrid: id  }, function(data){ if ( get_value('ch' + id + '_flag') == 0 && data != '' ) set_value('newmess_' + id,'1'); setTimeout("$apphtml('recv_text"+id+"','"+data+"'); update_chat('"+id+"');", 100); });
$('#recv_text'+id).scrollTo('100%',{axis:'y'});

}
catch(err){
setTimeout("$apphtml('recv_text"+id+"','"+data+"'); update_chat('"+id+"');", 100); 
}
}


function update_chat_status(id)
{
try
{
var nm = get_value('newmess_'+id);
//document.title= ??
$.post('class/chat.php',{ update_status: 'update_status', usrid: id, new_messages: nm  }, function(data){ setTimeout("$sethtml('chat_header_"+id+"','"+data+"');  update_chat_status('"+id+"');", 100); });
}
catch(err){
setTimeout("$sethtml('chat_header_"+id+"','"+data+"');  update_chat_status('"+id+"');", 100);
}
}

function send_chat_message(id, message)
{
var io = "";
if ( language == "it" )
{
io = "Io:";
}
if ( language == "us" )
{
io = "Me:";
}

if ( message != '' )
$.post('class/chat.php',{ message: 'message', text: message, usrid: id  }, function(data){ set_value('send_text'+id,''); $apphtml('recv_text'+id, '<br /> <small><b>'+io+' </b></small>' + message); $('#recv_text'+id).scrollTo('100%',{axis:'y'}); });

}

function evidenzia(target)
{
var e = document.getElementById(target);
e.focus();
}

function apri_una_chat(id)
{


if ( document.getElementById("chat"+id) == null)
{
$.post('class/chat.php',{ print: 'print', usrid: id   }, function(data){ $apphtml('fot',data);$('').addClass('chatAV'); set_value('chat_id', get_value('chat_id')+1 );   });
var upid = id;  //get_value('next_chat_id');
update_chat(upid);
update_chat_status(upid);
}
else
{
if ( get_value('ch'+id+'_flag') == '0' ) { hide('chat_recv_'+id); hide('chat_send_'+id);  $('#chat_header_'+id).addClass('chat'); $('#chat_header_'+id).removeClass('chatAV');   set_value('ch'+id+'_flag','1');   } else {hide('chat_send_'+id); hide('chat_recv_'+id); $('#chat_header_'+id).addClass('chatAV'); $('#chat_header_'+id).removeClass('chat'); set_value('ch'+id+'_flag','0');  }
}

}




function available_chats()
{
try
{
$.post('class/chat.php',{ available_chat: 'available_chat'  }, function(data){ $sethtml('chat_requests', data);  setTimeout(" available_chats();", 10000) });
}
catch(err){
setTimeout(" available_chats();", 10000);
}
}


function login()
{

var hname = "";
if ( language == "it" )
{
hname = "<br /><br />Benvenuto!";
}
if ( language == "us" )
{
hname = "<br /><br />Welcome!";
}



$('#loading_id').show('fast');
$.post('php_ajax/login.php',{ username: get_value('username'),password: get_value('password') }, function(data){ if ( data != hname  ) { alert(data); } else location.href = 'home.php';});
}

function register()
{
$('#loading_id').show('fast');
$.post('php_ajax/register.php',{ fullname: get_value('fullname'),Rusername: get_value('Rusername'),Rpassword: get_value('Rpassword'),email: get_value('email'),rsex: get_value('rsex'),rssex: get_value('rssex') }, function(data){ $sethtml('loading_id', data); hide_loading_timed(60000);});

}




function consenti_prive(count)
{
var cmd = '';
var c = 0;
var i = 0;

try
{


for ( c = 0; c< count; c++ )
{
var idc = 'consenti'+c;
if ( document.getElementById(idc).checked == true )
{
if ( i > 0 )
cmd = cmd + '.' + get_value(idc) ;
else
cmd = cmd + ':' + get_value(idc) ;
i=i+1;
}
}

//(alert(cmd);
if ( i > 0 )
{
$('#loading_id').show('fast');
$.post('php_ajax/consenti_prive.php',{ cmd: cmd  }, function(data){ richieste_prive(0);setTimeout('$(\'#loading_id\').hide(\'slow\')', 100);  });
}
}

catch(err){
//alert(cmd);
if ( i > 0 )
{
$('#loading_id').show('fast');
$.post('php_ajax/consenti_prive.php',{ cmd: cmd  }, function(data){ richieste_prive(0);setTimeout('$(\'#loading_id\').hide(\'slow\')', 100); });
}
}

}




function nega_prive(count)
{
var cmd = '';
var c = 0;
var i = 0;

try
{


for ( c = 0; c< count; c++ )
{
var idc = 'consenti'+c;
if ( document.getElementById(idc).checked == true )
{
if ( i > 0 )
cmd = cmd + '.' + get_value(idc) ;
else
cmd = cmd + ':' + get_value(idc) ;
i=i+1;
}
}

//(alert(cmd);
if ( i > 0 )
{
$('#loading_id').show('fast');
$.post('php_ajax/nega_prive.php',{ cmd: cmd  }, function(data){ richieste_prive(0);setTimeout('$(\'#loading_id\').hide(\'slow\')', 100); });
}
}

catch(err){
//alert(cmd);
if ( i > 0 )
{
$('#loading_id').show('fast');
$.post('php_ajax/nega_prive.php',{ cmd: cmd  }, function(data){ richieste_prive(0);setTimeout('$(\'#loading_id\').hide(\'slow\')', 100); });
}
}
}



function mostra_commenti(id)
{
 $.post('php_ajax/mostra_commenti.php',{ id: id  }, function(data){  $('#comments_'+id).fadeOut('fast', function() { $sethtml('comments_'+id, data); $('#comments_'+id).fadeIn('fast', function() { ; }); });  });
}


function mostra_commenti_gruppo(id, gruppo_id)
{
$.post('php_ajax/mostra_commenti_gruppo.php',{ id: id, gruppo_id: gruppo_id }, function(data){ $('#comments_'+id).fadeOut('fast', function() { $sethtml('comments_'+id, data); $('#comments_'+id).fadeIn('fast', function() { ; }); });     });
}

function commenta(id)
{
$.post('php_ajax/commenta.php',{ id: id, message: get_value('testo_commento_'+id)  }, function(data){ mostra_commenti(id);  });
}

function commenta_gruppo(id, gruppo_id)
{ 
$.post('php_ajax/commenta_gruppo.php',{ id: id, message: get_value('testo_commento_'+id)  }, function(data){ mostra_commenti_gruppo(id, gruppo_id);  });
}


function gruppi(start, filtro)
{

$.post('php_ajax/gruppi.php',{ start: start, filtro: filtro  }, function(data){  $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); });  });

var hname = "";
if ( language == "it" )
{
hname = "Gruppi";
}
if ( language == "us" )
{
hname = "Groups";
}

add_history('<a href="#" onclick="gruppi(\''+start+'\',\''+filtro+'\');"> <img src="media/backl.png" alt="Back" />  '+hname+'  </a>');
}

function gruppi_preferiti(start)
{

$.post('php_ajax/gruppi_preferiti.php',{ start: start  }, function(data){  $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); });  });


var hname = "";
if ( language == "it" )
{
hname = "I miei gruppi preferiti";
}
if ( language == "us" )
{
hname = "My favorites groups";
}

add_history('<a href="#" onclick="gruppi_preferiti('+start+');"> <img src="media/backl.png" alt="Back" />  '+hname+'  </a>');
}

function miei_gruppi(start)
{

$.post('php_ajax/miei_gruppi.php',{ start: start  }, function(data){  $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); });  });


var hname = "";
if ( language == "it" )
{
hname = "I miei gruppi";
}
if ( language == "us" )
{
hname = "My groups";
}


add_history('<a href="#" onclick="miei_gruppi('+start+');"> <img src="media/backl.png" alt="Back" /> '+hname+'  </a>');
}

function crea_gruppo()
{

$.post('php_ajax/crea_gruppo.php',{ start: 'start'  }, function(data){  $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); });  });
}

function crea_gruppo_salva()
{

$.post('php_ajax/crea_gruppo_post.php',{ nome_gruppo: get_value('nome_gruppo'), descrizione_gruppo: get_value('descrizione_gruppo'), categoria_gruppo: get_value('categoria_gruppo') }, function(data){  $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); });  });
}

function modifica_gruppo(gruppo_id)
{
$.post('php_ajax/modifica_gruppo.php',{ gruppo_id: gruppo_id }, function(data){  $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); });  });
}

function salva_modifiche_gruppo()
{

$.post('php_ajax/modifica_gruppo_post.php',{  gruppo_id: get_value('gruppo_id'), descrizione_gruppo: get_value('descrizione_gruppo'), categoria_gruppo: get_value('categoria_gruppo') }, function(data){  $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); });  });
}

function delete_groups(count)
{
var cmd = '';
var c = 0;
var i = 0;

try
{


for ( c = 0; c< count; c++ )
{
var idc = 'delete_group'+c;

if ( document.getElementById(idc).checked == true )
{


if ( i > 0 )
cmd = cmd + '.' + get_value(idc) ;
else
cmd = cmd + ':' + get_value(idc) ;


i=i+1;

}

}


//alert(cmd);
if ( i > 0 )
$.post('php_ajax/delete_groups.php',{ cmd: cmd  }, function(data){miei_gruppi(0);});
}

catch(err){

//alert(cmd);
if ( i > 0 )
$.post('php_ajax/delete_groups.php',{ cmd: cmd  }, function(data){miei_gruppi(0);});

}

}

function apri_gruppo(gruppo_id, start)
{

$.post('php_ajax/gruppo.php',{ gruppo_id: gruppo_id, start: start  }, function(data){  $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); });  });

var hname = "";
if ( language == "it" )
{
hname = "Gruppo aperto";
}
if ( language == "us" )
{
hname = "Last group";
}


add_history('<a href="#" onclick="apri_gruppo('+gruppo_id+');"> <img src="media/backl.png" alt="Back" /> '+hname+' </a>');
}

function utenti_gruppo(gruppo_id, start)
{

$.post('php_ajax/utenti_gruppo.php',{ gruppo_id: gruppo_id, start: start  }, function(data){  $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { ; }); });  });

var hname = "";
if ( language == "it" )
{
hname = "Utenti del gruppo";
}
if ( language == "us" )
{
hname = "Group users";
}

add_history('<a href="#" onclick="utenti_gruppo('+gruppo_id+');"> <img src="media/backl.png" alt="Back" /> '+hname+' </a>');
}


function apri_chat_gruppo(gruppo_id)
{

$.post('php_ajax/chat_gruppo.php',{ gruppo_id: gruppo_id  }, function(data){  $('#mainc_idR').fadeOut('fast', function() { $sethtml('mainc_idR', data); $('#mainc_idR').fadeIn('fast', function() { update_chat_gruppo(gruppo_id); update_chat_gruppo_status(gruppo_id); }); });  });



var hname = "";
if ( language == "it" )
{
hname = "Chat del gruppo";
}
if ( language == "us" )
{
hname = "Group chat";
}

add_history('<a href="#" onclick="apri_chat_gruppo('+gruppo_id+');"> <img src="media/backl.png" alt="Back" /> '+hname+' </a>');



//update_chat_status_gruppo(upid);

}

function update_chat_gruppo(id)
{
try
{

$.post('class/chat.php',{ update_gruppo: 'update_gruppo', gruppo_id: id, last_id: get_value('last_id') }, function(data){ $('#last_id').remove(); $apphtml('recv_text',data); setTimeout("update_chat_gruppo('"+id+"');", 3000);   });
$('#recv_text').scrollTo('100%',{axis:'y'});
}
catch(err){
setTimeout("update_chat_gruppo('"+id+"');", 3000); 
}
}

function update_chat_gruppo_status(id)
{

try
{
$.post('class/chat.php',{ online_gruppo_status: 'online_gruppo_status', gruppo_id: id  }, function(data){ $sethtml('users_online',data); setTimeout("update_chat_gruppo_status('"+id+"');", 5000); });
$('#recv_text').scrollTo('100%',{axis:'y'});
}
catch(err){
setTimeout("update_chat_gruppo_status('"+id+"');", 5000);
}

}


function send_chat_group_message(id, message)
{

if ( message != '' )
$.post('class/chat.php',{ group_message: 'group_message', text: message, gruppo_id: id  }, function(data){ set_value('send_text',''); });

}



function elimina_mio_commento(id, start)
{

$.post('php_ajax/elimina_mio_commento.php',{ id: id }, function(data){ $sethtml('loading_text_id',data);  reload_home(start); });
}

function elimina_mio_commento_reply(id, postid)
{

$.post('php_ajax/elimina_mio_commento_reply.php',{ id: id, post_id: postid }, function(data){ $sethtml('loading_text_id',data);  mostra_commenti(postid); });
}


function elimina_mio_commento_gruppo(id, start, gruppo_id)
{

$.post('php_ajax/elimina_mio_commento_gruppo.php',{ id: id, gruppo_id: gruppo_id }, function(data){ $sethtml('loading_text_id',data);  apri_gruppo(gruppo_id, start); });
}


function elimina_mio_commento_reply_gruppo(id, postid, gruppo_id)
{

$.post('php_ajax/elimina_mio_commento_reply_gruppo.php',{ id: id, post_id: postid, gruppo_id: gruppo_id }, function(data){ $sethtml('loading_text_id',data);  mostra_commenti_gruppo(postid, gruppo_id); });
}

