function estaMarcat(marcat){
	if (marcat == true){
		document.getElementById('seleccionats').value++;
	} else {
		document.getElementById('seleccionats').value--;
	}
}
function canviaEstat(id, op){
	enviaForm(id, op);
}
function mostraContingut(id){
	document.getElementById('tipus').value = "ContingutCat";
	document.getElementById('ordre').value = "";
	document.getElementById('sentit').value = "";
	enviaForm(id, '');
}
function pujaOrdre(id){
	enviaForm(id, 'pujaordre');
}
function baixaOrdre(id){
	enviaForm(id, 'baixaordre');
}
function desaOrdre(){
	marcaTot();
	document.getElementById('op').value = 'desaordre';
	document.getElementById('formulari').submit();
}
function busca(){
	document.getElementById('formulari').submit();
}
function enviaForm(id, op){
	desmarcaTot();
	marca(id);
	document.getElementById('op').value = op;
	document.getElementById('formulari').submit();
}
function desmarcaTot(){
	var i = 0;
	while(document.getElementById('id'+i)){
		document.getElementById('id'+i).checked = false;
		i++;
	}
	document.getElementById('seleccionats').value = 0;
}
function marca(id){
	document.getElementById(id).checked = true;
	estaMarcat(true);
}
function marcaTot() {
	var i = 0;
	while(document.getElementById('id'+i)){
		document.getElementById('id'+i).checked = true;
		i++;
	}
	document.getElementById('seleccionats').value = i;
}
function selecciona(sel){
	if(sel)
		marcaTot();
	else
		desmarcaTot();
}
function canviaLlista(){
	document.getElementById('op').value = 'veure';
	document.getElementById('formulari').submit();
}
function focusCerca(){
	if(document.getElementById('cerca')){
		document.getElementById('cerca').focus();
	}
	if(typeof(carrega) == "function")
		carrega();
}
function validaDates(ini, fi){
	var retorn = true;
	if(fi && ini){
		var di = parseInt(ini.replace(/[- :]/g,""));
		var fi = parseInt(fi.replace(/[- :]/g,""));
		if(di > fi)
			retorn = false;
	}
	return retorn;
}
function esborraData(id){
	if(document.getElementById(id))
		document.getElementById(id).value = "";
}
function canviaOrdre(ordre){
	var ordreActual = document.getElementById('ordre').value;
	var sentitActual = document.getElementById('sentit').value;
	if(ordre == ordreActual){
		document.getElementById('sentit').value = (sentitActual == 'asc' ? 'desc' : 'asc');
	}
	document.getElementById('ordre').value = ordre;
	document.getElementById('formulari').submit();
}
function canviaPagina(pagina){
	document.getElementById('inici').value = pagina;
	document.getElementById('formulari').submit();
}
function finestraEmergent(bot, titol, amplada, alcada){
	window.open(bot, titol, 'width='+amplada+',height='+alcada);
}
function passaValor(id){
	document.getElementById(id+'visible').value = document.getElementById(id).value;
	seleccionaInput(id);
}
function seleccionaInput(id){
	document.getElementById(id+'boto').select();
}
function muntaMenu(id){
	$(" #menus ul ").css({display: "none"}); // Opera Fix
	$(" #menus li").hover(function(){
			$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
			},function(){
			$(this).find('ul:first').css({visibility: "hidden"});
	});
}
function inicialitzaCercador(){
	if(document.getElementById('cercador')){
		if(document.getElementById('textCerca').value == ""){
			document.getElementById('textCerca').onclick = function(){
				document.getElementById('textCerca').value = "";
			};
			document.getElementById('textCerca').value = "cerca...";
		}
	}
}
function inicialitzaPagina(){
	muntaMenu('menus');
	carregaGaletes();
	inicialitzaCercador();
	if(typeof(carrega) == 'function')
		carrega();
}
function inicialitzaPortada(){
	carregaGaletes();
	inicialitzaCercador();
	if(typeof(carrega) == 'function')
		carrega();
}
function carregaGaletes(){
	document.cookie="ampladaPantalla="+screen.width+";";
	document.cookie="alcadaPantalla="+screen.height+";";
}
function validaArxiu(idNou, idActual){
	var retorn = false;
	if(document.getElementById(idNou).value != ''){
		if(document.getElementById(idActual).value == '')
			document.getElementById(idActual).value = document.getElementById(idNou).value;
		retorn = true;
	}
	return retorn;
}
function marcaGrup(camp){
	if(document.getElementById(camp) && document.getElementById("grup_"+camp)){
		var nomCamps = document.getElementById("grup_"+camp).value;
		var ids = nomCamps.split(',');
		for(var i=0; i < ids.length; i++){
			if(document.getElementById(ids[i]))
				document.getElementById(ids[i]).checked = document.getElementById(camp).checked;
		}
	}
}