var promocionactual;  // se guardará la promocion que se está viendo
var seccionactual;

function inicio(destacado,bienvenida,visorinformacion,formularioalta) {
	getData(destacado,'destacado'); 
	getData(bienvenida,'contenedorcentral');
	getData(visorinformacion,'infor');
	getData(formularioalta,'der');
	textoAsistente('default');
	promocionactual='destacado';
	seccionactual='situacion';
}

function textoAsistente(posicion) {
	getData("modulos/visorasistente.php?tid="+posicion, "asis");
}

function abre_menu (opcion) {
	switch (opcion) {
		case "inicio":
			getData('includes/promocion.php','destacado');
			getData('includes/bienvenida.php','contenedorcentral')
			promocionactual='destacado';
			seccionactual='situacion';
			break;
		case "masinformacion":
			getData("modulos/contacto.php?pid=" + promocionactual + "&seccion=" + seccionactual,"contenedorcentral");
			break;
		default:
			getData('modulos/' + opcion + '.php','contenedorcentral')
			break;
	}
}

function abre_seccion (promocion, seccion, idfoto) {
	seccionactual=seccion;
	switch (seccion) {
		case "situacion":
		case "vista":
		case "plano":
		case "calidad":
		case "avanceobra":
			if (idfoto) {
				getData("modulos/fotos.php?seccion="+seccion+"&pid="+promocion+"&fid="+idfoto,"contenedorcentral");
			} else {
				getData("modulos/fotos.php?seccion="+seccion+"&pid="+promocion,"contenedorcentral");
			}
			break;
		case "disponibilidad":
			if (idfoto) {
				getData("modulos/disponibilidad.php?pid="+promocion+"&fid="+idfoto,"contenedorcentral");
			} else {
				getData("modulos/disponibilidad.php?pid="+promocion,"contenedorcentral");
			}
			break;
	}
}

function abre_promocion (promocion) {
	seccionactual="situacion";
	promocionactual=promocion;
	getData("includes/promocion.php?pid="+promocion,"destacado");
}

function cambiaFoto (idSeccion, idFoto, idDiv) {
/*	switch (idSeccion) {
		case "situacion":
			document.getElementById(idDiv).innerHTML="<a href=\"javascript:fotoAmpliada('situacion','"+idFoto+"');\" class='popup'><img src='adjuntos/promociones/situaciones/situacion-" + idFoto + "-1-p.jpg' border='0' width='396'></a>";
			break;
		case "vista":
			document.getElementById(idDiv).innerHTML="<a href=\"javascript:fotoAmpliada('vista','"+idFoto+"');\" class='popup'><img src='adjuntos/promociones/vistas/vista-" + idFoto + "-1-p.jpg' border='0' width='396'></a>";
			break;
		case "plano":
			document.getElementById(idDiv).innerHTML="<a href=\"javascript:fotoAmpliada('plano','"+idFoto+"');\" class='popup'><img src='adjuntos/promociones//planos/plano-" + idFoto + "-1-p.jpg' border='0' width='396'></a>";
			break;
		case "calidad":
			document.getElementById(idDiv).innerHTML="<a href=\"javascript:fotoAmpliada('calidad','"+idFoto+"');\" class='popup'><img src='adjuntos/promociones/calidades/calidad-" + idFoto + "-1-p.jpg' border='0' width='396'></a>";
			break;
		case "avanceobra":
			document.getElementById(idDiv).innerHTML="<a href=\"javascript:fotoAmpliada('avanceobra','"+idFoto+"');\" class='popup'><img src='adjuntos/promociones/avancesobra/avanceobra-" + idFoto + "-1-p.jpg' border='0' width='396'></a>";
			break;
	}*/
}

/*function cambiaTexto (txtTexto, idDiv) {
	document.getElementById(idDiv).innerHTML=txtTexto;
}*/

function fotoAmpliada (idSeccion, idFoto) {
	window.open("includes/popup.php?idSeccion="+idSeccion+"&idFoto="+idFoto,"fotoampliada","width=860,height=660,scrollbars=no");
}
function disponibilidadAmpliada (idPromocion) {
	window.open("includes/popup_disponibilidad.php?pid="+idPromocion,"disponibilidadampliada","width=860,height=660,scrollbars=no");
}

