﻿function displayWindow(url, width, height) {
	var Win = window.open(url,"displayWindow",'width=' + width + ',height=' + height + ',resizable=no,scrollbars=no,menubar=no,status=no' );
}

function displayScrollWindow(url, width, height) {
	var Win = window.open(url,"displayWindow",'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes,menubar=yes,status=no' );
}
function preloadTabs() {
	var tab1 = new Image(88, 46);
	tab1.src = "pics/tabs/myhome-over.gif";
	var tab2 = new Image(79, 46);
	tab2.src = "pics/tabs/mylifelists-over.gif";
	var tab3 = new Image(79, 46);
	tab3.src = "pics/tabs/myprofile-over.gif";
	var tab4 = new Image(78, 46);
	tab4.src = "pics/tabs/myfavourites-over.gif";
	var tab5 = new Image(78, 46);
	tab5.src = "pics/tabs/mylegacylists-over.gif";
	var tab6 = new Image(80, 46);
	tab6.src = "pics/tabs/mysearch-over.gif";
	var tab7 = new Image(77, 46);
	tab7.src = "pics/tabs/mymessages-over.gif";
}

function addBookmark(title,url) { 
	if (window.sidebar) { 
		window.sidebar.addPanel(title, url,""); 
	} else if( document.all ) { 
		window.external.AddFavorite( url, title); 
	} else if( window.opera && window.print ) { 
		return true; 
	} else {
		alert("Sorry, your browser does not appear to support this function.");
	}
}
function backButtonOverride() {
  // Work around a Safari bug
  // that sometimes produces a blank page
  setTimeout("backButtonOverrideBody()", 1);
}

function backButtonOverrideBody() {
  // Works if we backed up to get here
  try {
    history.forward();
  } catch (e) {
    // OK to ignore
  }
  // Every quarter-second, try again. The only
  // guaranteed method for Opera, Firefox,
  // and Safari, which don't always call
  // onLoad but *do* resume any timers when
  // returning to a page
  setTimeout("backButtonOverrideBody()", 500);
}

function resizeWindow(width, height) {
	window.outerWidth = width
	window.outerHeight = height
}

function gotoAnchor(anchor) {
	window.location.hash = anchor
}

function getXmlHttpRequest() {
	var xmlHttpObj;
	if (window.XMLHttpRequest) {
		xmlHttpObj = new XMLHttpRequest();
	} else {
		try {
			xmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try {
				xmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				xmlHttpObj = false;
			}
		}
	}
	return xmlHttpObj;
}

var xhr = new Array(); // ARRAY OF XML-HTTP REQUESTS
var xi = new Array(0); // ARRAY OF XML-HTTP REQUEST INDEXES
xi[0] = 1; // FIRST INDEX SET TO 1 MAKING IT AVAILABLE


function xhrRequest(type) {
	if (!type) {
		type = 'html';
	}

	// xhrsend IS THE xi POSITION THAT GETS PASSED BACK
	// INITIALIZED TO THE LENGTH OF THE ARRAY(LAST POSITION + 1)
	// IN CASE A FREE RESOURCE ISN'T FOUND IN THE LOOP
	var xhrsend = xi.length;

	// GO THROUGH AVAILABLE xi VALUES
	for (var i=0; i<xi.length; i++) {

		// IF IT'S 1 (AVAILABLE), ALLOCATE IT FOR USE AND BREAK
		if (xi[i] == 1) {
			xi[i] = 0;
			xhrsend = i;
			break;
		}
	}

	// SET TO 0 SINCE IT'S NOW ALLOCATED FOR USE
	xi[xhrsend] = 0;

	// SET UP THE REQUEST
	if (window.XMLHttpRequest) {
		xhr[xhrsend] = new XMLHttpRequest();
		if (xhr[xhrsend].overrideMimeType) {
			xhr[xhrsend].overrideMimeType('text/' + type);
		}
	} else if (window.ActiveXObject) {
		try {
			xhr[xhrsend] = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xhr[xhrsend] = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	return (xhrsend);
}

var xmlhttp;
var xmlhttp2;
var xmlhttp3;
var ajaxObj = new Object();
var this_id;
var this_user_id;
var f_user_id;
var this_type;
var max_no;

function InsertMovie(my_classid, my_height, my_width, my_src, my_autoplay, my_controller) {
	document.write("<object classid=\"" + my_classid + "\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\" height=\"" + my_height + "\" width=\"" + my_width + "\">\n");
	document.write("<param name=\"src\" value=\"" + my_src + "\" />\n");
	document.write("<param name=\"autoplay\" value=\"" + my_autoplay + "\" />\n");
	document.write("<param name=\"controller\" value=\"" + my_controller + "\" />\n");
	document.write("<object type=\"video/quicktime\" data=\"" + my_src + "\" width=\"" + my_width + "\" height=\"" + my_height + "\">\n");
    document.write("<param name=\"autoplay\" value=\"" + my_autoplay + "\" />\n");
    document.write("<param name=\"controller\" value=\"" + my_controller + "\" />\n");
    document.write("</object>");
	document.write("</object>");
}

function findPos() {
	var curleft = curtop = 0;
	if (findPosObj.offsetParent) {
		curleft = findPosObj.offsetLeft
		curtop = findPosObj.offsetTop
		while (findPosObj = findPosObj.offsetParent) {
			curleft += findPosObj.offsetLeft
			curtop += findPosObj.offsetTop
		}
	}
	return [curleft,curtop];
}

function refresh_search_page(user_id,q_string) {
	this_user_id = user_id;
	//alert("user_id = " + this_user_id);
	//target_window = target;
	q_string = q_string.substring(1,(q_string.length));
	//alert("q_string = " + q_string);
	var xhri = xhrRequest('html');
	var qry = 'js=yes&user_id=' + this_user_id + '&' + q_string;
	//alert("qry = " + qry);
	var url = 'mysearch/search_content.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				theElementId = "search_content";
				elementToShow = document.getElementById(theElementId);
				//alert("update page");
				elementToShow.innerHTML = xhr[xhri].responseText;
				//alert("done");
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
					//alert(alertStr);
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
					//alert(alertStr);
				}
			}
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function print_search_page() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		var theElementId = 'search_content';
		var elementToShow = document.getElementById(theElementId);
		elementToShow.innerHTML = xmlhttp.responseText;
	} else {
		try {
			var alertStr = "xmlhttp.readyState=" + xmlhttp.readyState + " xmlhttp.status=" + xmlhttp.status;
			//alert(alertStr);
		}
		catch (e) {
			var alertStr = "error getting xmlhttp.readyState and xmlhttp.status";
			//alert(alertStr);
		}
	}
}

