var sendUNSuccess = function(o){ 
	var unstatdiv = document.getElementById("unstatdiv");
	var unformbut = document.getElementById("unformbut");
	var pass1head = document.getElementById("pass1head");
	var pass1formel = document.getElementById("pass1formel");
	var pass1formbut = document.getElementById("pass1formbut");
	
	var results = o.responseText.split('|');
	var respStat = parseInt(results[0]);
	var respText = results[1];
	if (respStat == 2) 
	{
		unstatdiv.innerHTML = "<div class='daisy'>SUCCESS: Username is available.</div>";
		unformbut.innerHTML = "";
		document.getElementById("unhead1").innerHTML = "Choose a Username [<a href='javascript:startOver()'>Start Over</a>]";
		document.forms.regform.nusername.disabled = true;
		pass1head.innerHTML = "Please choose a password";
		pass1formel.innerHTML = "<input type=password name=npass1 class=reginput />";
		pass1formbut.innerHTML = "<input type=submit value=\"Continue\" class=reginput onclick=\"checkP1();\" />";
		document.forms.regform.npass1.focus();
		document.getElementById("unwrap").style.border = "#FFFFFF 1px solid";
		document.getElementById("pass1wrap").style.border = "#0099FF 1px solid";
	}
	else 
	{
		unstatdiv.innerHTML = "<div class='woopsie'>ERROR: Username is already taken, please choose another.</div>";
		unformbut.innerHTML = "<input type=submit value=\"Continue\" class=reginput onclick=\"checkUN();\" />";
	}
}; 

var handleUNResp = 
{ 
success:sendUNSuccess
}; 

function checkUN()
{
	var unstatdiv = document.getElementById("unstatdiv");
	var unformbut = document.getElementById("unformbut");
	var username = document.forms.regform.nusername.value;
	
	if (notBlank(username)) 
	{
		unstatdiv.innerHTML = "";
		if (minMaxLength(username, 3, 20))
		{
			unstatdiv.innerHTML = "";
			if (onlyCharsNums(username)) 
			{
				unstatdiv.innerHTML = "";
				unformbut.innerHTML = "<img src='pics/mozilla_blu.gif />";
				var formObject = document.getElementById('reggform'); 
				YAHOO.util.Connect.setForm(formObject); 
				YAHOO.util.Connect.asyncRequest('GET', 'ajax/regcheckun.php', handleUNResp, null);
			}
			else
			{
				unstatdiv.innerHTML = "<div class='woopsie'>ERROR: Username may only have alphanumeric characters.</div>";
			}
		}
		else 
		{
			unstatdiv.innerHTML = "<div class='woopsie'>ERROR: Username must have a minimum of 3 and a maximum of 20 alphanumeric characters.</div>";
		}
	}
	else
	{
		unstatdiv.innerHTML = "<div class='woopsie'>ERROR: Username cannot be blank.</div>";
	}
}	

function checkP1()
{
	var pass1statdiv = document.getElementById("pass1statdiv");
	var pass1formbut = document.getElementById("pass1formbut");
	var pass2head = document.getElementById("pass2head");
	var pass2formel = document.getElementById("pass2formel");
	var pass2formbut = document.getElementById("pass2formbut");
	var pass1 = document.forms.regform.npass1.value;
	
	if (notBlank(pass1)) 
	{
		pass1statdiv.innerHTML = "";
		if (minMaxLength(pass1, 6, 15))
		{
			pass1statdiv.innerHTML = "";
			if (onlyCharsNums(pass1)) 
			{
				pass1statdiv.innerHTML = "<div class='daisy'>SUCCESS: Password is valid.</div>";
				pass1formbut.innerHTML = "";
				document.forms.regform.npass1.disabled = true;
				pass2head.innerHTML = "Please re-enter your password";
				pass2formel.innerHTML = "<input type=password name=npass2 class=reginput />";
				pass2formbut.innerHTML = "<input type=submit value=\"Continue\" class=reginput onclick=\"checkP2();\" />";
				document.forms.regform.npass2.focus();
				document.getElementById("pass1wrap").style.border = "#FFFFFF 1px solid";
				document.getElementById("pass2wrap").style.border = "#0099FF 1px solid";
			}
			else
			{
				pass1statdiv.innerHTML = "<div class='woopsie'>ERROR: Password may only have alphanumeric characters.</div>";
			}
		}
		else 
		{
			pass1statdiv.innerHTML = "<div class='woopsie'>ERROR: Password must have a minimum of 6 and a maximum of 15 alphanumeric characters.</div>";
		}
	}
	else
	{
		pass1statdiv.innerHTML = "<div class='woopsie'>ERROR: Password cannot be blank.</div>";
	}
}

