//======================================================================= //input validation: // acqui/uncertainprice.tmpl uses this function uncheckbox(form, field) { var price = new Number(form.elements['price' + field].value); var tmpprice = ""; var errmsg = MSG_INVALIDPRICE; if (isNaN(price)) { alert(errmsg); for(var i=0; i 0) { return false; } return true; } //Function returns false if v is not a number (if maybenull is 0, it also returns an error if the number is 0) function isNum(v,maybenull) { var n = new Number(v.value); if (isNaN(n)) { return false; } if (maybenull==0 && v.value=='') { return false; } return true; } //======================================================================= //======================================================================= // Functions for drag-and-drop functionality if( typeof(YAHOO) === "object"){ (function() { var Dom = YAHOO.util.Dom; var Event = YAHOO.util.Event; var DDM = YAHOO.util.DragDropMgr; DDApp = { init: function() { var uls = document.getElementsByTagName('ul'); var i,j; var ddtarget; for (i=0; i this.lastY) { this.goingUp = false; } this.lastY = y; }, onDragOver: function(e, id) { var srcEl = this.getEl(); var destEl = Dom.get(id); // We are only concerned with list items, we ignore the dragover // notifications for the list. if (destEl.nodeName.toLowerCase() == "li") { var orig_p = srcEl.parentNode; var p = destEl.parentNode; if (this.goingUp) { p.insertBefore(srcEl, destEl); // insert above } else { p.insertBefore(srcEl, destEl.nextSibling); // insert below } DDM.refreshCache(); } } }); })(); } //creates new group, parameter is the group's name function newGroup(event, name) { if (name == ''){ return 0; } if (!enterpressed(event) && event != "button"){ return false; } var pardiv = document.getElementById('groups'); var newdiv = document.createElement('div'); var newh3 = document.createElement('h3'); var newul = document.createElement('ul'); var newclose = document.createElement('a'); var newrename = document.createElement('a'); var newbasketgroupname = document.createElement('input'); var nbgclosed = document.createElement('input'); var newp = document.createElement('p'); var reg=new RegExp("[-]+", "g"); var i = 0; var maxid = 0; while( i < pardiv.getElementsByTagName('input').length ){ if (! isNaN(parseInt(pardiv.getElementsByTagName('input')[i].name.split(reg)[1])) && parseInt(pardiv.getElementsByTagName('input')[i].name.split(reg)[1]) > maxid){ maxid = parseInt(pardiv.getElementsByTagName('input')[i].name.split(reg)[1]); } ++i; } // var bgid = parseInt(pardiv.getElementsByTagName('input')[pardiv.getElementsByTagName('input').length-2].name.split(reg)[1]) + 1; var bgid = maxid + 1; var newchanged = document.createElement('input'); newul.id="bg-"+bgid; newul.className='draglist'; newh3.innerHTML=name; // newh3.style.display="inline"; newclose.innerHTML="close"; newclose.href="javascript: closebasketgroup('"+bgid+"', 'bg-"+bgid+"');"; newrename.href="javascript:" + "renameinit("+bgid+");"; newrename.innerHTML="rename"; // newp.style.display="inline"; newp.innerHTML=" [ "; newp.appendChild(newrename); newp.innerHTML+=" / "; newp.appendChild(newclose); newp.innerHTML+=" ]"; newbasketgroupname.type="hidden"; newbasketgroupname.name="basketgroup-" + bgid + "-name"; newbasketgroupname.id = "basketgroup-" + bgid + "-name"; newbasketgroupname.value=name; nbgclosed.type="hidden"; nbgclosed.name="basketgroup-" + bgid + "-closed"; nbgclosed.value="0"; nbgclosed.id=nbgclosed.name; newchanged.type="hidden"; newchanged.id="basketgroup-"+bgid+"-changed"; newchanged.name=newchanged.id; newchanged.value="1"; newdiv.style.backgroundColor='red'; newdiv.appendChild(newh3); newdiv.appendChild(newp); newdiv.appendChild(newul); newdiv.appendChild(newbasketgroupname); newdiv.appendChild(nbgclosed); newdiv.appendChild(newchanged); newdiv.className='workarea'; pardiv.appendChild(newdiv); YAHOO.util.Event.onDOMReady(DDApp.init, DDApp, true); } //this traps enters in input fields function enterpressed(event){ var keycode; if (window.event) keycode = window.event.keyCode; else if (event) keycode = event.which; else return false; if (keycode == 13) { return true; } else return false; } //Closes a basketgroup function closebasketgroup(bgid) { var answer = confirm(MSG_CONFIRM_CLOSE_BASKETGROUP); if(! answer){ return; } ulid = 'bg-'+bgid; var i = 0; tagname='basketgroup-'+bgid+'-closed'; var ddtarget; var closeinput = document.getElementById(tagname); closeinput.value = 1; var changed = document.getElementById("basketgroup-"+bgid+"-changed"); changed.value=1; var div = document.getElementById(tagname).parentNode; var stufftoremove = div.getElementsByTagName('p')[0]; var ul = document.getElementById(ulid); var lis = ul.getElementsByTagName('li'); if (lis.length == 0 ) { alert(MSG_CLOSE_EMPTY_BASKET); return; } var cantprint = document.createElement('p'); div.className = "closed"; ul.className="closed"; for(i=0; iDebug Log" + ""); doc.close(); log.window_ = win; } var logLine = log.window_.document.createElement("div"); logLine.appendChild(log.window_.document.createTextNode(message)); log.window_.document.body.appendChild(logLine); } //======================================================================= function getElementsByClass( searchClass, domNode, tagName) { if (domNode == null) domNode = document; if (tagName == null) tagName = '*'; var el = new Array(); var tags = domNode.getElementsByTagName(tagName); var tcl = " "+searchClass+" "; for(i=0,j=0; i 0 ) { remainingTotal.style.color = 'green'; } else { // if its negative, make it red.. remainingTotal.style.color = 'red'; } remainingTotal.textContent = remainingNew.toFixed(2) ; } function autoFillRow(bud_id) { var remainingTotal = document.getElementById("budget_est_"+bud_id); var remainingNew = new Number; var budgetTotal = document.getElementById("budget_tot_"+bud_id ).textContent; var arr = getElementsByClass("plan_entry_" + bud_id); budgetTotal = budgetTotal.replace(/\,/, ""); var qty = new Number; // get the totals var novalueArr = new Array(); for ( var i=0, len=arr.length; i


