function publicarMuroFacebook(comment){
	var attachment = {'name': document.title,
					  'href':document.URL,
					  'description':'View: '+document.URL
					  };
	//FB.Connect.streamPublish(comment,attachment,'','',document.title);
	FB.ui({
		method: 'feed',
		name: document.title,
		link: document.URL,
		description: 'View: '+document.URL,
		message: comment
	});
}


function getComments(content_id,comment_type,pag,porPagina,div_where){
	var xP='controller=getComments';
	xP = xP + '&content_id=' + content_id;
	xP = xP + '&comment_type=' + comment_type;
	xP = xP + '&pag=' + pag;
	xP = xP + '&porPagina=' + porPagina;
	goAJAX(div_where,'engines/comments/comments.ajax.php',xP);
	return false;
	}

function publishComment(content_id,comment_type,div_where,comm_mode){
	$('buttonsFTW').setStyle({ display: 'none' });	
	
	if (isDefined(comm_mode)) { 
		comm_mode = comm_mode;
	} else {
		comm_mode = 3;
	}
	
	var xP='&controller=publishComment';
	xP = xP + '&content_id=' + content_id;
	xP = xP + '&comment_type=' + comment_type;
	xP = xP + '&comm_mode=' + comm_mode;
	xP = xP + '&div_where=' + div_where;
	xP = xP + '&name=' + GetId('name').value;
	xP = xP + '&email=' + GetId('email').value;
	
	if(GetId('emailme').checked == true && GetId('email').value != ''){
		xP = xP + '&emailme=si';
	}else{
		xP = xP + '&emailme=no';
	}
	
	xP = xP + '&comment=' + escape(GetId('frmLeaveComment').txtComment.value);
	xP = xP + '&session=' + getSession();	
	
	var session = getSession();
	if(session == '' || session == 'a'){
		if(document.frmLeaveComment.name.value == ''){
			alert('Name is required');
			return 0; 
		}
		if(document.frmLeaveComment.email.value == ''){
			alert('Email is required');
			return 0; 
		}
	}
	
	var url = 'engines/comments/comments.ajax.php';

	var peticion = new Ajax.Request(url, 
	{
		method:'post',
		postBody: xP,
		onSuccess: 
			function(respuesta) {
			  	datos = respuesta.responseText;
				
				if(datos == 'noUser') {
					$('buttonsFTW').show();
				}else
					$(div_where).innerHTML = datos;		
						  
			}, 
		onFailure: function() { alert('Se ha producido un error'); }
	});

	return false;
	
	
}



function publishReply(comment_id,content_id,comment_type,div_where,comm_mode){
	

	//$('buttonsFTW'+comment_id).setStyle({ display: 'none' });	

	if (isDefined(comm_mode)) { 
		comm_mode = comm_mode;
	} else {
		comm_mode = 3;
	}
	
	
	var xP='controller=publishReply';
	xP = xP + '&comment_id=' + comment_id;
	xP = xP + '&content_id=' + content_id;
	xP = xP + '&comment_type=' + comment_type;
	xP = xP + '&comm_mode=' + comm_mode;
	xP = xP + '&div_where=' + div_where;
	xP = xP + '&name=' + $F('nameReply'+comment_id);
	xP = xP + '&email=' + $F('emailReply'+comment_id);
	
	if(GetId('emailmeReply'+comment_id).checked == true && GetId('emailReply'+comment_id).value != ''){
		xP = xP + '&emailme=si';
	}else{
		xP = xP + '&emailme=no';
	}
	xP = xP + '&comment=' + escape($F('txtCommentReply'+comment_id));
	xP = xP + '&session=' + getSession();	
	
	var session = getSession();
	if(session == '' || session == 'a'){
		if($F('nameReply'+comment_id) == ''){
			alert('Name is required');
			return 0; 
		}
		if($F('emailReply'+comment_id) == ''){
			alert('Email is required');
			return 0; 
		}
	}

	/*try{
		tinyMCE.execCommand('mceRemoveControl', false, 'txtComment');
	}catch(e){}*/
	//goAJAX(div_where,'engines/comments/comments.ajax.php',xP);	
	var url = 'engines/comments/comments.ajax.php';

	var peticion = new Ajax.Request(url, 
	{
		method:'post',
		postBody: xP,
		onSuccess: 
			function(respuesta) {
			  	datos = respuesta.responseText;
				if(datos == 'noUser')
				{
/*					$$('.buttonsFTW').each(
						function(n) {
							n.show();
						}
					)					
*/
					$('buttonsFTW'+comment_id).show();					
				}
				else
					$(div_where).innerHTML = datos;			  
			}, 
		onFailure: function() { alert('Se ha producido un error'); }
	});

	return false;
}


