1 //=======================================================================
3 // acqui/uncertainprice.tmpl uses this
4 function uncheckbox(form, field) {
5 var price = new Number(form.elements['price' + field].value);
7 var errmsg = MSG_INVALIDPRICE;
10 for(var i=0; i<form.elements['price' + field].value.length; ++i) {
11 price = new Number(form.elements['price' + field].value[i]);
12 if(! isNaN(price) || form.elements['price' + field].value[i] == ".") {
13 tmpprice += form.elements['price' + field].value[i];
16 form.elements['price' + field].value = tmpprice;
19 form.elements['uncertainprice' + field].checked = false;
23 // returns false if value is empty
24 function isNotNull(f,noalert) {
25 if (f.value.length ==0) {
31 function isNull(f,noalert) {
32 if (f.value.length > 0) {
38 //Function returns false if v is not a number (if maybenull is 0, it also returns an error if the number is 0)
39 function isNum(v,maybenull) {
40 var n = new Number(v.value);
44 if (maybenull==0 && v.value=='') {
53 //a logging function (a bit buggy, might open millions of log pages when initializing, but works fine after...
54 function log(message) {
55 if (!log.window_ || log.window_.closed) {
56 var win = window.open("", null, "width=400,height=200," +
57 "scrollbars=yes,resizable=yes,status=no," +
58 "location=no,menubar=no,toolbar=no");
60 var doc = win.document;
61 doc.write("<html><head><title>Debug Log</title></head>" +
62 "<body></body></html>");
66 var logLine = log.window_.document.createElement("div");
67 logLine.appendChild(log.window_.document.createTextNode(message));
68 log.window_.document.body.appendChild(logLine);
71 //=======================================================================
72 function getElementsByClass( searchClass, domNode, tagName) {
73 if (domNode == null) domNode = document;
74 if (tagName == null) tagName = '*';
76 var tags = domNode.getElementsByTagName(tagName);
77 var tcl = " "+searchClass+" ";
78 for(i=0,j=0; i<tags.length; i++) {
79 var test = " " + tags[i].className + " ";
80 if (test.indexOf(tcl) != -1)
87 function calcTotalRow(cell) {
89 var string = cell.name;
90 var pos = string.indexOf(",", 0);
91 var bud_id = string.substring(0, pos);
92 var val1 = cell.value;
93 var remainingTotal = document.getElementById("budget_est_"+bud_id);
95 var budgetTotal = document.getElementById("budget_tot_"+bud_id ).textContent;
96 var arr = getElementsByClass(cell.className);
98 budgetTotal = budgetTotal.replace(/\,/, "");
100 //percent strip and convert
101 if ( val1.match(/\%/) ) {
102 val1 = val1.replace(/\%/, "");
103 cell.value = (val1 / 100) * Math.abs(budgetTotal ) ;
106 for ( var i=0, len=arr.length; i<len; ++i ){
107 remainingNew += Math.abs(arr[i].value);
110 var cc = new Number(cell.value);
111 cell.value = cc.toFixed(2); // TIDYME...
112 remainingNew = Math.abs( budgetTotal ) - remainingNew ;
114 if ( remainingNew == 0) {
115 remainingTotal.style.color = 'black';
117 else if ( remainingNew > 0 ) {
118 remainingTotal.style.color = 'green';
119 } else { // if its negative, make it red..
120 remainingTotal.style.color = 'red';
123 remainingTotal.textContent = remainingNew.toFixed(2) ;
126 function autoFillRow(bud_id) {
128 var remainingTotal = document.getElementById("budget_est_"+bud_id);
129 var remainingNew = new Number;
130 var budgetTotal = document.getElementById("budget_tot_"+bud_id ).textContent;
131 var arr = getElementsByClass("plan_entry_" + bud_id);
133 budgetTotal = budgetTotal.replace(/\,/, "");
134 var qty = new Number;
136 var novalueArr = new Array();
137 for ( var i=0, len=arr.length; i<len; ++i ) {
138 remainingNew += Math.abs (arr[i].value );
140 if ( arr[i].value == 0 ) {
141 novalueArr[qty] = arr[i];
146 remainingNew = Math.abs( budgetTotal) - remainingNew ;
147 var newCell = new Number (remainingNew / qty);
148 var rest = new Number (remainingNew - (newCell.toFixed(2) * (novalueArr.length - 1)));
150 for (var i = 0; i<novalueArr.length; ++i) {
151 if (i == novalueArr.length - 1) {
152 novalueArr[i].value = rest.toFixed(2);
154 novalueArr[i].value = newCell.toFixed(2);
158 remainingTotal.textContent = '0.00' ;
159 remainingTotal.style.color = 'black';
163 function messenger(X,Y,etc){ // FIXME: unused?
164 win=window.open("","mess","height="+X+",width="+Y+",screenX=150,screenY=0");
166 win.document.close();
167 win.document.write("<body link='#333333' bgcolor='#ffffff' text='#000000'><font size='2'><p><br />");
168 win.document.write(etc);
169 win.document.write("<center><form><input type=button onclick='self.close()' value='Close'></form></center>");
170 win.document.write("</font></body></html>");
174 //=======================================================================
176 // NEXT BLOCK IS USED BY NEWORDERBEMPTY
178 function updateCosts(){
179 var quantity = new Number($("#quantity").val());
180 var discount = new Number($("#discount").val());
181 var applygst = new Number ($("#applygst").val());
182 var listprice = new Number($("#listprice").val());
183 var currcode = new String($("#currency").val());
184 var exchangerate = new Number($("#currency_rate_"+currcode).val());
187 var rrp = new Number(listprice*exchangerate);
189 if ( 100-discount != 100 ) { //Prevent rounding issues if no discount
190 ecost = new Number(Math.floor(rrp * (100 - discount )) / 100);
192 var total = new Number( ecost * quantity);
193 $("#rrp").val(rrp.toFixed(2));
194 $("#ecost").val(ecost.toFixed(2));
195 $("#total").val(total.toFixed(2));
196 $("listprice").val(listprice.toFixed(2));
201 // Calculates total amount in a suggestion
203 function calcNewsuggTotal(){
205 var quantity = Number(document.getElementById('quantity').value);
206 var currcode = String(document.getElementById('currency').value);
207 var price = Number(document.getElementById('price').value);
208 var exchangerate = Number(document.getElementById('currency_rate_'+currcode).value);
210 var total = Number(quantity*price*exchangerate);
212 document.getElementById('total').value = total.toFixed(2);
213 document.getElementById('price').value = price.toFixed(2);
218 // ----------------------------------------
219 //USED BY NEWORDEREMPTY.PL
221 function fetchSortDropbox(f) {
222 var budgetId=f.budget_id.value;
223 var handleSuccess = function(o){
224 if(o.responseText !== undefined){
225 sort_dropbox.innerHTML = o.responseText;
229 var callback = { success:handleSuccess };
230 var sUrl = '../acqui/fetch_sort_dropbox.pl?sort=1&budget_id='+budgetId
231 var sort_dropbox = document.getElementById('sort1');
232 var request1 = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);
235 // FIXME: --------- twice , coz the 2 requests get mixed up otherwise
237 var handleSuccess2 = function(o){
238 if(o.responseText !== undefined){
239 sort2_dropbox.innerHTML = o.responseText;
243 var callback2 = { success:handleSuccess };
244 var sUrl2 = '../acqui/fetch_sort_dropbox.pl?sort=2&budget_id='+budgetId;
245 var sort2_dropbox = document.getElementById('sort2');
246 var request2 = YAHOO.util.Connect.asyncRequest('GET', sUrl2, callback2);
253 //USED BY NEWORDEREMPTY.PL
254 function fetchSortDropbox(f) {
255 var budgetId=f.budget_id.value;
259 var sort_zone = document.getElementById('sort'+i+'_zone');
260 var url = '../acqui/fetch_sort_dropbox.pl?sort='+i+'&budget_id='+budgetId;
263 xmlhttp = new XMLHttpRequest();
264 if ( typeof xmlhttp.overrideMimeType != 'undefined') {
265 xmlhttp.overrideMimeType('text/xml');
268 xmlhttp.open('GET', url, false);
271 xmlhttp.onreadystatechange = function() {
272 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
275 // wait for the call to complete
278 // rc = eval ( xmlhttp.responseText );
279 var retRootType = xmlhttp.responseXML.firstChild.nodeName;
280 var existingInputs = sort_zone.getElementsByTagName('input');
281 if (existingInputs.length > 0 && retRootType == 'input') {
282 // when sort is already an input, do not override to preseve value
285 sort_zone.innerHTML = xmlhttp.responseText;
295 //USED BY NEWORDEREMPTY.PL
296 function totalExceedsBudget(budgetId, total) {
299 xmlhttp = new XMLHttpRequest();
300 if ( typeof xmlhttp.overrideMimeType != 'undefined') {
301 xmlhttp.overrideMimeType('text/xml');
304 var url = '../acqui/check_budget_total.pl?budget_id=' + budgetId + "&total=" + total;
305 xmlhttp.open('GET', url, false);
308 xmlhttp.onreadystatechange = function() {
309 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
311 actTotal = eval ( xmlhttp.responseText );
313 if ( Math.abs(actTotal) < Math.abs(total) ) {
314 // if budget is to low :(
324 //USED BY AQBUDGETS.TMPL
325 function budgetExceedsParent(budgetTotal, budgetId, newBudgetParent, periodID) {
329 xmlhttp = new XMLHttpRequest();
330 if ( typeof xmlhttp.overrideMimeType != 'undefined') {
331 xmlhttp.overrideMimeType('text/xml');
334 // make the call... yawn
335 // var url = '../admin/check_parent_total.pl?budget_id=' + budgetId + '&parent_id=' + newBudgetParent + "&total=" + budgetTotal + "&period_id="+ periodID ;
338 var url = '../admin/check_parent_total.pl?total=' + budgetTotal + "&period_id="+ periodID ;
340 if (budgetId ) { url += '&budget_id=' + budgetId };
341 if ( newBudgetParent ) { url += '&parent_id=' + newBudgetParent};
344 xmlhttp.open('GET', url, false);
347 xmlhttp.onreadystatechange = function() {
348 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
351 // wait for the call to complete
355 var result = eval ( xmlhttp.responseText );
358 return MSG_BUDGET_PARENT_ALLOCATION;
359 } else if (result == '2') {
360 return MSG_BUDGET_PERIOD_ALLOCATION;
369 //USED BY AQBUDGETS.TMPL
370 function checkBudgetParent(budgetId, newBudgetParent) {
372 xmlhttp = new XMLHttpRequest();
373 if ( typeof xmlhttp.overrideMimeType != 'undefined') {
374 xmlhttp.overrideMimeType('text/xml');
377 var url = '../admin/check_budget_parent.pl?budget_id=' + budgetId + '&new_parent=' + newBudgetParent;
378 xmlhttp.open('GET', url, false);
381 xmlhttp.onreadystatechange = function() {
382 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
383 // do something with the results
385 // wait for the call to complete
389 var result = eval ( xmlhttp.responseText );
392 return MSG_PARENT_BENEATH_BUDGET;
393 // } else if (result == '2') {
394 // return "- New budget-parent has insufficent funds\n";
400 function hideColumn(num) {
401 $("#hideall,#showall").removeAttr("checked").parent().removeClass("selected");
402 $("#"+num).parent().removeClass("selected");
403 var hide = Number(num.replace("col","")) + 2;
404 // hide header and cells matching the index
405 $("#plan td:nth-child("+hide+"),#plan th:nth-child("+hide+")").toggle();
408 function showColumn(num){
409 $("#hideall").removeAttr("checked").parent().removeClass("selected");
410 $("#"+num).parent().addClass("selected");
411 // set the index of the table column to hide
412 show = Number(num.replace("col","")) + 2;
413 // hide header and cells matching the index
414 $("#plan td:nth-child("+show+"),#plan th:nth-child("+show+")").toggle();
417 function showAllColumns(){
418 $("#selections").checkCheckboxes();
419 $("#selections span").addClass("selected");
420 $("#plan td:nth-child(2),#plan tr th:nth-child(2)").nextAll().show();
421 $("#hideall").removeAttr("checked").parent().removeClass("selected");
423 function hideAllColumns(){
424 var allCols = $("#plan th").length;
425 $("#selections").unCheckCheckboxes();
426 $("#selections span").removeClass("selected");
427 $("#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
428 $("#hideall").attr("checked","checked").parent().addClass("selected");