var years = '2002:2003:2004:2005:2006:2007:2008:2009:2010'; var selparam = ''; var alertct = 0; var seldata = new Array(); var changed_data_warning = 'THERE ARE UNSAVED CHANGES'; function dumpprops(obj, parent, recursion) { if (recursion <= 0) return(''); var msg = ''; if (parent) msg = 'Properties of ' + parent + '

\n'; else msg = 'Properties

\n'; for (var i in obj) { if (parent) { msg += '' + parent + '.' + i + ' (' + recursion + ')
\n' + obj[i] + '

\n'; } else { msg += '' + i + ' (' + recursion + ')
\n' + obj[i] + '

\n'; } if (typeof obj[i] == 'object') { if (parent) { msg += dumpprops(obj[i], parent + '.' + i, recursion - 1); } else { msg += dumpprops(obj[i], i, recursion - 1); } } } return(msg); } function listformfields(form, field) { answer = ''; eval ('myelements = document.' + form + '.elements'); for (var i = 0; i

'; } function updateaccess(reqperm, userperm, owner, user, share) { if (!reqperm.match(/update/) || !userperm) return(0); if (userperm == 'U' && user == owner) userperm = 'O'; var permlevel = strpos('EGUOADX', userperm); reqperm.replace(/^.*update:(\w).*/, "$1"); var reqpermlevel = strpos('EGUOADX', reqperm); if (permlevel >= reqpermlevel) return(1); else return(0); } function strpos(str, ch) { for (var i = 0; i < str.length; i++) if (str.substring(i, i+1) == ch) return i; return -1; } function fill_string(form, source, dest, type, template, options, editp, cssclass, onchange) { // alert('fill_string : type ' + type + ' template ' + template + ' options ' + options + ' dest ' + dest); loptions = options.replace(/\|/g, "','"); eval("var options_arr = new Array('" + loptions + "')"); var lvalue = ''; var v = 0; if (type == 'checkbox') { // alert('fill_string ' + source + ' ' + options + ' ' + editp); for (c=flag=0; c < options_arr.length; c++) { var opt_arr = options_arr[c].split('='); eval ('var cellname = document.' + form + '.' + source + '_' + opt_arr[0]); if (!cellname) { alert('Failed to update checkbox field ' + source + '.\nPlease save data or reload the page !'); return (-1); } if (cellname.checked) { if (lvalue) lvalue = lvalue + '|'; lvalue = lvalue + cellname.value; } } } else if (type == 'multiple_select') { for (v = 0; ; v++) { eval ('var cellname = document.' + form + '.' + source + '_' + v); if (!cellname) break; // alert('fill_string ' + source + ' ' + cellname.value); if (lvalue) lvalue = lvalue + '|'; lvalue = lvalue + cellname.value; } } else if (type == 'actions') { var lvalue; var plevels = new Array('', 'G', 'U', 'O', 'A', 'D'); for (v = 0; v < 30; v++) { eval ('var action = document.' + form + '.' + source + '_action_' + v); eval ('var plevel = document.' + form + '.' + source + '_plevel_' + v); if (!action || !action.value) continue; if (!plevel || plevel[0].checked) continue; // alert('fill_string ' + source + ' ' + action.value + ' ' + plevel.value); value = ''; for (l = 0; l < plevels.length; l++) if (plevel[l].checked) value = plevels[l]; if (lvalue) lvalue = lvalue + '|'; lvalue = lvalue + action.value + ':' + value; // alert('fill_string ' + lvalue); } } else if (type == 'list') { for (v = 0; ; v++) { eval ('var cellname = document.' + form + '.' + source + '_' + v); if (!cellname) break; // alert('fill_string ' + source + ' ' + cellname.value); if (lvalue) lvalue = lvalue + '|'; lvalue = lvalue + cellname.value; } } else if (type == 'options') { for (v = 0; ; v++) { eval ('var cellopt = document.' + form + '.' + source + '_opt_' + v); eval ('var celldesc = document.' + form + '.' + source + '_desc_' + v); if (!cellopt) break; if (v && !cellopt.value && !celldesc.value) continue; // alert("'" + cellopt.value + "'"); // alert('fill_string ' + source + ' ' + cellopt.value); if (lvalue) lvalue = lvalue + '|'; lvalue = lvalue + cellopt.value + '=' + celldesc.value; } // alert(lvalue); } else if (type == 'permissions') { // alert('fill_string ' + source + ' ' + options + ' ' + editp); var value; var lvalue; for (v = 0; v < 30; v++) { eval ('var user = document.' + form + '.' + source + '_user_' + v); eval ('var perm = document.' + form + '.' + source + '_perm_' + v); if (!user || !user.value) continue; if (!perm || !perm[0] || !perm[1] || !perm[2] || perm[0].checked) continue; if (perm[1].checked) value = 'view'; if (perm[2].checked) value = 'update'; // alert("'" + user.value + "' '" + perm[2].checked + "' '" + value + "'"); // alert(dumpprops(perm, 'perm', 1)); // alert('fill_string ' + source + ' ' + user.value); if (lvalue) lvalue = lvalue + '|'; lvalue = lvalue + user.value + ':' + value; } // alert(lvalue); } else if (type == 'radio') { // alert('fill_string ' + source + ' ' + options + ' ' + editp); for (c=flag=0; c < options_arr.length; c++) { var opt_arr = options_arr[c].split('='); eval ('var cellname = document.' + form + '.' + source + '[' + c + ']'); if (!cellname) { eval ('var cellname = document.' + form + '.' + source); // alert(cellname); if (!cellname) { alert('Failed to update radio field ' + source + '.\nPlease save data or reload the page !'); return (-1); } else lvalue = cellname.value; } else if (cellname.checked) { lvalue = cellname.value; } // alert(source + '[' + c + ']' + ' ' + cellname.checked + ' ' + cellname.value); } } else if (type == 'date') { eval ('var yearcell = document.' + form + '.' + source + '_year'); eval ('var monthcell = document.' + form + '.' + source + '_month'); eval ('var daycell = document.' + form + '.' + source + '_day'); if (yearcell.value || monthcell.value || daycell.value) lvalue = yearcell.value + '/' + monthcell.value + '/' + daycell.value; else lvalue = ''; } else if (type == 'component') { eval ('var cellname = document.' + form + '.' + source + '_name'); eval ('var cellconc = document.' + form + '.' + source + '_conc'); eval ('var cellph = document.' + form + '.' + source + '_ph'); if (cellname.value == 'random') { lvalue = 'random:::'; } else if (cellname.value || cellconc.value || cellph.value) { if (stock_UNIT[cellname.value] == 'M') var conc = fmtF(cellconc.value, 6); else if (stock_UNIT[cellname.value].match(/%/)) var conc = fmtF(cellconc.value, 3); else if (stock_UNIT[cellname.value] == 'mg/ml') var conc = fmtF(cellconc.value, 3); if (cellph.value) var ph = fmtF(cellph.value, 2); else ph = ''; lvalue = cellname.value + ':' + conc + ':' + stock_UNIT[cellname.value] + ':' + ph; } else lvalue = ''; // alert(lvalue); } else if (type == 'componentvol') { eval ('var cellname = document.' + form + '.' + source + '_name'); eval ('var cellvol = document.' + form + '.' + source + '_vol'); eval ('var cellph = document.' + form + '.' + source + '_ph'); if (cellname.value == 'random') { lvalue = 'random:::'; } else if (cellname.value || cellvol.value || cellph.value) { var vol = fmtF(cellvol.value, 2); if (cellph.value) var ph = fmtF(cellph.value, 2); else ph = ''; lvalue = cellname.value + ':' + vol + ':' + stock_UNIT[cellname.value] + ':' + ph; } else lvalue = ''; // alert(cellvol.value + ' 2 ' + lvalue); } else if (type == 'volume') { eval ('var vol = document.' + form + '.' + source); if (vol.value) lvalue = fmtF(vol.value, 2); else lvalue = ''; // alert(vol.value + ' 2 ' + lvalue); } else { eval ('var cellname = document.' + form + '.' + source); if (!cellname) { alert('Failed to update text field ' + source + '.\nPlease save data or reload the page !'); return (-1); } lvalue = cellname.value; // alert(lvalue); } reset_string(form, dest, lvalue, type, template, options, editp, cssclass, onchange); return(0); } function fill_form(form, fld, type, template, options, editp, cssclass, onchange) { //alert('fill_form : options ' + options); // alert('fill_form ' + form + ', ' + fld + ', type ' + type + ', template ' + template + ', options ' + options + ', editp ' + editp + ', onchange ' + onchange); restore_cell(); eval ("mydiv = document.getElementById('div_" + fld + "')"); if (!mydiv) { if (++alertct < 5) alert('failed to access field ' + fld); return; } if (type != 'checkbox' && type != 'date' && type != 'multiple_select' && type != 'actions' && type != 'list' && type != 'options' && type != 'permissions' && type != 'component' && type != 'componentvol') { eval ('cellname = document.' + form + '.' + fld); if (!cellname) { alert('fill_form: Failed to update field ' + fld + '.\nPlease save data or reload the page !'); return; } if (type != 'textspec' && type != 'html' && type != 'email' && type != 'template') cellname.value = cellname.value.replace(/"/g, """); } loptions = options.replace(/\|/g, "','"); eval("var options_arr = new Array('" + loptions + "')"); var output = ''; var v = 0; if (type == 'text' || type == 'html' || type == 'email' || type == 'template') output = ' '; else if (type == 'float' || type == 'int' || type == 'bigint' || type == 'tinyint') output = ' '; else if (type == 'password') output = ' '; else if (type == 'textarea' || type == 'textspec') output = ''; else if (type == 'select') { // alert('fill_form ' + form + ', ' + fld + ', type ' + type + ', options ' + options + ', editp ' + editp + ', onchange ' + onchange); output = ''; } else if (type == 'component') { // alert('fill_form ' + form + ', ' + fld + ', type ' + type + ', options ' + options + ', editp ' + editp + ', onchange ' + onchange); eval ('var cellname = document.' + form + '.' + fld + '_name'); eval ('var cellconc = document.' + form + '.' + fld + '_conc'); eval ('var cellph = document.' + form + '.' + fld + '_ph'); output = ''; if (stock_UNIT[cellname.value]) output += '
' + stock_UNIT[cellname.value] + '
'; else output += '
'; output += ' '; // alert(output); output += '
' + ' pH ' + '
'; } else if (type == 'componentvol') { // alert('fill_form ' + form + ', ' + fld + ', type ' + type + ', options ' + options + ', editp ' + editp + ', onchange ' + onchange); eval ('var cellname = document.' + form + '.' + fld + '_name'); eval ('var cellvol = document.' + form + '.' + fld + '_vol'); eval ('var cellph = document.' + form + '.' + fld + '_ph'); output = ' µl'; if (stock_CONC[cellname.value] && stock_UNIT[cellname.value]) output += '
' + compose_value(stock_CONC[cellname.value], stock_UNIT[cellname.value]) + '
'; else output += '
'; // alert(output); output += ' '; // alert(output); output += '
' + ' pH ' + '
'; } else if (type == 'volume') { // alert('fill_form ' + form + ', ' + fld + ', type ' + type + ', options ' + options + ', editp ' + editp + ', onchange ' + onchange); eval ('var vol = document.' + form + '.' + fld); output = ' µl'; // alert(output); } else if (type == 'multiple_select') { for (v = 0; ; v++) { eval ('var cellname = document.' + form + '.' + fld + '_' + v); if (!cellname) break; output += ''; } } else if (type == 'actions') { var plevels = new Array('', 'G', 'U', 'O', 'A', 'D'); var levdesc = new Array('nobody', 'guest', 'user', 'owner', 'admin', 'developer'); for (v = 0; ; v++) { eval ('var action = document.' + form + '.' + fld + '_action_' + v); eval ('var plevel = document.' + form + '.' + fld + '_plevel_' + v); if (!action) break; output += ''; lvalue = ''; if (!plevel.value) plevel.value = ''; // alert(fld + ' ' + action.value + ' ' + plevel.value); for (l=0; l < plevels.length; l++) { if (plevel.value == plevels[l]) checked = 'checked'; else checked = ''; lvalue += levdesc[l] + '\n'; } output += lvalue + '
'; if (!action.value) break; } } else if (type == 'list') { for (v = 0; ; v++) { eval ('var cellname = document.' + form + '.' + fld + '_' + v); if (!cellname) break; output += ' '; // alert(fld + ' ' + cellname.value); } // alert(output); } else if (type == 'options') { var nopt = 0; for (v = 0; ; v++) { eval ('var cellopt = document.' + form + '.' + fld + '_opt_' + v); eval ('var celldesc = document.' + form + '.' + fld + '_desc_' + v); if (!cellopt) break; if (!cellopt.value && v && nopt) break; output += ' '; output += ''; output += '
'; if (cellopt.value) nopt = 0; else nopt++; // alert(fld + ' ' + cellname.value); } output += ' '; output += ''; output += '
'; } else if (type == 'permissions') { var lvalue; var newoptions_arr = new Array(); for (c=ct=0; c < options_arr.length; c++) { newoptions_arr[ct++] = options_arr[c]; if (options_arr[c] == '=') { newoptions_arr[ct++] = 'all='; newoptions_arr[ct++] = 'group='; } } options_arr = newoptions_arr; output += ''; for (var v = 0; v < 30; v++) { lvalue = ''; eval ('var user = document.' + form + '.' + fld + '_user_' + v); eval ('var perm = document.' + form + '.' + fld + '_perm_' + v); if (!user || !perm) continue; // alert(fld + ' ' + user.value + ' ' + perm.value); lvalue += "\n"; if (!user.value || !perm.value) checked = 'checked'; else checked = ''; lvalue += '\n'; lvalue += ''; output += lvalue; // alert(lvalue); } output += '
\n"; // alert(user_opt[0] + ' ' + user.value + ' ' + perm.value); lvalue += ''; lvalue += "none' + '\n'; if (user.value && perm.value == 'view') checked = 'checked'; else checked = ''; lvalue += 'view' + '\n'; if (user.value && perm.value == 'update') checked = 'checked'; else checked = ''; lvalue += 'edit' + '
'; // alert(output); } else if (type == 'checkbox') { // alert(options); for (c=0; c < options_arr.length; c++) { var opt_arr = options_arr[c].split('='); if (!opt_arr[1]) opt_arr[1] = opt_arr[0]; if (!focus_on) var focus_on = opt_arr[0]; eval ('var cellname = document.' + form + '.' + fld + '_' + opt_arr[0]); if (cellname.checked) { checked = 'checked'; focus_on = opt_arr[0]; } else checked = ''; // alert(cellname.value + ' --- ' + opt_arr[0] + ' --- ' + cellname.checked); output += opt_arr[1] + '\n'; } // alert(output); } else if (type == 'radio') { var focus_on = 0; for (c=0; c < options_arr.length; c++) { var opt_arr = options_arr[c].split('='); if (!opt_arr[1]) opt_arr[1] = opt_arr[0]; // eval ('var tmp = document.' + form + '.' + fld + '[' + c + ']'); // alert('document.' + form + '.' + fld + '[' + c + ']' + ': ' + tmp); // alert(options + ' ' + fld + ' ' + cellname + ' ' + cellname.value); if (cellname.value == opt_arr[0]) { checked = 'checked'; var focus_on = c; } else checked = ''; // alert('document.' + form + '.' + fld + '.value' + ': ' + cellname.value + ' - ' + opt_arr[0] + ' - ' + checked); output += opt_arr[1] + '\n'; } // alert(output); } else if (type == 'date') { yearopts = years.split(':'); eval ('var cellname = document.' + form + '.' + fld + '_year'); output = ''; eval ('var cellname = document.' + form + '.' + fld + '_month'); output += ''; eval ('var cellname = document.' + form + '.' + fld + '_day'); output += ''; } output += ''; mydiv.innerHTML = output; // alert(onchange); if (type == 'component' || type == 'componentvol') { eval ("mydivph = document.getElementById('div_" + fld + "_ph')"); if (stock_CLASSES[cellname.value] && stock_CLASSES[cellname.value].match(/buffer/)) mydivph.style.display = ''; else mydivph.style.display = 'none'; } if (type == 'radio') eval ('var focusfld = \'' + fld + '[' + focus_on + ']\''); else if (type == 'checkbox') eval ('var focusfld = \'' + fld + '_' + focus_on + '\''); else var focusfld = fld; focus_on_fld(form, focusfld, type); seldata = new Array(form, fld, type, template, options, editp, cssclass, onchange); } function restore_cell() { // alert('restore_cell ' + seldata[0] + ', fld ' + seldata[1] + ', type ' + seldata[2] + ', template ' + seldata[3] + ', options ' + seldata[4] + ', editp ' + seldata[5] + ', cssclass ' + seldata[6]); if (seldata[0]) { fill_string(seldata[0], seldata[1], seldata[1], seldata[2], seldata[3], seldata[4], seldata[5], seldata[6], seldata[7]); seldata[0] = ""; } } function reset_string(form, fld, value, type, template, options, editp, cssclass, onchange) { var output = ''; onchange = onchange.replace(/'/g, '\\\''); eval ("mydiv = document.getElementById('div_" + fld + "')"); value = unescape(value); options = unescape(options); // alert(value); // alert(options); // alert(fld); if (!mydiv) { if (++alertct < 2) alert('failed to access div box div_' + fld); return; } if (type == 'file' || type == 'multiplefiles') { if ((type == 'file' && value == '') || type == 'multiplefiles') mydiv.innerHTML = 'new file: '; return; } if (editp) output = ""; loptions = options.replace(/\|/g, "','"); eval("var options_arr = new Array('" + loptions + "')"); if (type == 'checkbox') { // alert(fld + ': ' + options + ' - ' + loptions); var evalme = ''; var flag = 0; for (var c=0; c < options_arr.length; c++) { var opt_arr = options_arr[c].split('='); if (!opt_arr[1]) opt_arr[1] = opt_arr[0]; // alert('reset_string: ' + value + ' - ' + opt_arr[0]); if (value.match("(^|\\|)" + opt_arr[0] + "(\\||$)")) { checked = 'checked'; lvalue = opt_arr[0]; } else { checked = ''; lvalue = ''; } if (checked) { if (flag) output += ', '; output += opt_arr[1]; flag = 1; } // if (editp) output += ''; } if (!flag) if (editp) output += 'edit'; else output += ' '; // alert('reset_string: ' + output); } else if (type == 'select') { for (c=flag=0; c < options_arr.length; c++) { // alert(options_arr[c]); var opt_arr = options_arr[c].split('='); if (!opt_arr[1]) opt_arr[1] = opt_arr[0]; if (value == opt_arr[0]) { if (opt_arr[1]) lvalue = opt_arr[1]; else if (editp) lvalue = 'edit'; else lvalue = ' '; output += lvalue; flag = 1; break; } } if (!flag) { if (value) { if (!fld.match('Selector')) { output += value; if (editp) output += '
the value \'' + value + '\' is not among the select options
'; } } else { if (editp) { output += 'edit'; if (!fld.match('Selector')) output += '
the empty value is not among the select options
'; } else { output += ' '; } } } // alert(fld); // if (editp) output += ''; // alert('reset_string ' + fld + ', value ' + value + ', type ' + type + ', options ' + options + ', editp ' + editp + ', onchange ' + onchange + '\noutput ' + output); // alert('reset_string: ' + output); } else if (type == 'radio') { for (c=flag=0; c < options_arr.length; c++) { var opt_arr = options_arr[c].split('='); if (!opt_arr[1]) opt_arr[1] = opt_arr[0]; if (value == opt_arr[0]) { if (opt_arr[1]) lvalue = opt_arr[1]; else if (editp) lvalue = 'edit'; else lvalue = ' '; output += lvalue; flag = 1; break; } } if (!flag) if (value) { if (!fld.match('Selector')) { output += value; if (editp) output += '
the value \'' + value + '\' is not among the select options
'; } } else if (editp) { output += 'edit'; if (!fld.match('Selector')) output += '
the empty value is not among the select options
'; } // if (editp) output += ''; // alert(fld + ', ' + value + ', ' + type + ', ' + options + ', ' + editp + ', ' + output); } else if (type == 'multiple_select') { // alert(value + ' ' + editp); var val_arr = value.split('|'); var liststart = 1; var listend = 0; var lvalue; for (v = 0; v <= val_arr.length; v++) { lvalue = ''; if (listend) break; if (val_arr[v]) { // alert(v + ' ' + val_arr[v]); for (c = flag = 0; c < options_arr.length; c++) { var opt_arr = options_arr[c].split('='); if (!opt_arr[1]) opt_arr[1] = opt_arr[0]; if (val_arr[v] == opt_arr[0]) { if (opt_arr[1]) lvalue = opt_arr[1]; flag = 1; break; } } if(!flag) { lvalue = val_arr[v]; if (editp) if (lvalue) output += '
the value \'' + lvalue + '\' is not among the select options
'; else output += 'edit' + '
the empty value is not among the select options
'; } if (!liststart) output += ', '; // if (editp) lvalue += ''; } else { if (editp && liststart) lvalue = 'edit'; listend = 1; if (editp) lvalue += ''; } // alert('reset_string: ' + ''); // alert(lvalue); output += lvalue; liststart = 0; } // alert(output); } else if (type == 'actions') { // alert(value + ' ' + editp); var levdesc = {'':'nobody', 'G':'guest', 'U':'user', 'O':'owner', 'A':'admin', 'D':'developer'}; var val_arr = value.split('|'); var liststart = 1; var listend = 0; var lvalue; for (v = 0; v <= val_arr.length; v++) { if (listend) break; lvalue = ''; if (val_arr[v]) { var act_arr = val_arr[v].split(':'); if (!act_arr[1]) act_arr[1] = ''; // alert(v + ' ' + val_arr[v] + ' ' + act_arr[0] + ' ' + act_arr[1]); for (c = flag = 0; c < options_arr.length; c++) { var opt_arr = options_arr[c].split('='); if (!opt_arr[1]) opt_arr[1] = opt_arr[0]; if (act_arr[0] == opt_arr[0]) { if (opt_arr[1]) lvalue = opt_arr[1] + ' (' + levdesc[act_arr[1]] + ')'; flag = 1; break; } } if(!flag) { lvalue = act_arr[0] + ' (' + levdesc[act_arr[1]] + ')'; if (editp) if (act_arr[0]) output += '
the value \'' + lvalue + '\' is not among the select options
'; else output += 'edit' + '
the empty value is not allowed here
'; } if (!liststart) output += ', '; // if (editp) { lvalue += ''; lvalue += ''; // } } else { if (editp && liststart) lvalue = 'edit'; listend = 1; if (editp) { lvalue += ''; lvalue += ''; } } // alert('reset_string: ' + ''); // alert(lvalue); output += lvalue; liststart = 0; } // alert(output); } else if (type == 'list') { // alert(value + ' ' + editp); var val_arr = value.split('|'); var liststart = 1; var listend = 0; var lvalue; for (v = 0; v <= val_arr.length; v++) { lvalue = ''; if (listend) break; // alert(val_arr[v]); if (val_arr[v]) { lvalue = val_arr[v]; } else { if (editp && liststart) lvalue = 'edit'; listend = 1; val_arr[v] = ''; } if (lvalue && !liststart) output += ', '; // if (editp) lvalue += ''; // alert('reset_string: ' + ''); output += lvalue; liststart = 0; } if (val_arr.length == 1 && val_arr[0] == '' && !editp) output += ' '; // alert(output); } else if (type == 'options') { var flag = 1; if (value) { var val_arr = value.split('|'); for (v = 0; v < val_arr.length; v++) { // alert(val_arr[v]); var lvalue = ''; var opt_arr = val_arr[v].split('='); if (v && (opt_arr[0] || opt_arr[1])) lvalue += ', '; if (opt_arr[0]) { lvalue += '"' + opt_arr[0] + '"'; flag = 0; } if (editp) lvalue += ''; if (opt_arr[1]) { lvalue += ' ('+ opt_arr[1] + ')'; flag = 0; } // if (editp) lvalue += ''; output += lvalue; // alert('reset_string: ' + ''); // alert(lvalue); } } if (flag) output += 'edit'; // alert(output); } else if (type == 'permissions') { flag = 0; var liststart = 1; var lvalue; var val_arr = value.split('|'); options_arr[options_arr.length] = 'all='; options_arr[options_arr.length] = 'group='; // alert(val_arr); for (v = 0; v <= val_arr.length; v++) { lvalue = ''; if (val_arr[v]) { var val_parts = val_arr[v].split(':'); if (!val_parts[0]) val_arr[v] = ''; } if (val_arr[v]) { for (c = flag = 0; c < options_arr.length; c++) { var opt_arr = options_arr[c].split('='); if (!opt_arr[1]) opt_arr[1] = opt_arr[0]; if (val_parts[0] == opt_arr[0]) { lvalue = opt_arr[1]; flag = 1; break; } } if(lvalue) { if (val_parts[1] == 'view') lvalue += ': ' + 'view'; if (val_parts[1] == 'update') lvalue += ': ' + 'edit'; } else { lvalue = val_parts[0]; if (editp) if (val_parts[0]) lvalue += '
the username \'' + val_parts[0] + '\' is not among the select options
'; else lvalue += 'edit' + '
the empty value is not among the select options
'; } if (!liststart) output += ', '; } else if (v != val_arr.length) continue; if (v == val_arr.length) { var val_parts = new Array('', ''); if (liststart) if (editp) lvalue = 'edit'; else lvalue = ' '; } // if (editp) { lvalue += ''; lvalue += ''; // } // alert(lvalue); output += lvalue; liststart = 0; } // alert(output); // alert(fld + ', ' + value + ', ' + type + ', ' + options + ', ' + editp + '\n' + output); } else if (type == 'multiple_component') { flag = 0; // alert(value); var set = value.split('\|'); for (i=0; i < set.length; i++) { if (i) output += ', '; if (value) { var val_r = set[i].split(':'); var name = val_r[0]; var conc = val_r[1]; var unit = val_r[2]; var ph = val_r[3]; var lvalue = ''; if (name) { if (name == 'random') conc = ph = ''; else { if (conc.match(/^[\d.]*$/)) lvalue += compose_value(parseFloat(conc), unit) + ' '; else lvalue += conc + ' ' + unit + ' '; } lvalue += name; if (ph) { if (ph == 'random') lvalue += ', random pH'; else if (ph) { if (ph.match(/^[\d.]*$/)) lvalue += ', pH ' + fmtF(ph, 2); else lvalue += ', pH ' + ph; } } } else { lvalue = ' '; name = conc = ph = ''; } output += lvalue; // alert(lvalue); } else { name = conc = ph = ''; output += ' '; } } // alert('reset_string ' + fld + ', value ' + value + ', type ' + type + ', options ' + options + ', editp ' + editp + ', onchange ' + onchange + '\noutput ' + output); // alert('reset_string: ' + output); // alert(output); // alert(fld + ', ' + value + ', ' + type + ', ' + options + ', ' + editp + '\n' + output); } else if (type == 'component') { flag = 0; // alert(value); if (value) { var val_r = value.split(':'); var name = val_r[0]; var conc = val_r[1]; var unit = val_r[2]; var ph = val_r[3]; var lvalue = ''; if (name) { if (name == 'random') conc = ph = ''; else { if (conc > 0) { lvalue += compose_value(conc, unit) + ' '; if (stock_CONC[name] && stock_CONC[name] > 0 && parseFloat(stock_CONC[name]) < conc && (conc < 100 || !(unit == '%w/v' || unit == '%v/v'))) { lvalue += '
concentration ' + compose_value(conc, unit) + ' exceeds stock concentration (' + compose_value(stock_CONC[name], unit) + ')
'; alert(name + ": " + stock_CONC[name] + " < " + conc); } } else lvalue += '
no concentration
'; } lvalue += name; if (ph) { if (name && editp && (!stock_CLASSES[name] || !stock_CLASSES[name].match(/buffer/))) { lvalue += '
component \'' + name + '\' is not a buffer, ignoring ph \'' + ph + '\'
'; ph = ''; } if (ph == 'random') lvalue += ', random pH'; else if (ph) { lvalue += ', pH ' + fmtF(ph, 2); if (editp && (ph < 0 || ph > 14)) { lvalue += '
the pH must be between 0 and 14
'; // alert(name + ": " + stock_CONC[name] + " < " + conc); } } } } else { if (editp) lvalue = 'edit'; else lvalue = ' '; name = conc = ph = ''; } for (c=flag=0; c < options_arr.length; c++) { if (name == options_arr[c]) { flag = 1; break; } } if (!flag && name) { lvalue += '
\'' + name + '\' is either not defined or an invalid choice
'; // alert(options); } output += lvalue; // alert(lvalue); } else { name = conc = ph = ''; if (editp) output += 'edit'; else output += ' '; } output += ' '; output += ' '; output += ' '; // if (editp) { output += ''; output += ''; output += ''; // } // alert('reset_string ' + fld + ', value ' + value + ', type ' + type + ', options ' + options + ', editp ' + editp + ', onchange ' + onchange + '\noutput ' + output); // alert('reset_string: ' + output); // alert(output); // alert(fld + ', ' + value + ', ' + type + ', ' + options + ', ' + editp + '\n' + output); } else if (type == 'componentvol') { flag = 0; // alert(value); if (value) { var val_r = value.split(':'); var name = val_r[0]; var vol = val_r[1]; var unit = val_r[2]; var ph = val_r[3]; var lvalue = ''; if (name) { if (name == 'random') vol = ph = ''; else { if (parseFloat(vol)) { lvalue += '' + compose_value(parseFloat(vol), 'ul') + ' '; // alert(vol + ' - ' + parseFloat(vol) + ' - ' + compose_value(parseFloat(vol), 'ul')); } else lvalue += '
no volume
'; lvalue += compose_value(stock_CONC[name], unit) + ' '; } lvalue += name; if (ph) { if (!stock_CLASSES[name] || !stock_CLASSES[name].match(/buffer/)) { lvalue += '
component \'' + name + '\' is not a buffer, ignoring ph \'' + ph + '\'
'; ph = ''; } if (ph == 'random') lvalue += ', random pH'; else if (ph) lvalue += ', pH ' + fmtF(ph, 2); } } else { if (editp) lvalue = 'edit'; else lvalue = ' '; name = vol = ph = ''; } for (c=flag=0; c < options_arr.length; c++) { if (name == options_arr[c]) { flag = 1; break; } } if (!flag && name) lvalue += '
\'' + name + '\' is either not defined or an invalid choice
'; output += lvalue; } else { name = vol = ph = ''; if (editp) output += 'edit'; else output += ' '; } output += ' '; output += ' '; output += ' '; // if (editp) { output += ''; output += ''; output += ''; // } // alert('reset_string ' + fld + ', value ' + value + ', type ' + type + ', options ' + options + ', editp ' + editp + ', onchange ' + onchange + '\noutput ' + output); // alert('reset_string: ' + output); // alert(output); // alert(fld + ', ' + value + ', ' + type + ', ' + options + ', ' + editp + '\n' + output); } else if (type == 'volume') { // alert(value); if (value && parseFloat(value)) { output += compose_value(parseFloat(value), 'ul') + ' '; // alert(value + ' - ' + parseFloat(value) + ' - ' + compose_value(parseFloat(value), 'ul')); } else { if (editp) output += 'edit'; else output += ' '; } // if (editp) output += ''; // alert('reset_string: ' + output); } else if (type == 'date') { yearopts = years.split(':'); if (value) { matches = value.split('/'); if (!matches[0] && !matches[1] && !matches[2]) lvalue = 'edit'; else lvalue = value; } else { matches = new Array('', '', ''); if (editp) lvalue = 'edit'; else lvalue = ' '; } output += lvalue; // if (editp) { output += '\n'; output += '\n'; output += '\n'; // } // alert(fld + ', ' + value + ', ' + type + ', ' + options + ', ' + editp + '\n' + output); } else if (type == 'password') { value = value.replace(/"/g, """); if (value) lvalue = '********'; else if (editp) lvalue = 'edit'; else lvalue = ' '; lvalue = lvalue.replace(/(\r?\n)+/g, ''); output += lvalue; if (editp) output += ''; } else if (type == 'textarea') { value = value.replace(/"/g, """); if (value) lvalue = value; else if (editp) lvalue = 'edit'; else lvalue = ' '; // alert(lvalue); lvalue = lvalue.replace(/(\r?\n)/g, '
'); output += lvalue; // if (editp) output += ''; // alert(output); } else if (type == 'textspec') { if (editp) lvalue = 'edit

'; else lvalue = ' '; output += lvalue; // alert(output); var text = value.replace(/(\r?\n)+/g, '
'); text += ''; var evalme = "document." + form + "." + fld + ".style.display = 'none'; "; // alert(text); // alert(fld + ', ' + value + ', ' + type + ', ' + options + ', ' + editp); } else if (type == 'html') { text = '
' + value + ''; if (editp) output += 'edit '; // alert(output); // if (editp) output += ''; // alert(fld + ', ' + value + ', ' + type + ', ' + options + ', ' + editp); } else if (type == 'email') { text = '' + value + ''; if (editp) output += 'edit '; // alert(output); // if (editp) output += ''; // alert(fld + ', ' + value + ', ' + type + ', ' + options + ', ' + editp); } else if (type == 'template') { if (value != '') { template = unescape(template); text = ' ' + template.replace(/<\*value\*>/g, value); } if (value) lvalue = value; else if (editp) lvalue = 'edit'; else lvalue = ' '; // alert(lvalue); lvalue = lvalue.replace(/(\r?\n)/g, ''); output += lvalue; // alert(output); // if (editp) output += ''; // alert(fld + ', ' + value + ', ' + type + ', ' + options + ', ' + editp); } else if (type == 'float') { // alert(value); if (value != '') lvalue = value; else if (editp) lvalue = 'edit'; else lvalue = ' '; lvalue = lvalue.replace(/(\r?\n)/g, ''); if (lvalue != 'edit') { // alert(lvalue); lvalue = fmtF(lvalue, 10); // alert(lvalue); } output += lvalue; // if (editp) output += ''; // alert(output); // alert(fld + ', ' + value + ', ' + type + ', ' + options + ', ' + editp); } else if (type == 'int' || type == 'bigint' || type == 'tinyint') { // alert(value); if (value != '') lvalue = value; else if (editp) lvalue = 'edit'; else lvalue = ' '; lvalue = lvalue.replace(/(\r?\n)/g, ''); if (lvalue != 'edit') { // alert(lvalue); lvalue = fmtF(lvalue, 0); // alert(lvalue); } output += lvalue; // if (editp) output += ''; // alert(output); // alert(fld + ', ' + value + ', ' + type + ', ' + options + ', ' + editp); } else { // alert('reset_string ' + fld + ', value ' + value + ', type ' + type + ', template ' + template + ', options ' + options + ', editp ' + editp); // if (value.match(/nad/i)) // alert(value + ', ' + unescape(value)); value = value.replace(/"/g, """); // alert(value); if (value) lvalue = value; else if (editp) lvalue = 'edit'; else lvalue = ' '; // alert(lvalue); lvalue = lvalue.replace(/(\r?\n)/g, ''); output += lvalue; // if (editp) output += ''; // if (value.match(/nad/i)) // alert(output); // alert(fld + ', ' + value + ', ' + type + ', ' + options + ', ' + editp); } if (editp) output += ''; // alert(output); mydiv.innerHTML = output; // alert(mydiv.innerHTML); if (text) mydiv.innerHTML += text; //if(type=='select') //alert('reset_string: ' + mydiv + ' ' + mydiv.innerHTML); //if (fld == 'Options_28') { // alert(mydiv.innerHTML); //} if (type == 'checkbox' || type == 'textspec') eval(evalme); } function calc_recipe(field, conc, stockconc, unit, name, volume, formula, molweight, density) { // alert(field + ' ' + conc + ' ' + stockconc + ' ' + unit + ' ' + name + ' ' + volume + ' ' + formula + ' ' + molweight + ' ' + density); eval ('mydiv_recipe = document.getElementById(\"' + field + '\")'); if (!name || !conc) { mydiv_recipe.innerHTML = ' '; return; } if (!unit) { mydiv_recipe.innerHTML = 'Need stock unit for ' + name + ' '; return; } if (conc <= 0) { mydiv_recipe.innerHTML = ' '; return; } if (conc == '100' && (unit == '%w/v' || unit == '%v/v')) { mydiv_recipe.innerHTML = ' '; return; } if (volume <= 0) { mydiv_recipe.innerHTML = 'Need volume to calculate recipe '; return; } var output = ''; var amount = ''; if (stockconc > 0) { if (conc <= parseFloat(stockconc)) output += '' + compose_value(conc / stockconc * volume, 'ml') + ' ' + stockconc + ' ' + unit + ' ' + name; else output += '

concentration ' + compose_value(conc, unit) + ' exceeds stock concentration (' + compose_value(stockconc, unit) + ')
'; } // alert(volume); // alert(conc + ' ' + stockconc + ' ' + volume); if (unit == '%w/v') { amount = '' + compose_value(conc * volume * 10, 'mg') + ' ' + name + ' / ' + compose_value(volume, 'ml'); if (density > 0) amount += ', ' + compose_value(conc * volume * 10.0 / density, 'ul') + ' ' + name + ' / ' + compose_value(volume, 'ml'); if (output) output += ' (' + amount + ')'; else output = amount; } else if (unit == '%v/v') { if (stockconc <= 100) amount = '' + compose_value(conc * volume * 10, 'ul') + ' ' + name + ' / ' + compose_value(volume, 'ml'); // alert(density); if (density > 0) { if (amount) amount += ', '; amount += '' + compose_value(conc * volume * density * 10, 'mg') + ' ' + name + ' / ' + compose_value(volume, 'ml'); } if (amount) { if (output) output += ' (' + amount + ')'; else output = amount; } } else if (unit == 'M') { if (molweight > 0) { // alert((conc * molweight * volume) + ' mg'); amount = '' + compose_value(conc * molweight * volume, 'mg') + ' ' + formula + ' / ' + compose_value(volume, 'ml'); if (density > 0) amount += ', ' + compose_value(conc * molweight * volume / density, 'ul') + ' ' + formula + ' / ' + compose_value(volume, 'ml'); } else { amount = 'Need molecular weight for ' + name + ''; } if (output) output += ' (' + amount + ')'; else output = amount; } else if (unit == 'mg/ml') { amount = '' + compose_value(conc * volume, 'mg') + ' ' + name + ' / ' + compose_value(volume, 'ml'); if (density > 0) amount += ', ' + compose_value(conc * volume / density, 'ul') + ' ' + name + ' / ' + compose_value(volume, 'ml'); if (output) output += ' (' + amount + ')'; else output = amount; } // alert(output); if (output) mydiv_recipe.innerHTML = output; else mydiv_recipe.innerHTML = ' '; } function convert_value(value, unit, targetunit, molweight, density) { if (!value || !unit || unit == targetunit) return (''); if (unit == 'M') { if (targetunit == 'mg/ml' && molweight) return(value * molweight); if (targetunit == '%w/v' && molweight && value * molweight / 10.0 <= 100.0) return(value * molweight / 10.0); if (targetunit == '%v/v' && molweight && density && value * molweight / (10.0 * density) <= 100.0) return(value * molweight / (10.0 * density)); } if (unit == 'mg/ml') { if (targetunit == 'M' && molweight) return(value / molweight); if (targetunit == '%w/v' && value / 10.0 <= 100.0) return(value / 10.0); if (targetunit == '%v/v' && density && value / (10.0 * density) <= 100.0) return(value / (10.0 * density)); } if (unit == '%w/v') { if (targetunit == 'mg/ml') return(value * 10.0); if (targetunit == 'M' && molweight) return(value * 10.0 / molweight); if (targetunit == '%v/v' && density && value / density <= 100.0) return(value / density); } if (unit == '%v/v') { if (targetunit == 'M' && molweight && density) return(value * density * 10.0 / molweight); if (targetunit == 'mg/ml' && density) return(value * density * 10.0); if (targetunit == '%w/v' && density && value * density <= 100.0) return(value * density); } if (unit == 'mol') { if (targetunit == 'g' && molweight) return(value * molweight); if (targetunit == 'ml' && molweight && density) return(value * molweight / density); } if (unit == 'g') { if (targetunit == 'mol' && molweight) return(value / molweight); if (targetunit == 'ml' && density) return(value / density); } if (unit == 'ml') { if (targetunit == 'mol' && molweight && density) return(value * density / molweight); if (targetunit == 'g' && density) return(value * density); } return (''); } function compose_value(value, unit) { if (unit == '%v/v' || unit == '%w/v' || unit == '%') return (fmtF(value, 3) + ' ' + unit); if (!unit) return (value); var ct; var fmtvalue; if (unit.match(/^\w\S+$/)) { var modifier = unit.substring(0,1); var SI_unit = unit.substring(1); } else { var modifier = ''; var SI_unit = unit; } if (SI_unit != 'M' && SI_unit != 'l' && SI_unit != 'g' && SI_unit != 'B' && SI_unit != 'g/ml') return (value + ' ' + unit); value = fmtunit(value, unit); // alert(value + ' ' + unit); var modif_arr = {'-4':'p', '-3':'n', '-2':'u', '-1':'m', '0':'', '1':'k', '2':'M', '3':'G', '4':'T'}; var prec = 9; if (SI_unit == 'l') var prec = 8; if (SI_unit == 'g') var prec = 6; if (SI_unit == 'B') var prec = 0; if (SI_unit == 'M') var prec = 6; if (SI_unit == 'g/ml') var prec = 6; for (ct = -4; ct <= 4; ct++) if (modifier == modif_arr[ct]) break; var orig_ct = ct; prec += ct * 3; modif_arr['-2'] = 'µ'; if (value == 0) return ('0 ' + modif_arr[ct] + SI_unit); fmtvalue = value; while (fmtvalue < 1.0) { if (--ct == -4) break; fmtvalue *= 1000.0; prec -= 3; } while (fmtvalue >= 1000.0) { if (++ct == 4) break; fmtvalue /= 1000.0; prec += 3; } if (prec > 3) prec = 3; fmtvalue = fmtF(fmtvalue, prec); // alert(value + ' ' + unit + ' ' + prec + ' ' + ct + ' ' + fmtvalue); if (fmtvalue == 0) return ('0 ' + modif_arr[orig_ct] + SI_unit); else return (fmtvalue + ' ' + modif_arr[ct] + SI_unit); } function fmtunit(value, unit) { if (unit == '%v/v' || unit == '%w/v' || unit == '%') return (fmtF(value, 3)); if (!unit || !value) return (value); var ct; var fmtvalue; if (unit.match(/^\w\S+$/)) { var modifier = unit.substring(0,1); var SI_unit = unit.substring(1); } else { var modifier = ''; var SI_unit = unit; } if (SI_unit != 'M' && SI_unit != 'l' && SI_unit != 'g' && SI_unit != 'B' && SI_unit != 'g/ml') return (value); var modif_arr = {'-4':'p', '-3':'n', '-2':'u', '-1':'m', '0':'', '1':'k', '2':'M', '3':'G', '4':'T'}; var prec = 10; if (SI_unit == 'l') var prec = 8; if (SI_unit == 'g') var prec = 6; if (SI_unit == 'B') var prec = 0; if (SI_unit == 'M') var prec = 6; if (SI_unit == 'g/ml') var prec = 6; for (ct = -4; ct <= 4; ct++) if (modifier == modif_arr[ct]) break; prec += ct * 3; fmtvalue = fmtF(value, prec); // alert(value + ' ' + unit + ' ' + prec + ' ' + ct + ' ' + fmtvalue); return (fmtvalue); } function fmtF(value, prec) { if (value == '') return(value); // alert(value + ' ' + prec); var s; var zeros = ''; var i = parseFloat(value); if(isNaN(i)) { i = 0; } var minus = ''; if(i < 0) { minus = '-'; } i = Math.abs(i); var factor = Math.pow(10, prec); // while (factor * i > Math.pow(10, prec)) // factor /= 10; // alert(i + ' ' + prec + ' ' + factor); for (x = 0; x < prec; x++) zeros = zeros + '0'; i = parseInt((i + 0.5/factor) * factor); i = i / factor; s = new String(i); if(s.indexOf('.') < 0 && zeros) { s += '.' + zeros; } if(s.indexOf('.') == (s.length - prec)) { s += '0'; } while(s.indexOf('.') >= 0 && s.lastIndexOf('0') == s.length - 1) { s = s.substr(0, s.length-1);} if(s.indexOf('.') == (s.length - 1)) { s = s.substr(0, s.length-1); } s = minus + s; return s; } function Mod(a, b) { return a - Math.floor(a / b) * b; } function construct_selector(name, value, options, descriptors, cssclass, onchange, omit) { // alert(name + ' / ' + value + ' / ' + options + ' / ' + cssclass + ' / ' + onchange + ' / ' + omit); output = ""; // alert(output); return(output); } function construct_named_selector(name, value, options, cssclass, onchange, omit) { // alert(name + ' / ' + value + ' / ' + options + ' / ' + cssclass + ' / ' + onchange + ' / ' + omit); output = ""; // alert(output); return(output); } function validate(form, row, key, type, options, valid, str, regexdesc) { // alert(form + ' / ' + row + ' / ' + key + ' / ' + type + ' / ' + options + ' / ' + valid + ' / ' + str + ' / ' + regexdesc); var valid = valid.replace('/\\\\\|/', '%5c%7c'); var conds = valid.split('|'); for (c=flag=0; c < conds.length; c++) { conds[c] = conds[c].replace('/%5c%7c/', '|'); if ((type == 'float' || type == 'bigint' || type == 'int' || type == 'tinyint') && conds[c] == 'num') flag = 1; } if (!flag && (type == 'float' || type == 'bigint' || type == 'int' || type == 'tinyint')) conds[c] = 'num'; eval("var opts_r = new Array('" + options.replace(/\|/g, "','") + "')"); if (row) row = '_' + row; if (type == 'select') { eval('fld = document.' + form + '.' + key + row); if (!select_check_selected(fld, str)) { focus_on_fld(form, key + row, type); return(false); } } else if (type == 'radio') { eval('fld = document.' + form + '.' + key + row); if (!radio_check_selected(fld, str)) { eval ('var focusfld = \'' + key + row + '[0]\''); focus_on_fld(form, focusfld, type); return(false); } } else if (type == 'checkbox') { if (valid == 'ne') { var isset=0; for (c=flag=0; c < opts_r.length; c++) { var opt = opts_r[c].split('='); opt[0] = opt[0].replace('/%5c%7c/', '|'); eval('fld = document.' + form + '.' + key + row + '_' + opt[0]); if (!fld) isset = 1; else if (fld.checked) isset = 1; } if (!isset) { alert("Please enter a value for the " + str + " field."); focus_on_fld(form, key + row, type); return (false); } } } else { eval('fld = document.' + form + '.' + key + row); for (c=flag=0; c < conds.length; c++) { var cond = conds[c].split('='); // alert(conds[c] + ' ' + key + ' ' + row + ' ' + fld.value); if (conds[c] == 'ne') { if (!is_defined(fld, str)) { focus_on_fld(form, key + row, type); return(false); } } if (conds[c] == 'email') { if (!is_email(fld, str)) { focus_on_fld(form, key + row, type); return(false); } } if (conds[c] == 'date') { if (!is_date(fld, str)) { focus_on_fld(form, key + row, type); return(false); } } if (conds[c] == 'num') { if (!is_num(fld, str)) { focus_on_fld(form, key + row, type); return(false); } } if (cond[0] == 'min') { if (!equal_greater_than(fld, str, cond[1])) { focus_on_fld(form, key + row, type); return(false); } } if (cond[0] == 'max') { if (!equal_lower_than(fld, str, cond[1])) { focus_on_fld(form, key + row, type); return(false); } } if (cond[0] == 'maxl') { if (!within_maxsize(fld, str, cond[1])) { focus_on_fld(form, key + row, type); return(false); } } if (cond[0] == 'regex') { if (!does_match(fld, str, cond[1], regexdesc)) { focus_on_fld(form, key + row, type); return(false); } } if (cond[0] == 'invregex') { if (!does_not_match(fld, str, cond[1], regexdesc)) { focus_on_fld(form, key + row, type); return(false); } } } } return(true); } function select_check_selected(fld, desc) { if (!fld) return(true); var isset = 0; if (fld.options) { if (fld[fld.selectedIndex].value) isset = 1; } else if (fld.value != '') isset = 1; if (!isset) { alert('Please enter a value for the "' + unescape(desc) + '" field.'); return(false); } return(true); } function radio_check_selected(fld, desc) { if (!fld) return(true); var isset=0; if (fld.length) { for (var i=0; i < fld.length; i++) { if (fld[i].checked) { isset = 1; break; } } } else { if (fld.value != '') isset = 1; } if (!isset) { alert('Please enter a value for the "' + unescape(desc) + '" field.'); return(false); } return(true); } function radio_selectedIndex(fld) { var i = 0; if (fld.length) { for (var i=0; i < fld.length; i++) { if (fld[i].checked) { break; } } } else { if (fld.value != '') i = 0; } if (i == fld.length) return(-1); else return(i); } function is_defined(fld, desc) { if (fld && fld.value == '') { alert('Please enter a value for the "' + unescape(desc) + '" field.'); return (false); } return(true); } function equal_greater_than(fld, desc, min) { if (fld && fld.value != '' && Number(fld.value) < min) { alert('"' + unescape(desc) + '" must be at least ' + min + '.'); return (false); } return(true); } function equal_lower_than(fld, desc, max) { if (fld && fld.value != '' && Number(fld.value) > max) { alert('"' + unescape(desc) + '" must not exceed ' + max + '.'); return (false); } return(true); } function within_maxsize(fld, desc, max) { if (fld && fld.value.length > max) { alert('field "' + unescape(desc) + '" contains too many letters (max. ' + max + ')'); return (false); } return(true); } function is_email(fld, desc) { if (fld && fld.value && (fld.value.match(/(\@.*\@)|(\.\.)|(\@\.)|(\.\@)|(^\.)/) || !(fld.value.match(/^\s*\S+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,}|[0-9]{1,3})(\]?)\s*$/)))) { alert(fld.value + ' is not a valid e-mail address'); return (false); } return(true); } function is_date(fld, desc) { if (fld && fld.value && !(fld.value.match(/^[12][09][09][0-9]\/[01][0-9]\/[0-3][0-9]( [012][0-9]:[0-6][0-9]:[0-6][0-9])?$/))) { alert('The value in the "' + unescape(desc) + '" field must have the form YYYY/MM/DD'); return (false); } return(true); } function is_num(fld, desc) { if (fld && fld.value && !(fld.value.match(/^[0-9.]+$/))) { alert('\'' + fld.value + '\' The value in the "' + unescape(desc) + '" field must be a positive number'); return (false); } return(true); } function does_match(fld, desc, expr, regexdesc) { if (!fld) return(true); if (fld.value == '') return(true); // alert(fld.value + ' ' + expr); expr = expr.replace(/\//g, "\\/"); // alert(expr); eval('str = fld.value.match(/^' + expr + '$/i)'); if (!str) { regexdesc = unescape(regexdesc); if (regexdesc) { alert(regexdesc); } else { alert('field "' + unescape(desc) + '" must match the expression ' + expr); } return (false); } return(true); } function does_not_match(fld, desc, expr, regexdesc) { if (!fld) return(true); if (fld.value == '') return(true); eval('str = fld.value.match(/' + expr + '/i)'); if (str) { regexdesc = unescape(regexdesc); if (regexdesc) { alert(regexdesc); } else { alert('field "' + unescape(desc) + '" must not contain ' + expr); } return (false); } return(true); } function focus_on_fld (form, fld, type) { if (type == 'text' || type == 'volume' || type == 'html' || type == 'email' || type == 'template' || type == 'password' || type == 'float' || type == 'int' || type == 'bigint' || type == 'tinyint' || type == 'textarea' || type == 'textspec' || type == 'select' || type == 'radio' || type == 'checkbox') eval ('var absfld = document.' + form + '.' + fld); else if (type == 'multiple_select' || type == 'list' || type == 'file' || type == 'multiplefiles') eval ('var absfld = document.' + form + '.' + fld + '_0'); else if (type == 'actions') eval ('var absfld = document.' + form + '.' + fld + '_action_0'); else if (type == 'options') eval ('var absfld = document.' + form + '.' + fld + '_opt_0'); else if (type == 'permissions') eval ('var absfld = document.' + form + '.' + fld + '_user_0'); else if (type == 'date') eval ('var absfld = document.' + form + '.' + fld + '_year'); else if (type == 'component') eval ('var absfld = document.' + form + '.' + fld + '_conc'); else if (type == 'componentvol') eval ('var absfld = document.' + form + '.' + fld + '_vol'); if (absfld) absfld.focus(); }