/*
 * $Id: util.js,v 1.9 2009-10-26 14:49:17 byoung Exp $
 * Copyright (c) 2008 Orbis Technology Ltd. All rights reserved.
 */

var error_list = "";
var invalid_str = getXlation("JS_INVALID_STR");

// add an error
function add_error(str) {

	if(error_list.length > 0) {
		error_list += "\n";
	}
	error_list += str;
	return 1;
}

// reset error count
function reset_error() {
	error_list = "";
}

// check username and password are not identical
function ck_user_pass_comb(username,password) {

	if (username == password) {
		return add_error(getXlation("REG_USERNAME_PASS_COMB"));
	}

	return 0;
}

// check a mandatory string
function ck_mandatory(str, desc, min_len, max_len, val_chars) {

	if(str.length <= 0 || (min_len != 0 && str.length < min_len) ||
			(max_len != 0 && str.length > max_len)) {
		return add_error(invalid_str + desc + ".");
	}

	if(val_chars) {
		var re = "^[A-Za-z0-9\.\_\-]*$";
		if(!str.match(new RegExp(re))) {
			return add_error(invalid_str + desc + ".");
		}
	}
	return 0;
}


// check an integer
function ck_integer(str, desc, pm, min_len, max_len) {

	var inStr = str_trim(str, " ");
	var exp = pm ? /^[+-]?[0-9]+$/ : /^[0-9]+$/;

	if(!exp.test(inStr)) {
		return add_error(invalid_str + desc + ".");
	}

	if((min_len != 0 && inStr.length < min_len) || (max_len != 0 && inStr.length > max_len)) {
		return add_error(invalid_str + desc + ".");
	}

	return 0;
}


// check a float
function ck_float(str, desc) {

	var inStr = str_trim(str, " ");
	var exp = /^([0-9]*(\.[0-9]+))$|^([0-9]+(\.)?)$/;

	if((!inStr.length) || !exp.test(inStr)) {
		return add_error(invalid_str + desc + ".");
	}

	return 0;
}


// check a amount field
function ck_amount(str, desc, pm) {

	var inStr = str_trim(str, " ");
	var exp = pm ? /(^[+-]?\d+$)|(^[+-]?\d*\.\d{1,2}$)/ : /(^\d+$)|(^\d*\.\d{1,2}$)/;

	if((!inStr.length) || !inStr.match(new RegExp(exp))) {
		return add_error(invalid_str + desc + ".");
	}

	if (!isNaN(parseFloat(inStr))) {
		var num_val = parseFloat(inStr);
		if (num_val == 0){
			return add_error(invalid_str + desc + ".");
		}
	}

	return 0;
}

