// Handles all the rewriting duties for each playslip

function playslip() {
	var game = $('form').parent().parent().parent().parent().attr('class');	
	$('.clear').replaceWith('<li class="clear"><a class="clearline">Clear</a></li>');
	$('.clearline').bind('click',function(){enableClearLine(this);});
	$('.clearlines').replaceWith('<li class="clearlines"><a class="clearline" onclick="clearInputs(\'playsliplist\');">Clear all lines</a></li>');
}

// Enables clearing of a whole play line

function enableClearLine(row) {
	var playline = $(row).parent().parent().attr('id');
	$('#' + playline + ' > li > input:text').val('');
	if( $('#' + playline + '_hp').length > 0) 
	{
		$('#' + playline + ' > li > input:text').attr('disabled', 'disabled');
		$('#' + playline + '_hp > li > input:radio').removeAttr('checked');
	}

}

function clearInputs(parentId) {	
	$("#" + parentId + " input[@type = 'text']").each(function() {
		$(this).attr("disabled", "");
		$(this).val("");
	});
	
	$("#" + parentId + " input[@type = 'radio']").each(function() {
		$(this).attr("checked", "" );
	});
}

// Shows/hides div#helpboxcontainer

/*
function findOffsetTop(obj) {
	var divOffsetTop = document.getElementById(obj).offsetTop;
	alert('divOffsetTop: ' + divOffsetTop);
	return divOffsetTop;
}*/
function getTopLeft(obj)
{
	var isIE6 = ((navigator.userAgent.indexOf("MSIE 6.") != -1) && (navigator.userAgent.indexOf("Opera") == -1));
	var isIE7 = /*@cc_on!@*/false && ( parseInt( navigator.userAgent.toLowerCase().match( /msie (\d+)/ )[1] ) >= 7 );
	var divOffsetTop = document.getElementById(obj).offsetTop;

	obj = document.getElementById(obj).offsetParent;
	if(isIE6 || isIE7) { // IE6 and IE7 need to find the offsetTop of the offsetParent
		divOffsetTop = parseInt(divOffsetTop) + parseInt(obj.offsetTop);
		obj = obj.offsetParent;
	}
	return divOffsetTop;
}

$(document).ready(function(){
	playslip();

	$('a.lottohelpboxcontainerOpen').click(function() {
		document.getElementById('lottoHelpOverlay').style.display = 'block';
		document.getElementById('lottoHelpOverlay').style.zIndex = '2001';
		document.getElementById('lottoHelpOverlay').style.position = 'absolute';
		document.getElementById('lottoHelpOverlay').style.top = getTopLeft('lottoHelpAlign') + 0 + 'px';
		if (document.getElementById('lottoHelpOverlay').className == 'right')
		{
			document.getElementById('lottoHelpOverlay').style.left = '280px';
		}
		else
		{
			document.getElementById('lottoHelpOverlay').style.left = '-326px';
		}
		return false;
	});

	$('a.lottohelpboxcontainerClose').click(function() {
		document.getElementById('lottoHelpOverlay').style.display = 'none';
		return false;
	});

	$('a.dreamnohelpboxcontainerOpen').click(function() {
		document.getElementById('dreamnoHelpOverlay').style.display = 'block';
		document.getElementById('dreamnoHelpOverlay').style.zIndex = '2001';
		document.getElementById('dreamnoHelpOverlay').style.position = 'absolute';
		document.getElementById('dreamnoHelpOverlay').style.top = getTopLeft('dnHelpAlign') + 0 + 'px';
		if (document.getElementById('dreamnoHelpOverlay').className == 'right')
		{
			document.getElementById('dreamnoHelpOverlay').style.left = '280px';
		}
		else
		{
			document.getElementById('dreamnoHelpOverlay').style.left = '-326px';
		}
		return false;
	});

	$('a.dreamnohelpboxcontainerClose').click(function() {
		document.getElementById('lottoHelpOverlay').style.display = 'none';
		return false;
	});
});
