//jvlogin 1.5.1.6

function submitFormJVLogin(username){
    var form = document.form_jvlogin;
    var flag = true;
    $$('.require').each(function(item,index){
        if(item.value=='' || item.value==0 || item.value=='username'){
            item.setStyle('border','1px solid red');
            flag = false;
        }else{
            item.setStyle('border','1px solid #ccc');
        }
    });
    
    if(flag){
        form.submit();
    }
    return;
}

function module_popup(moduleid,widthform,heightform,delay,duration,transition,effect){
    
    if($('jvlogin_username') && $('jvlogin_password')){
    
        $('jvlogin_username').addEvent('keyup',function(event){
            if(event.keyCode==13){
                submitFormJVLogin('username');
            }
        });
        $('jvlogin_password').addEvent('keyup',function(event){
            if(event.keyCode==13){
                submitFormJVLogin('username');
            }
        });
    }
    
    var coordinates = $('btn_showlogin').getCoordinates();
    
    var jvclass = new Class({
        options:{
            'module_id':moduleid,
            'widthform':widthform,
            'heightform':heightform,
            'delay':parseInt(delay),
            'duration':parseInt(duration),
            'transitions':renderEffects(transition,effect),
            'top':coordinates.bottom + heightform/2,
            'left':coordinates.left - widthform/2
        },
        initialize:function(options){
            
            this.setOptions(options);
           
        },
        
        showPopup:function(){
            var options = this.options;
            var module = $(options.module_id);
            
            /*=========begin mask=======*/
            
            var divmask = new Element('div',{id:'divmask'});
            divmask.setStyles({
                width:'100%',
                height:'100%',
                background:'#000',
                opacity:'0.5',
                position:'fixed',
                left:0,
                top:0,
                'z-index':998
            }).inject($$('body')[0]);
            /*=========begin popup=======*/
             var myfx = new Fx.Styles(module,{
                duration:options.duration,
                transition:options.transitions
            });
            
            var widthform = options.widthform;
            var heightform = options.heightform;
            var leftpos = (screen.width - widthform)/2;
            var toppos = screen.height/2 - heightform;
            
            module.setStyles({
                position:'fixed',
                display:'block',
                opacity:0,
                background:'#fff',
                width:widthform+'px',    // editing...
                
                padding:'10px',
                top:toppos,
                left:leftpos,
                overflow:'hidden',
                'z-index':999
            });
           
            myfx.start({
               
               'opacity':[0,1],
               'top':[toppos- options.delay,toppos]
            });
            
            /*=========end popup=======*/
            
            divmask.addEvent('click',function(){
                this.remove();
                myfx.start({
                     'opacity':[1,0],
                     top:[toppos,toppos- options.delay]
                });
            });
           
        }
        
    });
    jvclass.implement(new Options);
    
    var popup = new jvclass();
    
    popup.showPopup();
    
    return ;
    
}

function renderEffects(transition,effect){
    
    var myfx;
    
    switch(transition){
        case 'Quad':
            myfx = Fx.Transitions.Quad;
            break;
        case 'Bounce':
            myfx = Fx.Transitions.Bounce;
            break;
        case 'Cubic':
            myfx = Fx.Transitions.Bounce;
            break;
        case 'Quart':
            myfx = Fx.Transitions.Bounce;
            break;
        case 'Quint':
            myfx = Fx.Transitions.Bounce;
            break;
        case 'Pow':
            myfx = Fx.Transitions.Bounce;
            break;
        case 'Expo':
            myfx = Fx.Transitions.Bounce;
            break;
        case 'Circ':
            myfx = Fx.Transitions.Bounce;
            break;
        case 'Sine':
            myfx = Fx.Transitions.Bounce;
            break;
        case 'Back':
            myfx = Fx.Transitions.Bounce;
            break;
        case 'Elastic':
            myfx = Fx.Transitions.Bounce;
            break;
        
        default:
            myfx = Fx.Transitions.linear;
    }
    
    if(transition!='linear' && transition){
        switch(effect){
            case 'easeIn':
                myfx = myfx.easeIn;
                break;
            case 'easeOut':
                myfx = myfx.easeOut;
                break;
            case 'easeInOut':
                myfx = myfx.easeInOut;
                break;
        }
    }
    
    
    return myfx;
}

