function showSubscribeOptions(id)
{
	document.getElementById("opt1").style.display = "none";
	document.getElementById("opt2").style.display = "none";
	document.getElementById("opt3").style.display = "none";

	document.getElementById(id).style.display = "block";

	var	tb = (username == null ? "uname" : "pass");

	if (id == "opt1")
		document.forms['logon'].elements[tb].focus();
	else if (id == "opt2")
		document.forms['transfer'].elements['uname'].focus();
}

function transferAcct(f, dest)
{
	var	a = new ajaxRequest();

	a.setCallbackParam(f.uname.value);

    if (typeof(dest) != "undefined")
        a.setCallbackParam(dest);

	a.getData("/servlet/proxy?tgt=user&attr=transfer&data=rd&uname=" + f.uname.value + "&pass=" + f.pass.value + (clientID != null ? "&clientID=" + clientID : ""), transferAcctCallback);

	return false;
}

function transferAcctCallback(xml, params)
{
//alert(xml);
	var	error = getValue(xml, "user.transfer.error");

	if (error != null)
	{
		switch (error)
		{
			case "UTR000":
				alert("This request is not allowed from your IP address. Please contact Customer Service");
			break;

			case "UTR001":
				alert("An account already exists for the user name \"" + params[0] + "\".\n\nMake sure this is the correct user name for your Day At The Track account, otherwise your account has already been transfered and you can log in directly at http://www.raincingday.com.");
			break;

			case "UTR002":
				alert("Your account was located on Day At The Track, but it could not be created on Racing Day because of an internal error.\n\nPlease try again in a few minutes or contact Customer Service.");
			break;

			case "UTR003":
				alert("An account for user name \"" + params[0] + "\" could not be found on Day At The Track.\n\nPlease contact Customer Service for assistance.");
			break;

			case "UTR004":
				alert("An account for user name \"" + params[0] + "\" found, but password is not correct.\n\nPlease make sure you are using the correct password or contact Customer Service for assistance.");
			break;

			default:
				alert("An unknown error has occurred transferring your account.\n\nPlease contact Customer Service for assistance.");
			break;
		}
	}
	else
	{
		alert("Your account has been successfully transferred.\n\nYou can begin using Racing Day immediately and will be logged in to your Racing Day account when you click the \"OK\" button.");

		if (params.length > 1)
			documnet.location = params[1];
		else
			document.location = "http://www.racingday.com/dashboard.mdg?_sessionid=" + getValue(xml, "user.transfer.session");
	}
}

function createAcct(f)
{
	var	a = new ajaxRequest();

	a.setCallbackParam(f.uname.value);

	var	params = "salutation=" + f.salutation.value +
			"&firstName=" + f.firstName.value +
			"&middleInitial=" + f.middleInitial.value +
			"&lastName=" + f.lastName.value +
			"&suffix=" + f.suffix.value +
			"&addr=" + f.addr.value +
			"&addr2=" + f.addr2.value +
			"&city=" + f.city.value +
			"&state=" + f.state.value +
			"&zip=" + f.zip.value +
			"&country=" + f.country.value +
			"&phone=" + (f.country.value == "USA" ?
				f.acode.value + f.phone.value : f.phone.value) +
//			"&govtID=" + f.govtID.value +
//			"&govtIDState=" + f.govtIDState.value +
			"&email=" + f.email.value +
			"&uname=" + f.uname.value +
			"&pin=" + f.pin.value +
			"&language=" + f.language.value +
			"&timeZone=" + f.timeZone.value +
			"&emailFormat=" + f.emailFormat.value +
//			"&month=" + f.month.value +
//			"&day=" + f.day.value +
//			"&year=" + f.year.value +
//			"&age=" + f.age.value +
			"&affiliateID=" + f.affiliateID.value;

	a.getData("/servlet/proxy?tgt=user&attr=create&data=rd&" + params + (clientID != null ? "&clientID=" + clientID : ""), createAcctCallback);

	return false;
}

function createAcctCallback(xml, params)
{
	var	error = getValue(xml, "user.create.error");

	if (error != null)
	{
		switch (error)
		{
			case "UCR000":
				alert("This request is not allowed from your IP address. Please contact Customer Service");
			break;

			case "UCR001":
				alert("Your account could not be created, please try again in a few minutes.");
			break;

			default:
				alert("An unknown error has occurred creating your account.\n\nPlease contact Customer Service for assistance.");
			break;
		}
	}
	else
	{
//		alert("Your account has been successfully created.\n\nYou will be receiving an email shortly containing instructions needed to activate your account. Once you ra ccount is activated, you can begin using Racing day.");

		document.location = "http://www.racingday.com/signupcomplete.mdg";
	}
}

function showOverlay(sub, msg)
{
	document.body.style.overflow = "hidden";

	var	div = document.getElementById("overlay");

	// DHTML menu builder call to control visibility

	if (typeof(tbVisC) != "undefined")
	{
		tbVisC[1] = new Function("return false");
		SetupToolbar();
	}

	div.style.width = document.body.clientWidth;
	div.style.height = document.body.clientHeight;

	div.style.visibility = "visible";

	window.onresize = function() { if (onresizeFunc) onresizeFunc(); showOverlay(sub) };

	if (typeof(msg) != "undefined")
		document.getElementById(sub + "Message").innerHTML = msg;

	document.getElementById(sub).style.visibility = "visible";

	if (sub == 'loginTransferRegister')
		showSubscribeOptions('opt1');
	else if (sub == 'restricted')
		;
}

function hideOverlay()
{
	document.body.style.overflow = "auto";

	var	div = document.getElementById("overlay");

	div.style.width = 100;
	div.style.height = 100;

	div.style.visibility = "hidden";

	// DHTML menu builder call to control visibility

	tbVisC[1] = new Function("return true");
	SetupToolbar();

	// needed to trigger menu to position itself correctly

	window.scroll(1,1);
	window.scroll(0,0);

	window.onresize = new function() { if (onresizeFunc) onresizeFunc(); };
}

var onresizeFunc = window.onresize;
