/* * Variabili globali */ var asyncMarqueeID = -1; var asyncCopyID = -1; /** Elemento scroll */ var postBodyScroll = null; /** Fine frame asincrono */ function asyncframeload(srcframe, dstdiv, marquee, loaddiv) { if (asyncCopyID == -1) { window.setTimeout("asyncframeload('" + srcframe + "','" + dstdiv + "','" + marquee + "','" + loaddiv + "')", 1000); return; } var sts = window[srcframe].document.readyState; if (asyncMarqueeID > -1) window.clearInterval(asyncMarqueeID); window.clearInterval(asyncCopyID); datacopyframe(srcframe, dstdiv); var obj = document.getElementById(marquee); if (typeof(obj) != "undefined") obj.style.display = "none"; var obj = document.getElementById(loaddiv); if (typeof(obj) != "undefined") obj.style.display = "none"; asyncMarqueeID = -1; asyncCopyID = -1; } /** Inizio frame asincrono */ function asyncframestart(srcframe, dstdiv, marquee) { // Se non c'รจ il documento aspetto 1 secondo var ok = true; if (!window[srcframe]) ok = false; else if (!window[srcframe].document) ok = false; else if (!window[srcframe].document.body) ok = false; if (!ok) { window.setTimeout("asyncframestart('" + srcframe + "', '" + dstdiv + "', '" + marquee + "')", 1000); return; } var sts = window[srcframe].document.readyState; if (marquee > "") asyncMarqueeID = window.setInterval("UIMarquee('" + marquee + "')", 1000); asyncCopyID = window.setInterval("datacopyframe('" + srcframe + "', '" + dstdiv + "')", 500); } /** Crea un oggetto ajax */ function createAJAX() { if (window.XMLHttpRequest) return new XMLHttpRequest(); else if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP"); } /** Ricerca un parent ricorsivamente */ function findparentbytagname(obj, tagName) { if (obj.parentNode == null) return null; if (obj.parentNode.tagName.toLowerCase() == tagName.toLowerCase()) return obj.parentNode; return findparentbytagname(obj.parentNode, tagName); } /** Cerca di capire l'esatto offset di un oggetto */ function recurseOffset(obj, side) { if (obj.style.position == "absolute") return 0; var ret = (side == "top") ? obj.offsetTop : obj.offsetLeft; if (obj.offsetParent != null) ret += recurseOffset(obj.offsetParent, side); return ret; } /** Ricopia i dati dall'iframe nascosto */ function datacopyframe(srcframe, dstdiv) { var tmp = window[srcframe].document.body.innerHTML; var obj = document.getElementById(dstdiv); obj.innerHTML = tmp; window.scrollTo(0, document.body.scrollHeight); } /** Padda una stringa a sinistra */ String.prototype.padLeft = function(len, car) { var n = this.length; var pad = ""; for (var i = 0; i < len - n; i++) pad += car; return pad + this; } /** Estende la stringa con la funzione TRIM */ String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); } Number.prototype.numberFormat = function(prec, dec, mig) { /*if (prec == null) prec = 2; if (dec == null) dec = ","; if (mig == null) mig = "."; var nStr = this.roundTo(prec) + ''; var x = nStr.split('.'); var x1 = x[0]; var x2 = dec + (x.length > 1 ? x[1] : '00'); var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + mig + '$2'); } while (x2.length < prec) { x2 += "0"; } return x1 + x2;*/ if (prec == null) prec = 2; if (dec == null) dec = ","; if (mig == null) mig = "."; var nStr = this.roundTo(prec) + ''; var x = nStr.split('.'); var x1 = ""; for (var i = 0; ((x.length == 1) && (x1 == "")) || (i < (x.length - 1)); i++) x1 = x1 + x[i].trim(); if (x1 == "") x1 = "0"; else { var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + mig + '$2'); } } var x2 = (x.length > 1 ? x[x.length - 1] : '00'); while (x2.length < prec) { x2 += "0"; } x2 = dec + x2.substring(0, prec); return x1 + x2; } Number.prototype.roundTo = function(decimalpositions) { var i = this * Math.pow(10,decimalpositions); i = Math.round(i); return i / Math.pow(10,decimalpositions); } /** URLENCODE per il passaggio dati via GET o POST */ function urlencode(str) { // http://kevin.vanzonneveld.net // + original by: Philip Peterson // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + input by: AJ // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // % note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/ // * example 1: urlencode('Kevin van Zonneveld!'); // * returns 1: 'Kevin+van+Zonneveld%21' // * example 2: urlencode('http://kevin.vanzonneveld.net/'); // * returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F' // * example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a'); // * returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a' var histogram = {}, histogram_r = {}, code = 0, tmp_arr = []; var ret = str.toString(); var replacer = function(search, replace, str) { var tmp_arr = []; tmp_arr = str.split(search); return tmp_arr.join(replace); }; // The histogram is identical to the one in urldecode. histogram['!'] = '%21'; histogram['%20'] = '+'; // Begin with encodeURIComponent, which most resembles PHP's encoding functions ret = encodeURIComponent(ret); for (search in histogram) { replace = histogram[search]; ret = replacer(search, replace, ret) // Custom replace. No regexing } // Uppercase for full PHP compatibility return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) { return "%"+m2.toUpperCase(); }); return ret; } /** Apre una finestra di popup contenente il report */ function PrintReport(e, div) { if (typeof(event) != "undefined") var src = event.srcElement; else var src = e.target; var oldHTML = src.innerHTML; var oldClass = src.getAttribute("class"); var oldClick = src.getAttribute("onclick"); src.innerHTML = " Stampa in corso"; src.setAttribute("class", ""); src.setAttribute("onclick", ""); var obj = UITable_GetInputElements(div + "_dati"); var url = UITable_CreateUrl(obj); var tab = document.getElementById(div + "_dati"); var page = tab.getAttribute("query_page"); page += (page.indexOf("?") == -1) ? "?" : "&"; page += "ajax=1"; url = page + "&stampa=1" + url; var req = createAJAX(); req.open("GET", url, true); req.send(null); req.onreadystatechange = function() { if (req.readyState != 4) return; src.innerHTML = oldHTML; src.setAttribute("class", oldClass); src.setAttribute("onclick", oldClick); try { var json = JSON.parse(Base64.decode(req.responseText)); } catch (err) { } if (json) { window.open(json.url, div + "_window", "status=1, resizable=1, height=" + (window.document.documentElement.clientHeight - 5) + ", width=" + (window.document.documentElement.clientWidth - 80) + ", top=40, left=30" ); } else { var log = document.getElementById(div + "_log"); if (log) { log.innerHTML = req.responseText; window.setTimeout(UIShowBalloonTip, 50); } } } } function PrintReportByName(section, name, urlData) { var url = Core.virtual_path + "report/ajax.php?ajax=1&sezione=" + section + "&name=" + name; urlData = JSON.parse(Base64.decode(urlData)); url += (urlData.indexOf("&") == 0) ? "" : "&"; url += urlData; var req = createAJAX(); req.open("GET", url, false); req.send(null); try { var json = JSON.parse(Base64.decode(req.responseText)); } catch (err) { } if (json) { window.open(json.url, "report_window", "status=1, resizable=1, height=" + (window.document.documentElement.clientHeight - 5) + ", width=" + (window.document.documentElement.clientWidth - 80) + ", top=40, left=30" ); } } function bodyScroll() { if (postBodyScroll == null) postBodyScroll = document.getElementById("postBodyScroll"); if (postBodyScroll) { if (Core.browser == "chrome") postBodyScroll.value = window.document.body.scrollTop; else postBodyScroll.value = window.document.documentElement.scrollTop; } } function loadBodyScroll() { if (postBodyScroll == null) postBodyScroll = document.getElementById("postBodyScroll"); if (postBodyScroll) { if (Core.browser == "chrome") window.document.body.scrollTop = postBodyScroll.value; else window.document.documentElement.scrollTop = postBodyScroll.value; } }