function regOnSubmit(check_only)
	{
	var f = $("#regForm");
	f[0].submitted_once = true;
	var ok = true;

	var fn = $("[name='firstName']",f);
	var ln = $("[name='lastName']",f);
	var p = $("[name='password']",f);
	var cp = $("[name='confirmPassword']",f);
	var e = $("[name='email']",f);
	var g = $("[name='gender']",f);
	var grad = $("[name='gradYear']",f);
	var bm = $("[name='birthMonth']",f);
	var bd = $("[name='birthDay']",f);
	var by = $("[name='birthYear']",f);
	var z = $("[name='zip']",f);

	if (fn.val() != fn[0].defaultValue) fn.val(fixName(fn.val()));
	if (ln.val() != ln[0].defaultValue) ln.val(fixName(ln.val()));
	if (e.val() != e[0].defaultValue) e.val(fixEmail(e.val()));
	if (z.val() != z[0].defaultValue) z.val(fixZip(z.val()));

	if (!inputHasValue(fn)) ok = alertField(fn,{id:"first_name",message:"Please enter your <strong>first name</strong>."});
	else alertField(fn,{id:"first_name"},true);
	if (!inputHasValue(ln)) ok = alertField(ln,{id:"last_name",message:"Please enter your <strong>last name</strong>."});
	else alertField(ln,{id:"last_name"},true);

	if (p.length && p.is(":visible"))
		{
		if (!inputHasValue(p)) ok = alertField(p,{id:"pass",message:"Please enter a password."});
		else if (p.val().length < 4 || p.val().length > 20) ok = alertField(p,{id:"pass",message:"Password must be between 4 and 20 characters in length."});
		else if (!isValidPassword(p.val())) ok = alertField(p,{id:"pass",message:"Password may contain only numbers, letters and underscores."});
		else alertField(p,{id:"pass"},true);
		if (cp.length)
			{
			if (cp.is(":visible"))
				{
				if (cp.val() != p.val()) ok = alertField(cp,{id:"confirm_pass",message:"Passwords do not match."});
				else alertField(cp,{id:"confirm_pass"},true);
				}
			else cp.val(p.val());
			}
		}

	if (!inputHasValue(e)) ok = alertField(e,{id:"email",message:"Please enter your <strong>email</strong> address."});
	else if (!strContains(e.val(),["@","."])) ok = alertField(e,{id:"email",message:"Please enter a valid <strong>email</strong> address."});
	else alertField(e,{id:"email"},true);

	if (g.attr("type") == "radio")
		{
		if (!g[0].checked && !g[1].checked) ok = alertField(g,{id:"gender",message:"Please select <strong>male</strong> or <strong>female</strong>."});
		else alertField(g,{id:"gender"},true);
		}
	else
		{
		if (!g.val()) ok = alertField(g,{id:"gender",message:"Please select <strong>male</strong> or <strong>female</strong>."});
		else alertField(g,{id:"gender"},true);
		}

	if (!grad.val()) ok = alertField(grad,{id:"grad_year",message:"Please select the <strong>year</strong> you graduated high school."});
	else alertField(grad,{id:"grad_year"},true);

	if (!by.val()) ok = alertField(by,{id:"birthdate",message:"Please select the <strong>year</strong> in which you were born."});
	else alertField(by,{},true);
	if (!bm.val()) ok = alertField(bm,{id:"birthdate",message:"Please select the <strong>month</strong> in which you were born."});
	else alertField(bm,{},true);
	if (!bd.val()) ok = alertField(bd,{id:"birthdate",message:"Please select the <strong>day</strong> on which you were born."});
	else alertField(bd,{},true);
	if (bm.val() && bd.val() && by.val()) alertField(by,{id:"birthdate"},true);

	if (!inputHasValue(z)) ok = alertField(z,{id:"zip",message:"Please enter your <strong>zip code</strong>."});
	else if (!strHasLengthOf(z.val(),[5,6,9,10])) ok = alertField(z,{id:"zip",message:"Please enter a <strong>valid US/Canadian zip code (no dashes)</strong>."});
	else alertField(z,{id:"zip"},true);

	if (ok && !check_only)
		{
		if (p.length && !p.is(":visible")) p.remove();
		if (cp.length && !cp.is(":visible")) cp.remove();
		if (typeof(visit_history) == "object") visit_history.current_visit.registered = true;
		loadProcessingOverlay({loading_copy:"Processing...",bg_color:"#000000",bg_alpha:"85"});
		}

	return ok;
	}

