function showPic(whichpic) {   // executa la imatge seleccionada d'<a>
  // verifica si existeix el lloc de la imatge gran
  // obtenim l'href de la imatge seleccionada
  var source = whichpic.getAttribute("href");    
  //alert ("source: " + source);
  
  if (whichpic.getAttribute("title")) {        
	var text = whichpic.getAttribute("title");   // title té la descripció tipus "El cognom"
	switch (text) {								 // text tindrà el nombre de la imatge
		case "El cognom": text = "101"; break;
		case "Etimologia dels cognoms": text = "102"; break;
		case "Arbres genealògics": text = "103"; break;
		case "Heràldica": text = "104"; break;
		case "Cens": text = "105"; break;
		case "impressions": text = "108"; break;
		case "Noms d'ahir": text = "201"; break;
		case "Noms d'avui": text = "202"; break;
		case "Del món de l'art": text = "203"; break;
		case "Beata Teresa Gallifa Palmarola": text = "204"; break;
		case "Missatges a la paret": text = "205"; break;
		case "Illa de Palmarola": text = "206"; break;
		case "El Molí dels Frares": text = "207"; break;
		case "Can Palmarola": text = "208"; break;
		case "Objectes per a la llar": text = "209"; break;
		case "L'euga Palmarola": text = "210"; break;
		case "Seient de cotxe": text = "211"; break;
		case "Palmarola S.L. Cas Banesto": text = "212"; break;
		case "Carrers Palmarola": text = "213"; break;
		case "Webs Palmarola": text = "214"; break;
		case "Palmarola a Amèrica": text = "215"; break;
		case "Diversos": text = "216"; break;
		case "Palau Palmerola": text = "301"; break;
		case "Veïnat Palmerola": text = "302"; break;
		case "Castell de Palmerola": text = "303"; break;
		case "Els marquesos de Palmerola": text = "304"; break;
		case "Ricard Palmerola": text = "305"; break;
		case "Ignasi Palmerola": text = "306"; break;
		case "Salvador Palmerola": text = "307"; break;
		case "Palmerola a Hondures": text = "308"; break;
		case "Carrers Palmerola": text = "309"; break;
		case "Webs Palmerola": text = "310"; break;
		case "Diversos Palmerola": text = "311"; break;
		case "Noms d'ahir ": text = "312"; break;
		case "Noms d'avui ": text = "313"; break;
		case "General Palmarole": text = "401"; break;
		case "Diversos Palmarole": text = "402"; break;
		case "Palmaroli, pintors": text = "501"; break;
		default: text = "101"; break;
	}
	crear_cookies(text);
	} else {var text = "";}

  //alert ("windowlocation: " + window.location);
  var textloc = window.location.href.indexOf("=");  // cerca si és una adreça $get o no
  //alert ("textloc: " + textloc);

  switch (textloc) 
  {  	

	case -1:    // aquest és el cas de quan l'adreça és http://palmarola.cat/cognom/   (adreça !$get)
		  	//alert ("locationhref: " + window.location.href.substring(0,window.location.href.indexOf("cognom/") + 7) + "index.php?titol=" + text + "&imatge=" + nomfoto);
		document.location.href = window.location.href.substring(0,window.location.href.indexOf("cognom/") + 7) + "index.php?titol=" + text + "&imatge=" + source;  // el substring obté l'arrel de la url fins cognom/ inclòs
		break;	  	

	default:   // aquest és el cas de quan l'adreça és http://palmarola.cat/cognom/index.php?titol=....... (adreça $get)
		switch (text) 
		{
			case '108':
				document.location.href = "http://palmarola-impressions.blogspot.com/";
				break;
			
			default:
				//alert ("locationhref: " + window.location.href.substring(0,window.location.href.indexOf("=") + 1) + text + "&imatge=" + source);
				document.location.href = window.location.href.substring(0,window.location.href.indexOf("=") + 1) + text + "&imatge=" + source;  // el substring obté l'arrel de la url fins el signe "=" que segueix a "titol"
				break; }
		}		
  return false;
}

/* és realment la primera funció que executa ja que el primer que fa és addLoadEvent(prepareGallery) */
function prepareGallery() {
  if (!document.getElementsByTagName) return false;    /* verifica si hi ha algun tagName */
  if (!document.getElementById) return false;   /* verifica si hi ha algun id="..." */
  if (!document.getElementById("menu-botons")) return false;  /* verifica si hi ha algun id="menu-botons" */
  var gallery = document.getElementById("menu-botons");  /* cerca on està id="menu-botons" i emmagatzema a gallery tot el contingut*/
  var links = gallery.getElementsByTagName("a"); /* en la variable links emmagatzema tots els tag <a> de gallery*/
  //alert ("links:" + links[0] + " " +  links[1]);
  for ( var i=0; i < links.length; i++) {
    links[i].onclick = function() {   
	  /* quan es fa click en un <a> emmmagatzema a links[i] el resultat d'executar la funció showPic(this)*/
      //alert ("links:" + this);
      return showPic(this); // li passem a la funció showPic tota la informació de <a>
	}
    links[i].onkeypress = links[i].onclick;  // farà per onkeypress el que faci per onclick
  }
}

