// As seguintes funções podem e devem ser usadas para qualquer aplicação:

function setHeight(alvo,frm,temp)
{
	try{	
		var oFrame	=	document.all(alvo);
		var oBody	=	frm.document.body;
		
		oFrame.style.height = oBody.scrollHeight;
	}
	catch(e) {
		alert('Erro: ' + e.number + ': ' + e.description);
		oFrame.style.height = temp;
	}
}

// #######################################################3

var changeFlag = true;

function clickIt(src,formulario,srcDiv,frameId) {
	if (src.style.backgroundColor == '') {
		showLLayer(src,srcDiv);
		if (formulario != null)
			formulario.submit();
	} else {
		hideLLayer(src,srcDiv);
		frameId.document.location = 'Null.do';
	}
}

function showLLayer(src,srcDiv) {
	var screenSize;
	src.style.backgroundColor = '#D4DAE3';
	if (navigator.userAgent.indexOf("MSIE") > 0) {
		screenSize = document.body.clientWidth;
	} else {                                                
		screenSize = window.outerWidth;
	}
	srcDiv.style.left = (screenSize / 2) + 103;
	srcDiv.style.top = 95;
	srcDiv.style.visibility = 'visible';
	srcDiv.style.display = 'block';
}

function hideLLayer(src,srcDiv) {
	src.style.backgroundColor = '';
	srcDiv.style.visibility = 'hidden';
	srcDiv.style.display = 'none';
}

// #######################################################3

function replaceImg(imagem,arquivo) {
	imagem.src = arquivo;
}

function fillIt(srcField,srcLength,srcString) {
	if (srcField.value.length == srcLength)
		srcField.value = srcField.value + srcString;
}

function toUpper(srcField) {
	srcField.value = srcField.value.toUpperCase();	
}

function openWindow(url,name,width,height,top,left,more) {
	window.open(url, name, 'height=' + height + ',width=' + width + ',top=' + top + ',left=' + left + more);
}

function expandIt(srcTr) {
	if (srcTr.style.display == "")
		srcTr.style.display = "none";
	else
		srcTr.style.display = "";
}

function changeMidia(src) {
	if (src.value == "2")
		trAdaptacao.style.display = "none";
	else
		trAdaptacao.style.display = "";
}

// As seguintes função são específicas desta aplicação:

function showBevel(src0, src1, src2) {
	src0.style.display = '';
	src1.style.display = 'none';
	src2.style.display = 'none';
}

function tipoServico(src) {
	if (src == 0) {
		aGeral.style.fontWeight = 'bold';
		aTelefones.style.fontWeight = '';
		aAdicionais.style.fontWeight = '';

		divGeral.style.display = '';
		divTelefones.style.display = 'none';
		divAdicionais.style.display = 'none';
	}
	if (src == 1) {
		aGeral.style.fontWeight = '';
		aTelefones.style.fontWeight = 'bold';
		aAdicionais.style.fontWeight = '';

		divGeral.style.display = 'none';
		divTelefones.style.display = '';
		divAdicionais.style.display = 'none';
	}
	if (src == 2) {
		aGeral.style.fontWeight = '';
		aTelefones.style.fontWeight = '';
		aAdicionais.style.fontWeight = 'bold';

		divGeral.style.display = 'none';
		divTelefones.style.display = 'none';
		divAdicionais.style.display = '';
	}
}

function perfil(strEstab,strCodigo) {
	window.open('PessoalTrazerEspecifico.do?method=trazerEspecifico&estabelecimentoCodigo=' + strEstab + '&codigo=' + strCodigo,'perfil','scrollbars,height=390,width=350,top=30,left=30');
}

function torpedo(strEstab,strCodigo,strNome) {
	window.open('TorpedoInserir.do?method=auxiliar&contatoNome=' + strNome + '&estabelecimentoCodigo=' + strEstab + '&codigo=' + strCodigo,'torpedo','height=290,width=350,top=30,left=30');
}

