// requires mouse.js and balloon/*.png function keycode(e) { return (window.event ? window.event.keyCode : e.which); } function disable_form(prefix) { $('#'+prefix+' input').attr('disabled','disabled'); $('#'+prefix+' select').attr('disabled','disabled'); $('#'+prefix+' button').attr('disabled','disabled'); $('#'+prefix+' textarea').attr('disabled','disabled'); } function enable_form(prefix) { $('#'+prefix+' input').attr('disabled',''); $('#'+prefix+' select').attr('disabled',''); $('#'+prefix+' button').attr('disabled',''); $('#'+prefix+' textarea').attr('disabled',''); } /******************************************************************************/ var constraints = []; function constrain(form,elem,rule,param) { var cns = {'form':form,'elem':element(elem),'rule':rule,'param':param}; constraints.push(cns); } function validate(form, notify) { var mistakes=[]; for (var i = 0 ; i < constraints.length ; ++i) { var cns = constraints[i]; if (cns.form != form) continue; var elem = element(cns.elem); if (elem == null) continue; switch (cns.rule) { case 'int': { var x = parseInt(str,10); if ( x != x ) { mistakes.push([elem, 'This is not a number.']); } } break; case 'real': { var x = parseFloat(str); if (x!=x || x==Infinity) { mistakes.push([elem, 'This is not a number.']); } } break; case 'nz': if ( elem.value == 0 ) { mistakes.push([elem, 'This cannot be empty or zero.']); } break; case 'ne': if ( ! elem.value.length ) { mistakes.push([elem, 'You must enter something here.']); } break; case 'date': if ( parseDate(elem.value) == null ) { mistakes.push([elem, 'This is not a valid date.']); } break; case 'fun': var result = cns.param(elem); if ( result == null || result == '' ) { mistakes.push([elem, result]); } break; } } if (mistakes.length > 0) { if (notify) { complain(mistakes, form); } return false; } return true; } function validate_post(id,then) { if ( ! validate(id, true) ) return false; disable_form(id); busy_on(); request(document.forms[id], null, function(req,ok) { busy_off(); enable_form(id); if (ok) { if (then!=undefined) then(req); } else { complain(req.responseText, id); return false; } }); } function read_mistakes(mistakes_string, id) { var ms = mistakes_string.split('\n'); var mistakes = []; for (var i=0 ; i= 0) { mist = [elem(id+'_'+mist.substr(0,j)), mist.substr(j+1)]; } else { while (++i < ms.length) { mist += "\n"+ms[i]; } mist = [null,mist]; } mistakes.push(mist); } return mistakes; } function complain(mistakes, form) { if (typeof mistakes == 'string') { mistakes = read_mistakes(mistakes,form) } var i, tosay=[], topoint=null; for (i = 0 ; i < mistakes.length ; ++i) { var mist = mistakes[i]; if (mist.length >= 2) { if (mist[0] != null) { if (topoint == null) topoint = mist; } else { tosay.push(mist[1]); } } else if (mist.length == 1) { tosay.push(mist[0]); } } var alerted = false; var something = false; // // show balloon over first mistake (or simply alert) // if (topoint != null) { var el = topoint[0]; try { var bal = new_balloon(topoint[1], el, 0); $(bal).fadeIn(150, function() { timeout(53*topoint[1].length+2000, function() { $(bal).fadeOut(500); }); }); something = true; } catch(x) { alert(topoint[1]); alerted = true; } el.focus(); } // // write inside
and show it // var mistakes_div = elem(form+'_mistakes'); if (mistakes_div != null) { mistakes_div.innerHTML = (tosay.length>1) ? "" : ''; $(mistakes_div).slideDown(); } else if (!alerted) { if (tosay.length > 1) { alert('* '+tosay.join("\n* ")); } else if (tosay.length > 0) { alert(tosay[0]); } else if (!something) { alert('áðïôõ÷ßá'); } } } /******************************************************************************/ function open_window(url) { /*var digest = function(s) { var x = ''; for (var i = 0 ; i < s.length ; ++i) { if (/[a-zA-Z]/.test(s.charAt(i))) { x += s.charAt(i); } else { x += '_'+s.charCodeAt(i)+'_'; } } return x; } var win = window.open('', 'window_'+digest(url)); if (win.location.href == 'about:blank') { win.location.href = url; } win.focus();*/ window.open(url, 'rightpane'); } /******************************************************************************/ var the_popups = {}; var the_popup_counter = 0; function new_popup(pos, innerHTML) { var div = document.createElement('div'); attribute(div,'class','popup'); div.style.position = 'absolute'; div.style.display = 'none'; div.innerHTML = innerHTML; document.body.appendChild(div); div.style.opacity = '0'; div.style.display = ''; var x = Math.min(Math.max(0,pos[0] - div.offsetWidth/2), document.body.offsetWidth-div.offsetWidth-1); var y = Math.max(0,pos[1] - div.offsetHeight/2); div.style.left = x+'px'; div.style.top = y+'px'; div.style.display = 'none'; div.style.opacity = ''; return div; } function open_popup(url, onok) { if (the_popups[url] != null) { focus_popup(the_popups[url]); } else { var id = 'POPUP_'+(the_popup_counter++); var zorder = the_popup_counter; the_popups[url] = id; if (/\?/.test(url)) url2 = url + '&_POPUP_='+urlencode(id); else url2 = url + '?_POPUP_='+urlencode(id); busy_on(); request(url2,null,function(req,succ) { busy_off(); if (succ) { var xtra = ' onselectstart="return false"'+ ' onmousedown="return drag_popup('+html(repr(id))+')"'+ ' ondblclick="return close_popup('+html(repr(id))+')"'; var before = "
>\"\">>\"\"
>>".replace(//g,xtra); var after = ">
>\"\">>\"\"
".replace(//g,xtra); var div = new_popup(the_mouse_position, hidden(id+'_url', url) +hidden(id+'_onok', onok) +before +req.responseText +after ); convert_links(div); div.setAttribute('id',id); div.setAttribute('zIndex',zorder); $(div).fadeIn(function(){ focus_first_widget(div); }); } else { complain(req.responseText); } }); return id; } } var the_old_mouse_position; function drag_popup(id) { the_old_mouse_position = [the_mouse_position[0],the_mouse_position[1]]; $(document.body).bind('mousemove',id,on_popup_drag); $(document.body).bind('mouseup',id,on_popup_focus); return false; } function on_popup_drag(e) { var div = elem(e.data); var x = Math.floor(div.style.left.substr(0,div.style.left.length-2)) + (e.pageX - the_old_mouse_position[0]); var y = Math.floor(div.style.top.substr(0,div.style.top.length-2)) + (e.pageY - the_old_mouse_position[1]); div.style.left = x + 'px'; div.style.top = y + 'px'; the_old_mouse_position = [e.pageX,e.pageY]; $(document.body).unbind('mouseup',on_popup_focus); $(document.body).bind('mouseup',e.data,on_popup_enddrag); } function on_popup_enddrag(e) { $(document.body).unbind('mousemove',on_popup_drag); $(document.body).unbind('mouseup',on_popup_enddrag); } function on_popup_focus(e) { focus_popup(e.data); $(document.body).unbind('mousemove',on_popup_drag); $(document.body).unbind('mouseup',on_popup_focus); } function focus_popup(id) { var div = elem(id); if (div != null) focus_first_widget(div); } function focus_first_widget(el) { if (el != null) { if ( (el.nodeName == 'INPUT' && el.attributes != null && el.attributes['type'] != null && el.attributes['type'].nodeValue != 'hidden') || el.nodeName == 'TEXTAREA' || el.nodeName == 'BUTTON' ) { el.focus(); return true; } else for (var i = 0 ; i < el.childNodes.length ; ++i) { if (focus_first_widget(el.childNodes[i])) { return true; } } } return false; } function close_popup(id,isok) { if (id instanceof Array) { id = the_popups[id]; if (id == null) { return; } } if (isok) { var x = get(id+'_onok'); if (x != null) { eval(x); } } the_popups[get(id+'_url')] = null; var div = elem(id); $(div).fadeOut(function(){ document.body.removeChild(div); }); } function convert_links(el) { if (el != null) { if ( el.nodeName == 'A' ) { var cls = attribute(el,'class'); if (cls != null) { var clss = cls.split(/\s+/); if ( array_has(clss,'popup') >= 0 ) { attribute(el,'onclick','open_popup(' +repr(attribute(el,'href'))+',' +repr(attribute(el,'onclick')) +')'); attribute(el,'href','#'); } else if ( array_has(clss,'window') >= 0 ) { attribute(el,'onclick','open_window('+repr(attribute(el,'href'))+')'); attribute(el,'href','#'); } } } else for (var i = 0 ; i < el.childNodes.length ; ++i) { convert_links(el.childNodes[i]); } } } /******************************************************************************/ function remove(x) { var xx = (typeof x == 'string') ? element(x) : x; xx.parentNode.removeChild(xx); } function replace(x,y) { var xx = (typeof x == 'string') ? element(x) : x; $(xx).replaceWith(y); } function append(x,y) { var xx = (typeof x == 'string') ? element(x) : x; $(xx).append(y); } function toid(x) { if (x instanceof Array) { return x.join('_'); } else { return String(x); } } function checkbox(name,checked,label,disabled,onchange) { if (checked === undefined) checked=false; if (disabled === undefined) disabled=false; if (onchange === undefined) onchange=''; return '' +(label.length?'':'') +''; } function radio(name,value,label,checked,disabled,onchange) { if (checked === undefined) checked=false; if (disabled === undefined) disabled=false; if (onchange === undefined) onchange=''; return ''+ (label?'':'')+''; } function dropdown_opt_text(opt) { if (typeof opt == 'string') { return opt; } else if (opt instanceof Array) { return opt[1]; } else if (opt['text'] != undefined) { return opt.text; } else if (opt['name'] != undefined) { return opt.name; } else if (opt['value'] != undefined) { return opt.value; } } function dropdown_opt(opt) { if (typeof opt == 'string') { return {'value':opt, 'text':dropdown_opt_text(opt)}; } else if (opt instanceof Array) { return {'value':String(opt[0]), 'text':dropdown_opt_text(opt[1])}; } else if (opt['value'] != undefined) { return {'value':opt.value, 'text':dropdown_opt_text(opt)}; } else if (opt['name'] != undefined) { return {'value':opt.name, 'text':dropdown_opt_text(opt)}; } else if (opt['text'] != undefined) { return opt.text; } } function dropdown_opts(obj) { var opts = []; if ( ! (obj instanceof Array) ) { for (var prop in obj) { var x = obj[prop]; if (typeof x != 'string') { x = prop; } opts.push(dropdown_opt([prop,x])) } } else { for (var i = 0 ; i < obj.length ; ++i) opts.push(dropdown_opt(obj[i])); } return opts; } function dropdown(id, value, opts, onchange, extra, onblur) { opts = dropdown_opts(opts,extra); if (extra !== undefined) opts = dropdown_opts(extra).concat(opts); var str = ''; } function hidden(id, value) { return ''; } function input(id, value, length, disabled, onchange, onfocus, onblur, onclick) { if (id instanceof Array) id = id[0]+'_'+id[1]; return '0?' maxlength="'+html(length)+'" size="'+html(length)+'"':'') +(disabled?' disabled="disabled"':'') +(onchange?' onchange="'+html(onchange)+'"':'') +(onfocus?' onfocus="'+html(onfocus)+'"':'') +(onblur?' onblur="'+html(onblur)+'"':'') +(onclick?' onclick="'+html(onclick)+'"':'') +' class="textarea"' +' />'; } var __the_calendar__ = null; function dateinput(id, value, disabled, onchange) { if (id instanceof Array) id = id[0]+'_'+id[1]; return input(id, value, -10, disabled, onchange, 'on_dateinput_focus('+repr(id)+')', 'on_dateinput_blur('+repr(id)+')'); } function on_dateinput_blur(id) { if (__the_calendar__ != null) { __the_calendar__.destroy(); __the_calendar__ = null; } } function on_dateinput_focus(id) { var el = element(id); if (__the_calendar__ != null) { __the_calendar__.destroy(); __the_calendar__ = null; } __the_calendar__ = new Calendar(1, null, function(c, value) { element(id).value = value; /*if (__the_calendar__ != null) { __the_calendar__.destroy(); __the_calendar__ = null; }*/ }, function(c) { if (__the_calendar__ != null) { __the_calendar__.destroy(); __the_calendar__ = null; } } ); __the_calendar__.weekNumbers = false; __the_calendar__.showsTime = false; __the_calendar__.create(); __the_calendar__.parseDate(el.value) __the_calendar__.showAtElement(el); } function textarea(name, value, cols, rows, disabled, onchange) { var prefix=null; if (name instanceof Array) { prefix = name[0]; name = name[1]; } return ''; } function icon(name, filename,alt, onclick) { var prefix=null; if (name instanceof Array) { prefix = name[0]; name = name[1]; } return ''; } function img(filename,alt) { return ''+html(alt)+'' }