function register()
{
    $('.register-box').fadeOut('fast', function(){$('.msg').fadeIn('fast');$('p.obs').hide();});
}
function moreInfo()
{
    $('.register-box').fadeOut('fast', function(){$('.msg').fadeIn('fast');$('p.obs').hide();});
}
function forgot(sucess)
{
    if(sucess)
        $('.forgot').fadeOut('fast', function(){$('.msg:first').fadeIn('fast');});
    else
        $('.forgot').fadeOut('fast', function(){$('.fail').fadeIn('fast');});
        
}

// so digita valor numerico sem os sinais, ponto e virgula
function valorNumerico(obj){
  if (event.keyCode < 48 || event.keyCode > 57){
	event.returnValue = false; 
  }
}

function validaFormCadastro() {

	if (document.frmCadastro.nome.value == '') {
		alert('Favor preencher o campo nome!');
		document.frmCadastro.nome.focus();
		return false;
	}

	  if (echeck (document.frmCadastro.email.value)) {

		null;

	  } else {
		alert ('Favor digitar um e-mail válido');
		document.frmCadastro.email.focus();
		return false;
	  }


	if (document.frmCadastro.ddd.value == '') {
		alert('Favor preencher o campo DDD');
		document.frmCadastro.ddd.focus();
		return false;
	}

	if (document.frmCadastro.telefone.value == '') {
		alert('Favor preencher o campo telefone');
		document.frmCadastro.telefone.focus();
		return false;
	}


	if (document.frmCadastro.empresa.value == '') {
		alert('Favor preencher o campo empresa!');
		document.frmCadastro.empresa.focus();
		return false;
	}

   numeros="0123456789";
   for(i=0; i<document.frmCadastro.ddd.value.length; i++){
	  if (numeros.indexOf(document.frmCadastro.ddd.value.charAt(i),0)==-1){
		 alert('Caracter inválido no campo DDD');
		 document.frmCadastro.ddd.focus();
		 return false;
	  }
   }

   for(i=0; i<document.frmCadastro.telefone.value.length; i++){
	  if (numeros.indexOf(document.frmCadastro.telefone.value.charAt(i),0)==-1){
		 alert('Caracter inválido no campo telefone!');
		 document.frmCadastro.telefone.focus();
		 return false;
	  }
   }
	if (document.frmCadastro.informacoes.value == '') {
		alert('Favor preencher o campo informações');
		document.frmCadastro.informacoes.focus();
		return false;
	}else{
		if (checktamanho(frmCadastro)){
			null;
		}else{
			document.frmCadastro.informacoes.focus();
			return false;
		}
	}

}

function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		return false
	 }

	 return true					
}

function checktamanho(form) {
var max=500;
if (form.informacoes.value.length > max) {
alert("A quantidade máxima de caracteres deste campo é 500!");
return false;
}
else
return true;
} 

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}

function preenchidoEmail (edit, nome) {
  if (echeck (edit.value)) {
    return true;
  } else {
    alert ('Favor digitar um e-mail válido');
    edit.focus();
    return false;
  }
}

function validate(form)
{
  if (form.txt_nomeamigo.value == ""){
    alert("Por favor, digite o nome do amigo");
    form.txt_nomeamigo.focus();
    return false;
   }
  if (form.txt_emailamigo.value == ""){
    alert("Por favor, digite o e-mail do amigo");
    form.txt_emailamigo.focus();
    return false;
   }else{
		if (preenchidoEmail(form.txt_emailamigo, '')){
		}else{
			form.txt_emailamigo.focus();
			return false;
		}
   }
  if (form.txt_seunome.value == ""){
    alert("Por favor, digite o seu nome");
    form.txt_seunome.focus();
    return false;
   }
  if (form.txt_seuemail.value == ""){
    alert("Por favor, digite o seu e-mail");
    form.txt_seuemail.focus();
    return false;
   }else{
		if (preenchidoEmail(form.txt_seuemail, '')){
		}else{
			form.txt_seuemail.focus();
			return false;
		}
   }
   form.submit();
}