function verifySession(content_id,comment_type,div_where){
	document.getElementById("profileFacebook").style.display = "none";
	document.getElementById("profileTwitter").style.display = "none";
	
	var parametersPOST = 'controller=verifySession';
	var url = 'engines/comments/comments.ajax.php';
	var peticion = new Ajax.Request(url, 
	{
		method:'post',
		postBody: parametersPOST,
		onSuccess: 
			function(respuesta) {
			  datos = respuesta.responseText;
			  if(datos == '1'){
				  setSession("w");												//pone la variable de sistema a "w" -> wehaa
				  
				  //loadSubmitComment(content_id,comment_type,div_where);
			  }else{
			  	   showSignInWindow();
				   //verifySession(content_id,comment_type,div_where);
			  }
			}, 
		onFailure: function() { alert('Se ha producido un error'); }
	});
return false;
}

function verifySessionReply(comment_id,content_id,comment_type){
	document.getElementById("profileFacebookReply"+comment_id).style.display = "none";
	document.getElementById("profileTwitterReply"+comment_id).style.display = "none";
	
	var parametersPOST = 'controller=verifySession';
	var url = 'engines/comments/comments.ajax.php';
	var peticion = new Ajax.Request(url, 
	{
		method:'post',
		postBody: parametersPOST,
		onSuccess: 
			function(respuesta) {
			  datos = respuesta.responseText;
			  if(datos == '1'){
				  setSession("w");												//pone la variable de sistema a "w" -> wehaa
				  winReplyComment(comment_id,content_id,comment_type)
				  //loadSubmitComment(content_id,comment_type,div_where);
			  }else{
			  	   showSignInWindow();
				   //verifySession(content_id,comment_type,div_where);
			  }
			}, 
		onFailure: function() { alert('Se ha producido un error'); }
	});
return false;
}


function verifySessionTwitter(content_id,comment_type,div_where){
	var parametersPOST = 'controller=verifySessionTwitter';
	var url = 'engines/comments/comments.ajax.php';
	var peticion = new Ajax.Request(url,{method:'post',postBody: parametersPOST,onSuccess: 
			function(respuesta) {
			  datos = respuesta.responseText;
			  if(datos == '1'){
				  var xP ='link=si';
				  xP = xP + '&field=profile';  // PROFILE no es un campo sino sue obtiene la img y el nombre completo
				  goAJAX("profileTwitterContent",'inc/twitter/getParams.php',xP,' ');
				  document.getElementById("profileFacebook").style.display =  'none';
				  document.getElementById("profileTwitter").style.display =  'inline';
				  setSession("t");												//pone la variable de sistema a "t" -> Twitter
				  //loadSubmitComment(content_id,comment_type,div_where);
			  }else{
			      verifySessionTwitterOpen(content_id,comment_type,div_where) // llama al twiter index
			  }
			  
			}, 
		onFailure: function() { alert('Se ha producido un error'); }
	});
return false;
}



function verifySessionTwitterOpen(content_id,comment_type,div_where){
	document.getElementById("profileFacebook").style.display = "none";
	
	// establece que el div que el profile que debe mostrar es Comment
	document.getElementById("paramsTwitter").innerHTML = 'C';
	
	var parametersPOST = '';
	//var url = 'engines/comments/comments.ajax.php';
	var url = 'inc/twitter/index.php';
	var peticion = new Ajax.Request(url, 
	{
		method:'post',
		postBody: parametersPOST,
		onSuccess: 
			function(respuesta) {
			  datos = respuesta.responseText;
			  
			  if(datos.substr(0,5) == 'https'){
					var left = (screen.availWidth - 800) / 2; 
				    var top = (screen.availHeight - 400) / 2; 
					
					window.open(datos,'Connect white Twitter','width=800,height=400,toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,top='+top+',left='+left);
			  }else{
				  var xP ='link=si';
				  xP = xP + '&field=profile';  // PROFILE no es un campo sino sue obtiene la img y el nombre completo
				  goAJAX('profileTwitterContent','inc/twitter/getParams.php',xP,' ');
				  document.getElementById("profileTwitter").style.display = "inline";
				  
				  setSession("t");												//pone la variable de sistema a "t" -> Twitter
				  //loadSubmitComment(content_id,comment_type,div_where);
			  }
			  
			}, 
		onFailure: function() { alert('Se ha producido un error'); }
	});
return false;
}





