
function Browser() {

var ua, s, i;

this.isIE = false;
this.isNS = false;
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;
}
}

var browser = new Browser();

// Global object to hold drag information.

var dragObj = new Object();
dragObj.zIndex = 0;

function dragStart(event, id) {

var el;
var x, y;

// If an element id was given, find it. Otherwise use the element being
// clicked on.

if (id)
dragObj.elNode = document.getElementById(id);
else {
if (browser.isIE)
dragObj.elNode = window.event.srcElement;
if (browser.isNS)
dragObj.elNode = event.target;

// If this is a text node, use its parent element.

if (dragObj.elNode.nodeType == 3)
dragObj.elNode = dragObj.elNode.parentNode;
}

// Get cursor position with respect to the page.

if (browser.isIE) {

x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
}
if (browser.isNS) {
x = event.clientX + window.scrollX;
y = event.clientY + window.scrollY;
}

// Save starting positions of cursor and element.

dragObj.cursorStartX = x;
dragObj.cursorStartY = y;
dragObj.elStartLeft = parseInt(dragObj.elNode.style.left, 10);
dragObj.elStartTop = parseInt(dragObj.elNode.style.top, 10);

if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 10;
if (isNaN(dragObj.elStartTop)) dragObj.elStartTop = 500;

// Update element's z-index.

dragObj.elNode.style.zIndex = ++dragObj.zIndex;

// Capture mousemove and mouseup events on the page.

if (browser.isIE) {
document.attachEvent("onmousemove", dragGo);
document.attachEvent("onmouseup", dragStop);
window.event.cancelBubble = true;
window.event.returnValue = false;
}
if (browser.isNS) {
document.addEventListener("mousemove", dragGo, true);
document.addEventListener("mouseup", dragStop, true);
event.preventDefault();
}
}

function dragGo(event) {

var x, y;

// Get cursor position with respect to the page.

if (browser.isIE) {
x = window.event.clientX + document.documentElement.scrollLeft
+ document.body.scrollLeft;
y = window.event.clientY + document.documentElement.scrollTop
+ document.body.scrollTop;
}
if (browser.isNS) {
x = event.clientX + window.scrollX;
y = event.clientY + window.scrollY;
}

// Move drag element by the same amount the cursor has moved.

dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
dragObj.elNode.style.top = (dragObj.elStartTop + y - dragObj.cursorStartY) + "px";

if (browser.isIE) {
window.event.cancelBubble = true;
window.event.returnValue = false;
}
if (browser.isNS)
event.preventDefault();
}

function dragStop(event) {

// Stop capturing mousemove and mouseup events.

if (browser.isIE) {
document.detachEvent("onmousemove", dragGo);
document.detachEvent("onmouseup", dragStop);
}
if (browser.isNS) {
document.removeEventListener("mousemove", dragGo, true);
document.removeEventListener("mouseup", dragStop, true);
}
}

//
//  THIS FILE IS SERVED FROM COMMONAPACHE SERVER.
//
try
{
	var cur_symbol="&#163;";
	if(cur == "978")
		cur_symbol="&#8364;";

	ChangeState("uname",username);
	ChangeState("the_usernameright",username);
	ChangeState("realbal",cur_symbol+bal);
	ChangeState("bonbal",cur_symbol+bonus);
	ChangeState("tollypoints",points);
	ChangeState("loyalty",loyalty);
	
	//Added for Common Header
    ChangeState("header_username",username);
	ChangeState("header_realbal",cur_symbol+bal);
	ChangeState("header_bonbal",cur_symbol+bonus);
	ChangeState("header_loyalty",loyalty);


}
catch(ignore)
{
	
}

