function gotoWengo(familyPm, posPm, xitiName) {

  var urlWengo='http://home.edt02.net/emc/banner/mstbc.php?c=';
  var trackWengo = '40060-174436-91631-335-306462';

  if(familyPm != '') {
    switch(familyPm) {
      case 100: 
      case '100': 
          trackWengo='40060-174390-91631-335-306416';
          xitiName += 'Livres';
          break;
      case 200: 
      case '200': 
          trackWengo='40060-174391-91631-335-306417';
          xitiName += 'Musique';
          break;
      case 300: 
      case '300': 
          trackWengo='40060-174392-91631-335-306418';
          xitiName += 'DVDVHS';
          break;
      case 400: 
      case '400': 
          trackWengo='40060-174393-91631-335-306419';
          xitiName += 'JeuxVideo';
          break;
      case 500: 
      case '500': 
          trackWengo='40060-174394-91631-335-306420';
          xitiName += 'TelPDA';
          break;
      case 600: 
      case '600':           
          trackWengo='40060-174395-91631-335-306421';
          xitiName += 'Informatique';
          break;
      case 700: 
      case '700': 
          trackWengo='40060-174399-91631-335-306425';
          xitiName += 'ImageSon';
          break;
      case 900: 
      case '900': 
          trackWengo='40060-174400-91631-335-306426';
          xitiName += 'MaisonElectromenager';
          break;
      case 1000: 
      case '1000': 
          trackWengo='40060-174398-91631-335-306424';
          xitiName += 'Enfant';
          break;
      case 1100: 
      case '1100': 
          trackWengo='40060-174397-91631-335-306423';
          xitiName += 'Mode';
          break;
      case 1400: 
      case '1400': 
          trackWengo='40060-174396-91631-335-306422';
          xitiName += 'SportLoisirs';
          break;
      case 1500: 
      case '1500': 
          trackWengo='40060-174401-91631-335-306427';
          xitiName += 'VinSaveur';
          break;
    }
  }
  else if(posPm != '') {
    switch(posPm) {
      case 1 : 
      case '1' : 
          trackWengo='40060-174436-91631-335-306462';
          break;
      case 2 : 
      case '2' : 
          trackWengo='40060-174439-91631-335-306465';
          break;
      case 3 : 
      case '3' : 
          urlWengo='http://home.edt02.net/emc/membership/mstac.php?c=';
          trackWengo='40060-23140-91631-0-154831';
          break;
      case 4 : 
      case '4' : 
          trackWengo='40060-174445-91631-335-306471';
          break;
    }
  }

  // xiti call
  if(xitiName != null) {
    xt_med('C','5',xitiName,'S');
  }

  // redirection to wengo tracked url
  window.open(urlWengo+trackWengo).focus();
}

/**
 * unespaceEntities
 *
 * @param cdata Data to process
 */
function unescapeEntities(cdata) {
    var buff='';
    for (var pos=0; pos<cdata.length; ) {
        if (cdata.substr(pos,'&#38;#60;'.length) == '&#38;#60;') {
              buff += '&lt;';
              pos += '&#38;#60;'.length;
        } else if (cdata.substr(pos, '&#62;'.length) == '&#62;') {
              buff += '&gt;';
              pos += '&#62;'.length;
        } else if (cdata.substr(pos, '&amp;amp;'.length) == '&amp;amp;') {
              buff += '&amp;';
              pos += '&amp;amp;'.length;
        } else if (cdata.substr(pos, '&amp;#39;'.length) == '&amp;#39;') {
              buff += '&#39;';
              pos += '&amp;#39;'.length;
        } else if (cdata.substr(pos, '&#34;'.length) == '&#34;') {
              buff += '&quot;';
              pos += '&#34;'.length;
        } else if (cdata.substr(pos, '&amp;'.length) == '&amp;') {
            buff += '&';
            pos += '&amp;'.length;
        } else  {
              buff += cdata.substr(pos, 1);
              ++pos;
        }
    }
    return buff;
}


/**
 * Write a popup (promo)
 */
