/*****************************************************************************/
/* E-BETTING: Online Betting System                                  v1.0.00 */
/* ================================                                          */
/*                                                                           */
/* Copyright (c) 2002 etote Ltd.                                             */
/* mail:info@e-tote.ltd.uk                                                   */
/* http://www.e-tote.ltd.uk/                                                 */
/*                                                                           */
/* E-BETTING is an online betting system allowing partner sites to offer     */
/* a range of betting options from the etote Ltd website.                    */
/*                                                                           */
/* etote Ltd. is a wholly owned subsidiary of DataTote (England) Ltd.        */
/*                                                                           */
/*****************************************************************************/

if (document.compatMode && document.compatMode != 'CSS1Compat') {
  alert('Your browser does not support the latest standards required by this site\nand may not render this site correctly.\n\nTo fix we suggest upgrading your browser to the latest version of\nInternet Explorer or Firefox.');
}

/*
 * OVERLIB configuration
 */

var ol_fgclass="fg-tt"
var ol_bgclass="bg-tt"
var ol_cgclass="cg-tt"
var ol_textfontclass="text-tt"
var ol_captionfontclass="caption-tt"
var ol_captionfontclass="caption-tt"
var ol_closefontclass="close-tt"

var ol_shadow=1;
var ol_shadowx=3;
var ol_shadowy=3;
var ol_shadowcolor='#000000';
var ol_shadowopacity=60;




var isIE = (window.navigator.userAgent.match("MSIE ([0-9]{1,}[\.0-9]{0,})") != null);
var isIEVersion = (isIE ? parseFloat(RegExp.$1) : -1);
var isIE6 = (isIE && isIEVersion >= 6.0);
var isIE7 = (isIE && isIEVersion >= 7.0);
var isPreIE7 = (isIE && isIEVersion < 7.0);
var isGecko = (window.navigator.userAgent.indexOf("Gecko/") != -1);

/*
 * CSS Browser Selector v0.3.1
 * Rafael Lima (http://rafael.adm.br)
 * http://rafael.adm.br/css_browser_selector
 * License: http://creativecommons.org/licenses/by/2.5/
 * Contributors: http://rafael.adm.br/css_browser_selector#contributors
 */
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1/*NMT*/+(RegExp.$1<7?' nopng':'')/*NMT*/):is('firefox/2')?g+' ff2':is('firefox/3')?g+' ff3':is('gecko/')?g:/opera(\s|\/)(\d+)/.test(ua)?'opera opera'+RegExp.$2:is('konqueror')?'konqueror':is('chrome')?w+' '+s+' chrome':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);
/* End of CSS Browser Selector */





if (typeof HTMLElement != "undefined" &&
    typeof HTMLElement.innerText != "undefined") {
  HTMLElement.prototype.__defineGetter__("innerText", 
              function () { return(this.textContent); });
  HTMLElement.prototype.__defineSetter__("innerText", 
              function (txt) { this.textContent = txt; });
}

function EBET_QueryVar(name) {
  // Get a variable from the query string
  var re = new RegExp(name+'=([^&]*)', 'i');
  if ((matches = window.location.search.match(re))) {
    return matches[1];
  }
  return null;
}

function EBET_SwapImgRestore() { //v3.0
  var i,x,a=document.ebet_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function EBET_PreloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.ebet_p) d.ebet_p=new Array();
    var i,j=d.ebet_p.length,a=EBET_PreloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.ebet_p[j]=new Image; d.ebet_p[j++].src=a[i];}}
}

function EBET_FindObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=EBET_FindObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function EBET_SwapImage() { //v3.0
  var i,j=0,x,a=EBET_SwapImage.arguments; document.ebet_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=EBET_FindObj(a[i]))!=null){document.ebet_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function EBET_ChangeProp(objName,x,theProp,theValue) { //v3.0
  var obj = EBET_FindObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)) eval("obj."+theProp+"='"+theValue+"'");
}

/* Make an object visible */
function EBET_ShowObj(obj) {
  if (typeof(obj) == 'string') {
    id = obj;
    obj = EBET_FindObj(id);
    if (!obj) {
      alert('No object named: '+id);
      return false;
    }
  }
  if (obj.style) {
    obj.style.visibility = "visible";
  } else {
    obj.visibility = "show";
  }
}

/* Make an object hidden */
function EBET_HideObj(obj) {
  if (typeof(obj) == 'string') {
    id = obj;
    obj = EBET_FindObj(id);
    if (!obj) {
      alert('No object named: '+id);
      return false;
    }
  }
  if (obj.style) {
    obj.style.visibility = "hidden";
  } else {
    obj.visibility = "hide";
  }
}


function EBET_VerisignPopUp(url) {
  if (!url) {
    url = 'https://servicecenter.verisign.com/cgi-bin/Xquery.exe?Template=authCertByIssuer&remote_host=https://digitalid.trustwise.com/globalServer/cgi-bin/haydn.exe&form_file=../fdf/authCertByIssuer.fdf&issuerSerial=836796a677ca9598d1bdc330ac1553dd'
  }
  var sealWin = window.open(url, 'win', 'toolbar=0,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,WIDTH=700,height=450');
  if (!sealWin) {
    alert('Failed to open new window showing security information');
  }
}

function EBET_SetCtrlProp(frm,ctl,prop,val) {
  //alert('EBET_SetValue("'+frm+'","'+ctl+'","'+prop+","+val+'")');
  var form = window.document.forms[frm];
  if (!form) {
    alert('No form named: '+frm);
    return false;
  }

  var elm = form.elements[ctl] ;
  if (!elm) {
    alert('No form element named: '+ctl);
    return false;
  }

  return EBET_SetElementProp(elm,prop,val);
}

