﻿function validate_form(form) {	if (!form) form = window.event; // fix for IE	if (form.elements["form_ignore"]) {		return true	} else {		var formValid = "1"		var reqFields = form.elements["required"].value.split(",")		for (var i = 0; i < reqFields.length; i++) {			if (form.elements[reqFields[i]].value == "") {				formValid = "0"			}		}		if (formValid == "0") {			alert("All required fields must be completed")			return false		} else {			return true		}	}}function validate_profile(myform) {	if (!myform) myform = window.event; // fix for IE	var formValid = "1"	var theDate = "0"	var reqFields = myform.elements["required"].value.split(",")	for (var i = 0; i < reqFields.length; i++) {		if (myform.elements[reqFields[i]].value == "") {			formValid = "0"		}	}	if (formValid == "0") {		alert("All fields marked with an * must be completed")		return false	}	return true}function validate_reg(form) {	if (!form) form = window.event; // fix for IE	if (form.password.value != form.password2.value) {		alert("Please re-enter your password (the two values do not match).")		form.password.value = ""		form.password2.value = ""		form.password.focus()		form.password.select()		return false	}	var formValid = "1"	var agreeTerms = "0"	var theDate = "0"	var reqFields = form.elements["required"].value.split(",")	for (var i = 0; i < reqFields.length; i++) {		if (form.elements[reqFields[i]].value == "") {			formValid = "0"		}	}	if (form.agree_terms.checked) {		agreeTerms = "1"	}	if (formValid == "0") {		alert("All fields marked with an * must be completed")		return false	} else if (agreeTerms == "0") {		alert("Please confirm you have read and agree to our Terms & Conditions by ticking the box at the bottom of the form")		return false	}	return true}function validate_login(form) {	if (!form) form = window.event; // fix for IE	var formValid = "1"	var reqFields = form.elements["required"].value.split(",")	for (var i = 0; i < reqFields.length; i++) {		if (form.elements[reqFields[i]].value == "") {			formValid = "0"		}	}	if (formValid == "0") {		alert("Please enter both your email address and password")		return false	} else {		return true	}}function validate_poll(form) {	if (!form) form = window.event; // fix for IE	var formValid = "0"	//var reqFields = form.elements["required"].value.split(",")	for (var i = 0; i < form.r.length; i++) {		if (form.r[i].checked) {			formValid = "1"		}	}	if (formValid == "0") {		alert("Please choose an option to vote for!")		return false	} else {		return true	}}function validate_search(form) {	if (!form) form = window.event; // fix for IE	if ((form.search_type.options[form.search_type.selectedIndex].text == "Lifelists that contain") && (form.elements["search_terms"].value == "")) {		alert("When searching for \"Lifelists that contain\" you must enter some search terms!")		return false	}	return true}/*function isEmpty(inputStr) {	if (inputStr == "" || inputStr == null) {		return true	}	return false}function inRange(inputStr, lo, hi) {	var num = parseInt(inputStr, 10)	if (num < lo || num > hi) {		return false	}	return true}function validateDate(day, month, year) {	if (!isEmpty(month)) {		if ((month.length != 2) && (month.length != 0)) {			return 2		}		month = parseInt(month, 10)		if (isNaN(month)) {			return 2		} else {			if (!inRange(month, 1, 12)) {				return 2			}		}	}	if (!isEmpty(day)) {		if ((day.length != 2) && (day.length != 0)) {			return 1		}		day = parseInt(day, 10)		if (isNaN(day)) {			return 1		} else {			var monthMax = new Array(31,31,29,31,30,31,30,31,31,30,31,30,31)			var top = monthMax[month]			if (!inRange(day, 1, top)) {				return 1			}		}	}	if (!isEmpty(year)) {		if ((year.length != 4) && (year.length != 0)) {			return 3		}		var year = parseInt(year, 10)		if (isNaN(year)) {			return 3		} else {			if (!inRange(year, 1900, 2006)) {				return 3			}		}	}	return 0}*/function quicklistSelect(option) {	if (!option) option = window.event; // fix for IE	if (option.value != "") {		window.location = "mylifelists.php?" + option.value;	}}function validateNickname(form) {	this_object = form.n_nickname;	new_nickname = this_object.value;	if (form.user_id) {		user_id = form.user_id.value;	} else {		user_id = 0;	}	if (new_nickname != "") {		this_user_id = user_id;		var myElement = "nickname_response";		var elementToShow = document.getElementById(myElement);		elementToShow.style.visibility = 'visible';		elementToShow.style.height = 'auto';		var the_text = "checking nickname...";		var current_text = elementToShow.innerHTML;		elementToShow.innerHTML = current_text + the_text;		if (!xmlhttp) {			xmlhttp = getXmlHttpRequest();		}		if (!xmlhttp) {			alert("could not create XmlHttpRequest");			return;		}		var qry = 'new_nickname=' + new_nickname + '&user_id=' + this_user_id;		var url = 'php/validate_nickname.php';		xmlhttp.open('POST', url, true);		xmlhttp.onreadystatechange = printValidateNickname;		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');		xmlhttp.send(qry);	}}function printValidateNickname() {	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {		var myElement = 'nickname_response';		var elementToShow = document.getElementById(myElement);		if (xmlhttp.responseText == "false") {			var the_text = "sorry, this nickname is already taken";			elementToShow.innerHTML = the_text;			elementToShow.style.visibility = 'visible';			elementToShow.style.height = 'auto';			this_object.focus();			this_object.select();		} else {			var the_text = "";			elementToShow.innerHTML = the_text;			elementToShow.style.visibility = 'hidden';			elementToShow.style.height = '0px';		}	} else {		try {			var alertStr = "xmlhttp.readyState=" + xmlhttp.readyState + " xmlhttp.status=" + xmlhttp.status;		}		catch (e) {			var alertStr = "error getting xmlhttp.readyState and xmlhttp.status";		}	}}function validate_email(email) {	if (!email) email = window.event; // fix for IE	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;	var address = email.value;	if(reg.test(address) == false) {		alert('the email address you entered does not appear to be valid!');		email.focus();		email.select();		return false;	} else {		return true;	}}function check_length(item) {	if (item.value.length > 255) {		item.value = item.value.substring(0,255);	}}function itemNumChange(item) {	var thisForm = item.form;	// first we need to know if the item is moving to a higher or lower position in the list	// so lets start by getting the 'new' and 'old' position numbers		// find the 'old' value of the changed element	var oldVal = parseInt(thisForm.elements[item.name + "_old"].value);	// find the 'new' value of the changed element	var newVal = parseInt(item.options[item.selectedIndex].value);		// now before we deal with the rest of the list, update the hidden 'old' field for this item so subsequent changes will work	thisForm.elements[item.name + "_old"].value = newVal;		if (newVal > oldVal) {		// we're moving the item down		// so we have to find all the elements that are greater than or equal to the new value, and decrement them		for (var i=0; i<thisForm.elements.length; i++) {			if ((thisForm.elements[i].type == "select-one") && (thisForm.elements[i].name.substring(0,12) == "form_item_no") && (thisForm.elements[i] != item)) {				// this is a select element, but not the one that was changed				if ((parseInt(thisForm.elements[i].options[thisForm.elements[i].selectedIndex].value) <= newVal) && (parseInt(thisForm.elements[i].options[thisForm.elements[i].selectedIndex].value) >= oldVal)) {					// this is a select element that needs it's number decrementing					// decrement the selection of the element					thisForm.elements[i].selectedIndex = parseInt(thisForm.elements[i].selectedIndex) - 1;					// decrement the hidden 'old' value field					thisForm.elements[thisForm.elements[i].name + "_old"].value = parseInt(thisForm.elements[thisForm.elements[i].name + "_old"].value) - 1;				}			}		}	} else {		// we're moving the item up		// so we have to find all the elements that are less than or equal to the new value, and increment them		for (var i=0; i<thisForm.elements.length; i++) {			if ((thisForm.elements[i].type == "select-one") && (thisForm.elements[i].name.substring(0,12) == "form_item_no") && (thisForm.elements[i] != item)) {				// this is a select element, but not the one that was changed, so we need to check it's value				if ((parseInt(thisForm.elements[i].options[thisForm.elements[i].selectedIndex].value) <= oldVal) && (parseInt(thisForm.elements[i].options[thisForm.elements[i].selectedIndex].value) >= newVal)) {					// this is a select element that needs it's number incrementing					// increment the selection of the element					thisForm.elements[i].selectedIndex = parseInt(thisForm.elements[i].selectedIndex) + 1;					// increment the hidden 'old' value field					thisForm.elements[thisForm.elements[i].name + "_old"].value = parseInt(thisForm.elements[thisForm.elements[i].name + "_old"].value) + 1;				}			}		}	}		// now we should hide the sort pulldown and show the reminder (and button) to save the number changes	document.getElementById('sort_pulldown').style.visibility = 'hidden';	document.getElementById('sort_pulldown').style.display = 'none';	document.getElementById('numchange_reminder').style.visibility = 'visible';	document.getElementById('numchange_reminder').style.display = 'block';}function chooseSort(thisSelect) {	if (thisSelect.form.this_action != undefined) {		var mode = thisSelect.form.this_action.value;	} else {		var mode = "";	}	var selected_list_id = thisSelect.form.selected_list_id.value;	var selected_cat_id = thisSelect.form.selected_cat_id.value;	var order_sort = thisSelect.options[thisSelect.selectedIndex].value;	var split_char = order_sort.lastIndexOf("_");	var order_by = order_sort.substring(0,split_char);	var sort_dir = order_sort.substring(split_char+1);	var new_href = location.protocol + "//" + location.host;	var new_pathname = location.pathname;	if (mode == "edit") {		var new_action = "edit";	} else {		switch ( selected_cat_id ) {			case "100":				var new_action = "show_todo_list";				break;			case "200":				var new_action = "show_picture_list";				break;			case "300":				var new_action = "show_bucket_list";				break;			case "400":				var new_action = "show_trivia_list";				break;			default:				var new_action = "show_list";		}	}	var new_url = new_href + new_pathname + "?action=" + new_action;	new_url += "&selected_list_id=" + selected_list_id + "&selected_cat_id=" + selected_cat_id + "&order_by=" + order_by + "&sort_dir=" + sort_dir;	//alert(new_url);	window.location.href = new_url;}