/* és una funció que index.php executa sempre al carregar rutines.js */
/* la valor func que ha d'executar és el resultat d'una altra funció (prepareGallery) */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

/*EMMAGATZEMAR TITLE IMATGE SELECCIONADA EN UNA COOKIE */
function crear_cookies(text) 
{
	//alert ("entrada crear_cookies:" + document.cookie);
	//alert ("text: " + text);
	//text.replace ("\'", "'");
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+1);
	document.cookie="cognom=- ; expires=Thu, 01-Jan-1970 00:00:01 GMT";
	document.cookie="cognom=-" + text + "; expires=" + exdate.toGMTString();
	//alert ("sortida crear_cookies:" + document.cookie);
	return;
}

/* quan carrega la pàgina index.html, com té indicat script showpic.js, memoritza les funcions i es troba que ha d'executar aquesta (addLoadEvent)*/
/*addLoadEvent(prepareGallery);*/

/* ==================================================================================
   5a. funcions del formulari d'opinió de cognom
===================================================================================*/   

/* VERIFICA LES DADES ENTRADES EN EL MENÚ D'OPINIÓ*/
function valida1(thisform)
{
with (thisform)
{
	switch (ohidden.value) 
	{
		case 'cat':
			if (validarCorreu(onom,"Un nom o un àlies que us identifiqui, si us plau. Gràcies.")==false)
				{onom.focus();return false;}
			if (validarCorreu(opoble,"Ens agradaria conèixer d'on ets. Gràcies.")==false)
			  {opoble.focus();return false;}
			if (validarCorreu(otext,"Ep!, t'has deixat el missatge en blanc.")==false)
			  {otext.focus();return false;}
			if ((oadreça.value.indexOf("@") == -1) || (oadreça.value.indexOf(".") == -1))
				{
				if (oadreça.value != "")
					{oadreça.value = "";
					validarCorreu(oadreça,"L'adreça ha de contenir alguna arrova i algun punt. Gràcies.");
					oadreça.focus();return false;}
				}
			break;
		case 'esp':
			if (validarCorreu(onom,"Indica un nombre o un seudónimo que te identifique, por favor. Gracias.")==false)
				{onom.focus();return false;}
			if (validarCorreu(opoble,"Nos gustaría conocer de dónde eres. Gracias.")==false)
			  {opoble.focus();return false;}
			if (validarCorreu(otext,"Te has dejado el mensaje en blanco!.")==false)
			  {otext.focus();return false;}
			if ((oadreça.value.indexOf("@") == -1) || (oadreça.value.indexOf(".") == -1))
				{
				if (oadreça.value != "")
					{oadreça.value = "";
					validarCorreu(oadreça,"El correo electrónico debe contener algún arroba y algún punto. Gracias.");
					oadreça.focus();return false;}
				}
			break;
	}
}
	return;
}

/* ======================================================================================================
   5. funció comuna a opina, bd, aportacions i fets
=========================================================================================================*/   

function validarCorreu(camp,missatgeErrada)
{
with (camp)
{
if (value==null||value=="")
  {alert(missatgeErrada);return false;}
else {return true}
}
}

/* ==================================================================================
  13. mostrar errades de verificació de dades formularis
===================================================================================*/   

function missatges(nummis,idioma)
{
	alert ("idioma: " + idioma);
	alert ("missatge: " + nummis);
	switch (idioma) {
		case 'cat':
		switch (nummis) {
			case 1:
			alert ("S'ha enviat un missatge al seu correu personal.");
			break;
			case 2:
			alert ("S'ha produït una errada a l'enviar un missatge al seu correu personal.");
			break;
			case 3:
			alert ("S'ha produït una errada a l'enregistrar el seu missatge.");
			break;
		}
		break;
		case 'esp':
		switch (nummis) {
			case 1:
			alert ("Se ha enviado un mensaje a su correo personal.");
			break;
			case 2:
			alert ("Se ha producido un error al enviar un mensaje a su correo personal.");
			break;
			case 3:
			alert ("Se ha producido un error al registrar su mensaje.");
			break;
			}
		break;
	}
}