function EBET_SetElementProp(elm,prop,val) {
  if (typeof elm == 'string') {
    elm = document.getElementById(elm);
  }

  if (!elm) {
    return false;
  }

  eval("elm."+prop+" = '"+val+"'");

  return true;
}

// Repopulate with the new options
// The input data can be an array/object where each element/member is an object
// with the members 'value' and 'text', in this case if the 'value' member is
// missing then the array/object index/member is used.
// Alternatively it can be an array/object where each element/member is a
// strings, in this case if the 'value' member is  missing then the
// array/object index/member is used.
function EBET_SetCtrlOptions(frm,sel,opts,val) {
  var form = window.document.forms[frm];
  if (!form) {
    alert('No form named: '+frm);
    return false;
  }

  var elm = form.elements[sel];
  if (!elm) {
    alert('No form element named: '+sel);
    return false;
  }

  return EBET_SetElementOptions(elm, opts, val);
}

function EBET_SetElementOptions(elm,opts,val) {

  if (typeof elm == 'string') {
    elm = document.getElementById(elm);
  }

  if (!elm) {
    return false;
  }

  if (elm.tagName != 'SELECT') {
    alert('Element '+elm.id+' is not a SELECT');
    return false;
  }

  if (opts && typeof opts.length == 'undefined') {
      var i = 0;
      for (key in opts)
          i++;
      opts.length = i;
  }

  // Empty the select box
  select.options.length = 0;

  if (opts && opts.length != 0) {
    // Repopulate with the new options from opts
    select.options.length = opts.length;

    var i = 0, key, value, text;
    for (key in opts) {
      if (key != 'length') {
        if (typeof opts[key] == 'string') {
          value = key;
          text = opts[key];
        } else {
          value = opts[key].value || key;
          text =  opts[key].text;
        }
        select.options[i].value = value;
        select.options[i].text =  text;
        if (value == val) {
          select.selectedIndex = i;
        }
        i++;
      }
    }
  }

  return true;
}

function EBET_SetCtrlValue(frm,sel,val) {
  var form = window.document.forms[frm];
  if (!form) {
    alert('No form named: '+frm);
    return false;
  }

  var elm = form.elements[sel];
  if (!elm) {
    alert('No form element named: '+sel);
    return false;
  }

  return EBET_SetElementValue(elm,val);
}

function EBET_SetElementValue(elm,val) {

  if (typeof elm == 'string') {
    elm = document.getElementById(elm);
  }

  if (!elm) {
    return false;
  }

  if (elm.tagName == 'SELECT') {
    elm.selectedIndex = 0;
    if (val) {
      var i, max_i;
      for (i = 0, max_i = elm.options.length; i < elm.options.length; i++) {
        if (elm.options[i].value == val) {
            elm.selectedIndex = i;
        }
      }
    }
  } else if (elm.tagName == 'RADIO') {
    // Clear all other radios with the same name
    var i, max_i, elms = document.getElementsByTagName('RADIO');
    for (i = 0, max_i = elms.length; i < max_i; i++) {
      if (elms[i].name == elm.name) {
        elms[i].checked = false;
      }
    }
    elm.checked = (elm.value == val);
  } else if (elm.tagName == 'CHECKBOX') {
    elm.checked = (elm.value == val);
  } else {
    elm.value = val;
  }

  return true;
}

function EBET_SetCtrlFocus(frm,ctl,val) {
  var form = window.document.forms[frm];
  if (!form) {
    alert('No form named: '+frm);
    return false;
  }

  var elm = form.elements[ctl];
  if (!elm) {
    alert('No form element named: '+ctl);
    return false;
  }

  return EBET_SetElementFocus(elm,val);
}

function EBET_SetElementFocus(id,val) {
  var elm = document.getElementById(id);
  if (!elm) {
    alert('No element with id: '+id);
    return false;
  }

  if (val) {
    elm.focus();
  } else {
    elm.blur();
  }

  return true;
}

function EBET_HoverOver(elm) {
  if (typeof elm == 'string') {
    if (!(elm = document.getElementById(elm))) {
      return;
    }
  }
  elm.className = elm.className.replace(/\bhover\b/, "")+" hover";
}

function EBET_HoverOut(elm) {
  if (typeof elm == 'string') {
    if (!(elm = document.getElementById(elm))) {
      return;
    }
  }
  elm.className = elm.className.replace(/\bhover\b/, "");
}

function _EBET_OnCellHoverOver(event) {
  EBET_HoverOver(this);
  // Do the same to the parent TR
  EBET_HoverOver(this.parentNode);
}

function _EBET_OnCellHoverOut(event) {
  EBET_HoverOut(this);
  // Do the same to the parent TR
  EBET_HoverOut(this.parentNode);
}

  
function EBET_GetParentByTagName(el, tagName) {
  if (el == null) {
    return null;
  } else if (el.tagName == tagName) {
    return el;
  } else {
    return EBET_GetParentByTagName(el.parentNode, tagName);
  }
}

/* Add striping classes and hover events to given elements */
function _EBET_Stripe(elms, tagName, baseClassName) {
  var last = null;
  for (var i = 0, c = 1, max_i = (elms.length - 1); i <= max_i; i++) {
    if (elms[i].tagName == tagName || (tagName == "TD" && elms[i].tagName == "TH")) {
      var className = " ";
      if (c == 1) {
        className += baseClassName+"-first first ";
      }
      className += baseClassName+"-"+(c & 1 ? "odd odd " : "even even ")+baseClassName+"-"+c+" "+baseClassName;
  
      elms[i].className += className;
  
      if (isPreIE7 && (elms[i].tagName == "TD" || elms[i].tagName == "TH")) {
        EBET_AddEventHandler(elms[i], "mouseover", _EBET_OnCellHoverOver);
        EBET_AddEventHandler(elms[i], "mouseout", _EBET_OnCellHoverOut);
      }
      last = elms[i];
      c++;
    }
  }
  if (last) {
    last.className = baseClassName+"-last last "+last.className;
  }
}

