// variable to hold the hostname
var host = document.domain;

// global flash check
var MM_contentVersion = 8;
var MM_FlashCanPlay   = 0;

function checkFlashVersion() {
  var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
  if ( plugin ) {
    var words = navigator.plugins["Shockwave Flash"].description.split(" ");
    for (var i = 0; i < words.length; ++i)
    {
      if (isNaN(parseInt(words[i])))
      continue;
      var MM_PluginVersion = words[i];
    }
    MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
  } else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1)) {
    document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
    document.write('on error resume next \n');
    document.write('dim obFlash \n');
    document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
    document.write('</SCR' + 'IPT\> \n');
  }
  return MM_FlashCanPlay;
}

if (!checkFlashVersion() && document.location != 'http://' + host + '/download_flash.php') {
  document.location.href = "/download_flash.php";
}


// get's round the ie security issue
function writeFlash(file, width, height, wmode, params, version) {

  document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"" + width + "\" height=\"" + height + "\" id=\"flash_movie\">");
  document.write("<param name=\"movie\" value=\"" + file + "?version=" + version + "\">");
  document.write("<param name=\"quality\" value=\"high\">");
  document.write("<param name=\"menu\" value=\"false\">");
  document.write("<param name=\"wmode\" value=\"" + wmode + "\">");
  document.write("<param name=\"FlashVars\" value=\"" + params + "\">");
  document.write("<embed src=\"" + file + "?version=" + version + "\" quality=\"high\" type=\"application/x-shockwave-flash\" width=\"" + width + "\" height=\"" + height +"\" wmode=\"" + wmode + "\" menu=\"false\" FlashVars=\"" + params + "\" name=\"flash_movie\"></embed>");
  document.write("</object>");
}


// generic window popup function
var strWin;
function windowPopUp (strURL,
strWinName,
iWinWidth,
iWinHeight,
strScrollBar,
strResize,
strToolbar,
strMenuBar) {

  if (strScrollBar == "yes") {
    if (is.ie == true || is.ns == true) { iWinWidth = iWinWidth + 16; }
  }

  // not first time we've opened the window?
  if (strWin!=null) {

    // window is open now?
    if (!strWin.closed) {
      // focus on it twice, sometimes the browser does not focus properly with one call only
      strWin.focus();
      strWin.focus();
    }
  }

  // open the window
  strWin = window.open(strURL,strWinName, "toolbar="+strToolbar+",scrollbars="+strScrollBar+",location=0,directories=0,status=1,resizable="+strResize+",width="+iWinWidth+",height="+iWinHeight+",menubar="+strMenuBar);

}


// generic reg popup
function go_register () {
  // windowPopUp('https://' + host + '/secure/bet-meccabingo?action=GoRegister', 'register', 700, 600, 1, 0, 0, 0);
  windowPopUp('https://www.meccabingo.com/secure/bet-meccabingo?action=GoRegister', 'register', 800, 600, 1, 0, 0, 0);
}


// generic deposit popup
function go_deposit () {
  windowPopUp('https://' + host + '/secure/bet-meccabingo?action=go_acct_login', 'account', 750, 600, 1, 0, 0, 0);
}

// generic reg popup
function go_play_online () {
  document.location.href = '/bingo/onlinebingo.php';
}

// generic signup popup
function sign_up () {
  document.location.href = '/bingo/signup.php';
}


// sets a cookie
function set_cookie (name, value, expires, path, domain, secure) {

  // set time, it's in milliseconds
  var today = new Date();
  today.setTime(today.getTime());

  /*
  if the expires variable is set, make the correct
  expires time, the current script below will set
  it for x number of days, to make it for hours,
  delete * 24, for minutes, delete * 60 * 24
  */
  if (expires) {
    expires = expires * 1000 * 60 * 60 * 24;
  }

  var expires_date = new Date(today.getTime() + (expires));

  document.cookie = name + "=" + escape(value) +
  ((expires) ? ";expires=" + expires_date.toGMTString() : "") +
  ((path) ? ";path=" + path : "") +
  ((domain) ? ";domain=" + domain : "") +
  ((secure) ? ";secure" : "");
}


// gets the cookie, if it exists
function get_cookie (name) {

  var start = document.cookie.indexOf( name + "=" );
  var len = start + name.length + 1;
  if ((!start) && (name != document.cookie.substring(0, name.length))) {
    return null;
  }

  if (start == -1) {
    return null;
  }

  var end = document.cookie.indexOf(";", len);
  if (end == -1) {
    end = document.cookie.length;
  }

  return unescape(document.cookie.substring(len, end));
}


// this deletes the cookie when called
function delete_cookie (name, path, domain) {

  if (get_cookie(name)) {
    document.cookie = name + "=" +
    ((path) ? ";path=" + path : "") +
    ((domain) ? ";domain=" + domain : "") +
    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
  }
}



// sets the affiliate cookie if there is on the url
function set_affiliate_cookie () {

  // get url & create regexp;
  var win_url    = window.location.href;
  var aff_regexp = /aff(_id)?=(\d+)/i;

  // is there an aff_id on the url set the cookie
  if (aff_regexp.test(win_url)) {

    var m = aff_regexp.exec(win_url);
    set_cookie("AFF_ID", m[2], 30, '/', '.meccabingo.com', '')
    //sub
    var m = aff_regexp.exec(win_url);
    var sub_regexp = /sub(_id)?=(.+)/i;

    // is there an aff_id on the url set the cookie
    if (sub_regexp.test(win_url)) {
      var m = sub_regexp.exec(win_url);
      set_cookie("SUB_ID", m[2], 30, '/', '.meccabingo.com', '');
    }
  }


}

// call set function
set_affiliate_cookie();


