 function getTimestamp(len) {

	// formats the time into YYYYMMDDHHMiSS
	// option param to specifiy how many chars to return - so that you can limit it to hours mins etc
	// len = 11 would return to the 10th min
	
	timeStamp = new Date();
	tsYear = timeStamp.getYear();
	if (tsYear < 2000) tsYear = 1900 + tsYear;
	
	tsMonth = timeStamp.getMonth() + 1 + "";
	if (tsMonth.length == 1) tsMonth = "0" + tsMonth;

	
	tsDay = timeStamp.getDate() + "";
	if (tsDay.length == 1) tsDay = "0" + tsDay;
	
	tsHours = timeStamp.getHours() + "";
	if (tsHours.length == 1) tsHours = "0" + tsHours;
	
	tsMins = timeStamp.getMinutes() + "";
	if (tsMins.length == 1) tsMins = "0" + tsMins;
	
	tsVar = tsYear + tsMonth + tsDay + tsHours + tsMins;
	
	if (len) {		
		return (tsVar.substr(0,len));	
	} else {
		return tsVar;
	}
	 
}


function renderLdb(response, total, fullPath, spanName) {					
	
	// check that we have some scores	

	// build up the data into some HTML then pop into the div...
	
	var ldbHTML = '';
	ldbHTML += '<h2 class="ms-header-s3 adlogo">Leaderboard</h2>';
	ldbHTML += '<table width="100%" cellpadding="0" cellspacing="0" title="' + response.ldb.status + '" class="ms-tables-s2">';
	ldbHTML += '<caption>' + response.ldb.status + '</caption>';
	if (fullPath) {
		ldbHTML += '<tfoot><tr><td colspan="3"><ul class="ms-list-style2"><li><a href="' + fullPath + '">Full leaderboard</a></li></ul></td></tr></tfoot>';
	}
	ldbHTML += '<thead><tr><th title="Position" scope="col" width="21%">Score</th><th title="Player" scope="col" width="56%">Player</th><th title="Score" scope="col" width="22%">Hole</th></tr></thead>';
	
	var totalScores = response.ldb.scores.length;
	
	if (totalScores < total || (!total)) {
		total = totalScores;
	}		

	ldbHTML += '<tbody>';
	
	
	var pos = 1;

	for(var i = 0; i < total; i++) {
	
		currScore = response.ldb.scores[i];			
		var matchName = currScore.name;
		var matchScore = currScore.score;
		var matchHoles = currScore.holes;
		
		// check it's not empty data - we at least need a name
		if (matchName) {
			if (pos % 2 == 0) {
				ldbHTML += '<tr class="ms-even">';
			} else {
				ldbHTML += '<tr>';
			}
			ldbHTML += '<td>' + matchScore + '</td>';
			ldbHTML += '<td>' + matchName + '</td>';
			ldbHTML += '<td>' + matchHoles + '</td>';
			ldbHTML += '</tr>';
			
			pos ++;
		}
	}
	ldbHTML += '</tbody>';
	ldbHTML += '</table>';
	
	if (!spanName) {
		var spanName = "ldbPromo";
	}
	document.getElementById(spanName).innerHTML = ldbHTML;			
	
}

function renderScbd(response, total, fullPath, spanName) {					
	// check that we have some scores	
	// build up the data into some HTML then pop into the div...
	
	var ldbHTML = '';
	ldbHTML += '<table summary="Ryder Cup Scores" class="ms-tables-s2 ms-mini-scores" border="0" cellpadding="0" cellspacing="0">';
	ldbHTML += '<caption class="adlogo">Day ' + response.ldb.day + ' - ' + response.ldb.status + '</caption>';
	ldbHTML += '<thead><tr><th scope="col" width="6%" class="flag-cell"><img src="/Images/m_shared/rydercup/site/us-mini-flag.jpg" alt="USA" /></th><th scope="col" width="40%">USA</th><th scope="col" width="40%" style="text-align:right; padding-right:4px;">EUR</th><th scope="col" width="6%" class="flag-cell"><img src="/Images/m_shared/rydercup/site/euro-mini-flag.jpg" alt="Europe" /></th></tr></thead><tbody>';
	
	var totalScores = response.ldb.scores.length;
	if (totalScores < total || (!total)) {
		total = totalScores;
	}
	
	var pos = 1;
	for(var i = 0; i < total; i++) {
		currScore = response.ldb.scores[i];			
		var matchName1 = currScore.name1;
		var matchName2 = currScore.name2;
		var matchScore = currScore.score;
		var matchWinner = currScore.winner;
		
		// check it's not empty data - we at least need a name
		if (matchName1) {
			if (pos % 2 == 0) {
				ldbHTML += '<tr>';
			} else {
				ldbHTML += '<tr class="ms-odd">';
			}
			if (matchWinner == 1) {
				ldbHTML += '<td class="usa-up">' + matchScore + '</td>';
			} else if (matchWinner == 0) {
				ldbHTML += '<td>A/S</td>';
			} else {
				ldbHTML += '<td></td>';
			}
			ldbHTML += '<td class="us">' + matchName1.replace('/','<br>') + '</td>';
			ldbHTML += '<td class="eu">' + matchName2.replace('/','<br>') + '</td>';
			if (matchWinner == 2) {
				ldbHTML += '<td class="euro-up">' + matchScore + '</td>';
			} else if (matchWinner == 0) {
				ldbHTML += '<td>A/S</td>';
			} else {
				ldbHTML += '<td></td>';
			}
			ldbHTML += '</tr>';
			
			pos ++;
		}
	}
	ldbHTML += '</tbody></table>';
	if (fullPath) {
		ldbHTML += '<ul class="ms-list-style2 ms-icon-plus">';
		ldbHTML += '<li class="view-scoreboard" style="font-weight:bold; padding:3px 10px;"><a title="Full Scoreboard (popup)" href="' + fullPath + '" rel="popUp|1018|680">Full Scoreboard</a></li>';
		ldbHTML += '</ul>';
	}
	if (!spanName) {
		var spanName = "ldbPromo";
	}
	document.getElementById(spanName).innerHTML = ldbHTML;
}