// write a select input box
function write_select() {

	var sel = arguments[0];
	var i;
	var n;
	var v;
	var sel_tag;

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

// open a different url
function go_url (url, new_win, win_width, win_height, win_resizeable,
			win_scrollbars, win_menubar) {

	if(new_win == "Y") {

		if (win_resizeable == "Y") {
			win_resizeable = "yes";
		} else {
			win_resizeable = "no";
		}

		if (win_scrollbars == "Y") {
			win_scrollbars = "yes";
		} else {
			win_scrollbars = "no";
		}

		if (win_menubar == "Y") {
			win_menubar = "yes";
		} else {
			win_menubar = "no";
		}

		var newsWin = window.open(url, "newsWin",
			"width=" + win_width +
			",height=" + win_height +
			",toolbar=" + win_menubar +
			",location=" + win_menubar +
			",directories=" + win_menubar +
			",status=yes" +
			",menubar=" + win_menubar +
			",scrollbars=" + win_scrollbars +
			",copyhistory=yes,resizable=" + win_resizeable);
		newsWin.focus();
	} else {
		self.location = url;
	}
}

// submit a form over SSL
function submit_ssl_form(name, action, method) {

	var f = document.forms[name];

	if (typeof(method) == "undefined") {
		method = "post";
	}

	f.action = getParameter("SSL_CGI_URL");
	submit_form(name, action, method);
}


// submit a form
document.bet_uid = getParameter("bet_uid");
function submit_form() {

	var name = arguments[0];
	var action = arguments[1];
	var method = 'get';

	if (arguments.length == 3) {
		method = arguments[2];
	}

	var f = document.forms[name];

	insertInputObj(f, 'hidden', '', 'action', action);

	if(document.bet_uid.length) {
		insertInputObj(f, 'hidden', '', 'bet_uid', document.bet_uid);
		if (getVariable("BETSLIP") == 1) {
			document.bet_uid = document.bet_uid;
		}
	}

	if (getVariable("LOGGED_IN") == 0) {
		insertInputObj(f, 'hidden', '', 'uid', getParameter("uid"));
	}

	f.method = method;
	f.submit();
}

// open the betslip
document.open_betslip = 0;
function view_betslip(url, forceOpen) {

	document.open_betslip = 1;
	if(document.bet_uid.length) {
		url += '&bet_uid=' + document.bet_uid;
	}

	// This is a bit dirty but IE needs to know
	// when it has finished
	setTimeout("actuallyOpen('"+url+"')",1);

	if(forceOpen == true) {
		openContent(this, 'betslipDiv');
	} else {
		expandcontent(this, 'betslipDiv');
	}

	window.scrollTo(0,0);
}

function actuallyOpen(url) {

	var iframe = top.betslip;
	iframe.location.href = url;
}

function go_logout() {
	upd_bet_count(0);
	submit_form('login', 'GoLogout');
}

// Swaps images
function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr;

	for(i=0; a && i<a.length && (x=a[i]) && x.oSrc; i++) {
		x.src=x.oSrc;
	}
}

// Preloads images
function MM_preloadImages() {
	var d=document;

	if (d.images) {
		if (!d.MM_p) {
			d.MM_p=new Array();
		}
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
		for(i=0; i<a.length; i++) {
			if (a[i].indexOf("#") !=0) {
				d.MM_p[j]=new Image;
				d.MM_p[j++].src=a[i];
			}
		}
	}
}

// MM_preloadImages('##TP_GIF_URL##/buttons/odds_bg.gif');

// finds an image element
function MM_findObj(n, d) {
	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=MM_findObj(n,d.layers[i].document);
	}
	if(!x && d.getElementById) {
		x=d.getElementById(n);
	}
	return x;
}