function writePopup(url, width, height, wait, cookie_name, cookie_duration, probability, scrollbars) {
  // Default parameters
  if (arguments.length < 8) scrollbars = 0;
  if (arguments.length < 7) probability = 1; // Should be betwen 0 and 1
  if (arguments.length < 6) cookie_duration = null; // In days
  if (arguments.length < 5) cookie_name = 'popup';
  if (arguments.length < 4) wait = 0;

  // If cookie is present, popup must not be displayed
  if (document.cookie.indexOf(cookie_name) != -1)
  return;

  // If random (between 0 and 1) is over probability, popup must not be displayed
  if (Math.random() >= probability)
  return;

  // Build a cookie to prevent other display
  var c = cookie_name + '=1;Path=/';
  if (cookie_duration != null) {
    var d = new Date();
    d.setTime(d.getTime() + (cookie_duration*24*60*60*1000));
    c = c + ';expires=' + d.toGMTString();
  }
  document.cookie = c; 

  // Open popup
  setTimeout('popPromo(\"' + url + '\", ' + width + ', ' + height + ', \'' + scrollbars + '\')', Math.max(wait, 1));
}



/***********************************
POPUNDER
***********************************/

function ggr(pu_u,pu_m,pu_w,pu_h,pu_c,pu_l,pu_p,pu_hh,pu_n,pu_e,pu_hhh,pu_ta, debug) {
  ggr2(pu_u, pu_m, pu_w, pu_h, pu_c, pu_l, pu_n, pu_p, pu_hhh, pu_e, pu_hh, false, pu_ta, debug);
}

