/**
 * javascript pour la partie publique
 *
 * @author frederic@opale.net
 * @since 2010-01-01
 */

/*
 * fonction de demarrage
 */
$(function() {
  // repositionnement de la page d'accueil'
  if ($('.page_home').length) {
    __mb_reframe();
    $(window).resize(function() {
      __mb_reframe();
    });
  }

  // replication des selections du formulaire
  $("select[name='genre']").change(function() {$("select[name='genre']").val($(this).val())});
  $("select[name='age']").change(function() {$("select[name='age']").val($(this).val())});
  $("select[name='orientation']").change(function() {$("select[name='orientation']").val($(this).val())});
  $("select[name='pays']").change(function() {$("select[name='pays']").val($(this).val())});
  $("select[name='rencontre']").change(function() {$("select[name='rencontre']").val($(this).val())});

  // traitement du formulaire
  $('.button_ok').click(function() {
    var genre;
    var age;
    var orientation;
    var pays;
    var rencontre;
    if ($("input:hidden[name='genre']").length) genre = $("input:hidden[name='genre']").val();
    if ($("select[name='genre'] option:selected").length) genre = $("select[name='genre'] option:selected").val();
    if ($("input:hidden[name='age']").length) age = $("input:hidden[name='age']").val();
    if ($("select[name='age'] option:selected").length) age = $("select[name='age'] option:selected").val();
    if ($("input:hidden[name='orientation']").length) orientation = $("input:hidden[name='orientation']").val();
    if ($("select[name='orientation'] option:selected").length) orientation = $("select[name='orientation'] option:selected").val();
    if ($("input:hidden[name='pays']").length) pays = $("input:hidden[name='pays']").val();
    if ($("select[name='pays'] option:selected").length) pays = $("select[name='pays'] option:selected").val();
    if ($("input:hidden[name='rencontre']").length) rencontre = $("input:hidden[name='rencontre']").val();
    if ($("select[name='rencontre'] option:selected").length) rencontre = $("select[name='rencontre'] option:selected").val();
    if (genre && age && orientation && pays && rencontre) {
      var url = '/'+genre+'/'+age+'/'+orientation+'/'+rencontre+'/'+pays+'/1-'+__affidate_mb_url_page;
      document.location = url;
    } else alert(genre+'/'+age+'/'+orientation+'/'+rencontre+'/'+pays);
  });
});

/*
 * repositionnement du contenu de la page d'accueil
 */
function __mb_reframe() {
  var _mb_wHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
  var _mb_margin = Math.max(0, ((_mb_wHeight-530)/2)|0);
  $('div.main_home .content').css('margin-top', _mb_margin+'px').css('margin-bottom', _mb_margin+'px');
}

function __ajouter_favori() {
  if (document.all) {
    window.external.AddFavorite(location.href, document.title);
  } else {
    alert('Vous pouvez faire CTRL + D pour ajouter cette page dans vos signets, ou favoris.');
  }
}