// JavaScript Document

function js_checkName(){
	js_progressIcon(true);
	var x = document.getElementById("f_username");
	if(x.value==''){
		x.style.backgroundColor='#FF9933';
		js_progressIcon(false);
		return false;
	}
	else{
		xajax_fn_checkUserNameAvailability(x.value);
	}	
}

function js_updateUsernameAvailability(j_availability){
	js_progressIcon(true);
	var x = document.getElementById("f_checkavailable");
	var y = document.getElementById("f_username");
	if(j_availability==0){
		y.style.backgroundColor='#FFFFFF';
		x.style.color='#00CC33';
		x.innerHTML="Sim";
	}
	if(j_availability==1){
		y.style.backgroundColor='#FF9933';
		x.style.color='#CC3333';
		x.innerHTML="N&atilde;o";
	}
}

function js_auxNewEmail(){
	js_progressIcon(true);
	//This only checks for the name availability (server side stuff). If it is ok, the server will continue with email creation
	var x = document.getElementById("f_username");
	if(x.value==''){
		x.style.backgroundColor='#FF9933';
		js_progressIcon(false);
		return false;
	}
	else{
		xajax_fn_auxCreateAccount(x.value);
	}
}

function js_newEmail(j_availability){
	js_progressIcon(true);
	var j_AllInOrder = true;
	var p1 = document.getElementById("f_password");
	var p2 = document.getElementById("f_password2");
	var pc1 = document.getElementById("f_checkpassword");
	var pc2 = document.getElementById("f_samepassword");
	pc1.innerHTML="";
	pc2.innerHTML="";
	p1.style.backgroundColor='#FFFFFF';
	p2.style.backgroundColor='#FFFFFF';
	if(p1.value==""){
		p1.style.backgroundColor='#FF9933';
		pc1.innerHTML = "Senha obrigat&oacute;ria!";
		j_AllInOrder = false;
	}
	if(p1.value!=p2.value){
		p1.style.backgroundColor='#FF9933';
		p2.style.backgroundColor='#FF9933';
		pc2.innerHTML = "Senhas diferentes!";
		j_AllInOrder = false;
	}

	if(j_availability==1)
		j_AllInOrder=false;

	if(j_AllInOrder){
		xajax_fn_createAccount(xajax.getFormValues("emailRegistration"));
		return false;
	}
	else{
		js_progressIcon(true);
		return false;
	}
}