var betSlipLoaded = false ;
var browser = new Browser();
var last_displayed_slip = '';
var last_displayed_bettype = '';

function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

function activateTracking() {
	if (browser.isIE)
	  document.onmousemove = pageMousedown;
	else
	  document.addEventListener("mousemove", pageMousedown, true);
}

function pageMousedown(evt)
{
	var el;
	    
	if (browser.isIE)
		el = window.event.srcElement;
	else {
		el = (evt.target.tagName ? evt.target : evt.target.parentNode);
	}
	hideInfos();

	if ((el.id.substring(0,4) == "BET_")||(el.id.substring(0,4) == "GAI_")||(el.id.substring(0,4) == "REF_"))
	{
		if (browser.isIE)
		{
			if (document.documentElement && document.documentElement.scrollTop) {
				tempY = event.clientY + document.documentElement.scrollTop ;
				tempX = event.clientX ;
			} else if (document.body) {
				tempY = event.clientY + document.body.scrollTop ;
				tempX = event.clientX ;
			}
		}
		else
		{
			tempX = evt.pageX;
			tempY = evt.pageY;
		}
		if (tempX < 0){tempX = 0;}
		if (tempY < 0){tempY = 0;}  
		display_slip(el.id.substring(4),tempX, tempY);
	}

	if ((el.id.substring(0,3) == "BH_"))
	{
		if (browser.isIE)
		{
			if (document.documentElement && document.documentElement.scrollTop) {
				tempY = event.clientY + document.documentElement.scrollTop ;
				tempX = event.clientX ;
			} else if (document.body) {
				tempY = event.clientY + document.body.scrollTop ;
				tempX = event.clientX ;
			}
		}
		else
		{
			tempX = evt.pageX;
			tempY = evt.pageY;
		}
		if (tempX < 0){tempX = 0;}
		if (tempY < 0){tempY = 0;}  
		display_help(el.id.substring(3),tempX, tempY);
	}	
	return true;
}
	
function addDetail(id)
{
	if(this.betSlipLoaded) {
		try {
	    	f = frames['slipframe'].document.forms['UPDATESLIP'];

			f.SLIPACTION.value = 'ADD';
			f.RESULTID.value = id;
			f.submit();
		}
		catch (oException) {
			frames['slipframe'].location='/slip.php?SLIPACTION=ADD&RESULTID=' + id;
		}
		this.betSlipLoaded = false ;
	} else {
		document.location.href = '/account/first_connexion.php';
	}
}

function resizeIFrame(iframeWindow) 
{ 	
	
	if (iframeWindow.document.height) // Firefox
	{
		var iframeElement = document.getElementById(iframeWindow.name);
		iframeElement.style.height = iframeWindow.document.height + 'px';
	}
	else if (document.all) // MSIE
	{
		var iframeElement = document.all[iframeWindow.name];
		
		if (iframeWindow.document.compatMode && iframeWindow.document.compatMode != 'BackCompat') // Backward compatibility
		{
			iframeElement.style.height = iframeWindow.document.documentElement.scrollHeight + 'px';
			
		}
		else // CSS1 compliant
		{
			if (String(iframeElement) != "undefined")
			{				
				iframeElement.style.height = iframeWindow.document.body.scrollHeight + 'px';
			}
		}
	}
}

function resizeIFrameBS(iframeWindow)
{
	resizeIFrame(iframeWindow);
	this.betSlipLoaded = true;
}

function switch_display(table_id)
{
	var tbl = window.document.getElementById('tbl'+table_id);
	var img = window.document.getElementById('img'+table_id);
	if (tbl.className=='visible')
	{
		tbl.className='invisible';
		img.src='/img/ico_more.gif';
	}
	else
	{
		tbl.className='visible';
		img.src='/img/ico_less.gif';
	}		
	return false ;
}


function display_slip(tracking_code,X,Y) {
	var xhr_object = null;   
   
	if( tracking_code != last_displayed_slip ){
		if(window.XMLHttpRequest) // Firefox
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject) // Internet Explorer
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else { // XMLHttpRequest non supporté par le navigateur
			return;
		}
		url = "/account/get_slip.php?TC=" + tracking_code ;
		xhr_object.open("GET", url, false);   
		xhr_object.send(null);   
	
		cadre = document.getElementById("hiddendiv");
		cadre.innerHTML = xhr_object.responseText ;
		last_displayed_slip = tracking_code ;
	}
	showInfos(X,Y);
	
}

