
/* aggiungere se si utilizza da sola 
function reset_form_privato(nome_form)
{
	$(nome_form).reset();
	var hidInp = $(nome_form).getElementsByTagName('input');
	for (var i = 1; i < hidInp.length; i++)
	{
		if (hidInp[i].type == 'hidden')
		{	
			hidInp[i--].destroy();
		}
		
	}
}         



function reset_form(nome_form)
{
	$(nome_form).reset();
	var hidInp = $(nome_form).getElementsByTagName('input');
	for (var i = 1; i < hidInp.length; i++)
	{
		if (hidInp[i].type == 'hidden')
		{	
			hidInp[i--].destroy();
		}
		
	}
}
 *
 *
 *
 *
 *
 

document.addEvent('domready',function() 
{	
	userAg = navigator.userAgent;
	if ($('shoutbox') && userAg.substring("MSIE") == -1)
		aggiorna_shoutbox();
	
		new DatePicker('input#data_ev',{ pickerClass: 'datepicker_jqui',positionOffset:{x:0,y:-190}});
	
	

});*/
function canc_mess_shout_privato(id_mess, user)
{	
		var req = new Request({
			url:  '/modules/shoutbox_privata/shoutbox_functions_privato.php',
			method: 'get',
			data: 'agg=del&us=' + user + '&mess=' + id_mess,
			async: false,
			onSuccess: function(risposta)
			{
				$('sb_container_messaggi_privato').empty().set('html', risposta);
				reset_form('form_shoutbox');	
			}
		}).send();
}

function check_shout_privato()
{
	var ok = true;
	var msg = document.getElementById('messaggio');
	var titolo = document.getElementById('msg_titolo');
	var destinazione = document.getElementById('msg_target');
	msg_err = 'Sono stati riscontrati i seguenti errori: ';
	
	if (msg == '' || msg == undefined)
	{
		msg_err += '- inserire un messaggio\n';
		ok = false;
	}
	
	if (titolo.length >= 250 || titolo.length >= 250)
	{
		ok = false;
		msg_err += '- il campo titolo non può contenere più di 250 caratteri\n';
	}

	if (ok == true)
	{
		dati = '';
		if (document.getElementById('agg') != null)
		{
			var func = document.getElementById('agg');
			dati = (func.value == 'mod') ? '?agg=mod' : '';
			dati += (func.value == 'mod') ? ('&mess=' + document.getElementById('mess').value) : '';
		}
		//se non ci sono errori inserisco il messaggio e faccio un update tramite request
			var req = new Request.HTML({
				url:  '/modules/shoutbox_privata/shoutbox_functions_privato.php' + dati,
				async: false,
				onComplete: function(resTxt)
				{
					$('sb_container_messaggi_privato').empty().adopt(resTxt);
					reset_form('form_shoutbox');
				}
			}).post($('form_shoutbox'));
	
	}
	else return msg;
}

function mod_mess_shout_privato(id_mess)
{
	var mezz = new Element('input', {
		'type' : 'hidden',
		'id' : 'mess',
		'name' : 'mess',
		'value' : id_mess});
		
	var mod = new Element('input', {
		'type' : 'hidden',
		'id' : 'agg',
		'name':'agg',
		'value' : 'mod'});
	reset_form('form_shoutbox');
	$('shout_priv').click();
	$('form_shoutbox').grab(mezz);
	$('form_shoutbox').grab(mod);
	$('msg_titolo').value = get_spec_campo_privato('TITOLO', id_mess);
	$('messaggio').value = get_spec_campo_privato('TESTO', id_mess);
	$('msg_target').value = get_spec_campo_privato('DESTINAZIONE', id_mess);
	
}
function aggiorna_shoutbox_privato()
{

		//ogni 30 secondi aggiorna la shoutbox
		var req = new Request({
				url:  '/modules/shoutbox_privata/shoutbox_functions_privato.php',
				method: 'get',
				data: 'agg=si',
				async: false,
				onSuccess: function(rsTxt)
				{
					$('sb_container_messaggi_privato').empty().set('html', rsTxt);
				}
			}).send();
			
	userAg = navigator.userAgent;
	if (userAg.substring("MSIE") == -1)
	{	
		var t=setTimeout("aggiorna_shoutbox_privato()",30000); // 30 secondi
	}
}



function get_spec_campo_privato(campo, idcampo)
{
	var req = new Request({
		url:  '/modules/shoutbox_privata/request_privato.php',
		method: 'get',
		data: 'type=get_spec&campo=' + campo + '&id=' + idcampo,
		async: false,
		onSuccess: function(riz)
		{
			resp = trim(riz);
		}
	}).send();
	return resp;
}


function switch_priv8(check){
	
	url_priv = '/modules/shoutbox_privata/shoutbox_functions_privato.php';
	if(check.checked){
		var req = new Request.HTML({
			url: url_priv,
			update: $('msg_targets')
		}).get('agg=getTargets&priv=priv');
		
		$('invia_shout').set('onclick', 'check_shout_privato()');
	}
	else{
		var req = new Request.HTML({
			url: url_priv,
			update: $('msg_targets')
		}).get('agg=getTargets');
		
		$('invia_shout').set('onclick', 'check_shout()');
	}
	
	
}