/* Initilise all striped elements */
function EBET_StripeInit() {
  // Initialise all striped elements to support zebra styles and hovers

  var elements = document.getElementsByTagName('TABLE');
  for (var i = 0, max_i = elements.length; i < max_i; i++) {
    if ((m = elements[i].className.match(/(\s|^)(grid|striped|form)(\s|$)/))) {
      EBET_GridInit(elements[i], m[0]);
    }
  }

  var elements = document.getElementsByTagName('UL');
  for (var i = 0, max_i = elements.length; i < max_i; i++) {
    if (elements[i].className.match(/(\s|^)striped(\s|$)/)) {
      EBET_ListInit(elements[i]);
    }
  }

  var elements = document.getElementsByTagName('OL');
  for (var i = 0, max_i = elements.length; i < max_i; i++) {
    if (elements[i].className.match(/(\s|^)striped(\s|$)/)) {
      EBET_ListInit(elements[i]);
    }
  }
}
 
/* Initialise a grid */
function EBET_GridInit(table, baseClassName) {
  if (typeof table == 'string') {
    if (!(table = document.getElementById(table))) {
      return;
    }
  }

  if (typeof baseClassName == 'undefined')  { baseClassName = 'grid'; }

  // First check that the grid is a table
  if (!table.tagName || table.tagName != "TABLE") {
    //alert("EBET_GridInit() - element is not a table: "+table.id);
    return;
  }

  // Ensure it has the correct base class name
  table.className = table.className + " "+baseClassName;

  // Get all its column elements and
  // ensure they have grid class and number them
  var cols = table.getElementsByTagName("COL");

  // Weed out COLS of which this table is the parent
  var our_cols = [];
  for (var i = 0, max_i = cols.length; i < max_i; i++) {
    if (EBET_GetParentByTagName(cols[i], "TABLE") == table) {
      our_cols[our_cols.length] = cols[i];
    }
  }

  _EBET_Stripe(our_cols, "COL", baseClassName);

  // Get all its head sections and
  // ensure they have grid class and number them
  var sectionNames = ["COLGROUP", "THEAD", "TBODY", "TFOOT"];
  var sections = table.childNodes;

  // For each section name
  for (var n = 0, max_n = sectionNames.length; n < max_n; n++) {

    // Strip all child sections of this table
    _EBET_Stripe(sections, sectionNames[n],  baseClassName);

    // For each section
    for (var s = 0, max_s = sections.length; s < max_s; s++) {

      if (sections[s].tagName == sectionNames[n]) {
        // Strip all child rows of this section
        var rows = sections[s].childNodes;
        _EBET_Stripe(rows, "TR", baseClassName);
   
        // For each row
        for (var r = 0, max_r = rows.length; r < max_r; r++) {
  
          if (rows[r].tagName == "TR") {
            // Strip all child cells of this row
            var cells = rows[r].childNodes;
            _EBET_Stripe(cells, "TD", baseClassName);
          }

        }
      }

    }
  }

  if (isGecko) {
    // Force FireFox to redraw the table otherwise any cell borders are not added
    table.innerHTML = table.innerHTML;
  }

}

/* Initialise a list */
function EBET_ListInit(list) {
  if (typeof list == 'string') {
    if (!(list = document.getElementById(list))) {
      return;
    }
  }

  // First check that the list is a OL or UL tag
  if (!list.tagName || (list.tagName != "OL" && list.tagName != "UL")) {
    //alert("EBET_ListInit() - element is not a list : "+list.id);
    return;
  }

  // Ensure it has the striped class
  list.className = list.className.replace(/(\s+|^)striped(\s+|$)/, "") + " striped ";

  // Strip all child LI's
  var children = list.childNodes;
  _EBET_Stripe(children, "LI",  "striped");

  // Nested lists are not yet supported

  if (navigator.userAgent.indexOf("Gecko") != -1) {
    // Force FireFox to redraw the list otherwise any cell borders are not added
    list.innerHTML = list.innerHTML;
  }
}

function EBET_GetWinContentSize(win)
{
  var ret = { contentWidth: 0 , contentHeight: 0 };

  if (window.scrollWidth) {
    ret.contentWidth = window.scrollWidth;
    ret.contentHeight = window.scrollHeight;
  } else if (window.document.documentElement && window.document.documentElement.scrollWidth) {
    ret.contentWidth = window.document.documentElement.scrollWidth;
    ret.contentHeight = window.document.documentElement.scrollHeight;
  } else if (window.document.body && window.document.body.scrollWidth) {
    ret.contentWidth = window.document.body.scrollWidth;
    ret.contentHeight = window.document.body.scrollHeight;
  }

  return ret;
}

function EBET_WinCenter(win, windowW, windowH)
{
  var screenW = screen.availWidth ? screen.availWidth : screen.width;
  var screenH = screen.availHeight ? screen.availHeight : screen.height;

  if (!windowW) {
    if (win.innerWidth) {
      windowW = win.innerWidth;
    } else if (win.document.documentElement) {
      windowW = win.document.documentElement.offsetWidth;
    } else {
      windowW = win.document.body.offsetWidth;
    }
  }
  
  if (!windowH) {
    if (win.innerWidth) {
      windowH = win.innerHeight;
    } else if (win.document.documentElement) {
      windowH = win.document.documentElement.offsetHeight;
    } else {
      windowH = win.document.body.offsetHeight;
    }
  }

  var windowX = Math.round((screenW - windowW) / 2);
  var windowY = Math.round((screenH - windowH) / 2);

  win.moveTo(windowX, windowY);

  return { left: windowX, right: windowY };
}

function EBET_WinSize(win, windowW, windowH)
{
  win.resizeTo(windowW, windowH);
}