// Swaps images
function MM_swapImage() {
	var i,j=0,x,a=MM_swapImage.arguments;

	document.MM_sr=new Array;

	for(i=0; i<(a.length-2); i+=3) {
		if ((x=MM_findObj(a[i])) !=null) {
			document.MM_sr[j++]=x;
			if(!x.oSrc) {
				x.oSrc=x.src;
			}
			x.src=a[i+2];
		}
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function generic_bg_highlight(id) {

	elems = document.getElementById(id).childNodes;

	for(i = 0; i < elems.length; i++){
		if (elems[i].id == id+"_odds") {
			elems[i].className = "results_bg2_odds";
		} else if (elems[i].id == id+"_hover"){
			elems[i].className = "results_bg2_hover";
		} else {
			elems[i].className = "results_bg2";
		}
	}

}

function generic_bg_lowlight(id) {
	elems = document.getElementById(id).childNodes;

	for(i = 0; i < elems.length; i++){
		if (elems[i].id == id+"_odds") {
			elems[i].className = "odds";
		} else if (elems[i].id == id+"_hover"){
			elems[i].className = "orange";
		} else{
			elems[i].className = "results_bg1";
		}
	}

}

///////////////////////////////////////////////
// JavaScript functions related to the clock //
///////////////////////////////////////////////

var clockID = 0;
var tDate = new Date();

function startClock(y, m, d, h, M, S) {
	tDate = new Date(y, m-1, d, h, M, S);

	_showTime();

	clockID = setTimeout("_updateClock()", 1000);
}

function _showTime() {

	var year = Number(tDate.getFullYear());
	
	var month = Number(tDate.getMonth());
	
	month = getMonthName(month);
	
	var date = Number(tDate.getDate());
	if (date < 10) date = "0"+ date;
	
	var mins = Number(tDate.getMinutes());
	if (mins < 10) mins = "0" + mins;

	var sec = Number(tDate.getSeconds());
	if (sec < 10) sec = "0" + sec;
	
	_getObj("clock").innerHTML = "" +month+" "+date+", "+year+" &nbsp; "+tDate.getHours() + ":" + mins + ":" + sec ;
}

function _updateClock() {
	if (clockID) {
		clearTimeout(clockID);
		clockID  = 0;
	}

	tDate.setTime(tDate.getTime() + 1000);

	_showTime();

	clockID = setTimeout("_updateClock()", 1000);
}

function _getObj(obj) {
	var objRef;

	if(document.all) {
		objRef = eval("document.all." + obj);
	}
	if(document.getElementById) {
		objRef = document.getElementById(obj);
	}

	return objRef;
}

/////////////////////////////////////////////////
// JavaScript function for formatting currency //
/////////////////////////////////////////////////

function formatCurrency(num, addDecimal) {

	num = num.toString().replace(/\£|&pound;|\,/g,'');

	if (isNaN(num)) num = "0";

	var sign = (num == (num = Math.abs(num)));
	num = Math.floor(num * 100 + 0.50000000001);
	var cents = num % 100;
	num = Math.floor(num / 100).toString();

	if (cents < 10) cents = "0" + cents;

	for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++) {
		num = num.substring(0, num.length - (4 * i + 3)) + ',' +
		num.substring(num.length - (4 * i + 3));
	}

	if (typeof(addDecimal) != "undefined" && !addDecimal) {
		return (((sign)?'':'-') + '&pound;' + num);
	} else {
		return (((sign)?'':'-') + '&pound;' + num + '.' + cents);
	}
}

///////////////////////////////////////////////////////////
// JavaScript functions related to customer detail entry //
///////////////////////////////////////////////////////////

var month_length = new Array("31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31");

// check a password and a 'confirm' password
function ck_passwords(pwd, c_pwd) {
	var n_errs = 0;

	n_errs += ck_mandatory(pwd, getXlation("REG_PASSWORD"), 6, 12, 1);
	n_errs += ck_mandatory(c_pwd, getXlation("REG_V_PASSWORD"), 6, 12, 1);

	if(n_errs == 0 && pwd != c_pwd) {
		n_errs += add_error(getXlation("REG_PASS_NOT_MATCH"));
	}

	// must contain a number
	if(n_errs == 0 && !(pwd.match(new RegExp("[0-9]")))) {
		n_errs += add_error(getXlation("REG_PASSWORD_NUM"));
	}

	return n_errs;
}


// function check date of birth
function ck_dob(f) {

	var d = f.d_dob.value;
	var m = f.m_dob.value;
	var y = f.y_dob.value;
	var desc = getXlation("REG_DOB");

	if(ck_integer(d, desc, false, 2, 2) != 0 ||
			ck_integer(m, desc, false, 2, 2) != 0 ||
			ck_integer(y, desc, false, 4, 4) != 0) {
		return 1;
	}

	var im = m;

	if(m.charAt(0) == "0"){
		im = m.charAt(1);
	}

	im = parseInt(im,10);
	var iy = parseInt(y,10);
	var id = parseInt(d,10);

	if(im < 1 || im > 12 || iy < 0) {
		return add_error(invalid_str + desc + ".");
	}

	var len = im == 2 && (iy % 4) == 0 ? 29 : month_length[im - 1];
	if(id < 0 || id > len) {
		return add_error(invalid_str + desc + ".");
	}

	if (id <1) {
		return add_error(invalid_str + desc + ".");
	}

	if (iy <1900) {
		return add_error(invalid_str + desc + ".");
	}


	f.dob.value = d + m + y;
	return 0;
}


// check an email address
function ck_email_addr(addr) {

	var re = "^\w*$";
	var desc = getXlation("REG_EMAIL");

	if(ck_mandatory(addr, desc, 1, 60, 0) != 0) {
		return 1;
	}
	if(addr.match(new RegExp(re))) {
		return add_error(invalid_str + desc + ".");
	}

	var email_re  = "^[^@ ]+@[^@ ]+\\.[^@ ]+$";

	if(!(addr.match(new RegExp(email_re)))) {
		return add_error(invalid_str + desc + ".");
	}

	return 0;
}


// check if email and confirmation email match
function ck_vfy_email(email, vfy_email) {
	if (email != vfy_email) {
		return add_error(getXlation("REG_EMAIL_NOT_MATCH"));
	}
	return 0;
}


// check address
function ck_address(f) {

	var address = new Array(f.addr_street_1.value, f.addr_street_2.value,
							f.addr_street_3.value, f.addr_street_4.value);
	for(i = 0; i < 3; i++) {
		for(j = i + 1; address[i] == "" && j < 4; j++) {
			address[i] = address[j];
			address[j] = "";
		}
	}
	f.addr_street_1.value = address[0];
	f.addr_street_2.value = address[1];
	f.addr_street_3.value = address[2];
	f.addr_street_4.value = address[3];

	return ck_mandatory(address[0], getXlation("REG_ADDR"), 1, 160, false);
}


// check country code
function ck_country(f) {

	var sel = f.country_code.selectedIndex;
	var country_code = f.country_code.options[sel].value;

	f.addr_country.value = f.country_code.options[sel].text;
	return ck_mandatory(country_code, getXlation("REG_COUNTRY"), 1, 3);
}


// check postcode
function ck_postcode(f) {

	var desc = getXlation("REG_POSTCODE");
	var postcode = f.postcode.value;
	var err = ck_mandatory(postcode, desc, 1, 8, false);

	if(!err) {
		var re = "^[ A-Za-z0-9\.\_\-]*$";
		if(!postcode.match(new RegExp(re))) {
			return add_error(invalid_str + desc + ".");
		}
	}
	
	return err;
}


// check a phone number
function ck_numeric(str,desc) {
	if (str.length >0) {
		if (str.match(/[^0-9 ]/)) { 
			return add_error(invalid_str + desc + ".");
		}
	}
	return(0);
}


function go_hist(txn_type, j_op_ref_id, j_op_ref_key, sub_acct_id) {

	var f = document.forms['history'];
	f.txn_type.value = txn_type;

	insertInputObj(f, 'hidden', '', 'j_op_ref_id', j_op_ref_id);
	insertInputObj(f, 'hidden', '', 'j_op_ref_key', j_op_ref_key);
	insertInputObj(f, 'hidden', '', 'sub_acct_id', sub_acct_id);
	submit_ssl_form('history', 'DoHist', 'get');
}

//////////////////////////////////////////////
// JavaScript functions related to the news //
//////////////////////////////////////////////

function go_highlight_submit(action, class_id, type_id, ev_id, coupon_id, seln_id) {
	var f = document.forms['mainnews'];
	f.ev_class_id.value = class_id;
	f.ev_type_id.value = type_id;
	f.ev_id.value = ev_id;
	f.coupon_id.value = coupon_id;
	f.seln_id.value = seln_id;
	submit_form('mainnews',action);
}

function go_to_betslip(id) {
	var url = document.place;
	url += "?action=GoFastBet&evocid="+id;
	
	view_betslip(url);
}

function go_highlight(class_id, id, level) {
	if (level == "CLASS") {
		go_highlight_submit('GoEvClass', id, 0, 0, 0, 0);
	}
	else if (level == "TYPE") {
		go_highlight_submit('GoEvType', class_id, id, 0, 0, 0);
	}
	else if (level == "EVENT") {
		go_highlight_submit('GoEv', 0, 0, id, 0, 0);
	}
	else if (level == "COUPON") {
		go_highlight_submit('GoCoupon', class_id, 0, 0, id, 0);
	} 
	else if (level == "SELECTION") {
		go_to_betslip(id);
	//	go_highlight_submit('GoFastBet', 0, 0, 0, 0, id);
	}
}

/////////////////////////////////////////////////////
// JavaScript functions for running active content //
/////////////////////////////////////////////////////

function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

////////////////////////////////////////////////////
// JavaScript functions for jackpot and countdown //
////////////////////////////////////////////////////

//
// Introduce a CountDown Time on the web page just by specifying a basename and
// two fields in the HTML:
//
// <basename>_closedate where the close date is stored
// <basename>_countdown where the remaining time is displayed
//

function countdownTimer(basename) {
	_countdownTimer(basename, 0);
}

function _countdownTimer(basename, count) {
	if (!document.getElementById(basename + "_CURRENT_closedate")) return;
	if (!document.getElementById("db_time_reference")) return;

	// gets closing date
	var closeDate = document.getElementById(basename + "_CURRENT_closedate").value;
	if (closeDate.length == 0) return;

	// Get the time reference from the DB
	dbTime = new Date(document.getElementById("db_time_reference").value).getTime();

	var difference = new Date(closeDate).getTime() - dbTime - (count * 1000);

	if (difference < 0) {

		if (document.getElementById(basename + "_countdown"))
			document.getElementById(basename + "_countdown").innerHTML = "closed";
		setTimeout("window.location.href = window.location.href",1600);

	} else {

		// gets individual values
		daysLeft = Math.floor((difference / (60*60*24)) / 1000);
		hoursLeft = Math.floor((difference / (60*60)) / 1000 % 24);
		minsLeft = Math.floor((difference / (60)) / 1000 % 60);
		secsLeft = Math.floor(difference / 1000 % 60);
	
		// changes certain values so they contain 2 decimals
		if (secsLeft >= 0 && secsLeft < 10) secsLeft = 0 + secsLeft.toString();
		if (minsLeft >= 0 && minsLeft < 10) minsLeft = 0 + minsLeft.toString();
	
		// writes out current countdown
		updateCounterTime(basename,daysLeft,hoursLeft,minsLeft,secsLeft);

		count++;
		// repeats every 1 second, if countdown isn't over
		setTimeout("_countdownTimer('" + basename + "', " + count + ")",1000);
	}
}

/*
This function has been split out due to p10 and S6 requiring different displays
NOTE: This function will be overridden in prems6.js for the p06WM game
*/
function updateCounterTime(basename,daysLeft,hoursLeft,minsLeft,secsLeft) {

		if (document.getElementById(basename + "_countdown"))
		document.getElementById(basename + "_countdown").innerHTML = daysLeft + ":" + hoursLeft + ":" + minsLeft + ":" + secsLeft;
}

//
// Inserts on the page a Jackpot Count Up increasing the value of the jackpot
// You need four hidden fields and one display field to plug it.
//
function jackpotCountUp(basename)
{
	// init
	if (!document.getElementById(basename + '_closedate')) return;
	if (!document.getElementById(basename + '_startdate')) return;
	if (!document.getElementById(basename + '_startprice')) return;
	if (!document.getElementById(basename + '_endprice')) return;

	// gets hidden field values
	var closeDate = document.getElementById(basename + '_closedate').value;
	var startDate = document.getElementById(basename + '_startdate').value;
	var startPrice = parseInt(document.getElementById(basename + '_startprice').value);
	var endPrice = parseInt(document.getElementById(basename + '_endprice').value);

	if(closeDate == "NONE" || startDate == "NONE" || startPrice == "NONE" || endPrice == "NONE") return;

	// gets date time details
	var endDate = new Date(closeDate);
	var beginDate = new Date(startDate);
	var today = new Date();

	// difference between end and start and today and start
	var endAndStart = endDate.getTime() - beginDate.getTime();
	var endAndNow = today.getTime() - beginDate.getTime();

	// gets percentage to complete
	var difference = (endAndNow / endAndStart) * 100;

	// uses same percentage to work out position of money
	var money = ((endPrice - startPrice) / 100) * difference; 

	// adds on start price
	money = Math.floor(startPrice + money);

	var moneyPence = ".00"
	//if (money > 0) {
	//	moneyPence = "" + Math.random().toString().substring(1,4);
	//}

	// writes out to span
	if (document.getElementById(basename + '_pool'))
		document.getElementById(basename + '_pool').innerHTML = formatCurrency(money + moneyPence);

	// Write the jackpot
	var jackpot = (money * 0.75).toFixed(2);
	if (document.getElementById(basename + '_jackpot'))
		document.getElementById(basename + '_jackpot').innerHTML = formatCurrency(jackpot);

	// In case we have a price breakdown, keep on displaying 8, 9, 10
	//
	// Sportech said:
	//
	// - 10 correct is 75% of the pool value
	// - 9 correct is 0.5% of the pool value
	// - 8 correct is 0.1% of the pool value

	var _tmp_value = (money * 0.75).toFixed(2);
	if (document.getElementById(basename + '_correct_10'))
		document.getElementById(basename + '_correct_10').innerHTML = formatCurrency(_tmp_value);

	_tmp_value = (money * 0.005).toFixed(2);
	if (document.getElementById(basename + '_correct_9'))
		document.getElementById(basename + '_correct_9').innerHTML = formatCurrency(_tmp_value);

	_tmp_value = (money * 0.001).toFixed(2);
	if (document.getElementById(basename + '_correct_8'))
		document.getElementById(basename + '_correct_8').innerHTML = formatCurrency(_tmp_value);

    // repeats every 10 seconds
    setTimeout("jackpotCountUp('" + basename + "')",10000);
}


function insertFundAndJackpotSuper6Wrapper(elementName)
{
	insertFundAndJackpot('SLIP1_'+elementName);
	insertFundAndJackpot('SLIP2_'+elementName);
	insertFundAndJackpot('SLIP3_'+elementName);
}

//
// Inserts on the page an estimate of the Total Fund and / or Jackpot
// You need four hidden fields and one display field to plug it.
//
function insertFundAndJackpot(elementName)
{
	// init
	if (!document.getElementById(elementName + '_CURRENT_fund_estimate')) return;
	if (!document.getElementById(elementName + '_CURRENT_jackpot_estimate')) return;

	// gets hidden field values
	var fundEstimate    = parseInt(document.getElementById(elementName + '_CURRENT_fund_estimate').value);
	var jackpotEstimate = parseInt(document.getElementById(elementName + '_CURRENT_jackpot_estimate').value);

	if(fundEstimate == "NONE" || jackpotEstimate == "NONE") return;

	// Write out the fund
	if (document.getElementById(elementName + '_pool'))
		document.getElementById(elementName + '_pool').innerHTML = formatCurrency(fundEstimate,false);

	// Write out the jackpot
	if (document.getElementById(elementName + '_jackpot'))
		document.getElementById(elementName + '_jackpot').innerHTML = formatCurrency(jackpotEstimate,false);

	// In case we have a price breakdown, keep on displaying 8, 9, 10
	//
	// Sportech said:
	//
	// - 10 correct is 75% of the pool value
	// - 9 correct is 0.5% of the pool value
	// - 8 correct is 0.1% of the pool value

	//var _tmp_value = (money * 0.75).toFixed(2);
	//if (document.getElementById(elementName + '_correct_10'))
	//	document.getElementById(elementName + '_correct_10').innerHTML = formatCurrency(_tmp_value);

	//_tmp_value = (money * 0.005).toFixed(2);
	//if (document.getElementById(elementName + '_correct_9'))
	//	document.getElementById(elementName + '_correct_9').innerHTML = formatCurrency(_tmp_value);

	//_tmp_value = (money * 0.001).toFixed(2);
	//if (document.getElementById(elementName + '_correct_8'))
	//	document.getElementById(elementName + '_correct_8').innerHTML = formatCurrency(_tmp_value);
}

/*
 * Swap the display style of two divs so only one is visible.
 */
function showDiv (id1, id2) {
    var handle1 = document.getElementById(id1)
    var handle2 = document.getElementById(id2)

    if (handle1.style.display=='none') {
        var new_handle1 = 'block'
        var new_handle2 = 'none'
    } else {
        var new_handle1 = 'none'
        var new_handle2 = 'block'
    }
    handle1.style.display = new_handle1;
    handle2.style.display = new_handle2;
}

/*
 * Toggle a div's display style
 */
function toggleDiv (div_id) {
    var handle = document.getElementById(div_id)
	if (handle.style.display=='none') {
		handle.style.display = 'block';
	} else {
		handle.style.display = 'none';
	}
}
