function getCommentsChunk(query, obj, cb, method) {
	if (typeof(cb) != "function" ) { cb = function () { return true; }; }
	if (method == null) { method == "GET" }	

	getChunk(query, obj,'', method);
}

var elForm = null;
var pageComment = 1;

function submitComment(form, id, tipochunk, parentComment, showform) {
	var limit = 5
	if (parentComment == null) {
		var parent = "";
	} else {
		var parent = "/" + parentComment;
	}


	if (showform == null) {
		showform == "true";
	}	

	var type = "/0";	// Comentario normal

	$('loading' + parentComment).style.display = 'block';
	$('captchaForm' + parentComment).style.display = 'none';
	
	adnCommand("/comments/newComment/" + id + type + parent, "POST" ,"nick=" + encodeURIComponent(form.nombre.value) + "&text=" + encodeURIComponent(form.text.value) + "&mail=" + encodeURIComponent(form.mail.value) + "&captcha=" + encodeURIComponent(form.captcha.value),
		   function (ret) {		  
			if(ret["code"] == 0 ){

							   // RECARGAMOS SOLO LA CAPA
			   if(typeof(comments_reload_page) != "undefined" 
			      && typeof(urlComments) != "undefined") {
				   
				   if(comments_reload_page == 0) {
					   var aux = urlComments.split("/");
					   aux[5] = 1;
					   
					   jQuery("#comentarios").load(aux.join("/"), function () {

						   jQuery(".closeCaptcha").click();
						   ADN.reload_all();
						   /*
						   if (email != null && email !="") {
							   jQuery("#commentsForm{{VAR:parentComment}} input[@name=mail]").val(email);				
						   }
						   if (nick != null && nick !="") {				
							   jQuery("#commentsForm{{VAR:parentComment}} input[@name=nombre]").val(nick);
						   }	
	
						   if (isAuthUser) {
							   jQuery("#identificate").hide();
						   } else {	
							   jQuery("#identificate").show();
						   }
*/

					   });
					   return false;
				   }

			   }


				var _url = location.href.split("#");
				if(parentComment != "") { 					
					if(location.href != _url[0] + "#comment_" + pageComment + "_" + parentComment) {
						location.href=_url[0] + "#comment_" + pageComment + "_" + parentComment;
						location.reload(true);
					} else {						
						location.reload(true);
					}

				} else {
					if(location.href != "#comment_" + pageComment + "_" + parentComment) {						 	 
						location.href=_url[0] + "#a_comentarios";
						location.reload(true);
					} else {
						location.reload(true);
					}
				}					
			} else {
			        $('loading' + parentComment).style.display = 'none';
			        $('captchaForm' + parentComment).style.display = 'block';
				alert(ret["message"])
			}	
		}, true);

	return false;
}

function submitComment2(form, id, tipochunk, parentComment, showform) {	
	var limit = 5
	if (parentComment == null) {
		var parent = "";
	} else {
		var parent = "/" + parentComment;
	}

	if (showform == null) {
		showform == "true";
	}	

	var type = "/0";	// Comentario normal

	jQuery(".loadingCaptchaForm").show();
	jQuery(".captchaForm").hide();

	adnCommand("/comments/newComment/" + id + type + parent, "POST" ,"nick=" + encodeURIComponent(form.nombre.value) + "&text=" + encodeURIComponent(form.text.value) + "&mail=" + encodeURIComponent(form.mail.value) + "&captcha=" + encodeURIComponent(jQuery("#captchaText").val()),
		   function (ret) {
         		   if(ret["code"] == 0 ){				
			   // RECARGAMOS SOLO LA CAPA
			   if(typeof(comments_reload_page) != "undefined" 
			      && typeof(urlComments) != "undefined") {
				   
				   if(comments_reload_page == 0) {
					   var aux = urlComments.split("/");
					   aux[5] = 1;
					   
					   jQuery("#comentarios").load(aux.join("/"), function () {
						   jQuery(".closeCaptcha").click();
						   ADN.reload_all();
						   /*
						   if (email != null && email !="") {
							   jQuery("#commentsForm{{VAR:parentComment}} input[@name=mail]").val(email);				
						   }
						   
						   if (nick != null && nick !="") {				
							   jQuery("#commentsForm{{VAR:parentComment}} input[@name=nombre]").val(nick);
						   }	

						   if (isAuthUser) {
							   jQuery("#identificate").hide();
						   } else {	
							   jQuery("#identificate").show();
						   }
*/

					   });
					   return false;
				   }

			   }

			   // RECARGAMOS LA PAGINA COMPLETA
		   	var _page = location.hash.split("_");
		   	if(_page.length == 3) {
		   		_page = _page[1];
		   	}
		   	else {
		   		_page = 0;
		   	}

				if(typeof(comments_submit_callback) == "function") {
					comments_submit_callback(ret);
					return false;
				}
				location.href = ret["data"];				
				if(parseInt(_page) <= 1) {
					location.reload(true);
				}					

			} else {
				jQuery(".loadingCaptchaForm").hide();
				jQuery(".captchaForm").show();
				alert(ret["message"])
			}	
		}, true);

	return false;
}