function EBET_WinShrink(win, minWidth, minHeight) {
  if (typeof minWidth == 'undefined')  { minWidth = 0; }
  if (typeof minHeight == 'undefined')  { minHeight = 0; }

  var d = win.document.documentElement, b = win.document.body;

  win.document.body.style.overflow = 'visible';

  // Squash content to minumum size
  win.resizeTo(0, 0);

  // Get amount of overflow
  var contentW = 0, contentH = 0;
  if (win.scrollWidth) {
    contentW = win.scrollWidth;
    contentH = win.scrollHeight;
  } else if (d && d.scrollWidth) {
    contentW = d.scrollWidth;
    contentH = d.scrollHeight;
  } else if (b && b.scrollWidth) {
    contentW = b.scrollWidth;
    contentH = b.scrollHeight;
  }

  //alert('contentW='+contentW+', contentH='+contentH);

  win.document.body.style.overflow = 'hidden';

  // Resize to bigger than content so as to loose scrollbars
  win.resizeTo(contentW + 200, contentH + 200);
  
  var windowW = 0, windowH = 0;
  if (win.innerWidth) {
    windowW = win.innerWidth;
    windowH = win.innerHeight;
  } else if (d && d.clientWidth) {
    windowW = d.clientWidth;
    windowH = d.clientHeight;
  } else if (b && b.clientWidth) {
    windowW = b.clientWidth;
    windowH = b.clientHeight;
  }
  
  if (win.opera && !win.document.childNodes) {
    windowW += 16;
  }
  
  var frameW = (contentW + 200) - windowW;
  var frameH = (contentH + 200) - windowH;
  
  //alert('windowW='+windowW+', windowH='+windowH+', frameW='+frameW+', frameH='+frameH+', contentW='+contentW+', contentH='+contentH);

  var windowW = Math.max(contentW, minWidth) + frameW;
  var windowH = Math.max(contentH, minHeight) + frameH;

  win.resizeTo(windowW, windowH);

  EBET_WinCenter(win, windowW, windowH);
}

function EBET_WinPopup(url, name, width, height, resizable) {
  if (typeof name == 'undefined') { name = 'ebet_popup'; }
  if (typeof width == 'undefined')  { width = 400; }
  if (typeof height == 'undefined')  { height = 300; }
  if (typeof resizable == 'undefined')  { resizable = 1; }

  var screenW = screen.availWidth ? screen.availWidth : screen.width;
  var screenH = screen.availHeight ? screen.availHeight : screen.height;

  var left = Math.round((screenW - width) / 2);
  var top = Math.round((screenH - height) / 2);

  var popwin = window.open(url, name, 'alwaysRaised=1,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable='+resizable+',left='+left+',top='+top+',height='+height+',width='+width);
  if (!popwin) {
    alert('Failed to open '+name+' window - please ensure any popup blockers are disabled for this site');
    return null;
  }

  popwin.focus();

  return popwin;
}

function EBET_HelpPopup(url) {
  return EBET_WinPopup(url, 'ebet_help', 350, 300, 1);
}

function EBET_VideoPopup(stadium, opportunity) {
  var url = ebet.url.root+'/video.php?skin='+ebet.partner+'&sessid=' + ebet.video_sid + (stadium ? '&stadium=' + stadium : '') + (opportunity ? '&opportunity=' + opportunity : '');

  return EBET_WinPopup(url, 'ebet_video', 612, 512, 0);
}

function EBET_VTVPopup() {
  return EBET_WinPopup(ebet.url.root+'/index.php?page=vtv/vtv', ebet.partner + '_vtvpop', 600, 500, 1);
}

function EBET_TVPopup() {
  return EBET_WinPopup(ebet.url.root+'/index.php?page=help/tv', ebet.partner + '_tvpop', 600, 500, 1);
}

ebet_vtv_init = false;
function EBET_VTVInit() {
  if (!isIE || ebet_vtv_init) {
    return;
  }

  document.body.innerHTML += '<object id="ebet_vtvobj" style="position:absolute;" classid="CLSID:E7303E08-D0E7-4903-99CD-89D38B8C1C80" width="1" height="1"><div id="ebet_novtv"></div></object>';

  ebet_vtv_init = true;
}

function EBET_VTVMove() {
  if (!isIE) {
    return;
  }

  EBET_VTVInit();
 
  if (document.getElementById('ebet_novtv')) {
    return;
  }

  var obj = document.getElementById('ebet_vtvobj');
  if (obj) {
    obj.style.top = event.clientY - 2;
    obj.style.left = event.clientX - 2;
  }
}

function EBET_CouponShowStatistics() {
  var selections = document.getElementById('coupon-selections');
  var statistics = document.getElementById('coupon-statistics');
  var button = document.getElementById('button-couponstats');
  if (!selections || !statistics || !button) {
    return;
  }
  selections.style.display = 'none';
  statistics.style.display = 'block';
  button.value = selections.title;
}

function EBET_CouponShowSelections() {
  var selections = document.getElementById('coupon-selections');
  var statistics = document.getElementById('coupon-statistics');
  var button = document.getElementById('button-couponstats');
  if (!selections || !statistics || !button) {
    return;
  }
  statistics.style.display = 'none';
  selections.style.display = 'block';
  button.value = statistics.title;
}

function EBET_CouponToggleStats() {
  var selections = document.getElementById('coupon-selections');
  var statistics = document.getElementById('coupon-statistics');
  var button = document.getElementById('button-couponstats');
  if (!selections || !statistics || !button) {
    return;
  }

  if (selections.style.display == 'none') {
      statistics.style.display = 'none';
      selections.style.display = 'block';
      button.value = statistics.title;
      button.className = button.className.replace('statistics', 'selections');
  } else {
      selections.style.display = 'none';
      statistics.style.display = 'block';
      button.value = selections.title;
      button.className = button.className.replace('selections', 'statistics');
  }

  return true;
}