function add_me2(user_id,selected_list_id,selected_item_id,selected_list_owner_id,selected_cat_id) {
	this_user_id = user_id;
	var this_selected_list_id = selected_list_id;
	this_selected_item_id = selected_item_id;
	var this_selected_list_owner_id = selected_list_owner_id;
	var this_selected_cat_id = selected_cat_id;
	var this_image_name = "addme2but_" + selected_item_id;
	var this_element_id = "row_" + selected_item_id;
	q_string = window.location.search;
	//if ((q_string.substring(0,1)) == "?") {
	//	q_string = q_string.substring(1);
	//}
	show_floating_box(this_element_id,'350');
	var xhri = xhrRequest('html');
	var qry = 'js=yes&user_id=' + this_user_id + '&selected_list_id=' + this_selected_list_id + '&selected_item_id=' + this_selected_item_id + '&selected_list_owner_id=' + this_selected_list_owner_id + '&selected_cat_id=' + this_selected_cat_id;
	var url = 'me2js.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
					var theElementId = "floating_box";
					var elementToShow = document.getElementById(theElementId);
					elementToShow.innerHTML = xhr[xhri].responseText;
					//alert("refresh: "+this_user_id+", "+q_string);
					refresh_search_page(this_user_id,q_string);
					document.myform.mybutton.select();
					document.myform.mybutton.focus();
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
					//alert(alertStr);
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
					//alert(alertStr);
				}
			}
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
	//xi[xhri] = 1;
	//xhr[xhri] = null;
}

function print_add_me2() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		var theElementId = 'floating_box';
		var elementToShow = document.getElementById(theElementId);
		elementToShow.innerHTML = xmlhttp.responseText;
		refresh_search_page(user_id,target,q_string)
	} else {
		try {
			var alertStr = "xmlhttp.readyState=" + xmlhttp.readyState + " xmlhttp.status=" + xmlhttp.status;
			//alert(alertStr);
		}
		catch (e) {
			var alertStr = "error getting xmlhttp.readyState and xmlhttp.status";
			//alert(alertStr);
		}
	}
}

function refresh_row(this_selected_item_id) {
	var theElementId = "row_" + this_selected_item_id;
	var elementToChange = document.getElementById(theElementId);
	elementToChange.innerHTML = "updating row...";
}

function toggleFavWatch(user_id,fav_id,action) {
	var watchElement = 'fav_watch_' + fav_id;
	var imageToSwitch = document.getElementById(watchElement);
	imageToSwitch.src = "pics/general/busy.gif";
	imageToSwitch.title = "updating...";
	var xhri = xhrRequest('html');
	var qry = 'js=yes&user_id=' + user_id + '&fav_id=' + fav_id + '&action=' + action;
	var url = 'myhome/toggle_fav_watch.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				if (action == "watch") {
					imageToSwitch.src = "pics/myfavourites/watch-on.gif";
					imageToSwitch.title = "stop watching this list";
					document.getElementById("fav_watch_href_" + fav_id).href = "javascript:toggleFavWatch(" + user_id + "," + fav_id + ",'unwatch')";
				} else {
					imageToSwitch.src = "pics/myfavourites/watch-off.gif";
					imageToSwitch.title = "watch this list";
					document.getElementById("fav_watch_href_" + fav_id).href = "javascript:toggleFavWatch(" + user_id + "," + fav_id + ",'watch')";
				}
				xi[xhri] = 1;
 				xhr[xhri] = null;
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
				//alert(alertStr);
			}
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function deleteFav(user_id,fav_id) {
	var watchElement = 'delete_fav_' + fav_id;
	var imageToSwitch = document.getElementById(watchElement);
	imageToSwitch.src = "pics/general/busy.gif";
	imageToSwitch.title = "updating...";
	var xhri = xhrRequest('html');
	var qry = 'js=yes&user_id=' + user_id + '&fav_id=' + fav_id;
	var url = 'myhome/delete_fav.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				mh_show(user_id,'fa','auto')
				// update fa head
				// set up query and url
				var qry = 'js=yes&user_id=' + user_id;
				var url = 'myhome/fa_head.php';
				// handle ajax object
				var xhri3 = xhrRequest('html');
				xhr[xhri3].open('POST', url, true);
				xhr[xhri3].onreadystatechange = function () {
						if (xhr[xhri3].readyState == 4 && xhr[xhri3].status == 200) {
							var myElement = 'mh_user_summary_fa_head';
							var elementToShow = document.getElementById(myElement);
							//alert(xhr[xhri3].responseText);
							elementToShow.innerHTML = "";
							elementToShow.innerHTML = xhr[xhri3].responseText;
							xi[xhri3] = 1;
 							xhr[xhri3] = null;
						} else {
							try {
								var alertStr = "xhr[xhri3].readyState=" + xhr[xhri3].readyState + " xhr[xhri3].status=" + xhr[xhri3].status;
							}
							catch (e) {
								var alertStr = "error getting xhr[xhri3].readyState and xhr[xhri3].status";
							}
							//alert(alertStr);
						}
					};
				xhr[xhri3].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				xhr[xhri3].send(qry);
				xi[xhri] = 1;
 				xhr[xhri] = null;
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
				//alert(alertStr);
			}
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function show_floating_box(this_element,my_width) {
	if (my_width == "auto") {
		xmy_width = "350";
	} else {
		xmy_width = my_width;
	}
	var myElement = 'page_frame';
	var elementToShow = document.getElementById(myElement);
	set_opacity(elementToShow,.5);
	myElement = 'floating_box';
	elementToShow = document.getElementById(myElement);
	elementToShow.style.visibility = 'visible';
	elementToShow.style.width = my_width + 'px';
	if ((my_width == "auto") || (my_width <= "550px")) {
		elementToShow.style.maxWidth = "550px";
	}
	elementToShow.style.height = 'auto';
	var w_margin = (Geometry.getViewportWidth() - xmy_width) / 2;
	elementToShow.style.left = w_margin + 'px';
	elementToShow.style.right = w_margin + 'px';
	var t_margin = Geometry.getVerticalScroll() + 150;
	elementToShow.style.top = t_margin + 'px';
	elementToShow.innerHTML = floating_box_wait_content();
}

function floating_box_wait_content() {
	var output = fb_close_link();
	output += "<div align=\"center\"><span class=\"brownnamehead\">\n";
	output += "<img src=\"pics/general/mylifelistslogo200.gif\" /><br>\n";
	output += "<img src=\"pics/general/busy.gif\" alt=\"working...\" title=\"working...\" /> Loading, please wait...<br>\n";
	output += "</span></div>\n";
	return output;
}

