var XMLReq = createXMLReq(); // variavel para request
// acoes do Ajax
var AJAX_NAVEGA = 1;
var AJAX_CONSULTA = 2;
var AJAX_FORM = 4;
var AJAX_TEXT = 8;
var AJAX_XML = 16;
var jsAcao = 0;
// campos da matriz parser.
var PSR_STATUS = 0;
var PSR_CAMPOS = 1;
var PSR_NOME = 0;
var PSR_VALOR = 1;
// para o tipo de resposta esperada do servidor
var RS_XML = 1;
var RS_TEXT = 2;
var jsTipoResposta = 0;
var DELIMITADOR = '|';
/*
* exibe mensagens de erro. Devera ser melhorada.
*/
function Erro(eMsg)
{
alert(eMsg);
} // Erro
/*
* Funcao de callback para envio de link
*/
function CallbackLink()
{
if (XMLReq.readyState == 4)
{
if (XMLReq.status == 200)
{
if (!Parser2Matriz(XMLReq))
{
Erro('Erro em Ajax. Mande email para pericles.luz@gmail.com');
return false;
}
}
else
{
Erro('Retorno desconhecido!');
return false;
}
return true;
}
} // CallbackLink
/*
* cria XMLHttpRequest e atribui a XMLReq
*/
function createXMLReq()
{
var XMLReq = false;
try
{
XMLReq = new XMLHttpRequest();
if (http_request.overrideMimeType)
{
http_request.overrideMimeType('text/xml');
}
}
catch(e)
{
var aryXmlHttp = new Array(
"MSXML2.XMLHTTP",
"Microsoft.XMLHTTP",
"MSXML2.XMLHTTP.6.0",
"MSXML2.XMLHTTP.5.0",
"MSXML2.XMLHTTP.4.0",
"MSXML2.XMLHTTP.3.0"
);
for (var i = 0; i < aryXmlHttp.length && !XMLReq; i++)
{
try
{
XMLReq = new ActiveXObject(aryXmlHttp[i]);
}
catch(e){Erro('createXMLReq: XMLReq Error');}
}
}
if (!XMLReq)
{
Erro('Erro: Falha ao criar XMLHttpRequest.');
}
else
{
return XMLReq;
}
} // createXMLReq
/*
* envia LinkDados via GET. Funcao sera usada para mandar LinkDados de links
* mgTipo determina o Tipo de remessa.
* mgTipo = 1, para remessa a partir de links de navegacao
* mgTipo = 2, para remessa a partir das combos de contas do modulo Lancamento Contabil
* usado para buscar o historico padrao dos lancamentos
*/
function MandaGet(LinkDados, mgTipo, mgPost)
{
if (!XMLReq) return true; // nao inicializado
try
{
if (window.ActiveXObject) //IE
{
// se for XML, passa pra Text
if (mgTipo & AJAX_XML)
{
mgTipo = (mgTipo ^ AJAX_XML) | AJAX_TEXT;
}
jsTipoResposta = RS_TEXT;
}
else // FF
{
if ((mgTipo & AJAX_XML))
{
jsTipoResposta = RS_XML;
}
else if ((mgTipo & AJAX_TEXT))
{
jsTipoResposta = RS_TEXT;
}
else
{
jsTipoResposta = 0;
}
}
LinkDados += '&CPAjax=' + mgTipo;
XMLReq.open("POST", LinkDados, true);
XMLReq.onreadystatechange = CallbackLink;
XMLReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
XMLReq.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
var objDiv = document.getElementById('Lendo');
objDiv.innerHTML = '
';
}
catch(e)
{
Erro('MandaGet: Erro preparando link: ' + LinkDados);
return true; // usa link normal
}
try
{
XMLReq.send(mgPost);
}
catch(e)
{
Erro('MandaGet: XMLReq.onreadystatechange - Erro enviando dados');
return true; // usa link normal
}
return false; // nao usa link normal - usou ajax
} // MandaGet
/*
* Trata dados XML e os coloca na matriz jsDados
*/
function XML2Matriz(xmDados, xmResposta)
{
try
{
// busca status
var xmNome = xmResposta.getElementsByTagName('Status')[0].firstChild.nodeValue;
var xmValor = xmResposta.getElementsByTagName('Mensagem')[0].firstChild.nodeValue;
xmDados.push([xmNome, xmValor]);
// busca campos
var xmCampos = new Array();
var xmCampo = xmResposta.getElementsByTagName('campo');
for (var i = 0; i < xmCampo.length; i++)
{
xmCampoTemp = xmCampo[i];
xmNome = xmCampoTemp.getElementsByTagName('Nome')[0].firstChild.nodeValue;
xmValor = xmCampoTemp.getElementsByTagName('Valor')[0].firstChild.nodeValue;
xmCampos.push([xmNome, xmValor]);
}
xmDados.push(xmCampos);
return TrataExibicao(xmDados);
}
catch(e)
{
Erro('Erro XML2Matriz: ' + xmResposta);
return false;
}
} // XML2Matriz
/*
* auxilia Text2Matriz, buscando o proximo item(nome ou valor)
*/
function BuscaProximo(bpTexto, bpTipo)
{
try
{
var bpNome = '';
var bpValor = '';
var bpX = 0;
var bpRetorno = new Array();
if (bpTipo == PSR_STATUS)
{
if (bpTexto.charAt(bpX) == DELIMITADOR) bpX++;
while ((bpTexto.charAt(bpX) != DELIMITADOR) && (bpX < bpTexto.length))
{
bpNome += bpTexto.charAt(bpX);
bpX++;
}
bpX++;
while ((bpTexto.charAt(bpX) != DELIMITADOR) && (bpX < bpTexto.length))
{
bpValor += bpTexto.charAt(bpX);
bpX++;
}
bpRetorno.push(bpNome, bpValor);
}
else if (bpTipo == PSR_CAMPOS)
{
var bpLendo = 0; // nao le nada
while (bpX < (bpTexto.length - 1))
{
if ((bpTexto.charAt(bpX) == DELIMITADOR) && (bpTexto.charAt(bpX + 1) == DELIMITADOR) && (bpLendo == 0))
{
bpLendo = 1; // le nome do campo
bpX += 2;
}
if ((bpLendo == 1) || (bpLendo == 2))
{
if ((bpTexto.charAt(bpX) == DELIMITADOR) || (bpX >= (bpTexto.length - 1)))
{
if (bpLendo == 1)
{
bpLendo = 2;
bpX++;
continue;
}
else if (bpLendo == 2)
{
bpRetorno.push([bpNome, bpValor]);
bpNome = '';
bpValor = '';
bpLendo = 0;
continue;
}
}
if (bpLendo == 1)
{
bpNome += bpTexto.charAt(bpX);
}
else if (bpLendo == 2)
{
bpValor += bpTexto.charAt(bpX);
}
}
bpX++;
} // while
if (bpNome != '') bpRetorno.push([bpNome, bpValor]);
}
}
catch (e)
{
Erro('BuscaProximo: Erro buscando delimitador' + bpTexto);
}
return bpRetorno;
} // BuscaProximo
/*
* Trata dados Text e os coloca na matriz jsDados
*/
function Text2Matriz(tmDados, tmResposta)
{
try
{
// busca status
tmDados.push(BuscaProximo(tmResposta, PSR_STATUS));
// busca campos
tmDados.push(BuscaProximo(tmResposta, PSR_CAMPOS));
return TrataExibicao(tmDados);
}
catch(e)
{
Erro('Erro Text2Matriz: ' + tmResposta);
return false;
}
}
/*
* Trata dados retornados e os coloca na matriz jsDados
*/
function Parser2Matriz(pmXMLReq)
{
try
{
pmDados = new Array();
if (jsTipoResposta == RS_TEXT)
{
var pmResposta = pmXMLReq.responseText;
Text2Matriz(pmDados, pmResposta);
}
else if (jsTipoResposta == RS_XML)
{
var pmResposta = pmXMLReq.responseXML;
XML2Matriz(pmDados, pmResposta);
}
return true;
}
catch(e)
{
Erro('Erro Parser2Matriz: ' + pmResposta);
return false;
}
}
/*
* Trata dados retornados para serem exibidos
*/
function TrataExibicao(teDados)
{
try
{
var objDiv = document.getElementById('Lendo');
teStatus = teDados[PSR_STATUS][PSR_NOME];
teMensagem = teDados[PSR_STATUS][PSR_VALOR];
if (teStatus == '0')
{
objDiv.innerHTML = teMensagem;
Erro('Erro: ' + teMensagem);
return true;
}
else if (teStatus == '1')
{
objDiv.innerHTML = teMensagem;
}
else if (teStatus == '2')
{
objDiv.innerHTML = teMensagem;
return true;
}
// historico padrao do contabil
else if (teStatus == '3')
{
grHP = teMensagem;
objDiv.innerHTML = '';
GeraHistorico('1');
}
// insercao
else if (teStatus == '4')
{
objDiv.innerHTML = teMensagem;
ZeraForm('Dados');
return true;
}
else
{
Erro('Status indefinidos: ' + teStatus);
objDiv.innerHTML = '';
}
for (var i = 0; i < teDados[PSR_CAMPOS].length; i++)
{
teDestino = document.getElementById(teDados[PSR_CAMPOS][i][PSR_NOME]);
if (teStatus == '4')
{
teDestino.value = teDados[PSR_CAMPOS][i][PSR_VALOR];
}
else
{
teDestino.innerHTML = teDados[PSR_CAMPOS][i][PSR_VALOR];
}
}
return true;
}
catch(e)
{
Erro("Erro TrataExibicao: " + teDados);
return false;
}
}
/*
01: var HttpReq = null;
02: var dest_combo = null;
03:
04: function ajaxComboBox(url, comboBox){
05: dest_combo = comboBox;
06: var indice = document.getElementById('estados').selectedIndex;
07: var sigla = document.getElementById('estados').options[indice].getAttribute('value');
08: url = url + '?uf=' + sigla;
09: if (document.getElementById) { //Verifica se o Browser suporta DHTML.
10: if (window.XMLHttpRequest) {
11: HttpReq = new XMLHttpRequest();
12: HttpReq.onreadystatechange = XMLHttpRequestChange;
13: HttpReq.open("GET", url, true);
14: HttpReq.send(null);
15: } else if (window.ActiveXObject) {
16: HttpReq = new ActiveXObject("Microsoft.XMLHTTP");
17: if (HttpReq) {
18: HttpReq.onreadystatechange = XMLHttpRequestChange;
19: HttpReq.open("GET", url, true);
20: HttpReq.send();
21: }
22: }
23: }
24: }
25:
26: function XMLHttpRequestChange() {
27: if (HttpReq.readyState == 4 && HttpReq.status == 200){
28: var result = HttpReq.responseXML;
29: var cidades = result.getElementsByTagName("nome");
30: document.getElementById('dest_combo').innerHTML = "";
31: for (var i = 0; i < cidades.length; i++) {
32: new_opcao = create_opcao(cidades[i]);
33: document.getElementById('dest_combo').appendChild(new_opcao);
34: }
35: }
36: }
37:
38: function create_opcao(cidade) {
39: var new_opcao = document.createElement("option");
40: var texto = document.createTextNode(cidade.childNodes[0].data);
41: new_opcao.setAttribute("value",cidade.getAttribute("id"));
42: new_opcao.appendChild(texto); //Adiciona o texto a OPTION.
43: return new_opcao; // Retorna a nova OPTION.
44: }*/
//
// openWYSIWYG v1.01 Copyright (c) 2006 openWebWare.com
// This copyright notice MUST stay intact for use.
//
// An open source WYSIWYG editor for use in web based applications.
// For full source code and docs, visit http://www.openwebware.com/
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
// License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along
// with this library; if not, write to the Free Software Foundation, Inc., 59
// Temple Place, Suite 330, Boston, MA 02111-1307 USA
/* ---------------------------------------------------------------------- *\
Global Variables: Set global variables such as images directory,
WYSIWYG Height, Width, and CSS Directory.
\* ---------------------------------------------------------------------- */
// Images Directory
imagesDir = "icons/";
// CSS Directory
cssDir = "styles/";
// Popups Directory
popupsDir = "popups/";
// WYSIWYG Width and Height
wysiwygWidth = 500;
wysiwygHeight = 150;
// Include Style Sheet
document.write('\n');
/* ---------------------------------------------------------------------- *\
Toolbar Settings: Set the features and buttons available in the WYSIWYG
Toolbar.
\* ---------------------------------------------------------------------- */
// List of available font types
var Fonts = new Array();
Fonts[0] = "Arial";
Fonts[1] = "Sans Serif";
Fonts[2] = "Tahoma";
Fonts[3] = "Verdana";
Fonts[4] = "Courier New";
Fonts[5] = "Georgia";
Fonts[6] = "Times New Roman";
Fonts[7] = "Impact";
Fonts[8] = "Comic Sans MS";
// List of available block formats (not in use)
var BlockFormats = new Array();
BlockFormats[0] = "Address";
BlockFormats[1] = "Bulleted List";
BlockFormats[2] = "Definition";
BlockFormats[3] = "Definition Term";
BlockFormats[4] = "Directory List";
BlockFormats[5] = "Formatted";
BlockFormats[6] = "Heading 1";
BlockFormats[7] = "Heading 2";
BlockFormats[8] = "Heading 3";
BlockFormats[9] = "Heading 4";
BlockFormats[10] = "Heading 5";
BlockFormats[11] = "Heading 6";
BlockFormats[12] = "Menu List";
BlockFormats[13] = "Normal";
BlockFormats[14] = "Numbered List";
// List of available font sizes
var FontSizes = new Array();
FontSizes[0] = "1";
FontSizes[1] = "2";
FontSizes[2] = "3";
FontSizes[3] = "4";
FontSizes[4] = "5";
FontSizes[5] = "6";
FontSizes[6] = "7";
// Order of available commands in toolbar one
var buttonName = new Array();
buttonName[0] = "bold";
buttonName[1] = "italic";
buttonName[2] = "underline";
//buttonName[3] = "strikethrough";
buttonName[4] = "seperator";
buttonName[5] = "subscript";
buttonName[6] = "superscript";
buttonName[7] = "seperator";
buttonName[8] = "justifyleft";
buttonName[9] = "justifycenter";
buttonName[10] = "justifyright";
buttonName[11] = "seperator";
buttonName[12] = "unorderedlist";
buttonName[13] = "orderedlist";
buttonName[14] = "outdent";
buttonName[15] = "indent";
// Order of available commands in toolbar two
var buttonName2 = new Array();
buttonName2[0] = "forecolor";
buttonName2[1] = "backcolor";
buttonName2[2] = "seperator";
buttonName2[3] = "cut";
buttonName2[4] = "copy";
buttonName2[5] = "paste";
buttonName2[6] = "seperator";
buttonName2[7] = "undo";
buttonName2[8] = "redo";
buttonName2[9] = "seperator";
buttonName2[10] = "inserttable";
buttonName2[11] = "insertimage";
buttonName2[12] = "createlink";
buttonName2[13] = "seperator";
buttonName2[14] = "viewSource";
buttonName2[15] = "seperator";
buttonName2[16] = "help";
// List of available actions and their respective ID and images
var ToolbarList = {
//Name buttonID buttonTitle buttonImage buttonImageRollover
"bold": ['Bold', 'Bold', imagesDir + 'bold.gif', imagesDir + 'bold_on.gif'],
"italic": ['Italic', 'Italic', imagesDir + 'italics.gif', imagesDir + 'italics_on.gif'],
"underline": ['Underline', 'Underline', imagesDir + 'underline.gif', imagesDir + 'underline_on.gif'],
"strikethrough": ['Strikethrough', 'Strikethrough', imagesDir + 'strikethrough.gif', imagesDir + 'strikethrough_on.gif'],
"seperator": ['', '', imagesDir + 'seperator.gif', imagesDir + 'seperator.gif'],
"subscript": ['Subscript', 'Subscript', imagesDir + 'subscript.gif', imagesDir + 'subscript_on.gif'],
"superscript": ['Superscript', 'Superscript', imagesDir + 'superscript.gif', imagesDir + 'superscript_on.gif'],
"justifyleft": ['Justifyleft', 'Justifyleft', imagesDir + 'justify_left.gif', imagesDir + 'justify_left_on.gif'],
"justifycenter": ['Justifycenter', 'Justifycenter', imagesDir + 'justify_center.gif', imagesDir + 'justify_center_on.gif'],
"justifyright": ['Justifyright', 'Justifyright', imagesDir + 'justify_right.gif', imagesDir + 'justify_right_on.gif'],
"unorderedlist": ['InsertUnorderedList', 'InsertUnorderedList',imagesDir + 'list_unordered.gif', imagesDir + 'list_unordered_on.gif'],
"orderedlist": ['InsertOrderedList', 'InsertOrderedList', imagesDir + 'list_ordered.gif', imagesDir + 'list_ordered_on.gif'],
"outdent": ['Outdent', 'Outdent', imagesDir + 'indent_left.gif', imagesDir + 'indent_left_on.gif'],
"indent": ['Indent', 'Indent', imagesDir + 'indent_right.gif', imagesDir + 'indent_right_on.gif'],
"cut": ['Cut', 'Cut', imagesDir + 'cut.gif', imagesDir + 'cut_on.gif'],
"copy": ['Copy', 'Copy', imagesDir + 'copy.gif', imagesDir + 'copy_on.gif'],
"paste": ['Paste', 'Paste', imagesDir + 'paste.gif', imagesDir + 'paste_on.gif'],
"forecolor": ['ForeColor', 'ForeColor', imagesDir + 'forecolor.gif', imagesDir + 'forecolor_on.gif'],
"backcolor": ['BackColor', 'BackColor', imagesDir + 'backcolor.gif', imagesDir + 'backcolor_on.gif'],
"undo": ['Undo', 'Undo', imagesDir + 'undo.gif', imagesDir + 'undo_on.gif'],
"redo": ['Redo', 'Redo', imagesDir + 'redo.gif', imagesDir + 'redo_on.gif'],
"inserttable": ['InsertTable', 'InsertTable', imagesDir + 'insert_table.gif', imagesDir + 'insert_table_on.gif'],
"insertimage": ['InsertImage', 'InsertImage', imagesDir + 'insert_picture.gif', imagesDir + 'insert_picture_on.gif'],
"createlink": ['CreateLink', 'CreateLink', imagesDir + 'insert_hyperlink.gif', imagesDir + 'insert_hyperlink_on.gif'],
"viewSource": ['ViewSource', 'ViewSource', imagesDir + 'view_source.gif', imagesDir + 'view_source_on.gif'],
"viewText": ['ViewText', 'ViewText', imagesDir + 'view_text.gif', imagesDir + 'view_text_on.gif'],
"help": ['Help', 'Help', imagesDir + 'help.gif', imagesDir + 'help_on.gif'],
"selectfont": ['SelectFont', 'SelectFont', imagesDir + 'select_font.gif', imagesDir + 'select_font_on.gif'],
"selectsize": ['SelectSize', 'SelectSize', imagesDir + 'select_size.gif', imagesDir + 'select_size_on.gif']
};
/* ---------------------------------------------------------------------- *\
Function : insertAdjacentHTML(), insertAdjacentText() and insertAdjacentElement()
Description : Emulates insertAdjacentHTML(), insertAdjacentText() and
insertAdjacentElement() three functions so they work with
Netscape 6/Mozilla
Notes : by Thor Larholm me@jscript.dk
\* ---------------------------------------------------------------------- */
if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement){
HTMLElement.prototype.insertAdjacentElement = function
(where,parsedNode)
{
switch (where){
case 'beforeBegin':
this.parentNode.insertBefore(parsedNode,this)
break;
case 'afterBegin':
this.insertBefore(parsedNode,this.firstChild);
break;
case 'beforeEnd':
this.appendChild(parsedNode);
break;
case 'afterEnd':
if (this.nextSibling)
this.parentNode.insertBefore(parsedNode,this.nextSibling);
else this.parentNode.appendChild(parsedNode);
break;
}
}
HTMLElement.prototype.insertAdjacentHTML = function
(where,htmlStr)
{
var r = this.ownerDocument.createRange();
r.setStartBefore(this);
var parsedHTML = r.createContextualFragment(htmlStr);
this.insertAdjacentElement(where,parsedHTML)
}
HTMLElement.prototype.insertAdjacentText = function
(where,txtStr)
{
var parsedText = document.createTextNode(txtStr)
this.insertAdjacentElement(where,parsedText)
}
};
// Create viewTextMode global variable and set to 0
// enabling all toolbar commands while in HTML mode
viewTextMode = 0;
/* ---------------------------------------------------------------------- *\
Function : generate_wysiwyg()
Description : replace textarea with wysiwyg editor
Usage : generate_wysiwyg("textarea_id");
Arguments : textarea_id - ID of textarea to replace
\* ---------------------------------------------------------------------- */
function generate_wysiwyg(textareaID) {
// Hide the textarea
document.getElementById(textareaID).style.display = 'none';
// Pass the textareaID to the "n" variable.
var n = textareaID;
// Toolbars width is 2 pixels wider than the wysiwygs
toolbarWidth = parseFloat(wysiwygWidth) + 2;
// Generate WYSIWYG toolbar one
var toolbar;
toolbar = '
![]() | ';
// Create IDs for inserting Font Type and Size drop downs
toolbar += ''; toolbar += ' | '; // Output all command buttons that belong to toolbar one for (var i = 0; i <= buttonName.length;) { if (buttonName[i]) { var buttonObj = ToolbarList[buttonName[i]]; var buttonID = buttonObj[0]; var buttonTitle = buttonObj[1]; var buttonImage = buttonObj[2]; var buttonImageRollover = buttonObj[3]; if (buttonName[i] == "seperator") { toolbar += ' |
![]() | ';
// Output all command buttons that belong to toolbar two
for (var j = 0; j <= buttonName2.length;) {
if (buttonName2[j]) {
var buttonObj = ToolbarList[buttonName2[j]];
var buttonID = buttonObj[0];
var buttonTitle = buttonObj[1];
var buttonImage = buttonObj[2];
var buttonImageRollover = buttonObj[3];
if (buttonName2[j] == "seperator") {
toolbar2 += '';
toolbar2 += ' | ';
}
else {
toolbar2 += '
| \n' + '\n' + ' |
'; FontSelectDropDown[n] += ''; for (var i = 0; i <= Fonts.length;) { if (Fonts[i]) { FontSelectDropDown[n] += ' '; } i++; } FontSelectDropDown[n] += ' |
'; FontSizesDropDown[n] += ''; for (var i = 0; i <= FontSizes.length;) { if (FontSizes[i]) { FontSizesDropDown[n] += ' '; } i++; } FontSizesDropDown[n] += ' |