function AlunoValidar(){
	
	DWRUtil.useLoadingMessage('Processando');

	var param = $('matricula').value+ ' ' +','+document.getElementById('cpf').value + ' ';
							
	DWREngine._execute(_ajaxConfig._cfscriptLocation, null,'MatriculaValidar',param,RetornoMatriculaValidar);
}

function RetornoMatriculaValidar(objeto){//objeto
	if(objeto.sucesso != 1){
		alert('Matrícula ou CPF Inválido.');
		$('matricula').focus()
		return false;
	}else{
		Recebe();
	}
}

function Recebe(){			
	var amigo = 0;
	var email = 0;
	var resposta = 0;
	var nome = 0;
	var emailI = 0;
	var tel = 0;
	
	if(Trim($('resposta').value) == ""){
		resposta = 1;
		alert('A pergunta deve ser respondida.');
		$('resposta').value='';
		$('resposta').focus();
		return false;
	}else{
		resposta = 0;
	}
	
	
	if(Trim($('nome').value) == ""){
		nome = 1;
		alert('Nome deve ser preenchido.');
		$('nome').value='';
		$('nome').focus();
		return false;
	}
	
	if(Trim($('email').value) == ""){
		emailI = 1;
		alert('Email deve ser preenchido.');
		$('email').value='';
		$('email').focus();
		return false;
	}
	
	if(Trim($('tel').value) == ""){
		tel = 1;
		alert('Telefone deve ser preenchido.');
		$('tel').value='';
		$('tel').focus();
		return false;
	}

	var preenchido = 0;
	for (i=1;i<=5;i++){
		if(Trim(document.getElementById('amigo'+ i).value) != ""){
			if(Trim(document.getElementById('email'+ i).value) == ""){
				alert('Todos os indicados devem ter seus e-mails correspondentes.');
				email = 1;
				$('email'+ i).focus();
				return false;
			}else{
				preenchido = 1;
			}
		}
	}
	
	if(preenchido == 0){
		alert('Indique pelo menos um amigo.');
		$('amigo1').focus();
		return false;
	}
	
	if(email == 0 && resposta == 0 && nome == 0 && emailI == 0 && tel == 0){
		// send data to CF
		DWRUtil.useLoadingMessage('Processando');

		//var form = DWRUtil.serializeForm(document.form);
					
		var param = $('matricula').value+ ' ' +','+$('cpf').value+ ' ' +','+
					$('nome').value+ ' ' +','+$('email').value+ ' ' +','+
					$('tel').value+ ' ' +','+$('amigo1').value+ ' ' +','+
					$('email1').value+ ' ' +','+$('amigo2').value+ ' ' +','+
					$('email2').value+ ' ' +','+$('amigo3').value+ ' ' +','+
					$('email3').value+ ' ' +','+$('amigo4').value+ ' ' +','+
					$('email4').value+ ' ' +','+$('amigo5').value+ ' ' +','+
					$('email5').value+ ' ' +','+$('resposta').value+ ' ' +','+
					$('Campanha').value;
		
		DWREngine._execute(_ajaxConfig._cfscriptLocation, null,'PromocaoCadastrar',param,Retorno);
	
	}
}

// call back function
function Retorno(objeto) {
	if(objeto.sucesso != 0){
		alert('Dados enviados com suceso.');
		$('form').reset();
		$('amigo1').focus()
	}else{
		alert('Tente novamente.');
	}
	
	//document.getElementById('recebe').innerHTML = objeto.texto;
	//document.getElementById('loading').style.display  = 'none';
	//document.getElementById('recebe').style.display = 'block';
}
