
   /** this double array defines the varietions to each language
*   keywords, images path, download location for each langyage and brand.
*   @return: none
*/
var languages_data = {
     'da' : {
        'poker_keywords' : ['Poker', 'Texas' ,'Hold’em', 'pokerspil', 'pokerrum'],
        'casino_keywords' : ['casino', 'casinos', 'gambling', 'roulette', 'blackjack'],
        'poker_image': 'http://images.images4us.com/888poker/da/888hp_popup_poker.jpg',
        'casino_image': 'http://images.images4us.com/888/da/888hp_popup_casino.jpg',
        'poker_pre_download': 'http://da.888poker.com/download/download.htm',
        'casino_pre_download': 'http://da.888casino.com/download/download.htm',
        'ok_title': 'OK',
        'cancel_title': 'Annuller',
        'poker_dl': '3270',
        'casino_dl': '3266',
        'timeout_interval': '2000',
        'blocked_agent': ['Linux','SunOs','Unix']
    },
    'de' : {
        'poker_keywords' : ['poker'],
        'casino_keywords' : ['casino', 'casinos', 'Glücksspiel', 'gambling', 'roulette', 'blackjack'],
        'poker_image': 'http://images.images4us.com/888poker/de/888hp_popup_poker.jpg',
        'casino_image': 'http://images.images4us.com/888casino/de/888hp_popup_casino.jpg',
        'poker_pre_download': 'http://de.888poker.com/download/download.htm',
        'casino_pre_download': 'http://de.888casino.com/download/download.htm',
        'ok_title': 'OK',
        'cancel_title': 'Abbrechen',
        'poker_dl': '3270',
        'casino_dl': '3266',
        'timeout_interval': '2000',
        'blocked_agent': ['Linux','SunOs','Unix']
    },
    'es' : {
        'poker_keywords' : ['Poker', 'Texas' ,'Hold’em'],
        'casino_keywords' : ['Casino', 'Ruleta', 'Blackjack', 'Tragamonedas', 'Juego+Azar', 'Black+Jack'],
        'poker_image': 'http://images.images4us.com/888poker/es/888hp_popup_poker.jpg',
        'casino_image': 'http://images.images4us.com/888/es/888hp_popup_casino_es.jpg',
        'poker_pre_download': 'http://es.888poker.com/download/download.htm',
        'casino_pre_download': 'http://es.888casino.com/download/download.htm',
        'ok_title': 'Aceptar',
        'cancel_title': 'Cancelar',
        'poker_dl': '3270',
        'casino_dl': '3266',
        'timeout_interval': '2000',
        'blocked_agent': ['Linux','SunOs','Unix']
    },
    'fr':{
        'poker_keywords' : ['Poker', 'Texas', 'Hold’em', 'Omaha'],
        'casino_keywords' :['Casino', 'roulette', 'ligne', 'blackjack'],
        'poker_image': 'http://images.images4us.com/888poker/fr/888hp_popup_poker_fr.jpg',
        'casino_image': 'http://images.images4us.com/888casino/fr/888hp_popup_casino_fr.jpg',
        'poker_pre_download': 'http://fr.888poker.com/download/download.htm',
        'casino_pre_download': 'http://fr.888casino.com/download/download.htm',
        'ok_title': 'OK',
        'cancel_title': 'Annuler',
        'poker_dl': '3270',
        'casino_dl': '3266',
        'timeout_interval': '2000',
        'blocked_agent': ['Linux','SunOs','Unix']
    },
     'it' : {
        'poker_keywords' : ['Poker' ,'Texas' ,'Hold’em'],
        'casino_keywords' : ['casino', 'casinò' , 'gioco online', 'roulette','online'],
        'poker_image': 'http://images.images4us.com/888poker/it/888hp_popup_poker.jpg',
        'casino_image': 'http://images.images4us.com/888/it/888hp_popup_casino.jpg',
        'poker_pre_download': 'http://it.888poker.com/download/download.htm',
        'casino_pre_download': 'http://it.888casino.com/download/download.htm',
        'ok_title': 'Aceptar',
        'cancel_title': 'Cancelar',
        'poker_dl': '3270',
        'casino_dl': '3266',
        'timeout_interval': '2000',
        'blocked_agent': ['Linux','SunOs','Unix']
    },
    'nl':{
        'poker_keywords' : ['Poker', 'pokerkamer',  'freerolls'],
        'casino_keywords' :['casino', 'casinos', 'gambling', 'roulette', 'blackjack'],
        'poker_image': 'http://images.images4us.com/888poker/nl/888hp_popup_poker.jpg',
        'casino_image': 'http://images.images4us.com/888casino/nl/888hp_popup_casino.jpg',
        'poker_pre_download': 'http://nl.888poker.com/download/download.htm',
        'casino_pre_download': 'http://nl.888casino.com/download/download.htm',
        'ok_title': 'OK',
        'cancel_title': 'Annuleren',
        'poker_dl': '3270',
        'casino_dl': '3266',
        'timeout_interval': '2000',
        'blocked_agent': ['Linux','SunOs','Unix']
    },
     'pt':{
        'poker_keywords' : ['poker', 'Texas' ,'Holdem'],
        'casino_keywords' :['casino', 'roleta', 'blackjack', 'online vinte-e-um'],
        'poker_image': 'http://images.images4us.com/888poker/pt/888hp_popup_poker.jpg',
        'casino_image': 'http://images.images4us.com/888/pt/888hp_popup_casino.jpg',
        'poker_pre_download': 'http://pt.888poker.com/download/download.htm',
        'casino_pre_download': 'http://pt.888casino.com/download/download.htm',
        'ok_title': 'OK',
        'cancel_title': 'Cancelar',
        'poker_dl': '3270',
        'casino_dl': '3266',
        'timeout_interval': '2000',
        'blocked_agent': ['Linux','SunOs','Unix']
    },  
     'ru':{
        'poker_keywords' : ['покер', 'Техасский' ,'Холдем', 'покерные', 'игры', 'играть' ,'покер', 'poker', 'покеррум'],
        'casino_keywords' :['казино', 'casino', 'онлайн'],
        'poker_image': 'http://images.images4us.com/888poker/ru/888hp_popup_poker.jpg',
        'casino_image': 'http://images.images4us.com/888/ru/888hp_popup_casino.jpg',
        'poker_pre_download': 'http://ru.888poker.com/download/download.htm',
        'casino_pre_download': 'http://ru.888casino.com/download/download.htm',
        'ok_title': 'OK',
        'cancel_title': 'Oтmeнa',
        'poker_dl': '3270',
        'casino_dl': '3266',
        'timeout_interval': '2000',
        'blocked_agent': ['Linux','SunOs','Unix']
    },            
   'sv':{
        'poker_keywords' : ['poker', 'Texas' ,'Hold’em', 'pokerspel', 'hold’em-poker', 'pokerrum'],
        'casino_keywords' :['casino', 'kasino', 'kasinon', 'online-spel', 'roulett', 'blackjack'],
        'poker_image': 'http://images.images4us.com/888poker/sv/888hp_popup_poker.jpg',
        'casino_image': 'http://images.images4us.com/888/sv/888hp_popup_casino.jpg',
        'poker_pre_download': 'http://sv.888poker.com/download/download.htm',
        'casino_pre_download': 'http://sv.888casino.com/download/download.htm',
        'ok_title': 'OK',
        'cancel_title': 'Avbryt',
        'poker_dl': '3270',
        'casino_dl': '3266',
        'timeout_interval': '2000',
        'blocked_agent': ['Linux','SunOs','Unix']
    },        
   
    'en' : {
        'poker_keywords' : ['poker'],
        'casino_keywords' :['casino'],
        'poker_image': 'http://images.images4us.com/888poker/en/New%20Image1.JPG',
        'casino_image' : 'http://images.images4us.com/888casino/en/New%20Image.JPG',
        'casino_8M_image_ndl' : 'http://images.images4us.com/888casino/en/free_spin_popup_continue.gif',
        'casino_8M_image_dl' : 'http://images.images4us.com/888casino/en/free_spin_popup_DL_new.gif',
        'poker_pre_download': 'http://www.888poker.com/download/download.htm',
        'casino_pre_download': '#',
        'ok_title': 'OK',
        'cancel_title': 'Cancel',
        'poker_dl': '3270',
        'casino_dl': '3268',
        'timeout_interval': '2000',
        'blocked_agent': ['Linux','SunOs','Unix']        
    }
};

