window.onload = function(){
	afegirEvents();	
}
function validarnom(obj){
	console.log(obj.value);
	var ele = document.getElementById("validarnom");
	if(obj.value.match(/^([a-zA-Z]+\s)*[a-zA-Z]+$/)){
		var clase = document.getElementById("validarnom").className;
		clase = clase.substring(0,clase.indexOf("alert"));
		ele.className = clase;
		ele.innerHTML = "";
	}else{
		ele.innerHTML = obj.value + " no te un format correcte";
		ele.className += " alert-danger text-center" ;
	}
}
function validartaula(obj){
	var reg = /^[a|b|c|d|A|B|C|D{1}]+\d{1}$/;
	var ele = document.getElementById("validartaula");
	console.log(obj.value);
	if(obj.value.match(reg)){
		var clase = document.getElementById("validartaula").className;
		clase = clase.substring(0,clase.indexOf("alert"));
		ele.className = clase;
		ele.innerHTML = "";
	}else{
		ele.innerHTML = "El format per a les taules es A-D seguit d'un numero";
		ele.className += " alert-danger text-center" ;
	}
}
function afegirEvents(){
	e = document.images;
	for(i=0;i<e.length;i++){
		e[i].addEventListener("click", function(){seleccionarplat(this)});
	}	
}
function seleccionarplat(obj){
	if(obj.style.border == ""){
		obj.style.border = "5px blue solid";
	}else{
		obj.style.border = "";
	}
	var plat = document.getElementById("platsocults");
	console.log(plat);	
	plat.value ="";
	var e = document.images;
	for (i=0;i<e.length;i++){
		if(e[i].style.border != ""){
			e[i].src.indexOf("img"	);
			var text = e[i].src.substring(e[i].src.indexOf("img") + 4, e[i].src.indexOf(".jp"));
			plat.value += text + ";";

		}
	}
	console.log(plat.value);
	
}