var shortPass = "<span style=\"color: #FF0000; font-weight: bold;\">Curta</span>";
var badPass = "<span style=\"color: #FF0000; font-weight: bold;\">Ruim</span>";
var goodPass = "<span style=\"color: #333333; font-weight: bold;\">Boa</span>";
var strongPass = "<span style=\"color: #0000CC; font-weight: bold;\">Forte</span>";
function SenhaIdentica2()
{	
	if(document.getElementById("txtLogin").value.trim()=="")
	{
		alert("O campo [Nome de Usuario] e de preenchimento obrigatorio");
		return false;
	}
	if(document.getElementById("txtSenha1").value.trim()=="")
	{
			alert("O campo [nova senha] e de preenchimento obrigatorio");
			return false;	
	}	
	if(document.getElementById("txtSenha1").value.length < 4)
	{
			alert("O campo [nova senha] tem tamanho minimo de 4 digitos");
			return false;	
	}
	if ((document.getElementById("txtSenha1").value==document.getElementById("txtSenha2").value))
	{
		return true;
	}
	else
	{
		alert("O campo [Senha de Acesso] e [Confirmar Senha de Acesso] devem ser identicos");
		return false;
	}
}
String.prototype.trim = function()
{	
	return this.replace(/^\s*/,"").replace(/\s*$/, "");
}
function SenhaIdentica()
{
	var senha1 = document.getElementById("txtSenha1").value; 
	var senha2 = document.getElementById("txtSenha2").value; 
	
	if(senha1!=senha2)
	{
		document.getElementById('spanMensagem2').innerHTML = "<span style=\"color: #FF0000; font-weight: bold;\">As senhas não conferem</span>";
		return false;
	}
	else
	{
		if(document.getElementById('spanMensagem2').innerHTML!="")
		{
			document.getElementById('spanMensagem2').innerHTML = "<span style=\"color: #0000CC; font-weight: bold;\">Confere!</span>";
		}
		return true;
	}
}
function passwordStrength() {

	var username = document.getElementById("txtLogin").value; 
	var password = document.getElementById("txtSenha1").value; 

    score = 0

    //password < 4
    if (password.length < 4 ) { return shortPass }

    //password == username
    if (password.toLowerCase()==username.toLowerCase()) return badPass

    //password length
    score += password.length * 4
    score += ( checkRepetition(1,password).length - password.length ) * 1
    score += ( checkRepetition(2,password).length - password.length ) * 1
    score += ( checkRepetition(3,password).length - password.length ) * 1
    score += ( checkRepetition(4,password).length - password.length ) * 1

    //password has 3 numbers
    if (password.match(/(.*[0-9].*[0-9].*[0-9])/))  score += 5

    //password has 2 sybols
    if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) score += 5

    //password has Upper and Lower chars
    if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))  score += 10

    //password has number and chars
    if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/))  score += 15
    //
    //password has number and symbol
    if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/))  score += 15

    //password has char and symbol
    if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z])/))  score += 15

    //password is just a nubers or chars
    if (password.match(/^w+$/) || password.match(/^d+$/) )  score -= 10

    //verifing 0 < score < 100
    if ( score < 0 )  score = 0
    if ( score > 100 )  score = 100

    if (score < 34 )  return badPass
    if (score < 68 )  return goodPass
    return strongPass
}

