var number = /[^0-9]/gi;
function formatDate(e, object) {
	var key = e.keyCode;
	var valor = object.value.replace(number, "");
	var size = valor.length;
	var valFormatado = "";
	var dia = "", mes = "", ano = "";
	if (key != 8 && key != 37 && key != 39) {
		for ( var i = 0; i < size; i++) {
			valFormatado = valFormatado + valor.substr(i, 1);
			if (i == 1) {
				dia = parseInt(valor.substr(0, 2), 10);
				if (dia < 1 || dia > 31) {
					valFormatado = "";
				} else {
					valFormatado = valFormatado + "/";
				}
			}
			if (i == 3) {
				mes = parseInt(valor.substr(2, 2), 10);
				if ((mes < 1 || mes > 12)
						|| ((mes == 4 || mes == 6 || mes == 9 || mes == 11) && dia == 31)) {
					valFormatado = valFormatado.substr(0, 3);
				} else if (mes == 2) {
					if (dia > 29) {
						valFormatado = "";
					} else {
						valFormatado = valFormatado + "/";
					}
				} else {
					valFormatado = valFormatado + "/";
				}
			}
			if (i == 7) {
				ano = parseInt(valor.substr(4, 4), 10);
				if (ano < 1900 || ano > 2100) {
					valFormatado = valFormatado.substr(0, 6);
				} else {
					var isBissexto = ((0 == ano % 4) && (0 != (ano % 100))) || (0 == ano % 400);
					if (isBissexto && dia > 29 && mes == 2) {
						valFormatado = "";
					} else if (!isBissexto && dia > 28 && mes == 2) {
						valFormatado = "";
					}
				}
			}
		}
		object.value = size > 8 ? valFormatado.substr(0, 10) : valFormatado;
	}
}
function formatTime(e, object) {
	var key = e.keyCode;
	var valor = object.value.replace(number, "");
	var size = valor.length;
	var valFormatado = "";
	var hora = "", min = "", seg = "";
	if (key != 8 && key != 37 && key != 39) {
		for ( var i = 0; i < size; i++) {
			valFormatado = valFormatado + valor.substr(i, 1);
			if (i == 1) {
				hora = parseInt(valor.substr(0, 2), 10);
				if (hora < 0 || hora > 23) {
					valFormatado = "";
				} else {
					valFormatado = valFormatado + ":";
				}
			}
			if (i == 3) {
				min = parseInt(valor.substr(2, 2), 10);
				if (min < 0 || min > 59) {
					valFormatado = valor.substr(0, 2) + ":";
				} else {
					valFormatado = valFormatado;
				}
			}
		}
		object.value = size > 4 ? valFormatado.substr(0, 5) : valFormatado;
	}
}
function formatNumber(object, hasDot, e) {
	format(object, 0, hasDot);
}
function formatDecimal(object, hasDot, e) {
	format(object, 2, hasDot);
}

function format(object, nroCasas, hasDot) {
	var maxLength = object.maxLength;
	var valor = object.value;


	object.value = getNumberFormated(valor, nroCasas, maxLength, hasDot);
}

function getNumberFormatedDecimal(valor, nroCasas, maxLength, hasDot) {
	if (valor == null) {
		return "";
	}

	valor = valor.toString();
	
	if (valor.indexOf(',') > 0) {
		valor = valor.replace(/\./g, '').replace(',', '.');
	}
	
	var dot = valor.indexOf('.');

	var decLength = null;
	if (dot > 0) {
		decLength = valor.substr(dot + 1).length;
	} else {
		decLength = 0;
	}
	
	for (a = 0; a < (nroCasas - decLength); a ++) {
		valor = valor + "0";
	}
	return getNumberFormated(valor, nroCasas, maxLength, hasDot)
}

function getNumberFormated(valor, nroCasas, maxLength, hasDot) {
	valor = valor.toString().replace(number, "");
	
	if (valor == "") {
		return "";
	}
	
	if (nroCasas == null) {
		nroCasas = 2;
	}
	if (!maxLength) {
		maxLength = 0;
	}
	
	if (hasDot == null) {
		hasDot = true;
	}
	
	if (maxLength > 0) {
		valor = valor.substr(0, maxLength - (hasDot ? 1 : 0));
	}
	
	var size = valor.length;
	var valFormatado = "";
	var hasDecimal = nroCasas > 0;
	var hasComma = false;
	
	for (var i = 0; i < size; i++) {
		var posRev = size - i;
		valFormatado = valFormatado + valor.substr(i, 1);
		if (!hasComma && hasDecimal && posRev > 1 && posRev <= (nroCasas + 1)) {
			valFormatado = valFormatado + ",";
			hasComma = true;
		} else {
			if (hasDot) {
				if ((!hasDecimal && posRev >= 4 && (posRev - 4) % 3 === 0) || (hasDecimal && posRev > nroCasas && (posRev - (nroCasas + 1)) % 3 === 0)) {
					valFormatado = valFormatado + ".";
				}
			}
		}
	}
	return valFormatado;
}

function formatTelefone(object) {
	var tel = object.value;
	if(tel) {
		var er = /([1-9]\d{3}[-\s]\d{4})|(0800\d{6,9})/;
		if (!er.exec(tel)) {
			alert("Telefone inválido. Os formatos validos são: 0800nnnnnnnnn ou nnnn-nnnn");
			
			object.focus();
		}
	}
	
}

function fillZeros(object, nroCasas) {
	var valor = object.value.replace(number, "");
	var size = valor.length;
	if (size <= nroCasas) {
		var zeros = "";
		for (i = 0; i <= nroCasas - size; i ++) {
			zeros += "0";
		}
		valor = valor + zeros;
		size = valor.length;
	}
	
	valor = valor.substr(0, (size - nroCasas)) + "," + valor.substr(size - nroCasas);
	
	object.value = valor;
}

function mascara(event, object, func) {
	key = event.keyCode;
	obj = object;
	fun = func;
	setTimeout("execmascara()", 1);
}
function execmascara() {
	if (key != 8 && key != 37 && key != 39 && key != 46) {
		obj.value = fun(obj.value);
	}
}

/*Função que padroniza telefone 4184-1241*/
function telefone(v){
	
	v=v.replace(/\D/g,"");
	
	
	v=v.replace(/(\d{4})(\d)/,"$1-$2");

	return v
}