/** returns a requested value from the array according to the language
*   uses eval command to ceate an object with dynamic id. 
*   @param: attribute - the requested value from the array
*   @return: an object accoeding to string id.
*/
function objParser(attribute)
{
    return languages_data[rlLang][attribute];
} 

/** sets the title attribute to an object
*   @param: id - objec's id 
*   @param: title - title text
*   @return: none.
*/
function setTitle (id, title)
{
    var obj = document.getElementById(id);
    if (obj != null)
    {
        obj.title = objParser(title);
    }
}

/** calls to the "OpenAndDownload" funcrion after checking the brand and getting the relevant id.
*   @param: brand - download brand (888poker or 888casino)
*   @return: none.
*/

function entryPopupDownload(brand)
{
    var dl = "0";
    if (brand == '888casino')
    {
        dl = objParser('casino_dl');        
    }
    else if (brand == '888poker')
    {
        dl = objParser('poker_dl');        
    }
    OpenAndDownload(dl,brand);
}

/** checks the user browser (this functionlity is not supported in some browsers
*   checks which popup image to display according to referrer
*   set pre download page link with relevant parametrs
*   set the title attribute to the popup functionality buttons
*   then sets opacity and displayes the entry popup div.
*   @return: none.
*/

 function displayEntryPopup() 
 {
  if (typeof rlLang == 'undefined') {
    rlLang = 'en';
  }
  
  if (typeof rlSerial == 'undefined') {
    rlSerial = '485472';
  }
  
  var defaultParams = "sr=" + rlSerial + "&lang=" + rlLang;

  if ( !isBlockedByFlag() && document.cookie.indexOf('HPShowPopup') < 0) 
  {
    var date = new Date();
    date.setTime(date.getTime() + 7200000);
    document.cookie = 'HPShowPopup=0; expires=' + date.toGMTString() + ' ;path=/';
    
    //get product (poker/casino) according to referrer
    product = "casino"; 
    //alert(product);
    if (product == 'casino') 
    {          
      //set href and title for "ok" button.
      var download_button = document.getElementById('map_casino_download');
      if (download_button != null)
      {
                    
        setTitle ('map_casino_download', 'ok_title');
      }  
      setTitle ('map_casino_cancel', 'cancel_title');
      setTitle ('map_casino_x', 'cancel_title');      
      document.getElementById('EntryPopupImg').src = objParser('casino_image');
    }
       
    if ( !isBlockedUserAgent() ) 
    {
      var whitespace = document.getElementById('EntryPopupWhiteSpace');
     
      whitespace.style.backgroundColor = '#5D5C5C';
      if (typeof whitespace.style.filter != 'undefined') 
      {
        try
        {
            whitespace.className = 'change_opacity';
        }
        catch (e){}        
      }
      else 
      {           
        whitespace.style.opacity = '0.8';
      } 
    }  
    setTimeout(OpenEntryPopup, objParser('timeout_interval'));
   }
  }
  
