function Valida1() {
	var OK 				= new Array ('srt', 'sub', 'zip', 'rar');
	var fieldFile 		= document.getElementById("file");
	var filename 		= document.getElementById("file").value;
	var fieldTitulo 	= document.getElementById("titulo");
	var fieldTituloMsg 	= "Titulo não pode ser vazio";
	var fieldDesc 		= document.getElementById("desc");
	var fieldDescMsg 	= "Descrição não pode estar vazio";
	var ext 				= getExt(filename);
	var fileOK 			= 0;
	
	for (i = 0; i < OK.length; i++) {
		if (OK[i] == ext) {
			fileOK = 1; // one of the file extensions found
		} 
	}	
	
	if (fieldTitulo.value == "") {
		alert(fieldTituloMsg);
		fieldTitulo.focus();
		fieldTitulo.style.borderColor = 'red';
		return false;
	} else {
		fieldTitulo.style.borderColor = '#cccccc';
	}
	
	if (fileOK == 0) {
		alert ("O ficheiro não é válido. Só ficheiros .SRT .SUB .ZIP ou .RAR");
		fieldFile.focus();
		return false;
	}
	
	if (fieldDesc.value == "") {
		alert(fieldDescMsg);
		fieldDesc.focus();
		fieldDesc.style.borderColor = 'red';
		return false;
	}
}


function Valida2() {
	var fieldDesc 		= document.getElementById("desc");
	var fieldDescMsg 	= "Descrição não pode estar vazio";
	if (fieldDesc.value == "") {
		alert(fieldDescMsg);
		fieldDesc.focus();
		fieldDesc.style.borderColor = 'red';
		return false;
	}
}



function getExt(filename) {
	var dot_pos = filename.lastIndexOf(".");
	if(dot_pos == -1)
		return "";
	return filename.substr(dot_pos+1).toLowerCase();
}



function validate_required(field, alerttxt) {
	with (field) {
		if (value==null||value=="") {
			alert(alerttxt);
			return false;
		} else {
			return true;
		}
	}
}


function valida_elemento(thisform, Elemento, msg) {
	with (thisform) {
		if (validate_required(Elemento, msg)==false)
			{Elemento.focus();return false;}
	}
}






















