﻿  $(document).ready(function() {
	$('.error').hide(); 
	
	$(".aux4").click(function() {
      // validate and process form here
	  $('.error').hide();
  	  var name = $("input#nombre").val();
	  name = name.replace(/^\s*|\s*$/g,"");
  		if (name == "") {
        $("label#name_error").show();
        $("input#nombre").focus();
        return false;
      }
  		var email = $("input#email").val();
		 email = email.replace(/^\s*|\s*$/g,"");
  		if (email == "") {
        $("label#name_error").show();
        $("input#email").focus();
        return false;
      }
  		var phone = $("input#telefono").val();
  		phone = phone.replace(/^\s*|\s*$/g,"");
  		if (phone == "") {
        $("label#name_error").show();
        $("input#telefono").focus();
        return false;
      }
	  var opo = $("input#oposicion").val();
	  opo = opo.replace(/^\s*|\s*$/g,"");
  		if (opo == "") {
        $("label#name_error").show();
        $("input#oposicion").focus();
        return false;
      }
	   jQuery.fn.reset = function () {
		$(this).each (function() { this.reset(); });
	   }
	   $("#frmContacto").reset();	
      var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&opo=' + opo;
	  //alert (dataString);return false;
	  $.ajax({
	    type: "POST",
	    url: "bin/rate.php",
	    data: dataString,
		complete: function() {
		  $("#aux").reset();		  
	      	  $('#message').html("<h2>¡¡Formulario enviado!!</h2>")	      
	      .hide()
	      .fadeIn(1500, function() {
	        $('#message').append("<span style=\"FLOAT: left\"><img src='images/left_nav_arrow.gif' />Pronto contactaremos con usted.<br>Gracias</span>");			
	      });
		  $('#message').fadeOut(4500);      
		  
		}
	});
	
	return false;
    });
	$('#name_error_busqueda').hide(); 
	$(".aux5").click(function() {
      // validate and process form here
	  $('#name_error_busqueda').hide();
  	 // var texto = $("input#textoclave").val();
		var idCatOpo=  $("select#idCatOpo").val();
	  	var idOpo=  $("select#idOpo").val();
  		var idp = $("select#idProvincia").val(); 
		
		
		if (idCatOpo!="1" && idp == "-1" && idOpo=="-1") {
			$("label#name_error_busqueda").show();
			$("select#idOpo").focus();
			return false;
		}
				
      	   var dataString = 'idOpo='+ idOpo + '&idProvincia=' + idp+ '&idCatOpo='+idCatOpo;

	 $.ajax({
	    type: "POST",
	    url: "bin/main.php",
	    data: dataString,
		dataType: "script",
     	 	beforeSend: function(objeto){	     	 	
			$("#results").html("<span style=\"FLOAT: left\">Realizando búsqueda. Espere por favor...<img src='images/bigrotation2.gif'  alt='cargando...' /></span>");
		  },
		  success: function(msg){			
			$("#results").html(msg);
		  },
		  error: function(objeto, quepaso, otroobj){
			$("#results").html("ERROR!! Error en la búsqueda");
		  }
		
	});
	return false;
	});	

 });
   
    
function mostrarMapa1(mapa)
{	
	document.getElementById('iframe1').src='html/mapa1.html';
}

function mostrarMapa2(mapa)
{	
document.getElementById('iframe1').src='html/mapa2.html';
}
function mostrarMapa3(mapa)
{	
document.getElementById('iframe1').src='html/mapa3.html';
}
function enviar()
{
document.frmContacto.submit();
}
function enviarBusqueda()
{
document.frmBusqueda.submit();
}
function ponerFoco()
{
document.getElementById('nombre').focus();
}
function goToForm(texto)
{
document.frmContacto.oposicion.value=texto;
document.frmContacto.nombre.focus();

}
function goBlur(obj)
{
obj.className='contact_input';
}
function goFocus(obj)
{
obj.className='contact_inputfocus';
}