/** displates the entry popup div and setting it in the middle of the screen (according to user's resulotion)
*   @return: none.
*/ 
  function OpenEntryPopup()
  {
    try 
    {
      var popup_wrapper = document.getElementById('EntryPopupWrapper');
      var whitespace = document.getElementById('EntryPopupWhiteSpace');
      var popup = document.getElementById('EntryPopup');
      
      if (typeof popup_wrapper != 'undefined' && typeof whitespace != 'undefined' && typeof popup != 'undefined') 
      {
        var height = Math.max(
          Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
          Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
          Math.max(document.body.clientHeight, document.documentElement.clientHeight),
          689
        );
        
        whitespace.style.height = height + 'px';
        popup_wrapper.style.visibility = "visible";
      }
    }
    catch (e) 
    {
      /* do nothing */
    }
  }
  
/** checks which product (casino or poker) according to referrer, defalt is casino
*   @return: the required product after analysis.
*/ 
function ParseProduct() 
{
    var product = 'casino';
    var referrer = document.referrer.toLowerCase();
    if (typeof referrer == 'string') 
    {
      var poker_keywords = objParser('poker_keywords');      
      for (keyword in poker_keywords) 
      {
        if (referrer.indexOf(poker_keywords[keyword].toLowerCase()) >= 0) 
        {
          product = 'poker';
          break;
        }
      }
    }

    if (product != 'casino') 
    {
      var casino_keywords = objParser('casino_keywords');
      for (keyword in casino_keywords) 
      {
        if (referrer.indexOf(casino_keywords[keyword]) >= 0) 
        {
          product = 'casino';
          break;
        }
      }
    }
    return product;
}  

