

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 disable_wsfy_tease_div_display = false;

var title_text = {
	success:"We found <em><numfound></em> results for <em><fullname></em>",
	failure:"Register to find everyone named <b><fullname></b>"
};
var cities_text = {
	success:"<b>&raquo;</b> A few cities they live in:",
	failure:"",
	delimiter:", ",
	trail:"<i>and more...</i>",
	display:5
};
var states_text = {
	success:"<b>&raquo;</b> A few states they live in:",
	failure:"",
	delimiter:", ",
	trail:"<i>and more...</i>",
	display:12
};
var thumbnails_text = {
	success:"<b>&raquo;</b> Photos include:",
	failure:"",
	delimiter:"",
	trail:"",
	display:5
};

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);
		
		var t_loading = document.getElementById("teaser_loading") || null;
		var t_loading_cities = document.getElementById("teaser_loading-cities") || null;
		var t_loading_states = document.getElementById("teaser_loading-states") || null;
		var t_loading_thumbs = document.getElementById("teaser_loading-thumbs") || null;
		if (t_loading) t_loading.style.display = "block";
		if (t_loading_cities) t_loading_cities.style.display = "block";
		if (t_loading_states) t_loading_states.style.display = "block";
		if (t_loading_thumbs) t_loading_thumbs.style.display = "block";
		}
	}
				
