// remote scripting library // (c) copyright 2005 modernmethod, inc var sajax_debug_mode = false; var sajax_request_type = "POST"; var sajax_target_id = ""; var sajax_failure_redirect = ""; function sajax_debug(text) { if (sajax_debug_mode) alert(text); } function sajax_init_object() { sajax_debug("sajax_init_object() called..") var A; var msxmlhttp = new Array( 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'); for (var i = 0; i < msxmlhttp.length; i++) { try { A = new ActiveXObject(msxmlhttp[i]); } catch (e) { A = null; } } if(!A && typeof XMLHttpRequest != "undefined") A = new XMLHttpRequest(); if (!A) sajax_debug("Could not create connection object."); return A; } var sajax_requests = new Array(); function sajax_cancel() { for (var i = 0; i < sajax_requests.length; i++) sajax_requests[i].abort(); } function sajax_do_call(func_name, args) { var i, x, n; var uri; var post_data; var target_id; sajax_debug("in sajax_do_call().." + sajax_request_type + "/" + sajax_target_id); target_id = sajax_target_id; if (typeof(sajax_request_type) == "undefined" || sajax_request_type == "") sajax_request_type = "GET"; uri = "/_js/functionsSajax.php"; if (sajax_request_type == "GET") { if (uri.indexOf("?") == -1) uri += "?rs=" + escape(func_name); else uri += "&rs=" + escape(func_name); uri += "&rst=" + escape(sajax_target_id); uri += "&rsrnd=" + new Date().getTime(); for (i = 0; i < args.length-1; i++) uri += "&rsargs[]=" + escape(args[i]); post_data = null; } else if (sajax_request_type == "POST") { post_data = "rs=" + escape(func_name); post_data += "&rst=" + escape(sajax_target_id); post_data += "&rsrnd=" + new Date().getTime(); for (i = 0; i < args.length-1; i++) post_data = post_data + "&rsargs[]=" + escape(args[i]); } else { alert("Illegal request type: " + sajax_request_type); } x = sajax_init_object(); if (x == null) { if (sajax_failure_redirect != "") { location.href = sajax_failure_redirect; return false; } else { sajax_debug("NULL sajax object for user agent:\n" + navigator.userAgent); return false; } } else { x.open(sajax_request_type, uri, true); // window.open(uri); sajax_requests[sajax_requests.length] = x; if (sajax_request_type == "POST") { x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1"); x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); } x.onreadystatechange = function() { if (x.readyState != 4) return; sajax_debug("received " + x.responseText); var status; var data; var txt = x.responseText.replace(/^\s*|\s*$/g,""); status = txt.charAt(0); data = txt.substring(2); if (status == "") { // let's just assume this is a pre-response bailout and let it slide for now } else if (status == "-") alert("Error: " + data); else { if (target_id != "") document.getElementById(target_id).innerHTML = eval(data); else { try { var callback; var extra_data = false; if (typeof args[args.length-1] == "object") { callback = args[args.length-1].callback; extra_data = args[args.length-1].extra_data; } else { callback = args[args.length-1]; } callback(eval(data), extra_data); } catch (e) { sajax_debug("Caught error " + e + ": Could not eval " + data ); } } } } } sajax_debug(func_name + " uri = " + uri + "/post = " + post_data); x.send(post_data); sajax_debug(func_name + " waiting.."); delete x; return true; } // wrapper for montaSelectPessoas function x_montaSelectPessoas() { sajax_do_call("montaSelectPessoas", x_montaSelectPessoas.arguments); } // wrapper for baixaCP function x_baixaCP() { sajax_do_call("baixaCP", x_baixaCP.arguments); } // wrapper for cancelaCP function x_cancelaCP() { sajax_do_call("cancelaCP", x_cancelaCP.arguments); } // wrapper for baixarCH function x_baixarCH() { sajax_do_call("baixarCH", x_baixarCH.arguments); } // wrapper for excluirCH function x_excluirCH() { sajax_do_call("excluirCH", x_excluirCH.arguments); } // wrapper for verificaEstoqueProduto function x_verificaEstoqueProduto() { sajax_do_call("verificaEstoqueProduto", x_verificaEstoqueProduto.arguments); } // wrapper for verificaDadosMov function x_verificaDadosMov() { sajax_do_call("verificaDadosMov", x_verificaDadosMov.arguments); } // wrapper for saveCookie function x_saveCookie() { sajax_do_call("saveCookie", x_saveCookie.arguments); } // wrapper for efetuarLogin function x_efetuarLogin() { sajax_do_call("efetuarLogin", x_efetuarLogin.arguments); } // wrapper for atualizaCampo function x_atualizaCampo() { sajax_do_call("atualizaCampo", x_atualizaCampo.arguments); } // wrapper for alteraSenha function x_alteraSenha() { sajax_do_call("alteraSenha", x_alteraSenha.arguments); } preLoadImg = new Image(); preLoadImg.src = "/images/loading.gif"; function efetuarLogin(login, senha) { imprimeDiv("divLoginMsg", ""); divAguardeAction("1", "Aguarde ..."); x_efetuarLogin(login, senha, resultadoLogin); } function resultadoLogin(retorno) { if (retorno == "1") self.location = '/index.php'; else if (retorno == "2") imprimeDiv("divLoginMsg", "Desculpe, seu acesso ao sistema está bloqueado.
Contacte o Administrador."); else if (retorno == "3") imprimeDiv("divLoginMsg", "Login/Senha inválidos! Tente novamente."); divAguardeAction("0"); document.getElementById("formPrincipal").login.focus(); } function atualizaCampo(className, id, field, value, storee) { divAguardeAction("1", "Aguarde ..."); value = dbFormatValue(field, value); x_atualizaCampo(className, id, field, value, r_atualizaCampo); } function r_atualizaCampo(retorno) { divAguardeAction("0"); } function r_mudaEmpresa(retorno) { location.reload(); } function dbFormatValue(field, value) { if (field.indexOf('datahora') != -1 || field.indexOf('DataHora') != -1) { dia = value.getDate().toString().pad(2, '0', 0); mes = (Number(value.getMonth())+1).toString().pad(2, '0', 0); ano = value.getFullYear().toString(); if (ano.length == 3) ano = "20" + ((Number(ano) - 100).toString().pad(2, '0', 0)); hour = value.getHours(); min = value.getMinutes(); value = dia + '/' + mes + '/' + ano + ' ' + hour + ':' + min; } else if (field.indexOf('data') != -1 || field.indexOf('Data') != -1) { dia = value.getDate().toString().pad(2, '0', 0); mes = (Number(value.getMonth())+1).toString().pad(2, '0', 0); ano = value.getFullYear().toString(); if (ano.length == 3) ano = "20" + ((Number(ano) - 100).toString().pad(2, '0', 0)); value = dia + '/' + mes + '/' + ano; } else if (field.indexOf('valor') != -1) { value = cNumero(value); } else if (value == true) value = 1; else if (value == false) value = 0; return value; }