var xmlHttp
var idobj
var oldhtml
var textareaid

function openCom(idcom,tipo){

	var html="";
	html+= "<div class='commentoart'>\n";
	html+= "<textarea id='c"+idcom+"_get' name='commento' cols='50' rows='3' ></textarea><br/>\n";
	html+= "<input id='postbt' name='postbt' type='button' class='f_submit' value='Post' onclick=\"savecomment('"+idcom+"',"+tipo+")\" />\n";
	html+= "</div>\n";
		
	if(oldhtml)oldhtml.innerHTML = "";		
	document.getElementById('com'+idcom).innerHTML=html;
 	document.getElementById("c"+idcom+"_get").focus();
 	oldhtml = document.getElementById('com'+idcom);
	
} 

function savecomment(id,tipo){

    var comxmlHttp		= GetXmlHttpObject() //See if it works with users browser.
 	 
   	var url 			= RootPath+"www/ajaxindex.php?pag=ajaxphp/social/SetCommenti.php";
   	 	
	var commento 		= document.getElementById("c"+id+"_get").value;
	
	var params  		= Array();
	
	params.push('id='+id);
	params.push('message=' + commento);
	params.push('fpage=ins');
	params.push('tipo='+tipo);
	
	var mypars  = params.join("&");
	
	comxmlHttp.open("POST", url, true);
	
    comxmlHttp.obj = 'combox'+id;

	//Send the proper header information along with the request
	comxmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	comxmlHttp.setRequestHeader("Content-length", params.length);
	comxmlHttp.setRequestHeader("Connection", "close");
	comxmlHttp.onreadystatechange = function(){
									 if (comxmlHttp.readyState==4 || comxmlHttp.readyState=="complete")
									 { 
									 document.getElementById(this.obj).innerHTML=comxmlHttp.responseText;
									 } 
							     };
	comxmlHttp.send(mypars);

}

function savemsg(id){
    xmlHttp		= GetXmlHttpObject() //See if it works with users browser.
   	
   	var url 	= RootPath+"www/ajaxindex.php?pag=ajaxphp/social/SetCommenti.php";
	
	commento 	= document.getElementById("c"+id+"_get").value;
	document.getElementById("c"+id+"_get").value = "";
	var params  = Array();
	params.push('id='+id);
	params.push('message=' + commento);
	params.push('fpage=insmsg');
	var mypars  = params.join("&");
	
	xmlHttp.open("POST", url, true);
	
	xmlHttp.obj		= 'combox'+id;

	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.onreadystatechange=function(){
									 if (comxmlHttp.readyState==4 || comxmlHttp.readyState=="complete")
									 { 
									 document.getElementById(this.obj).innerHTML=comxmlHttp.responseText;
									 } 
							     };
	xmlHttp.send(mypars);

}

function delCom(id,idc){
	
	Msg="Sei sicuro di voler eliminare il tuo commento?";
	
	var agree=confirm(Msg);
	if (agree){
						
			if(idobj!=null){ document.getElementById(idobj).innerHTML=oldhtml }
			idobj 		= 'com'+id;
			oldhtml 	= document.getElementById(idobj).innerHTML;
			
			xmlHttp		= GetXmlHttpObject() //See if it works with users browser.

		   	var url 	= RootPath+"www/ajaxindex.php?pag=ajaxphp/social/SetCommenti.php";
				
			var params  = Array();
			params.push('id='+id);
			params.push('idc='+idc);
			params.push('fpage=del');
			var mypars  = params.join("&");
			
			xmlHttp.open("POST", url, true);
			
			idobj 		= 'combox'+id;
		
			//Send the proper header information along with the request
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", params.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange=function() 
								{ 
								if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
								 { 
								 document.getElementById(idobj).innerHTML = xmlHttp.responseText;
								 oldhtml 	= document.getElementById(idobj).innerHTML;
								 } 
								};;
			xmlHttp.send(mypars);
	
	}else{
		return false ;
	}
					
}

function delUpd(id,idc){
	
	Msg="Sei sicuro di voler eliminare il tuo aggiornamento ed i commenti associati?";
	
	var agree=confirm(Msg);
	if (agree){
						
			//if(idobj!=null){ document.getElementById(idobj).innerHTML=oldhtml }
			idobj 		= 'com'+id;
			oldhtml 	= document.getElementById(idobj).innerHTML;
			
			xmlHttp		= GetXmlHttpObject() //See if it works with users browser.

		   	var url 	= RootPath+"www/ajaxindex.php?pag=ajaxphp/social/SetCommenti.php";
		
			var params  = Array();
			params.push('id='+id);
			params.push('fpage=delup');
			var mypars  = params.join("&");
			
			xmlHttp.open("POST", url, true);
			
			xmlHttp.obj = 'combox'+id;
		
			//Send the proper header information along with the request
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", params.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange=function(){
										if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
										 { 
										 document.getElementById(this.obj).innerHTML=xmlHttp.responseText;
										 } 
										};
			xmlHttp.send(mypars);
	
	}else{
		return false ;
	}
					
}



function sendListMsg(userp){
	
	xmlHttp		= GetXmlHttpObject() //See if it works with users browser.

   	var url 	= RootPath+"www/ajaxindex.php?pag=ajaxphp/social/SetCommenti.php";
   	   	
	commento 	= document.getElementById("lmsg").value;
	
	document.getElementById("lmsg").value="";
	
	var params  = Array();
	params.push('message=' + commento);
	params.push('userpage=' + userp);
	params.push('fpage=lmsg');
	var mypars  = params.join("&");
	
	xmlHttp.open("POST", url, true);
	
	idobj 		= 'loglist';

	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.onreadystatechange=function() 
								{ 
								if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
								 { 
								 document.getElementById(idobj).innerHTML = xmlHttp.responseText;
								 oldhtml 	= document.getElementById(idobj).innerHTML;
								 } 
								};
	xmlHttp.send(mypars);
	
}





function setMail(id,oper,area){
	
	if(oper=='delMail'){
		Msg="Sei sicuro di voler eliminare la mail?";
		var agree = confirm(Msg);
	}else{
		agree=1;
	}

	if (agree){
 
 		  var listid=Array();

		  var el=document.getElementById('maillist');
		  
		  var divs=el.getElementsByTagName('input');
	
		  if(id==""){
			  for (var i=0; i<divs.length;i++) {
					if (divs[i].type == 'checkbox') {
						if(divs[i].checked==true){
							listid.push(divs[i].value);
						}
					}
			  }
		  }else{
			  listid.push(id);
		  }
		
			var mylistid  = listid.join(",");

			xmlHttp		= GetXmlHttpObject() //See if it works with users browser.

		   	var url 	= RootPath+"www/ajaxindex.php?pag=ajaxphp/social/SetMail.php";		
		
			var params  = Array();
			params.push('id='+mylistid);
			params.push('area='+area);
			params.push('oper='+oper);
			var mypars  = params.join("&");
			
			xmlHttp.open("POST", url, true);
			
			xmlHttp.obj 		= 'maillist';
		
			//Send the proper header information along with the request
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", params.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange=function(){
										if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
										 { 
										 document.getElementById(this.obj).innerHTML = xmlHttp.responseText;
										 } 
										};
			xmlHttp.send(mypars);

	}else{
		return false ;
	}
					
}

