function isEmpty(parameter) {
	var result = false;
	if ((parameter == null) || (parameter == "") || (parameter == "undefined")) {
		result = true;
	}
	
	return result;
}


function validarFormClave() {
	var result = true;
	var formClave = document.getElementById("formAccesoTrabajoPrivado");
	if (isEmpty(formClave.clave.value)) {
		alert("Debes introducir la clave para poder acceder al evento privado");
		result = false;
	}
	
	return result;
}

function enviarFormClave() {
	var result = true;
	if (validarFormClave()) { 
		var formClave = document.getElementById("formAccesoTrabajoPrivado");
		formClave.submit();
	} else {
		result = false;
	}
	return result;

}

function crearVisualizadorFotosPeq(idDiv, id, marca, ancho, alto) {
	var num_aleat = Math.random() * 999;
	var url = "html/swf/foto.swf?f="+num_aleat
	var so = new SWFObject(url, "foto", ancho, alto, "7", "#252525");
	so.addVariable("id", id);
	so.addVariable("marca", marca);
	so.addVariable("ancho", ancho);
	so.addVariable("alto", alto);
	so.write(idDiv);
}

function crearVisualizadorFotosGra(idDiv, id, marca, ancho, alto) {
	var num_aleat = Math.random() * 999;
	var url = "html/swf/zoom.swf?z="+num_aleat
	var so = new SWFObject(url, "foto", ancho, eval(alto) + 30, "7", "#252525");
	so.addVariable("id", id);
	so.addVariable("marca", marca);
	so.addVariable("ancho", ancho);
	so.addVariable("alto", alto);
	so.write(idDiv);
}

function validarFormPedido() {
	var result = true;
	var formPedido = document.getElementById("formPedido");
	var entregaDomicilio = document.getElementById("entregaDomicilio");
	if (isEmpty(formPedido.nombre.value)
		|| isEmpty(formPedido.apellidos.value)
		|| isEmpty(formPedido.dni.value)
		|| isEmpty(formPedido.telefono.value)
		|| isEmpty(formPedido.email.value)) {
		alert("Debes rellenar los datos obligatorios");
		result = false;
	}
	if (entregaDomicilio.checked && (isEmpty(formPedido.nombre.value)
		|| isEmpty(formPedido.direccion.value)
		|| isEmpty(formPedido.cp.value)
		|| isEmpty(formPedido.poblacion.value)
		|| isEmpty(formPedido.provincia.value)
		|| isEmpty(formPedido.pais.value))) {
		alert("Debes rellenar los datos obligatorios");
		result = false;
	}
		
	
	return result;
}

function enviarFormPedido() {
	var result = true;
	if (validarFormPedido()) { 
		var formPedido = document.getElementById("formPedido");
		formPedido.submit();
	} else {
		result = false;
	}
	return result;

}

function cambioPagoTarjeta(oInput) {
	if (oInput.checked) {
		// Ocultamos el formulario del pedido
		mostrarDatosPagoCuenta(false);
		mostrarFormPayPal(true);
	}
}

function cambioPagoCuenta(oInput) {
	if (oInput.checked) {
		// Ocultamos el formulario del pedido
		mostrarDatosPagoCuenta(true);
		mostrarFormPayPal(false);
	}
}

function mostrarFormPayPal(visible) {
	var bloquePayPal = document.getElementById("formPayPal");
	if (visible) {
		bloquePayPal.style.display = "inline";
	} else {
		bloquePayPal.style.display = "none";
	}
}

function mostrarDatosPagoCuenta(visible) {
	var bloqueDatosPersonles = document.getElementById("datosPersonales");
	var bloqueComentarios = document.getElementById("bloqueComentarios");
	var botonEnvioPedido = document.getElementById("botonEnvioPedido");
	var entregaDomicilio = document.getElementById("entregaDomicilio");
	var datosEnvio = document.getElementById("datosEnvio");
	if (visible) {
		bloqueDatosPersonles.style.display = "inline";
		bloqueComentarios.style.display = "inline";
		botonEnvioPedido.style.display = "inline";
		if (entregaDomicilio.checked) {
			datosEnvio.style.display = "inline";
		}
		entregaDomicilio.style.display = "inline";
	} else {
		bloqueDatosPersonles.style.display = "none";
		bloqueComentarios.style.display = "none";
		botonEnvioPedido.style.display = "none";
		datosEnvio.style.display = "none";
	}
}

function cambioEntregaDomicilio(oInput) {
	var pagoCuenta = document.getElementById("pagoCuenta");
	if (oInput.checked) {
		document.getElementById("shipping").value = 3;
		document.getElementById("no_shipping").value = 0;
		if (pagoCuenta.checked) {
			// Mostramos el formulario del pedido
			mostrarDatosDireccion(true);
		}
	}
}

function cambioEntregaTienda(oInput) {
	if (oInput.checked) {
		// Ocultamos el formulario del pedido
		mostrarDatosDireccion(false);
		document.getElementById("shipping").value = 0;
		document.getElementById("no_shipping").value = 2;
	}
}

function mostrarDatosDireccion(visible) {
	var bloqueDatosDireccion = document.getElementById("datosEnvio");
	if (visible) {
		bloqueDatosDireccion.style.display = "inline";
	} else {
		bloqueDatosDireccion.style.display = "none";
	}
}


function validarEmail() {
	var inEmail = document.getElementById("email");
	var email = inEmail.value;
	if ((email != null) && (email != "undefined") && (email != "")) {
		var arroba = email.indexOf('@');
		var punto = email.indexOf('.',arroba); 
		if ((arroba == -1) || (punto == -1)) {
			alert("El formato del email no es correcto");
			return false;
		}

	} else {
		alert("Por favor, introduzca el email antes de continuar.");
		return false;
	}

	return true;
}

function enviarFormPedidoPagado() {
	var formEnvioPedidoPagado = document.getElementById("formPedidoPagado");
	if (validarEmail()) {
		formEnvioPedidoPagado.submit();
		return true;
	}
	
	return false;
}


/**********************************
 * Empresas amigas
 **********************************/
 function mostrarImagen(idImg, visible) {
	 var objeto = document.getElementById(idImg);
	 if (visible)
	 {
		 objeto.style.position = "absolute";
		 objeto.style.display = "inline";
		 objeto.style.zIndex = 99;
	 }
	 else
	 {
		 objeto.style.display = "none";
	 }
 }
