$(document).ready(function(){
  $('.volver').click(function(){
   $(this).attr({ href:"#"});
   window.location.href='javascript:window.history.back();';
   return false;
  });
  $('#volver').click(function(){
   $(this).attr({ href:"#"});
   window.location.href='javascript:window.history.back();';
   return false;
  });
  //Todos los inputs al pulsarlos, si tiene el contenido por defecto lo borramos.
  $(':input').click(function(){
    if ($(this).val() == "email" || $(this).val() == "e-mail" ||
        $(this).val() == "nombre" || $(this).val() == "name" || $(this).val() == "contraseña" ||
        $(this).val() == "password" || $(this).attr("type") == "password" ||
        $(this).val() == "nif" || $(this).val() == "nif o cif" || $(this).val() == "buscar" || $(this).val() == "búsqueda" ||
        $(this).val() == "search" || $(this).val() == "localizador" || $(this).val() == "locator" ||
        $(this).val() == "empresa" || $(this).val() == "codigo cliente" || $(this).val() == "codigo" ||
        $(this).val() == "company" || $(this).val() == "clien code" || $(this).val() == "code")
        $(this).val("")
  });
  $(':input').blur(function(){
    if ($(this).val() == "" && 
        ( $(this).attr("name") == "search" || $(this).attr("name") == "localizador" || 
        $(this).attr("name") == "locator") 
       )
        $(this).val($(this).attr("name"))
  });
  $("a").attr({ title:""});
  $("img").attr({ alt:"",longdesc:""});
  $("abbr").attr({ title:""});
  $("dl").attr({ title:""});
  
  //Indicamos todos los enlaces temporales
    switch(idiomaPrincipal){
      case "es":
        $("a[href='#']").attr({href:"javascript:alert('Próximamente')"});  
        $("a[href='#taller']").attr({href:"javascript:alert('En construcción, próximo Diciembre 2009')"});
        break;
      default:
        $("a[href='#']").attr({href:"javascript:alert('Coming soon')"});
        $("a[href='#taller']").attr({href:"javascript:alert('Under construction, December 2009')"});
    }
})

function buscar(inputString) {
	if(inputString.length <= 3 || inputString == "localizador" || inputString == "search" || inputString == "locator") {
		$('#resultados-buscador').hide();
	} else {
		$.post("/php_lib/buscador.php", {busqueda: ""+inputString+""}, function(data){
			if(data.length >0) {
				$('#resultados-buscador').show();
				$('#resultados').html(data);
			}
		});
	}
}

function busquedaTerminar() {
	setTimeout("$('#resultados-buscador').hide();$('#resultados-buscador').val('');", 200);
	return true;
}