function checkRepetition(pLen,str) {
    res = ""
    for ( i=0; i<str.length; i++ ) {
        repeated=true
        for (j=0;j < pLen && (j+i+pLen) < str.length;j++)
            repeated=repeated && (str.charAt(j+i)==str.charAt(j+i+pLen))
        if (j<pLen) repeated=false
        if (repeated) {
            i+=pLen-1
            repeated=false
        }
        else {
            res+=str.charAt(i)
        }
    }
    return res
}
function Valida()
{
	if(document.getElementById("txtNome").value.trim()=="")
	{
		alert("O campo [Nome] e de preenchimento obrigatorio");
		document.getElementById("txtNome").focus();
		document.getElementById("txtNome").select();
		return false;
	}
	if(document.getElementById("txtDDD").value.trim()=="")
	{
		alert("O campo [ddd] e de preenchimento obrigatorio");
		document.getElementById("txtDDD").focus();
		document.getElementById("txtDDD").select();
		return false;
	}
	if(document.getElementById("txtTelefone1").value.trim()=="")
	{
		alert("O campo [Telefone] e de preenchimento obrigatorio");
		document.getElementById("txtTelefone1").focus();
		document.getElementById("txtTelefone1").select();
		return false;
	}
	if(document.getElementById("txtTelefone2").value.trim()=="")
	{
		alert("O campo [Telefone] e de preenchimento obrigatorio");
		document.getElementById("txtTelefone2").focus();
		document.getElementById("txtTelefone2").select();
		return false;
	}
	if(document.getElementById("txtEmail").value.trim()=="")
	{
		alert("O campo [E-Mail] e de preenchimento obrigatorio");
		document.getElementById("txtEmail").focus();
		document.getElementById("txtEmail").select();
		return false;
	}
	if(!ValidaEmail(document.getElementById("txtEmail").value))
	{
		document.getElementById("txtEmail").focus();
		document.getElementById("txtEmail").select();
		return false;
	}
	return true;
}
function SomenteNumeros(event)
{		
  var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
  var caract = new RegExp(/[0-9,','{1}]+$/i);
  var caract = caract.test(String.fromCharCode(keyCode));
//  alert(keyCode);
  
  if(keyCode==8)return true;
  if(keyCode==13)keyCode = 9;
  if(keyCode==9) return true;
  if((keyCode > 95) && (keyCode < 106))return true;

   if(!caract)
   {
   	   //alert("Caracter inválido: " + keyCode);
  	   keyCode=0;
   	   return false;
   }
}
function ValidaEmail(email) 
{
	if (email == "") 
	{
		alert("Informe seu e-mail.");
		return false;
	}
	else 
	{
		prim = email.indexOf("@")
		if(prim < 2) 
		{
			alert("O e-mail informado parece nao estar correto.");
			return false;
		}
		if(email.indexOf("@",prim + 1) != -1) 
		{
			alert("O e-mail informado parece nao estar correto.");
			return false;
		}
		if(email.indexOf(".") < 1) 
		{
			alert("O e-mail informado parece nao estar correto.");
			return false;
		}
		if(email.indexOf(" ") != -1) 
		{
			alert("O e-mail informado parece nao estar correto.");
			return false;
		}
		if(email.indexOf("zipmeil.com") > 0) 
		{
			alert("O e-mail informado parece nao estar correto.");
			return false;
		}
		if(email.indexOf("hotmeil.com") > 0) 
		{
			alert("O e-mail informado parece nao estar correto.");
			return false;
		}
		if(email.indexOf(".@") > 0) 
		{
			alert("O e-mail informado parece nao estar correto.");
			return false;
		}
		if(email.indexOf("@.") > 0) 
		{
			alert("O e-mail informado parece nao estar correto.");
			return false;
		}
		if(email.indexOf(".com.br.") > 0) 
		{
			alert("O e-mail informado parece nao estar correto.");
			return false;
		}
		if(email.indexOf("/") > 0) 
		{
			alert("O e-mail informado parece nao estar correto.");
			return false;
		}
		if(email.indexOf("[") > 0) 
		{
			alert("O e-mail informado parece nao estar correto.");
			return false;
		}
		if(email.indexOf("]") > 0)
		{
			alert("O e-mail informado parece nao estar correto.");
			return false;
		}
		if(email.indexOf("(") > 0)
		{
			alert("O e-mail informado parece nao estar correto.");
			return false;
		}
		if(email.indexOf(")") > 0) 
		{
			alert("O e-mail informado parece nao estar correto.");
			return false;
		}
		if(email.indexOf("..") > 0)
		{
			alert("O e-mail informado parece nao estar correto.");;
			return false;
		}
	}
	return true;
}
function ValidaLogin()
{
	var login = document.getElementById("txtLogin").value.trim(); 
	var senha = document.getElementById("txtSenha").value.trim(); 
	if((login==""))
	{
		alert("O campo [Nome de Usuario] nao foi preenchido corretamente");
		return false;
	}
		if((senha==""))
	{
		alert("O campo [Senha de Acesso] nao foi preenchido corretamente");
		return false;
	}
	return true;
}
function ValorDoDrop(Drop1,valor1)
{
	var Sel1 = Drop1;
	var indice = 0;
	for (var i=0; i < Sel1.options.length; i++)
	{
		if(Sel1.options[i].value==valor1) 
		{
			indice = i;
			break;
		}
	}
	Sel1.selectedIndex = indice;
}
