
function validaemail(pStr)
{
	if (pStr != ""){
		reEmail = /^[\w!#$%&*+\/=?^`{|}~-]+(\.[\w!#$%&*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
		if (reEmail.test(pStr) && pStr.length>0) {return true;} else{return false;}
	}
}

function Val(field,tipo)
{
if (tipo=="txt")pat=/[0-9]/;
if (tipo=="num")pat=/[^0-9]/;
if (tipo=="tel")pat=/[^0-9\-]/;
if (tipo=="dt")pat=/[^0-9\/]/;
idx = field.value.search( pat );
while ( idx > -1 ) {field.value = field.value.replace( pat, '' ); idx = field.value.search( pat );}
}

function formCheckContato(formobj){
	/*Nome dos Campos*/var fieldRequired = Array("Nome","Email","Assunto","Mensagem");
	/* Nome p/ Exibição*/var fieldDescription = Array("Nombre","E-mail","Assunto","Mensaje");
	
	var alertMsg = "";
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
		switch(obj.type){//Um case pra cada tipo de campo
		case "select-one":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "select-multiple":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "text":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "password":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "textarea":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		default:if (obj.type == undefined){var blnchecked = false;for (var j = 0; j < obj.length; j++){if (obj[j].checked){blnchecked = true;}}if (!blnchecked){alertMsg += " - " + fieldDescription[i] + "\n";}}
		}
		}
	}
	//EXTRas - Não vazios, mas inválidos --------------------v
		if(validaemail(formobj.Email.value)==false){alertMsg += " - E-mail incorrecto\n";}
	//EXTRas - Não vazios, mas inválidos --------------------^

	if (alertMsg!=""){alert("Los siguientes campos son obligatorios:\n" + alertMsg);return false;}else{return true;}
}			

function formCheckTrabalhe(formobj){
	/*Nome dos Campos*/var fieldRequired = Array("Nome","Email","Assunto","Cidade","Estado","DDD_Tel","Tel","Interesse","Formacao","Universidade");
	/* Nome p/ Exibição*/var fieldDescription = Array("Nombre","E-mail","Assunto","Ciudad","Estado","DDD Teléfono","Teléfono","Área de Interés","Graduación Académica","Universidad/Facultad de Graduación");
	
	var alertMsg = "";
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
		switch(obj.type){//Um case pra cada tipo de campo
		case "select-one":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "select-multiple":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "text":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "password":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "textarea":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		default:if (obj.type == undefined){var blnchecked = false;for (var j = 0; j < obj.length; j++){if (obj[j].checked){blnchecked = true;}}if (!blnchecked){alertMsg += " - " + fieldDescription[i] + "\n";}}
		}
		}
	}
	//EXTRas - Não vazios, mas inválidos --------------------v
		if(validaemail(formobj.Email.value)==false){alertMsg += " - E-mail incorrecto\n";}
		
		//if(formobj.Dia.value != "" && formobj.Dia.value.length!=2){alertMsg += " - Dia de Nascimento Inválida\n";}
		//if(formobj.Mes.value != "" && formobj.Mes.value.length!=2){alertMsg += " - Mês de Nascimento Inválida\n";}
		//if(formobj.Ano.value != "" && formobj.Ano.value.length!=4){alertMsg += " - Ano de Nascimento Inválido\n";}
				
	//EXTRas - Não vazios, mas inválidos --------------------^

	if (alertMsg!=""){alert("Los siguientes campos son obligatorios:\n" + alertMsg);return false;}else{return true;}
}		


function formCheckQuero(formobj){
	/*Nome dos Campos*/var fieldRequired = Array("Nome","Email","Temas");
	/* Nome p/ Exibição*/var fieldDescription = Array("Nombre","E-mail","Asuntos de noticia");
	
	var alertMsg = "";
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
		switch(obj.type){//Um case pra cada tipo de campo
		case "select-one":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "select-multiple":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "text":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "password":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "textarea":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		default:if (obj.type == undefined){var blnchecked = false;for (var j = 0; j < obj.length; j++){if (obj[j].checked){blnchecked = true;}}if (!blnchecked){alertMsg += " - " + fieldDescription[i] + "\n";}}
		}
		}
	}
	//EXTRas - Não vazios, mas inválidos --------------------v
		if(validaemail(formobj.Email.value)==false){alertMsg += " - E-mail incorrecto\n";}
	//EXTRas - Não vazios, mas inválidos --------------------^

	if (alertMsg!=""){alert("Los siguientes campos son obligatorios:\n" + alertMsg);return false;}else{return true;}
}		

function formCheckLogin(formobj){
	/*Nome dos Campos*/var fieldRequired = Array("usuario","senha");
	/* Nome p/ Exibição*/var fieldDescription = Array("El campo usuario no fue rellenado","El campo contraseña no fue rellenado");
	
	var alertMsg = "";
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
		switch(obj.type){//Um case pra cada tipo de campo
		case "select-one":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "select-multiple":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "text":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "password":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "textarea":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		default:if (obj.type == undefined){var blnchecked = false;for (var j = 0; j < obj.length; j++){if (obj[j].checked){blnchecked = true;}}if (!blnchecked){alertMsg += " - " + fieldDescription[i] + "\n";}}
		}
		}
	}
	//EXTRas - Não vazios, mas inválidos --------------------v
	
	//EXTRas - Não vazios, mas inválidos --------------------^

	if (alertMsg!=""){alert("Los siguientes campos son obligatorios:\n" + alertMsg);return false;}else{return true;}
}		


function formCheckPublicacao(formobj){
	/*Nome dos Campos*/var fieldRequired = Array("Nome","Email","Telefone","Arquivo");
	/* Nome p/ Exibição*/var fieldDescription = Array("Nombre","E-mail","Teléfono","Publicaciones");
	
	var alertMsg = "";
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
		switch(obj.type){//Um case pra cada tipo de campo
		case "select-one":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "select-multiple":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "text":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "password":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "textarea":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		default:if (obj.type == undefined){var blnchecked = false;for (var j = 0; j < obj.length; j++){if (obj[j].checked){blnchecked = true;}}if (!blnchecked){alertMsg += " - " + fieldDescription[i] + "\n";}}
		}
		}
	}
	//EXTRas - Não vazios, mas inválidos --------------------v
		if(validaemail(formobj.Email.value)==false){alertMsg += " - E-mail incorrecto\n";}
	//EXTRas - Não vazios, mas inválidos --------------------^

	if (alertMsg!=""){alert("Los siguientes campos son obligatorios:\n" + alertMsg);return false;}else{return true;}
}

	
function AutoNext(who, maxLength) 
{
	if (who.value.length == maxLength) 
	{
		var i=0,j=0, indice=-1;
		for (i=0; i<document.forms.length; i++) 
		{
			for (j=0; j<document.forms[i].elements.length; j++) 
			{
				if (document.forms[i].elements[j].name == who.name) 
				{
					indice=i;
					break;
				}
			}
			if (indice != -1)
		         break;
		}
		for (i=0; i<=document.forms[indice].elements.length; i++) {
			if (document.forms[indice].elements[i].name == who.name) {
				while ( (document.forms[indice].elements[(i+1)].type == "hidden") &&
						(i < document.forms[indice].elements.length) ) {
							i++;
				}
				document.forms[indice].elements[(i+1)].focus();
				break;
			}
		}
	}
}

