// JavaScript Document

	var imgOldImatges;
	var imgImatges = Array();
	var imgAltImatges = Array();
	var imgNames = Array();

	ie = (navigator.appName.indexOf("Explorer") > -1)
	
	function canviaImatge(name) {

		ndx = cercaImatge(name);
		imgOldImatgeName = name;
		imgOldImatges = imgImatges[ndx].src;

		img = document.getElementById(name);	
		img.src = imgAltImatges[ndx].src;
	}
	
	function restauraImatge(name) {
		img = document.getElementById(imgOldImatgeName);
		img.src = imgOldImatges;
	}
		
	function cercaImatge(name) {
		ndx = 0;
		for(n=0;n<imgNames.length; n++) {
			if(imgNames[n]==name) {
				ndx = n;
			}
		}
		return ndx;
	}
	
	function carregaImatge(name, img, alt) {
		n = imgNames.length;
		imgAltImatges[n] = new Image;	imgAltImatges[n].src = alt;
		imgImatges[n] = new Image;		imgImatges[n].src = img;
		imgNames[n] = name
	}
		

	function basename(url) {
		ndx = url.lastIndexOf("/")+1;
		doc = url.substr(ndx, url.length);
		return doc;
	}
	
	function obreFinestra(RUTA, W, H, SCROLL) {
			Xpos = (screen.availWidth / 2) - (W / 2);
			Ypos = (screen.availHeight / 2) - (H / 2);
			wOpen = window.open(RUTA, null, "scrollbars="+SCROLL+", height="+H+", width="+W);
			wOpen.moveTo(Xpos, Ypos);

	}
	
	function numeric(e) {
		key = e.keyCode;
		if(key>=48 && key<=57) {
			return true;
		}
		return false;
	}

	function mailCorrecta(mail) {
		
		a = mail.indexOf("@");
		if(a<0) {
			return false;
		}
		p = mail.lastIndexOf(".");
		{
			if(p<a) {
				return false;
			}
		}
		return true;	
	}

	function URLencode(sStr) {
		return escape(sStr).replace("/\+/g", '%2B').replace("/\"/g",'%22').replace("/\'/g", '%27').replace("/\//g",'%2F');
	  }


	// Especifiques AUGASSANTAS

	function mostra(FOTO) {
		LOGO = document.getElementById("logo");
		mostrafoto(FOTO, false);
		xbase.closemenu();
		LOGO.className = "xmenumask";
	}

	function mostrafoto(FOTO, MASCARA) {
		novaimatgecarregada=false;
		newimg = new Image();
		newimg.onload = function() { processaImatge(); }
		if(MASCARA) {
			FOTO = "tourfoto.php?FOTO="+FOTO;
		}
		newimg.src = FOTO;
	}
	
	function processaImatge() {
		PORTADA = document.getElementById("portada");
		if(!ie) { estat = "complete"; } else { estat = newimg.readyState };
		if(estat=="complete") {
			if(ie) {
				PORTADA.filters[0].apply();
				PORTADA.background = newimg.src;
				PORTADA.filters[0].play();
			} else {
				PORTADA.style.background="url('"+newimg.src+"')";
			}
		}
	}