function fb_close_link() {
	var output = "<div align=\"right\">\n";
	output += "<a href=\"javascript:close_floating_box()\"><span class=\"instruction\">Close</span> <img src=\"pics/general/close_box.gif\" align=\"top\" alt=\"close window\" title=\"close window\" /></a><br\n";
	output += "</div>\n";
	return output;
}

function printFloatingBox() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		var theElementId = 'floating_box';
		var elementToShow = document.getElementById(theElementId);
		elementToShow.innerHTML = xmlhttp.responseText;
		//if ((typeof(my_focus) != "undefined") && (my_focus == true)) {
		//if ((typeof(action) != "undefined") && (action == "send_message")) {
		//if (typeof(document.myform.mybutton) != "undefined") {
		//	document.myform.mybutton.focus();
		//	document.myform.mybutton.select();
		//}
	} else {
		try {
			var alertStr = "xmlhttp.readyState=" + xmlhttp.readyState + " xmlhttp.status=" + xmlhttp.status;
		}
		catch (e) {
			var alertStr = "error getting xmlhttp.readyState and xmlhttp.status";
		}
	}
}

function close_floating_box() {
	var myElement = 'floating_box';
	var elementToShow = document.getElementById(myElement);
	elementToShow.innerHTML = "";
	elementToShow.style.visibility = 'hidden';
	myElement = 'page_frame';
	elementToShow = document.getElementById(myElement);
	set_opacity(elementToShow,1);
	//alert("if");
	//if (typeof(this_form) != "undefined") {
	//	alert("doing if");
	//	this_form.submit.disabled = false;
	//	alert("end doing if");
	//}
	//alert("end if");
}

function set_opacity(obj,val) {
	obj.style.opacity = val;
	obj.style.MozOpacity = val;
	obj.style.KhtmlOpacity = val;
	val *= 100;
	obj.style.filter = "alpha(opacity=" + val + ")";
}

function wait(msecs) {
	var start = new Date().getTime();
	var cur = start
	while (cur - start < msecs) {
		cur = new Date().getTime();
	}
}

function start_login(this_element,my_width) {
	if (navigator.userAgent.search(/Safari/) != -1) {
		window.location = "index.php";
		return;
	} else {
		show_floating_box(this_element,my_width)
		var myElement = 'floating_box';
		var elementToShow = document.getElementById(myElement);
		var output = fb_close_link();
		output += login_form();
		elementToShow.innerHTML = output;
		if (document.getElementById('login_form')) {
			document.getElementById('login_form').innerHTML = '';
		}
	}
}

function login_form() {
	var output = "<form id='login_fb' name='login_fb' onsubmit='do_login(); return false;'><input type='hidden' name='login_form_js' value='yes'><span class='brownbodynoindent'>Email&nbsp;<input class='brownbodynoindent' type='text' name='email' />&nbsp;Password&nbsp;<input class='brownbodynoindent' type='password' name='password' />&nbsp;&nbsp;<input class='brownbodynoindent' type='submit' name='submit' value='Login' /></span><a href='javascript:start_pw_recover();'><span class='brownbodynoindent'>&nbsp;Forgotten&nbsp;password?</span></a><br /><span class='brownbodynoindent'><br><input class='brownbodynoindent' type='checkbox' name='remember_me'>Remember me (don't use this on shared computers or in internet cafés etc.)<br><br>Not registered? </span><a href='register.php'><span class='brownbodynoindent'>Click here</span></a><span class='brownbodynoindent'> to create an account</span></form>";
	return output;
}
/*
function do_login() {
	email = document.login_fb.email.value;
	var password = document.login_fb.password.value;
	if (document.login_fb.remember_me.checked) {
		remember_me = 'y';
	} else {
		remember_me = 'n';
	}
	show_floating_box('paper_frame',500);
	if (document.login_fb.login_form_js.value == 'no') {
		document.getElementById('login_form').innerHTML = "";
	}
	var myElement = 'floating_box';
	var elementToShow = document.getElementById(myElement);
	elementToShow.innerHTML = floating_box_wait_content();
	if (!xmlhttp) {
		xmlhttp = getXmlHttpRequest();
	}
	if (!xmlhttp) {
		alert("could not create XmlHttpRequest");
		return;
	}
	var qry = 'action=do_js_login&email=' + email + '&password=' + password + '&remember_me=' + remember_me;
	var url = 'php/do_login.php';
	xmlhttp.open('POST', url, true);
	xmlhttp.onreadystatechange = login_return;
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send(qry);
}
*/
function do_login() {
	//var fwd_location = location.href;
	email = document.login_fb.email.value;
	var password = document.login_fb.password.value;
	if (document.login_fb.remember_me.checked) {
		remember_me = 'y';
	} else {
		remember_me = 'n';
	}
	if ((document.login_fb.login_form_js != null) && (document.login_fb.login_form_js.value == 'no')) {
		document.getElementById('login_form').innerHTML = "";
	}
	show_floating_box('paper_frame',500);
	document.getElementById('floating_box').innerHTML = floating_box_wait_content();
	var xhri = xhrRequest('html');
	var qry = 'action=do_js_login&email=' + email + '&password=' + password + '&remember_me=' + remember_me;
	var url = 'php/do_login.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				if (xhr[xhri].responseText == "login_ok") {
					//window.location = "myhome.php";
					window.location.reload(true);
				} else if (xhr[xhri].responseText.substring(0,11) == "unvalidated") {
					document.getElementById('floating_box').innerHTML = fb_close_link() + "<span class='brownnamehead'>Your registration has not yet been validated.</span><span class='brownbodynoindent'><br><br>You should have received a Welcome email with details of how to validate your registration. Please either check your email account for new messages or <a href=\"javascript:resend_welcome(" + xhr[xhri].responseText.substring(11) + ");\">click here</a> to request another copy of your Welcome email.</span>";
				} else if (xhr[xhri].responseText == "bad_pw") {
					var output = fb_close_link();
					output += "<span class='brownnamehead'>Sorry, your password is not recognised (maybe you mis-typed?), please try again:</span><span class='brownbodynoindent'><br>(Password problems? </span><a href='pw_recover.php'><span class='brownbodynoindent'>Click here</span></a><span class='brownbodynoindent'> to reset your password.)</span><br><br>";
					output += login_form();
					document.getElementById('floating_box').innerHTML = output;
				} else if (xhr[xhri].responseText == "bad_email") {
					var output = fb_close_link();
					output += "<span class='brownnamehead'>Sorry, your email address is not recognised (maybe you mis-typed?), please try again:</span><span class='brownbodynoindent'><br><br></span>";
					output += login_form();
					document.getElementById('floating_box').innerHTML = output;
				} else if (xhr[xhri].responseText == "resend_welcome_good") {
					document.getElementById('floating_box').innerHTML = fb_close_link() + "<span class=\"brownnamehead\">Your Welcome email has been resent to " + email + ".</span><span class=\"brownbodynoindent\"><br><br>You should soon receive your Welcome email with details of how to validate your registration. Please check your email account and follow the instructions before you try to log in again. </span><a href=\"contact.php\"><span class=\"brownbodynoindent\">Click here</span></a><span class=\"brownbodynoindent\"> to contact us if you are still having difficulties.</span>";
				} else if (xhr[xhri].responseText == "resend_welcome_bad") {
					document.getElementById('floating_box').innerHTML = fb_close_link() + "Sorry, there was a problem resending your Welcome email (maybe the mailserver is down). Please refresh and try again.";
				} else {
					document.getElementById('floating_box').innerHTML = fb_close_link() + "Sorry, there was a problem logging in. Please refresh and try again.<br><br>(unrecognised output: " + xhr[xhri].responseText;
				}
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
				//alert(alertStr);
			}
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
	return false;
}