function EBET_CouponTotal(numBets) {
  //alert('EBET_CouponTotal('+numBets+')');
  var elm = document.getElementById('coupon-stake');
  if (!elm) {
    return;
  }

  var total = numBets * elm.value;

  var elm = document.getElementById('coupon-stake-multiplier');
  if (elm) {
    total *= elm.value;
  }

  var elm = document.getElementById('coupon-total');
  if (!elm) {
    return;
  }

  if (elm.tagName == 'INPUT') {
    elm.value = total.toFixed(2);
  } else {
    elm.innerHTML = total.toFixed(2);
  }
}

function EBET_CouponTotaliseBet(numSels, numCompetitors) {
  //alert('EBET_CouponTotaliseBet('+numSels+', '+numCompetitors+')');
  if (!document.getElementById('coupon-total') ||
      !document.getElementById('coupon-stake')) {
    return;
  }

  var numSels = numSels || (ebet.coupon.numLegs > 1 ? ebet.coupon.numLegs : ebet.coupon.numSelections);
  var numCompetitors = numCompetitors || ebet.coupon.numCompetitors;

  //alert('EBET_CouponTotaliseBet() - numSels='+numSels+', numCompetitors='+numCompetitors);

  var bets = 1;
  var competitors = [];

  // work out the number of selections on each leg
  for (var l = 1; l <= numSels; l++) {
    var sels = 0;
    for (var c = 1; c <= numCompetitors; c++) {
      var id = 'coupon-selection-'+l+'-'+c;
      var elm = document.getElementById(id);
      if (elm && !elm.disabled && elm.checked) {
        sels++;
     }
    }
    bets *= sels;
  }

  var elm = document.getElementById('coupon-allways');
  if (elm && elm.checked) {
    bets *= (2 * numSels);
  }

  EBET_CouponTotal(bets);
}

function EBET_CouponLuckyDip(numSels, numCompetitors) {
  var numSels = numSels || (ebet.coupon.numLegs > 1 ? ebet.coupon.numLegs : ebet.coupon.numSelections);
  var numCompetitors = numCompetitors || ebet.coupon.numCompetitors;

  //alert('EBET_CouponLuckyDip() - numSels='+numSels+', numCompetitors='+numCompetitors);

  // Ensure the coupon is displayed and not the statistics
  EBET_CouponShowSelections();

  // Foreach leg - clear selections and then randomly select a winner
  for (var l = 1; l <= numSels; l++) {
    for (var c = 1; c <= numCompetitors; c++) {
      var id = 'coupon-selection-'+l+'-'+c;
      var elm = document.getElementById(id);
      if (elm && !elm.disabled) {
        elm.checked = false;
      }
    }
    while (true) {
      var c = Math.floor(Math.random() * numCompetitors) + 1;
      var id = 'coupon-selection-'+l+'-'+c;
      var elm = document.getElementById(id);
      if (elm && !elm.disabled) {
        elm.checked = true;
        break;
      }
    }
  }

  EBET_CouponTotal(1);
}

function EBET_CouponUseSel(selection) {
  //alert('EBET_CouponUseSel('+selection+')');
  // clear all check boxes
  var elms = document.getElementsByTagName('INPUT');
  var m = elms.length;
  for (var i = 0; i < m; i++) {
    if (elms[i].type == 'checkbox' && elms[i].id.match(/^coupon-selection-.*$/)) {
      elms[i].checked = false;
    }
  }

  if (selection) {
    for (i in selection) {
      if (typeof selection[i].length != 'number') {
        //alert('Selection '+i+' skipped as not an array');
        continue;
      }
      max_j = selection[i].length;
      for (j = 0; j < max_j; j++) {
        id = 'coupon-selection-'+i+'-'+selection[i][j];
        elm = document.getElementById(id);
        if (!elm) {
          //alert('element coupon-selection-'+i+'-'+selection[i][j]+' was not found');
        } else {
          //alert('id='+id+', elm='+elm);
        }
        if (elm && !elm.disabled) {
          elm.checked = true;
        }
      }
    }
  }

}

function EBET_CouponUseTip(selection) {
  // Ensure the coupon is displayed and not the stats
  EBET_CouponShowSelections();

  // clear any existing selection
  EBET_CouponUseSel(null);

  // check the items in the selection
  var m = selection.length;
  for (var i = 0; i < m; i++) {
    var id = 'coupon-selection-'+(i + 1)+'-'+selection[i];
    var elm = document.getElementById(id);
    if (elm && !elm.disabled) {
      elm.checked = true;
    }
  }
}

function EBET_SetOpportunities1(frm,sel1,sel2,allopts,val1,val2) {
  var form = window.document.forms[frm];
  if (!form) {
    alert('No form named: '+frm);
    return false;
  }

  var select1 = form.elements[sel1];
  if (!select1) {
    alert('No selection box named: '+sel1);
    return false;
  }

  var select2 = form.elements[sel2];
  if (!select2) {
    alert('No selection box named: '+sel2);
    return false;
  }

  // Select any desired item in the first select box
  if (val1 != null && !EBET_SetSelection(frm,sel1,val1)) {
    alert('Failed to selection required meeting in list box');
  }

  // Populate second select box depending on selection in first select box
  var val = select1.options[select1.selectedIndex].value;
  if (!allopts || !(opts = allopts[val])) {
    alert('No options for value: '+val);
    return false;
  }

  // If selection box 2 has multiple win pools then we can offer a quickpick
  /*
  if (opts[0].value.indexOf('QPK') == -1) {
    var opt = null;
    var win = 0;
    for (i = 0; i < opts.length; i++) {
      if (opts[i].value.indexOf('WIN') != -1) {
        if (win == 0) {
          opt = opts[i];
        }
        win++;
      }
    }
    if (win > 1) {
      var o = new Object();
      o.value = opt.value.replace('WIN', 'QPK');
      o.text = 'QuickPick';
      opts.unshift(o);
    }
  }
  */

  // Fill sel2 with options and then select the required option in sel1 and sel2
  if (!EBET_SetOptions(frm,sel2,opts,val2)) {
    alert('Failed to set entries for events/pools list box');
    return false;
  }

  return true;
}

