var _isBadIE = jQuery.browser.msie && jQuery.browser.version<7;

function jauge(x,tot) {
    if(tot>0 && x>=0 && x<=tot) {
        var cur=Math.round((100*(tot-x))/tot);
        var h= "<div style='width:20px;height:100px;border:1px solid black;background:#98A697;margin:4px;'>";
        h+="<img src='/static/spacer.gif' style='width:20px;height:"+cur+"px;'/></div>";
        return h;
    }
    else return "";
}


var _dialog;

function popupClose(dialog)
{
  if(!dialog) dialog=_dialog;
  dialog.data.fadeOut('fast', function () {
    dialog.container.slideUp('fast', function () {
      dialog.overlay.fadeOut('fast', function () {
        $.modal.close(); // must call this to have SimpleModal
                         // re-insert the data correctly and
                         // clean up the dialog elements
      });
    });
  });
}

function popupOpen(o,h)
{
   $.modal($(o),{'overlay':20,
                 "containerCss":{"height":h},
                onOpen: function (dialog) {
                  _dialog=dialog;
                  $("a.modalCloseImg").html('X');
                  $(o+" button").focus();
                  dialog.overlay.fadeIn('fast', function () {
                    dialog.container.slideDown('fast', function () {
                      dialog.data.fadeIn('fast'); // See Other Notes below regarding
                                                     // data display property and
                                                     // iframe details
                    });
                  });
                },

                onClose: popupClose

   }
   );
}

function popup(url,height)
{
    $.get(url,
      {},
      function(data){
        $('#popup').html(data);
        popupOpen("#popup",height);
      }
    );
}


function popupAbo() {popup("/reminder","70px");}
function popupHelp() {popup("/givemeachance","100px");}
function popupRegister() {popup("/register","260px");}


function submitForm(url) // submit les "input" de #winPopup en POST
{
    var t={};
    $("#winPopup input,#winPopup select").each( function() {t[this.name] = $(this).val()} );
    t["i"]=new Date().getTime();
    $.post(url,
      t,
      function(data){
        if(data)
            $('#popup').html(data);
        else
            popupClose();
      }
    );
}