function login_return() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		var theElementId = 'floating_box';
		var elementToShow = document.getElementById(theElementId);
		if (xmlhttp.responseText == "login_ok") {
			window.location = "myhome.php";
		} else if (xmlhttp.responseText.substring(0,11) == "unvalidated") {
			elementToShow.innerHTML = fb_close_link() + "<span class='brownnamehead'>Your registration has not yet been validated.</span><span class='brownbodynoindent'><br><br>You should have received a Welcome email with details of how to validate your registration. Please either check your email account for new messages or <a href=\"javascript:resend_welcome(" + xmlhttp.responseText.substring(11) + ");\">click here</a> to request another copy of your Welcome email.</span>";
		} else if (xmlhttp.responseText == "bad_pw") {
			var output = fb_close_link();
			output += "<span class='brownnamehead'>Sorry, your password is not recognised (maybe you mis-typed?), please try again:</span><span class='brownbodynoindent'><br>(Password problems? </span><a href='pw_recover.php'><span class='brownbodynoindent'>Click here</span></a><span class='brownbodynoindent'> to reset your password.)</span><br><br>";
			output += login_form();
			elementToShow.innerHTML = output;
		} else if (xmlhttp.responseText == "bad_email") {
			var output = fb_close_link();
			output += "<span class='brownnamehead'>Sorry, your email address is not recognised (maybe you mis-typed?), please try again:</span><span class='brownbodynoindent'><br><br></span>";
			output += login_form();
			elementToShow.innerHTML = output;
		} else if (xmlhttp.responseText == "resend_welcome_good") {
			elementToShow.innerHTML = fb_close_link() + "<span class=\"brownnamehead\">Your Welcome email has been resent to " + email + ".</span><span class=\"brownbodynoindent\"><br><br>You should soon receive your Welcome email with details of how to validate your registration. Please check your email account and follow the instructions before you try to log in again. </span><a href=\"contact.php\"><span class=\"brownbodynoindent\">Click here</span></a><span class=\"brownbodynoindent\"> to contact us if you are still having difficulties.</span>";
		} else if (xmlhttp.responseText == "resend_welcome_bad") {
			elementToShow.innerHTML = fb_close_link() + "Sorry, there was a problem resending your Welcome email (maybe the mailserver is down). Please refresh and try again.";
		} else {
			elementToShow.innerHTML = fb_close_link() + "Sorry, there was a problem logging in. Please refresh and try again.<br><br>(unrecognised output: " + xmlhttp.responseText;
		}
	} else {
		try {
			var alertStr = "xmlhttp.readyState=" + xmlhttp.readyState + " xmlhttp.status=" + xmlhttp.status;
		}
		catch (e) {
			var alertStr = "error getting xmlhttp.readyState and xmlhttp.status";
		}
	}
}

function resend_welcome(user_id) {
	var myElement = 'floating_box';
	var elementToShow = document.getElementById(myElement);
	elementToShow.innerHTML = floating_box_wait_content();
	if (!xmlhttp) {
		xmlhttp = getXmlHttpRequest();
	}
	if (!xmlhttp) {
		alert("could not create XmlHttpRequest");
		return;
	}
	var qry = "action=do_js_login&user_id=" + user_id;
	var url = 'php/resend_welcome.php';
	xmlhttp.open('POST', url, true);
	xmlhttp.onreadystatechange = login_return;
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send(qry);
}

function start_pw_recover() {
	show_floating_box('null',500)
	var qry = 'js=yes';
	var xhri = xhrRequest('html');
	var url = 'pw_recover.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				var myElement = 'floating_box';
				var elementToShow = document.getElementById(myElement);
				elementToShow.innerHTML = fb_close_link() + xhr[xhri].responseText;
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
				//alert(alertStr);
			}
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function pw_recover() {
	var form = document.forms["pwrecover"];
	if (form.email.value == "") {
		alert("Please enter your email address");
	} else {
		show_floating_box('null',500)
		var action = form.action1.value;
		var email = form.email.value;
		var qry = 'js=yes&action=' + action + '&email=' + email;
		var xhri = xhrRequest('html');
		var url = 'pw_recover.php';
		xhr[xhri].open('POST', url, true);
		xhr[xhri].onreadystatechange = function () {
				if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
					var myElement = 'floating_box';
					var elementToShow = document.getElementById(myElement);
					elementToShow.innerHTML = fb_close_link() + xhr[xhri].responseText;
				} else {
					try {
						var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
					}
					catch (e) {
						var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
					}
					//alert(alertStr);
				}
			};
		xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xhr[xhri].send(qry);
	}
}

function tellafriend() {
	var myElement = 'floating_box';
	var elementToShow = document.getElementById(myElement);
	if (elementToShow.style.visibility != 'visible') {
		show_floating_box('paper_frame','400')
	}
	if (typeof(document.tellafriend_form) != "undefined") {
		action = document.tellafriend_form.action.value;
		your_name = document.tellafriend_form.your_name.value;
		your_email = document.tellafriend_form.your_email.value;
		dest_name = document.tellafriend_form.dest_name.value;
		dest_email = document.tellafriend_form.dest_email.value;
		add_message = document.tellafriend_form.add_message.value;
		var qry = 'action=' + action + '&your_name=' + your_name + '&your_email=' + your_email + '&dest_name=' + dest_name + '&dest_email=' + dest_email + '&add_message=' + add_message;
	} else {
		var qry = "";
	}
	elementToShow.innerHTML = floating_box_wait_content();
	if (!xmlhttp) {
		xmlhttp = getXmlHttpRequest();
	}
	if (!xmlhttp) {
		alert("could not create XmlHttpRequest");
		return;
	}
	var url = 'php/tellafriend.php';
	xmlhttp.open('POST', url, true);
	xmlhttp.onreadystatechange = tellafriend_return;
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send(qry);
}