function checkdeposit()
{
	if(levelId == 1)
	{
		location.href=built_url+"/bingo/registration/registration_step2.thtml";
	}
	else
	{
		location.href=built_url+"/deposit/depositView.do";
	}
}
function checkwithdraw()
{
	
	if(levelId == 1)
	{
		location.href=built_url+"/bingo/registration/registration_step2.thtml";
	}
	else if((levelId == 2)&&(bal < 10))
	{
		alert("Insufficient funds available");
	}
	else
	{
		location.href=built_url+"/withdraw/WithdrawView.do";
	}
	
}
function checkredeem()
{
	if(loyalty <= 0 )
	{
		alert("Insufficient loyalty points available");
	}
	else
	{
		location.href=built_url+"/bingo/account/redeem.thtml";
	}
}
function cardverify()
{
	if(bal>minChangeCardDepAmt)
	{
		location.href=built_url+"/bingo/account/card_accessdenied.thtml";
	}
	else
	{
		location.href=built_url+"/bingo/account/change_card.thtml";
	}

}
function allTransactions(transType)
{
	if(levelId == 1)
	{
		location.href=built_url+"/bingo/registration/registration_step2.thtml";
	}
	else
	{

		document.getElementById(transType).href=built_url+"/deposit/common_transactions.html?type="+transType;
		NewWindow(document.getElementById(transType).href,'mywin','600','550','yes','center');
		return false;
	}
}

function checkredeemBonus()
{
	location.href=built_url+"/bingo/account/redeembonus.thtml";
}
function checklink()
{
	if(levelId == 1)
	{
		location.href=built_url+"/bingo/registration/registration_step2.thtml";
	}
	else
	{
		location.href=built_url+"/deposit/depositView.do";
	}
}

function limitWithdraw()
{
	
	if(levelId == 1)
	{
		location.href=built_url+"/bingo/registration/registration_step2.thtml";
	}
	else
	{
		location.href=built_url+"/withdraw/WithdrawView.do";
	}
}
function createRequestObject() {
    var httprReqobj;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
	try{
			httprReqobj = new ActiveXObject("Microsoft.XMLHTTP");        
	}catch(recreate){
	        httprReqobj = new XMLHttpRequest();		
	}
    }else{
        httprReqobj = new XMLHttpRequest();
    }
    return httprReqobj;
}


var balhttp_request = createRequestObject();
function getBalance() {
	balhttp_request.open("POST",context+"/account/balance_retriver.jsp",true);
	balhttp_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	balhttp_request.setRequestHeader("Content-length", 0);
	balhttp_request.setRequestHeader("Connection", "close");
	balhttp_request.send(null);
	balhttp_request.onreadystatechange = handleBalResponse;
}
function handleBalResponse() {
	if(balhttp_request.readyState == 4){
		var balResponse = balhttp_request.responseText;
		if(balhttp_request.status == 200){
			var account_res = balResponse.split('&');
			formatted_bal = account_res[0].split("=")[1];
			formatted_bonus = account_res[1].split("=")[1];
			try
			{
				ChangeState("realbal",formatted_bal);
				ChangeState("bonbal",formatted_bonus);	
				ChangeState("header_realbal",formatted_bal);
				
			}
			catch (e)
			{
			}
			
		   
		}
	}
}
setInterval("getBalance()", 60000);

function openLiveHelp(){
	if(levelId == 2){
		if (browser.isIE){
			window.open('http://livechat.stenodoc.com/cgi-local/start.cgi/apps/livehelp/index.html?uid='+username+'&gids=Bingo&label=FD%20UK','LHC_'+Math.floor(Math.random()*100000),'left=10,top=10,resizable,height=355,width=400');
		}
		else{
			document.getElementById('boxToDrag').style.display='block';
			document.getElementById('iframeLive').src='http://livechat.stenodoc.com/cgi-local/start.cgi/apps/livehelp/index.html?uid='+username+'&gids=Bingo&label=FD%20UK';
		}
	}else if(levelId == 1){
		if (browser.isIE){
			window.open('http://livechat.stenodoc.com/cgi-local/start.cgi/apps/livehelp/index.html?uid='+username+'&gids=Bingo&label=Reg%20UK','LHC_'+Math.floor(Math.random()*100000),'left=10,top=10,resizable,height=355,width=400');		
			
		}
		else{
			document.getElementById('boxToDrag').style.display='block';
			document.getElementById('iframeLive').src='http://livechat.stenodoc.com/cgi-local/start.cgi/apps/livehelp/index.html?uid='+username+'&gids=Bingo&label=Reg%20UK';
		}
	}
	return false;
}
function closeWindow(){
	document.getElementById('boxToDrag').style.display='none';
	document.getElementById('iframeLive').src='';
	return false;
}

