arrPermitidos = new Array(".jpg",".jpeg");

function validaForm(form) {
	
	var elementos = form.elements;
	for (var i=0; i< elementos.length; i++){
		//if (elementos[i].getAttribute("type")=="text") {
			if (elementos[i].getAttribute("obrigatorio")=="1") {
				if (elementos[i].value=="") {
					alert("O campo "+elementos[i].getAttribute("name")+" é obrigatorio.");
					return false;
				}	
				
				if(elementos[i].getAttribute("name")=="imagem" && elementos[i].getAttribute("value")!=null){
					if(!limitaAnexo(elementos[i].value)){
						alert("Por favor selecione apenas arquivos dos tipos:  " + (arrPermitidos.join("  ")) + "\nPor favor selecione novamente!");
						return false;
					}
				}
			}
			
			//alert(elementos[i].getAttribute("value"));
			
			
		//}
	}
	
	
	
	return true;
}

function limitaAnexo(arquivo) {
	enviar = false;
	
	if (!arquivo) 
		return;
	
	while (arquivo.indexOf("\\") != -1)
		arquivo = arquivo.slice(arquivo.indexOf("\\") + 1);
	
	ext = arquivo.slice(arquivo.indexOf(".")).toLowerCase();
	
	for (var i = 0; i < arrPermitidos.length; i++) {
		if (arrPermitidos[i] == ext) {
			enviar = true; break; 
		}
	}
	if (enviar) 
		return true;
	else
		return false;
}