function presupuestoEnviar()
{
  //Lo primero es comprobar que ha introducido la empresa
  if ($('#empresa').val()==""){
    switch(idiomaPrincipal){
      case "en":
        alert("Please indicate the company. It is mandatory.");
        break;
      case "de":
        alert("Bitte geben Sie an, das Unternehmen. Es ist zwingend erforderlich.");
        break;
      case "fr":
        alert("S'il vous plaît indiquer la société. Il est obligatoire.");
        break;
      default:
        alert("Por favor, indique la empresa. Es obligatorio.");
    }
    $('#empresa').val("");
    $('#empresa').css({border: "1px solid red"}).focus();
    return false;
  }else{$('#empresa').css({border: "1px solid #ff9627"});}
  
  //Persona de contacto
  if ($('#contacto').val()==""){
    switch(idiomaPrincipal){
      case "en":
        alert("Please indicate the contact person. It is mandatory.");
        break;
      case "de":
        alert("Bitte geben Sie die Ansprechpartner. Es ist zwingend erforderlich.");
        break;
      case "fr":
        alert("S'il vous plaît indiquer la personne à contacter. Il est obligatoire.");
        break;
      default:
        alert("Por favor, indique la persona de contacto. Es obligatorio.");
    }
    $('#contacto').val("");
    $('#contacto').css({border: "1px solid red"}).focus();
    return false;
  }else{$('#contacto').css({border: "1px solid #ff9627"});}
  
  //Ciudad
  if ($('#ciudad').val()==""){
    switch(idiomaPrincipal){
      case "en":
        alert("Please indicate the city. It is mandatory.");
        break;
      case "de":
        alert("Bitte geben Sie die Stadt. Es ist zwingend erforderlich.");
        break;
      case "fr":
        alert("S'il vous plaît indiquer la ville. Il est obligatoire.");
        break;
      default:
        alert("Por favor, indique la ciudad. Es obligatorio.");
    }
    $('#ciudad').val("");
    $('#ciudad').css({border: "1px solid red"}).focus();
    return false;
  }else{$('#ciudad').css({border: "1px solid #ff9627"});}
  
  //Provincia
  if ($('#provincia').val()==""){
    switch(idiomaPrincipal){
      case "en":
        alert("Please indicate the province. It is mandatory.");
        break;
      case "de":
        alert("Bitte geben Sie die Provinz. Es ist zwingend erforderlich.");
        break;
      case "fr":
        alert("S'il vous plaît indiquer la province. Il est obligatoire.");
        break;
      default:
        alert("Por favor, indique la provincia. Es obligatorio.");
    }
    $('#provincia').val("");
    $('#provincia').css({border: "1px solid red"}).focus();
    return false;
  }else{$('#provincia').css({border: "1px solid #ff9627"});}
  
  //País
  if ($('#pais').val()==""){
    switch(idiomaPrincipal){
      case "en":
        alert("Please indicate the country. It is mandatory.");
        break;
      case "de":
        alert("Bitte geben Sie an, das Land. Es ist zwingend erforderlich.");
        break;
      case "fr":
        alert("S'il vous plaît indiquer le pays. Il est obligatoire.");
        break;
      default:
        alert("Por favor, indique el país. Es obligatorio.");
    }
    $('#pais').val("");
    $('#pais').css({border: "1px solid red"}).focus();
    return false;
  }else{$('#pais').css({border: "1px solid #ff9627"});}
  
  //Teléfono
  if ($('#telefono').val()==""){
    switch(idiomaPrincipal){
      case "en":
        alert("Please indicate the phone. It is mandatory.");
        break;
      case "de":
        alert("Bitte geben Sie an, das Telefon. Es ist zwingend erforderlich.");
        break;
      case "fr":
        alert("S'il vous plaît indiquer le téléphone. Il est obligatoire.");
        break;
      default:
        alert("Por favor, indique el teléfono. Es obligatorio.");
    }
    $('#telefono').val("");
    $('#telefono').css({border: "1px solid red"}).focus();
    return false;
  }else{$('#telefono').css({border: "1px solid #ff9627"});}
  
  //Email
  if ($('#email').val()==""){
    switch(idiomaPrincipal){
      case "en":
        alert("Please indicate the e-mail. It is mandatory.");
        break;
      case "de":
        alert("Bitte geben Sie die E-Mail. Es ist zwingend erforderlich.");
        break;
      case "fr":
        alert("S'il vous plaît indiquer l'e-mail. Il est obligatoire.");
        break;
      default:
        alert("Por favor, indique el correo electrónico. Es obligatorio.");
    }
    $('#email').val("");
    $('#email').css({border: "1px solid red"}).focus();
    return false;
  }else{$('#email').css({border: "1px solid #ff9627"});}
  
  //Productos
  if ($('#consulta').val()==""){
    switch(idiomaPrincipal){
      case "en":
        alert("Please indicate the products. It is mandatory.");
        break;
      case "de":
        alert("Bitte geben Sie die Produkte. Es ist zwingend erforderlich.");
        break;
      case "fr":
        alert("S'il vous plaît indiquer les produits. Il est obligatoire.");
        break;
      default:
        alert("Por favor, indique los productos de su interés. Es obligatorio.");
    }
    $('#consulta').val("");
    $('#consulta').css({border: "1px solid red"}).focus();
    return false;
  }else{$('#consulta').css({border: "1px solid #ff9627"});}
  
  $.get("/php_lib/ajax.php", { accion: "presupuestoEnviar", empresa: $('#empresa').val(), contacto:$('#contacto').val(),
                               ciudad:$('#ciudad').val(), provincia:$('#provincia').val(), pais:$('#pais').val(), telefono:$('#telefono').val(), 
                               fax:$('#fax').val(), email:$('#email').val(), consulta:$('#consulta').val() },
  function(data){
    if (data != "error"){//Indicamos mensaje de OK
      $('#resultado-formulario').html(data);
      $('#form-presupuesto :input').val('');
      return true;
    }else{
      switch(idiomaPrincipal){
        case "en":
          $('#resultado-formulario').html("Error, try again in a few minutes.");
          break;
        case "de":
          $('#resultado-formulario').html("Fehler, versuchen Sie es in ein paar Minuten erneut.");
          break;
        case "fr":
          $('#resultado-formulario').html("Erreur, réessayer dans quelques minutes.");
          break;
        default:
          $('#resultado-formulario').html("Error, inténtelo de nuevo en unos segundos.");
      }
      return false;
    }
  });
  return true;
}

