// JavaScript Document
function validate()
{
	doc = eval("document.forms[0]");
	pick = 0;
	ou = 0;
	format_date('display_date',doc.display_date.value);
	pick = set_pickline('pick',doc.pick.value);
	ou - test_overunder('pick_ou',doc.pick_ou.value);
	flag = 0;
	msg = "";
	if(doc.favorite[doc.favorite.selectedIndex].value == "team" || doc.underdog[doc.underdog.selectedIndex].value == "team")
	{
		alert("Please select a team for Favorite and Underdog");
		flag = 1;
		return;
	}
	if(doc.favorite[doc.favorite.selectedIndex].text == doc.underdog[doc.underdog.selectedIndex].text)
	{
		alert("Please select different teams for Favorite and Underdog");
		flag = 1;
		return;
	}
	if(!pick && !ou)
	{
		alert("You must select either Straight Pick or Over/Under Pick");
		flag = 1;
		return;
	}
	if(pick && ou)
	{
		alert("You must select either Straight Pick or Over/Under Pick, not BOTH!");
		for(i=0;i<doc.pick_ou.length;i++)
		{
			if(doc.pick_ou[i].checked)
			{
				doc.pick_ou[i].checked = false;
			}
		}
		for(i=0;i<doc.pick.length;i++)
		{
			if(doc.pick[i].checked)
			{
				doc.pick[i].checked = false;
			}
		}
		doc.overunder.value = "";
		doc.line.value = "";
		pick = 0;
		ou =0;
		flag = 1;
		return;
	}
	if(pick)
	{
		pick = set_pickline('pick',doc.pick.value);
		doc.overunder.value = "";
		if(doc.line.value == "")
		{
			alert("You must enter a line for Straight Pick");
			flag = 1;
			return;
		}
	}
	if(ou)
	{
		doc.line.value = "";
		doc.pick_line.value = "";
		if(doc.overunder.value == "")
		{
			alert("You must enter a line for Over/Under Pick");
			flag = 1;
			return;
		}
	}
	if(!flag)
        makePick(doc.league.value);
//		alert(doc.pick_line.value);
//		document.forms[0].submit();
}
function format_date(fieldname,val)
{
	doc1 = eval("document.forms[0]."+fieldname);
	month = doc1.value.substring(0,2);
	day = doc1.value.substring(3,5);
	year = doc1.value.substring(6,10);
	document.forms[0].date.value = year + "-" + month + "-" + day;
}
function set_pickline(fieldname,val)
{
	doc2 = eval("document.forms[0]."+fieldname);
	for(i=0;i<doc2.length;i++)
	{
		if(doc2[i].checked)
		{
			doc.pick_line.value = doc2[i].value;
			pick = 1;
			return pick;
		}
	}
}
function test_overunder(fieldname,val)
{
	doc3 = eval("document.forms[0]."+fieldname);
	for(i=0;i<doc2.length;i++)
	{
		if(doc3[i].checked)
		{
			ou = 1;
			return ou;
		}
	}
}

function getLoginBox()
{
	$('loginbox').style.display = "block";
	$('user').focus();
}

function closeLoginBox()
{
	$('loginalert').innerHTML = "&nbsp;";
	$('loginbox').style.display = "none";
}

function tryLogin()
{
    var pars = Form.serialize($('loginform'));
	
	var options = {
		method : 'post',
		evalScripts:true,
		asynchronous:true,
		parameters : {
			formVars: pars,
			state: 0
		},
		onSuccess: function(transport){
			if(transport.responseText == 1)
			{
				$('loginbox').style.display = "none";
				location = location;
			}
		}
	};

	new Ajax.Updater('loginbox','/login.php', options);
}

function logout()
{	
	var options = {
		method : 'post',
		evalScripts:true,
		asynchronous:true,
		parameters : {
			formVars: "",
			state: 1
		},
		onSuccess: function(transport){
			location = location;
		}
	};

	new Ajax.Updater('loginbox','/login.php', options);
}

function specificRecords(sport)
{
	var options = {
		method : 'post',
		evalScripts:true,
		asynchronous:true,
		parameters : {
			sportID: sport
		},
		onSuccess: function(transport){
		}
	};

	new Ajax.Updater('records_panel','/specific_records.php', options);
}
