

function psOnSubmit()
	{
	return formOnSubmit("ps");
	}

function wsfyOnSubmit()
	{
	return formOnSubmit("wsfy");
	}

function formOnSubmit(type)
	{
	var f = $("#"+type+"Form");
	f[0].submitted_once = true;
	var ok = true;
	
	var fn = $("[name='"+(type=="ps"?"searchFirstName":"firstName")+"']",f);
	var ln = $("[name='"+(type=="ps"?"searchLastName":"lastName")+"']",f);
	var a = $("[name='"+(type=="ps"?"searchAge":"age")+"']",f);

	if (fn.val() != fn[0].defaultValue) fn.val(fixName(fn.val()));
	if (ln.val() != ln[0].defaultValue) ln.val(fixName(ln.val()));
	if (a.val() != a[0].defaultValue) a.val(fixAge(a.val()));
	
	var des = type == "ps" ? "their" : "your";
	if (!inputHasValue(fn)) ok = alertField(fn,{id:"first_name",message:"Please enter "+des+" <strong>first name</strong>."});
	else alertField(fn,{id:"first_name"},true);
	if (!inputHasValue(ln)) ok = alertField(ln,{id:"last_name",message:"Please enter "+des+" <strong>last name</strong>."});
	else alertField(ln,{id:"last_name"},true);
	if (!inputHasValue(a)) ok = alertField(a,{id:"age",message:"Please enter "+des+" <strong>age</strong>."});
	else alertField(a,{id:"age"},true);
	
	return ok;
	}

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 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 (!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 alertField(jobj,err,pass)
	{
	var err_elm = jobj.parents("form:first").find(".error."+err.id);
	if (pass)
		{
		jobj.removeClass("highlight");
		jobj.addClass("successful");
		if (err.id) err_elm.html("");
		if (err_elm.hasClass("dblock")) err_elm.fadeOut(300);
		return true;
		}
	else
		{
		jobj.removeClass("successful");
		jobj.addClass("highlight");
		err_elm.html(err.message);
		if (err_elm.hasClass("dblock")) err_elm.fadeIn(300);
		return false;
		}
	}

var reg_exp_bad_age_chars = new RegExp("[^0-9]","g");
var reg_exp_bad_name_chars = new RegExp("[^a-zA-Z\-\' ]","g");
var reg_exp_bad_email_chars = new RegExp("[^a-zA-Z0-9_@\+\-\.]","g");
var reg_exp_bad_zip_chars = new RegExp("[^a-zA-Z0-9]","g");
var reg_exp_bad_password_chars = new RegExp("[^a-zA-Z0-9_]","g");
var reg_exp_perimeter_spaces = new RegExp("^( )+|( )+$","g");
var reg_exp_consecutive_spaces = new RegExp(" +","g");

function fixAge(age)
	{
	var max = 120;
	age = age ? age+"" : "";
	age = age.substring(0,3);
	age = age.replace(reg_exp_bad_age_chars,"");
	if (age && age > max) age = age.substring(0,2);
	return age;
	}

function fixName(name)
	{
	name = name ? name+"" : "";
	name = name.replace(reg_exp_perimeter_spaces,"");
	name = name.replace(reg_exp_consecutive_spaces," ");
	name = name.replace(reg_exp_bad_name_chars,"");
	var lcase = name.toLowerCase();
	if (lcase == "firstname" || lcase == "lastname" || lcase == "theirfirstname" || lcase == "theirlastname") name = "";
	return name;
	}

function fixEmail(email)
	{
	email = email ? email+"" : "";
	return email.replace(reg_exp_bad_email_chars,"");
	}

function fixZip(zip)
	{
	zip = zip ? zip+"" : "";
	return zip.replace(reg_exp_bad_zip_chars,"");
	}

function isValidPassword(str)
	{
	if (typeof(str) != "string") return false;
	if (str.length < 4 || str.length > 20) return false;
	if (str.replace(reg_exp_bad_password_chars,"") != str) return false;
	return true;
	}

function inputHasValue(jobj)
	{
	if (!jobj.val() || (jobj.attr("type") != "hidden" && jobj.val() == jobj[0].defaultValue)) return false;
	return true;
	}

function strHasLengthOf(str,l_arr)
	{
	for (var i=0;i<l_arr.length;i++)
		{
		if (str.length == l_arr[i]) return true;
		}
	return false;
	}

function strContains(val,str_arr)
	{
	val = typeof(val) == "object" ? val.value : (val || "");
	for (var i=0;i<str_arr.length;i++)
		{
		if (val.indexOf(str_arr[i]) == -1) return false;
		}
	return true;
	}

function capitalize(str)
	{
	var words = str.split(" ");
	for (var i=0;i<words.length;i++)
		{
		words[i] = words[i].charAt(0).toUpperCase()+words[i].substr(1).toLowerCase();
		if (words[i].substr(0,2) == "Mc") words[i] = words[i].substr(0,2) + words[i].substr(2,1).toUpperCase() + words[i].substr(3);
		else if (words[i] == "Hs") words[i] = words[i].toUpperCase();
		}
	return words.join(" ");
	}

function cacheImage(url)
	{
	if (typeof("img_cache") != "object") img_cache = new Array();
	img_cache.push(new Image());
	img_cache[img_cache.length-1].src = url;
	}

cacheImage("http://a1.mylife.com/a/landa/i/processing_overlay_logo.gif");
cacheImage("http://a1.mylife.com/a/landa/i/processing_overlay_loader.gif");
function loadProcessingOverlay(params)
	{
	if (typeof(params) != "object") var params = {};
	var bg_color = params["bg_color"] || "#000000";
	var bg_alpha = Math.round((params["bg_alpha"] || 85)*1);
	var loading_copy = params["loading_copy"] || "Processing...";
	var window_height = getWidthHeightOfWindow().height;
	var d = getWidthHeightOfDocument();
	var c = getCenterOfScreen();
	$("body").append('<div id="processing_overlay-cont"><div id="processing_overlay-bg"></div><div id="processing_overlay"></div></div>');
	$("#processing_overlay-cont").css({"position":"absolute","left":"-10000px","top":"0px","z-index":"9999"});
	$("#processing_overlay-bg").css({"position":"absolute","left":"0px","top":"0px","background":bg_color});
	$("#processing_overlay-bg").css({"opacity":bg_alpha/100,"filter":"alpha(opacity="+bg_alpha+")"});
	$("#processing_overlay-bg").css({"width":d.width+"px","height":(d.height < window_height ? window_height : d.height)+"px"});
	$("#processing_overlay").html('<img src="http://a1.mylife.com/a/landa/i/processing_overlay_logo.gif" alt="MyLife.com" width="96" height="58" /><br /><img src="http://a1.mylife.com/a/landa/i/processing_overlay_loader.gif" alt="loading..." width="128" height="15" /><br />'+loading_copy);
	$("#processing_overlay").css({"position":"absolute"});
	var i_xy = {
		x:c.x-$("#processing_overlay").width()/2,
		y:c.y-$("#processing_overlay").height()/2
		};
	if (i_xy.y < 0) i_xy.y = 0;
	$("#processing_overlay").css({"left":i_xy.x+"px","top":i_xy.y+"px"});
	$("#processing_overlay-cont").css({"display":"none","left":"0px"});
	$("#processing_overlay-cont").fadeIn(500);
	}

function genderOnChange(inp,dont_animate)
	{
	var m = $("#maiden");
	var i = $(inp);
	if (i.val() == "2")
		{
		if (dont_animate) m.css("display","block");
		else m.fadeIn(300);
		}
	else
		{
		if (dont_animate) m.css("display","none");
		else m.fadeOut(300);
		}
	}

function maximizeWindow(relocate,set_width,set_height)
	{
	set_width = set_width || 9999;
	set_height = set_height || 9999;
	if (screen.availWidth || screen.width)
		{
		var max_width = screen.availWidth || screen.width;
		var max_height = screen.availHeight || screen.height;
		var new_width = (!set_width || max_width < set_width) ? max_width : set_width;
		var new_height = (!set_height || max_height < set_height) ? max_height : set_height;
		if (window.resizeTo) window.resizeTo(new_width,new_height);
		else if (window.outerWidth)
			{
			window.outerWidth = new_width;
			window.outerHeight = new_height;
			}
		}
	if (relocate)
		{
		if (window.moveTo) window.moveTo(0,0);
		else if (window.screenX)
			{
			window.screenX = 0;
			window.screenY = 0;
			}
		}
	}

function fireRegOpenedPixel()
	{
	if (typeof(global_regopenedpx) == "undefined" && !$_GET["debug"])
		{
		var px = new Image();
		px.src = "http://r.casalemedia.com/j.gif?u=123830&s=2";
		global_regopenedpx = true;
		}
	}

function stop_tab(e)
	{
	e = e || window.event;
	var key_code = e.which || e.keyCode;
	if (key_code == 9) return false;
	}

function getWidthHeightOf(element)
	{
	var e = $(element);
	return {width:e.width(),height:e.height()};
	}

function getWidthHeightOfWindow()
	{
	return {width:$(window).width(),height:$(window).height()};
	}

function getWidthHeightOfDocument()
	{
	return {width:$(document).width(),height:$(document).height()};
	}

function getCenterOfScreen()
	{
	var scrollHeight = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
	var w_wh = getWidthHeightOfWindow();
	var x = w_wh.width/2;
	var y = w_wh.height/2+scrollHeight;
	return {x:x,y:y};
	}

function selectOptionWithValue(sel,val)
	{
	for (var i=0;i<sel.length;i++) sel[i].selected = false;
	for (var i=0;i<sel.length;i++)
		{
		if (sel[i].value == val)
			{
			sel[i].selected = true;
			return sel[i];
			}
		}
	return null;
	}

function getURLVars(from_str)
	{
	if (from_str) var url = from_str;
	else var url = ((typeof(window.location) == "string") ? window.location : window.location.href) || "";
	var var_string = url.split("?")[1] || "";
	var var_pairs = var_string.split("&");
	var get_object = new Object();
	for (var i=0;i<var_pairs.length;i++)
		{
		var pair = var_pairs[i].split("=");
		if (pair.length == 2) get_object[pair[0]] = pair[1];
		}
	return get_object;
	}
$_GET = getURLVars();

function inputOnBlur(inp)
	{
	var i = $(inp);
	i.removeClass("current");
	if (!i.val() && i[0] && i[0].defaultValue)
		{
		i.val(i[0].defaultValue);
		i.addClass("example");
		}
	}

function inputOnFocus(inp)
	{
	var i = $(inp);
	i.addClass("current");
	if (i[0] && i.val() == i[0].defaultValue)
		{
		i.val("");
		i.removeClass("example");
		}
	}

function assignDefaultValue(inp,default_value)
	{
	var i = $(inp);
	i.val(default_value);
	i[0].defaultValue = default_value;
	i.addClass("example");
	}

function applyFormEventHandlers()
	{
	var relevants = $("#psForm [type='text'],#wsfyForm [type='text'],#regForm [type='text'],#regForm [type='password'],#regForm select");
	relevants.live("focus",function()
		{
		inputOnFocus(this);
		});
	relevants.live("blur",function()
		{
		inputOnBlur(this);
		});
	
	$("#psForm [type='text']").live("blur",function()
		{
		if ($("#psForm")[0].submitted_once) psOnSubmit();
		});
	$("#wsfyForm [type='text']").live("blur",function()
		{
		if ($("#wsfyForm")[0].submitted_once) wsfyOnSubmit();
		});
	$("#regForm [type='text'],#regForm [type='password']").live("blur",function()
		{
		if ($("#regForm")[0].submitted_once) regOnSubmit(true);
		});
	$("#regForm select").live("change",function()
		{
		if ($("#regForm")[0].submitted_once) regOnSubmit(true);
		});
	$("#regForm select[name='gender']").live("change",function()
		{
		genderOnChange(this);
		});
	$("#regForm [name='gender'][type='radio']").live("click",function()
		{
		genderOnChange(this);
		if ($("#regForm")[0].submitted_once) regOnSubmit(true);
		});
	}

function regFormOnEnterForIE()
	{
	if ($.browser.msie && $.browser.version <= 7)
		{
		var submit_btn = null;
		var rf = $("#regForm");
		if ($("input[type='submit']:last",rf)[0]) submit_btn = $("input[type='submit']:last",rf);
		else if ($("input[type='image']:last",rf)[0]) submit_btn = $("input[type='image']:last",rf);
		if (submit_btn)
			{
			rf[0].submit_btn = submit_btn;
			rf.bind("keydown",function(e)
				{
				var key = e ? (e.which || e.keyCode || null) : null;
				if (key == 13)
					{
					this.submit_btn.click();
					return false;
					}
				});
			}
		}
	}

function qa_ids()
	{
	var wf = $("#wsfyForm");
	$("[name='firstName']",wf).attr("id","searchFName");
	$("[name='lastName']",wf).attr("id","searchLName");
	$("[name='age']",wf).attr("id","searchAge");
	$("[type='image']:last, [type='submit']:last",wf).attr("id","searchSubmit");

	var pf = $("#psForm");
	$("[name='searchFirstName']",pf).attr("id","searchFName");
	$("[name='searchLastName']",pf).attr("id","searchLName");
	$("[name='searchAge']",pf).attr("id","searchAge");
	$("[type='image']:last, [type='submit']:last",pf).attr("id","searchSubmit");
	
	var rf = $("#regForm");
	$("[name='firstName']",rf).attr("id","regFName");
	$("[name='lastName']",rf).attr("id","regLName");
	$("[name='email']",rf).attr("id","regEmail");
	$("[name='gender']",rf).attr("id","regGender");
	$("[name='maidenName']",rf).attr("id","regMName");
	$("[name='birthMonth']",rf).attr("id","regBdayMon");
	$("[name='birthDay']",rf).attr("id","regBdayDay");
	$("[name='birthYear']",rf).attr("id","regBdayYear");
	$("[name='zip']",rf).attr("id","regZipcode");
	$("[type='image']:last, [type='submit']:last",rf).attr("id","regSubmit");
	}

function setGender(to,hide)
	{
	if (to == 1) to = "m";
	else if (to == 2) to = "f";
	var gval = {"m":1,"f":2};
	var g = $("#regForm [name='gender']");
	if (typeof(global_custom_radio_controller) != "undefined" && global_custom_radio_controller && typeof(global_custom_radio_controller.setState) == "function")
		{
		global_custom_radio_controller.setState(to);
		}
	else if (g.attr("type") == "radio")
		{
		for (var i=0;i<g.length;i++)
			{
			if (g[i].value == gval[to]) $(g[i]).click();
			}
		}
	else
		{
		g.val(gval[to]);
		genderOnChange(g[0]);
		}
	if (hide) $("#gender").css("display","none");
	}

function insertQueryStringVarsIntoRegForm()
	{
	var rf = $("#regForm");
	var names = "firstName|lastName|searchFirstName|searchLastName|";
	var ages = "age|searchAge|";
	for (var k in $_GET)
		{
		if ($_GET[k])
			{
			var val = $_GET[k];
			if (names.indexOf(k+"|") != -1) val = fixName(val);
			else if (ages.indexOf(k+"|") != -1) val = fixAge(val);
			if (val)
				{
				var jelm = $("[name='"+k+"']",rf);
				if (k == "gender") setGender(val);
				else jelm.val(val);
				}
			}
		}
	}

$(function()
	{
	applyFormEventHandlers();
	regFormOnEnterForIE();
	qa_ids();
	insertQueryStringVarsIntoRegForm();
	if (typeof(activateVisitHistory) == "function") activateVisitHistory();
	});

var display_result = {
	max_thumbs:4,
	max_states:12,
	max_cities:5,
	list_delimiter:", ",
	list_trail:"<em>and more...</em>"
	};

function loadTeaser(fn,ln)
	{
	if (fn && ln && fn != "null" && ln != "null")
		{
		ps_info = {};
		ps_info.first_name = (fn.substr(0,1)).toUpperCase()+fn.substr(1);
		ps_info.last_name = (ln.substr(0,1)).toUpperCase()+ln.substr(1);
		ps_info.full_name = ps_info.first_name+" "+ps_info.last_name;
		$.get("/PS/ps_api.php",{searchFirstName:fn,searchLastName:ln},handlePSRequest);
		$("#search_section").css("display","none");
		$("#results_section").css("display","block");
		}
	}
				
function handlePSRequest(data)
	{	
	ps_info.result = eval("("+data+")");
	
	var results_header = $("#results .results_header");
	var photos_row = $("#photos_row");
	var livesin_row = $("#livesin_row");
	var states_module = $("#results_states");
	var cities_module = $("#results_cities");
	
	if (ps_info.result.count) results_header.html("We found <em>"+ps_info.result.count+"</em> "+(ps_info.result.count == 1 ? "result" : "results")+" for <em>"+ps_info.full_name+"</em>");
	else results_header.html("Register to find everyone named <strong>"+ps_info.full_name+"</strong>");
	
	var has_enough_thumbs = psinfo_hasAtLeast(1,"thumbnails or pictures");
	var has_enough_states = psinfo_hasAtLeast(1,"states");
	var has_enough_cities = psinfo_hasAtLeast(1,"cities");
	
	if (has_enough_thumbs)
		{
		var thumbs_to_display = new Array();
		for (var i=0;thumbs_to_display.length<=display_result.max_thumbs&&i<ps_info.result.items.length;i++)
			{
			if (ps_info.result.items[i].thumb_url || ps_info.result.items[i].picture_url) thumbs_to_display.push(ps_info.result.items[i].thumb_url || ps_info.result.items[i].picture_url);
			}
		var thumbs_html = "";
		for (var i=0;i<thumbs_to_display.length;i++) thumbs_html += '<div class="thumb"><img src="'+thumbs_to_display[i]+'" alt="'+ps_info.full_name+'" /></div>';
		$(".data",photos_row).html(thumbs_html);
		}
	else photos_row.css("display","none");
	
	if (has_enough_states && has_enough_cities)
		{
		if (has_enough_states)
			{
			var states_to_display = new Array();
			for (var i=0;states_to_display.length<=display_result.max_states&&i<ps_info.result.items.length;i++)
				{
				if (ps_info.result.items[i].state && !arrayContains(states_to_display,ps_info.result.items[i].state)) states_to_display.push(ps_info.result.items[i].state);
				}
			states_to_display.push(display_result.list_trail);
			$(".data",states_module).html(states_to_display.join(display_result.list_delimiter));			
			}
		else states_module.css("display","none");
		if (has_enough_cities)
			{
			var cities_to_display = new Array();
			for (var i=0;cities_to_display.length<=display_result.max_cities&&i<ps_info.result.items.length;i++)
				{
				if (ps_info.result.items[i].city && !arrayContains(cities_to_display,ps_info.result.items[i].city)) cities_to_display.push(ps_info.result.items[i].city);
				}
			cities_to_display.push(display_result.list_trail);
			$(".data",cities_module).html(cities_to_display.join(display_result.list_delimiter));	
			}
		else cities_module.css("display","none");
		}
	else livesin_row.css("display","none");
	
	if ($.browser.msie && $.browser.version < 7)
		{
		$("#results_loading").fadeOut(300,function()
			{
			$("#results").slideDown(300);
			});		
		}
	else
		{
		$("#results_loading").fadeOut(300,function()
			{
			$("#results").fadeIn(300);
			});
		}
	}

function psinfo_hasAtLeast(num,ofwhat)
	{
	var num_has = 0;
	if (ps_info.result && ps_info.result.items)
		{
		for (var i=0;i<ps_info.result.items.length;i++)
			{
			if (ofwhat.indexOf("cities") != -1 && ps_info.result.items[i].city) {num_has++;continue;}
			if (ofwhat.indexOf("states") != -1 && ps_info.result.items[i].state) {num_has++;continue;}
			if (ofwhat.indexOf("locations") != -1 && ps_info.result.items[i].location) {num_has++;continue;}
			if (ofwhat.indexOf("thumbnails") != -1 && ps_info.result.items[i].thumb_url) {num_has++;continue;}
			if (ofwhat.indexOf("pictures") != -1 && ps_info.result.items[i].picture_url) {num_has++;continue;}
			//if (num_has >= num) return true;
			}
		}
	return num_has >= num;
	}

function arrayContains(arr,what)
	{
	for (var i=0;i<arr.length;i++)
		{
		if (arr[i] === what) return true;
		}
	return false;	
	}

function launchItNow(fn,ln,a)
	{
	var ok_to_launch = true;
	
	var tform = document.getElementById("psForm");

	fn = fixName(fn);
	ln = fixName(ln);
	a = fixAge(a);
	
	if (fn && ln && !a) a = "33";
	
	if (fn) tform.searchFirstName.value = fn;
	else ok_to_launch = false;
	if (ln) tform.searchLastName.value = ln;
	else ok_to_launch = false;
	if (a) tform.searchAge.value = a;

	if (ok_to_launch) submitPS(tform);
	else
		{
		if (!a) {try{tform.searchAge.focus()} catch(e){}};
		if (!ln) {try{tform.searchLastName.focus()} catch(e){}};
		if (!fn) {try{tform.searchFirstName.focus()} catch(e){}};	
		}
	}

function submitPS()
	{
	var tform = document.getElementById("psForm");
	if (psOnSubmit())
		{
		var fn = tform.searchFirstName.value;
		var ln = tform.searchLastName.value;
		var a = tform.searchAge.value || false;
		fn = fixName(fn);
		ln = fixName(ln);
		a = fixAge(a);
		loadTeaser(fn,ln);
		var rform = document.getElementById("regForm");
		if (rform.searchFirstName) rform.searchFirstName.value = fn;
		if (rform.searchLastName) rform.searchLastName.value = ln;
		if (rform.searchAge) rform.searchAge.value = a;

		$("#welcome_name").html("Register Now to See Detailed Results for <b>" + fn + " " + ln + "</b>");
		$("#search_section").hide();
		$("#results_section").show();
		$("#teaser_title").hide();
		$("#teaser_title").fadeIn(100);
		$("#regForm [name='firstName']").focus();
		
		fireRegOpenedPixel();
		}
	return false;
	}

function fireRegOpenedPixel()
	{
	if (typeof(global_regopenedpx) == "undefined")
		{
		var px = new Image();
		px.src = "http://r.casalemedia.com/j.gif?u=123830&s=2";
		global_regopenedpx = true;
		}
	}

function loadWSFYTeaser(fn,ln,a)
	{
	a = a || 37;
	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);
		}
	}

