function getElementByIdOrNameAndTagName(idOrName, tagName) {
	var el = document.getElementById(idOrName);
	if (el.tagName.toLowerCase() != tagName.toLowerCase()) {
		var els = document.getElementsByTagName(tagName);
		for (var i = 0; i < els.length; i++) {
			if (els[i].id == idOrName) {
				el = els[i];
				break;
			}
		}
	}
	
	return el;
}

function $(s) {
	return getElementByIdOrNameAndTagName(s, 'input');
}

function F(s) {
	return $(s).value;
}

function isValidEmail(email_field) {
	if (email_field.value != '') {
		var ExpReg = /^[a-zA-Z0-9_\.-]{2,}@([A-Za-z0-9_-]{2,}\.)+[A-Za-z]{2,4}$/;
		if (!ExpReg.test(email_field.value))
			return false;
			
		return true;
	}
	
	return false;
}

function validate_comment() {
	if ( F('author') == "" ) {
		alert("O campo Nome é obrigatório!");
		$('author').focus();
		return false;
	}
	if ( F('email') == "" ) {
		alert("O campo E-mail é obrigatório!");
		$('email').focus();
		return false;
	}
	else {
		if ( !isValidEmail($('email')) ) {
			alert("E-mail inválido!");
			$('email').focus();
			return false;
		}
	}
	if ( F('comment') == "" ) {
		alert("O campo Comentário é obrigatório!");
		$('comment').focus();
		return false;
	}
}

function validate_contact() {
	if ( F('author') == "" ) {
		alert("O campo Nome é obrigatório!");
		$('author').focus();
		return false;
	}
	if ( F('email') == "" ) {
		alert("O campo E-mail é obrigatório!");
		$('email').focus();
		return false;
	}
	else {
		if ( !isValidEmail($('email')) ) {
			alert("E-mail inválido!");
			$('email').focus();
			return false;
		}
	}
	if ( F('subject') == "" ) {
		$('subject').focus();
		alert("O campo Assunto é obrigatório!");
		return false;
	}
	if ( F('message') == "" ) {
		alert("O campo Mensagem é obrigatório!");
		$('message').focus();
		return false;
	}
}

function validate_forward() {
	if ( F('dest') == "" ) {
		alert("O campo E-mail do Destinatário é obrigatório!");
		$('dest').focus();
		return false;
	}
	else {
		if ( !isValidEmail($('dest')) ) {
			alert("E-mail do Destinatário inválido!");
			$('dest').focus();
			return false;
		}
	}
	if (F('author') == "") {
		alert("O campo Nome é obrigatório!");
		$('author').focus();
		return false;
	}
	if ( F('email') == "" ) {
		alert("O campo E-mail é obrigatório!");
		$('email').focus();
		return false;
	}
	else {
		if ( !isValidEmail($('email')) ) {
			alert("E-mail inválido!");
			$('email').focus();
			return false;
		}
	}
}