/*funcions dels formularis*/
var capant='';

function canviFoto(camp){
	document.getElementById('img_'+camp).src=document.getElementById(camp).value;
}

function comprovacio(camps,noms,eltexte,frase){
	camps=camps.split(',');
	noms=noms.split(',');
	correcte=1;

	for(i=0;i<(camps.length-1);i++){
		if(!document.getElementById(camps[i]).value){
			alert(eltexte+noms[i]);
			document.getElementById(camps[i]).focus();
			correcte=0;
		}
	}
	
	if(correcte){
		if(confirm(frase)) correcte=1;
		else correcte=0;
	}
	
	if(correcte){
		cargar(1,'Cargando ');
		return true
	}else return false;
}

function data(camp){
	document.getElementById(camp).value=document.getElementById('anyo_'+camp).value+'-'+document.getElementById('mes_'+camp).value+'-'+document.getElementById('dia_'+camp).value;
}

function hora(camp){
	document.getElementById(camp).value=document.getElementById('hora_'+camp).value+':'+document.getElementById('minuts_'+camp).value;
}

function check(camp,total){
	document.getElementById(camp).value='';
	for (i=0;i<total;i++){	

		if(document.getElementById('check'+i+'_'+camp).checked)
			document.getElementById(camp).value=document.getElementById(camp).value+document.getElementById('check'+i+'_'+camp).value+',';
	}
}

function cargasub(camp,elidsel,campdepenentinvisble){ 		
	document.getElementById(camp).options.length=0;
 	parent.frames.eliframe.location.href = 'invis.php?nomdelselect='+camp+'&elidepen='+campdepenentinvisble+'&taula='+camp+'&elidsel='+elidsel;
}


function SelectMultipleBorra(camp1,camp2){
 	document.getElementById(camp1).value='';
 	document.getElementById(camp2).value='';
 	parent.frames.eliframe2.location.href = '/admin/invis.php?camp1='+camp1+'&camp2='+$camp2+'&valor1='+document.getElementById(camp1).value+'&valor2='+document.getElementById(camp2).value;
}
 	
function SelectMultipleOmplir(camp1,camp2){
 	document.getElementById(camp1).value=document.getElementById(camp1).value+document.getElementById('id_comarca').value+',';
 	document.getElementById(camp2).value=document.getElementById(camp2).value+document.getElementById('id_municipi').value+',';
 	parent.frames.eliframe2.location.href = '/admin/invis.php?camp1='+camp1+'&camp2='+camp2+'&valor1='+document.getElementById(camp1).value+'&valor2='+document.getElementById(camp2).value;
}

function SelectInfinitAfegir(camp,id){
	document.getElementById(camp).value=document.getElementById(camp).value+id+',';
}

function SelectMultipleAfegir(camp,frame,taula1,taulamig,camp1,idreg){
	document.getElementById(camp).value=document.getElementById(camp).value+document.getElementById('select'+camp).value+',';
	frame.location.href='invis.php?nominput='+camp+'&id='+idreg+'&camp1='+camp1+'&taula1='+taula1+'&taulamig='+taulamig+'&ids='+document.getElementById(camp).value;
}

function afegirSelectIdpare(nom,nomselect,idreg,campveure,taula){
	if(document.getElementById('idsrel').value) idsafegits=document.getElementById('idsrel').value+document.getElementById(nomselect).value+",";
	else idsafegits=document.getElementById(nomselect).value+",";

	document.location.href="iframes.php?idsrel="+idsafegits+"&include=selectIdpare&taula="+taula+"&campveure="+campveure+"&idreg="+idreg+"&nom="+nom;
}

/*funcions pel menu*/
function apareixaCapa(capa){
	
	
	if(document.getElementById(capa).style.visibility=='hidden'){
		if(capant && document.getElementById(capant).style.visibility=='visible') document.getElementById(capant).style.visibility='hidden';
		document.getElementById(capa).style.visibility='visible';
		capant=capa;
	}else{
		document.getElementById(capa).style.visibility='hidden';
		capant='';
	}
	
	
}


function afegirDocuments(valor,taula,idreg){
	
	valors=valor.split('_');
	
	if(document.getElementById(taula).value) idsafegits=document.getElementById(taula).value+valors[0]+",";
	else idsafegits=valors[0]+",";

	document.getElementById('iframeDocs').src="iframes.php?idsrel="+idsafegits+"&include=varisFitxers&taula="+taula+"&idreg="+idreg;
}

function afegirCalendariMultiple(capa,data){
	parent.document.getElementById(capa).value=parent.document.getElementById(capa).value+','+data;
	frami=parent.document.getElementById('calendari'+capa+'Multiple');
	frami.src="iframes.php?include=calendariMultipleList&nom="+capa+"&valors="+parent.document.getElementById(capa).value;
}


function ShowMenu(num, menu, max)
{
		
		//alert (num);
		for(i = 1; i <= max; i++){
		var menu2 = menu + i;
		if (num==i)		document.getElementById(menu2).style.display = 'block';
		else document.getElementById(menu2).style.display = 'none';
	}
	
}

function cargar(i,frase){
	if(i) document.getElementById('cargando').innerHTML=frase;
	else document.getElementById('cargando').innerHTML=document.getElementById('cargando').innerHTML+' .';
	setTimeout("cargar(0,'"+frase+"')",500);
}

function apareixapestanya(capa,menu){
	menu=menu.split(',');

	for(i=0;i<(menu.length-1);i++){				
		document.getElementById('capa'+menu[i]).style.visibility='hidden';
		document.getElementById('capa'+menu[i]).style.position='absolute';
		document.getElementById('td'+menu[i]).className="pestanyaoff";
	}
	
	document.getElementById('capa'+capa).style.visibility='visible';
	document.getElementById('capa'+capa).style.position='static';
	document.getElementById('td'+capa).className="pestanyaon";
}

function comparadates(d1_str,d2_str){
	d1 = new Date(d1_str.split('-')[2],d1_str.split('-')[1],d1_str.split('-')[0]);
	d2 = new Date(d2_str.split('-')[2],d2_str.split('-')[1],d2_str.split('-')[0]);

	if (d1.getTime()<d2.getTime()) {
  	return true;
	}else return false;
	
}