
function BrowserDetect() {
   var ua = navigator.userAgent.toLowerCase();

   // browser engine name
   this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

   // browser name
   this.isKonqueror   = (ua.indexOf('konqueror') != -1);
   this.isSafari      = (ua.indexOf('safari') != - 1);
   this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
   this.isOpera       = (ua.indexOf('opera') != -1);
   this.isIcab        = (ua.indexOf('icab') != -1);
   this.isAol         = (ua.indexOf('aol') != -1);
   this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) );
   this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isFirefox     = (ua.indexOf('firefox') != -1);
   this.isFirebird    = (ua.indexOf('firebird/') != -1);
   this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );

   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);

   // rendering engine versions
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
   this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
   this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );

   // browser version
   this.versionMinor = parseFloat(navigator.appVersion);

   // correct version number
   if (this.isGecko && !this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
   }
   else if (this.isOmniweb) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
   }
   else if (this.isOpera) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
   }
   else if (this.isIcab) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
   }

   this.versionMajor = parseInt(this.versionMinor);

   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);

   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin    = (ua.indexOf('win') != -1);
   this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac    = (ua.indexOf('mac') != -1);
   this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux  = (ua.indexOf('linux') != -1);

   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   this.isFirefox = (ua.indexOf('firefox') != -1);

   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);

   this.isIE4xMac = (this.isIE4x && this.isMac);
}
var browser = new BrowserDetect();