function tellafriend_return() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		var theElementId = 'floating_box';
		var elementToShow = document.getElementById(theElementId);
		elementToShow.innerHTML = fb_close_link() + xmlhttp.responseText;
	} else {
		try {
			var alertStr = "xmlhttp.readyState=" + xmlhttp.readyState + " xmlhttp.status=" + xmlhttp.status;
		}
		catch (e) {
			var alertStr = "error getting xmlhttp.readyState and xmlhttp.status";
		}
	}
}

function change_theme(form) {
	if (!form) form = window.event; // fix for IE
	var theme = form.theme.options[form.theme.selectedIndex].text.toLowerCase();
	var user_id = form.user_id.value;
	//alert("form: " + form);
	//alert("selectedIndex: " + form.theme.selectedIndex);
	//alert("theme: " + theme);
	//alert("user_id: " + user_id);
	theElementId = 'paper_top';
	elementToSwitch = document.getElementById(theElementId);
	elementToSwitch.style.background = "url('pics/themes/" + theme + "/listpagetop.jpg')";
	theElementId = 'paper_middle';
	elementToSwitch = document.getElementById(theElementId);
	elementToSwitch.style.background = "url('pics/themes/" + theme + "/listpageside.jpg')";
	theElementId = 'paper_bottom';
	elementToSwitch = document.getElementById(theElementId);
	elementToSwitch.style.background = "url('pics/themes/" + theme + "/listpagebot.jpg')";
	var xhri = xhrRequest('html');
	var qry = 'js=yes&action=switch_theme&user_id=' + user_id + '&theme=' + theme;
	//alert(qry);
	var url = 'php/switch_theme.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				if (xhr[xhri].responseText != "0") {
					alert("Sorry, an error occurred saving your chosen theme" + xhr[xhri].responseText);
				}
				xi[xhri] = 1;
 				xhr[xhri] = null;
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
				//alert(alertStr);
			}
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function change_list_theme(thisSelect) {
	if (!thisSelect) thisSelect = window.event; // fix for IE
	var theme = thisSelect[thisSelect.selectedIndex].text.toLowerCase();
	//alert("thisSelect: " + thisSelect);
	//alert("selectedIndex: " + thisSelect.selectedIndex);
	//alert("theme: " + theme);
	theElementId = 'paper_top';
	elementToSwitch = document.getElementById(theElementId);
	elementToSwitch.style.background = "url('pics/themes/" + theme + "/listpagetop.jpg')";
	theElementId = 'paper_middle';
	elementToSwitch = document.getElementById(theElementId);
	elementToSwitch.style.background = "url('pics/themes/" + theme + "/listpageside.jpg')";
	theElementId = 'paper_bottom';
	elementToSwitch = document.getElementById(theElementId);
	elementToSwitch.style.background = "url('pics/themes/" + theme + "/listpagebot.jpg')";
}

function change_list_theme_auto(theme) {
	if (!theme) theme = window.event; // fix for IE
	theElementId = 'paper_top';
	elementToSwitch = document.getElementById(theElementId);
	elementToSwitch.style.background = "url('pics/themes/" + theme + "/listpagetop.jpg')";
	theElementId = 'paper_middle';
	elementToSwitch = document.getElementById(theElementId);
	elementToSwitch.style.background = "url('pics/themes/" + theme + "/listpageside.jpg')";
	//theElementId = 'paper_bottom';
	//elementToSwitch = document.getElementById(theElementId);
	//elementToSwitch.style.background = "url('pics/themes/" + theme + "/listpagebot.jpg')";
}

function check_page_height() {
	/*
	theElementId = 'paper_middle';
	elementToCheck = document.getElementById(theElementId);
	elementToCheck.style.height = 'auto';
	theElementId = 'paper_top';
	elementToCheck = document.getElementById(theElementId);
	//alert(elementToCheck);
	findPosObj = elementToCheck;
	top_pos = findPos();
	theElementId = 'paper_bottom';
	elementToCheck = document.getElementById(theElementId);
	//alert(elementToCheck);
	findPosObj = elementToCheck;
	bottom_pos = findPos();
	middle_height = bottom_pos[1] - (top_pos[1] + 50);
	//current_height = elementToCheck.style.height;
	//alert("page height = " + middle_height);
	if ((middle_height % 150) != 0) {
		the_int = Math.floor(middle_height / 150);
		new_int = the_int + 1;
		new_height = new_int * 150;
		if (new_height < 450) {
			new_height = 450;
		}
		theElementId = 'paper_middle';
		elementToCheck = document.getElementById(theElementId);
		elementToCheck.style.height = new_height + 'px';
	}
	*/
	// set 'paper_middle' height to 'auto'
	document.getElementById('paper_middle').style.height = 'auto';
	// get co-ordinates of 'paper_top'
	findPosObj = document.getElementById('paper_top');
	var top_pos = findPos();
	// get co-ordinates of 'paper_bottom'
	findPosObj = document.getElementById('paper_bottom');
	var bottom_pos = findPos();
	// calculate height of 'paper_middle' ('paper_top' is 50px high)
	var middle_height = bottom_pos[1] - (top_pos[1] + 50);
	// get co-ordinates of 'footer'
	findPosObj = document.getElementById('footer');
	var footer_pos = findPos();
	// set min height for paper
	var new_min_height = footer_pos[1];
	// if the current paper height isn't enough, increase it to the minimum
	if ((top_pos[1] + 50 + middle_height + 49 + 75) < new_min_height) {
		middle_height = new_min_height - (top_pos[1] + 50 + 49 + 75);
	}
	// see if 'middle_height' is correct size for the graphic and, if not, increase it
	if ((middle_height % 150) != 0) {
		the_int = Math.floor(middle_height / 150);
		new_int = the_int + 1;
		middle_height = new_int * 150;
		if (middle_height < 450) {
			middle_height = 450;
		}
	}
	// set 'paper_middle' to desired height
	document.getElementById('paper_middle').style.height = middle_height + 'px';
}

function toggleKey() {
	var theElementId = 'key_to_symbols';
	var elementToCheck = document.getElementById('key_to_symbols');
	cur_state = elementToCheck.style.visibility;
	//alert(elementToCheck + " is " + cur_state);
	if ((elementToCheck.style.visibility == "") || (elementToCheck.style.visibility == "undefined")) {
		elementToCheck.style.visibility = "hidden";
	}
	if (elementToCheck.style.visibility == "hidden") {
		//alert("showing");
		elementToCheck.style.visibility = "visible";
		elementToCheck.style.height = "auto";
		elementToCheck.style.display = "block";
		theElementId = 'key_img_switch';
		elementToCheck = document.getElementById(theElementId);
		elementToCheck.src = "pics/general/ajaxarrowdown.gif";
		elementToCheck.alt = "hide key";
		elementToCheck.title = "hide key";
	} else if (elementToCheck.style.visibility == "visible") {
		//alert("hiding");
		elementToCheck.style.visibility = "hidden";
		elementToCheck.style.height = "0px";
		elementToCheck.style.display = "none";
		theElementId = 'key_img_switch';
		elementToCheck = document.getElementById(theElementId);
		elementToCheck.src = "pics/general/ajaxarrowright.gif";
		elementToCheck.alt = "show key";
		elementToCheck.title = "show key";
	}
}

