function autoTab(input) {
    input.form[(getIndex(input)+1) % input.form.length].focus();
}
function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1) {
        if (input.form[i] == input) {
            index = i;
        } else {
            i++;
        }
    }
    return index;
}

function startDDD(id) {
    input = document.getElementById(id);
    input.onkeypress = onlyNumber;
    input.onkeyup = dddComplete;
}
function startFone(id) {
    input = document.getElementById(id);
    input.onkeypress = onlyNumber;
    input.onkeyup = dddComplete;
}
function startCep1(id) {
    input = document.getElementById(id);
    input.onkeypress = onlyNumber;
    input.onkeyup = dddComplete;
}
function startTelefone(id) {
    input = document.getElementById(id);
    input.onkeypress = onlyNumber;
    //input.onkeyup = dddComplete;
    //input.onblur = formatFone;
}
function formatFone() {
    value = this.value.replace(/\D/gi,"");
    value = value.replace(/(\d{4})(\d{4})/,"$1-$2");
    this.value = value;
}
function dddComplete() {
    element = this;
    max = element.getAttribute("maxlength");
    if(element.value.length >= max) {
        autoTab(element);
    }
}
function getKey(e) {
    if(typeof(e) == "undefined") e = window.event;
    var keyCode = "";
    switch(navigator.appName) {
        case "Netscape":
            keyCode = e.which;
            break;
        case "Microsoft Internet Explorer":
            keyCode = e.keyCode;
            break;
        default:
            keyCode = e.which;
            break;
    }
    var key = "";

    if(keyCode == 0 || keyCode == 8 || keyCode == 13) {
        key = "specialKey";
    } else {
        key = String.fromCharCode(keyCode);
    }
    return key;
}
function onlyNumber(e) {
    //dbug(this);
    var r;
    if(typeof(e) == "undefined") e = window.event;
    var key = getKey(e);
    if(key.search(/\d/gi) >= 0 || key == "specialKey") {
        r = true;
    } else {
        r = false;
    }
    return r;
}
function init() {
	document.getElementById("callSiglaProduto").value = periodoParseGet(window.location);
    var callConvenio = getCallConvenio(window.location);
    var callOperacao = getCallOperacao(window.location);
    if(callConvenio) {
        document.getElementById("callConvenio").value = callConvenio;
    }
    if(callOperacao) {
        document.getElementById("callOperacao").value = callOperacao;
    }
    startDDD("txtDDD");
	startFone("txtFone");
	startCep1("txtCep1");
    startTelefone("telefone1");
    //callTpAgendamento.onkeypress = onlyNumber;
    startDDD("ddd2");
    startTelefone("telefone2");
    //startDate("callTpAgendamento");
    //startDDD("callDDD3");
    //startTelefone("callTelefone3");
    //RG.onkeypress = onlyNumber;
    //CGCCPF.onkeypress = onlyNumber;
    document.forms["formCallback"].onsubmit = validateFom;
    startLigth("formCallback");
    //dbug(navigator.mimeTypes["application/x-shockwave-flash"]);
    //document.oncontextmenu = contextMenu;
    //document.getElementsByTagName("fieldset")[0].oncontextmenu = contextMenu;
}

function Verifica()
 {
 var LOGIN  = document.FormAdd.txtLogin.value;
 var SENHA  = document.FormAdd.txtSenha.value;
 var SENHA2  = document.FormAdd.txtSenha2.value;
 var EMAIL  = document.FormAdd.txtMail.value;

 erro = "";
 //Campos vazios
 if (LOGIN == "")
	 erro = "* Digitar um Login \n";
 if (SENHA == "")
	 erro = erro +"* Digitar uma Senha \n";
 if (SENHA2 == "")
	 erro = erro +"* Repetir a Senha \n";
 if (EMAIL == "")
	 erro = erro +"* Digitar seu e-mail \n";
 if (erro != "")
 {
	alert("É necessário: \n" + erro);
	aux=0;
	if (aux==0) {
		if (LOGIN==""){
			aux=1;
			document.FormAdd.txtLogin.focus();
		}
	}
	if (aux==0) {
		if (SENHA == "") {
			aux=1;
			document.FormAdd.txtSenha.focus();
		}
	}
	if (aux==0) {
		if (SENHA2 == "") {
			aux=1;
			document.FormAdd.txtSenha2.focus();
		}
	}
	if (aux==0) {
		if (EMAIL == "") {
			aux=1;
			document.FormAdd.txtMail.focus();
		}
	}
	return false;
 }
 if (EMAIL.indexOf('@') == -1 || EMAIL.indexOf('.') == -1) {
 alert ('Preencha o campo e-mail no formato seu@email.com.br');
 document.FormAdd.txtMail.focus();
 return false;
 }

	//Campos com valor errado
if (((document.FormAdd.txtLogin.value.length <= 4) || (document.FormAdd.txtLogin.value.length > 12)))
	erro = "O login deve ter no mínimo 5 caracteres e no máximo 12. \n";
	document.FormAdd.txtLogin.focus();
if (((document.FormAdd.txtSenha.value.length <= 4) || (document.FormAdd.txtSenha.value.length > 12)))
	erro = erro + "A senha deve ter no mínimo 5 caracteres e no máximo 12.";
	document.FormAdd.txtSenha.focus();
if (erro != "") 
{
	alert("Atenção: \n" + erro);
	aux=0;
	if (aux==0) {
		if (((document.FormAdd.txtLogin.value.length <= 4) || (document.FormAdd.txtLogin.value.length > 12))){
		aux=1;
		document.FormAdd.txtLogin.focus();
		}
	}
	if (aux==0) {
		if (((document.FormAdd.txtSenha.value.length <= 4) || (document.FormAdd.txtSenha.value.length > 12))){
		aux=1;
		document.FormAdd.txtSenha.focus();
		}
	}
	return false;
}

//Senha
if (document.FormAdd.txtSenha.value != document.FormAdd.txtSenha2.value)
{
	alert("Senha inválida! \n As senhas informadas não são iguais.");
	document.FormAdd.txtSenha2.focus();
	return false;
}

}

