EN.registerModule("formValidation", {
        intervalSpeed:20,
        messageSpeed:5,
        messageOffset:2,
        messageHide:3,
        timer:null,
        alpha:0,
        showMessage:function(target,string,autohide) {
                if(EN.formValidation.alpha > 1) {                        
                        return;
                };
                
                //EN.formValidation.alpha = 1;
                
                var msg, msgcontent;
                if(!document.getElementById('msg')) {
                        msg = document.createElement('div');
                        msg.id = 'msg';
                        msgcontent = document.createElement('div');
                        msgcontent.id = 'msgcontent';
                        document.body.appendChild(msg);
                        msg.appendChild(msgcontent);
                        msg.style.filter = 'alpha(opacity=0)';
                        msg.style.opacity = 0;                        
                } else {
                        msg = document.getElementById('msg');
                        msgcontent = document.getElementById('msgcontent');
                };
                
                msgcontent.innerHTML = string;
                msg.style.display = 'block';
                
                var targetElem          = document.getElementById(target),                    
                    coords              = EN.formValidation.currentPosition(targetElem);
                    
                try { targetElem.focus(); } catch(err) {};                 
                                     
                msg.style.top  = (coords[1] + targetElem.offsetHeight + EN.formValidation.messageOffset) + 'px';
                msg.style.left = (coords[0] + ((targetElem.offsetWidth - msg.offsetWidth) / 2)) + 'px';
                 
                clearInterval(EN.formValidation.timer);
                
                EN.formValidation.timer = setInterval("EN.formValidation.fadeMessage(1)", EN.formValidation.intervalSpeed);                
                window.setTimeout("EN.formValidation.hideMessage()", (autohide || EN.formValidation.messageHide) * 1000);
        },
        hideMessage: function() {  
                clearInterval(EN.formValidation.timer);                          
                EN.formValidation.timer = setInterval("EN.formValidation.fadeMessage(0)", EN.formValidation.intervalSpeed);                
        },
        fadeMessage: function(flag) {                 
                var msg = document.getElementById('msg'); 
                                 
                EN.formValidation.alpha += (flag ? EN.formValidation.messageSpeed : -EN.formValidation.messageSpeed);                    
                msg.style.opacity = (EN.formValidation.alpha / 100);
                msg.style.filter = 'alpha(opacity=' + EN.formValidation.alpha + ')';
                
                if(EN.formValidation.alpha >= 99) {
                        clearInterval(EN.formValidation.timer);
                        EN.formValidation.timer = null;           
                } else if(EN.formValidation.alpha <= 1) {
                        msg.style.display = "none";                        
                        clearInterval(EN.formValidation.timer);
                        EN.formValidation.timer = null; 
                };                
        },
        currentPosition:function(target) {        
                var coords = [0,0];
                if(target.offsetParent) {
                        while(1) {
                                coords[0] += target.offsetLeft;
                                coords[1] += target.offsetTop;
                                if(!target.offsetParent) { break; };
                                target = target.offsetParent;
                        };
                } else if(target.x) {
                        coords[0] += target.x;
                        coords[1] += target.y;
                };
                return coords;
        }        
});