function make_favourite(selected_list_id,selected_list_owner_id,selected_cat_id,user_id) {
	q_string = window.location.search;
	show_floating_box('paper_frame','300')
	var xhri = xhrRequest('html');
	var qry = 'js=yes&user_id=' + user_id + '&selected_list_id=' + selected_list_id + '&selected_list_owner_id=' + selected_list_owner_id;
	if (selected_cat_id != '') {
		qry += '&selected_cat_id=' + selected_cat_id;
	}
	//alert(qry);
	var url = 'makefav.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				var theElementId = 'floating_box';
				var elementToShow = document.getElementById(theElementId);
				elementToShow.innerHTML = fb_close_link() + xhr[xhri].responseText;
				refresh_search_page(user_id,q_string);
				document.myform.mybutton.focus();
				document.myform.mybutton.select();
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
				//alert(alertStr);
			}
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function give_goldstar(selected_list_id,selected_list_owner_id,selected_cat_id,user_id) {
	show_floating_box('paper_frame','300')
	var xhri = xhrRequest('html');
	var qry = 'js=yes&user_id=' + user_id + '&selected_list_id=' + selected_list_id + '&selected_list_owner_id=' + selected_list_owner_id;
	if (selected_cat_id != '') {
		qry += '&selected_cat_id=' + selected_cat_id;
	}
	//alert(qry);
	var url = 'give_goldstar.php';
	q_string = window.location.search;
	//alert(q_string);
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				var theElementId = 'floating_box';
				var elementToShow = document.getElementById(theElementId);
				elementToShow.innerHTML = fb_close_link() + xhr[xhri].responseText;
				refresh_search_page(user_id,q_string);
				document.myform.mybutton.focus();
				document.myform.mybutton.select();
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
				//alert(alertStr);
			}
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function give_medal(user_id,selected_list_id,selected_list_item_id,selected_list_owner_id,selected_cat_id) {
	show_floating_box('paper_frame','300');
	var xhri = xhrRequest('html');
	var qry = 'js=yes&user_id=' + user_id + '&selected_list_id=' + selected_list_id + '&selected_list_item_id=' + selected_list_item_id + '&selected_list_owner_id=' + selected_list_owner_id;
	if (selected_cat_id != '') {
		qry += '&selected_cat_id=' + selected_cat_id;
	}
	//alert(qry);
	var url = 'give_medal.php';
	q_string = window.location.search;
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				var theElementId = 'floating_box';
				var elementToShow = document.getElementById(theElementId);
				elementToShow.innerHTML = fb_close_link() + xhr[xhri].responseText;
				refresh_search_page(user_id,q_string);
				document.myform.mybutton.focus();
				document.myform.mybutton.select();
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
				//alert(alertStr);
			}
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function emaillist(list_id,cat_id) {
	show_floating_box('paper_frame','400')
	var xhri = xhrRequest('html');
	var qry = 'js=yes&action=prep&list_id=' + list_id + '&cat_id=' + cat_id;
	var url = 'php/emaillist.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				var theElementId = 'floating_box';
				var elementToShow = document.getElementById(theElementId);
				elementToShow.innerHTML = fb_close_link() + xhr[xhri].responseText;
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
				//alert(alertStr);
			}
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function sendemaillist(form) {
	show_floating_box('paper_frame','400')
	var xhri = xhrRequest('html');
	var d_name = form.d_name.value;
	var d_email = form.d_email.value;
	var d_subject = form.d_subject.value;
	var d_message = form.d_message.value;
	var list_id = form.list_id.value;
	var cat_id = form.cat_id.value;
	var qry = 'js=yes&action=send&list_id=' + list_id + '&cat_id=' + cat_id + '&d_name=' + d_name + '&d_email=' + d_email + '&subject=' + d_subject + '&d_message=' + d_message;
	var url = 'php/emaillist.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				var theElementId = 'floating_box';
				var elementToShow = document.getElementById(theElementId);
				elementToShow.innerHTML = fb_close_link() + xhr[xhri].responseText;
				document.myform.mybutton.focus();
				document.myform.mybutton.select();
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
				//alert(alertStr);
			}
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function delete_goldstar(id,user_id,target,start) {
	var xhri = xhrRequest('html');
	var qry = 'js=yes&id=' + id;
	var url = 'myhome/goldstars_delete.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				refreshGivenGoldstars(user_id,target,start);
				mh_refresh_head(user_id,'gs');
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
			}
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function refreshReceivedGoldstars(user_id,target,start) {
	var xhri = xhrRequest('html');
	var qry = 'js=yes&user_id=' + user_id + '&start=' + start;
	var url = 'myhome/goldstars_received.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				var theElementId = 'goldstars_received';
				var elementToShow = document.getElementById(theElementId);
				elementToShow.innerHTML = xhr[xhri].responseText;
				mh_refresh_head(user_id,'gs');
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
			}
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function refreshGivenGoldstars(user_id,target,start) {
	var xhri = xhrRequest('html');
	var qry = 'js=yes&user_id=' + user_id + '&start=' + start;
	var url = 'myhome/goldstars_given.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				var theElementId = 'goldstars_given';
				var elementToShow = document.getElementById(theElementId);
				elementToShow.innerHTML = xhr[xhri].responseText;
				mh_refresh_head(user_id,'gs');
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
			}
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function refreshReceivedMedals(user_id,target,start) {
	var xhri = xhrRequest('html');
	var qry = 'js=yes&user_id=' + user_id + '&start=' + start;
	var url = 'myhome/medals_received.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				var theElementId = 'medals_received';
				var elementToShow = document.getElementById(theElementId);
				elementToShow.innerHTML = xhr[xhri].responseText;
				mh_refresh_head(user_id,'md');
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
			}
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function refreshGivenMedals(user_id,target,start) {
	var xhri = xhrRequest('html');
	var qry = 'js=yes&user_id=' + user_id + '&start=' + start;
	var url = 'myhome/medals_given.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				var theElementId = 'medals_given';
				var elementToShow = document.getElementById(theElementId);
				elementToShow.innerHTML = xhr[xhri].responseText;
				mh_refresh_head(user_id,'md');
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
			}
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function delete_medal(id,user_id,target,start) {
	var xhri = xhrRequest('html');
	var qry = 'js=yes&id=' + id + '&user_id=' + user_id;
	var url = 'myhome/medals_delete.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				refreshGivenMedals(user_id,target,start);
				mh_refresh_head(user_id,'md');
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
			}
			//alert(alertStr);
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function refreshReceivedMe2s(user_id,target,start) {
	var xhri = xhrRequest('html');
	var qry = 'js=yes&user_id=' + user_id + '&start=' + start;
	var url = 'myhome/me2s_received.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				var theElementId = 'me2s_received';
				var elementToShow = document.getElementById(theElementId);
				elementToShow.innerHTML = xhr[xhri].responseText;
				mh_refresh_head(user_id,'me');
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
			}
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function refreshGivenMe2s(user_id,target,start) {
	var xhri = xhrRequest('html');
	var qry = 'js=yes&user_id=' + user_id + '&start=' + start;
	var url = 'myhome/me2s_given.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				var theElementId = 'me2s_given';
				var elementToShow = document.getElementById(theElementId);
				elementToShow.innerHTML = xhr[xhri].responseText;
				mh_refresh_head(user_id,'me');
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
			}
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function delete_me2(id,user_id,target,start) {
	var xhri = xhrRequest('html');
	var qry = 'js=yes&id=' + id + '&user_id=' + user_id;
	var url = 'myhome/me2s_delete.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				refreshGivenMe2s(user_id,target,start);
				mh_refresh_head(user_id,'me');
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
			}
			//alert(alertStr);
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function check_trivia_cat() {
	the_select = document.getElementById("list_cat");
	the_option = document.getElementById("trivia_cat");
	if (the_select.value == "Other...") {
		the_option.style.visibility = "visible";
	} else {
		the_option.style.visibility = "hidden";
	}
}

