$(document).ready ( function() {
	//resto
	$("#form_comentario").submit( function() {
		//Comprobamos que no hay error de validación
		var error_validacion = false;
		$("input, select, textarea", this).each( function() {
			if ($(this).hasClass("error")) {
					error_validacion = true;
			}
		});
		if (!error_validacion) {
			var idf = $("#id_foro").val();
			var idn = $("#id_noti").val();
			var nom = $("#nombre").val();
			var mail= $("#email").val();
			var com = $("#comentario").val();
			nom = trataEspeciales(nom,true);
			com = convierte_saltos_de_linea(com);
		  com = trataEspeciales(com,true);
		  nom = trataEspeciales(nom,true);
		  com = procesos(com,221);
			$("#capa_formulario").load("http://" + location.host + "/captcha/captcha_noticia.asp", {id_foro:idf, id_noti:idn, nombre:nom, email:mail, comentario:com}, function() {
				$("#form_comentario").submit( function() {
					var error = false;
					$("input, select, textarea", "#form_comentario").each( function() {
						if ($(this).attr("class")) {
							if (!validateField(this)) error = true;
						}
					});
					if (!error) {
						$("#texto_captcha").val($("#texto_captcha").val().toUpperCase());
						url = "http://" + location.host + "/foros/insertar_comentario_x.asp";
						texto_captcha = $("#texto_captcha").val();
						$.post(url, { nombre:nom, email:mail, comentario:com, texto_captcha:texto_captcha, id_foro:idf, noticia:idn }, resultado_form_comentario);
						return false;
					} else {
						return false;
					}
				});
			});
			return false;
		} else {
			return false;
		}
	});
});

function resultado_form_comentario(data) {
	$("#capa_formulario").html(data);
}
function ventana_condiciones() {
	window.open("","condiciones","width=400,height=550");
}

function convierte_saltos_de_linea(cadena) {
	texto = cadena;
	if (navigator.platform=="Win32" && navigator.appName!="Netscape") {
		rExp = /(\r\n)+/gi;
		texto = texto.replace(rExp,"<br />")
	}
	else if (navigator.platform=="MacPPC" && texto.charAt(texto.length-1)!='\r') {
		rExp = /(\n)+/gi;
		texto = texto.replace(rExp,"<br />")
	}
	else if (navigator.appName=="Netscape") {
		rExp = /(\n)+/gi;
		texto = texto.replace(rExp,"<br />")
	}
	else {
		rExp = /[\f\n\r]+/gi;
		texto = texto.replace(rExp,"<br />")
	}
	return texto;
}