var user="";


function carregauser (user_a) {
	user=user_a;
}
function verifica_registo(){
	nome=document.getElementById("name").value;
	mail=document.getElementById("xemail").value;
	mailconf=document.getElementById("emailconf").value;

	erro=0;
	if (nome=="") {
		alert("Têm de Introduzir um Nome!");
		document.getElementById("name").select();
		erro=1;
	}
	if (nome.length<2 && erro==0) {
		alert("O Nome têm de ter pelo menos 2 caracteres!");
		document.getElementById("name").select();
		erro=1;		
	}
	var charpos = nome.search("[^A-Za-z áàãâéèêíìóòõôúùûÁÀÃÂÉÈÊÍÌÓÒÕÔÚÙçÇ]");
	if (charpos>=0 && erro==0) {
		alert("O Nome contem caracteres inválidos!");
		document.getElementById("name").select();
		erro=1;		
	}
	
	resultado=isEmail(mail);
	if (resultado==false && erro==0) {
		alert("Verifique se introduziu o Email correctamente!");
		erro=1;
	}
	
	if (mail!=mailconf && erro==0) {
		alert("O email de confirmação está errado!");
		erro=1;
	}
	if (erro==0) {
		a_enviar="../lib/ajax_ganhardo.php?tarefa=guarda&user="+user+"&nome="+nome+"&email="+mail;
		$.post(a_enviar,"","");
		alert("Obrigado! Vai ser reencaminhado para a página de registo!");
		return true;
	} else {
		return false;
	}
}

function verifica_email(){
	vmail=document.getElementById("xemail").value;
	mailconf=document.getElementById("xemailconf").value;
	erro=0;

	resultado=isEmail(vmail);
	if (resultado==true) {
		if (vmail==mailconf) {
			nome=document.getElementById("xname").value;
			if (nome!="") {
					erro=0;	
			} else {
				alert("Têm de Introduzir um nome!")
				erro=1;	
			}
		} else {
			alert("Verifique se introduziu o Email correctamente!")		
			erro=1;	
		}

	} else {
		alert("Verifique se introduziu o Email correctamente!")
		erro=1;	
	}

	if (erro==0) {
		return true;
	} else {
		return false;
	}
}


function isEmail(text){
   var 	arroba = "@",
		ponto = ".",
		posponto = 0,
		posarroba = 0;
	
	 if (text =="") return false;
	
	 for (var indice = 0; indice < text.length; indice++){
		if (text.charAt(indice) == arroba) {
			posarroba = indice;
			break;
		 }
	 }
	
	for (var indice = posarroba; indice < text.length; indice++){
		if (text.charAt(indice) == ponto) {
			posponto = indice;
			break;
		}
	}
	if (posponto == 0 || posarroba == 0) return false;
	if (posponto == (posarroba + 1)) return false;
	if ((posponto + 1) == text.length) return false;
	return true;
}




/* para fazer as caixas das mensagens modal*/
messageObj = new DHTML_modalMessage();	// We only create one object of this class
messageObj.setShadowOffset(5);	// Large shadow

function abre_janela() {
	messageContent="<div id='mostra_janela_reg'><div align='right'><img src='../templates/ganhardo/fechar.png' boder='0' onclick='fecha_janela();'></div><div id='desenha'></div></div>";
	messageObj.setHtmlContent(messageContent);
	messageObj.setSize("200","160");
	messageObj.setCssClassMessageBox(false);
	messageObj.setSource(false);	// no html source since we want to use a static message here.
	messageObj.setShadowDivVisible(false);	// Disable shadow for these boxes	
	messageObj.display();
	
	a_enviar="../lib/ajax_ganhardo.php?tarefa=formulario";
	$.post(a_enviar,"",function(retorno){$("#desenha").html(retorno)});
}

function fecha_janela() {
	messageObj.close();	
}

/* fim de -  para fazer as caixas das mensagens modal*/