<!--// JavaScript Document
var username_check = "0";

function checkProfile(frm, a)
{
	var emptyErrors, formatErrors;
	emptyErrors = '';
	formatErrors = '';
	if(frm.firstName.value == '')
		emptyErrors += "First Name\n";
	if(frm.lastName.value == '')
		emptyErrors += "Last Name\n";
	if(frm.home.value == '' && frm.cell.value == '')
		emptyErrors += "Home or Cell Phone\n";
	if(frm.email.value == '')
		emptyErrors += "Email Address\n";
	if(frm.username.value == '')
		emptyErrors += "Username\n";
	if(frm.password.value == '')
		emptyErrors += "Password\n";
	if(frm.repeatPassword.value == '')
		emptyErrors += "Repeat Password\n";
	
	if(emptyErrors != '')
	{
		alert("Please fill out the following fields:\n\n" + emptyErrors);
		return false;
	}
	else//format errors
	{
		if(a == true)
		{
			checkUsername(frm.username.value)
			//alert(username_check)
			if(username_check == 1)
			{
				alert("The username " + frm.username.value + " is already in use.\nPlease try another username.")
				return false;
			}
		}
		re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
		if(!re.test(frm.email.value))
			formatErrors += "The Email Address should be in the following format: xxx@yyy.zzz\n";
		re = /^(\d){3}-(\d){3}-(\d){4}$/;
		if(frm.home.value != "")
		{
			if(!re.test(frm.home.value))
				formatErrors += "The Phone Number should be in the following format: 416-555-1212\n";
		}
		if(frm.cell.value != "")
		{
			if(!re.test(frm.cell.value))
				formatErrors += "The Cell Number should be in the following format: 416-555-1212\n";			
		}
		if(frm.work.value != "")
		{
			if(!re.test(frm.work.value))
				formatErrors += "The Work Number should be in the following format: 416-555-1212\n";			
		}
		if(frm.password.value != frm.repeatPassword.value)
		{
			formatErrors += "The password and repeated password do no match\n";
		}
		if(formatErrors != '')	
		{
			alert("There are the following formatting errors:\n\n" + formatErrors);
			return false;
		}
	}
}
function checkMailing(frm)
{
	var emptyErrors, formatErrors;
	emptyErrors = '';
	formatErrors = '';
	if(frm.full_name.value == '')
		emptyErrors += "Your full name\n";
	if(frm.email.value == '')
		emptyErrors += "Your email address\n";
	
	if(emptyErrors != '')
	{
		alert("Please fill out the following fields:\n\n" + emptyErrors);
		return false;
	}
	else//format errors
	{
		re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
		if(!re.test(frm.email.value))
			formatErrors += "The Email Address should be in the following format: xxx@yyy.zzz\n";
		re = /^(\d){3}-(\d){3}-(\d){4}$/;
		if(frm.phone.value != "")
		{
			if(!re.test(frm.phone.value))
				formatErrors += "The Phone Number should be in the following format: 416-555-1212\n";
		}
		if(formatErrors != '')	
		{
			alert("There are the following formatting errors:\n\n" + formatErrors);
			return false;
		}
	}
}
function checkRemove(frm)
{
	var emptyErrors, formatErrors;
	emptyErrors = '';
	formatErrors = '';
	if(frm.emailAddress.value == '')
		emptyErrors += "Your email address\n";
	
	if(emptyErrors != '')
	{
		alert("Please fill out the following fields:\n\n" + emptyErrors);
		return false;
	}
	else//format errors
	{
		re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
		if(!re.test(frm.emailAddress.value))
			formatErrors += "The Email Address should be in the following format: xxx@yyy.zzz\n";
		re = /^(\d){3}-(\d){3}-(\d){4}$/;
		if(formatErrors != '')	
		{
			alert("There are the following formatting errors:\n\n" + formatErrors);
			return false;
		}
	}
}
function checkUsername(str)
{
	if (str.length==0)
	{ 
		document.getElementById("txtHint").innerHTML=""
		return
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url="check_username.asp"
	url=url+"?q="+str
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,false)
	xmlHttp.send(null)
}
	
function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		username_check = xmlHttp.responseText
	} 
} 
function GetXmlHttpObject(handler)
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}
//-->