function cpf(val) {
	val = val.replace(/\D/g, "");
	val = val.replace(/(\d{3})(\d)/, "$1.$2");
	val = val.replace(/(\d{3})(\d)/, "$1.$2");
	val = val.replace(/(\d{3})(\d{1,2})$/, "$1-$2");
	if (val.length > 14) {
		val = val.substr(0, 14);
	}
	return val;
}
function cnpj(val) {
	val = val.replace(/\D/g, "");
	val = val.replace(/^(\d{2})(\d)/, "$1.$2");
	val = val.replace(/^(\d{2})\.(\d{3})(\d)/, "$1.$2.$3");
	val = val.replace(/\.(\d{3})(\d)/, ".$1/$2");
	val = val.replace(/(\d{4})(\d)/, "$1-$2");

	return val;
}
function cei(val) {
	val = val.replace(/\D/g, "");
	val = val.replace(/^(\d{2})(\d)/, "$1.$2");
	val = val.replace(/^(\d{2})\.(\d{3})(\d)/, "$1.$2.$3");
	val = val.replace(/\.(\d{5})(\d)/, ".$1/$2");
	if (val.length > 15) {
		val = val.substr(0, 15);
	}

	return val;
}
function cep(val) {
	val = val.replace(/\D/g, "");
	val = val.replace(/^(\d{5})(\d)/, "$1-$2");
	return val;
}
// Somente letras e números
function alphanumeric(v) {
	v1 = v.value.replace(/\W/g, "");
	v.value = v1;
}

// Somente números
function numeric(v) {
	v1 = v.value.replace(/\D/g, "");
	v.value = v1;
}

var enviado = false;
function enviar(url) {
	if (!enviado) {
		document.body.style.cursor = "wait";
		enviado = true;
		window.location = url;
	}
}

function enviarDiv(div, url) {
	if (!enviado) {
		// document.body.style.cursor = "wait";
		// enviado = true;
		loadPage(div, url);
	}
}
function enviarFormAjax(div, form, val) {
	
	if(!val){
		val = validation;
	}
	if (!div) {
		div = messageObj.divs_content.id;
	}
	if (!enviado && val.validate(form)) {
		var url = populateUrl(form);
		loadPage(div, url, "POST");
	}
	
}

function enviarForm(form) {
	if (!enviado && validation.validate(form)) {
		document.body.style.cursor = "wait";
		enviado = true;
		form.submit();
	}
}

function popinFormPost(form) {
	popinValidationFormPost(validationPopin, form);
}

function popinValidationFormPost(novoValidation, form) {
	if (novoValidation.validate(form)) {
		var url = form.action + "?";
		var els = form.elements;
		var amper = "";
		for (i = 0; i < els.length; i++) {
			if ((els[i].type != "button" && els[i].type != "checkbox"
					&& els[i].name != "" && els[i].value != "")
					|| (els[i].type != "checkbox" && els[i].checked)) {
				url += amper + els[i].name + "=" + els[i].value;
				if (amper == "") {
					amper = "&";
				}
			}
		}
		displayMessage(url, messageObj.width, messageObj.height);
		// enviado = true;
	}
}

function populateUrl(form) {
	var url = form.action + "?";
	var els = form.elements;
	var amper = "";
	for (i = 0; i < els.length; i++) {
		if (
				(els[i].type != "button" && els[i].type != "checkbox" && els[i].type != "radio" && els[i].name != "" && els[i].value != "") || 
				((els[i].type == "checkbox" || els[i].type == "radio") && els[i].checked)
			) {
			url += amper + els[i].name + "=" + els[i].value;
			if (amper == "") {
				amper = "&";
			}
		}
	}
	return url
}

function clearForm(form) {
	for ( var i = 0; i < form.elements.length; i++) {
		var el = form.elements[i];
		if (el.type == "radio" || el.type == "checkbox") {
			el.checked = false;
		} else {
			if (el.type == "select-one") {
				el.selectedIndex = 0;
			} else {
				if (el.type != "button" && el.type != "submit") {
					el.value = "";
				}
			}
		}
	}
}

function apagarDiv(div, url) {
	if (confirm("Clique em OK para confirmar.")) {
		enviarDiv(div, url);
	}
}

function apagar(url) {
	if (confirm("Clique em OK para confirmar.")) {
		enviar(url);
	}
}


function showErrorMessagePopin(msg) {
	displayChildStaticMessage("Aten&ccedil&atilde;o !", msg, getButton("OK", "closeMessage()"), 450, 250, true);
}

function showErrorMessageCallbackPopin(msg, callback) {
	displayChildStaticMessage("Aten&ccedil&atilde;o !", msg, getButton("OK", callback + ";closeMessage()"), 450, 250, true);
}

function showMessagePopin(msg) {
	displayChildStaticMessage("ConnectOdonto", "<ul class='success'>" + msg + "</ul>", getButton("OK", "closeMessage()"), 450, 250, false);
}

function showMessageEnviarPopin(msg, url) {
	displayChildStaticMessage("ConnectOdonto", "<ul class='success'>" + msg + "</ul>", getButton("OK", "enviar('" + url + "')"), 450, 250, false);
}

//BEGIN ABAS
function changeAba(idAba, div, url) {
	var abas = document.getElementById("submenuAba");
	var count = 0;
	for (i = 0; i < abas.childNodes.length; i++) {
		if (count == idAba) {
			abas.childNodes[i].id = "current";
		} else {
			abas.childNodes[i].id = "";
		}
		var divAba = document.getElementById("abaAtributo" + count);
		if (divAba != null) {
			divAba.style.display = "none";
		}
		if (abas.childNodes[i].tagName == "LI") {
			count++;
		}
	}
	document.getElementById("conteudoSubBarra").style.display = "none";
	if (url == "") {
		document.getElementById(div).style.display = "";
		document.getElementById("conteudoSubBarra").innetHTML = "";
	} else {
		document.getElementById(div).style.display = "";
		loadPage(div, url);
	}
	//breadcrumbAjax.setAba(idAba);
}

function changeGrupo(idGrupo, div, url) {
	var grupo = document.getElementById(div);
	var count = 0;
	for (i = 0; i < grupo.childNodes.length; i++) {
		if (grupo.childNodes[i].id != null
				&& grupo.childNodes[i].id.indexOf(div + "Grupo") == 0) {
			if (count == idGrupo) {
				display = "";
				document.getElementById(div + "BarraGrupo" + count).className = "barraGrupo";
			} else {
				display = "none";
				document.getElementById(div + "BarraGrupo" + count).className = "barraGrupob";
			}
			document.getElementById(div + "GrupoTr" + count).style.display = display;
			count++;
		}
	}
	if (url != null && url != "") {
		loadPage(div + "GrupoDiv" + idGrupo, url);
	}
	//breadcrumbAjax.setGrupo(div, idGrupo);
}