function EBET_SubmitOpportunity1(frm,sel1,sel2) {
  var form = window.document.forms[frm];
  if (!form) {
    alert('No form named: '+frm);
    return false;
  }

  var select1 = form.elements[sel1];
  if (!select1) {
    alert('No selection box named: '+sel1);
    return false;
  }

  var select2 = form.elements[sel2];
  if (!select2) {
    alert('No selection box named: '+sel2);
    return false;
  }

  // Check the user selected an option with a value (ie. not a divider)
  var val = select2.options[select2.selectedIndex].value;
  if (!val) {
    alert('You can not select this entry - please choose another');
    return false;
  }

  return true;
}

function EBET_SetOpportunities(frm,meeting_sel,event_sel,pool_sel,data,meeting_id,event_id,pool_id) {
  //alert('EBET_SetOpportunities('+frm+','+meeting_sel+','+event_sel+','+pool_sel+','+data+','+meeting_id+','+event_id+','+pool_id+')');

  if (!data) {
    alert('No opportunities');
    return false;
  }

  var form = window.document.forms[frm];
  if (!form) {
    alert('No form named: '+frm);
    return false;
  }

  var select1 = form.elements[meeting_sel];
  if (!select1) {
    alert('No selection box named: '+meeting_sel);
    return false;
  }

  var select2 = form.elements[event_sel];
  if (!select2) {
    alert('No selection box named: '+event_sel);
    return false;
  }

  var select3 = form.elements[pool_sel];
  if (!select3) {
    alert('No selection box named: '+pool_sel);
    return false;
  }

  var meeting_data = null;
  var event_data = null;

  if (meeting_id != -1) {
      // Fill meeting_sel with options and then select the required option
      if (!EBET_SetOptions(frm,meeting_sel,data,meeting_id)) {
        alert('Failed to set entries for meetings list box');
        return false;
      }
      if (event_id == -1) { event_id = null; }
  }

  meeting_id = select1.options[select1.selectedIndex].value;

  if (!data || !(meeting_data = data[meeting_id])) {
    alert('No details for meeting: '+meeting_id);
    return false;
  }

  // Populate second select box depending on selection in first select box
  if (event_id != -1) {
      // Fill event_sel with options and then select the required option
      if (!EBET_SetOptions(frm,event_sel,meeting_data.events,event_id)) {
        alert('Failed to set entries for events list box');
        return false;
      }
      if (pool_id == -1) { pool_id = null; }
  }

  event_id = select2.options[select2.selectedIndex].value;
  if (!meeting_data || !(event_data = meeting_data.events[event_id])) {
    alert('No details for event: '+event_id);
    return false;
  }

  // Populate third select box depending on selection in second select box
  if (pool_id != -1) {
    // If meeting is virtual then just disable the box
    select3.disabled = meeting_data.virtual;
    select3.selectedIndex = 0;

    // Remove the jackpot pool
    var i, max_i = select3.options.length; 
    for (i = 0; i < max_i; i++) {
      if (select3.options[i].value.charAt(0) == 'J') {
        select3.options[i] = null;
      } else if (select3.options[i].value == pool_id) {
          select3.selectedIndex = i;
      }
    }

    // Insert the correct jackpot pool if required
    if (meeting_data.jackpot) {
      i = select3.options.length; 
      select3.options.length++; 
      select3.options[i] = new Option();
      select3.options[i].value = meeting_data.jackpot.pool_id+':'+meeting_data.jackpot.event_id;
      select3.options[i].text = meeting_data.jackpot.text;
      if (meeting_data.jackpot.pool_id == pool_id) {
          select3.selectedIndex = i;
      }
    }
  }

  return true;
}

function EBET_SubmitOpportunity(frm,meeting_sel,event_sel,pool_sel) {
  var form = window.document.forms[frm];
  if (!form) {
    alert('No form named: '+frm);
    return false;
  }

  var select1 = form.elements[meeting_sel];
  if (!select1) {
    alert('No selection box named: '+meeting_sel);
    return false;
  }

  var select2 = form.elements[event_sel];
  if (!select2) {
    alert('No selection box named: '+event_sel);
    return false;
  }

  var select3 = form.elements[pool_sel];
  if (!select3) {
    alert('No selection box named: '+pool_sel);
    return false;
  }

  var hidden = form.elements['opportunity'];
  if (!hidden) {
    alert('No hidden element named: opportunity');
    return false;
  }

  // Check the user selected an option with a value (ie. not a divider)
  var meeting_id = select1.options[select1.selectedIndex].value;
  if (!meeting_id) {
    alert('You must select a valid meeting');
    return false;
  }

  var event_id = select2.options[select2.selectedIndex].value;
  if (!event_id) {
    alert('You must select a valid event');
    return false;
  }

  var pool_id = select3.options[select3.selectedIndex].value;
  if (!pool_id) {
    alert('You must select a valid pool');
    return false;
  }

  // For jackpot pools, which appear on all events, the real event id
  // is stored in the pool_id value when required.
  if (pool_id.charAt(0) == 'J') {
    var s = pool_id.split(':', 2);
    if (s.length > 1) {
      pool_id = s[0];
      event_id = s[1];
    }
  }

  hidden.value = meeting_id+','+event_id+','+pool_id;

  return true;
}

