hg_login_form_submit = function(e)
{
    var keynum;
    
    if(window.event) // IE
      keynum = e.keyCode;
    else if(e.which) // Netscape/Firefox/Opera
      keynum = e.which;
      
    if(keynum==13)
        $('#form_login').submit();
}

hg('helpval')(); // bind

/**
 * @todo to be changed to $.live() binds, when I'll switch to jQuery-1.3
 */
$(function() {

    $('input[hg-maxlength]').live('keyup', function(){
        hg('formsLimitLength')(this);
    });

    // login form
    $('a[href="#login"]').live('click',function(){
        hg('prompt')({
                title : '<small><a href="'+hg.base+'User/resetPasswd">forgot password</a></small>',
                url : hg.base+'User/login',
                id: 'form_login',
                i : [
                    {
                        label : '<small style="margin-left:-30px">E-mail</small>',
                        name : 'login',
                        onblur: "hg('ifreplace_val')($('#'+this.id),'','E-mail')",
                        onfocus: "hg('ifreplace_val')($('#'+this.id),'E-mail','')",
                        value: 'E-mail'
                    },
                    {
                        label : '<small style="margin-left:-30px">Password</small>',
                        type : 'password',
                        name : 'password',
                        onkeydown: 'hg_login_form_submit(event)'
                    }
                ],
                buttons:{'Login':true,'Cancel':false}
            });
    });

    // flags
    $('a[href="#flags"]').click(function(){
           
        hg('prompt')({
                url : hg.base+'Flags/add;Articles/Show:'+$('#head_articles_id').val(),
                title: 'What’s wrong?',
                i : [
                    {
                        type : 'textarea',
                        name : 'flags_content'
                    },
                    {
                        type : 'hidden',
                        name : 'oid',
                        value : $(this).attr('id')
                    }                    
                ],
                buttons:{'Report':true,'Cancel':false}
            });
    });
    
    // share
    $('a[href="#share"]').click(function(){
           
        hg('prompt')({
                url : hg.base+'Articles/Share:'+$('#head_articles_id').val()+';Articles/Show:'+$('#head_articles_id').val(),
                title: 'Enter an email address and send a mail with a link to this article',
                i : [
                    {
                        label: '',
                        type : 'text',
                        name : 'share_email'
                    }                    
                ],
                buttons:{'Send':true,'Cancel':false}
            });
    });
    
    // tooltips
    $('.tooltip').live('mouseover',function(){
        hg('tooltip')(this);
    });
    $('.tooltip').live('mouseout',function(){
        hg('tooltipHide')(this);
    });
/*
    // thickbox-alike galleries
    $('a.thickbox').live('click', function(){
        return ! hg('modalDialogImg').apply(this);
    });
*/
    // confirmations
    // ..
    
    //calendar
    //inicjacja datepicker'a
    //FIXME! make it more... live.
    $('.datepicker').datepicker({
                changeMonth:true,
                changeYear:true,
                showButtonPanel: true,
                
                yearRange: '-100:0'
    });
    
    //random advert
    /*
    $('div.random_advert').each(
       function(){
           var current = $(this);
           var advert_id = 0;
           $.getJSON(
               hg.base+'Adverts/ShowRandom:'+current.width(),
               function(response, textStatus){
                   if ('string' != typeof response.html)
                     return;
                   current.html(response.html);
               }
          );
       }); 
    */
});
