// ************************************* FUNCIONES PARA AJAX *****************************************************
var net = new Object();
net.READY_STATE_UNINITIALIZED=0;
net.READY_STATE_LOADING=1;
net.READY_STATE_LOADED=2;
net.READY_STATE_INTERACTIVE=3;
net.READY_STATE_COMPLETE=4;

// Constructor
net.CargadorContenidos = function(url, funcion, metodo, parametros,contentType,funcionError) {
    this.url = url;
    this.req = null;
    this.onload = funcion;
    this.onerror = (funcionError) ? funcionError : this.defaultError;
    this.cargaContenidoXML(url, metodo, parametros, contentType);
}

net.CargadorContenidos.prototype = {
    cargaContenidoXML: function(url, metodo, parametros, contentType) {
	if (window.XMLHttpRequest) {
	    this.req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
	    this.req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(this.req) {
	    try {
		var loader = this;
		this.req.onreadystatechange = function() {
		    loader.onReadyState.call(loader);
		}
		this.req.open(metodo, url, true);
		if(contentType) {
		    this.req.setRequestHeader("Content-Type", contentType);
		}
		this.req.send(parametros);
	    } catch (err) {
		this.onerror.call(this);
	    }
	}
    },onReadyState: function() {
	var req = this.req;
	var ready = req.readyState;
	if (ready == net.READY_STATE_COMPLETE) {
	    var httpStatus = req.status;
	    if(httpStatus == 200 || httpStatus == 0) {
		this.onload.call(this);
	    }else {
		this.onerror.call(this);
	    }
	}
    },defaultError: function() {
	alert("Se ha producido un error al obtener los datos" + "\n\nreadyState:" + this.req.readyState	+ "\nstatus: " + this.req.status + "\nheaders: " + this.req.getAllResponseHeaders());
    }
}

// ************************************************* FUNCIONES COMUNES DE JAVASCRIPT *************************************

function validar_formulario_bolsa(form) { 
  resultado = false; 
  if(form.nombre.value == '' ){
      return alert('El campo Nombre es obligatorio');
  }else{  
      if (form.apellidos.value == "")  {
          return alert('El campo Apellidos es obligatorio');
      }else{
          if(form.fecha.value == '' ){
	      return alert('El campo Fecha de Nacimiento es obligatorio');
	  }else{
	      if (form.direccion.value == ''){
	          return alert('El campo Dirección es obligatorio');
   	      }else{
	          if (form.cp.value == ''){
		      return alert('El campo Código Postal es obligatorio');
		  }else{
		      if (form.ciudad.value == ''){
		          return alert('El campo Localidad es obligatorio');
		      }else{
		          if (form.provincia.value == ''){
			      return alert('El campo Provincia es obligatorio');
			  }else{			   
			     if ((form.correo.value == "") || 
   				  (form.correo.value.indexOf('@') == -1) || 
   				  (form.correo.value.indexOf('.') == -1)){
			          return alert('El campo Correo electrónico es obligatorio, debe cumplimentarlo correctamente.');
			      }else{   			  
			        if (form.telefono1.value == ''){
			            return alert('El campo Teléfono 1 es obligatorio');
			        }else{
			           if (form.estudios.value == 0){
				       return alert('Debe especificar un nivel de estudios');
				   }else{
				      if ((form.chek[0].checked == false)&&(form.chek[1].checked == false)&&(form.chek[2].checked == false)&&(form.chek[3].checked == false)&&(form.chek[4].checked == false)){
				          return alert('Debe especificar como llego a www.deltabravoconsultores.com');
				      }else{
				         if((form.chek[4].checked == true)&&(form.check_otros.value == '')){
					   form.check_otros.focus();
					   return alert('Debe cumplimentar el campo Otros, es obligatorio');
					 }else{				      
				             if (confirm('¿Está seguro de enviar el formulario?')){
					      resultado = "location.href='../includes/enviar_formulario_bolsa.php'";
					      return form.submit();
					     }
					  }	      
				      }
				  }
		              }
			  }
	              }
		  }
	      }
	  }
      }
  } 
}
}

function validar_formulario_bolsa_eng(form) { 
  resultado = false; 
  if(form.nombre.value == '' ){
      return alert('The Name is obligatory');
  }else{  
      if (form.apellidos.value == "")  {
          return alert('The surname is obligatory');
      }else{
          if(form.fecha.value == '' ){
	      return alert('The Date of Birth is obligatory');
	  }else{
	      if (form.direccion.value == ''){
	          return alert('The Address is obligatory');
   	      }else{
	          if (form.cp.value == ''){
		      return alert('The Zip code is obligatory');
		  }else{
		      if (form.ciudad.value == ''){
		          return alert('The Locality is obligatory');
		      }else{
		          if (form.provincia.value == ''){
			      return alert('The Province is obligatory');
			  }else{
			       if ((form.correo.value == "") || 
   				  (form.correo.value.indexOf('@') == -1) || 
   				  (form.correo.value.indexOf('.') == -1)){
			          return alert('The field Email is obligatory, it must complete it correctly.');
			      }else{ 
			        if (form.telefono1.value == ''){
			          return alert('The Phone 1 is obligatory');
			        }else{
			          if (form.estudios.value == 0){
				      return alert('The studies is obligatory');
				   }else{
				      if ((form.chek[0].checked == false)&&(form.chek[1].checked == false)&&(form.chek[2].checked == false)&&(form.chek[3].checked == false)&&(form.chek[4].checked == false)){
				          return alert('Please select How you find www.deltabravoconsultores.com?');
				      }else{
				         if((form.chek[4].checked == true)&&(form.check_otros.value == '')){
					   form.check_otros.focus();
					   return alert('The field Others, is obligatory');
					 }else{			
				             if (confirm('¿Are you sure to send the form?')){
					      resultado = "location.href='../includes/enviar_formulario_bolsa_eng.php'";
					      return form.submit();
					      }
					  }	      
				      }
				  }
		              }
			  }
	              }
		  }
	      }
	  }
      }
  } 
}
}

//función abre ventana sin barra de herramientas
function abrir_ventana (pagina) {
var opciones="toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, width=800, height=600, top=85, left=140";
window.open(pagina,"",opciones);
}


//funcion validar formulario 
function validar_formulario(form) { 
  resultado = false;
  if(form.nombre.value == '' ){alert('El campo NOMBRE es obligatorio');}else{
  if(form.apellidos.value == '' ){alert('El campo APELLIDOS es obligatorio');}else{
  if(form.empresa.value == '' ){alert('El campo EMPRESA es obligatorio');}else{
  if ((form.correo.value == "") || 
   (form.correo.value.indexOf('@') == -1) || 
   (form.correo.value.indexOf('.') == -1)) {alert('Por favor rellene correctamente el campo CORREO ELECTRÓNICO, es obligatorio.');}else{
  if(form.telefono.value == '' ){alert('El campo TELÉFONO es obligatorio');}else{
  if(form.texto.value == '' ){alert('El campo MENSAJE es obligatorio');}
  else{resultado = true; }}}}}}
  return resultado;
 }

 function validar_formulario_eng(form) { 
  resultado = false;
  if(form.nombre.value == '' ){alert('The field NAMES is obligatory');}else{
  if(form.apellidos.value == '' ){alert('The field SURNAME is obligatory');}else{
  if(form.empresa.value == '' ){alert('The field COMPANY is obligatory');}else{
  if ((form.correo.value == "") || 
   (form.correo.value.indexOf('@') == -1) || 
   (form.correo.value.indexOf('.') == -1)) {alert('The EMAIL direction is not correct.');}else{
  if(form.telefono.value == '' ){alert('The field PHONE is obligatory');}else{
  if(form.texto.value == '' ){alert('The field MESSAGE is obligatory');}
  else{resultado = true; }}}}}}
  return resultado;
 }
 

 //funcion validar formulario 
function validar_suscripcion(form) { 
  resultado = false;
  if(form.nombre.value == '' ){alert('El campo NOMBRE es obligatorio');}else{  
  if(form.apellidos.value == '' ){alert('El campo APELLIDOS es obligatorio');}else{  
  if ((form.correo.value == "") || 
   (form.correo.value.indexOf('@') == -1) || 
   (form.correo.value.indexOf('.') == -1)) {alert('Por favor rellene correctamente el campo CORREO ELECTRÓNICO, es obligatorio.');}else{resultado = true; }}}
  return resultado;
 }

function solo_numeros(){
var key=window.event.keyCode;//codigo de tecla.
if (key < 48 || key > 57){//si no es numero 
window.event.keyCode=0;//anula la entrada de texto.
}} 

 function validar_correo(form) { 
  resultado = false; 
  if ((form.correo.value == "") || 
   (form.correo.value.indexOf('@') == -1) || 
   (form.correo.value.indexOf('.') == -1)) {alert('Por favor rellene correctamente el campo Correo electrónico, es obligatorio.');}else{
   resultado = true;}
  return resultado;
 }

//CAMBIACOLOR_CELDA: Se le pueden pasar 2 objetos para el caso en que se
//use para cambiar el color en un marcador u omitiendo el objeto2 y usándola, 
//por ejemplo, en un menu para resaltar la celda
function cambiacolor_celda(objeto,color,puntero,objeto2){
    objeto.style.backgroundColor = color;    
    objeto2.style.cursor = puntero;
}

//CAMBIA_IMG: se pasa el objeto y la img con ruta 
function cambia_img(objeto,img){
  objeto.src=img;
}

// CAMBIAIMAGEN_CELDA cambiar la imagen de background de una objeto
function cambiaimagen_celda(objeto,imagen,puntero){
  objeto.style.background = "url("+imagen+")";
  objeto.style.cursor = puntero;
}

//HABILITACAPA: función para habilitar capas para simular pestañas. En la página donde están las
//capas creamos una matriz con el nombre de las capas que hay, y a la función le pasamos la posición
//en la matriz de la capa que queremos visible y la matriz de capas.
function HabilitaCapa(posicionVisible,matriz){
document.getElementById(matriz[posicionVisible]).style.display = 'block';
for (i=0;i<(matriz.length);i++){ // recorremos la matriz y desactivamos todas las capas
  if (i != posicionVisible){
    document.getElementById(matriz[i]).style.display = 'none';
    }
  }

}
function confirmaEnviar () {
  if (confirm('¿Está seguro de Enviar el Newsletter?')){
    return true
  } else {
    return false
  }
}

function confirmaEnviar_eng () {
  if (confirm('¿Are you sure sure of Send Newsletter?')){
    return true
  } else {
    return false
  }
}

function confirmaPublicar () {
  if (confirm('¿Está seguro de Publicar el Newsletter?')){
    return true
  } else {
    return false
  }
}

function confirmaCrear () {
  if (confirm('¿Está seguro de Crear un nuevo Newsletter?')){
    return true
  } else {
    return false
  }
}


function confirmaBorradoNewsletter (id) {
  if (confirm('¿Está seguro de eliminar el Newsletter seleccionado?, se borrarán las noticias relacionadas a éste')){
    location.href="bd/eliminar_newsletter.php?id="+id;
    return true;
  } else {
    return false;
  }
}

function confirmaBorradoNewsletter_eng (id) {
  if (confirm('Are you sure sure of delete the selected Newsletter?, there will resign the news related to this one')){
    location.href="bd/eliminar_newsletter_eng.php?id="+id;
    return true;
  } else {
    return false;
  }
}

function confirmaBorrado (id) {
  if (confirm('¿Está seguro de eliminar el registro seleccionado?')){
    location.href="bd/eliminar_noticia_newsletter.php?id="+id;
    return true;
  } else {
    return false;
  }
}

function confirmaBorradoUser (id) {
  if (confirm('¿Está seguro de eliminar el registro seleccionado?')){
    location.href="bd/eliminar_suscripcion_newsletter.php?idioma=esp&id="+id;
    return true;
  } else {
    return false;
  }
}
function confirmaBorradoUserEng (id) {
  if (confirm('Are you sure of delete the selected record?')){
    location.href="bd/eliminar_suscripcion_newsletter.php?idioma=eng&id="+id;
    return true;
  } else {
    return false;
  }
}

function confirmaBorradoEng (id) {
  if (confirm('¿Are you sure of delete the selected record?')){
    location.href="bd/eliminar_noticia_newsletter_eng.php?id="+id;
    return true;
  } else {
    return false;
  }
}

function confirmasustituir () {
  if (confirm('¿Está seguro de sustituir el PDF actual?')){
    return true;
  } else {
    return false;
  }
}

function confirmasustituirEng () {
  if (confirm('Are you sure of replacing the current PDF?')){
    return true;
  } else {
    return false;
  }
}



