var mCat = '', mNom = '', mPsw = '';


function repChrs(msg)
{
	var tmsg = msg;
	tmsg = tmsg.replace("à", "a'");
	tmsg = tmsg.replace("è", "e'");
	tmsg = tmsg.replace("é", "e'");
	tmsg = tmsg.replace("ì", "i'");		
	tmsg = tmsg.replace("ò", "o'");
	tmsg = tmsg.replace("ù", "u'");
	//tmsg = tmsg.replace("'", "´");		
	//while(tmsg.indexOf('\n') >= 0)
		//tmsg = tmsg.replace('\n','%0d%0a');	
	return tmsg;
}



function parseFrmComment()
{
	var tipObj = fcom.tip;
	var msg = '';
	var tip = '';
	var psw = '';	
	for(var i=0; i<tipObj.length; i++)
	  if(tipObj[i].checked) 
		tip = tipObj[i].value;

	msg += 'cmd=cmm';		
	msg += '&nom='+fcom.nom.value;
	msg += '&psw='+fcom.psw.value;
	msg += '&tip='+tip;
	msg += '&msg='+repChrs(encodeURIComponent(fcom.msg.value));

	mNom = fcom.nom.value;
	mPsw = fcom.psw.value;	
	
	// mod comm
	if(tip == 'mod')
	{
		modComm(tip,'','cres');
		return;
		//window.parent.ASlnk('pag/docs/messaggi/?'+msg);		
		//document.title = res + ' - ' + new Date().getTime();		
	}	
	
	Ajaxres('messaggi/pub.php',msg,'cres');
}




function getComments(cat)
{
	mCat = cat;
	var msg = '';
	msg += '&cat='+cat;
	//document.title = cat;	
	Ajaxres('messaggi/get.php',msg,'comm');
}




function getFotos(cat)
{
	mCat = cat;
	var msg = '';
	msg += '&cat='+cat;
	//document.title = msg;
	Ajaxres('foto/get.php',msg,'fots');
}




function getNews(cat)
{
	mCat = cat;
	var msg = '';
	msg += '&cat='+cat;
	//document.title = msg;
	Ajaxres('news/get.php',msg,'nws');
	Ajaxres('news/lnkn.php',msg,'lnkn');	
}




function modComm(cmd,idx,res)
{
	var msg = '';
	msg += '&cmd='+cmd;
	msg += '&nom='+mNom;
	msg += '&psw='+mPsw;
	msg += '&cat='+mCat;
	msg += '&idx='+idx;	
	
	if(cmd == 'sav')  
	{
		//document.title += document.getElementById('txa'+idx).value;		
		msg += '&txa='+repChrs(encodeURIComponent(document.getElementById('txa'+idx).value));
	}
	
	Ajaxres('messaggi/mod.php',msg,res);		
}




function Ajaxres(prg,msg,res)
{
	var host = 'http://www.criticalmasscatania.it/it/';
	//var host = 'http://127.0.0.1/cmct/it/';
	
	var ajxres = false;
	try{ajxres = new ActiveXObject("Msxml2.XMLHTTP");}
	catch(e){try{ajxres = new ActiveXObject("Microsoft.XMLHTTP");}
	catch(e){ajxres = false;}}
	if(!ajxres && typeof XMLHttpRequest != 'undefined'){ajxres = new XMLHttpRequest();}
	if(ajxres)
	{
		ajxres.open('POST',host+prg);
		ajxres.setRequestHeader('content-type','application/x-www-form-urlencoded');
		ajxres.onreadystatechange = function() 
		{
			if(ajxres.readyState == 4 && ajxres.status == 200) 
			{
				//document.getElementById(res).innerHTML = ajxres.responseText;	//encodeURIComponent
				responseAction(res,ajxres.responseText);
			}
		}
		ajxres.send(msg);
	}
	else
	{
		//document.getElementById(res).style.background = '#000000';
		document.getElementById(res).innerHTML = '';
	}
}




function responseAction(res,txt)
{
	if(txt.indexOf('modok') > -1) 
	{
		modComm('get','','comm');
		return;
	}
try{	
	document.getElementById(res).innerHTML = txt;
}catch(e){;}
finally{;}	
}



function visEmoticon(hit)
{
	document.getElementById('btnEmo').style.display = 'none';	
	document.getElementById('emos').style.display = 'block';
}


function getEmoticon(hit)
{
	document.title = hit;
	document.getElementById('msg').innerHTML += hit;	
}



///////////
ppiu = new Image(18,16);
ppiu.src = 'img/piu.gif';
pmno = new Image(18,16);
pmno.src = 'img/mno.gif';


function flip(det) 
{	disp = document.getElementById(det).style.display;
	//window.parent.document.title = disp;
	if(disp == 'none') 
	{document.getElementById(det).style.display = 'block';
     document.images['img'+det].src = pmno.src;
	}	
   if(disp == 'block' || disp == '')  
   { document.getElementById(det).style.display = 'none';
      document.images['img'+det].src = ppiu.src;
   }
}