﻿function saveItem(){ //Validación de los campos del formulario de Salidas
	var nombre = document.getElementById('nombre').value;
	
	var titulo = document.getElementById('titulo').value;
	
	var contenido = FCKeditorAPI.GetInstance('contenido');
	contenido = contenido.GetHTML();
	
	if (nombre == "")
		alert("Porfavor, introduce un nombre");
	else{
		if(titulo == "")
			alert("Porfavor, introduce un título")
		else{
			if(contenido == "")
				alert("Porfavor, introduce contenido para que se muestre en la página");		
			else
				document.getElementById('datos').submit();
		}
	}
}

function openPaginaCorp(idPagina, paginaActual){
	var respuesta = sendFormGET("formulario&layout=false&idPagina="+idPagina); 
	document.getElementById('formularioSuperior').innerHTML = respuesta;
	
	//Creamos los fckeditor 
	var oFCKeditor = new FCKeditor( 'contenido','465','200'); 
	oFCKeditor.BasePath = BASEDIR+'libs/fckeditor/'; 
	oFCKeditor.ReplaceTextarea();
	
	var oFCKeditor2 = new FCKeditor( 'contenido_eng','465','200'); 
	oFCKeditor2.BasePath = BASEDIR+'libs/fckeditor/'; 
	oFCKeditor2.ReplaceTextarea();
	
	if(document.getElementById('formularioSuperior').style.display=='none'){
		new Effect.BlindDown('formularioSuperior');
	}
}

function cancelarSalida(){
	new Effect.BlindUp("formularioSuperior");
}

function checkEstado(idSalida){
//alert("asdasdasd");
var respuesta = sendFormGET("cambiarEstado&layout=false&template=false&idSalida="+idSalida);
//alert(respuesta);
if(parseInt(respuesta) != 1){
	alert("Problemas al cambiar el estado.");
}
}

function deletePaginaCorp(idPaginaCorp, pagina, PHPSESSIONID){
if (confirm("¿Esta seguro de que desea eliminar esta página Corporativa?")){
	var respuesta = sendFormGET("eliminarPaginaCorporativa&layout=false&template=false&idPaginaCorp="+idPaginaCorp+"&PHPSESSIONID="+PHPSESSIONID);
	//alert(respuesta);
	//location.href="index&page="+pagina;
	window.location.reload();
	}
}

function cambiarIdioma(idioma){
	if(idioma == "General"){
		document.getElementById('Ingles').style.display = "none";
		document.getElementById('General').style.display = "block";
	}else{
		document.getElementById('General').style.display = "none";
		document.getElementById('Ingles').style.display = "block";
	}
}

function checkPeticionInformacion(express){
	var nombre = document.getElementById('nombre').value;
	/*if(express==0) var email = document.getElementById('email').value;
	else var email = "Petición Express";*/
	var email = document.getElementById('email').value;
	
	var telefono = document.getElementById('telefono').value;
	var comentario = document.getElementById('comentario').value;
	
	var filtro_email = /^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	var filtro_telefono = /^[0-9]{9}$/;
	
	if(nombre == "")
		alert("Porfavor, introduce tu Nombre y  Apellidos");
	else{
		if(express == 0 && email == "")
			alert("Porfavor, introduce tu Correo Electrónico");
		else if(express == 0 && !filtro_email.test(email)){
			alert("Porfavor introduce un correo electrónico correcto. Ej. nombre@dominio.es");
		}
		else{
			if(telefono == "")
				alert("Porfavor, introduce un teléfono");
			else if(!filtro_telefono.test(telefono)){
				alert("Porfavor introduce un telefono de 9 digitos.");
			}
			else{
				if(comentario == "")
					alert("Porfavor, introduce la información que estas buscando");
				else{
					if(express == 0) var respuesta = sendFormGET("enviarPeticionInformacion&layout=false&template=false&nombre="+nombre+"&email="+email+"&telefono="+telefono+"&comentario="+comentario);
					else var respuesta = sendFormGET("Pagina/enviarPeticionInformacion&layout=false&template=false&nombre="+nombre+"&email="+email+"&telefono="+telefono+"&comentario="+comentario);
					//alert(respuesta);
					document.getElementById('nombre').value = "";
					/*if(express == 0) document.getElementById('email').value= "";*/
					document.getElementById('email').value= "";
					document.getElementById('telefono').value = "";
					document.getElementById('comentario').value = "";
					document.getElementById("peticionEnviada").style.display = "block";
				}
			}
		}
	}
}