EBET_SelectCalendar = function() {
  this.select = null;
  this.calendar = null;

  this.onSelected = null;

  this.onCalendarClose = function(cal) {
    if (!cal.dateClicked) {
      cal._obj.select.selectedIndex = -1;
    }
    cal.hide();
  };

  this.onCalendarSelect = function(cal, date) {
    var opt = cal._obj.select.options[cal._obj.select.selectedIndex];
    var val = opt.value;
    var txt = opt.text;
    var fmt = opt.getAttribute('_date_format');

    val = val.replace(/\d{8}$/, cal.date.print('%Y%m%d'));
    if (!fmt || fmt == '') {
      txt = date;
    } else {
      txt = fmt.replace('%', date);
    }

    cal._obj.addDate(val, txt, cal._obj.select);

    if (cal.dateClicked) {
      cal.callCloseHandler();
    }

    if (cal._obj.onSelected) {
      cal._obj.onSelected(cal._obj);
    }
  };

  this.getCalendar = function() {
    if (this.calendar) {
      this.calendar.hide();
      return this.calendar;
    }

    this.calendar = new Calendar(0, null, this.onCalendarSelect, this.onCalendarClose);
    this.calendar.showsTime = false;
    this.calendar.weekNumbers = false;
    this.calendar.showsOtherMonths = false;
    this.calendar.setRange(1900, 2070);
    this.calendar.setDateFormat('%a, %b %e %Y');
    this.calendar.setTtDateFormat('%a, %b %e %Y');
    this.calendar.create(); // creates a popup calendar

    this.calendar._obj = this;

    return this.calendar;
  };

  this.selectDate = function(elm) {
    this.select = elm;

    var value =  elm.options[elm.selectedIndex].value;
    var text = elm.options[elm.selectedIndex].text;
    var m, re = /(\d{8})$/;

    if (m = value.match(re)) {
      var cal = this.getCalendar();
  
      if (m[1] != '00000000') {
        cal.parseDate(m[1]);
      }
  
      cal.showAtElement(elm, 'Tl');

      return true;
    }

    return false;
  };

  this.addDate = function(val, txt, sel) {
    var l = sel.options.length++;
    sel.options[l].value = val;
    sel.options[l].text = txt;
    sel.selectedIndex = l;
    return true;
  };

}


function EBET_AddEventHandler(el, type, fn) {
  if (el.attachEvent) { // IE
    el["e"+type+fn] = fn;
    el[type+fn] = function() { el["e"+type+fn](window.event); }
    el.attachEvent("on" + type, el[type+fn]);
  } else if (el.addEventListener) { // Gecko / W3C
    el.addEventListener(type, fn, true);
  } else {
    el["on" + type] = fn;
  }
}

function EBET_RemoveEventHandler(el, type, fn) {
  if (el.detachEvent) { // IE
    el.detachEvent("on"+type, el[type+fn]);
    el[type+fn] = null;
    el["e"+type+fn] = null;
  } else if (el.removeEventListener) { // Gecko / W3C
    el.removeEventListener(type, fn, true);
  } else {
    el["on" + type] = null;
  }
}


function EBET_CancelBubble(event) {
  if (event && event.stopPropagation) {
    event.stopPropagation();
  } else if (window.event) {
    window.event.cancelBubble = true;
  }
}

function EBET_SetCookie(name, value) {
  document.cookie = name + '=' + escape(value);
}

function EBET_GetCookie(name) {
  if (!document.cookie) {
    return null;
  }

  var cookies = ' ' + document.cookie;
  var start = cookies.indexOf(' ' + name + '=');
  if (start == -1) {
    return null;
  }

  var end = cookies.indexOf(';', start);
  if (end == -1) {
    end = cookies.length;
  }

  var cookie = cookies.substr(start, end - start);
  var equpos = cookie.indexOf('=');

  return unescape(cookie.substr(equpos + 1, cookie.length - equpos + 1));
}

function EBET_WordFind(str, find) {
  return str.match(new RegExp('(\\s|^)'+find+'(\\s|$)'));
}

function EBET_WordSwap(str, from, to) {
  return str.replace(new RegExp('(\\s+|^)'+from+'(\\s+|$)'), '$1'+to+'$2');
}

function EBET_ClassToggle(elm, from, to, store) {
  if (typeof elm == 'string') {
    elm = document.getElementById(elm);
  }

  if (!elm) {
    return false;
  }

  if (EBET_WordFind(elm.className, from)) {
    elm.className = EBET_WordSwap(elm.className, from, to);
  } else {
    elm.className = EBET_WordSwap(elm.className, to, from);
  }
  if (store) {
    EBET_SetCookie(elm.id+'.className', elm.className);
  } 
}

function EBET_ClassInit(elm) {
  if (typeof elm == 'string') {
    elm = document.getElementById(elm);
  }

  if (!elm) {
    return false;
  }

  var className = EBET_GetCookie(elm.id+'.className');
  if (className != null) {
    elm.className = className;
  }
}

function EBET_GetIBlock(id) {
  var elm;
  if (!(elm = document.getElementById('iblock-'+id))) {
    return null;
  }

  var iblock = {
    'id': id,
    'div': elm,
    'elm': function(which, doc) {
        if (!doc) { doc = document; }
        return doc.getElementById('iblock-'+this.id+'-'+which);
      },
    'set': function(which, html) {
        var elm;
        if (!(elm = this.elm(which))) {
          return null;
        }
        elm.innerHTML = html;
      },
    'caption': function(caption) { this.set('caption', caption); this.loading(false); },
    'content': function(content) { this.set('content', content); this.loading(false); },
    'loading': function(loading) {
        var elm;
        if (!(elm = this.elm('refresh'))) {
          return null;
        }
        this.div.className = (loading ? this.div.className.replace('loaded', 'loading') : this.div.className.replace('loading', 'loaded'));
        elm.src = (loading ? elm.src.replace('loaded', 'loading') : elm.src.replace('loading', 'loaded'));
      },
    'refresh': function() {
        var elm;
        if (!(elm = this.elm('iframe'))) {
          return null;
        }
        this.loading(true);
        elm.src = elm.src;
      },
    'sync': function() {
        var iframe, elm;
        if (!(iframe = this.elm('iframe'))) {
          alert('block['+this.id+'].sync() - iframe missing');
          return;
        }
        if ((elm = this.elm('caption', iframe.contentWindow.document))) {
          this.caption(elm.innerHTML);
        }
        if ((elm = this.elm('content', iframe.contentWindow.document))) {
          this.content(elm.innerHTML);
        }
      }
  };

  return iblock;
}