/** checkes whether the there is a blocked user agent (OS/browser), if so the there will be no opacity on the moin div.
*  @return: true if blocked user agent , false otherwise.
*/

function isBlockedUserAgent()
{
    var userAgent = navigator.userAgent.toLowerCase();
    if (typeof userAgent == 'string') 
    {
      var blockedAgent = objParser('blocked_agent');      
      for (indx in blockedAgent) 
      {
        if (userAgent.indexOf(blockedAgent[indx].toLowerCase()) >= 0) 
        {
          return true;
        }
      }
    }
     return false;
}   

/** checkes whether the first bit of the flag parameter is equals=1, if so the entty popup will not be displayed.
*  @return: true if 1st bit is 1, false otherwise.
*/
function isBlockedByFlag()
{
    var FlagAr = rlFlag.split("");
    if (FlagAr[0] == '1')
        return true;
    return false;
}

 function display8MEntryPopup(optimizer_combination) 
 {
  if (typeof rlLang == 'undefined') {
    rlLang = 'en';
  }
  
  if (typeof rlSerial == 'undefined') {
    rlSerial = '485472';
  }
  
  var defaultParams = "sr=" + rlSerial + "&lang=" + rlLang;

  if ( !isBlockedByFlag() && document.cookie.indexOf('HPShowPopup') < 0) 
  {
    var date = new Date();
    date.setTime(date.getTime() + 7200000);
    document.cookie = 'HPShowPopup=0; expires=' + date.toGMTString() + ' ;path=/';
 
  
    //set href and title for "ok" button.
    var download_button = document.getElementById('map_casino_download');
    if (download_button != null)
    {                  
      setTitle ('map_casino_download', 'ok_title');
    }    
  
    setTitle ('map_casino_cancel', 'cancel_title');   
    
    //get the image and set the image map
    var img = document.getElementById('EntryPopupImg'); //image object   
    if (img != null) 
    {
      if(optimizer_combination == 'Download')
      {
        img.src = objParser('casino_8M_image_dl');
        img.useMap = "#map_casino_8M_dl";
      }
      else if (optimizer_combination == 'UKOriginal')
      {
        img.src = objParser('casino_image');
        img.useMap = "#map_casino";
      }
      else if (optimizer_combination == 'PopNdl' || optimizer_combination == 'UKMacPopNdl')
      {
        img.src = objParser('casino_8M_image_ndl');
        img.useMap = "#map_casino_8M_ndl";
      }
    }  
      
    if ( !isBlockedUserAgent() ) 
    {
      var whitespace = document.getElementById('EntryPopupWhiteSpace');
     
      whitespace.style.backgroundColor = '#5D5C5C';
      if (typeof whitespace.style.filter != 'undefined') 
      {
        try
        {
            whitespace.className = 'change_opacity';
        }
        catch (e){}        
      }
      else 
      {           
        whitespace.style.opacity = '0.8';
      } 
    }  
    setTimeout(OpenEntryPopup, objParser('timeout_interval'));
  }
 }   



function displayTestEntryPopup()
{        
  if (rlCountry == 'gbr')
  {
    if(navigator.userAgent.indexOf('Mac') > 0)
      display8MEntryPopup('PopNdl');
    else    
      display8MEntryPopup(optimizer_combination);
    getTrackingParams();
  }    
  else
  {
    displayEntryPopup();
  }
}


function getTrackingParams()
{        
    var date = new Date();
    var cookieValue = optimizer_test_id + "*" + optimizer_combination + "*" + optimizer_st;
    date.setTime(date.getTime() + 7200000);
    document.cookie = '8Mpopup=' + cookieValue + '; expires=' + date.toGMTString() + ' ;path=/';  
}