function VerificaRecuperarSenha()
 {
 var EMAIL  = document.FormRecuperar.txtMail.value;

 erro = "";
 //Campos vazios
 if (EMAIL == "")
	 erro = erro +"* Digitar seu e-mail \n";
 if (erro != "")
 {
	alert("É necessário: \n" + erro);
	aux=0;
	if (aux==0) {
		if (EMAIL == "") {
			aux=1;
			document.FormRecuperar.txtMail.focus();
		}
	}
	return false;
 }
 if (EMAIL.indexOf('@') == -1 || EMAIL.indexOf('.') == -1) {
 alert ('Preencha o campo e-mail no formato seu@email.com.br');
 document.FormRecuperar.txtMail.focus();
 return false;
 }
}

function Verifica_alterar()
 {
 var LOGIN  = document.FormAlter.txtLogin.value;
 var SENHA  = document.FormAlter.txtSenha.value;
 var SENHA2  = document.FormAlter.txtSenha2.value;
 var EMAIL  = document.FormAlter.txtMail.value;
 var NOME = document.FormAlter.txtNome.value;

 erro = "";
 //Campos vazios
 if (LOGIN == "")
	 erro = "* Digitar um Login \n";
 if (SENHA == "")
	 erro = erro +"* Digitar uma Senha \n";
 if (SENHA2 == "")
	 erro = erro +"* Repetir a Senha \n";
 if (EMAIL == "")
	 erro = erro +"* Digitar seu e-mail \n";
 if (NOME == "")
 	 erro = erro +"* Digitar seu Nome \n";
 if (erro != "")
 {
	alert("É necessário: \n" + erro);
	aux=0;
	if (aux==0) {
		if (LOGIN==""){
			aux=1;
			document.FormAlter.txtLogin.focus();
		}
	}
	if (aux==0) {
		if (SENHA == "") {
			aux=1;
			document.FormAlter.txtSenha.focus();
		}
	}
	if (aux==0) {
		if (SENHA2 == "") {
			aux=1;
			document.FormAlter.txtSenha2.focus();
		}
	}
	if (aux==0) {
		if (EMAIL == "") {
			aux=1;
			document.FormAlter.txtMail.focus();
		}
	}
	if (aux==0) {
		if (NOME == "") {
			aux=1;
			document.FormAlter.txtNome.focus();
		}
	}
	return false;
 }
 if (EMAIL.indexOf('@') == -1 || EMAIL.indexOf('.') == -1) {
 alert ('Preencha o campo e-mail no formato seu@email.com.br');
 document.FormAlter.txtMail.focus();
 return false;
 }

	//Campos com valor errado
if (((document.FormAlter.txtLogin.value.length <= 4) || (document.FormAlter.txtLogin.value.length > 12)))
	erro = "O login deve ter no mínimo 5 caracteres e no máximo 12. \n";
	document.FormAlter.txtLogin.focus();
if (((document.FormAlter.txtSenha.value.length <= 4) || (document.FormAlter.txtSenha.value.length > 12)))
	erro = erro + "A senha deve ter no mínimo 5 caracteres e no máximo 12.";
	document.FormAlter.txtSenha.focus();
if (erro != "") 
{
	alert("Atenção: \n" + erro);
	aux=0;
	if (aux==0) {
		if (((document.FormAlter.txtLogin.value.length <= 4) || (document.FormAlter.txtLogin.value.length > 12))){
		aux=1;
		document.FormAlter.txtLogin.focus();
		}
	}
	if (aux==0) {
		if (((document.FormAlter.txtSenha.value.length <= 4) || (document.FormAlter.txtSenha.value.length > 12))){
		aux=1;
		document.FormAlter.txtSenha.focus();
		}
	}
	return false;
}

//Senha
if (document.FormAlter.txtSenha.value != document.FormAlter.txtSenha2.value)
{
	alert("Senha inválida! \n As senhas informadas não são iguais.");
	document.FormAlter.txtSenha2.focus();
	return false;
}

}
/*---------------------------contato-------------------------------------------*/
function testacampos()
 {
 aux=0;
 xnome=document.contato.Nome.value;
 if (aux==0) {
 if (xnome==""){
 aux=1;
 alert("Preencha o campo Nome");
 document.contato.Nome.focus();
 return false;
 }
 }
 xemail=document.contato.Email.value;
 if (aux==0) {
 if (xemail == ""){
 aux=1;
 alert("Preencha o campo Email");
 document.contato.Email.focus();
 return false;
 }
 }
 if (aux==0) {
 if (document.contato.Email.value.indexOf("@") < 0){
 aux=1;
 alert("Preencha o campo e-mail no formato seu@email.com.br")
 document.contato.Email.focus();
 return false;
 }
 }
 if (aux==0) {
 if (document.contato.Email.value.indexOf(".") < 0){
 aux=1;
 alert("Preencha o campo e-mail no formato seu@email.com.br");
 document.contato.Email.focus();
 return false;
 }
 }
 }