//funcao trim(string)
//retira os espacos em branco do inicio e fim de uma string
function trim(s)
{
  while (s.substring(0,1) == ' ')
  {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ')
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}

//funcao checkNotEmpty(id_do_objeto)
//verifica o se o campo estÃ¡ vazio (retorna false) ou não (retorna true)
function checkNotEmpty(idObject)
{
	valueObject = trim(eval(document.getElementById(idObject)).value);
	
	if(valueObject=='')
		return false;
	else
		return true;
}


function showSession(session)
{
		error = 'Ocorreram os seguintes erros:';
		switch (session)
		{
			case 1:
				error += '\n\nEtapa 1 - Identificação\n';
				break;
			case 2:
				error += '\n\nEtapa 2 - Formação Superior - Bacharelato\n';
				break;	
			case 3:
				error += '\n\nEtapa 3 - Formação Superior - Outros cursos\n';
				break;
			case 4:
				error += '\n\nEtapa 4 - Experiência profissional\n';
				break;	
			case 5:
				error += '\n\nEtapa 5 - Outras informações\n';	
		}
}

function showErrors(session)
{
	compareError = 'Ocorreram os seguintes erros:';
	switch (session)
	{
		case 1:
			compareError += '\n\nEtapa 1 - Identificação\n';
			break;
		case 2:
			compareError += '\n\nEtapa 2 - Formação Superior - Bacharelato\n';
			break;	
		case 3:
			compareError += '\n\nEtapa 3 - Formação Superior - Outros cursos\n';
			break;
		case 4:
			compareError += '\n\nEtapa 4 - Experiência profissional\n';
			break;	
		case 5:
			compareError += '\n\nEtapa 5 - Outras informações\n';	
	}
	
	
	if(error != compareError)
	{
		window.alert(error);
		existsError=true;
	}
}


function checkForm()
{
	existsError=false;
	error = '';
	sessao = 1;
	showSession(sessao);
		
	CEP1 = document.getElementById('CEP1').value;
	CEP2 = document.getElementById('CEP2').value;
	if( isNaN(CEP1) || isNaN(CEP2) || !checkNotEmpty('CEP1') || !checkNotEmpty('CEP2') || CEP1.lenght < 5 || CEP2.lenght < 3 || CEP1==0) error += '"CEP" é inválido ou está em branco.\n';
	
	showErrors(sessao);
			
	
	if(existsError)
	{	
	 	return false;
	}
	else
	{
		return true;
	}
	
}