function envio(strEstab,strCodigo,strNome) {
	window.open('Envio.do?nome=' + strNome + '&estabelecimentoCodigo=' + strEstab + '&codigo=' + strCodigo,'envio','height=390,width=350,top=30,left=30');
}

function contatos(strEstab,strCodigo) {
	var globalScreenSize;
	if (navigator.userAgent.indexOf("MSIE") > 0) {
		globalScreenSize = document.body.clientWidth;
	} else {                                                
		globalScreenSize = window.outerWidth;
	}
	window.open('ContatosPopupInserirSubmit.do?method=inserir&estabelecimentoCodigo=' + strEstab + '&codigo=' + strCodigo,'contato','height=20,width=200,top=30,left=' + (globalScreenSize/2 - 100));
}

function contato() {
	window.open('Contato.do?','contato','height=390,width=350,top=10,left=10');
}

var testBuscaLayer = 0;
var testTexto = 0;
var buscaLocation;
var reduzidoFlag = false;

function showHideLayer(id,tipo) {
	if (testBuscaLayer == 0) {
		ShowLayer(id,tipo);
	} else {
		HideLayer(id);
	}
}

function HideLayer(id) {
	if (testBuscaLayer == 1) {
		id.style.visibility = 'hidden';
		id.style.display = 'none';
		testBuscaLayer = 0;
		buscaForm.buscaDropdown.src = 'pages/images/icons/buscaDropdown.gif';
	}
}

function ShowLayer(id,tipo) {
	var screenSize;
	if (testBuscaLayer == 0) {
		if (navigator.userAgent.indexOf("MSIE") > 0) {
			screenSize = document.body.clientWidth;
			//screen.width
		} else {                                                
			screenSize = window.outerWidth;
		}
		id.style.visibility = 'visible';
		id.style.display = 'block';
		if (tipo == 1) {
			id.style.left = (screenSize / 2) + 163;
			id.style.top = 157;
			reduzidoFlag = false;
		} else {
			id.style.left = (screenSize / 2) + 40;
			id.style.top = 111;
			reduzidoFlag = true;
		}
		testBuscaLayer = 1;
		buscaForm.buscaDropdown.src = 'pages/images/icons/buscaDropdownX.gif';
	}
}

function configurarBusca(formId, formAction, strParam, strOnde) {
	buscaLocation = 'Acesso.do?method=dispatch&target=';

	if (formAction == 1) {
		buscaLocation = buscaLocation + 'uol/bc_recebe_texto_consulta?p_nr_sessao=' + sessao + '&p_tp_ambiente=4&p_tp_chamada=1&p_tp_apresentacao=5&p_base=' + strParam + '&p_busca=A&p_ds_texto=';
	}
	if (formAction == 2) {
		buscaLocation = buscaLocation + 'conteudo/w_uol_documento.p_monta_consulta_tc?p_nr_sessao=' + sessao + '&p_tp_ambiente=4&p_tp_chamada=1&p_tp_apresentacao=5&p_imp_cab_rod=N&p_nr_pagina=1&p_direcao_busca=N&p_nova_busca=S&p_tp_conteudo=' + strParam + '&p_ds_buscar=';
	}
	if (formAction == 3) {
		buscaLocation = buscaLocation + 'uol/w_uol_ramais_nome?p_nr_sessao=' + sessao + '&p_tp_ambiente=4&p_tp_chamada=1&p_tp_apresentacao=5&p_nm_pesquisa=';
	}
	if (formAction == 4) {
		buscaLocation = buscaLocation + 'uol/w_uol_ramais_setor?p_nr_sessao=' + sessao + '&p_tp_ambiente=4&p_tp_chamada=1&p_tp_apresentacao=5&p_nm_pesquisa=';
	}
	if (!reduzidoFlag) {
		formId.onde.value = strOnde;
	} else {
		formId.buscaDropdown.alt = strOnde;
	}
}

function buscar(formId) {
	buscaLocation = buscaLocation + formId.buscaTexto.value;
	document.location = buscaLocation;
}


function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit)
		field.value = field.value.substring(0, maxlimit);
	else 
		countfield.value = maxlimit - field.value.length;
}