function save_add_pics(form) {
	form.action.value = form.action.value + '_add';
}

function lf_tl_toggle(key) {
	var xhri = xhrRequest('html');
	var qry = 'js=yes&lf_tl_choice=' + key;
	var url = 'php/trivialists.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				document.getElementById('lf_trivialists').innerHTML = xhr[xhri].responseText;
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
			}
			//alert(alertStr);
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function change_numbering(thisSelect) {
	show_floating_box('paper_frame','300');
	thisSelect.form.submit();
	/*
	document.getElementById('numbering_update').style.visibility = "visible";
	document.getElementById('numbering_update').style.display = "inline";
	
	if (!thisSelect) thisSelect = window.event; // fix for IE
	
	// get the vars to work with
	var numbering = thisSelect[thisSelect.selectedIndex].value;			// the state to which we are switching: 'yes' or 'no'
	//alert("change numbering to: " + numbering);
	var selected_list_id = thisSelect.form.selected_list_id.value;		// the id of this list
	var selected_cat_id = thisSelect.form.selected_cat_id.value;		// the category of this list (100, 200, 300, 400, other)
	switch ( selected_cat_id ) {
		case "100":
			var url = 'mylifelists/edit_todo.php';
			break;
		case "200":
			var url = 'mylifelists/edit_picture.php';
			break;
		case "300":
			var url = 'mylifelists/edit_bucket.php';
			break;
		case "400":
			var url = 'mylifelists/edit_trivia.php';
			break;
		default:
			var url = 'mylifelists/edit_std.php';
	}
	
	var xhri = xhrRequest('html');
	var qry = 'js=yes&jsaction=change_numbering&numbering=' + numbering + '&selected_list_id=' + selected_list_id + '&selected_cat_id=' + selected_cat_id;
	//alert(qry);
	//alert(url);
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				document.getElementById("edit_content").innerHTML = xhr[xhri].responseText;
				document.getElementById('numbering_update').style.visibility = "hidden";
				document.getElementById('numbering_update').style.display = "none";
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
			}
			//alert(alertStr);
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
	*/
}

function reset_numbering(selected_list_id, selected_cat_id) {
	show_floating_box('paper_frame','400');
	var xhri = xhrRequest('html');
	var qry = 'js=yes&jsaction=reset_req&selected_list_id=' + selected_list_id + '&selected_cat_id=' + selected_cat_id;
	//alert(qry);
	var url = 'php/reset_numbering.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				document.getElementById("floating_box").innerHTML = xhr[xhri].responseText;
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
			}
			//alert(alertStr);
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function reset_numbering_confirm(this_form) {
	var selected_list_id = this_form.selected_list_id.value;
	var selected_cat_id = this_form.selected_cat_id.value;
	show_floating_box('paper_frame','400');
	var xhri = xhrRequest('html');
	var qry = 'js=yes&jsaction=reset_confirm&selected_list_id=' + selected_list_id + '&selected_cat_id=' + selected_cat_id;
	//alert(qry);
	var url = 'php/reset_numbering.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				//close_floating_box();
				location.reload();
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
			}
			//alert(alertStr);
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function toggleModerateItemComments() {
	if (document.getElementById('item_comments').value == 'yes') {
		document.getElementById('moderate_item_comments_div').style.visibility = 'visible';
		document.getElementById('moderate_item_comments_div').style.display = 'block';
	} else {
		document.getElementById('moderate_item_comments_div').style.visibility = 'hidden';
		document.getElementById('moderate_item_comments_div').style.display = 'none';
	}
}