"); win.document.write(etc); win.document.write("

"); win.document.write("
"); } //======================================================================= // NEXT BLOCK IS USED BY NEWORDERBEMPTY function updateCosts(){ var quantity = new Number($("#quantity").val()); var discount = new Number($("#discount").val()); var applygst = new Number ($("#applygst").val()); var listprice = new Number($("#listprice").val()); var currcode = new String($("#currency").val()); var exchangerate = new Number($("#currency_rate_"+currcode).val()); var gst_on=false; var rrp = new Number(listprice*exchangerate); var ecost = rrp; if ( 100-discount != 100 ) { //Prevent rounding issues if no discount ecost = new Number(Math.floor(rrp * (100 - discount )) / 100); } var total = new Number( ecost * quantity); $("#rrp").val(rrp.toFixed(2)); $("#ecost").val(ecost.toFixed(2)); $("#total").val(total.toFixed(2)); $("listprice").val(listprice.toFixed(2)); return true; } // Calculates total amount in a suggestion function calcNewsuggTotal(){ //collect values var quantity = new Number(document.getElementById('quantity').value); // var currency = f.currency.value; var currcode = new String(document.getElementById('currency').value); var price = new Number(document.getElementById('price').value); var exchangerate = new Number(document.getElementById('currency_rate_'+currcode).value); var total = new Number(quantity*price*exchangerate); document.getElementById('total').value = total.toFixed(2); document.getElementById('price').value = price.toFixed(2); return true; } // ---------------------------------------- //USED BY NEWORDEREMPTY.PL /* function fetchSortDropbox(f) { var budgetId=f.budget_id.value; var handleSuccess = function(o){ if(o.responseText !== undefined){ sort_dropbox.innerHTML = o.responseText; } } var callback = { success:handleSuccess }; var sUrl = '../acqui/fetch_sort_dropbox.pl?sort=1&budget_id='+budgetId var sort_dropbox = document.getElementById('sort1'); var request1 = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback); var rr = '00'; // FIXME: --------- twice , coz the 2 requests get mixed up otherwise var handleSuccess2 = function(o){ if(o.responseText !== undefined){ sort2_dropbox.innerHTML = o.responseText; } } var callback2 = { success:handleSuccess }; var sUrl2 = '../acqui/fetch_sort_dropbox.pl?sort=2&budget_id='+budgetId; var sort2_dropbox = document.getElementById('sort2'); var request2 = YAHOO.util.Connect.asyncRequest('GET', sUrl2, callback2); } */ //USED BY NEWORDEREMPTY.PL function fetchSortDropbox(f) { var budgetId=f.budget_id.value; for (i=1;i<=2;i++) { var sort_zone = document.getElementById('sort'+i+'_zone'); var url = '../acqui/fetch_sort_dropbox.pl?sort='+i+'&budget_id='+budgetId; var xmlhttp = null; xmlhttp = new XMLHttpRequest(); if ( typeof xmlhttp.overrideMimeType != 'undefined') { xmlhttp.overrideMimeType('text/xml'); } xmlhttp.open('GET', url, false); xmlhttp.send(null); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { // stupid JS... } else { // wait for the call to complete } }; // rc = eval ( xmlhttp.responseText ); var retRootType = xmlhttp.responseXML.firstChild.nodeName; var existingInputs = sort_zone.getElementsByTagName('input'); if (existingInputs.length > 0 && retRootType == 'input') { // when sort is already an input, do not override to preseve value return; } sort_zone.innerHTML = xmlhttp.responseText; } } //USED BY NEWORDEREMPTY.PL function totalExceedsBudget(budgetId, total) { var xmlhttp = null; xmlhttp = new XMLHttpRequest(); if ( typeof xmlhttp.overrideMimeType != 'undefined') { xmlhttp.overrideMimeType('text/xml'); } var url = '../acqui/check_budget_total.pl?budget_id=' + budgetId + "&total=" + total; xmlhttp.open('GET', url, false); xmlhttp.send(null); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { actTotal = eval ( xmlhttp.responseText ); if ( Math.abs(actTotal) < Math.abs(total) ) { // if budget is to low :( return true ; } else { return false; } } } } //USED BY AQBUDGETS.TMPL function budgetExceedsParent(budgetTotal, budgetId, newBudgetParent, periodID) { var xmlhttp = null; xmlhttp = new XMLHttpRequest(); if ( typeof xmlhttp.overrideMimeType != 'undefined') { xmlhttp.overrideMimeType('text/xml'); } // make the call... yawn // var url = '../admin/check_parent_total.pl?budget_id=' + budgetId + '&parent_id=' + newBudgetParent + "&total=" + budgetTotal + "&period_id="+ periodID ; var url = '../admin/check_parent_total.pl?total=' + budgetTotal + "&period_id="+ periodID ; if (budgetId ) { url += '&budget_id=' + budgetId }; if ( newBudgetParent ) { url += '&parent_id=' + newBudgetParent}; xmlhttp.open('GET', url, false); xmlhttp.send(null); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { // stupid JS... } else { // wait for the call to complete } }; var result = eval ( xmlhttp.responseText ); if (result == '1') { return MSG_BUDGET_PARENT_ALLOCATION; } else if (result == '2') { return MSG_BUDGET_PERIOD_ALLOCATION; } else { return false; } } //USED BY AQBUDGETS.TMPL function checkBudgetParent(budgetId, newBudgetParent) { var xmlhttp = null; xmlhttp = new XMLHttpRequest(); if ( typeof xmlhttp.overrideMimeType != 'undefined') { xmlhttp.overrideMimeType('text/xml'); } var url = '../admin/check_budget_parent.pl?budget_id=' + budgetId + '&new_parent=' + newBudgetParent; xmlhttp.open('GET', url, false); xmlhttp.send(null); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { // do something with the results } else { // wait for the call to complete } }; var result = eval ( xmlhttp.responseText ); if (result == '1') { return MSG_PARENT_BENEATH_BUDGET; // } else if (result == '2') { // return "- New budget-parent has insufficent funds\n"; // } else { // return false; } } function hideColumn(num) { $("#hideall,#showall").removeAttr("checked").parent().removeClass("selected"); $("#"+num).parent().removeClass("selected"); var hide = Number(num.replace("col","")) + 2; // hide header and cells matching the index $("#plan td:nth-child("+hide+"),#plan th:nth-child("+hide+")").toggle(); } function showColumn(num){ $("#hideall").removeAttr("checked").parent().removeClass("selected"); $("#"+num).parent().addClass("selected"); // set the index of the table column to hide show = Number(num.replace("col","")) + 2; // hide header and cells matching the index $("#plan td:nth-child("+show+"),#plan th:nth-child("+show+")").toggle(); } function showAllColumns(){ $("#selections").checkCheckboxes(); $("#selections span").addClass("selected"); $("#plan td:nth-child(2),#plan tr th:nth-child(2)").nextAll().show(); $("#hideall").removeAttr("checked").parent().removeClass("selected"); } function hideAllColumns(){ var allCols = $("#plan th").length; $("#selections").unCheckCheckboxes(); $("#selections span").removeClass("selected"); $("#plan td:nth-child(2),#plan th:nth-child(2)").nextUntil("th:nth-child("+(allCols-1)+"),td:nth-child("+(allCols-1)+")").hide(); // hide all but the last two columns $("#hideall").attr("checked","checked").parent().addClass("selected"); }