function curriculumEnviar()
{
  //Comprobar que ha seleccionado algún destinatario
  if ($('#departamento').val()=="" || $('#departamento').val()=="- - - - - - - -"){
    switch(idiomaPrincipal){
      case "en":
        alert("Please indicate the department. It is mandatory.");
        break;
      case "de":
        alert("Bitte geben Sie die Abteilung. Es ist zwingend erforderlich.");
        break;
      case "fr":
        alert("S'il vous plaît indiquer le département. Il est obligatoire.");
        break;
      default:
        alert("Por favor, indique un departamento. Es obligatorio.");
    }
    return false;
  }
  
  //Persona de contacto
  if ($('#contacto').val()==""){
    switch(idiomaPrincipal){
      case "en":
        alert("Please indicate the name. It is mandatory.");
        break;
      case "de":
        alert("Bitte geben Sie den Namen. Es ist zwingend erforderlich.");
        break;
      case "fr":
        alert("S'il vous plaît indiquer le nom. Il est obligatoire.");
        break;
      default:
        alert("Por favor, indique su nombre. Es obligatorio.");
    }
    $('#contacto').val("");
    $('#contacto').css({border: "1px solid red"}).focus();
    return false;
  }else{$('#contacto').css({border: "1px solid #ff9627"});}
  
  //Ciudad
  if ($('#ciudad').val()==""){
    switch(idiomaPrincipal){
      case "en":
        alert("Please indicate the city. It is mandatory.");
        break;
      case "de":
        alert("Bitte geben Sie die Stadt. Es ist zwingend erforderlich.");
        break;
      case "fr":
        alert("S'il vous plaît indiquer la ville. Il est obligatoire.");
        break;
      default:
        alert("Por favor, indique la ciudad. Es obligatorio.");
    }
    $('#ciudad').val("");
    $('#ciudad').css({border: "1px solid red"}).focus();
    return false;
  }else{$('#ciudad').css({border: "1px solid #ff9627"});}
  
  //País
  if ($('#pais').val()==""){
    switch(idiomaPrincipal){
      case "en":
        alert("Please indicate the country. It is mandatory.");
        break;
      case "de":
        alert("Bitte geben Sie an, das Land. Es ist zwingend erforderlich.");
        break;
      case "fr":
        alert("S'il vous plaît indiquer le pays. Il est obligatoire.");
        break;
      default:
        alert("Por favor, indique el país. Es obligatorio.");
    }
    $('#pais').val("");
    $('#pais').css({border: "1px solid red"}).focus();
    return false;
  }else{$('#pais').css({border: "1px solid #ff9627"});}
  
  //Teléfono
  if ($('#telefono').val()==""){
    switch(idiomaPrincipal){
      case "en":
        alert("Please indicate the phone. It is mandatory.");
        break;
      case "de":
        alert("Bitte geben Sie an, das Telefon. Es ist zwingend erforderlich.");
        break;
      case "fr":
        alert("S'il vous plaît indiquer le téléphone. Il est obligatoire.");
        break;
      default:
        alert("Por favor, indique el teléfono. Es obligatorio.");
    }
    $('#telefono').val("");
    $('#telefono').css({border: "1px solid red"}).focus();
    return false;
  }else{$('#telefono').css({border: "1px solid #ff9627"});}
  
  //Email
  if ($('#email').val()==""){
    switch(idiomaPrincipal){
      case "en":
        alert("Please indicate the e-mail. It is mandatory.");
        break;
      case "de":
        alert("Bitte geben Sie die E-Mail. Es ist zwingend erforderlich.");
        break;
      case "fr":
        alert("S'il vous plaît indiquer l'e-mail. Il est obligatoire.");
        break;
      default:
        alert("Por favor, indique el correo electrónico. Es obligatorio.");
    }
    $('#email').val("");
    $('#email').css({border: "1px solid red"}).focus();
    return false;
  }else{$('#email').css({border: "1px solid #ff9627"});}
  
  //Productos
  if ($('#consulta').val()==""){
    switch(idiomaPrincipal){
      case "en":
        alert("Please indicate the comment. It is mandatory.");
        break;
      case "de":
        alert("Bitte geben Sie den Kommentar. Es ist zwingend erforderlich.");
        break;
      case "fr":
        alert("S'il vous plaît indiquer le commentaire. Il est obligatoire.");
        break;
      default:
        alert("Por favor, indique la consulta. Es obligatorio.");
    }
    $('#consulta').val("");
    $('#consulta').css({border: "1px solid red"}).focus();
    return false;
  }else{$('#consulta').css({border: "1px solid #ff9627"});}
  
  $.get("/php_lib/ajax.php", { accion: "curriculumEnviar", departamento: $('#departamento').val(), contacto:$('#contacto').val(),
                               ciudad:$('#ciudad').val(), pais:$('#pais').val(), telefono:$('#telefono').val(), 
                               email:$('#email').val(), consulta:$('#consulta').val() },
  function(data){
    if (data != "error"){//Indicamos mensaje de OK
      $('#resultado-formulario').html(data);
      $('#form-presupuesto :input').val('');
      return true;
    }else{
      switch(idiomaPrincipal){
        case "en":
          $('#resultado-formulario').html("Error, try again in a few minutes.");
          break;
        case "de":
          $('#resultado-formulario').html("Fehler, versuchen Sie es in ein paar Minuten erneut.");
          break;
        case "fr":
          $('#resultado-formulario').html("Erreur, réessayer dans quelques minutes.");
          break;
        default:
          $('#resultado-formulario').html("Error, inténtelo de nuevo en unos segundos.");
      }
      return false;
    }
  });
  return true;
}

