var Aceituna = { namespace : function(name) { if ( !name || !name.length ) { return null; } var current = window; var names = name.split("."); for ( var i = 0 ; i < names.length ; i++ ) { current[names[i]] = current[names[i]] || {}; current = current[names[i]]; } }, extend : function(obj, properties) { if ( !obj ) { return; } for ( property in properties ) { obj[property] = properties[property]; } } }; //---------------------------------------------------------------------------> Aceituna.namespace('Aceituna.images'); Aceituna.images = { toPNG: function(img) { img = EL(img); var src = img.getAttribute("source"); if( browser.isMSIE && browser.majorVersion < 7 ) { img.style.filter='progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + src + ')'; img.src=Aceituna.contextPath + '/common/img/none.gif'; } else { img.src = src; } }, changePNG: function(img, src) { if( browser.isMSIE && browser.majorVersion < 7 ) { img.style.filter='progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + src + ')'; } else { img.src = src; } }, createPNG : function(url) { var img = document.createElement('img'); if( browser.isMSIE && browser.majorVersion < 7 ) { img.src=Aceituna.contextPath + '/common/img/none.gif'; img.style.filter='progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + url + ')'; } else { img.src=url; } return img; }, renderPNG : function(url, parent) { if( parent != null ) { parent = EL(parent); var img = Aceituna.images.createPNG(url); parent.appendChild(img); } else { var s = " Aceituna.namespace('Aceituna.DOM'); Aceituna.DOM = { toElement : function(e) { if ( typeof e == "string" ) { return document.getElementById(e); } return e; }, getClassNames : function(element) { return EL(element).className.split(/\s+/); }, updateClassName : function(element, classNames) { EL(element).className = classNames.join(' '); }, hasClassName : function(element, className) { var classes = Aceituna.DOM.getClassNames(element); for ( var i = 0 ; i < classes.length ; i++ ) { if ( classes[i] == className ) { return true; } } return false; }, addClassName : function(element, className, multiply) { if ( Aceituna.DOM.hasClassName(element, className) ) { return; } var classes = Aceituna.DOM.getClassNames(element); if ( multiply ) { var l = classes.length; for ( var i = 0 ; i < l ; i++ ) { classes.push(classes[i] + '-' + className); } } classes.push(className); Aceituna.DOM.updateClassName(element, classes); }, removeClassName : function(element, className, multiply) { var classes = Aceituna.DOM.getClassNames(element); var newClasses = new Array(); var reg = new RegExp('-?(' + className + '-|' + className + '$)'); var i, j; for ( i = 0, j = 0; i < classes.length ; i++ ) { if ( !multiply ) { if ( classes[i] != className ) { newClasses[j++] = classes[i]; } } else { if ( !reg.test(classes[i]) ) { newClasses[j++] = classes[i]; } } } Aceituna.DOM.updateClassName(element, newClasses); } }; var EL = Aceituna.DOM.toElement; //---------------------------------------------------------------------------> Aceituna.namespace("Aceituna.util"); Aceituna.util = { trim : function(s) { if ( typeof s != "string" ) { return s; } return s.replace(/^(\s*)([\W\w]*)(\b\s*$)/, '$2'); }, checkDate: function(value) { if( value.length != 10 || value.indexOf("/") != 2 || value.lastIndexOf("/") != 5 ) { return false; } var jj = value.substring(0, 2); var mm = value.substring(3, 5); var aaaa = value.substring(6, 10); var date = new Date(aaaa, parseInt(mm, 10) - 1, jj); if( date.getDate() != parseInt(jj, 10) || date.getMonth() != (parseInt(mm, 10) - 1) || date.getFullYear() != parseInt(aaaa, 10) ) { return false; } return true; }, parseDate: function(value) { if( value.length != 10 || value.indexOf("/") != 2 || value.lastIndexOf("/") != 5 ) { return null; } var jj = value.substring(0, 2); var mm = value.substring(3, 5); var aaaa = value.substring(6, 10); var date = new Date(aaaa, parseInt(mm, 10) - 1, jj); return date; }, isDateBefore: function(value1, value2) { value1 = Aceituna.util.parseDate(value1); value2 = Aceituna.util.parseDate(value2); if( value1 == null || value2 == null ) { return null; } return value1.getTime() < value2.getTime(); }, checkInt: function(val) { return parseInt(val, 10) == val; }, checkFloat: function(val) { val = val.replace(/\,/g, "."); return parseFloat(val) == val; }, intToString : function(v, nbDigit) { var s = '' + v; if ( v < 0 ) { return s; } var l = nbDigit - s.length; if ( l <= 0 ) { return s; } // insert '0' for ( var i = 0; i < l; i++, s = '0' + s ); return s; }, changeOpacity: function(id, opacity) { /* if( slidePause ) { setTimeout( function() { Aceituna.util.changeOpacity(id, opacity)} , 500); return; } */ if( EL(id) == null ) { return; } var object = EL(id).style; object.opacity = (opacity / 100); object.MozOpacity = (opacity / 100); object.filter = "alpha(opacity=" + opacity + ")"; }, fading: function(id,opacStart,opacEnd,millisec) { if( EL(id) == null ) { return; } //speed for each frame var speed = Math.round(millisec / 100); var timer = 0; //determine the direction for the blending, if start and end are the same nothing happens if(opacStart > opacEnd) { for(i = opacStart; i >= opacEnd; i--) { //setTimeout("Aceituna.util.changeOpacity('" + id + "'," + i + " )",(timer * speed)); Aceituna.timer.TaskManager.Instance.addTask( "Aceituna.util.changeOpacity('" + id + "'," + i + " )",(timer * speed), 1); timer++; } } else if(opacStart < opacEnd) { for(i = opacStart; i <= opacEnd; i++) { //setTimeout("Aceituna.util.changeOpacity('" + id + "'," + i + " )",(timer * speed)); Aceituna.timer.TaskManager.Instance.addTask( "Aceituna.util.changeOpacity('" + id + "'," + i + " )",(timer * speed), 1 ); timer++; } } }, checkEmail: function(val) { var usr = "([a-zA-Z0-9][a-zA-Z0-9_.-]*|\"([^\\\\\x80-\xff\015\012\"]|\\\\[^\x80-\xff])+\")"; var domain = "([a-zA-Z0-9][a-zA-Z0-9._-]*\\.)*[a-zA-Z0-9][a-zA-Z0-9._-]*\\.[a-zA-Z]{2,5}"; var regex = "^"+usr+"\@"+domain+"$"; var myrxp = new RegExp(regex); return(myrxp.test(val)); }, checkURL: function(url) { var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/; return RegExp.test(url); }, checkRadio : function(r) { var checked = false; for(var i = 0; i < r.length; i ++) { if( r[i].checked ) { checked = true; break; } } return checked; }, addWindowOnload: function(func) { var windowonload = window.onload; window.onload = function() { if( windowonload != null ) { windowonload(); } func(); } }, addEnterEvent: function(elt, func) { if( elt == null ) { return null; } elt = EL(elt); if( document.all ) { elt.onkeydown = function() { if( event.keyCode == 13) func(event); }; } else { elt.onkeydown = function(e) { if( e.keyCode == 13) func(e); }; } }, launchWhenBWisLoaded: function( bw, func) { if( typeof bw == 'string' ) { bw = document.getElementById(bw); } if( !bw.selfclassName ) { setTimeout( function() { Aceituna.util.launchWhenBWisLoaded( bw, func); }, 500); return; } func(); } }; //---------------------------------------------------------------------------> Aceituna.namespace('Aceituna.timer'); Aceituna.timer.TaskManager = function() { this.initialize.apply(this, arguments) }; Aceituna.timer.TaskManager.prototype = { tasks:[], time: 0, initialize: function() { }, updateTask: function(name, func, interval, nb) { for(var i = 0; i < this.tasks.length; i ++) { var t = this.tasks[i]; if( t.name == name ) { t.func = func; t.interval = interval; t.nb = nb; t.last = new Date().getTime(); t.counter = 0; return; } } this.addTask( func, interval, nb, name); }, addTask: function(func, interval, nb, name) { var t = {}; t.func = func; t.interval = interval; t.nb = nb != null ? nb : 0; t.last = new Date().getTime(); t.counter = 0; t.name = name; this.tasks.push(t); }, pause: function () { this.stopped = true; }, resume : function() { this.stopped = false; this.startTime = new Date().getTime(); }, start: function () { this.startTime = new Date().getTime(); setInterval( function() {Aceituna.timer.TaskManager.Instance.loop() } , 150 ); this.stopped = false; }, loop: function () { var time = new Date().getTime(); if( this.stopped ) { return; } var tmp = []; for(var i = 0; i < this.tasks.length; i ++) { var t = this.tasks[i]; if( t.nb > 0 && t.counter >= t.nb ) { continue; } tmp.push(t); } this.tasks = tmp; for(var i = 0; i < this.tasks.length; i ++) { var t = this.tasks[i]; if( time - t.last > t.interval ) { if( typeof t.func == 'string' ) { eval(t.func); } else { t.func(); } t.last = time; t.counter++; } } } }; Aceituna.timer.TaskManager.Instance = new Aceituna.timer.TaskManager(); //---------------------------------------------------------------------------> Aceituna.namespace("Aceituna.net"); Aceituna.net.Browser = function() { this.initialize.apply(this, arguments) }; Aceituna.net.Browser.prototype = { navigator : null, platform : null, userAgent : null, isWin32 : false, isLinux : false, isMac : false, isGecko : false, isFirefox : false, isNetscape : false, isMSIE : false, isSafari : false, isOpera : false, code : null, name : null, majorVersion : 0, minorVersion : 0, minorVersion2 : 0, version : "", /** * The engine inner object */ _Engine : function() { /** * The engine code * (Mozilla, Opera, ...) */ this.code = navigator.appCodeName; /** * The engine version : version + platform + ... */ this.versionString = navigator.appVersion; this.version = parseFloat(this.versionString); /** * The name of the client that implements this engine. */ this.clientName = navigator.appName; }, //--------------------------------------------> /** * Creates a new declared Browser */ initialize : function() { this.navigator = window.navigator; this.Engine = new this._Engine(); this.platform = navigator.platform; this.userAgent = navigator.userAgent; this.isWin32 = (this.platform.indexOf("Win32") >= 0); this.isLinux = (this.platform.indexOf("Linux") >= 0); this.isMac = (this.platform.indexOf("Mac") >= 0); this.isGecko = (this.userAgent.indexOf("Gecko/") >= 0); this.isFirefox = (this.userAgent.indexOf("Firefox/") >= 0); this.isNetscape = (this.userAgent.indexOf("Netscape/") >= 0); this.isMSIE = (this.userAgent.indexOf("MSIE") >= 0); this.isSafari = (this.userAgent.indexOf("Safari/") >= 0); this.isOpera = (this.userAgent.indexOf("Opera") >= 0); if( this.isOpera ) { this.isMSIE = false; } this.code = this.Engine.code; if ( this.isGecko ) this.code = "Gecko"; if ( this.isFirefox ) this.code = "Firefox"; if ( this.isNetscape ) this.code = "Netscape"; if ( this.isMSIE ) this.code = "MSIE"; if ( this.isSafari ) this.code = "Safari"; if ( this.isOpera ) this.code = "Opera"; this.name = this.Engine.clientName; if ( this.isFirefox ) this.name = "Mozilla Firefox"; if ( this.isSafari ) this.name = "Safari" if ( this.isOpera ) this.name = "Opera" /** * The version of the browser */ this.version = "" + this.Engine.version; //------------------------------------ // Detect the version of the browser //------------------------------------ if ( this.code ) { var reg = new RegExp(this.code + '/?\\s?;?([\\d.]*)'); var res = this.userAgent.match(reg); if ( res.length == 2 ) { this.version = res[1]; res = this.version.match(/\d+/g); this.majorVersion = (res[0] ? parseInt(res[0]) : 0); this.minorVersion = (res[1] ? parseInt(res[1]) : 0); this.minorVersion2 = (res[2] ? parseInt(res[2]) : 0); } } } }; Aceituna.net.Browser.Instance = new Aceituna.net.Browser(); //---------------------------------------------------------------------------> Aceituna.namespace('Aceituna.CSS'); Aceituna.CSS = { appendNavigatorInformations : function () { var list = document.getElementsByTagName("html"); if ( list != null && list.length > 0 ) { // presume that only one html tag has been declared var html = list.item(0); // get the browser var browser = Aceituna.net.Browser.Instance; var classNames = Aceituna.DOM.getClassNames(html); classNames.push(browser.isGecko ? "Gecko" : "NotGecko"); classNames.push(browser.isFirefox ? "Firefox" : "NotFirefox"); classNames.push(browser.isNetscape ? "Netscape" : "NotNetscape"); classNames.push(browser.isSafari ? "Safari" : "NotSafari"); classNames.push(browser.isOpera ? "Opera" : "NotOpera"); classNames.push(browser.isMSIE ? "MSIE" : "NotMSIE"); if( browser.isMSIE ) { classNames.push("MSIE" + browser.majorVersion); } Aceituna.DOM.updateClassName(html, classNames); } } }; Aceituna.CSS.appendNavigatorInformations(); //---------------------------------------------------------------------------> Aceituna.namespace("Aceituna.CSS.events"); Aceituna.CSS.events = { overOn : function(element, multiply) { Aceituna.DOM.addClassName(element, "over", multiply); }, outOf : function(element, multiply) { Aceituna.DOM.removeClassName(element, "over", multiply); }, clickOn : function(element, multiply, toggleSelect) { if ( Aceituna.DOM.hasClassName(element, "clicked") ) { Aceituna.DOM.removeClassName(element, "clicked", multiply); } else { Aceituna.DOM.addClassName(element, "clicked", multiply); } if ( toggleSelect ) { Aceituna.CSS.events.toggleSelect(); } }, toggleSelect : function() { var selects = document.getElementsByTagName('select'); if( selects.length == 0 ) { return; } var visibility = (selects[0].style.visibility == 'hidden') ? 'visible' : 'hidden'; for(var i = 0; i < selects.length ; i ++) { selects.item(i).style.visibility = visibility; } } }; //---------------------------------------------------------------------------> Aceituna.namespace('Aceituna.form'); Aceituna.form = { rules : [], isEmpty: function(element) { var value = Aceituna.form.getFieldValue(element); if( value == null ) { return true; } return false; }, checkDate: function(element) { var value = Aceituna.form.getFieldValue(element); if( value == null ) { return false; } return Aceituna.util.checkDate(value); }, getFieldValue: function(element) { element = EL(element); var value; if( element == null ) { return null; } switch(element.type) { case 'password': case 'textarea': case 'text': { value = element.value; break; } case 'select-one': { value = Aceituna.form.select.getSelectedValue(element); break; } case 'radio': { for(var i = 0; i < element.options.length; i ++) { if( element.options[i].checked ) { value = element.options[i].value; } } break; } default: if( typeof element == 'object' ) { for(var i = 0; i < element.length ; i ++ ) { if( element[i].checked ) { value = element[i].value; } } } break; } if( value == null || value.length == 0 ) { return null; } return value; }, addRule: function(form, field, text, testFunc, noWarning ) { Aceituna.form.rules.push( {field : field, text: text, testFunc : testFunc, noWarning: noWarning, form : form} ); }, checkFields: function(f) { for(var i = 0; i < Aceituna.form.rules.length; i ++) { var rule = Aceituna.form.rules[i]; if( rule.form != f.name ) { continue; } var ok = Aceituna.form.checkField(f, rule); if( !ok ) { return false; } } }, checkField: function(f, rule) { var field = f[rule.field]; var text = rule.text; var testFunc = rule.testFunc; var noWarning = rule.noWarning; var ok; if( testFunc != null ) { ok = testFunc($(field).val(), f); } else { ok = $(field).val() != ''; } if( !ok ) { alert(text); var name = $(field).attr('name'); name = name.replace('[', ''); name = name.replace(']', ''); $('#warn'+name).remove(); $(window).scrollTo($(field), 800, {onAfter:function() {$(field).focus();} }); if( noWarning ) { return ok; } if( !Aceituna.form.nohighlight ) { var w = $(field).parent().width(); var e = $('
<< '+text+'
'); e.attr('id', 'warn'+name); e.css('margin-left', (w+30) + 'px' ); var target = $(field).parent().find(':first-child').get(0); target = $(target); e.insertBefore(field); } var action = $(field).attr('type') == 'text' || $(field).attr('type') == 'password' ? 'keyup' : 'click'; var unbindaction = action; var entity = $(field); if( $(field).attr('type') == 'file' ) { action = 'blur'; } if( $(field).attr('liste') != null ) { //myselect var liste = $(field).attr('liste'); entity = $('#' + liste + ' INPUT'); action = 'click'; unbindaction = 'none'; } entity.unbind(unbindaction).bind(action, function() { var ok; if( testFunc != null ) { ok = testFunc($(this).val(), f); } else { ok = $(this).val() != ''; } if( ok ) { $('#warn'+name).hide(); } else { $('#warn'+name).show(); } }); } return ok; } }; Aceituna.namespace('Aceituna.form.select'); Aceituna.form.select = { getSelectedOption : function (element) { return EL(element).options[EL(element).selectedIndex]; }, getSelectedValue : function (element) { return Aceituna.form.select.getSelectedOption(element).value; }, getSelectedText : function (element) { return Aceituna.form.select.getSelectedOption(element).text; }, setSelectedValue : function (element, value) { for(var i = 0; i < EL(element).options.length ; i ++) { var opt = EL(element).options[i]; if( opt.value == value ) { EL(element).selectedIndex = i; break; } } }, clear : function(element) { element = EL(element); while ( element.firstChild != null ) { element.removeChild( element.firstChild ); } }, appendOption : function(element, value, text) { element = EL(element); var o = document.createElement ("option"); o.setAttribute("value", value); o.appendChild( document.createTextNode(text) ); element.appendChild(o); }, appendDisabledOption : function(element, text) { element = EL(element); var o = document.createElement ("optgroup"); o.setAttribute("label", text); o.className = "optdisabled"; element.appendChild(o); }, appendOptions : function (element, data, clear) { element = EL(element); if( clear ) { Aceituna.form.select.clear(element); } for(value in data) { Aceituna.form.select.appendOption(element, value, data[value]); } }, appendDisabledOptions : function (element, data, clear, disabledList) { element = EL(element); if( clear ) { Aceituna.form.select.clear(element); } for(value in data) { if( disabledList[value] ) { Aceituna.form.select.appendDisabledOption(element, data[value]); } else { Aceituna.form.select.appendOption(element, value, data[value]); } } } };