function MM_reloadPage(init) {
	if (init==true) with (navigator) {if ((navigator.appName=="Netscape")&&(parseInt(navigator.appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

// used to load link in parent window (or else pop another one up)
function parentRefresh(url) {
	if (top==self) {
		window.location = url;
	} else {
		if (!(top.window.opener) || top.window.opener.closed==true) {
			var parent = window.open(url,'BlueSquare_POPUP','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
			opener = parent;
		} else {
			top.window.opener.location = url;
			top.window.opener.focus();
		}
	}
}

function printPage() {
	window.print()
}

function printFramePage() {
	if (is_nav45up ||  is_ns6) {
		parent.content.print();
	} else if(is_ie5up) {
		parent.content.focus();
		parent.content.print();
	}
}

function submitForm() {
	if (is_nav45up) {
		document.floatLayer.document.fm_login.submit();
	} else {
		document.fm_login.submit();
	}
	return false;
}

function switchForm(pin_or_passwd) {
	var fm;
	if (is_nav45up) {
		fm = document.floatLayer.document.fm_login;
	} else {
		fm = document.fm_login;
	}
	if ( pin_or_passwd == "pin" ) {
		fm.tbUsername.value = "";
		fm.tbPassword.value = "";
	} else {
		fm.tbAccNo.value = "";
		fm.tbPin.value = "";
	}
	fm.FormName.value = "";
	fm.LoginSwitch.value = pin_or_passwd;
	fm.method = "get";
	fm.submit();
}

function highlight(what,color) {
	what.style.background=color
}

function highlight_light_blue_on(e) {
	if (document.all) {
		cell=event.srcElement;
	} else if (document.getElementById) {
		cell=e.target;
	}
	if (cell.className=="Box") {
		highlight(cell,"#deefff");
	} else {
		while(cell.tagName!="TABLE") {
			cell=document.getElementById? cell.parentNode : cell.parentElement;
			if (cell.className=="Box") {
				highlight(cell,"#deefff");
			}
		}
	}
}

function highlight_light_blue_off(e) {
	if (document.all) {
		cell=event.srcElement;
	} else if (document.getElementById) {
		cell=e.target;
	}
	if (cell.className=="Box") {
		highlight(cell,"#ffffff");
	} else {
		while(cell.tagName!="TABLE") {
			cell=document.getElementById? cell.parentNode : cell.parentElement;
			if (cell.className=="Box") {
				highlight(cell,"#ffffff");
			}
		}
	}
}

function toggleBox(id) {
	var box = document.getElementById("sub_"+id);
	var img = document.getElementById("img_"+id);
	if (box && box.className) {
		if (box.className == "submenu_hidden") {
			box.className = "submenu_visible";
			img.src="/bluesquare/sportsbook/interface/images/bullet_yellow_menu_hide.gif";
		} else {
			box.className = "submenu_hidden";
			img.src="/bluesquare/sportsbook/interface/images/bullet_yellow_menu_expand.gif";
		}
	}
}

function set_sbook_menu_style_class(id) {
	var sbook_menu = document.getElementById(id);
	if (sbook_menu && sbook_menu.className) {
		sbook_menu.className = "LocalMenuSelected";
	}
}

function set_left_nav_menu_style_class(id) {
	var selected_menu = document.getElementById(id);
	if (selected_menu && selected_menu.className) {
		selected_menu.className = "menu_item_picked";
	}
}

function setBalance(bal) {
	var bal_box = document.getElementById('user_balance');
	if (bal_box) {
		bal_box.innerHTML = bal;
	}
}

var WhichImage;
var WhichSource;

var SportsBookOff = new Image();
var SportsBookOver = new Image();
var GamesOff = new Image();
var GamesOver = new Image();
var PokerOff = new Image();
var PokerOver = new Image();
var CasinoOff = new Image();
var CasinoOver = new Image();
var MobileOff = new Image();
var MobileOver = new Image();
var PromotionsOff = new Image();
var PromotionsOver = new Image();
var SkillOver = new Image();
var SkillOff  = new Image();

function preloadBsqToolBarRollovers () {

	if (document.images) {
		SportsBookOff.src = "/bluesquare/global/images/global_sportsbook_off.gif";
		SportsBookOver.src = "/bluesquare/global/images/global_sportsbook_over.gif";
		GamesOff.src = "/bluesquare/global/images/global_games_off.gif";
		GamesOver.src = "/bluesquare/global/images/global_games_over.gif";
		PokerOff.src = "/bluesquare/global/images/global_poker_off.gif";
		PokerOver.src = "/bluesquare/global/images/global_poker_over.gif";
		CasinoOff.src = "/bluesquare/global/images/global_casino_off.gif";
		CasinoOver.src = "/bluesquare/global/images/global_casino_over.gif";
		MobileOff.src = "/bluesquare/global/images/global_mobile_off.gif";
		MobileOver.src = "/bluesquare/global/images/global_mobile_over.gif";
		PromotionsOff.src = "/bluesquare/global/images/global_promotions_off.gif";
		PromotionsOver.src = "/bluesquare/global/images/global_promotions_over.gif";
		SkillOver.src = "/bluesquare/global/images/global_skill_over.gif";
		SkillOff.src = "/bluesquare/global/images/global_skill_off.gif";
	}

}

function GoOver(WhichImage, WhichSource) {
	if (document.images) {
		eval("document.images."+WhichImage+".src = "+WhichSource+".src;");
	}
}

function GoOff(WhichImage, WhichSource) {
	if (document.images) {
		eval("document.images."+WhichImage+".src = "+WhichSource+".src;");
	}
}

var strWin;
var strURL;
var strWinName;
var strScrollBar;
var iWinWidth;
var iWinHeight;
var strToolbar;
var strMenuBar;

function windowOpen(strURL, strWinName, strOptions) {

	var win = window.open(strURL, strWinName, strOptions);
	if (win) {
		try {
			win.focus();
		} catch (e) {
		}
	}

	return win;
}

function windowPopUp(strURL,strWinName,iWinWidth,iWinHeight,strScrollBar,strResize,strToolbar,strMenuBar)
{
	if (strScrollBar == "yes") {
		if (is.ie == true || is.ns == true) { iWinWidth = iWinWidth + 16; }
	}
	if (strWin!=null) {   		/*not first time we've opened the window?*/
		if(!strWin.closed) {	/*window is open now?*/
			strWin.focus();		/*focus on it*/
			strWin.focus();		/*focus on it again, sometimes the browser does not focus properly with one call only*/
								/*load the content again*/
			strWin = windowOpen(strURL,strWinName, "toolbar="+strToolbar+",scrollbars="+strScrollBar+",location=0,directories=0,status=1,resizable=1,width="+iWinWidth+",height="+iWinHeight+",menubar="+strMenuBar);
			return;
		}
	}
	strWin = windowOpen(strURL,strWinName, "toolbar="+strToolbar+",scrollbars="+strScrollBar+",location=0,directories=0,status=1,resizable=1,width="+iWinWidth+",height="+iWinHeight+",menubar="+strMenuBar);	/* open the window */
}

function betslipPopUp(strURL) {
	windowPopUp(strURL, "BSQ_betslip_popup", 455, 555, 1, 1, 0, 0);
}

function GoLogout(url) {
	var isXPSP2 = (window.navigator.userAgent.indexOf("SV1") != -1);

	if (!isXPSP2) {
		windowClose("BSQ_betslip_popup");
		windowClose("accountPopUp");
		windowClose("game_win");
		windowClose("tv_streaming");
		windowClose("ext_game_win");
		windowClose("birAppPopUp");
	}

	self.location = url;
}

function windowClose(strWinName) {
	var win = window.open('', strWinName);

	if (win) {
		win.close();
	}
}

// Hide a content div
//
//    id      - Unique id of the div
//    content - Name of the div
//    button  - Name of the Show/Hide button
//    _scroll - Scroll the window to the div
//
function hideDiv (id, content, button, _scroll) {
	setDisplay(content + id, "none");
	setDisplay(button + 'hide_' + id, "none");
	setDisplay(button + 'show_' + id, "block");

	if (_scroll) {
		_scrollToDiv (document.getElementById(content + id));
	}
}

// Show a content div
//
//    id      - Unique id of the div
//    content - Name of the div
//    button  - Name of the Show/Hide button
//    _scroll - Scroll the window to the div
//
function showDiv (id, content, button, _scroll) {
	setDisplay(content + id, "block");
	setDisplay(button + 'hide_' + id, "block");
	setDisplay(button + 'show_' + id, "none");

	if (_scroll) {
		_scrollToDiv (document.getElementById(content + id));
	}
}

// Toggle a div
//
//    id      - Unique id of the div
//    content - Name of the div
//    button  - Name of the Show/Hide button
//    _scroll - Scroll the window to the div
//
function toggleDiv (id, content, button, _scroll) {
	var disp = getDisplay(content + id);

	if (disp == "block") {
		hideDiv(id, content, button, _scroll);
	} else if (disp == "none") {
		showDiv(id, content, button, _scroll);
	}
}

// Get the display of an object
//
function getDisplay (id) {
	var div = document.getElementById(id);

	if (div && div.style) {
		return div.style.display;
	}

	return false;
}
// Actually set the display of the div
//
//    div     - The div object
//    display - The new display value
//
function setDisplay (id, display) {
	var div = document.getElementById(id);

	if (div && div.style) {
		div.style.display = display;
	}
}

// Actually set the display of the div
//
//    div     - The div object
//    display - The new display value
//
function setVisibility (id, vis) {
	var div = document.getElementById(id);

	if (div && div.style) {
		div.style.visibility = vis;
	}
}

// Scroll to a particular div vertically
//
function _scrollToDiv (div) {
	var top = _getTop(div) - 30;

	window.scrollTo(0, top);
}

function _getTop (obj) {

	var top = 0;

	if (obj.offsetParent) {
		while (obj.offsetParent) {
			top += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y) {
		top += obj.y;
	}

	return top;
}

// Clear all radio buttons in a form
//
//    id      - Unique id of the div
//    content - Name of the div
//    button  - Name of the Show/Hide button
//
function clearRadio (form) {

	var frm = document.forms[form];
	var len = frm.elements.length;

	for (i = 0;i < len;i++) {
		if (frm.elements[i].type == 'radio') {
			frm.elements[i].checked = false;
		}
	}
}

// Clear all check boxes in a form
//
//    id      - Unique id of the div
//    content - Name of the div
//    button  - Name of the Show/Hide button
//
function clearCheck (form) {

	var frm = document.forms[form];
	var len = frm.elements.length;

	for (i = 0;i < len;i++) {
		if (frm.elements[i].type == 'checkbox') {
			frm.elements[i].checked = false;
		}
	}
}

// Clear the text of an input field
//
//    field - the field object
//
function clearInput (field) {
	if (field) {
		field.value = "";
	}
}

// Fill the text of an input field with value
//
//    field - the field object
//    value - the text to enter
//
function fillInput (field, value) {
	if (field && field.value == "") {
		field.value = value;
	}
}

// Post a form to the betslip popup window. This first
// opens the betslip window, then submits the form. The form
// must have a target set to BSQ_betslip_popup
//
function postBetslip (form) {
	betslipPopUp('');

	document.forms[form].submit();
}




function getCookie(name) {
	var dcookie = document.cookie;
	var cname = name + "=";
	var clen = dcookie.length;
	var cbegin = 0;

	while (cbegin < clen) {
		var vbegin = cbegin + cname.length;

		if (dcookie.substring(cbegin, vbegin) == cname) {
			var vend = dcookie.indexOf (";", vbegin);
			if (vend == -1) vend = clen;
				return unescape(dcookie.substring(vbegin, vend));
		}
		cbegin = dcookie.indexOf(" ", cbegin) + 1;
		if (cbegin == 0) break;
	}
	return null;
}


function getDayName(theDate)
{
	var nameOfDay;
	var currentDay = theDate.getDay();
	if      (currentDay == 0) nameOfDay = "Sunday"
	else if (currentDay == 1) nameOfDay = "Monday"
	else if (currentDay == 2) nameOfDay = "Tuesday"
	else if (currentDay == 3) nameOfDay = "Wednesday"
	else if (currentDay == 4) nameOfDay = "Thursday"
	else if (currentDay == 5) nameOfDay = "Friday"
	else nameOfDay = "Saturday";
	return nameOfDay;
}

function getMonthName(theDate)
{
	var nameOfMonth;
	var currentMonth = theDate.getMonth();

	if      (currentMonth == 0) nameOfMonth = "January"
	else if (currentMonth == 1) nameOfMonth = "February"
	else if (currentMonth == 2) nameOfMonth = "March"
	else if (currentMonth == 3) nameOfMonth = "April"
	else if (currentMonth == 4) nameOfMonth = "May"
	else if (currentMonth == 5) nameOfMonth = "June"
	else if (currentMonth == 6) nameOfMonth = "July"
	else if (currentMonth == 7) nameOfMonth = "August"
	else if (currentMonth == 8) nameOfMonth = "September"
	else if (currentMonth == 9) nameOfMonth = "October"
	else if (currentMonth == 10) nameOfMonth = "November"
	else nameOfMonth = "December";

	return nameOfMonth;
}

function getDate()
{	var myDateObject = new Date;

	var thisDay = getDayName(myDateObject);
	var thisMonth = getMonthName(myDateObject);
	var thisYear = myDateObject.getFullYear();
	var thisDate = myDateObject.getDate();
	var fullDate = thisDay + ", " + thisDate + " " + thisMonth + " " + thisYear;

	return fullDate;
}

function open_form_guide (url) {
	var formWindow = window.open(url,'sportinglife',config='toolbar=yes,menubar=yes,resizable=yes,location=no,directories=yes,scrollbars=yes');
	formWindow.focus();
}

function write_options_with_selected_value () {
	var a = write_options_with_selected_value.arguments;
	var str = "";

	if (a.length < 1) {
		return str;
	}

	var sel_val = a[0];

	for (i = 1; i < a.length; i += 2) {
		str += '<option ';
		if (a[i] == sel_val) {
			str += 'selected ';
		}
		str += 'value="' + a[i] + '">' + a[i+1] + '</option>\n';
	}
	return str;
}

// Sanity check of login params
function check_login_params (username, password, xl_username, xl_password) {

	// Username between 1 and 32 characters
	if (username.length < 1 || username.length > 32)
		return 'OB_ERR_VAL_BAD_UNAME_FORMAT';

	if (xl_username) {
		if (username == xl_username) {
			return 'OB_ERR_VAL_BAD_UNAME_FORMAT';
		}
	}

	// Password >= than 6 chars
	if (password.length < 4)
		return 'OB_ERR_VAL_BAD_PWD_FORMAT';

	if (xl_password) {
		if (password == xl_password) {
			return 'OB_ERR_VAL_BAD_PWD_FORMAT';
		}
	}

	return '';
}



// Code for displaying popups for world cup popup, wimbledon and
// popup validation
//
function ShowBox(id) {
	var version=0;
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		temp=navigator.appVersion.split("MSIE");
		version=parseFloat(temp[1]);
	}

	if((navigator.appVersion.indexOf("Win") != -1) && (version>=5.5)){
		ShowBoxIE(id);
	}
	else {
		ShowBoxElse(id);
	}
}

function ShowBoxIE(id) {
	document.getElementById(id).filters[0].enabled = true;
	document.getElementById(id).filters[0].Apply();
	document.getElementById(id).style.visibility="visible";
	document.getElementById(id).filters[0].Play();
}

function ShowBoxElse(id) {
	document.getElementById(id).style.visibility="visible";
}

/**
 * Hack for Promo div as we need to skip the ShowBoxIE proc for this one
 */
function ShowPromoPopUPBox(id) {
	ShowBoxElse(id);
}

function CloseBox(id) {
	document.getElementById(id).style.visibility="hidden";
}


// Array to store all of the radio button values. Indexed by the
// name of the radio button.
var radioValues = new Array();

// Allow a set of radio buttons to be unselected if the user clicks
// the radio button twice. Used on the football coupon.
function clickRadio(obj) {

	if (obj) {
		var num = obj.name;
		var val = radioValues[num];

		if (val && val == obj.value) {
			obj.checked = false;
			radioValues[num] = "";
		} else {
			radioValues[num] = obj.value;
		}
	}

	return true;
}

/**
 * BIR stuff
*/
var birWinName="birAppPopUp";
var bir_win;

// Bir pop-up window
function BirWindowPopUp(strURL,iWinWidth,iWinHeight,strScrollBar,strResize) {

        bir_win = window.open(strURL,birWinName, "toolbar=0,scrollbars="+strScrollBar+",location=0,directories=0,status=1,resizable="+strResize+",width="+iWinWidth+",height="+iWinHeight);
}

function setFlashWidth(divid, newW){
	document.getElementById(divid).style.width = newW+"px";
}
function setFlashHeight(divid, newH){
	document.getElementById(divid).style.height = newH+"px";
        spacer = document.getElementById(divid+"_spacer");
        if (spacer != null) {
                if (newH == 0) {
                        spacer.height = 0;
                }
                else {
                        spacer.height = 12;
                }
        }
}

function setFlashSize(divid, newW, newH){
    setFlashWidth(divid, newW);
    setFlashHeight(divid, newH);
} 