function consultaEnviar()
{
  //Lo primero es comprobar que ha introducido la empresa
  if ($('#empresa').val()==""){
    switch(idiomaPrincipal){
      case "en":
        alert("Please indicate the company. It is mandatory.");
        break;
      case "de":
        alert("Bitte geben Sie an, das Unternehmen. Es ist zwingend erforderlich.");
        break;
      case "fr":
        alert("S'il vous plaît indiquer la entreprise. Il est obligatoire.");
        break;
      default:
        alert("Por favor, indique la empresa. Es obligatorio.");
    }
    $('#empresa').val("");
    $('#empresa').css({border: "1px solid red"}).focus();
    return false;
  }else{$('#empresa').css({border: "1px solid #ff9627"});}
  
  //Persona de contacto
  if ($('#contacto').val()==""){
    switch(idiomaPrincipal){
      case "en":
        alert("Please indicate the contact person. It is mandatory.");
        break;
      case "de":
        alert("Bitte geben Sie die Ansprechpartner. Es ist zwingend erforderlich.");
        break;
      case "fr":
        alert("S'il vous plaît indiquer la personne à contacter. Il est obligatoire.");
        break;
      default:
        alert("Por favor, indique la persona de contacto. Es obligatorio.");
    }
    $('#contacto').val("");
    $('#contacto').css({border: "1px solid red"}).focus();
    return false;
  }else{$('#contacto').css({border: "1px solid #ff9627"});}
  
  //Ciudad
  if ($('#ciudad').val()==""){
    switch(idiomaPrincipal){
      case "en":
        alert("Please indicate the city. It is mandatory.");
        break;
      case "de":
        alert("Bitte geben Sie die Stadt. Es ist zwingend erforderlich.");
        break;
      case "fr":
        alert("S'il vous plaît indiquer la ville. Il est obligatoire.");
        break;
      default:
        alert("Por favor, indique la ciudad. Es obligatorio.");
    }
    $('#ciudad').val("");
    $('#ciudad').css({border: "1px solid red"}).focus();
    return false;
  }else{$('#ciudad').css({border: "1px solid #ff9627"});}
  
  //País
  if ($('#pais').val()==""){
    switch(idiomaPrincipal){
      case "en":
        alert("Please indicate the country. It is mandatory.");
        break;
      case "de":
        alert("Bitte geben Sie an, das Land. Es ist zwingend erforderlich.");
        break;
      case "fr":
        alert("S'il vous plaît indiquer le pays. Il est obligatoire.");
        break;
      default:
        alert("Por favor, indique el país. Es obligatorio.");
    }
    $('#pais').val("");
    $('#pais').css({border: "1px solid red"}).focus();
    return false;
  }else{$('#pais').css({border: "1px solid #ff9627"});}
  
  //Teléfono
  if ($('#telefono').val()==""){
    switch(idiomaPrincipal){
      case "en":
        alert("Please indicate the phone. It is mandatory.");
        break;
      case "de":
        alert("Bitte geben Sie an, das Telefon. Es ist zwingend erforderlich.");
        break;
      case "fr":
        alert("S'il vous plaît indiquer le téléphone. Il est obligatoire.");
        break;
      default:
        alert("Por favor, indique el teléfono. Es obligatorio.");
    }
    $('#telefono').val("");
    $('#telefono').css({border: "1px solid red"}).focus();
    return false;
  }else{$('#telefono').css({border: "1px solid #ff9627"});}
  
  //Email
  if ($('#email').val()==""){
    switch(idiomaPrincipal){
      case "en":
        alert("Please indicate the e-mail. It is mandatory.");
        break;
      case "de":
        alert("Bitte geben Sie die E-Mail. Es ist zwingend erforderlich.");
        break;
      case "fr":
        alert("S'il vous plaît indiquer l'e-mail. Il est obligatoire.");
        break;
      default:
        alert("Por favor, indique el correo electrónico. Es obligatorio.");
    }
    $('#email').val("");
    $('#email').css({border: "1px solid red"}).focus();
    return false;
  }else{$('#email').css({border: "1px solid #ff9627"});}
  
  //Productos
  if ($('#consulta').val()==""){
    switch(idiomaPrincipal){
      case "en":
        alert("Please indicate the products. It is mandatory.");
        break;
      case "de":
        alert("Bitte geben Sie die Produkte. Es ist zwingend erforderlich.");
        break;
      case "fr":
        alert("S'il vous plaît indiquer les produits. Il est obligatoire.");
        break;
      default:
        alert("Por favor, indique los productos de su interés. Es obligatorio.");
    }
    $('#consulta').val("");
    $('#consulta').css({border: "1px solid red"}).focus();
    return false;
  }else{$('#consulta').css({border: "1px solid #ff9627"});}
  
  $.get("/php_lib/ajax.php", { accion: "consultaEnviar", empresa: $('#empresa').val(), contacto:$('#contacto').val(),
                               ciudad:$('#ciudad').val(), pais:$('#pais').val(), telefono:$('#telefono').val(), 
                               fax:$('#fax').val(), email:$('#email').val(), consulta:$('#consulta').val() },
  function(data){
    if (data != "error"){//Indicamos mensaje de OK
      $('#resultado-formulario').html(data);
      $('#form-presupuesto :input').val('');
      return true;
    }else{
      switch(idiomaPrincipal){
        case "en":
          $('#resultado-formulario').html("Error, try again in a few minutes.");
          break;
        case "de":
          $('#resultado-formulario').html("Fehler, versuchen Sie es in ein paar Minuten erneut.");
          break;
        case "fr":
          $('#resultado-formulario').html("Erreur, réessayer dans quelques minutes.");
          break;
        default:
          $('#resultado-formulario').html("Error, inténtelo de nuevo en unos segundos.");
      }
      return false;
    }
  });
  return true;
}
