/* Version 1.0 - Modified 3-20-08 */ //Mootools upgrades Request.JSON.implement({ success: function(text){ this.response.json = JSON.decode(text, this.options.secure); if (this.response.json) { this.onSuccess(this.response.json, text) } else { alert("ERROR: "+text); } } }); Element.implement({ toJSON: function(){ var jsonString = []; this.getElements('input, select, textarea', true).each(function(el){ var name = el.name, type = el.type, value = Element.get(el, 'value'); if (value === false || !name) return; $splat(value).each(function(val){ jsonString.push('"'+name+'": '+JSON.encode(val)); }); }); if (jsonString.length > 0) { return "{"+jsonString.join(',')+"}"; } else { return null; } }, fromJSON: function(jsonObj) { for (x in jsonObj) { var elements = $$(document.getElementsByName(x)); if (elements.length == 1) { elements[0].value = jsonObj[x]; if (typeof (elements[0].getAttribute('checked')) != undefined) { if (jsonObj[x] == "on") elements[0].checked=true; //click checkboxes } } else if (elements.length > 1 ) { elements.each(function(item, index, array) { if(item.value == jsonObj[x]) { item.checked=true; } }); } } }, incrementNames: function(inc) { //This works great in FF, but in IE we have no access to the name attribute for XMLDOM element created dynamically in memory. this.getElements('input, textarea, select, div, span, table, tr, td', true).each(function(el) { if (el.name) el.name = el.name.replace(/\d+/, inc); if (el.id) el.id = el.id.replace(/\d+/, inc); }); } }); String.implement({ incrementNames: function(inc) { return this.replace(/_\d+\"/g, "_"+inc+"\""); }, toStringCurrency: function() { num = this.toString().replace(/[^0-9.]/g, ""); if(isNaN(num)) num = "0"; sign = (num == (num = Math.abs(num))); num = Math.floor(num*100+0.50000000001); cents = num%100; num = Math.floor(num/100).toString(); if(cents<10) cents = "0" + cents; for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) { num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3)); } return (((sign)?'':'-') + '$' + num + '.' + cents); }, toStringCommas: function() { num = this.toString().replace(/[^0-9.]/g, ""); if(isNaN(num)) num = "0"; sign = (num == (num = Math.abs(num))); num = Math.floor(num*100+0.50000000001); cents = num%100; num = Math.floor(num/100).toString(); if(cents<10) cents = "0" + cents; for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) { num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3)); } return (((sign)?'':'-') + num + '.' + cents); }, toNumFloat: function() { return(parseFloat(this.toString().replace(/[^\d.]/g, ""))); }, toNumInt: function() { return(parseInt(this.toString().replace(/\D/g, ""))); } }); Number.implement({ toStringCurrency: function() { num = this.toString().replace(/[^0-9.]/g, ""); if(isNaN(num)) num = "0"; sign = (num == (num = Math.abs(num))); num = Math.floor(num*100+0.50000000001); cents = num%100; num = Math.floor(num/100).toString(); if(cents<10) cents = "0" + cents; for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) { num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3)); } return (((sign)?'':'-') + '$' + num + '.' + cents); }, toStringCommas: function() { num = this.toString().replace(/[^0-9.]/g, ""); if(isNaN(num)) num = "0"; sign = (num == (num = Math.abs(num))); num = Math.floor(num*100+0.50000000001); cents = num%100; num = Math.floor(num/100).toString(); if(cents<10) cents = "0" + cents; for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) { num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3)); } return (((sign)?'':'-') + num + '.' + cents); } }); //Fix sortable tables adding pixels /* Sortables.implement({ getClone: function(element) { return element.clone(true); } }); */ var $returnFile = function(url) { var theRequest = (window.XMLHttpRequest) ? new XMLHttpRequest() : ((window.ActiveXObject) ? new ActiveXObject('Microsoft.XMLHTTP') : null); if (theRequest) { theRequest.open('GET', url, false); theRequest.send(null); return(theRequest.responseText); } } var $clearSelect = function(obj) { while (obj.options.length > 0) { obj.options[0] = null; } return obj; } var $clearTable = function(obj, row) { if (row==null) row=0; while (obj.rows.length > row) { obj.deleteRow(obj.rows.length-1); } return obj; } var $name = function(name, child) { !child ? child = 0 : child; return ($(document.getElementsByName(name)[child])); } $httpsRedirect = function() { var loc = window.location.toString().split("://"); if (loc[0] == "http") window.location = "https://"+loc[1]; }