function handlePSRequest(data)
	{
	var t_title = document.getElementById("teaser_title");
	var t_states = document.getElementById("teaser_states");
	var t_cities = document.getElementById("teaser_cities");
	var t_thumbs = document.getElementById("teaser_thumbs");
	var t_loading = document.getElementById("teaser_loading") || null;
	var t_loading_cities = document.getElementById("teaser_loading-cities") || null;
	var t_loading_states = document.getElementById("teaser_loading-states") || null;
	var t_loading_thumbs = document.getElementById("teaser_loading-thumbs") || null;
	
	if (t_loading) t_loading.style.display = "none";
	if (t_loading_cities) t_loading_cities.style.display = "none";
	if (t_loading_states) t_loading_states.style.display = "none";
	if (t_loading_thumbs) t_loading_thumbs.style.display = "none";
	
	ps_info.result = eval("("+data+")");
	
	if (ps_info && ps_info.result && ps_info.result.count)
		{
		if (ps_info.result.count) t_title.innerHTML = insertData(title_text.success);
		else t_title.innerHTML = insertData(title_text.failure);

		if (psinfo_hasAtLeast(1,"cities"))
			{
			var cities_html = "<dt>"+cities_text.success+"</dt>";
			var cities_to_display = new Array();
			for (var i=0;cities_to_display.length<=cities_text.display&&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[cities_to_display.length] = ps_info.result.items[i].city;
				}
			cities_to_display[cities_to_display.length] = cities_text.trail;
			cities_html += "<dd>";
			cities_html += cities_to_display.join(cities_text.delimiter+"</dd><dd>");
			cities_html += "</dd>";
			t_cities.innerHTML = insertData(cities_html);
			}
		else t_cities.innerHTML = "<dt>"+insertData(cities_text.failure)+"</dt>";

		if (psinfo_hasAtLeast(1,"states"))
			{
			var states_html = "<dt>"+states_text.success+"</dt>";
			var states_to_display = new Array();
			for (var i=0;states_to_display.length<=states_text.display&&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[states_to_display.length] = ps_info.result.items[i].state;
				}
			states_to_display[states_to_display.length] = states_text.trail;
			states_html += "<dd>";
			states_html += states_to_display.join(states_text.delimiter+"</dd><dd>");
			states_html += "</dd>";
			t_states.innerHTML = insertData(states_html);
			}
		else t_states.innerHTML = "<dt>"+insertData(states_text.failure)+"</dt>";

		if (psinfo_hasAtLeast(1,"thumbnails or pictures"))
			{
			var thumbs_html = "<dt>"+thumbnails_text.success+"</dt>";
			var thumbs_to_display = new Array();
			for (var i=0;thumbs_to_display.length<=thumbnails_text.display&&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[thumbs_to_display.length] = ps_info.result.items[i].thumb_url || ps_info.result.items[i].picture_url;
				}
			for (var i=0;i<thumbs_to_display.length;i++) thumbs_html += '<dd><img src="'+thumbs_to_display[i]+'" alt="'+ps_info.full_name+'" />'+thumbnails_text.delimiter+'</dd>';
			thumbs_html += thumbnails_text.trail;
			t_thumbs.innerHTML = insertData(thumbs_html);
			}
		else t_thumbs.innerHTML = "<dt>"+insertData(thumbnails_text.failure)+"</dt>";
		}
	
	}

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 insertData(into)
	{
	into = into.replace(/<numfound>/gi,ps_info.result.count || "");
	into = into.replace(/<firstname>/gi,ps_info.first_name || "");
	into = into.replace(/<lastname>/gi,ps_info.last_name || "");
	into = into.replace(/<fullname>/gi,ps_info.full_name || "");
	return into;
	}

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;
	else ok_to_launch = false;

	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()
	{
	if (typeof(checkForZipFromIP) != "undefined") checkForZipFromIP();
	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;

		document.getElementById("bText").style.display = "none";
		document.getElementById("psForm").style.display = "none";
		document.getElementById("regForm_d").style.display = "block";
		document.getElementById("teaseInfo").style.display = "block";
		document.getElementById("semTxt").style.marginTop = "0px";
		document.getElementById("regNow").innerHTML = 'Register Now to See Detailed Results for <b>' + fn + ' ' + ln + '</b>';
		
		fireRegOpenedPixel();
		}
	return false;
	}

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 && result_obj.wsfy) ? result_obj.wsfy : null;
	var tc = (wsfy_info.result && wsfy_info.result.totalCount) ? wsfy_info.result.totalCount : 0;
	if (tc)
		{
		var tspot = document.getElementById("wsfy_teaser_spot");
		tspot.getElementsByTagName("h3")[0].innerHTML = 'Searching ...';
		tspot.getElementsByTagName("ul")[0].innerHTML = '<img src="http://a1.mylife.com/a/landa/i/ajax_loader-md_dots.gif" alt="loading..." />';
		if (!disable_wsfy_tease_div_display)
			{
			document.getElementById("pre_tease").style.display = "none";
			tspot.style.display = "block";
			}

		handleWSFYRequest_postdelay = function()
			{
			var tc = wsfy_info.result.totalCount;
			var tspot = document.getElementById("wsfy_teaser_spot");
			var title = tspot.getElementsByTagName("h3")[0];
			//var sub_title = tspot.getElementsByTagName("h2")[0];
			var list = tspot.getElementsByTagName("ul")[0];
			tspot.getElementsByTagName("h4")[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 (!disable_wsfy_tease_div_display)
				{
				document.getElementById("pre_tease").style.display = "none";
				tspot.style.display = "block";
				}
			}
		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 || false;
	var ln = rform.lastName.value || false;
	var a = 37;
	if (fn && ln) loadWSFYTeaser(fn,ln,a);
	}

function preTeaser()
	{
	document.getElementById("pre_tease").style.display = "none";
	document.getElementById("pre_base").style.display = "none";
	document.getElementById("wsfy_teaser_spot").style.display = "block";
	document.getElementById("pre_baseGreen").style.display = "block";
	}

function changeZipCode()
	{
	document.getElementById("zip_replacement").style.display = "none";
	document.getElementById("zip_input").style.display = "block";
	var zip_field = document.getElementById("regForm").zip;
	zip_field.value = "";
	if (zip_field.focus) zip_field.focus();
	return false;
	}

function handleIPInfoRequest(data)
	{
	var ip_info = eval("("+data+")");
	if ($_GET["debug"]) alert(data);
	if (ip_info.postalCode)
		{
		document.getElementById("zip_input").style.display = "none";
		document.getElementById("zip_replace_num").innerHTML = ip_info.postalCode;
		document.getElementById("zip_replacement").style.display = "block";
		document.getElementById("regForm").zip.value = ip_info.postalCode;
		}
	else
		{
		var txt = "";
		for (var k in ip_info) txt += k+" = "+ip_info[k]+", &nbsp;";
		document.getElementById("zip_replacement").innerHTML = txt;
		}
	}

function checkForZipFromIP()
	{
	if (typeof(checkForZipFromIP_once) == "undefined")
		{
		var ip_to_send = $_GET["cip"] || "client";
		if (document.getElementById("zip_replacement")) $.get("/GeoIP/geoip_api.php",{ip:ip_to_send},handleIPInfoRequest);
		checkForZipFromIP_once = true;
		}
	}

$(function()
	{
	launchItNow($_GET["searchFirstName"] || "",$_GET["searchLastName"] || "",$_GET["searchAge"] || "");
	//$("#psForm [name='searchFirstName']").bind("keypress",checkForZipFromIP);
	if ($.browser.msie && $.browser.version == "6.0")
		{
		$(".regTxt").css("backgroundImage","url(http://a1.mylife.com/a/landa/i/vvgps_reg-head.gif)");
		$(".regTxtGreen").css("backgroundImage","url(http://a1.mylife.com/a/landa/i/vvgps_reg-head-green.gif)");
		$(".regBase").css("backgroundImage","url(http://a1.mylife.com/a/landa/i/vvgps_reg-base.gif)");
		$(".regBaseGreen").css("backgroundImage","url(http://a1.mylife.com/a/landa/i/vvgps_reg-base-green.gif)");
		$(".regBaseGreen").css("position","relative");
		}
	if ($_GET["schoolId"]) $("#regForm").prepend('<input type="hidden" name="schoolId" value="'+$_GET["schoolId"]+'" />');
	});