// Code that handles all the search form processing
var searchForm = {
initForm: function() {
this.setForm();
},
setForm: function() {
var that = this;
$("#paises").change(function() {
$("#pais").val( $(this).val() );
$.ajax({
url: '/templates/main_base/objects/ajax.php',
dataType: 'json',
type: 'POST',
data: {
query: '/lista/distritos?pais=' + $(this).val()
},
success: function(response) {
// Populate the 'distrito' select
$("#distritos").html("");
$.each(response.items, function(i, o) {
$("#distritos").append(
""
);
});
}
});
return false;
});
$("#activo-checkbox").change(function() {
if ( $(this).is(':checked') ) {
$("#activo").val(true);
} else {
$("#activo").val("");
}
});
$("#ccontratos-checkbox").change(function() {
if ( $(this).is(':checked') ) {
$("#ccontratos").val(true);
} else {
$("#ccontratos").val("");
}
});
$("#distritos").change(function() {
$("#distrito").val( $(this).val() );
$.ajax({
url: '/templates/main_base/objects/ajax.php',
dataType: 'json',
type: 'POST',
data: {
query: '/lista/concelhos?distrito=' + $(this).val()
},
success: function(response) {
// Populate the 'concelhos' select
$("#concelhos").html("");
$.each(response.items, function(i, o) {
$("#concelhos").append(
""
);
});
}
});
return false;
});
$("#concelhos").change(function() {
$("#concelho").val( $(this).val() );
});
$("#tipo-contrato").change(function() {
$("#tipocontrato").val( $(this).val() );
return false;
});
$("#tipo-procedimento").change(function() {
$("#tipoprocedimento").val( $(this).val() );
return false;
});
$("#tipo-acto").change(function() {
$("#tipoacto").val( $(this).val() );
return false;
});
$("#tipo-modelo").change(function() {
$("#tipomodelo").val( $(this).val() );
return false;
});
$("#tipo-contrato2").change(function() {
$("#tipocontrato2").val( $(this).val() );
return false;
});
$(".form-ws").submit(function() {
// Clean placeholders from the form submit
//$(".clearit").each(function() {
// if ($(this).attr('placeholder') == $(this).val()) {
// $(this).val("");
// }
//});
var query = encodeURIComponent($(this).serialize()),
type = $(this).attr('id').split('-')[1];
// We need to now the lang and the page to show the results
var lang = $(".getLang").attr("lang");
if (lang == "pt") {
page = 'ResultadosPesquisa';
} else {
page = 'SearchResults';
}
//window.location = '/resultados.php?type=' + type + '&query=' + query;
window.location = '/Base/' + lang + '/' + page + '?type=' + type + '&query=' + query;
return false;
});
},
}
$(document).ready(function() {
$("#advanced1").click(function() {$("#advanceFields1").slideToggle("fast");});
$("#advanced2" ).click(function() {$("#advanceFields2").slideToggle("fast");});
$("#advanced4" ).click(function() {$("#advanceFields4").slideToggle("fast");});
$("#advanced5" ).click(function() {$("#advanceFields5").slideToggle("fast");});
searchForm.initForm();
});