function actualizaPromocionDestacada () {
	var PID=document.getElementById("pid").value;
	getData("includes/promocion.php?pid="+PID,"destacado");
	getData("includes/bienvenida.php","contenedorcentral");
	promocionactual=PID;
	seccionactual='situacion';
}

function emailValido (texto) {
	var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if (texto.length == 0 ) return true;
	if (filter.test(texto)) {
		return true;
	} else {
		return false;
	}
}

function enviarFormularioAlta () {
	if (document.getElementById('fLeidoCondiciones').checked) {
		var varLlamar, varDeseoBoletin;
		if (document.getElementById('fNombre').value=="" || document.getElementById('fApellido').value=="" || document.getElementById('fEMail').value=="") {
			alert("Es necesario rellenar el nombre, apellido y email");
			return (false);
		}
		if (document.getElementById('fLlamar').checked && document.getElementById('fTelefono').value=="") {
			alert("No ha indicado su número de telefono");
			return (false);
		}
		if (!emailValido(document.getElementById('fEMail').value)) {
			alert("El e-mail introducido no es correcto.");
			return (false);
		}
		varNombre=document.getElementById('fNombre').value;
		varApellido=document.getElementById('fApellido').value;
		varEdad=document.getElementById('fEdad').value;
		varTelefono=document.getElementById('fTelefono').value;
		varEMail=document.getElementById('fEMail').value;
		varDiaPreferente=document.getElementById('fDiaPreferente').options[document.getElementById('fDiaPreferente').selectedIndex].value;	
		varHoraPreferente=document.getElementById('fHoraPreferente').options[document.getElementById('fHoraPreferente').selectedIndex].value;
		if (document.getElementById('fLlamar').checked) varLlamar=document.getElementById('fLlamar').value;
		if (document.getElementById('fDeseoBoletin').checked) varDeseoBoletin=document.getElementById('fDeseoBoletin').value;
		
		postData("includes/derecha.php","fNombre="+varNombre+"&fApellido="+varApellido+"&fEdad="+varEdad+"&fTelefono="+varTelefono+"&fEMail="+varEMail+"&fDiaPreferente="+varDiaPreferente+"&fHoraPreferente="+varHoraPreferente+"&fLlamar="+varLlamar+"&fDeseoBoletin="+varDeseoBoletin+"&pid="+promocionactual, "der");
		
		return (true);
	} else {
		alert("Tienes que leer y aceptar las condiciones antes de continuar.");
		return (false);
	}
}

function enviarFormularioContacto () {
	//if (document.getElementById('fLeidoCondiciones').checked) {
		if (document.getElementById('fNombre').value=="" || document.getElementById('fTelefono').value=="" || document.getElementById('fEMail').value=="") {
			alert("Es necesario rellenar el nombre, teléfono y email");
			return (false);
		}
		if (!emailValido(document.getElementById('fEMail').value)) {
			alert("El e-mail introducido no es correcto.");
			return (false);
		}
		varNombre=document.getElementById('fNombre').value;
		varDireccion=document.getElementById('fDireccion').value;
		varLocalidad=document.getElementById('fLocalidad').value;
		varCodigoPostal=document.getElementById('fCodigoPostal').value;
		varProvincia=document.getElementById('fProvincia').value;
		varTelefono=document.getElementById('fTelefono').value;
		varEMail=document.getElementById('fEMail').value;
		varDepartamento=document.getElementById('fDepartamento').options[document.getElementById('fDepartamento').selectedIndex].value;	
		varComentario=document.getElementById('fComentario').value;
		
		postData("modulos/contacto.php","fNombre="+varNombre+"&fDireccion="+varDireccion+"&fLocalidad="+varLocalidad+"&fCodigoPostal="+varCodigoPostal+"&fProvincia="+varProvincia+"&fTelefono="+varTelefono+"&fEMail="+varEMail+"&fDepartamento="+varDepartamento+"&fComentario="+varComentario, "contenedorcentral");
		
		return (true);
	/*} else {
		alert("Tienes que leer y aceptar las condiciones antes de continuar.");
		return (false);
	}*/
}