function submitQuestion(form, id, tipochunk) {	
	var limit = 5

	var type = "/1";	// Comentario pregunta

	$('loading_2').style.display = 'block';
	jQuery('#loading_2').html("Cargando...");
	$('captchaForm_2').style.display = 'none';
 	adnCommand("/comments/newComment/" + id + type, "POST" ,"nick=" + encodeURIComponent(form.nombre.value) + "&text=" + encodeURIComponent(form.text.value) + "&mail=" + encodeURIComponent(form.mail.value) + "&captcha=" + encodeURIComponent(form.captcha.value),
		   function (ret) {		  
			   if(ret["code"] == 0 ){				
 
				   jQuery('#loading_2').html("Muchas gracias por enviar su pregunta.<br/>En breve será dada de alta por nuestros moderadores");
				   jQuery(".capa_popup_cont .cerrar").click(function () {
					   $('loading_2').style.display = 'none';
					   $('captchaForm_2').style.display = 'block';
					   jQuery("#interview-ask").hide();
					   location.reload(true);
					   
				   });
				   
		   } else {
			        $('loading_2').style.display = 'none';
			        $('captchaForm_2').style.display = 'block';
				alert(ret["message"])
			}	
		}, true);

	return false;
}

function sendAbuse(contentId, commentId) {
	var _search_form = "#commentsAbuseForm" + commentId;
	var _nombre = jQuery(_search_form + " input[name='nombre']").val();
	var _mensaje = jQuery(_search_form + " textarea[name='mensaje']").val();
	var _email = jQuery(_search_form + " input[name='mail']").val();
	var _captcha = jQuery("#captchaText").val();

	if(jQuery.trim(_mensaje) == "") {
		alert("Introduzca un mensaje valido");
		return false;
	}

	if(!validateNick(_nombre)) {
		alert("Nombre no valido");
		return false;
	}

	if(!validateEmail(_email)) {
		alert("Email no valido");
		return false;
	}
	
	jQuery(".captchaForm").hide();
	jQuery(".loadingCaptchaForm").show();
	
	var query_data = {  nombre: _nombre, 
			    mensaje: _mensaje,
			    email: _email,
			    captcha: _captcha,
			    contentId: 	contentId,
			    commentId: 	commentId
			 };

	jQuery.post("/comments/sendAbuse", query_data, function(data) {
		if(data["error"] == 0) {			
			jQuery(".loadingCaptchaForm").hide();
			jQuery("#mensajeResponse").html("<p>" + unescape(data["message"]) + "</p>");
			jQuery("#mensajeResponse").show();
		}
		else {
			jQuery(".captchaForm").show();
			jQuery(".loadingCaptchaForm").hide();		
			alert(unescape(data["message"]));
		}
	},  "json");
}
jQuery(document).ready(function() {
	jQuery(".closeCaptcha").click(function() {	
		jQuery("#captchaForm").show();
	 	jQuery("#mensajeResponse").hide();
	 	jQuery("#loading").hide();
	 	jQuery("#captchaText").empty();
	 	closeDiv('layerCaptcha')
	 	return false
	});
});