var Popup = {
	toggle:        function(t) { if($(t)!==null) { $(t).style.display=='none' ? this.reveal(t) : this.conceal(t) }},
	conceal:       function(t) { if($(t)!==null) { new Effect.SlideUp(t,   { duration: .65 }); } },
	reveal:        function(t) { if($(t)!==null) { new Effect.SlideDown(t, { duration: .75  });} },
    toggle_member_edit: function(t) {  if($(t).style.display=='none'){this.conceal('profile-view');this.reveal('perm-view');}else{this.conceal('perm-view');this.reveal('profile-view');}},
    toggle_emails: function(t) {  if($('send_emails').style.display=='none'){this.reveal('send_emails');}else{this.conceal('send_emails');}},
    toggle_advertisement_add: function(t) {
        if($(t).style.display=='none') { 
            this.conceal('detail-ad-view');
            this.reveal('add-ad-view');            
        } else { 
            this.conceal('add-ad-view');
            this.reveal('detail-ad-view');
        }  
        if($('message_box') != null) {
            $('message_box').style.display = 'none';    
        }    
    },    
    toggle_add_detail: function(t) {
        if($(t).style.display=='none') { 
            this.conceal('detail-view');
            this.reveal('add-view');            
        } else { 
            this.conceal('add-view');
            this.reveal('detail-view');
        }  
        if($('message_box') != null) {
            $('message_box').style.display = 'none';    
        }    
    },    
    toggle_add_leg_detail: function(t) {
        if($(t).style.display=='none') { 
            this.conceal('detail-leg-view');
            this.reveal('add-leg-view');            
        } else { 
            this.conceal('add-leg-view');
            this.reveal('detail-leg-view');
        }  
        if($('message_box') != null) {
            $('message_box').style.display = 'none';    
        }    
    },    
    toggle_add_constraint_detail: function(t) {
        if($(t).style.display=='none') { 
            this.conceal('detail-constraint-view');
            this.reveal('add-constraint-view');            
        } else { 
            this.conceal('add-constraint-view');
            this.reveal('detail-constraint-view');
        }  
        if($('message_box') != null) {
            $('message_box').style.display = 'none';    
        }    
    },    
    toggle_pace_view: function(t) {
        if($(t).style.display=='none') { 
            this.conceal('exchange_view');
            this.reveal('runner_view');            
        } else { 
            this.conceal('runner_view');
            this.reveal('exchange_view');
        }  
        if($('message_box') != null) {
            $('message_box').style.display = 'none';    
        }    
    }
}

function adminPageSortable() {
    Sortable.create('list',{  
        dropOnEmpty:true,
        onUpdate:function() { 
            new Ajax.Request('/admin/pages/update_order', 
                             { onComplete:function(request){
                                    new Effect.Highlight('list');
                                    new Ajax.Updater('page-view','/admin/pages/update_page_view',{evalScripts:true,asynchronous:true});
                                    new Ajax.Updater('left-nav','/admin/pages/update_left_nav',{evalScripts:true,asynchronous:true});
                                }, 
                                parameters:Sortable.serialize('list'), 
                                evalScripts:true, 
                                asynchronous:true}
                             )
        }
    });   
}

function savePermField(formObj, updateId) {
    new Ajax.Request(
                     '/members/myprofile/update_perms/?update_params['+formObj.name+']='+formObj.value,
                     { onComplete:function(request) {
                            new Effect.Highlight(updateId,{ duration:2 });
                       },
                       asynchronous:true 
                     }
                       
    );  
}

function deleteProfileImage() {
    new Ajax.Request(
                     '/members/myprofile/delete_image',
                     { onComplete:function(request) {                        
                            new Effect.SlideUp('current_image',{duration:2});  
                       },
                       asynchronous:true 
                     }
                       
    );        
}