function addAba(id, nome, url, change){
	if (change == null) {
		change = true;
	}
	
	var indexAba = $('#submenuAba>li').size();
	$('#submenuAba').append('<li><a href="javascript:void(0)" onclick="changeDynamicAba(this, \'conteudoSubBarra\', \'' + url + '\')" title="' + nome + '">' + nome + '&nbsp;&nbsp;&nbsp;<span style="color: black;" onclick="removeAba(this, \''+ id + '\', \'' + url + '\')">x</span></a></li>');
	
	if (change) {
		changeAba(indexAba, 'conteudoSubBarra', url);
	}
}

function createAba(id, nome, url){
	var callback = function(created) {
		addAba(id, nome, url);
		if (created) {
		}
	};
	
	utilAjax.addAba(id, nome, url, callback);
}

function loadAbas(id) {
	var callback = function(abas) {
		for (i = 0; i < abas.length; i ++) {
			addAba(id, abas[i].nome, abas[i].url, false);
		}
	};
	
	utilAjax.getAbas(id, callback);
}

function removeAba(aba, id, url) {
	var li = $(aba).parent().parent();
	
	removeAbaPorLI(li, id, url);
}
function removeLastAba(id, url) {
	var li = $('#submenuAba>li:last');
	removeAbaPorLI(li, id, url);
}

function removeAbaPorLI(li, id, url) {
	var indexAba = $('#submenuAba>li').index(li);
	utilAjax.removeAba(id, $('#submenuAba>li:eq(' + indexAba + ')>a:eq(0)').attr('title'), url);
	
	li.remove();

	var size = $('#submenuAba>li').size();
	indexAba = (indexAba < size ? (indexAba) : (indexAba - 1));
	$('#submenuAba>li:eq(' + indexAba + ')>a:eq(0)').click();
}

function changeDynamicAba(aba, div, url) {
	var li = $(aba).parent();
	var idAba = $('#submenuAba>li').index(li);
	changeAba(idAba, div, url);
}

function openAbaSeguradoComplemento(idSegurado) {
	createAba("segurado_" + idSegurado, "Segurado", "cadastro-divSeguradoComplemento.action?id=" + idSegurado);
}
//FIM ABAS

function maxlength(obj, size) {
	if (obj.value.length >= size) {
		obj.value = obj.value.substr(0, (size - 1));
	}
}
var tipoConselhoClasse;
function showConselhoClasse(t) {
	tipoConselhoClasse = t;
	displayMessage("webprestador-popinListRegistroConselhoClasse.action", 850, 500);
}

function getRegistroConselhoClasseInSession() {
	var callback = function(registroConselhoClasse) {
		setRegistroConselhoClasse(registroConselhoClasse.id, registroConselhoClasse.tipoConselhoClasse.id, registroConselhoClasse.uf.id, registroConselhoClasse.numero, registroConselhoClasse.nome)
	};
	cadastroGeralAjax.getRegistroConselhoClasseInSession(callback)
}

function setRegistroConselhoClasse(id, tipoConselhoClasseId, ufId, numero, nome) {
	getObject("id" + tipoConselhoClasse).value = id;
	getObject("nome" + tipoConselhoClasse).value = tipoConselhoClasseId + "-"
			+ ufId + "-" + numero + " " + nome;
	closeMessage();
}

// Registro Conselho de Classe
function searchRegistroConselhoClasse(tipo) {
	tipoConselhoClasse = tipo;
	var uf = document.getElementById("idUfRegistroConselhoClasse"
			+ tipoConselhoClasse).value;
	var tcc = document.getElementById("idTipoRegistroConselhoClasse"
			+ tipoConselhoClasse).value;
	var ncc = document.getElementById("numeroRegistroConselhoClasse"
			+ tipoConselhoClasse).value;
	if (uf != "" || tcc != "" || (ncc != "" && ncc.match("\\D") != null)) {
		displayMessage(
				"webprestador-popinListRegistroConselhoClasse.action?pesquisar=true"
						+ (uf != "" ? "&vo.uf.id=" + uf : "")
						+ (tcc != "" ? "&vo.tipoConselhoClasse.id=" + tcc : "")
						+ (ncc != "" ? "&vo.numero=" + ncc : ""), 850, 500);
	} else {
		displayMessage("webprestador-popinListRegistroConselhoClasse.action",
				850, 500);
	}
}
function searchRegistroConselhoClasseBlur(tipo) {
	tipoConselhoClasse = tipo;
	var uf = document.getElementById("idUfRegistroConselhoClasse"
			+ tipoConselhoClasse).value;
	var tcc = document.getElementById("idTipoRegistroConselhoClasse"
			+ tipoConselhoClasse).value;
	var ncc = document.getElementById("numeroRegistroConselhoClasse"
			+ tipoConselhoClasse).value;
	if (uf != "" && tcc != "" && ncc != "" && ncc.match("\\D") == null) {
		credenciamentoAjax.findRegistroConselhoClasse(uf, tcc, ncc,
				callbackRegistroConselhoClasse);
	}
}
function callbackRegistroConselhoClasse(rcc) {
	if (rcc != null) {
		document.getElementById("idUfRegistroConselhoClasse" + tipoConselhoClasse).value = rcc.uf.id;
		document.getElementById("idTipoRegistroConselhoClasse" + tipoConselhoClasse).value = rcc.tipoConselhoClasse.id;
		document.getElementById("numeroRegistroConselhoClasse" + tipoConselhoClasse).value = rcc.numero;
		document.getElementById("idRegistroConselhoClasse" + tipoConselhoClasse).value = rcc.id;
		document.getElementById("nomeRegistroConselhoClasse" + tipoConselhoClasse).value = rcc.nome;
		closeMessage();
	} else {
		document.getElementById("idUfRegistroConselhoClasse" + tipoConselhoClasse).value = "";
		document.getElementById("idTipoRegistroConselhoClasse" + tipoConselhoClasse).value = "";
		document.getElementById("numeroRegistroConselhoClasse" + tipoConselhoClasse).value = "";
		document.getElementById("idRegistroConselhoClasse" + tipoConselhoClasse).value = "";
		document.getElementById("nomeRegistroConselhoClasse" + tipoConselhoClasse).value = "";
		searchRegistroConselhoClasse(tipoConselhoClasse);
	}
}
function setRegistroConselhoClasse(id, tipoConselhoClasseId, ufId, numero, nome) {
	document.getElementById("idRegistroConselhoClasse" + tipoConselhoClasse).value = id;
	document.getElementById("nomeRegistroConselhoClasse" + tipoConselhoClasse).value = nome;
	document.getElementById("idUfRegistroConselhoClasse" + tipoConselhoClasse).value = ufId;
	document.getElementById("idTipoRegistroConselhoClasse" + tipoConselhoClasse).value = tipoConselhoClasseId;
	document.getElementById("numeroRegistroConselhoClasse" + tipoConselhoClasse).value = numero;
	closeMessage();
}