function ggr2(pu_u, pu_m, pu_w, pu_h, pu_c, pu_l, pu_n, pu_p, pu_hhh, pu_e, pu_hh, pu_ad, pu_ta, debug) {
  var cpu = PM.Cookie.get(pu_c);
  var lastTrackId = PM.Cookie.getParam("pm", "lasttracking");

  // Test condamned popunder
  if(cpu != null) {
    if(cpu < 0) return;
    // cookie update
    cpu = parseInt(cpu) + 1;
  }
  else {
    // init cpu
    cpu = 0;
  }

  var puTestsNeeded = (cpu == 0);

  var arrExclTracks = [1276040, 1276041, 1276042, 1276043, 1276044, 1276045, 1276046, 1276047, 1278040, 1278041, 1278042, 1284040, 1288040, 1290040, 1296040, 1296041, 1298040, 1298041, 1298042, 1298043, 1298044, 1422040];
  var arrInclTracks = [];
  var arrRefNat = ["google","yahoo","search.live.com","search.msn","search.ke.voila.fr","www.altavista.com","search.free.fr","search.lycos.com"];

  
  // Execution of TESTS
  if(puTestsNeeded) {
    /****************************************
     * Blocking tests
     ***************************************/
    
    // New price user
    if(pu_hhh) {
      var cpm = PM.Cookie.get("pm");
      if(cpm != null) {
        // get last track timetamp to test with now date
        lastTrackTs = PM.Cookie.getParam("pm", "trackingts");
        var now_date = new Date();
        // if cookie date and now date are same, so this is a new user
        var diff = Math.abs(lastTrackTs-now_date.getTime());
        // compare the two dates with 10 sec of tolerance
        var sameDate = (diff >= 0 && diff <= 10000);
        if(sameDate == false) {
          if(debug) {
            // mode debug
            PM.Cookie.set("pu_debug", ": L'utilisateur n'est pas un nouvel utilisateur PM!");
          }
          // We condamn popunder display
          PM.Cookie.set(pu_c, -1, pu_l);
          return;
        }
      }
    }

    // Proba test
    if((Math.random() * 100) >= pu_p) {
         if(debug) {
          // mode debug
          PM.Cookie.set("pu_debug", ": Le test de proba a échoué!");

        }
        // We condamn popunder display
        PM.Cookie.set(pu_c, -1, pu_l);
        return;
    }

    // Tracking Exclusion test if necessary
    if(pu_e) {
        var bbExclTracks = false;
        // Test the last tracking id is excluded
        for(var i = 0; i < arrExclTracks.length; i++) {
          if(arrExclTracks[i] == lastTrackId)
            bbExclTracks = true;
        }
        // test liens sponsos : si 7xxx, pas de popunder
        var matchTrackingLS = new RegExp('^'+PM.Constants.SL.trackingCodeRegExp+'$');
        if (matchTrackingLS .exec(lastTrackId) != null) bbExclTracks = true;
        if(lastTrackId != null && bbExclTracks) {
          if(debug) {
            // mode debug
            PM.Cookie.set("pu_debug", ": Le tracking "+lastTrackId+" est exclu!");
          }
          // We condamn popunder display
          PM.Cookie.set(pu_c, -1, pu_l);
          return;
        }
    }
    
    
    /***********************************************
     * 3 access tests (complementary tests):
     *  - direct acces
     *  - from ref nat
     *  - with tracking

     **********************************************/
     
    // Natural referencement test
    var ref = document.referrer;
    var refNatRequired  = pu_hh;
    var refNatFound = false;
    if(ref != null && !PM.Util.getInterrogationUrlParam("t")) {
      // Get domain name with the url referer
      var matcher = new RegExp("^[\\w]{2,6}:\\/\\/([\\w\\d\\.\\-]+).*$");
      var arrMatches = matcher.exec(ref);
      // 1 domain finded
      if(arrMatches && arrMatches.length == 2) {
        var domainName = arrMatches[1];
        // Test if the referer domain is from natural referencement
        for(var i = 0; i < arrRefNat.length; i++) {
          if(domainName.indexOf(arrRefNat[i]) != -1) {
            refNatFound = true;
            break;
          }
        }
      }
    }

    // Tracking test if necessary
    if (typeof(pu_ta) == "boolean") {
      pu_ta = pu_ta ? arrInclTracks : null;
    }
    var trackingRequired = (pu_ta != null && pu_ta.length > 0);
    var allTrackingAllowed = (pu_ta != null && pu_ta.length == 1 && pu_ta[0] == 'all');
    var trackingRequiredFound = false;
    if(trackingRequired) {
      if(lastTrackId != null) {
        if(allTrackingAllowed) { 
          trackingRequiredFound = true;
        }
        else {
          for(var i=0; i<pu_ta.length; i++) {
            if(lastTrackId == pu_ta[i]) {
              trackingRequiredFound = true;
              break;
            }
          }
        }
      }
    }
    
    var displayPU = false;
    var directAccessRequired = pu_ad;
    var trackingExistingInUrl = (lastTrackId != null);
    if(refNatRequired       && refNatFound)                                 { displayPU = true; }
    if(trackingRequired     && trackingRequiredFound)                       { displayPU = true; }
    if(directAccessRequired && !refNatFound     && !trackingExistingInUrl) { displayPU = true; }
    if(!refNatRequired      && !trackingRequired && !directAccessRequired)   { displayPU = true; }
    
    if(!displayPU) {
      if(debug) {
        // mode debug
        PM.Cookie.set("pu_debug",pu_c+"_refNatRequired_"+refNatRequired+"__refNatFound_"+refNatFound+"__trackingRequired_"+trackingRequired+"__trackingRequiredFound_"+trackingRequiredFound+"__directAccessRequired_"+directAccessRequired+"__directAccessFound_"+(!refNatFound && !trackingExistingInUrl));
      }
      // We condamn popunder display
      PM.Cookie.set(pu_c, -1, pu_l);
      return;
    }
  }

  // Test cpu value with ncr
  if(cpu < pu_n) {
    PM.Cookie.set(pu_c, cpu, pu_l);
    return;
  }
  else if(cpu == pu_n) {
    if(debug) {
      // mode debug
      PM.Cookie.set("pu_debug", "Le_nb_de_clicks_requis_a_ete_atteint");
    }
    // We condamn popunder display
    PM.Cookie.set(pu_c, -1, pu_l);
  }

  xt_med('C','0','Ggr2::Before::'+pu_c,'S');

  if(pu_m == "pop") {
    win=window.open('', 'pump', 'toolbar=no,location=no, status=0, menubar=0, scrollbars=yes, location=no, resizable=no, width=' + pu_w + ', height=' + pu_h);
  }
  else {
    win=window.open('', 'pump', 'toolbar=yes,location=yes, status=1, menubar=1, scrollbars=yes, location=yes, resizable=yes, width=' + pu_w + ', height=' + pu_h);
  }
  win.resizeTo(pu_w, pu_h);
  win.document.location.href = pu_u;
  win.blur();

  xt_med('C','0','Ggr2::After::'+pu_c,'S');
}

