/* Valida una direcció d'email */
function isEmailAddress(theElement) {
   var s = theElement;
   var filter=/^[A-Za-z][A-Za-z0-9_.\\-]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
   if (s=="") return false;
   if (s.length == 0 ) return false;
   if (filter.test(s)) return true;
   else return false;
}

function CampText(camp){
	var valid = false;
	
	el = document.getElementById(camp);
	if (el.value.length > 0) valid = true;
	
	CambiaColor(el,valid);
	CambiaImg(el.name,valid);
	
	return valid;
}

function CampEmail(camp){
	
	el = document.getElementById(camp);
	valid = isEmailAddress(el.value);
	
	CambiaColor(el,valid);
	CambiaImg(el.name,valid);
	
	return valid;
	
}

function CampNumeric(camp,digits){
	var valid = false;
	
	var el = document.getElementById(camp);
	var num=el.value;
	
	
	if(digits == 0){
		if(num.length > 1) valid = soloNumerico(num);
	}
	else if(num.length == digits) valid = soloNumerico(num);
	
	CambiaColor(el,valid);
	CambiaImg(el.name,valid);
	
	return valid;
}

function soloNumerico(valor) {
	return !isNaN(valor);
}

function CambiaColor(obj,valid){
	//if(!valid) obj.style.border = "1px solid #e51d13";
	//else obj.style.border = "1px solid #cccccc";
}

function CambiaImg(n,valid){
	el = document.getElementById(n+'-img');
	if(!valid) el.style.display='';
	else el.style.display='none';
}