/* Popin de Localidade */
var tipoLocalidade;
function showLocalidade(tl) {
	tipoLocalidade = tl;
	displayMessage("cadastrogeral-popinListLocalidade.action", 800, 400);
}
function setLocalidade(id, nome, uf) {
	getObject(tipoLocalidade + ".id").value = id;
	getObject(tipoLocalidade + ".nome").value = nome
			+ (uf != null && uf != "" ? " - " + uf : "");
	closeMessage();
}

/* Popin de Bairro */
var tipoBairro;
function showBairro(b, idLocalidade) {
	tipoBairro = b;
	if (idLocalidade == null && tipoLocalidade != null) {
		idLocalidade = getObject(tipoLocalidade + ".id").value;
	}
	if (idLocalidade != null && idLocalidade != "") {
		displayMessage(
				"/OdontoUtilisWeb/cadastrogeral-popinListBairro.action?idLocalidade="
						+ idLocalidade, 800, 450);
	} else {
		alert("Selecione a localidade.");
		// displayMessage('/OdontoUtilisWeb/cadastrogeral-popinListBairro.action',
		// 670, 470)
	}
}
function setBairro(id, nome) {
	getObject(tipoBairro + ".id").value = id;
	getObject(tipoBairro + ".nome").value = nome;
	closeMessage();
}
/* Popin de Convênio */
var conv;
function showConvenio(c, idOperadora) {
	conv = c;
	if (idOperadora != null) {
		displayMessage(
				"/OdontoUtilisWeb/cadastro-popinListConvenio.action?vo.operadora.id="
						+ idOperadora + "&idOperadora=" + idOperadora, 630, 400);
	} else {
		displayMessage("/OdontoUtilisWeb/cadastro-popinListConvenio.action",
				630, 400);
	}
}
function setConvenio(id, nome) {
	getObject("id" + conv).value = id;
	getObject("nome" + conv).value = nome;
	closeMessage();
}
function getObject(id) {
	var obj = document.getElementById(id);
	if (obj == null) {
		obj = document.getElementsByName(id)[0];
	}
	return obj;
}

/* Popin Rede Credenciada */
var rc;
function showRedeCredenciada(rc) {
	redecr = rc;
	displayMessage(
			"/OdontoUtilisWeb/credenciamento-popinListRedeCredenciada.action",
			630, 400);
}
function setRedeCredenciada(id, nome) {
	getObject("id" + redecr).value = id;
	getObject("nome" + redecr).value = nome;
	closeMessage();
}

/* Popin Especialidade */
var es;
function showEspecialidade(es) {
	esp = es;
	displayMessage(
			"/OdontoUtilisWeb/procedimento-popinListEspecialidade.action", 630,
			400);
}
function setEspecialidade(id, nome) {
	getObject("id" + esp).value = id;
	getObject("nome" + esp).value = nome;
	closeMessage();
}

/* Popin Evento Tabela */
var et;
function showEventoTabela(et, idTabela) {
	evttb = et;
	displayMessage("webprestador-popinListEventoTabela.action?idTabela=" + idTabela, 630, 500);
}
function setEventoTabela(id, codigo, nome) {
	getObject("id" + evttb).value = id;
	getObject("nome" + evttb).value = codigo + " - " + nome;
	closeMessage();
}

/* Popin Estipulante */
var estip;
function showEstipulante(e, idOperadora) {
	estip = e;
	displayMessage(
			"/OdontoUtilisWeb/cadastro-popinListEstipulante.action?idOperadora="
					+ idOperadora, 650, 450);
}
function setEstipulante(id, nome) {
	getObject("id" + estip).value = id;
	getObject("nome" + estip).value = nome;
	closeMessage();
}

/* Popin Subestipulante */
var subest;
function showSubestipulante(sub, idOperadora, origem) {
	subest = sub;
	if (!idOperadora) {
		if( document.getElementById("idOperadora").value != ''){
			idOperadora = document.getElementById("idOperadora").value;
		}else{
			idOperadora = document.getElementById("vo.operadora.id").value;
		}
	}

	if (origem != null) {
		displayMessage("/ConnectOdontoWeb/webempresa-popinListSubestipulante.action?idOperadora=" + idOperadora + "&origem=" + origem, 650, 450);
	} else {	
		displayMessage("/ConnectOdontoWeb/webempresa-popinListSubestipulante.action?idOperadora=" + idOperadora, 650, 450);
	}
}
function setSubestipulante(id, nome) {
	var idField, nameField;
	if (subest.indexOf('*') > 0) {
		idField = subest.replace("*", "id");
		nameField = subest.replace("*", "nome");
	} else {
		idField = "id" + subest;
		nameField = "nome" + subest;
	}
	
	if(subest.indexOf('vo') != -1){
		idField = subest + ".id" ;
		nameField = subest + ".nome";	
	}	
	
	getObject(idField).value = id;
	getObject(nameField).value = nome;
	closeMessage();
}

/* Popin Segurado */
var segurado;
function showSegurado(seg, idOperadora) {
	if (!idOperadora) {
		showErrorMessagePopin('<li class="error">Escolha uma operadora primeiro</li>');
		return;
	}
	segurado = seg;
	displayMessage("cadastro-popinSegurado.action?idOperadora=" + idOperadora, 950, 550);
}
var codigoSeguradoAtual;
function getSegurado(idOperadora, codigoSegurado, seg) {
	segurado = seg;
	var callback = function(segurado) {
		if (segurado) {
			codigoSeguradoAtual = codigoSegurado;
			setSegurado(segurado.idSegurado, segurado.nomeSegurado, segurado.codigoSeguradoFormatado, segurado.nomeSubestipulante, segurado.nomePlano, segurado.nomeTipoParentesco, segurado.idadeEmAnos, segurado.nomeSeguradoTitular, segurado.idConvenio, segurado.idSubestipulante, segurado.necessitaAtivacao);
		} else {
			showErrorMessagePopin("<li class='error'>Segurado n&atilde;o cadastrado.</li>");
		}
		
	}
	
	if (codigoSegurado.length > 0 && codigoSegurado.length < 4) {
		showErrorMessagePopin('<li class="error">O c&oacute;digo do segurado precisa ter pelo menos tamanho 4</li>');
		return null;
	}
	
	if (codigoSegurado && codigoSegurado != codigoSeguradoAtual) {
		cadastroAjax.getSeguradoByCodigo(idOperadora, codigoSegurado, callback);
	}
}

