var indiceForm = 0;
function setDo(valor){
	document.getElementById('do').value=valor;
  	return true;
};	
function llamarCercar(){
	setDo('cercarMiniAny');
	/*Se ha puesto el método getElementById() por que el document.forms[0] en gencat.cat es un buscador diferente. */
	document.getElementById("cercaItinerarisForm").target = 'new';
	document.getElementById("cercaItinerarisForm").submit();			
}
function llamarMesOpcions(){
	setDo('mesOpcionsMiniAny'); 
	/*Se ha puesto el método getElementById() por que el document.forms[0] en gencat.cat es un buscador diferente. */
	document.getElementById("cercaItinerarisForm").target = 'new';
	document.getElementById("cercaItinerarisForm").submit();			
}
(function($){
	$(document).ready(function(){
		$(window).trigger("resize");
		$("#enviarDades, #cercar").click(switchSubmit);
	});
	$(window).resize(function(){ $(".boxline > .FW_sImpacteForm").children("p").equalizeHeights(); });
	$.fn.equalizeHeights = function(){
		if(arguments.length > 1 && typeof arguments[1] == "function") 
			arguments[1].apply(this, arguments);
		var marginAndPadding = arguments.length && arguments[0] === true ? true: false,
			maxHeight = 0;
		this.css("min-height","0");
		if(marginAndPadding)
			maxHeight = Math.max.apply(this, $(this).map(function(i,e){ return $(e).outerHeight(true) }).get());
		else
			maxHeight = Math.max.apply(this, $(this).map(function(i,e){ return $(e).height() }).get());
		return this.css("min-height",maxHeight+"px");
	};
	function switchSubmit(e){
		var e = e || window.event,
			target = e.target || e.srcElement,
			wrap = $(target).closest(".boxline"),
			form = wrap.find("form"),
			message = wrap.find(".infomessage"),
			isEmpty = form.find("input[type='text']").map(function(){ if(this.value.length == 0) return true; })[0];
		
		if (isEmpty) 
			message.removeClass("hidden");
		else {
			message.addClass("hidden");
			if (form.is("#cerca_itineraris")) {
				tractar_camp('ctn_o');
				tractar_camp('ctn_d');
				form[0].submit();
			}
			else 
				if (form.is("#cercaItinerarisForm")) 
					llamarCercar();
		}
		$(".boxline .FW_sCaixaFormClar").equalizeHeights();
	}
})(jQuery);