function verifySessionTwitterReply(comment_id,content_id,comment_type){
	var parametersPOST = 'controller=verifySessionTwitter';
	var url = 'engines/comments/comments.ajax.php';
	var peticion = new Ajax.Request(url,{method:'post',postBody: parametersPOST,onSuccess: 
			function(respuesta) {
			  datos = respuesta.responseText;
			  if(datos == '1'){
				  var xP ='link=si';
				  xP = xP + '&field=profile';  // PROFILE no es un campo sino sue obtiene la img y el nombre completo
				  goAJAX("profileTwitterReplyContent"+comment_id,'inc/twitter/getParams.php',xP,' ');
				  document.getElementById("profileFacebookReply"+comment_id).style.display =  'none';
				  document.getElementById("profileTwitterReply"+comment_id).style.display =  'inline';
				  setSession("t");												//pone la variable de sistema a "t" -> Twitter
				  loadUserbox();
				  //winReplyComment(comment_id,content_id,comment_type);
			  }else{
			      verifySessionTwitterReplyOpen(comment_id,content_id,comment_type); // llama al twiter index
			  }
			  
			}, 
		onFailure: function() { alert('Se ha producido un error'); }
	});
return false;
}


function verifySessionTwitterReplyOpen(comment_id,content_id,comment_type){
	// establece que el div que el profile que debe mostrar es Reply y guarda el id	del comment
	document.getElementById("paramsTwitter").innerHTML = comment_id;
	
	var parametersPOST = '';

	//var url = 'engines/comments/comments.ajax.php';
	var url = 'inc/twitter/index.php';
	var peticion = new Ajax.Request(url,{method:'post',postBody: parametersPOST,onSuccess: 
	function(respuesta) {
	  datos = respuesta.responseText;
	  if(datos.substr(0,5) == 'https'){
		var left = (screen.availWidth - 800) / 2; 
		var top = (screen.availHeight - 400) / 2; 
		window.open(datos,'Connect white Twitter','width=800,height=400,toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,top='+top+',left='+left);
	  }else{
		  var xP ='link=si';
		  xP = xP + '&field=profile';  // PROFILE no es un campo sino sue obtiene la img y el nombre completo
		  goAJAX("profileTwitterReply"+comment_id,'inc/twitter/getParams.php',xP,' ');
		  document.getElementById("profileTwitterReplyContent"+comment_id).style.display = "inline";
		  
		  setSession("t");												//pone la variable de sistema a "t" -> Twitter
		  //winReplyComment(comment_id,content_id,comment_type);
	  }
	}, 
   onFailure: function() { alert('Se ha producido un error'); }
});
return false;
}

function loadSubmitComment(content_id,comment_type,div_where,comm_mode){

	//document.getElementById("useProfile").style.display = "";
	try{tinyMCE.execCommand('mceRemoveControl', false, 'txtComment');}catch(e){}
/*	try{tinyMCE.execCommand('mceRemoveControl', false, 'txtCommentReply');}catch(e){}*/
	
	var xP='controller=loadSubmitComment';
	xP = xP + '&content_id=' + content_id;
	xP = xP + '&comment_type=' + comment_type;
	xP = xP + '&div_where=' + div_where;
	xP = xP + '&comm_mode=' + comm_mode;
	goAJAX(div_where,'engines/comments/comments.ajax.php',xP,'try{toggleEditor(\'txtComment\');}catch(e){}	');

	GetId(div_where).style.display='';
}
function loadSubmitCommentEditor(){
		try{tinyMCE.execCommand('mceRemoveControl', false, 'txtComment');}catch(e){}
		try{tinyMCE.execCommand('mceRemoveControl', false, 'txtCommentReply');}catch(e){}
		//tinyMCE.execCommand('mceAddControl', false, 'txtComment');		
		toggleEditor('txtCommentReply');
		}



