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

// global flash check
var MM_contentVersion = 7;
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.href = "/common/download_flash.html";
}

// 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 +"\">");
  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 + "\"></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);

}


// writes out a combo box
function write_combo()
{
  var sel = arguments[0];
  var i;

  for (i = 1; i < arguments.length; i += 2) {
    var v = arguments[i];
    var n = arguments[i+1];
    var sel_tag = (sel == v) ? " selected" : "";
    document.writeln
    ('<option value="' + v + '"' + sel_tag + '>' + n + '</option>');
  }
}


// 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], '', '/', '.meccabingo.com', '');
    //SUB
    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], '', '/', '.meccabingo.com', '');
    }
  }

}

// call set function
set_affiliate_cookie();

