﻿tinyMCE.init({
	theme : "advanced",
	mode : "exact",
	elements : "mailbody",

	theme_advanced_disable : "help, code, formatselect, styleselect, cleanup, visualaid, anchor, hr, removeformat, sub, sup, charmap, separator", 
	theme_advanced_toolbar_align : "center",
	
	theme_advanced_buttons1_add: "forecolor, fontsizeselect",
	theme_advanced_buttons2_add: "hr, removeformat",
	
	doctype : '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">',
	language : "es",
	
	debug : false
});

function validarMail() {
	var msg;
	var campo;
	var id;
	var i1;
	var i2;
	
	// validar nombre
	id = "mailfromname";
	campo = document.getElementById(id);
	if (campo.value == null || campo.value == "") {
		msg = "Indique un nombre con el que dirigirse a usted.";
		alert(msg);
		campo.focus();
		return false;
	}

	// validar email
	id = "mailfrom";
	campo = document.getElementById(id);
	if (campo.value == null || campo.value == "") {
		msg = "Escriba la dirección de correo donde recibirá la respuesta.";
		alert(msg);
		campo.focus();
		return false;
	} else {
		i1 = campo.value.indexOf("@");
		i2 = campo.value.indexOf(".");
		if (i1 == -1 || i2 == -1 || i2 < i1) {
			msg = "La dirección de correo indicada parece incorrecta, vuelva a comprobarla.";
			alert(msg);
			campo.focus();
			return false;
		}
	}

	// validar mensaje
	id = "mailbody";
	tinyMCE.triggerSave();
	campo = document.getElementById(id);
	if (campo.value == null || campo.value == "") {
		msg = "Escriba el mensaje que desea enviar.";
		alert(msg);
		campo.focus();
		return false;
	}

	// validar asunto
	id = "mailsubject";
	campo = document.getElementById(id);
	if (campo.value == null || campo.value == "") {
		msg = "No ha indicado el asunto del mensaje.\n ¿Desea continuar?";
		if (!confirm(msg)) {
			campo.focus();
			return false;
		}
	}

	return true;
}