function getSeguradoByConvenio(idConvenio, codigoSegurado, seg){
	segurado = seg;
	var callback = function(segurado) {
		if (segurado) {
			codigoSeguradoAtual = codigoSegurado;
			idConvenioAtual = idConvenio;
			setSegurado(segurado.idSegurado, segurado.nomeSegurado, segurado.codigoSeguradoFormatado, segurado.nomeSubestipulante, segurado.nomePlano, segurado.nomeTipoParentesco, segurado.idadeEmAnos, segurado.nomeSeguradoTitular, segurado.idConvenio, segurado.idSubestipulante, segurado.necessitaAtivacao);
		} else {
			showErrorMessagePopin("<li class='error'>Benefici&aacute;rio n&atilde;o encontrado no Conv&ecirc;nio - Benefici&aacute;rio selecionado.</li>");
		}
	}
	
	if (codigoSegurado.length > 0 && codigoSegurado.length < 4) {
		showErrorMessagePopin('<li class="error">O c&oacute;digo do segurado precisa ter pelo menos tamanho 4</li>');
		return null;
	}
	
	if (codigoSegurado && codigoSegurado != codigoSeguradoAtual) {
		cadastroAjax.getSeguradoByConvenioAndCodigo(idConvenio, codigoSegurado, callback);
	}
	else{
		if(codigoSegurado == "" || codigoSegurado == null){
			showErrorMessagePopin("<li class='error'>Preencha o campo Carteirinha.</li>");
		}
	}
}

function setSegurado(idSegurado, nomeSegurado, codigoSegurado, nomeSubestipulante, nomePlano, nomeTipoParentesco, idadeEmAnos, nomeSeguradoTitular, idConvenio, idSubestipulante, necessitaAtivacao) {
	populateSegurado(idSegurado, nomeSegurado, codigoSegurado, nomeSubestipulante, nomePlano, nomeTipoParentesco, idadeEmAnos, nomeSeguradoTitular, idConvenio, idSubestipulante, necessitaAtivacao);
	closePopin();
}

function populateSegurado(idSegurado, nomeSegurado, codigoSegurado, nomeSubestipulante, nomePlano, nomeTipoParentesco, idadeEmAnos, nomeSeguradoTitular, idConvenio, idSubestipulante, necessitaAtivacao) {
	closeMessage();
	getObject("id" + segurado).value = idSegurado;
	getObject("nome" + segurado).value = nomeSegurado;
	getObject("codigo" + segurado).value = codigoSegurado;
	getObject("nomeSubestipulante" + segurado).value = nomeSubestipulante;
	getObject("nomePlano" + segurado).value = nomePlano;
	getObject("idadeEmAnos" + segurado).value = idadeEmAnos;
	getObject("nomeSeguradoTitular" + segurado).value = nomeSeguradoTitular;
	//getObject("nomeTipoParentesco" + segurado).value = nomeTipoParentesco;
	
	codigoSeguradoAtual = codigoSegurado;
	if (necessitaAtivacao == 'S') {
		showErrorMessagePopin("<li class='error'>Segurado precisa entrar em contato com a central para atualiza&ccedil;&atilde;o cadastral.</li>");
	}
}

/* 	 Prestador - Retorna um PrestadorDTO*/

var prestador;
function getPrestador(codigo, idOperadora, prest) {
	prestador = prest;
	var callback = function(prestador) {
		if (prestador) {
			setPrestador(prestador.idContratoPrestador, prestador.codigoContratoPrestador, prestador.nome, prestador.nomeLocalidade, prestador.uf, prestador.telefone1);
		} else {
			showContratoPrestadorPerito(prest,idOperadora,'S');
		}
	}

	credenciamentoAjax.getPrestador(codigo, callback);

}

function setPrestador(codigo, nome, nomeLocalidade, uf, telefone1) {
	populatePrestador(codigo, nome, nomeLocalidade, uf, telefone1);
}
function populatePrestador(id, codigo, nome, nomeLocalidade, uf, telefone1) {
	getObject("vo.contratoPrestadorPerito.id").value = id;
	getObject("vo.contratoPrestadorPerito.codigo").value = codigo;
	getObject("vo.contratoPrestadorPerito.prestador.nome").value = nome;
	getObject("nomeLocalidadePerito").value = nomeLocalidade;
	getObject("ufPerito").value = uf;	
	getObject("telefonePerito").value = telefone1;	
	closeMessage();
}

/* Popin ContPrestEspecialidade */
var cpes;
function showContPrestEspecialidade(cpes, idContratoPrestador) {
	cpesp = cpes;
	displayMessage("credenciamento-popinListContPrestEspecialidade.action?idContratoPrestador=" + idContratoPrestador, 650, 450);
}
function setContPrestEspecialidade(id, nome) {
	getObject("id" + cpesp).value = id;
	getObject("nome" + cpesp).value = nome;
	closeMessage();
}

/* Popin EventoOperadora */
var eventoOperadora;
function showEventoOperadora(eo) {
	eventoOperadora = eo;
	displayMessage("/OdontoUtilisWeb/procedimento-popinListEventoOperadora.action", 650, 450);
}

function showEventoOperadoraCobertura(planoId) {
	displayMessage("/OdontoUtilisWeb/modelagem-popinListEventoOperadoraCobertura.action?pesquisar=true&planoId=" + planoId, 650, 450);
}

function setEventoOperadora(id, nome) {
	getObject("id" + eventoOperadora).value = id;
	getObject("nome" + eventoOperadora).value = nome;
	closeMessage();
}

/* Popin Entidade Legal */
var entidadeLegal;
function showEntidadeLegal(e, idOperadora) {
	entidadeLegal = e;
	displayMessage("/OdontoUtilisWeb/seguranca-popinListEntidadeLegal.action", 650, 450);
}
function setEntidadeLegal(id, nome) {
	getObject("id" + entidadeLegal).value = id;
	getObject("nome" + entidadeLegal).value = nome;
	closeMessage();
}

/* Popin Autorização */

function showBuscaAutorizacao(idContratoPrestador) {
	displayMessage("central-popinBuscaAutorizacao.action?idContratoPrestador=" + idContratoPrestador, 800, 500);
}