function loadWSFYTeaser(fn,ln,a)
	{
	if (fn && ln && a)
		{
		wsfy_info = {};
		wsfy_info.first_name = (fn.substr(0,1)).toUpperCase()+fn.substr(1);
		wsfy_info.last_name = (ln.substr(0,1)).toUpperCase()+ln.substr(1);
		wsfy_info.age = a;
		wsfy_info.full_name = wsfy_info.first_name+" "+wsfy_info.last_name;
		//$.get("/WSFY/wsfy_api.php",{firstName:fn,lastName:ln,age:a},handleWSFYRequest);
		$.get("/REUNION/proxy.php",{proxyurl:"http://creative.mylife.com/WSFY/wsfy_api.php",firstName:fn,lastName:ln,age:a},handleWSFYRequest);
		}
	}

function handleWSFYRequest(data)
	{
	var delay = 2000;
	var result_obj = eval("("+data+")");
	wsfy_info.result = result_obj.wsfy || null;
	var tc = (wsfy_info.result && wsfy_info.result.totalCount) ? wsfy_info.result.totalCount : 0;
	if (tc)
		{
		var tspot = $("#wsfy_teaser");
		$("h4",tspot).html("Searching...");
		$("ul",tspot).html('<li class="loader"><img src="http://a1.mylife.com/a/landa/i/ajax_loader-md_dots.gif" alt="loading..." /></li>');

		handleWSFYRequest_postdelay = function()
			{
			var tc = wsfy_info.result.totalCount;
			var tspot = $("#wsfy_teaser");
			var num_people = $(".num_people",tspot);
			var num_female = $(".num_gender.female",tspot);
			var num_male = $(".num_gender.male",tspot);

			num_people.html("We found<br /><strong>"+tc+" "+(tc==1?"person":"people")+" searching for "+wsfy_info.full_name+"</strong>");
			if (wsfy_info.result.numFemales) num_female.html(wsfy_info.result.numFemales+" "+(wsfy_info.result.numFemales == 1 ? "is" : "are")+" female").css("display","block");
			else num_female.css("display","none");
			if (wsfy_info.result.numMales) num_male.html(wsfy_info.result.numMales+" "+(wsfy_info.result.numMales == 1 ? "is" : "are")+" male").css("display","block");
			else num_male.css("display","none");
			
			var num_thumbs = tc <= 14 ? tc : 14;
			var gender = num_female == 0 ? "m" : (num_male == 0 ? "f" : false);
			tspot.find(".result_thumbs").html('<img alt="" src="' + getThumbsList(num_thumbs,gender).join('" /><img alt="" src="') + '" />');

			$(".one",tspot).fadeOut(400,function()
				{
				$("#wsfy_teaser .two").fadeIn(400);
				});

			}
		if (typeof(wsfy_teaser_timeout) != "undefined") clearTimeout(wsfy_teaser_timeout);
		wsfy_teaser_timeout = setTimeout("handleWSFYRequest_postdelay()",delay);
		}
	}

function checkForWSFYTease()
	{
	var rform = $("#regForm");
	var fn = $("[name='firstName']",rform).val();
	var ln = $("[name='lastName']",rform).val();
	var a = 37;
	if (fn && ln) loadWSFYTeaser(fn,ln,a);
	}

function arrayContains(arr,what)
	{
	for (var i=0;i<arr.length;i++)
		{
		if (arr[i] == what) return true;
		}
	return false;
	}

function getUniqueRandomIntegers(how_many,min,max)
	{
	var ints = new Array();
	if (max-min+1 < how_many) how_many = max-min+1;
	while (ints.length < how_many)
		{
		var next_int = Math.round(Math.random()*(max-min))+min;
		if (!arrayContains(ints,next_int)) ints.push(next_int);
		}
	return ints;
	}

function prependZeros(int,places)
	{
	var str = ""+int;
	while (str.length < places) str = "0"+str;
	return str;
	}

function getBlurredThumbs(how_many,type)
	{
	var max = type == "female" ? 34 : 20;
	if (how_many > max) how_many = max;
	var random_start_index = Math.round(Math.random()*max);
	var thumbs = new Array();
	for (var i=0;i<how_many;i++) thumbs.push("http://a1.mylife.com/a/landa/i/blur-profiles/"+type+"_"+prependZeros((random_start_index+i)%max,3)+".jpg");
	return thumbs;
	}

function getThumbsList(how_many,type)
	{
	if (type == "m") type = "male";
	else if (type == "f") type = "female";
	else type = Math.round(Math.random()) ? "female" : "male";
	var num_blurred = how_many == 1 ? 0 : Math.ceil(how_many/1.5);
	var blurred_thumbs = getBlurredThumbs(num_blurred,type);
	var avatar_url = "http://a1.mylife.com/a/landa/i/default_prof_pic-"+type.charAt(0)+".png";
	var b_indices = getUniqueRandomIntegers(blurred_thumbs.length,0,how_many-1);
	var thumbs = new Array();
	for (var i=0;i<b_indices.length;i++) thumbs[b_indices[i]] = blurred_thumbs[i];
	for (var i=0;i<how_many;i++)
		{
		if (!thumbs[i]) thumbs[i] = avatar_url;
		}
	return thumbs;
	}