function handleWSFYRequest(data)
	{
	var delay = 2000;
	var result_obj = eval("("+data+")");
	wsfy_info.result = result_obj.wsfy;
	var tc = wsfy_info.result.totalCount || 0;
	if (tc)
		{
		var tspot = document.getElementById("teaser_info");
		tspot.getElementsByTagName("h4")[0].innerHTML = 'Searching ...';
		tspot.getElementsByTagName("ul")[0].innerHTML = '<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 = document.getElementById("teaser_info");
			var title = tspot.getElementsByTagName("h4")[0];
			var list = tspot.getElementsByTagName("ul")[0];
			tspot.getElementsByTagName("h5")[0].innerHTML = 'Fill out this form and find out who they are!';
			list.innerHTML = "";
			title.innerHTML = "<strong>"+tc+"</strong> "+(tc>1?"people are":"person is")+" searching for &quot;"+wsfy_info.full_name+"&quot;";
			var li;
			if (wsfy_info.result.numFemales)
				{
				li = document.createElement("li");
				li.innerHTML = "<strong>"+wsfy_info.result.numFemales+"</strong> "+(wsfy_info.result.numFemales == 1 ? "is" : "are")+" female";
				list.appendChild(li);
				}
			if (wsfy_info.result.numMales)
				{
				li = document.createElement("li");
				li.innerHTML = "<strong>"+wsfy_info.result.numMales+"</strong> "+(wsfy_info.result.numMales == 1 ? "is" : "are")+" male";
				list.appendChild(li);
				}
			if (wsfy_info.result.numSearchedInLastWeek)
				{
				li = document.createElement("li");
				li.innerHTML = "<strong>"+wsfy_info.result.numSearchedInLastWeek+"</strong> "+(wsfy_info.result.numSearchedInLastWeek == 1 ? "has" : "have")+" searched in the last week";
				list.appendChild(li);
				}
			}
		if (typeof(wsfy_teaser_timeout) != "undefined") clearTimeout(wsfy_teaser_timeout);
		wsfy_teaser_timeout = setTimeout("handleWSFYRequest_postdelay()",delay);
		}
	}

function checkForWSFYTease()
	{
	var rform = document.getElementById("regForm");
	var fn = rform.firstName.value || "";
	var ln = rform.lastName.value || "";
	var a = 37;
	if (fn && ln) loadWSFYTeaser(fn,ln,a);
	}

$(document).ready(function()
	{
	launchItNow($_GET["searchFirstName"] || "",$_GET["searchLastName"] || "",$_GET["searchAge"] || "");
	}
);