function showAutorizacao(nome, idOperadora) {
	if (!idOperadora) {
		showErrorMessagePopin('<li class="error">Escolha uma operadora primeiro</li>');
		return;
	}

	displayMessage("central-popinBuscaAutorizacao.action?idOperadora=" + idOperadora, 800, 500);
}

function setAutorizacao(idAutorizacao, codigoAutorizacao, idContratoPrestador, nomePrestador, idSegurado, nomeSegurado, carteirinha, codigoContratoPrestador) {
	getObject("idAutorizacao").value = idAutorizacao;
	getObject("codigoAutorizacao").value = codigoAutorizacao;
	getObject("idContratoPrestador").value = idContratoPrestador;

	var nomePrestadorObj = getObject("nomePrestador");
	if (nomePrestadorObj) {
		nomePrestadorObj.value = nomePrestador;
	}
	
	var idSeguradoObj = getObject("idSegurado");
	if (idSeguradoObj) {
		idSeguradoObj.value = idSegurado;
	}
	
	var nomeSeguradoObj = getObject("nomeSegurado");
	if (nomeSeguradoObj) {
		nomeSeguradoObj.value = nomeSegurado;
	}
	
	closeMessage();
}

/* Popin Prestador */
var prestador;
function showBuscaPrestador(idOperadora, p) {
	prestador = p;
	displayMessage("central-popinBuscaPrestador.action?idOperadora=" + idOperadora, 800, 500);
}
function showContratoPrestador(p, idOperadora) {
	if (!idOperadora) {
		showErrorMessagePopin('<li class="error">Escolha uma operadora primeiro</li>');
		return;
	}
	prestador = p;
	displayMessage("central-popinBuscaPrestador.action?idOperadora=" + idOperadora, 800, 500);
}
function setBuscaPrestador(id, idContrato, nome, cpfCnpj, codigoContrato, idRegistroConselhoClasse, uf) {
	var idPrestador = getObject("id" + prestador);
	if (idPrestador) {
		idPrestador.value = id;
	}

	var idContratoPrestador = getObject("idContrato" + prestador);
	if (idContratoPrestador) {
		idContratoPrestador.value = idContrato;
	}

	var nomePrestador = getObject("nome" + prestador);
	if (nomePrestador) {
		nomePrestador.value = nome;
	}

	var cpfCnpjPrestador = getObject("cpfCnpj" + prestador);
	if (cpfCnpjPrestador) {
		cpfCnpjPrestador.value = cpfCnpj;
	}

	var codigoContratoPrestador = getObject("codigoContrato" + prestador);
	if (codigoContratoPrestador) {
		codigoContratoPrestador.value = codigoContrato;
	}
	
	var numeroRegistroConselhoClassePrestador = getObject("numeroRegistroConselhoClasse" + prestador);
	if (numeroRegistroConselhoClassePrestador && idRegistroConselhoClasse) {
		var callback = function(registroConselhoClasse) {
			numeroRegistroConselhoClassePrestador.value = registroConselhoClasse.numeroCompleto;
		}
		cadastroGeralAjax.getRegistroConselhoClasse(idRegistroConselhoClasse, callback);
	}

	var ufPrestador = getObject("uf" + prestador);
	if (ufPrestador) {
		ufPrestador.value = uf;
	}

	closeMessage();
}

//BEGIN CONTA BANCARIA
function showAgencia() {
    var idBanco = document.getElementById("idBanco").value;
    
    if(idBanco == ""){
    	alert("Selecione o banco.");
	} else {
		displayMessage("webempresa-popinListAgencia.action?idBanco=" + idBanco, 750, 450)
	}    
}

function setAgencia(id, numero, nome) {
	dwr.util.setValue("idAgencia", id);
	dwr.util.setValue("agenciaNumero", numero);
	dwr.util.setValue("agenciaNome", nome);
	closeMessage();
}

function setNumeroBanco(numero) {
	dwr.util.setValue("idAgencia", "");
	dwr.util.setValue("agenciaNumero", "");
	dwr.util.setValue("agenciaNome", "");
	dwr.util.setValue("bancoNumero", numero);
}

function changeBanco(idBanco){
	dwr.util.setValue("idAgencia", "");
	dwr.util.setValue("agenciaNumero", "");
	dwr.util.setValue("agenciaNome", "");
	dwr.util.setValue("idBanco", idBanco);
	if(idBanco != dwr.util.getValue("idBanco")){
		dwr.util.setValue("idBanco", "");
	}
	
}

function searchAgencia() {
	var numero = document.getElementById("agenciaNumero").value;
	var numeroBanco = document.getElementById("idBanco").value;
	if (numero!= "") {
		displayMessage("webempresa-popinListAgencia.action?pesquisar=true&idBanco=" + numeroBanco  + (numero != "" ? "&numero=" + numero : ""), 850, 500);
	} else {
		displayMessage("webempresa-popinListAgencia.action?idBanco=" + numeroBanco, 850, 500);
	}
}

function searchAgenciaBlur() {	
	var numero = document.getElementById("agenciaNumero").value;
	var numeroBanco = document.getElementById("idBanco").value;
	
	if(numeroBanco == "") {
		alert("Selecione o Banco");
	}
	if (numero != "" && numeroBanco != "") {
		credenciamentoAjax.findAgencia(numero, numeroBanco, callbackAgencia);
	}
}

function callbackAgencia(ag) {
	if (ag != null) {
		document.getElementById("idAgencia").value = ag.id;
		document.getElementById("agenciaNumero").value = ag.numero;
		document.getElementById("agenciaNome").value = ag.nome;
	} else {
		document.getElementById("agenciaNumero").value = "";
		document.getElementById("agenciaNome").value = "";	
		searchAgencia();
	}
}
//END CONTA BANCARIA

function fillList(id, optionValue, optionLabel, value, list, callback) {
	dwr.util.removeAllOptions(id);
	
	if (list.length > 0) {

		if(id != 'idRedeCredenciada' && id != 'idRedesCredenciadas'){
			appendEmptyOption(id);
		}	
		dwr.util.addOptions(id, list, optionValue, optionLabel);
		if (value) {
			dwr.util.setValue(id, value.toString().trim());
		}
		if (callback != null) {
			callback(document.getElementById(id).value.trim());
		}
	}
}

