$(document).ready(function() {
	$('#formu_cercador').submit(function() {
  		buscar_form();
 		return false;
	});
	$(".contingut").click(function(){tancar()});
});
buscar_form = function(){
	if(document.formu_cercador.query.value != ""){
		document.formu_cercador.action = document.formu_cercador.action + "/"+escape(document.formu_cercador.query.value);
		document.location = document.formu_cercador.action;
	}
}
function volver(ruta){
	if(history.length > 1){
		history.back();
	}else{
		document.location = ruta;
	}
}
function firstCapital(str){
	return str.substr(0, 1).toUpperCase() + str.substr(1);	
}
function IsNumeric(input){
   return (input - 0) == input && input.length > 0;
}
function IsArray(input){
	return typeof(input)=='object'&&(input instanceof Array);
}
function in_array (needle, haystack, argStrict) {
    var key = '', strict = !!argStrict; 
    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {                return true;
            }
        }
    }
     return false;
}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}
function trimNumber(s) {
  while (s.substr(0,1) == '0' && s.length>1) { s = s.substr(1,9999); }
  return s;
}
function getPropFromArray(arr,id,prop){
	for(var it in arr){
		if(arr[it].id == id){
			return arr[it][prop];
		}
	}
}
function num2money(n_value) {
// validate input
if (isNaN(Number(n_value)))
return 'ERROR';

// save the sign
var b_negative = Boolean(n_value < 0);
n_value = Math.abs(n_value);

// round to 1/100 precision, add ending zeroes if needed
var s_result = String(Math.round(n_value * 1e2) % 1e2 + '00').substring(0, 2);

// separate all orders
var b_first = true;
var s_subresult;
while (n_value >= 1) {
s_subresult = (n_value >= 1e3 ? '00' : '') + Math.floor(n_value % 1e3);
s_result = s_subresult.slice(-3) + (b_first ? ',' : '.') + s_result;
b_first = false;
n_value = n_value / 1e3;
}
// add at least one integer digit
if (b_first)
s_result = '0,' + s_result;

// apply formatting and return
return b_negative
? '(' + s_result + ' €)'
: s_result + ' €';
}

function fecha_para_usuario(str){
	if(str.search(" ") > -1){
		var ar = str.split(" ");
		var hora = ar[1].split(":");
		hora = hora[0]+":"+hora[1];
		str = ar[0];
		var myDate = str.split("-");
	}
	str = myDate[2]+"-"+myDate[1]+"-"+myDate[0];
	if(hora != ""){
		return str+"<br/>"+hora;
	}else{
		return str;
	}
}
function fecha_pasada(str){
	var ar = str.split(" ");
	var hora = ar[1].split(":");
	hora = hora[0]+":"+hora[1];
	str = ar[0];
	var myDate = str.split("-");
	var fecha = new Date();
	fecha.setFullYear(myDate[0],myDate[1]-1,myDate[2]);
	var ahora = new Date();
	return (ahora > fecha);
}
