/* DEBUG */
function var_dump(obj)
{
  if(typeof obj == "object") {
    return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
  } else {
    return "Type: "+typeof(obj)+"\nValue: "+obj;
  }
}

/* FRANCE BILLET */
function france_billet()
{
  $.get("/index/france-billet", {}, function(reponse) {
    window.open(reponse);
  }, "text");
}

/* FLASH BANDEAU ACCUEIL */
$(document).ready(function () {
  if ($('#flashbandeau').length != 0) {

    $('#flashbandeau').flash({
      swf: '/images/site/anim_mc.swf',
      height: 159,
      width: 332,
      params: {
        wmode: 'transparent'
      }
    });

  }
});

/* NEWSLETTER */
function newsletter_subscribe()
{
    var email_value = $('#email_box').val();

    $('#error_box_newsletter').html('');
    $('#succes_box_newsletter').html('');

    $.get("/index/newsletterbox", {email_box: email_value}, function(reponse) {

      var msg = reponse.split('|');
    if (msg[0] == 'erreur') {
      $('#error_box_newsletter').html(msg[1]);
    } else {
      $('#email_box').val('');
      $('#succes_box_newsletter').html(msg[1]);
    }
    }, "text");
}

/* RECHERCHE */
$(document).ready(function() {
  $('input.onFocusClear').focus(function(){
    $(this).val('');
  });
});


/* PNG TRANSPARENT IE6 */
function setie6png(img) { if(document.all && (IEver=parseFloat(navigator.appVersion.split("MSIE")[1])) && (IEver>=5.5) && (IEver<7) && document.body.filters && img) {
  imgName=img.src.toUpperCase();
  if(imgName.substring(imgName.length-3,imgName.length)=="PNG") img.outerHTML=
    "<span "+(img.id?"id='"+img.id+"' ":"")+(img.className?"class='"+img.className+"' ":"")+(img.title?"title=\""+img.title+"\" ":"")
    +"style=\"width:"+img.width+"px;height:"+img.height+"px;"+(img.align=="left"?"float:left;":(img.align=="right"?"float:right;":""))
    +(img.parentElement.href?"cursor:hand;":"")+"display:inline-block;"+img.style.cssText+";"
    +"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img.src+"',sizingMethod='scale');\"></span>";
}}
$(document).ready(function() {
  $('img.png').each(function() {
    setie6png(this);
  });
});

/* JQUERY UI */
$(document).ready(function() {
  $('button.ui-state-default').hover(
    function(){
      $(this).addClass("ui-state-hover");
    },
    function(){
      $(this).removeClass("ui-state-hover");
    }
  )

  var elements = $(this).find('button.ui-state-default');
  elements.each(function(){
     var html = $(this).html();
     var reg1 = new RegExp("&lt;", "g");
     var reg2 = new RegExp("(&gt;)", "g");

     html = html.replace(reg1, "<");
     html = html.replace(reg2, ">");

     $(this).html(html)
  });

});


/*
 * Message box jquery
 * By DOD ;)
 *
 * param 1 : Message  => TEXT      (obligatoir)
 * param 2 : Titre     => TEXT      (option, [defaut : 'Message'])
 * param 3 : Modal     => true/false  (option, [defaut : true])
 *
 */

function alert_hm(arg_msg){

  var argTitle='Message';
  var argModal=true;

  if(alert_hm.arguments.length>1 && alert_hm.arguments[1]!=''){
    argTitle=alert_hm.arguments[1];
  }
  if(alert_hm.arguments.length>2 && alert_hm.arguments[2]!=''){
    argModal=alert_hm.arguments[2];
  }

  $("#dialog-message-hm").html('<p><span class="ui-icon ui-icon-info"></span>'+arg_msg+'</p>');

  if(argTitle!='')$("#dialog-message-hm").attr('title',argTitle);

  $("#dialog-message-hm").dialog({
    autoOpen: false,
    modal: argModal,
    buttons: {
      Ok: function() {
        $(this).dialog('close');
      }
    }
  });

  $("#dialog-message-hm").dialog('open');
}

var waitConfirmHm='';
var timeOutWait='';

/*
 * Confirm box jquery
 * By DOD ;)
 *
 * param 1 : Message  => TEXT      (obligatoir)
 * param 2 : ActionTrue  => TEXT
 * param 3 : ActionFalse=> TEXT
 * param 4 : Titre     => TEXT      (option, [defaut : 'Demande de confirmation'])
 * param 5 : Modal     => true/false  (option, [defaut : true])
 * param 6 : BtnTrue  => TEXT      (option, [defaut : 'Oui'])
 * param 7 : BtnFalse  => TEXT      (option, [defaut : 'Non'])
 *
 */

function confirm_hm(arg_msg){

  argTrue=true;
  argFalse=true;
  var argTitle='Demande de confirmation';
  var argModal=true;
  var argBtnTrue='Ok';
  var argBtnFalse='Annuler';

  if(confirm_hm.arguments.length>1 && confirm_hm.arguments[1]!=''){
    argTrue=confirm_hm.arguments[1];
  }
  if(confirm_hm.arguments.length>2 && confirm_hm.arguments[2]!=''){
    argFalse=confirm_hm.arguments[2];
  }
  if(confirm_hm.arguments.length>3 && confirm_hm.arguments[3]!=''){
    argTitle=confirm_hm.arguments[3];
  }
  if(confirm_hm.arguments.length>4 && confirm_hm.arguments[4]!=''){
    argModal=confirm_hm.arguments[4];
  }

  if(confirm_hm.arguments.length>5 && confirm_hm.arguments[5]!=''){
    argBtnTrue=confirm_hm.arguments[5];
  }
  if(confirm_hm.arguments.length>6 && confirm_hm.arguments[6]!=''){
    argBtnFalse=confirm_hm.arguments[6];
  }

  $("#confirm-message-hm").html('<p>'+arg_msg+'</p>');

  if(argTitle!='')$("#confirm-message-hm").attr('title',argTitle);

  var BTN="{"+argBtnTrue+" : function() {eval(argTrue);$(this).dialog('close');},"+argBtnFalse+" : function() {eval(argFalse);$(this).dialog('close');return false;}}";

  $("#confirm-message-hm").dialog({
    autoOpen: false,
    modal: argModal,
    buttons: eval('('+BTN+')')

  });

  $("#confirm-message-hm").dialog('open');

}

$(function() {

  $("button, input:submit, input:button").each(
      function()
      {
        var cl=$(this).attr('class');
        var iWhere = cl.indexOf('ui-state-default');
        if( iWhere > -1)
        {
          $(this).hover(
              function() { $(this).addClass('ui-state-hover'); },
              function() { $(this).removeClass('ui-state-hover'); }
            );
        }
        else
        {
          $(this).addClass('ui-state-default-light ui-corner-all no_bold');
          $(this).hover(
              function() { $(this).addClass('ui-state-hover-light'); },
              function() { $(this).removeClass('ui-state-hover-light'); }
            );
        }
      }
  );
});