//Tipo Parentesto
function listTipoParentesco(idTipoGrauParentesco, idTipoParentesco) {
	vTipoParentesco = document.getElementById("idTipoParentesco");
	var fillTipoParentesco = function(list) {
		fillList("idTipoParentesco", "id", "nome", idTipoParentesco, list);
			
		if(vTipoParentesco.length <= 2 && vTipoParentesco.length != 0){
			vTipoParentesco.options[1].selected = true;		
		}		
	}

	cadastroAjax.listTipoParentesco(idTipoGrauParentesco, fillTipoParentesco);
}


var fnStack = new Array();
window.onDomReady = DomReady;
function DomReady(fn) {
	fnStack.push(fn);
	if (fnStack.length == 1) {
		if (document.addEventListener) {
			document.addEventListener("DOMContentLoaded", fnProxy, false);
		} else {
			document.onreadystatechange = function() {
				readyState(fnProxy);
			};
		}
	}
}

function fnProxy() {
	while (fnStack.length > 0) {
		fn = fnStack.pop();
		fn();
	}
}

function readyState(fn) {
	if (document.readyState == "complete") {
		fn();
	}
}

function getDateFromString(valor) {
	if (valor != "" && valor.length >= 10) {
		var dia = parseInt(valor.substring(0, 2), 10);
		var mes = parseInt(valor.substring(3, 5), 10) - 1;
		var ano = parseInt(valor.substring(6, 10), 10);
		if (dia < 1 || dia > 31 || mes < 0 || mes > 11 || ano < 1900
				|| ano > 2100) {
			return null;
		}
		var isBissexto = ((0 == ano % 4) && (0 != (ano % 100)))
				|| (0 == ano % 400);
		if (mes == 1 && ((isBissexto && dia > 29) || (!isBissexto && dia > 28))) {
			return null;
		}
		return new Date(ano, mes, dia);
	}
	return null;
}
function getStringFromDate(valor) {
	if (valor != null) {
		var dia = (valor.getDate() < 10 ? "0" : "") + valor.getDate();
		var mes = ((valor.getMonth() + 1) < 10 ? "0" : "")
				+ (valor.getMonth() + 1);
		var ano = valor.getYear();
		return dia + "/" + mes + "/" + ano;
	}
	return null;
}
function getStringDateTimeFromDate(valor) {
	if (valor != null) {
		var data = getStringFromDate(valor);
		return data + " " + valor.getHours() + ":"
				+ (valor.getMinutes() < 10 ? "0" : "") + valor.getMinutes();
	}
	return null;
}
function validarData(url) {
	objDataInicio = document.getElementById("dataInicio");
	objDataFim = document.getElementById("dataFim");

	// Validações
	var objDataInicioDate = getDateFromString(objDataInicio.value);
	var objDataFimDate = getDateFromString(objDataFim.value);
	if (objDataInicioDate == null) {
		alert("Data Inicio \xe9 obrigat\xf3rio");
		return null;
	}
	if (objDataInicioDate != null && objDataFimDate != null) {
		if (objDataInicioDate.getTime() > objDataFimDate.getTime()) {
			alert("A Data Inicio n\xe3o pode ser maior que a Data Fim.");
			objCheckIn.focus();
			return false;
		}
	}
	enviarForm(url);
}
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g, "");
};
function toUpperCase(obj) {
	obj.value = obj.value.toUpperCase();
}
var fieldRepository = new Array();
function disabelFields(form) {
	var elements = form.elements;
	for (j = 1; j < arguments.length; j++) {
		if (elements[arguments[j]] != null) {
			elements[arguments[j]].disabled = "true";
		} else {
			fieldRepository[arguments[j]] = document
					.getElementById(arguments[j]).onclick;
			document.getElementById(arguments[j]).onclick = "";
		}
	}
}
function enableFields(form) {
	var elements = form.elements;
	for (j = 1; j < arguments.length; j++) {
		if (elements[arguments[j]] != null) {
			elements[arguments[j]].disabled = "";
		} else if (fieldRepository[arguments[j]]) {
			document.getElementById(arguments[j]).onclick = fieldRepository[arguments[j]];
		}
	}
}
function isNumberKey(event) {
	var charCode = (event.which) ? event.which : event.keyCode;
	if ((charCode != 37 && charCode != 46)
			&& (charCode > 31 && (charCode < 48 || charCode > 57))) {
		return false;
	}
	return true;
}
function appendEmptyOption(id) {
	var sel = document.getElementById(id);
	var opt = document.createElement("option");
	sel.appendChild(opt);
}
function keyValidation(e) {
	return (e == null || (e.keyCode == 8 || e.keyCode == 32 || e.keyCode == 46 || e.keyCode >= 48)
			&& !(e.keyCode > 90 && e.keyCode < 94)
			&& !(e.keyCode > 112 && e.keyCode < 127)
			&& !(e.keyCode > 144 && e.keyCode < 146));
}
function showEscolhaOperadora(idSistema, idModulo, idDominio) {
	if (idSistema && idModulo && idDominio) {
		displayMessage("seguranca-popinSaveEscolhaDominio.action?idSistema="
				+ idSistema + "&idModulo=" + idModulo + "&idDominio="
				+ idDominio, 350, 180);
	} else if (idSistema && idModulo) {
		displayMessage("seguranca-popinListEscolhaDominio.action?idSistema="
				+ idSistema + "&idModulo=" + idModulo, 350, 180);
	} else if (idSistema) {
		displayMessage("seguranca-popinListEscolhaDominio.action?idSistema="
				+ idSistema, 350, 180);
	} else {
		displayMessage("seguranca-popinListEscolhaDominio.action", 350, 180);
	}
}