/**
 * Tools for promotions
 *
 * @base PM
 */
PM.Promos = {}

/**
 * Promotion formats
 *
 * @base PM.Promos
 */
PM.Promos.PromoFormats = {
  SQUARE_250: 0,
  BANNER: 1, 
  SQUARE_300: 2,
  BUTTON_1_300: 3,
  BUTTON_2_300: 4,
  BUTTON_1_250: 5,
  BUTTON_1_120: 6,
  BUTTON_2_120: 7,
  BUTTON_3_120: 8,
  BUTTON_4_120: 9
}

/**
 * Promotion channels
 *
 * @base PM.Promos
 */
PM.Promos.PromoChannels = {}

/**
 * Get promotion channel
 *
 * @param family the current familly
 * @param format format of the promotion
 * @param xiti   xiti label
 *
 * @base PM.Promos
 */
PM.Promos.getPromoChannel = function(family, format, categories) {
  var value = '';
  if (categories!=null && categories.indexOf('accessoires-auto') != -1) {
    family = 'auto_acc';
  }
  var values = PM.Promos.PromoChannels[family];

  if (values) {
    if (format) {
        value = values[format];
    } else {
        value = values[0];
    }
  }

  return value;
}

/**
 * Promotion channels
 *
 * @base PM.Promos
 */
PM.Promos.PromoChannels = {
  none:        ['otros'],
  books:       ['libros'],
  music:       ['musica'],
  games:      ['videojuegos'],
  video:       ['dvd'],
  hifi:       ['imagen'],
  computer:  ['informatica'],
  sport:       ['deporte'],
  white:       ['hogar'],
  clothing:    ['moda'],
  electronics: ['telefonos'],
  baby:        ['ninos_y_juguetes']
}
var seller_ministite_url_alias = "op/trucos_vendedor";
gotoSellerMinisite = function(xiti_tag) {

  var popup = false;
  var url_default = "/";
  var url            = "/info/no/" + seller_ministite_url_alias;
  var url_popup  = "/info/co/" + seller_ministite_url_alias;
  var anchor = "";

  switch(xiti_tag) {
    case 'MonCompte::PasVendeur::MiniSiteVendeur':
      popup = true;
      anchor = "hp_pas_vendeur";
      break;
    case 'MonCompte::DejaVendeur::MiniSiteVendeur':
      break;
    case 'Inventaire::MiniSiteVendeur':
      popup = true;
      break;
    case 'ToutesMesVentes::MiniSiteVendeur':
      anchor = "hp_deja_vendeur";
      break;
    case 'MonCompte::DetailVente::MiniSiteVendeur':
      popup = true;
      anchor = "reussir_premiere_vente";
      break;
    case 'Vendre::DejaVendeurBlocDroite::MiniSiteVendeur':
      break;
    case 'Vendre::NouveauVendeurEtape2::MiniSiteVendeur':
      break;
    case 'Assistance::TrucsAstuces::MiniSiteVendeur':
      break;
    case 'VendezLeVotre::MiniSiteVendeur':
      popup = true;
      anchor = "creer_annonce_ideale";
      break;
    case '[PageConcernée]::BlocMiseEnVenteRapide::MiniSiteVendeur':
      popup = true;
      break;
    case 'ConfirmationCreationAnnonce::MiniSiteVendeur':
      popup = true;
      anchor = "cinq_conseils";
      break;
    case 'Assistance::AideALaVente::MiniSiteVendeur':
      popup = true;
      break;
    case 'ConfirmationAchat::PoursuivreNavigation::OperationCoupDouble':
      break;
    default:
      url = url_default;
      break;
  }
  
  xt_med('C','5',xiti_tag,'N');
  
  if (anchor != "") anchor = "#page="+anchor;

  if(popup == true) {
    var popup_param = (anchor != "")? "&popup=true": "#popup=true";
    win=window.open(url_popup + anchor + popup_param, '', 'width=965,height=525,toolbar=no,location=no, status=0, menubar=0, scrollbars=yes, location=no, resizable=no');
  }
  else {
    window.location = url + anchor;
  }
}
