
function ScrollProgressiveCounters(prId){

	//var objstr = "document.forms['jpform"+prId+"'].elements['progressive"+prId+"']";
	// var objstr = "document.all('progressive"+prId+"')";
 	var tickerId = 'progressiveTicker'+prId;
 	var objstr = "document.getElementById(tickerId)";

	var obj = eval(objstr);

	if (obj) {

		JP[prId] += (Inc[prId]);	

		obj.innerHTML = num2dollar(JP[prId]/100);

	}

	window.setTimeout( "ScrollProgressiveCounters("+prId+")",1000); 

}

function bookmarkMe(docTitle){
	if (document.all) {
		window.external.AddFavorite(location.href, docTitle);
	}
	else if (window.sidebar) {
		window.sidebar.addPanel(docTitle, location.href, "")
	}
}

function printTickerAmount(tickerID,currency){
	
	
	
	xmlHttp=getXmlHttpObject();
	tickerURL = "/resources/feeds/progressiveXML.php?jp="+tickerID+"&ts="+getTimestamp();
	
	if (xmlHttp==null) {
		//alert("Your browser does not support AJAX!");
		return false;
	}
	var This = this;
	
	this.currencySymbol = "&pound;";
	if(currency == "GBP"){
		this.currencySymbol = "&pound;";
	} else if(currency == "EUR") {
		this.currencySymbol = "&euro;";
	} else if(currency == "USD"){
		this.currencySymbol = "$";
	}
	
	
	xmlHttp.open("GET",tickerURL,true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			var xmlDoc = xmlHttp.responseXML;
			var tickerID = xmlDoc.getElementsByTagName("jackpotID")[0].firstChild.nodeValue;
			var tickerAmount = xmlDoc.getElementsByTagName("jackpotCValue")[0].firstChild.nodeValue;
			var tickerIncrement = xmlDoc.getElementsByTagName("value_dif")[0].firstChild.nodeValue;
			var tickerInterval = xmlDoc.getElementsByTagName("changeTime")[0].firstChild.nodeValue;
			var tickerPounds = (parseInt(tickerAmount)/100).toFixed(2);
			var formattedAmount = addCommas(tickerPounds.toString());
			var destination = document.getElementById("ticker"+tickerID);
			destination.innerHTML = This.currencySymbol + formattedAmount;
			setInterval("advanceTicker('"+tickerID+"','"+tickerIncrement+"','"+This.currencySymbol+"')",parseInt(tickerInterval)*1000);
		}
	}
	xmlHttp.send(null);

}

function advanceTicker(tickerID,tickerIncrement,currencySymbol){
	var destination = document.getElementById("ticker"+tickerID);
	var oldAmount = destination.firstChild.nodeValue;
	var oldAmountPence = oldAmount.replace(/\./g,"");
	oldAmountPence = oldAmountPence.replace(/\,/g,"");
	oldAmountPence = oldAmountPence.slice(1);
	var newAmountPence = parseInt(oldAmountPence) + parseInt(tickerIncrement);
	var newAmountFormatted = addCommas((newAmountPence/100).toFixed(2));
	destination.innerHTML = currencySymbol+newAmountFormatted;
}

function getXmlHttpObject() {
	
	var xmlHttp=null;
	try {
  		// Firefox, Opera 8.0+, Safari
  		xmlHttp=new XMLHttpRequest();
  	} catch (e) {
	 	// Internet Explorer
	  	try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	return xmlHttp;
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}


function getTimestamp() {
	var timestamp = new Date();
	return timestamp.getDate()+"-"+timestamp.getMonth()+"-"+timestamp.getFullYear()+"-"+timestamp.getHours()+"-"+timestamp.getMinutes()+"-"+timestamp.getSeconds()+"-"+timestamp.getMilliseconds(); 	
}