function loadReplyComment(comment_id,content_id,comment_type,div_where,comm_mode){

	//document.getElementById("useProfile").style.display = "";
/*	try{tinyMCE.execCommand('mceRemoveControl', false, 'txtComment');}catch(e){}*/
	try{tinyMCE.execCommand('mceRemoveControl', false, 'txtCommentReply'+comment_id);}catch(e){}
	
	var xP='controller=winReplyComment';
	xP = xP + '&comment_id=' + comment_id;
	xP = xP + '&content_id=' + content_id;
	xP = xP + '&div_where=' + div_where;
	xP = xP + '&comment_type=' + comment_type;
	xP = xP + '&comm_mode=' + comm_mode;
	goAJAX(div_where,'engines/comments/comments.ajax.php',xP,'try{toggleEditor(\'txtCommentReply'+comment_id+'\');}catch(e){}	');


	GetId(div_where).style.display='';
}

/*
function winReplyComment(comment_id,content_id,comment_type){
	try{tinyMCE.execCommand('mceRemoveControl', false, 'txtComment');}catch(e){}
	try{tinyMCE.execCommand('mceRemoveControl', false, 'txtCommentReply');}catch(e){}
	get('frmLeaveComment').innerHTML='';
	putIn('winTit400','Respond a comment');
	var xP='controller=winReplyComment';
	xP = xP + '&comment_id=' + comment_id;
	xP = xP + '&content_id=' + content_id;
	xP = xP + '&comment_type=' + comment_type;
	goAJAX('winCont400','engines/comments/comments.ajax.php',xP,'centerDivWindow(\'win400\');winReplyCommentEditor();');
	showWindow('win400');
	}
*/

function winReplyCommentEditor(){
		//try{tinyMCE.execCommand('mceRemoveControl', false, 'txtComment');}catch(e){}
		try{tinyMCE.execCommand('mceRemoveControl', false, 'txtCommentReply');}catch(e){}
		//tinyMCE.execCommand('mceAddControl', false, 'txtCommentReply');
		toggleEditor('txtCommentReply');
}










/*
function publishReply(comment_id,content_id,comment_type,Frm,comm_mode){
	
	comm_mode = typeof(comm_mode) != 'undefined' ? comm_mode : 3;
	try{tinyMCE.execCommand('mceRemoveControl', false, 'txtCommentReply');}catch(e){}
	var xP='controller=publishReply';
	xP = xP + '&comment_id=' + comment_id;
	xP = xP + '&content_id=' + content_id;
	xP = xP + '&comment_type=' + comment_type;
	xP = xP + '&comm_mode=' + comm_mode;
	
	//xP = xP + '&name=' + GetId(Frm).nameReply.value;
	xP = xP + '&email=' + GetId(Frm).emailReply.value;
	
	if(GetId(Frm).emailmeReply.checked == true && GetId(Frm).emailReply.value != ''){
		xP = xP + '&emailme=si';
	}else{
		xP = xP + '&emailme=no';
	}

	xP = xP + '&comment=' + escape(GetId(Frm).txtCommentReply.value);
	xP = xP + '&session=' + getSession();
	
	var session = getSession();
	if(session == '' || session == 'a'){
		if(document.frmLeaveComment.name.value == ''){
			alert('Name is required');
			return 0; 
		}
		if(document.frmLeaveComment.email.value == ''){
			alert('Email is required');
			return 0; 
		}	
	}
	
	//alert(xP);
	goAJAX(Frm,'engines/comments/comments.ajax.php',xP);
	return false;
}

*/
function checkLogin()
{
	var parametersPOST = 'controller=checkLogin';
	var url = 'engines/comments/comments.ajax.php';
	var peticion = new Ajax.Request(url, 
	{
		method:'post',
		postBody: parametersPOST,
		onSuccess: 
			function(respuesta) {
			  datos = respuesta.responseText;
			  if(datos == '1'){
				 	return true;
			  }else{
				  return false;
			  }
			}, 
		onFailure: function() { return false; }
	});	
}