function checkP2()
{
	var pass2statdiv = document.getElementById("pass2statdiv");
	var pass2formbut = document.getElementById("pass2formbut");
	var emhead = document.getElementById("emhead");
	var emformel = document.getElementById("emformel");
	var emformbut = document.getElementById("emformbut");
	
	if (document.forms.regform.npass1.value == document.forms.regform.npass2.value)
	{
		pass2statdiv.innerHTML = "<div class='daisy'>SUCCESS: Passwords match.</div>";
		pass2formbut.innerHTML = "";
		document.forms.regform.npass2.disabled = true;
		emhead.innerHTML = "Please enter your email address";
		emformel.innerHTML = "<input type=text name=nemail class=reginput />";
		emformbut.innerHTML = "<input type=submit value=\"Continue\" class=reginput onclick=\"checkEMail();\" />";
		document.forms.regform.nemail.focus();
		document.getElementById("pass2wrap").style.border = "#FFFFFF 1px solid";
		document.getElementById("emwrap").style.border = "#0099FF 1px solid";
	}
	else
	{
		pass2statdiv.innerHTML = "<div class='woopsie'>ERROR: Passwords do not match.</div>";
	}
}

var sendEMSuccess = function(o){ 
	var emstatdiv = document.getElementById("emstatdiv");
	var emformbut = document.getElementById("emformbut");
	var nutermsdiv = document.getElementById("nutermsdiv");
	
	var results = o.responseText.split('|');
	var respStat = parseInt(results[0]);
	var respText = results[1];
	if (respStat == 2) 
	{
		emstatdiv.innerHTML = "<div class='daisy'>SUCCESS: E-mail is OK.</div>";
		emformbut.innerHTML = "";
		document.forms.regform.nemail.disabled = true;
		nutermsdiv.innerHTML = "In checking the box below and completing the registration you are agreeing to the terms and conditions for using this site.<br /><br /><center><input type=checkbox name=ntac onclick=\"checkCB();\" /> I AGREE</center>";
		document.getElementById("emwrap").style.border = "#FFFFFF 1px solid";
		document.getElementById("tacwrap").style.border = "#0099FF 1px solid";
	}
	else 
	{
		emstatdiv.innerHTML = "<div class='woopsie'>ERROR: Email address has already been taken, please click here to retrieve your username or password.</div>";
		emformbut.innerHTML = "<input type=submit value=\"Continue\" class=reginput onclick=\"checkEMail();\" />";
	}
}; 

var handleEMResp = 
{ 
success:sendEMSuccess
}; 

function checkEMail()
{
	var emstatdiv = document.getElementById("emstatdiv");
	var emformbut = document.getElementById("emformbut");
	var nutermsdiv = document.getElementById("nutermsdiv");
	var em = document.forms.regform.nemail.value;
	
	if (notBlank(em)) 
	{
		emstatdiv.innerHTML = "";
		if (minMaxLength(em, 6, 50))
		{
			emstatdiv.innerHTML = "";
			if (isEmail(em)) 
			{
				emstatdiv.innerHTML = "";
				emformbut.innerHTML = "<img src='pics/mozilla_blu.gif />";
				YAHOO.util.Connect.asyncRequest('GET', 'ajax/regcheckem.php?em='+em, handleEMResp, null);
			}
			else
			{
				emstatdiv.innerHTML = "<div class='woopsie'>ERROR: E-mail is not in the correct form (emailname@exampledomain.net).</div>";
			}
		}
		else 
		{
			emstatdiv.innerHTML = "<div class='woopsie'>ERROR: E-mail must have a minimum of 6 and a maximum of 50 alphanumeric characters.</div>";
		}
	}
	else
	{
		emstatdiv.innerHTML = "<div class='woopsie'>ERROR: E-mail cannot be blank.</div>";
	}
}

function checkCB()
{
	var nusubmitdiv = document.getElementById("nusubmitdiv");
	
	if (document.forms.regform.ntac.checked)
	{
		nusubmitdiv.innerHTML = "We can now process your registration.  When you click FINISH below, we will add an account for the username you selected.  The account will not be activated until you follow the instructions contained in an email that we will send to your email address.<br /><br /><center><input type=submit value=\"F I N I S H\" class=reginput onclick=\"finishReg();\" /></center>";
		document.getElementById("tacwrap").style.border = "#FFFFFF 1px solid";
		document.getElementById("finalwrap").style.border = "#0099FF 1px solid";
	}
	else
	{
		nusubmitdiv.innerHTML = "";
		document.getElementById("tacwrap").style.border = "#0099FF 1px solid";
		document.getElementById("finalwrap").style.border = "#FFFFFF 1px solid";
	}
}

