// -------------------------------------------------------------------------------------------------------- // Ajax // -------------------------------------------------------------------------------------------------------- function objXML(){ try { var XMLHTTP = new XMLHTTPRequest(); } catch(ee) { try { XMLHTTP = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try{ XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP"); } catch(E) { XMLHTTP = false; } } } return XMLHTTP; } // -------------------------------------------------------------------------------------------------------- // TRIM Js String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,""); } // -------------------------------------------------------------------------------------------------------- // Variaveis de sessao dinamicas // -------------------------------------------------------------------------------------------------------- var obj_sessao_var = new objAjax(); // Lendo mensagens function ajaxSetVar( variavel, valor ){ obj_sessao_var.open("GET","adm/sessao_var.ajax.php?variavel=" + variavel + "&valor=" + valor,true); } // -------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------- // Funçoes JS comuns para todas as paginas // ----------------------------------------------------------------------- // Exibe / Inibe Box function showBox( objBox, sender ){ try { var alvo = document.getElementById(objBox); if( alvo.style.display == 'none' ) { // Exibindo alvo.style.display = 'block'; // Verificando se o sender é uma imagem if( sender.src ) { // Alterando a imagem sender.src = "img/icones/icon_seta_cima.gif"; // Alterando o title sender.title = "Recolher"; } // Controle via cookie var bln_exibir = 1; } else { // Inibindo alvo.style.display = 'none'; // Verificando se o sender é uma imagem if( sender.src ) { // Alterando a imagem sender.src = "img/icones/icon_seta_baixo.gif"; // Alterando o title sender.title = "Expandir"; } // Controle via cookie var bln_exibir = 0; } // Cookie var str_nome_cookie = "WS_painel_controle"; // deleteCookie(str_nome_cookie); try{ var str_cookie = getCookie(str_nome_cookie); } catch(e) { // Erro } if( str_cookie ) { // Verifica se o box ja existe no cookie var bln_existe = str_cookie.search(objBox+"="); // Retirando valores indefinidos str_cookie = str_cookie.replace("undefined&", "", "gi"); str_cookie = str_cookie.replace("undefined", "", "gi"); // Valores do cookie if( bln_existe > -1 ){ // String ja consta no cookie // Substituir valor atual str_cookie = str_cookie.replace(objBox+"=0", "[X]"); str_cookie = str_cookie.replace(objBox+"=1", "[X]"); str_cookie = str_cookie.replace("[X]", objBox+"="+bln_exibir, "gi"); } else { if( str_cookie != undefined ) var str_cookie = str_cookie + "&" + objBox+"="+bln_exibir; else var str_cookie = objBox+"="+bln_exibir; } // Aplicando o cookie try{ setCookie(str_nome_cookie, str_cookie, 360); } catch(e){} } } catch( e ) { // Erro } } // Menu DropDown function showMenu(){ var alvo = document.getElementById("menu_dropdown"); // Inibindo ou exibindo if( alvo.style.display == 'none' || alvo.style.display == '' ) alvo.style.display = 'block'; else alvo.style.display = 'none'; // Posicionando alvo.style.left = 90; alvo.style.top = 145; } // Envia Pesquisar Google function enviaPesquisaGoogle(objForm){ if( !objForm.q.value ) { alert("Digite o termo a ser pesquisado !"); objForm.q.focus(); return false; } if( objForm.tipo[0].checked ) { var url = "http://www.google.com.br/search"; } else { var url = "http://images.google.com.br/images"; } // Aplicando o action do form objForm.action = url; return true; } // Abre janela function janela(url,nome,W,H,scroll,maximizar){ // Centralizando var T = (screen.height/2)-(H/2); var L = (screen.width/2)-(W/2); // Maximização var M = ( ( !maximizar ) ? 0 : maximizar ) ; // Configs var configs = "width="+W+",height="+H+",scrollbars="+scroll+",left="+L+",top="+T+",resizable="+M; // Janela var janela = window.open(url,nome,configs); // Focus if( janela ) janela.focus(); } //-------------------------------------------------------------------------------------------------------- // Cookies //-------------------------------------------------------------------------------------------------------- /* * Sets a Cookie with the given name and value. * * name Name of the cookie * value Value of the cookie * [expires] Expiration date of the cookie (default: end of current session) * [path] Path where the cookie is valid (default: path of calling document) * [domain] Domain where the cookie is valid * (default: domain of calling document) * [secure] Boolean value indicating if the cookie transmission requires a * secure transmission */ function setCookie(name, value, days, path, domain, secure) { // Tempo de duracao do cookie if ( days ) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = date; } document.cookie= name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : ""); } /** * Gets the value of the specified cookie. * * name Name of the desired cookie. * * Returns a string containing value of specified cookie, * or null if cookie does not exist. */ function getCookie(name) { var dc = document.cookie; var prefix = name + "="; var begin = dc.indexOf("; " + prefix); if (begin == -1) { begin = dc.indexOf(prefix); if (begin != 0) return null; } else { begin += 2; } var end = document.cookie.indexOf(";", begin); if (end == -1) end = dc.length; return unescape(dc.substring(begin + prefix.length, end)); } /** * Deletes the specified cookie. * * name name of the cookie * [path] path of the cookie (must be same as path used to create cookie) * [domain] domain of the cookie (must be same as domain used to create cookie) */ function deleteCookie(name, path, domain) { if (getCookie(name)) { document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT"; } } //-------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------- // Status do site //-------------------------------------------------------------------------------------------------------- function statusSite(){ var resp = confirm("Alterar status atual do site ?"); if( resp ) { url = "status_site.php?status=1&url_retorno="; location = url; } } //-------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------- // Captura de posicao do mouse //-------------------------------------------------------------------------------------------------------- if (document.layers) { // Netscape document.captureEvents(Event.MOUSEMOVE); document.onmousemove = captureMousePosition; } else if (document.all) { // Internet Explorer document.onmousemove = captureMousePosition; } else if (document.getElementById) { // Netcsape 6 document.onmousemove = captureMousePosition; } // Global variables xMousePos = 0; yMousePos = 0; xMousePosMax = 0; yMousePosMax = 0; function captureMousePosition(e) { if (document.layers) { xMousePos = e.pageX; yMousePos = e.pageY; xMousePosMax = window.innerWidth+window.pageXOffset; yMousePosMax = window.innerHeight+window.pageYOffset; } else if (document.all) { xMousePos = window.event.x+document.body.scrollLeft; yMousePos = window.event.y+document.body.scrollTop; xMousePosMax = document.body.clientWidth+document.body.scrollLeft; yMousePosMax = document.body.clientHeight+document.body.scrollTop; } else if (document.getElementById) { xMousePos = e.pageX; yMousePos = e.pageY; xMousePosMax = window.innerWidth+window.pageXOffset; yMousePosMax = window.innerHeight+window.pageYOffset; } } //-------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------- // INSERIR NOVA ANOTACAO //-------------------------------------------------------------------------------------------------------- // Exibindo box para nova anotacao function inserirAnotacao(){ // Box anotacoes var alvo = document.getElementById("box_anotacoes"); if( alvo.style.display == 'none' || !alvo.style.display ){ // Visible true alvo.style.display = 'block'; // Posicionamento alvo.style.top = yMousePos+30; alvo.style.left = xMousePos-350; // Foco document.frmAnotacoes.str_titulo.focus(); } else { // Posicionamento alvo.style.top = yMousePos+30; alvo.style.left = xMousePos-350; } } // Cancelando anotacoes function cancelarAnotacoes( bln_outras_ferramentas ){ if( document.frmAnotacoes.str_titulo.value != "" || document.frmAnotacoes.str_descricao.value != "" ){ var resp = confirm("Descartar a anotação ?"); if(!resp) return false; } var alvo = document.getElementById("box_anotacoes"); document.frmAnotacoes.reset(); alvo.style.display = 'none'; // Inibindo tooltip var tooltip = document.getElementById("box_anotacoes_msg"); tooltip.innerHTML = ""; tooltip.style.display = "none"; if( !bln_outras_ferramentas ){ // Refresh pagina document.location = ""; } } // Salvando as anotacoes function enviarAnotacoes(){ var alvo = document.getElementById("box_anotacoes_msg"); alvo.innerHTML = "Por favor aguarde, salvando informações..."; alvo.style.display = "block"; // Salvando salvarAnotacoes(); return false; } //-------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------- // Suporte //-------------------------------------------------------------------------------------------------------- function suporte(){ // alert("Em manutenção. Desculpe o transtorno."); janela("suporte.php","Suporte",400,450,"auto"); } //-------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------- // Preview de imagens do campo file //-------------------------------------------------------------------------------------------------------- function preview_img( urlImg, strImg ){ var img = document.getElementById( strImg ); img.src = ""; img.src = urlImg; } function addslashes( str ) { str=str.replace(/\'/g,'\\\''); str=str.replace(/\"/g,'\\"'); str=str.replace(/\\/g,'\\\\'); str=str.replace(/\0/g,'\\0'); return str; } function stripslashes( str ) { str=str.replace(/\\'/g,'\''); str=str.replace(/\\"/g,'"'); str=str.replace(/\\\\/g,'\\'); str=str.replace(/\\0/g,'\0'); return str; } //-------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------- // Refresh //-------------------------------------------------------------------------------------------------------- function refresh_page(){ // Refresh document.location = ""; } //-------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------- // Marca TR //-------------------------------------------------------------------------------------------------------- function marca_tr(tr_id,class_atual,ck){ if( tr_id && ck.checked ) tr_id.className = tr_id.className + " tr_destaque"; else tr_id.className = class_atual; } function marca_ck(tr_id,class_atual,ck){ if( ck.checked ) ck.checked = false; else ck.checked = true; marca_tr(tr_id,class_atual,ck); } //-------------------------------------------------------------------------------------------------------- // AUTO CONFIG EMAIL function gerar_auto_config(){ // Form var frm = document.frm_auto_config; var email = frm.str_email; if( !email.value ){ alert("Digite o email a ser configurado !"); document.frm_auto_config.str_email.focus(); } else { // Ajax // Gerar config var oDiv = document.getElementById("box_auto_config"); // Exibe o div oDiv.style.display = 'block'; var obj_auto_config_ajax = new objAjax(); var str_url = "auto_config_email.ajax.php?control_cache=20100905150327&str_email=" + email.value; // Open XML obj_auto_config_ajax.open("POST",str_url,true); // Header obj_auto_config_ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // Prepara para leitura obj_auto_config_ajax.onreadystatechange = function(){ // Verifica se o XML esta pronto para leitura if( obj_auto_config_ajax.readyState == 4 ){ // Dados XML var str_dados = obj_auto_config_ajax.responseText; // Comando oDiv.innerHTML = str_dados; } } // Finaliza obj Ajax obj_auto_config_ajax.send(null); } } // Formatando o número function format_number( pnumber,decimals ){ if (isNaN(pnumber)) { return 0}; if (pnumber=='') { return 0}; var snum = new String(pnumber); var sec = snum.split('.'); var whole = parseFloat(sec[0]); var result = ''; if(sec.length > 1){ var dec = new String(sec[1]); dec = String(parseFloat(sec[1])/Math.pow(10,(dec.length - decimals))); dec = String(whole + Math.round(parseFloat(dec))/Math.pow(10,decimals)); var dot = dec.indexOf('.'); if(dot == -1){ dec += '.'; dot = dec.indexOf('.'); } while(dec.length <= dot + decimals) { dec += '0'; } result = dec; } else{ var dot; var dec = new String(whole); dec += '.'; dot = dec.indexOf('.'); while(dec.length <= dot + decimals) { dec += '0'; } result = dec; } return result; } // Somente numeros // input // onkeyup="soNumeros( this );" function soNumeros( oInput ) { oInput.value = oInput.value.replace(/[^0-9,.-]/g, ''); } // Substitui valor de tag function ereg_replace ( str_alvo, tag, valor ) { var str_reg = tag + "[^a-z]"; // Reg var regex = new RegExp( str_reg ,"g"); // Encontrado str_alvo = str_alvo.replace(regex, tag +"="+ valor + " " ); // Retorn da funcao return str_alvo; } // VALIDAÇÃO AUTOMATIZADA - WEBSTUDIO function valid( e ){ for(i=0;i
function maskCPF( campo ){ var caracteres = '01234567890'; var separacoes = 3; var separacao1 = '.'; var separacao2 = '-'; var conjuntos = 4; var conjunto1 = 3; var conjunto2 = 7; var conjunto3 = 11; var conjunto4 = 14; if ((caracteres.search(String.fromCharCode (window.event.keyCode))!=-1) && campo.value.length < (conjunto4)) { if (campo.value.length == conjunto1) campo.value = campo.value + separacao1; else if (campo.value.length == conjunto2) campo.value = campo.value + separacao1; else if (campo.value.length == conjunto3) campo.value = campo.value + separacao2; } else event.returnValue = false; } // ****************************************************************** // ****************************************************************** // Somente número // ****************************************************************** function SomenteNumero(e){ var tecla=(window.event)?event.keyCode:e.which; if( (tecla > 47 && tecla < 58) ){ return true; } else { if (tecla != 8) return false; else return true; } } // ****************************************************************** // ****************************************************************** // Aviso Fade // ****************************************************************** function aviso_fade( divName, msg ){ var alvo = $( "#" + divName ); alvo.show(); alvo.html( msg ); alvo.removeClass('aviso_fade').addClass('aviso_fade ok'); alvo.delay(2000).hide( 'slow', function() { // Animation complete } ); } // ******************************************************************