function EBET_IBlockRefresh(id) {
  var block = EBET_GetIBlock(id);
  if (!block) {
    alert('EBET_IBlockRefresh(): No iblock: '+id);
  } else {
    block.refresh();
  }
}

function EBET_IBlockSync(id) {
  var block = EBET_GetIBlock(id);
  if (!block) {
    alert('EBET_IBlockSync(): No iblock: '+id);
  } else {
    block.sync();
  }
}

function EBET_EmbedSendMsg(msg) {
  if (!ebet.embed || !ebet.embed.ctlurl || !ebet.embed.initialised) {
    return;
  }
  var src = ebet.embed.ctlurl+msg;
  var control_iframe = document.getElementById('_ebet_control_frame');
  if (control_iframe) {
    control_iframe.src = src;
  }
}

function _EBET_EmbedInitRemote() {
  // Get amount of overflow
  window.document.body.style.overflow = 'visible';
  var size = EBET_GetWinContentSize(window);
  EBET_EmbedSendMsg('op=init&height='+size.contentHeight+'&width='+size.contentWidth);
  window.document.body.style.overflow = 'hidden'; // Remove IFRAME scrollbars in IE
}

function EBET_EmbedInit() {
  if (!ebet.embed || !ebet.embed.ctlurl || ebet.embed.initialised) {
    return;
  }
  document.write('<iframe id="_ebet_control_frame" height="0" width="0" border="0" frameBorder="no" marginheight="0" marginwidth="0" scrolling="auto" src=""></iframe>');
  EBET_AtContentLoaded('_EBET_EmbedInitRemote()');
  ebet.embed.initialised = true;
}

/* Add a string to be evaluated as code to be run at load time */
_ebet_atLoadFuncs = new Array();
function EBET_AtLoad(func) {
  _ebet_atLoadFuncs[_ebet_atLoadFuncs.length] = func;
}

function _EBET_OnLoad() {
  _EBET_OnContentLoaded();

  for (var i = 0; i < _ebet_atLoadFuncs.length; i++) {
    if (typeof _ebet_atLoadFuncs[i] == 'function') {
      _ebet_atLoadFuncs[i]();
    } else {
      eval(_ebet_atLoadFuncs[i]);
    }
  }

}

/* Add a string to be evaluated as code to be run when DOM is ready */
_ebet_atContentLoadedFuncs = new Array();
function EBET_AtContentLoaded(func) {
  _ebet_atContentLoadedFuncs[_ebet_atContentLoadedFuncs.length] = func;
}

_ebet_onContentLoaded = false;

function _EBET_OnContentLoaded() {
  if (_ebet_onContentLoaded) {
    return;
  }
  _ebet_onContentLoaded = true;

  // Initialise all forms
  if (document.getElementsByTagName) {
    // Fixup text widths for IE controls as they render differently in
    // Standard compliant mode to what we require
    // FF and IE compatible - only works on elements with width set
    var adjust = (isIE ? 6 : 4);
    var ctls = document.getElementsByTagName('INPUT');
    //alert('checking width of '+ctls.length+' controls');
    for (var i = 0, max_i = ctls.length; i < max_i; i++) {
      var ctl = ctls[i];
      var w = null;
      if (ctl.currentStyle) {
        w = ctl.currentStyle.width + "";
      } else if (document.defaultView && document.defaultView.getComputedStyle) {
        w = document.defaultView.getComputedStyle(ctl,null).width + "";
      }
      if (w.match(/px/) && (w = parseInt(w))) {
        if (w > adjust && (ctl.type == 'text' || ctl.type == 'password')) {
          ctl.style.width = (w - adjust) + 'px';
          //alert('adjusting width of '+ctl.id+' from '+w+'px to '+ctl.style.width);
        }
      }
    }

    EBET_StripeInit();

  } else {
    // Fixup text widths for IE controls as they render differently in
    // Standard compliant mode to what we require
    // IE only
    for (var f = 0, max_f = window.document.forms.length; f < max_f; f++) {
      var form  = window.document.forms[i];
      for (var i = 0, max_i = form.elements.length; i < max_i; i++) {
        var ctl = form.elements[i];
        var w = parseInt(ctl.style.width);
        if (w > 6 && (ctl.type == 'text' || ctl.type == 'password')) {
          ctl.style.width = (w - 6) + 'px';
        }
      }
    }
  }

  for (var i = 0; i < _ebet_atContentLoadedFuncs.length; i++) {
    if (typeof _ebet_atContentLoadedFuncs[i] == 'function') {
      _ebet_atContentLoadedFuncs[i]();
    } else {
      eval(_ebet_atContentLoadedFuncs[i]);
    }
  }

}


if (document.addEventListener)
  document.addEventListener("DOMContentLoaded", _EBET_OnContentLoaded, false)
/*
else if (document.all && !window.opera){
  document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>')
  var contentloadtag = document.getElementById("contentloadtag")
  contentloadtag.onreadystatechange = function() {
    alert('onreadystatechange='+this.readyState);
    if (this.readyState == "complete") {
      _EBET_OnContentLoaded();
    }
  }
}
*/

window.onload = _EBET_OnLoad;

/* vim: set expandtab tabstop=2 shiftwidth=2: */