var sendRFSuccess = function(o){ 
	var unwrap = document.getElementById("unwrap");
	
	document.getElementById("unhead1").innerHTML = "";
	document.getElementById("unstatdiv").innerHTML = "";
	document.getElementById("unformel").innerHTML = "";
	document.getElementById("unformbut").innerHTML = "";
	document.getElementById("pass1head").innerHTML = "";
	document.getElementById("pass1formel").innerHTML = "";
	document.getElementById("pass1formbut").innerHTML = "";
	document.getElementById("pass1statdiv").innerHTML = "";
	document.getElementById("pass2head").innerHTML = "";
	document.getElementById("pass2formel").innerHTML = "";
	document.getElementById("pass2formbut").innerHTML = "";
	document.getElementById("pass2statdiv").innerHTML = "";
	document.getElementById("emhead").innerHTML = "";
	document.getElementById("emformel").innerHTML = "";
	document.getElementById("emformbut").innerHTML = "";
	document.getElementById("emstatdiv").innerHTML = "";
	document.getElementById("nutermsdiv").innerHTML = "";
	document.getElementById("finalwrap").innerHTML = "";
	
	var results = o.responseText.split('|');
	var respStat = parseInt(results[0]);
	var respText = results[1];
	
	document.getElementById("unwrap").style.border = "#0099FF 1px solid";
	document.getElementById("finalwrap").style.border = "#FFFFFF 1px solid";
	unwrap.innerHTML = respText;
}; 

var handleRFResp = 
{ 
success:sendRFSuccess
}; 

function finishReg()
{
	var nusubmitdiv = document.getElementById("nusubmitdiv");
	document.forms.regform.ntac.disabled = true;
	var un = document.forms.regform.nusername.value;
	var p1 = document.forms.regform.npass1.value;
	var ema = document.forms.regform.nemail.value;
	
	nusubmitdiv.innerHTML = "<center><img src='pics/mozilla_blu.gif /></center>";
	var formObject = document.getElementById('reggform'); 
	YAHOO.util.Connect.setForm(formObject); 
	YAHOO.util.Connect.asyncRequest('GET', 'ajax/regfinish.php?un='+un+'&p1='+p1+'&ema='+ema+'&sn='+sitename+'&su='+sitebaseurl+'&fake=44', handleRFResp, null);
}

function startOver()
{
	document.getElementById("unhead1").innerHTML = "Choose a Username";
	document.getElementById("unstatdiv").innerHTML = "";
	document.getElementById("unformel").innerHTML = "<input type=text name=nusername class=reginput />";
	document.getElementById("unformbut").innerHTML = "<input type=submit value='Continue' class=reginput onclick='checkUN();' />";
	document.getElementById("unwrap").style.border = "#0099FF 1px solid";
	document.getElementById("pass1head").innerHTML = "";
	document.getElementById("pass1formel").innerHTML = "";
	document.getElementById("pass1formbut").innerHTML = "";
	document.getElementById("pass1statdiv").innerHTML = "";
	document.getElementById("pass1wrap").style.border = "#FFFFFF 1px solid";
	document.getElementById("pass2head").innerHTML = "";
	document.getElementById("pass2formel").innerHTML = "";
	document.getElementById("pass2formbut").innerHTML = "";
	document.getElementById("pass2statdiv").innerHTML = "";
	document.getElementById("pass2wrap").style.border = "#FFFFFF 1px solid";
	document.getElementById("emhead").innerHTML = "";
	document.getElementById("emformel").innerHTML = "";
	document.getElementById("emformbut").innerHTML = "";
	document.getElementById("emstatdiv").innerHTML = "";
	document.getElementById("emwrap").style.border = "#FFFFFF 1px solid";
	document.getElementById("nutermsdiv").innerHTML = "";
	document.getElementById("tacwrap").style.border = "#FFFFFF 1px solid";
	document.getElementById("nusubmitdiv").innerHTML = "";
	document.getElementById("finalwrap").style.border = "#FFFFFF 1px solid";
	document.forms.regform.nusername.focus();
}