function showComments(item_id,cat_id) {
	//document.getElementById('comment_bubble_' + item_id).src = 'pics/general/busy.gif';
	//document.getElementById('comment_bubble_' + item_id).title = 'busy...';
	//document.getElementById('comment_bubble_' + item_id).alt = 'busy...';
	document.getElementById('comments_link_' + item_id).href = 'javascript:hideComments(' + item_id + ',' + cat_id + ')';
	var xhri = xhrRequest('html');
	var qry = 'js=yes&item_id=' + item_id + '&cat_id=' + cat_id;
	var url = 'php/show_comments.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				document.getElementById('s_comment_content_' + item_id).innerHTML = xhr[xhri].responseText;
				document.getElementById('s_comment_content_' + item_id).style.visibility = 'visible';
				document.getElementById('s_comment_content_' + item_id).style.display = 'block';
				//document.getElementById('comment_bubble_' + item_id).src = 'pics/general/bubble.gif';
				//document.getElementById('comment_bubble_' + item_id).title = 'Hide comments';
				//document.getElementById('comment_bubble_' + item_id).alt = 'Hide comments';
				tmtOpenTags['new_comment_' + item_id] = new Array();
				updateCommentCount(item_id,cat_id,0);
				check_page_height();
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
			}
			//alert(alertStr);
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function showMyComments(item_id,cat_id,user_id) {
	//var bubble_img_src = document.getElementById('comment_bubble_' + item_id).src;
	//document.getElementById('comment_bubble_' + item_id).src = 'pics/general/busy.gif';
	//document.getElementById('comment_bubble_' + item_id).title = 'busy...';
	//document.getElementById('comment_bubble_' + item_id).alt = 'busy...';
	document.getElementById('comments_link_' + item_id).href = 'javascript:hideMyComments(' + item_id + ',' + cat_id + ',' + user_id + ')';
	var xhri = xhrRequest('html');
	var qry = 'js=yes&item_id=' + item_id + '&cat_id=' + cat_id+ '&user_id=' + user_id;
	var url = 'php/show_my_comments.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				document.getElementById('s_comment_content_' + item_id).innerHTML = xhr[xhri].responseText;
				document.getElementById('s_comment_content_' + item_id).style.visibility = 'visible';
				document.getElementById('s_comment_content_' + item_id).style.display = 'block';
				//document.getElementById('comment_bubble_' + item_id).src = bubble_img_src;
				//document.getElementById('comment_bubble_' + item_id).title = 'Hide comments';
				//document.getElementById('comment_bubble_' + item_id).alt = 'Hide comments';
				updateCommentCount(item_id,cat_id,1);
				check_page_height();
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
			}
			//alert(alertStr);
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function hideComments(item_id,cat_id) {
	//document.getElementById('comment_bubble_' + item_id).src = 'pics/general/bubble.gif';
	//document.getElementById('comment_bubble_' + item_id).title = 'Show comments';
	//document.getElementById('comment_bubble_' + item_id).alt = 'Show comments';
	document.getElementById('comments_link_' + item_id).href = 'javascript:showComments(' + item_id + ',' + cat_id + ')';
	document.getElementById('s_comment_content_' + item_id).style.visibility = 'hidden';
	document.getElementById('s_comment_content_' + item_id).style.display = 'none';
	updateCommentCount(item_id,cat_id,0);
	check_page_height();
}

function hideMyComments(item_id,cat_id,user_id) {
	//document.getElementById('comment_bubble_' + item_id).src = 'pics/general/bubble.gif';
	//document.getElementById('comment_bubble_' + item_id).title = 'Show comments';
	//document.getElementById('comment_bubble_' + item_id).alt = 'Show comments';
	document.getElementById('comments_link_' + item_id).href = 'javascript:showMyComments(' + item_id + ',' + cat_id + ',' + user_id + ')';
	document.getElementById('s_comment_content_' + item_id).style.visibility = 'hidden';
	document.getElementById('s_comment_content_' + item_id).style.display = 'none';
	updateCommentCount(item_id,cat_id,1);
	check_page_height();
}

function addNewComment(item_id,is_owner) {
	if (document.getElementById('new_comment_' + item_id).value == "") {
		return false;
	}
	var list_id = document.getElementById('selected_list_id').value;
	var cat_id = document.getElementById('selected_cat_id').value;
	var user_id = document.getElementById('user_id').value;
	var comment = escape(encodeURIComponent(document.getElementById('new_comment_' + item_id).value));
	var xhri = xhrRequest('html');
	var qry = 'js=yes&jsaction=do_add&item_id=' + item_id + '&cat_id=' + cat_id + '&list_id=' + list_id + '&user_id=' + user_id + '&comment=' + comment;
	var url = 'php/add_comment.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				if (xhr[xhri].responseText == "true") {
					if (is_owner == 0) {
						showComments(item_id,cat_id);
					} else {
						showMyComments(item_id,cat_id,user_id);
					}
					updateCommentCount(item_id,cat_id,is_owner);
					check_page_height();
				} else if (xhr[xhri].responseText == "wait") {
					if (is_owner == 0) {
						showComments(item_id,cat_id);
					} else {
						showMyComments(item_id,cat_id,user_id);
					}
					updateCommentCount(item_id,cat_id,is_owner);
					check_page_height();
					show_floating_box('s_comment_content_' + item_id,250);
					var fb_content = fb_close_link();
					fb_content += "<div align=\"center\"><span class=\"brownnamehead\">\n";
					fb_content += "<img src=\"pics/general/mylifelistslogo200.gif\" /><br />\n";
					fb_content += "Thank you, your comment has been submitted for approval.<br />\n";
					fb_content += "</span></div>\n";
					document.getElementById('floating_box').innerHTML = fb_content;
				} else {
					alert("Sorry, an error occurred [" + xhr[xhri].responseText + "]");
				}
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
			}
			//alert(alertStr);
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function commentAction(action_type,comment_id,item_id) {
	var user_id = document.getElementById('user_id').value;
	var cat_id = document.getElementById('selected_cat_id').value;
	var xhri = xhrRequest('html');
	var qry = 'js=yes&action_type=' + action_type + '&comment_id=' + comment_id + '&item_id=' + item_id + '&cat_id=' + cat_id;
	var url = 'php/comment_action.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				if ((xhr[xhri].responseText == "true") || (xhr[xhri].responseText == "true_all_mod")) {
					showMyComments(item_id,cat_id,user_id);
					if (xhr[xhri].responseText == "true_all_mod") {
						document.getElementById('comment_bubble_div_' + item_id).style.backgroundImage = "url(pics/general/bubble.gif)";
					} else {
						document.getElementById('comment_bubble_div_' + item_id).style.backgroundImage = "url(pics/general/bubble_red.gif)";
					}
					updateCommentCount(item_id,cat_id,1);
					check_page_height();
				} else {
					alert("Sorry, an error occurred [" + xhr[xhri].responseText + "]");
				}
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
			}
			//alert(alertStr);
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function updateCommentCount(item_id,cat_id,is_owner) {
	var bubble_href = document.getElementById('comments_link_' + item_id).href;
	var xhri = xhrRequest('html');
	var qry = 'js=yes&&item_id=' + item_id + '&cat_id=' + cat_id + '&is_owner=' + is_owner;
	var url = 'php/comment_count.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				document.getElementById('comment_bubble_div_' + item_id).innerHTML = '<a id="comments_link_' + item_id + '" href="' + bubble_href + '"><span class="comment_count">&nbsp;' + xhr[xhri].responseText + '&nbsp;</span></a>';
				//alert('<a id="comments_link_' + item_id + '" href="' + bubble_href + '"><span class="comment_count">' + xhr[xhri].responseText + '</span>');
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
			}
			//alert(alertStr);
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function sizeTextArea50(box) {
	var chars = box.value.length;
	var lines = Math.floor(chars / 50) + 2;
	box.rows = lines;
	check_page_height();
}

function isVoid() {
	return false;
}