function SoLetra(event) {
	if (!((event.keyCode >= 65 && event.keyCode <= 90)
			|| (event.keyCode >= 97 && event.keyCode <= 122)
			|| (event.keyCode >= 128 && event.keyCode <= 151)
			|| (event.keyCode >= 153 && event.keyCode <= 154) || (event.keyCode >= 161 && event.keyCode <= 165))) {
		event.keyCode = 0;
	}
}
function closePopin() {
	closeMessage();
}
function showHint(divName, strValue) {
	var div = document.getElementById(divName);
	div.innerHTML = strValue;
	div.style.visibility = "visible";
}
function showHint2(divName, strValue) {
	var div = document.getElementById(divName);
	div.innerHTML = strValue + " (...)";
	div.style.visibility = "visible";
}
function closeHint(divName) {
	document.getElementById(divName).style.visibility = "hidden";
}
function setFocusById(id) {
	document.getElementById(id).focus();
}
function setFocusByName(id, idx) {
	document.getElementsByName(id)[idx].focus();
}
function formataMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e,
		Tamanho) {
	var sep = 0;
	var key = "";
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = "0123456789";
	var aux = aux2 = "";
	var whichCode = (window.Event) ? e.which : e.keyCode;
	// 13=enter, 8=backspace as demais retornam 0(zero)
	// whichCode==0 faz com que seja possivel usar todas as teclas como delete,
	// setas, etc
	if (objTextBox.value.length >= Tamanho) {
		whichCode = 1;
	}
	if ((whichCode == 13) || (whichCode == 0) || (whichCode == 8)) {
		return true;
	}
	key = String.fromCharCode(whichCode); // Valor para o código da Chave
	if (strCheck.indexOf(key) == -1) {
		return false;
	} // Chave inválida
	len = objTextBox.value.length;
	for (i = 0; i < len; i++) {
		if ((objTextBox.value.charAt(i) != "0")
				&& (objTextBox.value.charAt(i) != SeparadorDecimal)) {
			break;
		}
	}
	aux = "";
	for (; i < len; i++) {
		if (strCheck.indexOf(objTextBox.value.charAt(i)) != -1) {
			aux += objTextBox.value.charAt(i);
		}
	}
	aux += key;
	len = aux.length;
	if (len == 0) {
		objTextBox.value = "";
	}
	if (len == 1) {
		objTextBox.value = "0" + SeparadorDecimal + "0" + aux;
	}
	if (len == 2) {
		objTextBox.value = "0" + SeparadorDecimal + aux;
	}
	if (len > 2) {
		aux2 = "";
		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += SeparadorMilesimo;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		objTextBox.value = "";
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--) {
			objTextBox.value += aux2.charAt(i);
		}
		objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
	}
	return false;
}

// Função que move options de um combo para outro
function move(fbox, tbox) {
	var arrFbox = new Array();
	var arrTbox = new Array();
	var arrLookup = new Array();
	var i;
	for (i = 0; i < tbox.options.length; i++) {
		arrLookup[tbox.options[i].text] = tbox.options[i].value;
		arrTbox[i] = tbox.options[i].text;
	}
	var fLength = 0;
	var tLength = arrTbox.length;
	for (i = 0; i < fbox.options.length; i++) {
		arrLookup[fbox.options[i].text] = fbox.options[i].value;
		if (fbox.options[i].selected && fbox.options[i].value != "") {
			arrTbox[tLength] = fbox.options[i].text;
			tLength++;
		} else {
			arrFbox[fLength] = fbox.options[i].text;
			fLength++;
		}
	}
	arrFbox.sort();
	arrTbox.sort();
	fbox.length = 0;
	tbox.length = 0;
	var c;
	for (c = 0; c < arrFbox.length; c++) {
		var no = new Option();
		no.value = arrLookup[arrFbox[c]];
		no.text = arrFbox[c];
		fbox[c] = no;
	}
	for (c = 0; c < arrTbox.length; c++) {
		var no = new Option();
		no.value = arrLookup[arrTbox[c]];
		no.text = arrTbox[c];
		tbox[c] = no; 
	}
}

// Mover todos os itens de um combo para outro
function moveAll(fbox, tbox, selectAll) {
	if (typeof fbox == "string") {
		fbox = document.getElementById(fbox);
	}
	if (fbox.type == "select-multiple") {
		for ( var i = 0; i < fbox.options.length; i++) {
			fbox.options[i].selected = selectAll;
		}
	}

	move(fbox, tbox);
}

function confirma() {
	return confirm('Confirma a exclus\u00E3o?');
}

function getMousePosition(e) {
	e = e || window.event;
	var cursor = {
		x :0,
		y :0
	};
	if (e.pageX || e.pageY) {
		cursor.x = e.pageX;
		cursor.y = e.pageY;
	} else {
		var de = document.documentElement;
		var b = document.body;
		cursor.x = e.clientX + (de.scrollLeft || b.scrollLeft)
				- (de.clientLeft || 0);
		cursor.y = e.clientY + (de.scrollTop || b.scrollTop)
				- (de.clientTop || 0);
	}
	return cursor;
}

function getObjectPosition(obj) {
	var cursor = {
		x :0,
		y :0
	};
	if (obj.offsetParent) {
		cursor.x = obj.offsetLeft + obj.offsetWidth;
		cursor.y = obj.offsetTop - 7;
		while (obj = obj.offsetParent) {
			cursor.x += obj.offsetLeft;
			cursor.y += obj.offsetTop;
		}
	}
	return cursor;
}

function getObjectAbsolutePosition(obj) {
	var cursor = {
		x :0,
		y :0
	};
	if (obj.offsetParent) {
		cursor.x = obj.offsetLeft;
		cursor.y = obj.offsetTop;
		while (obj = obj.offsetParent) {
			cursor.x += obj.offsetLeft;
			cursor.y += obj.offsetTop;
		}
	}
	return cursor;
}




function getArray(objs, arr) {
	if (!arr) {
		arr = new Array();
	}

	for (i = 0; i < objs.length; i++) {
		if (objs[i].type == "checkbox" && objs[i].checked) {
			arr.push(objs[i].value);
		}
	}
	return arr;
}
var exportPaginatorName;
function showExportFile(paginatorName) {
	exportPaginatorName = paginatorName;
	displayMessage("foundation-exportRedirect.action", 300, 150);
}

function exportFile() {
	var type = null;
	var typeObj = document.getElementsByName("exportType");
	for (i = 0; i < typeObj.length; i++) {
		if (typeObj[i].checked) {
			type = typeObj[i].value;
			break;
		}
	}
	if (type) {
		window.location = 'export.serv?paginatorName=' + exportPaginatorName + '&type=' + type;
		closeMessage();
	}
}

function removeChildNodes(obj) {
	while(obj.hasChildNodes()){
		obj.removeChild(obj.lastChild);
	}
}

function showEventoOperadora() {
	displayMessage("procedimento-popinListEventoOperadora.action", 800, 400);
}





var arrayHasObject = function (arr, o) {
    var l = arr.length + 1;

    while (l -= 1) {
        if (arr[l - 1] === o) {
            return true;
        }
    }

    return false;
};

function showObservacao(field){
	displayStaticMessage("Observa&ccedil;&atilde;o", '<textarea name="' + field + 'Tmp" id="' + field + 'Tmp" cols="120" rows="15">' + $('#' + field).val() + '</textarea>', getButton("Fechar",'closeMessage()') + getButton("OK", "setObservacao('" + field + "')"), 525, 283);
}

function setObservacao(field) {
	$('#' + field).val($('#' + field + 'Tmp').val());
	closeMessage();
}

function redirect(url) {
	window.location = url;
}