function display_help(bettype,X,Y) {
	var xhr_object = null;   
   
	if( bettype != last_displayed_bettype ){
		if(window.XMLHttpRequest) // Firefox
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject) // Internet Explorer
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else { // XMLHttpRequest non supporté par le navigateur
			return;
		}
		
		url = "/help/help.php?" + bettype ;
		xhr_object.open("GET", url, false);   
		xhr_object.send(null);   
	
		cadre = document.getElementById("hiddendiv");
		cadre.innerHTML = xhr_object.responseText ;
		last_displayed_bettype = bettype ;
	}
	showInfos(X,Y);
}

function refresh_user_info() {
	
	var xhr_object = null;   
   
	if(window.XMLHttpRequest) // Firefox
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // Internet Explorer
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else { // XMLHttpRequest non supporté par le navigateur
		return;
	}
	
	xhr_object.open("GET", "/account/get_user_info.php", false);   
	xhr_object.send(null);   
	
	cadre = document.getElementById("account");
	cadre.innerHTML = xhr_object.responseText ;	
}

function showInfos(tempX, tempY)
{
	var cadre;
	cadre = document.getElementById("hiddendiv");
	
	if (cadre != null)
	{
		if (browser.isIE)
		{
			hauteur = document.body.clientHeight;
			largeur = document.body.clientWidth;	
		}
		else
		{
			hauteur = window.innerHeight;
			largeur = window.innerWidth;
		}
		posX = tempX - cadre.offsetWidth - 10  ;
		posY = tempY - (cadre.offsetHeight/2) ;

		
		if(posX<0) posX = tempX + 10  ;
		if(posY<0) posY = tempY + 10  ;
		
		cadre.style.left = posX +"px";
		cadre.style.top = posY +"px";
		cadre.style.visibility = "visible";
	}

};

function hideInfos()
{
	cadre = document.getElementById("hiddendiv");

	if (cadre != null)
	{
		cadre.style.visibility = "hidden";
	}
};

function disableButton(which) {
	
	var button = $(which);
	if (button) {
		button.style.visibility = "hidden" ; 
	} 
};

function compute_dollar_amount(rate) {
	
	fld = document.getElementById("user_currency_amount");
	dblUserCurrencyAmount = fld.value;
	dblDollarAmount = dblUserCurrencyAmount * rate;
	
	txtDollarAmount=formatNumber(dblDollarAmount,2,'US');
	document.getElementById("dollar_amount").innerHTML = txtDollarAmount ;
	
}

function formatNumber(total, decimals, language)
 {
	switch (language)
	{
		case 'FR':
		{
		decimal_sep = ',';	
		thousand_sep = '&nbsp;';
		break
		}	
		case 'DE':
		{
		decimal_sep = ',';	
		thousand_sep = '.';
		break
		}	
		default:
		{
		decimal_sep = '.';	
		thousand_sep = ',';
		break
		}	
	}
 	
	var num = parseFloat(total);
	if (!(num = parseFloat(num)))
		num = "0.00";
		
	var Pad = "";
	num = "" + Math.floor(num * Math.pow(10,decimals + 1) + 5);
	if(num.length < decimals+1)
		{
		for(Count = num.length; Count <= decimals; Count++)
		Pad += "0";
		}
	num = Pad + num;
	
	num = num.substring(0,num.length - decimals - 1) + decimal_sep + num.substring(num.length - decimals -1, num.length -1);
	if((num == "") || (num.substring(0,1) == decimal_sep))
		num = "0" + num;

	
	num2=num.substring(num.length-decimals-1, num.length);
	j=1;
	for (i = num.length-decimals-2; i>=1; i--) {
		num2 = num.substring(i,i+1) + num2;
		if (j==3) {
			num2 = thousand_sep + num2;
			j=0;
		}
		j++;
	}
	num2 = num.substring(0,1) + num2;
	return num2;
}

function launchPoker(url) {
	oNewWindow = window.open(url + '/poker/launch_poker.php','WinamaxPoker','width=988, height=600, status=no, directories=no, toolbar=no, location=no, menubar=no, scrollbars=no, resizable=no') ;
}

function launchCustomPoker(url) {
	oNewWindow = window.open(url,'WinamaxPoker','width=988, height=564, status=no, directories=no, toolbar=no, location=no, menubar=no, scrollbars=no, resizable=no') ;
}

function popup() {
	window.open('http://www.adictel.com/banniere/adictel.html','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=213,height=420,left=100,top=100');
}

function launch_and_next(launch_url,next_url) {
	oNewWindow = window.open(launch_url,'Download','width=10, height=10, status=no, directories=no, toolbar=no, location=no, menubar=no, scrollbars=no, resizable=no') ;
	window.location.href = next_url;
}

