/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// acte_gestio.php
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function SendOnOff(id_acte, show)
{
	document.FormModif.accio.value="onoff";
	document.FormModif.acte.value=id_acte;
	document.FormModif.onoff.value=show;
	document.FormModif.modificar.value=null;
	
	if(show==1)
	{
		if(confirm("estas segur que vols ANULAR aquest ACTE?"))
			document.FormModif.submit();
		else
			return false;
	}
	else			
		document.FormModif.submit();
}
function SendGeneralOnOff(id_acte, general)
{
	document.FormModif.accio.value="general";
	document.FormModif.acte.value=id_acte;
	document.FormModif.general.value=general;
	document.FormModif.modificar.value=null;
	/*
	if(general==1)
	{
		if(confirm("estas segur que vols ANULAR aquest ACTE?"))
			document.FormModif.submit();
		else
			return false;
	}
	else	
	*/
		document.FormModif.submit();
}
function SendDelete(id_acte)
{
	if(confirm("estas segur que vols ELIMINAR aquest ACTE?\nes borraran tots els comentaris i totes les fotos...\npotser millor l\'anulis..."))
	{
		document.FormModif.accio.value="del";
		document.FormModif.acte.value=id_acte;
		document.FormModif.onoff.value=null;
		document.FormModif.modificar.value=null;
		document.FormModif.submit();
	}
}
function SendModif(id_acte)
{		
	document.FormModif.accio.value="modif";
	document.FormModif.acte.value=id_acte;
	document.FormModif.onoff.value=null;
	document.FormModif.modificar.value="1";
	document.FormModif.submit();
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// acte_insert.php
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function FuncioInsertar()
{
	if(document.FormInsert.preu.value=="")
		document.FormInsert.preu.value = 0;
	else
	{		
		if(isNaN(document.FormInsert.preu.value)||(document.FormInsert.preu.value.charAt(0)==' '))
		{
			alert("el preu ha de tenir un numero valid!\np.ex. 10 o 10.50");
			return false;
		}
	}
	
	document.FormInsert.ACTE_insert_ok.value="1";
	document.FormInsert.ACTE_modif_ok.value=null;
	
	/*
	if(!document.FormInsert.imatge.value)
	{
		if(document.FormInsert.FOTO_SERVER.value!=null)
		{
			document.FormInsert.imatge.value = document.FormInsert.FOTO_SERVER.value;
			//alert(document.FormInsert.imatge.value);
		}
	}
	*/
	
	document.FormInsert.submit();
}
function FuncioModificar(id_acte)
{
	if(document.FormInsert.preu.value=="")
		document.FormInsert.preu.value = 0;
	else
	{		
		if(isNaN(document.FormInsert.preu.value)||(document.FormInsert.preu.value.charAt(0)==' '))
		{
			alert("el preu ha de tenir un numero valid!\np.ex. 10 o 10.50");
			return false;
		}
	}
	
	document.FormInsert.ACTE_insert_ok.value=null;
	document.FormInsert.ACTE_modif_ok.value=id_acte;
	
	//if(!document.FormInsert.imatge.value)
		//alert("noooor");		
	
	document.FormInsert.submit();
}
function FuncioReset()
{
	document.FormInsert.ACTE_insert_ok.value=null;
	document.FormInsert.ACTE_modif_ok.value=null;
	document.FormInsert.submit();
}
function FuncioVeureImatges()
{
	var element = document.getElementById('fotos_server');
	
	if(element.className == 'style_div_imatges_server_on')
		element.className = 'style_div_imatges_server_off';
	else
		element.className = 'style_div_imatges_server_on';
}
function FuncioImatgeTitol(id,total)
{	
	if(document.getElementById(id).className == 'style_imatge_normal')
	{
		document.getElementById(id).className = 'style_imatge_titol';
		document.FormInsert.imatge.value = document.getElementById(id).name;
		//document.FormInsert.FOTO_SERVER.value =;
	}
	else
		document.getElementById(id).className = 'style_imatge_normal';
		
	for(i=0; i<total; i++)
	{			
		img_imatge = "img"+i;
		if(img_imatge==id) continue;
		document.getElementById(img_imatge).className = 'style_imatge_normal';
	}		
}
function FuncioSeleccioFotos(id_acte,total)
{		
	//totes visibles...
	if(id_acte==0)
	{
		for(i=0; i<total; i++)
		{
			img_imatge = "img"+i;
			document.getElementById(img_imatge).parentNode.className = 'style_div_imatge_on';
		}
	}	
	else if(id_acte==-1)
	{
		for(j=0; j<total; j++)
		{
			img_imatge = "img"+j;
	
			var FK_acte = document.getElementById(img_imatge).parentNode.id.split('_');		
		
			var off=0;
			for(i=1; i<document.getElementById('combo_actes').options.length-1; i++)
			{				
				if(FK_acte[0] == document.getElementById('combo_actes').options[i].value)
				{
					document.getElementById(img_imatge).parentNode.className = 'style_div_imatge_off';
					off = 1;
					break;						
				}			
			}
			
			if(off!=1)
				document.getElementById(img_imatge).parentNode.className = 'style_div_imatge_on';
		}
	}
	else
	{
		for(i=0; i<total; i++)
		{
			img_imatge = "img"+i;
	
			var FK_acte = document.getElementById(img_imatge).parentNode.id.split('_');	
			
			if(FK_acte[0]==id_acte)
			{
				document.getElementById(img_imatge).parentNode.className = 'style_div_imatge_on';
			}
			else
			{
				document.getElementById(img_imatge).parentNode.className = 'style_div_imatge_off';
			}
		}
	}
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// newuser.php
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function FuncioAcceptNewUser()
{	
	f = document.FormNewUser;
	
	if(!CadenaOK(f.nom.value))
	{
		alert ("fica un NOM correcte!");
		f.nom.focus();
		return false;
	}
	
	if(!CadenaOK(f.cognoms.value))
	{
		alert ("fica uns COGNOMS correctes!");
		f.cognoms.focus();
		return false;
	}
	
	if(!NickOK(f.nickname.value))
	{
		alert ("fica un NICK correcte i sense espais en blanc!");
		f.nickname.focus();
		return false;
	}
	
	if(!EmailOK(f.email01.value))
	{
		alert ("fica un ENAIL correcte!");
		f.email01.focus();
		return false;
	}

	if(f.email01.value != f.email02.value)
	{
		alert ("els EMAILS no coincideixen!");
		f.email02.focus();
		return false;
	}
	
	if(!PasswordOK(f.pass01.value))
	{
		alert ("fica un PASSWORD sense espais en blanc!");
		f.pass01.focus();
		return false;
	}
	
	if(f.pass01.value != f.pass02.value)
	{
		alert ("els PASSWORDS no coincideixen!");
		f.pass02.focus();
		return false;
	}
	
	f.submit();
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// user_data.php
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function FuncioModifyDataUser()
{	
	f = document.FormUserData;
	
	if(!CadenaOK(f.nom.value))
	{
		alert ("fica un NOM correcte!");
		f.nom.focus();
		return false;
	}
	
	if(!CadenaOK(f.cognoms.value))
	{
		alert ("fica uns COGNOMS correctes!");
		f.cognoms.focus();
		return false;
	}
	/*
	if(!NickOK(f.nickname.value))
	{
		alert ("fica un NICK correcte i sense espais en blanc!");
		f.nickname.focus();
		return false;
	}
	*/
	if(!EmailOK(f.email01.value))
	{
		alert ("fica un ENAIL correcte!");
		f.email01.focus();
		return false;
	}

	if(f.email01.value != f.email02.value)
	{
		alert ("els EMAILS no coincideixen!");
		f.email02.focus();
		return false;
	}
	
	if(f.pass01.value != "")
	{
		if(!PasswordOK(f.pass01.value))
		{
			alert ("fica un PASSWORD sense espais en blanc!");
			f.pass01.focus();
			return false;
		}
		
		if(f.pass01.value != f.pass02.value)
		{
			alert ("els PASSWORDS no coincideixen!");
			f.pass02.focus();
			return false;
		}
	}
	
	f.submit();
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// login.php
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ViewInsert()
{
	document.ViewAdmin.INDEX_session_close.value=null;
	document.ViewAdmin.INDEX_acte_new.value="1";
	document.ViewAdmin.INDEX_acte_gest.value=null;
	
	if( document.URL.substring(document.URL.lastIndexOf("/",document.URL.length)+1, document.URL.length) != "index.php")
	{
		document.ViewAdmin.action = "index.php";
	}
	
	document.ViewAdmin.submit();
}
function ViewGestion()
{	
	document.ViewAdmin.INDEX_session_close.value=null;	
	document.ViewAdmin.INDEX_acte_new.value=null;
	document.ViewAdmin.INDEX_acte_gest.value="1";

	if( document.URL.substring(document.URL.lastIndexOf("/",document.URL.length)+1, document.URL.length) != "index.php")
	{
		document.ViewAdmin.action = "index.php";
	}		
	
	document.ViewAdmin.submit();
}
function ViewUsuaris()
{	
	document.ViewAdmin.INDEX_session_close.value=null;	
	document.ViewAdmin.INDEX_acte_new.value=null;
	document.ViewAdmin.INDEX_acte_gest.value=null;
	document.ViewAdmin.INDEX_usuaris.value="1";

	if( document.URL.substring(document.URL.lastIndexOf("/",document.URL.length)+1, document.URL.length) != "index.php")
	{
		document.ViewAdmin.action = "index.php";
	}		
	
	document.ViewAdmin.submit();
}
function CloseSession()
{		
	document.ViewAdmin.INDEX_session_close.value="1";
	document.ViewAdmin.INDEX_acte_new.value=null;
	document.ViewAdmin.INDEX_acte_gest.value=null;		
	document.ViewAdmin.submit();
}
function FuncioLoggin()
{
	document.LogginForm.USER_LOGGIN.value=1;
	document.LogginForm.USER_REGISTER.value=null;
	document.LogginForm.submit();
}
function FuncioRegister()
{
	document.LogginForm.USER_LOGGIN.value=null;
	document.LogginForm.USER_REGISTER.value=1;
	document.LogginForm.action = "index.php";
	document.LogginForm.submit();
}
function ShowModifUserInfo()
{
	document.ViewAdmin.INDEX_session_close.value=null;	
	document.ViewAdmin.INDEX_acte_new.value=null;
	document.ViewAdmin.INDEX_acte_gest.value=null;
	document.ViewAdmin.INDEX_usuaris.value=null;
	document.ViewAdmin.INDEX_modifcar_dades_usuari.value=1;
	
	if( document.URL.substring(document.URL.lastIndexOf("/",document.URL.length)+1, document.URL.length) != "index.php")
	{
		document.ViewAdmin.action = "index.php";
	}		
	
	document.ViewAdmin.submit();
}
function Mailing()
{
	document.ViewAdmin.INDEX_session_close.value=null;	
	document.ViewAdmin.INDEX_acte_new.value=null;
	document.ViewAdmin.INDEX_acte_gest.value=null;
	document.ViewAdmin.INDEX_usuaris.value=null;

/*
	if( document.URL.substring(document.URL.lastIndexOf("/",document.URL.length)+1, document.URL.length) != "index.php")
	{
		document.ViewAdmin.action = "index.php";
	}
	
	document.ViewAdmin.submit();
*/
	var pagina="code/php/toSend_mailing.php";
	var opciones="toolbar=0, location=0, directories=0 status=0, menubar=0, scrollbars=yes, resizable=0, width=920, height=720 ";
	nuevaVentana = window.open(pagina,"jajaja",opciones);
	nuevaVentana.document.body.style.marginLeft=0;
	nuevaVentana.document.body.style.marginTop=0;
	nuevaVentana.document.title=pagina.split('/')[1];	
}
function Publicitat()
{
	var pagina="code/php/publicitat_update.php";
	var opciones="toolbar=0, location=0, directories=0 status=0, menubar=0, scrollbars=0, resizable=0, width=600, height=500 ";
	nuevaVentana = window.open(pagina,"jajaja",opciones);
	nuevaVentana.document.body.style.marginLeft=0;
	nuevaVentana.document.body.style.marginTop=0;
	nuevaVentana.document.title=pagina.split('/')[1];
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// blog_acte.php
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function InsertComentari()
{
	//alert( document.URL.substring(document.URL.lastIndexOf("=",document.URL.length)+1, document.URL.length) );
	if(confirm("segur que vol enviar aquest comentari?"))
		document.InsertComment.submit();
	else
		return false;
}
function ComentariOnOff(id_comentari, activate)
{
	document.FormBlogActeModif.accio.value="onoff";
	document.FormBlogActeModif.comentari.value=id_comentari;
	document.FormBlogActeModif.onoff.value=activate;
	
	if(activate==1)
	{
		if(confirm("estas segur que vols ANULAR aquest COMENTARI?"))
			document.FormBlogActeModif.submit();
		else
			return false;
	}
	else			
		document.FormBlogActeModif.submit();	
}
function ComentariDelete(id_comentari)
{
	document.FormBlogActeModif.accio.value="delete";
	document.FormBlogActeModif.comentari.value=id_comentari;
	document.FormBlogActeModif.onoff.value=null;
	
	if(confirm("estas segur que vols ELIMINAR aquest COMENTARI?"))
		document.FormBlogActeModif.submit();
	else
		return false;
}
function FuncioSelectBlog(id_acte)
{
	if(id_acte==-1)
		return;
		
	document.AllBlogs.action = "blog.php?acte="+id_acte;
	document.AllBlogs.submit();
}
function FuncioVeureDiv(evento,nom_div,div_hidden_1)
{
	var element = document.getElementById(nom_div);
	var posx = 0;
	var posy = 0;
	var incX = 5;
	var incY = 5;
	
	if(document.all)
	{
		posx = event.clientX + document.body.scrollLeft + incX;
		posy = event.clientY + document.body.scrollTop  + incY;
	}
	else
	{
		document.captureEvents(Event.MOUSEMOVE);		
		posx = evento.pageX + incX;
		posy = evento.pageY + incY;
	}
	
	if(element.style.visibility == 'hidden')
	{
		element.style.visibility = 'visible';
		element.style.top = posy;
		element.style.left = posx;
	}
	else
	{
		element.style.visibility = 'hidden';
	}
	
	//anulo tots els altres
	element = document.getElementById(div_hidden_1);
	element.style.visibility = 'hidden';
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// users_gestio.php
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function UsuariOnOff(id_usuari, show)
{
	document.FormUserGestio.usuari.value=id_usuari;
	document.FormUserGestio.accio.value="onoff";
	document.FormUserGestio.onoff.value=show;
		
	if(show==1)
	{
		if(confirm("estas segur que vols ANULAR aquest USUARI?"))
			document.FormUserGestio.submit();
		else
			return false;
	}
	else			
		document.FormUserGestio.submit();
}
function ModifUsuari(id_usuari,sel)
{
	document.FormUserGestio.usuari.value=id_usuari;
	document.FormUserGestio.accio.value="modif";
	document.FormUserGestio.limfoto.value=sel.options[sel.selectedIndex].value;
	//document.FormUserGestio.onoff.value=show;		
	document.FormUserGestio.submit();
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// tots els que vulguin...
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function AmpliarFoto(pagina)
{
	var opciones="toolbar=0, location=0, directories=0 status=0, menubar=0, scrollbars=0, resizable=0, width=320, height=240 ";
	nuevaVentana = window.open(pagina,"jajaja",opciones);
	nuevaVentana.document.body.style.marginLeft=0;
	nuevaVentana.document.body.style.marginTop=0;
	nuevaVentana.document.title=pagina.split('/')[1];	
}



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// menu_actes.php
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function MenuActes(visible)
{
	var element = document.getElementById('menuactes');
	
	if(visible)
		element.className = 'style_temp_visible';
	else
		element.className = 'style_temp_hidden';
}

function MenuActesSelect(year,month)
{
	var txt_year = ""+year;
	var txt_month = ""+month;
	
	if(month<10)
		txt_month = "0"+month;
		
	document.FormMenuActes.MENU_data.value = txt_year+txt_month+"01";
	
	document.FormMenuActes.submit();
}



function ShowMyAlt(evento,element,texto)
{
	var div = document.createElement('div');	
	div.id = 'MyAlt';	
	div.className = 'MyAltStyle';
	div.innerHTML = texto;
	
	element.appendChild(div);
}


function RemoveMyAlt(element)
{
	var el = document.getElementById('MyAlt');
	
	if(el)
		element.removeChild(el);
}