function validarEmail(pEmail)
{
	var oRegExp = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/;
	return oRegExp.test(pEmail);
}

function retornarFecha(pDestino)
{
	var aDias = new Array("Domingo", "Lunes", "Martes",
		"Mi&eacute;rcoles",  "Jueves", "Viernes", "S&aacute;bado");
	var aMeses = new Array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
	
	var dFecha = new Date();
	with(dFecha)
	{
		var lIDDia = getDay();
		var sDia = new String(getDate());
		//var sMes = new String(getMonth() + 1);
		var sMes = getMonth();
		var lAno = getYear();
		var sHora = new String(getHours());
		var sMinutos = new String(getMinutes());
	}
	if(sDia.length == 1) sDia = "0" + sDia;
	if(sMes.length == 1) sMes = "0" + sMes;
	if(lAno < 1900) lAno += 1900;
	if(sHora.length == 1) sHora = "0" + sHora;
	if(sMinutos.length == 1) sMinutos = "0" + sMinutos;
	pDestino = document.getElementById(pDestino);
	if(pDestino)
	{
		pDestino.innerHTML = aDias[lIDDia] + ", " + sDia + " de " + aMeses[sMes] + " de " + lAno;
	}
}

function enviarContacto(pForm)
{
	with(pForm)
	{
		if(nombres.value.length > 0)
		{
			if(validarEmail(email.value))
			{
				if(mensaje.value.length > 0)
				{
					x_EnviarContacto(producto.value,
									 nombres.value, 
									 email.value,
									 localidad.value,
									 provincia.value,
									 mensaje.value, 
									 function(pCadena)
					{		 
						reset();
						alert("Su mensaje ha sido enviado");
					});
				}
				else
				{
					alert("Por favor, ingrese un Mensaje");
					mensaje.focus();
				}
			}
			else
			{
				alert("Por favor, ingrese un Email válido");
				email.focus();
			}
		}
		else
		{
			alert("Por favor, ingrese su Nombre");
			nombres.focus();
		}
	}
	return false;
}

function enviarContacto2(pForm)
{
	with(pForm)
	{
		if(nombres.value.length > 0)
		{
			if(validarEmail(email.value))
			{
				if(mensaje.value.length > 0)
				{
					x_EnviarContacto(telefono.value,
									 nombres.value, 
									 email.value,
									 localidad.value,
									 provincia.value,
									 mensaje.value, 
									 function(pCadena)
					{		 
						reset();
						alert("Su mensaje ha sido enviado");
					});
				}
				else
				{
					alert("Por favor, ingrese un Mensaje");
					mensaje.focus();
				}
			}
			else
			{
				alert("Por favor, ingrese un Email válido");
				email.focus();
			}
		}
		else
		{
			alert("Por favor, ingrese su Nombre");
			nombres.focus();
		}
	}
	return false;
}


function guardarSuscriptor(pForm)
{
	with(pForm)
	{
		if(nombres.value.length > 0) 
		{
			if(validarEmail(email.value))
			{
					x_GuardarSuscriptor(nombres.value, email.value, function(pCadena)
						{
							alert("Gracias por suscribirse a nuestro newsletter.\n");
							pForm.reset();

						});
			}

			else
			{
				alert("Por favor, ingrese un Email válido");
				email.focus();
			}
		}
		else
		{
			alert("Por favor, ingrese su Nombre");
			nombres.focus();
		}
	}
	return false;
}

/*******************************************/
// @pControl		combo principal
// @pRelacionado	combo cuyos valores estan relacionados al seleccionado en pControl
/*******************************************/
function cargarListas(pControl, pRelacionado, pSeleccionado)
{
	var oLista;
	var pValor = pControl.options[pControl.selectedIndex].value;
	oLista = document.getElementById(pRelacionado);
	oLista.length = 1;
	oLista.options[0].text = "Cargando...";
	oLista.disabled = true;
	
	if(pControl != "")
	{
		oLista = document.getElementById(pRelacionado);
		x_CargarListas(pValor, pRelacionado, function(pCadena)
		{
			var lJ;
			var lK = 0;
			var aDatos = pCadena.split(":|:");

			oLista.disabled = false;
			for(lJ = 1; lJ < aDatos.length; lJ++)
			{
				if(aDatos[lJ] == pSeleccionado)
					oLista[lK] = new Option(aDatos[lJ + 1], aDatos[lJ], "defaultSelected");
				else
					oLista[lK] = new Option(aDatos[lJ + 1], aDatos[lJ]);
				lJ++;
				lK++;
			}
			//alert(pCadena);
		});
	}
}

