/* Este fichero contiene la clase Contacto, que será el manejador para dicho WebPage
 */


function Contacto()
{
	var regexp = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;


		this.fields = [	new Field("name", "text", 50, "not_null", ""),
					new Field("email", "text", 50, "not_null", ""),
					new Field("description", "blob", 255, "not_null", ""),
					new Field("style_desc", "blob", 255, "not_null", ""),
					new Field("colour_1", "text", 10, "not_null", ""),
					new Field("colour_2", "text", 10, "not_null", ""),
					new Field("colour_3", "text", 10, "not_null", ""),
					new Field("cont_forum", "int", 1, "", ""),
					new Field("cont_blog", "int", 1, "", ""),
					new Field("cont_users", "int", 1, "", ""),
					new Field("cont_chat", "int", 1, "", ""),
					new Field("cont_shop", "int", 1, "", ""),
					new Field("updates", "int", 1, "", "") ]


	this.conf  =
	[
		{ "data": { "name": "Nombre:" }  },
		{ "data": { "name": "E-mail:", "reg_exp": /./ } },
		{ "data": { "name": "Descripción general:" } },
		{ "data": { "name": "Descripción del estilo:" } },
		{ "data": { "name": "Color principal", "type": "radio", "select_values": { 1: "Azul", 2: "Verde", 3: "Rojo"} } },
		{ "data": { "name": "Color secundario", "type": "radio", "select_values": ["Marrón", "Amarillo", "Rosita" ] } },
		{ "data": { "name": "Color de fondo", "type": "radio", "select_values": ["Azul cielo", "Verde moco", "Rojo Infierno"] } },
		{ "data": { "name": "Contenido: FORO", "type": "checkbox" } },
		{ "data": { "name": "Contenido: BLOG", "type": "checkbox" } },
		{ "data": { "name": "Contenido: REGISTRO USUARIOS", "type": "checkbox" } },
		{ "data": { "name": "Contenido: CHAT", "type": "checkbox" } },
		{ "data": { "name": "Contenido: TIENDA", "type": "checkbox" } },
		{ "data": { "name": "Actualización de contenidos", "type": "checkbox" } }
	];

	
	this.def_conf =
	{
		par:
		{
			input:
			{
				class_names:
				{
					div_cell:		"field selected_field",
					div_title:		"label",
					div_input:		"input",
					div_error:		"fr"
				}
			}
		},

		impar:
		{
			input:
			{
				class_names:
				{
					div_cell:		"field nonselected_field",
					div_title:		"label",
					div_input:		"input",
					div_error:		"fr"
				}
			}
		}
	};


}


Contacto.prototype =
{
	onLoadPage:			function()
	{

		this.fields = [	new Field("name", "text", 50, "not_null", ""),
						new Field("email", "text", 50, "not_null", ""),
						new Field("description", "blob", 255, "not_null", ""),
						new Field("style_desc", "blob", 255, "not_null", ""),
						new Field("colour_1", "text", 10, "not_null", ""),
						new Field("colour_2", "text", 10, "not_null", ""),
						new Field("colour_3", "text", 10, "not_null", ""),
						new Field("cont_forum", "int", 1, "", ""),
						new Field("cont_blog", "int", 1, "", ""),
						new Field("cont_users", "int", 1, "", ""),
						new Field("cont_chat", "int", 1, "", ""),
						new Field("cont_shop", "int", 1, "", ""),
						new Field("updates", "int", 1, "", "") ]

		for(var i = 0; i < this.fields.length; i++)
	{
		this.fields[i].setup(this.conf[i]);
	}

		this.form = new Form("contacto_sel2_cont", this.fields, false, this.def_conf);


		this.contacto_selected = "contacto_sel1";
		var self = this;
		EH.addEventHandler(document.getElementById("contacto_sel1"), "click", function() { self.contactoChange(EH.getEvent()); }, 100);
		EH.addEventHandler(document.getElementById("contacto_sel2"), "click", function() { self.contactoChange(EH.getEvent()); }, 100);
		EH.addEventHandler(document.getElementById("contacto_sel3"), "click", function() { self.contactoChange(EH.getEvent()); }, 100);

	
		this.form.show("input");

	},

	onUnloadPage:		function()
	{
	},

	contactoChange:		function(event)
	{
		if(event.target.nodeName != "DIV")
		{
			var id = event.target.getAttribute("id") ? event.target.getAttribute("id") : event.target.parentNode.getAttribute("id");

			if(this.contacto_selected && document.getElementById(this.contacto_selected + "_cont"))
			{
				document.getElementById(this.contacto_selected + "_cont").className = "hid";
			}

			document.getElementById(id + "_cont").className = "";
			this.contacto_selected = id;
		}
	}
}