var dateFormat = "";
var lastMessageDate = "";

var formats = new Array('D M d, Y g:i a','D M d, Y g:i A','D M d, Y G:i A','D M d, Y G:i a','D M d, Y G:i','d M Y h:i a','d M Y h:i A','d M Y H:i a','d M Y H:i A','d M Y H:i','M d, Y g:i a','M d, Y g:i A','M d, Y G:i a','M d, Y G:i A','M d, Y G:i');

function checkDateFormat(sFormat)
{
	for (var i =0;i<formats.length;i++)
	{
		if (sFormat == formats[i])
			return (true);
	}
	return (false);
}

function convertData(dateFormat,dateToConv)
{
	if (dateFormat.substring(0,1) == 'D')
		dateToConv = dateToConv.substring(4);
	
	if (dateFormat.substring(0,3) == 'M d')
		dateToConv = dateToConv.substring(3,6) + ' ' + dateToConv.substring(0,3) + dateToConv.substring(6);
	
	dateToConv = dateToConv.replace('Gen','Jan');
	dateToConv = dateToConv.replace('Mag','May');
	dateToConv = dateToConv.replace('Giu','Jun');
	dateToConv = dateToConv.replace('Lug','Jul');
	dateToConv = dateToConv.replace('Ago','Aug');
	dateToConv = dateToConv.replace('Set','Sep');
	dateToConv = dateToConv.replace('Ott','Oct');
	dateToConv = dateToConv.replace('Dic','Dec');
	
	var pos = dateFormat.indexOf('G:i');
	var pos2 = dateFormat.indexOf('H:i');
	
	if (pos >= 0 || pos2 >= 0)
	{ 
		dateToConv = dateToConv.replace('pm','');
		dateToConv = dateToConv.replace('PM','');
		dateToConv = dateToConv.replace('am','');
		dateToConv = dateToConv.replace('AM','');
	}
	
	//alert(dateToConv);
	return(dateToConv);
}

function getDateFormat()
{
	var url = "http://lifroccolotto.forumup.it/profile.php?mode=editprofile&mforum=lifroccolotto";
	var callback = readFormat;
	sendRequest(url,callback, false, 'GET', false);
	return (dateFormat);
}

function readFormat(text)
{
	var c =text.indexOf('name="dateformat"');
	var start = text.indexOf('"',c+18);
	var end = text.indexOf('"',start+1);
	dateFormat = text.substring(start+1,end);
	return;
}

function getLastMessageDate(user)
{
	var url = "http://lifroccolotto.forumup.it/search.php?search_author=" + user + "&mforum=lifroccolotto";
	var callback = readMessage;
	sendRequest(url,callback, false, 'GET', false);
	return (lastMessageDate);
}

function readMessage(text)
{
	lastMessageDate="";
	var count =text.indexOf('Inviato');
  var mess = "";
  if (count>=0)
  {
		var start = count+9;
		var end = text.indexOf('&',start+1);
  	lastMessageDate = text.substring(start,end);
 		//alert(user + " Hai inviato l'ultimo messaggio <" + mess);
	}
  else
  {
  	if (text.indexOf('Non puoi eseguire una nuova ricerca') >=0)		
  		alert('Attendere 15 secondi');
  	//else
  		//alert('Utente messaggi 0');	
  }	
	
	return;
}

function getDiffHours(strDate)
{
	//alert(strDate);
	var o = new Date(strDate);
	if (o.toString() == 'NaN')
		return(-1);
	
	var o2 = new Date();
	//alert(o.toString());	
	
	var ms = o2.getTime() - o.getTime();
	
	out = ms/(3600*1000); 
		
	return (out);
}

