

function show_properties_by_email(search_criteria)
{
	var width = 780;
	var height = 510;
	var top = 50;
	var left = 50;
	window.open("property-mail-agent.asp?"+search_criteria, "", "toolbar=no,directories=no,menubar=no,scrollbars=yes,status=yes,resizable=1,left=" + left + ",top=" + top + ",width=" + width + ",height=" + height);
}





function show_tip_friend(property_id)
{
	var width = 632;
	var height = 510;
	var top = 50;
	var left = 50;
	window.open("tip-friend.asp?property_id=" + property_id, "", "toolbar=no,directories=no,menubar=no,scrollbars=yes,status=yes,resizable=1,left=" + left + ",top=" + top + ",width=" + width + ",height=" + height);
}





function show_print_property(property_id)
{
	var width = 670;
	var height = 500;
	var top = 50;
	var left = 50;
	window.open("print.asp?property_id=" + property_id, "", "toolbar=no,directories=no,menubar=no,scrollbars=yes,status=yes,resizable=1,left=" + left + ",top=" + top + ",width=" + width + ",height=" + height);
}





function show_images(property_id, index)
{
	var top = 50;
	var left = 50;
	var width = 350;
	var height = 350;
	window.open("show-images.asp?property_id=" + property_id + "&index=" + index, "", "toolbar=no,directories=no,menubar=no,scrollbars=yes,status=no,resizable=1,left=" + left + ",top=" + top + ",width=" + width + ",height=" + height);
}





function show_contact_estate_agent(property_id, company_id)
{
	var top = 50;
	var left = 50;
	var width = 670;
	var height = 590;
	window.open("contact-estate-agent.asp?property_id=" + property_id + "&company_id=" + company_id, "", "toolbar=no,directories=no,menubar=no,scrollbars=yes,status=no,resizable=1,left=" + left + ",top=" + top + ",width=" + width + ",height=" + height);
}





function show_terms()
{
	var top = 50;
	var left = 50;
	var width = 600;
	var height = 600;
	window.open("terms.asp", "", "toolbar=no,directories=no,menubar=no,scrollbars=yes,status=no,resizable=1,left=" + left + ",top=" + top + ",width=" + width + ",height=" + height);
}





function select_location(id)
{
	var option_list = document.this_page.location;
	for (var i=0; i<option_list.length; i++)
	{
		if (option_list[i].value == id)
		{
			option_list[i].selected = 1;
		}
	}
}





function get_location_list()
{
	var location_list 	= document.this_page.location;
	var location_array	= new Array();
	var location_str	= "";
	if (location_list[0].selected == 1)
	{
		location_str = "";
	}
	else
	{
		for (var i=1; i<location_list.length; i++)
		{
			if (location_list[i].selected == 1)
			{
				location_array[location_array.length] = location_list[i].value;
			}
		}
	}
	
	location_str = location_array.join(",");
	return location_str;
}





function save_property(property_id)
{
	// Save Property Ad
	document.this_page.command.value = "save_property";
	document.this_page.property_id.value = property_id;
	document.this_page.submit();
}





function show_navigation_links(id, from_row, to_row, rowcount, ads_on_list, page_index, search_params)
{
	// typeCast parameters
	from_row 	= parseInt(from_row);
	to_row 		= parseInt(to_row);
	rowcount 	= parseInt(rowcount);
	ads_on_list = parseInt(ads_on_list);
	page_index 	= parseInt(page_index);
	
	if (rowcount == 0 || rowcount == "")
	{
		var list_ref = document.getElementById("search_list_top");
		list_ref.style.display = "none";
		
		var top_ref = document.getElementById("top_count");
		if (top_ref)
		{
			top_ref.style.display = "none";
			document.write("<span style='font-size:16pt; color:#880000;'>No results in list</span>");
		}
		
		return false;
	}
	
	if (from_row > 0 && to_row > 0)
	{
		// Remove list page from search_params
		var re = new RegExp();
		re = /&list_page=(\d+)/g;
		search_params = String(search_params).replace(re, "");
		
		// Keep original list_index
		var list_page = page_index;
		
		// Get page to relocate to in list navigation
		var page_href = "search-list-property.asp?" + search_params;
		
		// Get  first page index
		var first_page = 0;
		
		// Get last page index
		var last_page = parseInt(rowcount/ads_on_list) - 1;
		if (parseInt(rowcount%ads_on_list)/ads_on_list > 0)	{ last_page++; }
		
		// Get prev page
		var prev_index = ( parseInt(page_index)-1 >= first_page )? parseInt(page_index)-1 : first_page;
		
		// Get next page
		var next_index = ( parseInt(page_index)+1 <= last_page )?  parseInt(page_index)+1 : last_page;
		
		var selected_nav_to = "";
		var nav_to_index = new Array();
		var nav_to_pages = new Array();
		
		for (var i=0; i<5; i++)
		{
			// Build link from/to
			var list_index = page_index - (page_index % 5);
			var link_from	= (parseInt(list_index) * parseInt(ads_on_list)) + parseInt((i * ads_on_list)) + 1;
			var link_to		= (parseInt(link_from)) + parseInt(ads_on_list) - 1;
			var nav_index	= parseInt(page_index) + i;
			
			// Set Max link_to
			if (link_to > rowcount)
			{
				link_to = rowcount;
			}
			
			// Get selected nav_to
			if ( (link_from == from_row) && (link_to == to_row) )
			{
				selected_nav_to = i;
			}
			
			// Set Max link_from
			if ( (link_from > rowcount) || (link_to < ads_on_list) )
			{
				// Clear nav_to links
				nav_to_index[i] = "";
				nav_to_pages[i] = "";
			}
			else
			{
				// Build nav_to links
				nav_to_index[i] = parseInt(list_index) + i;
				nav_to_pages[i] = link_from + " - " + link_to;
			}
		}
		
		// Display Navigation HTML
		var html_output = "" +
			"<table cellspacing=0 cellpadding=0 border=0 width=490>" +
				"<tr>" +
					"<td><img src='images/tp.gif' height=5></td>" +
				"</tr>" +
				"<tr>" +
					"<td align='right'>" +
						"<table cellpadding=0 cellspacing=0 border=0>" +
							"<tr>" +
								"<td width=65><span id='first"+id+"'><a href='"+page_href+"&list_page="+first_page+"'><img src='images/first.gif' border=0 align='top'></a>&nbsp;<a href='"+page_href+"&list_page="+first_page+"'>First page</a></span></td>" +
								"<td width=55><span id='prev" +id+"'><a href='"+page_href+"&list_page="+prev_index+"'><img src='images/prev.gif' border=0 align='top'></a>&nbsp;<a href='"+page_href+"&list_page="+prev_index+"'>Previous</a></span></td>" +
								"<td width=55><span id='nav0_"+id+"'><a href='"+page_href+"&list_page="+nav_to_index[0]+"'>" + nav_to_pages[0] + "</a></span>&nbsp;</td>" +
								"<td width=55><span id='nav1_"+id+"'><a href='"+page_href+"&list_page="+nav_to_index[1]+"'>" + nav_to_pages[1] + "</a></span>&nbsp;</td>" +
								"<td width=55><span id='nav2_"+id+"'><a href='"+page_href+"&list_page="+nav_to_index[2]+"'>" + nav_to_pages[2] + "</a></span>&nbsp;</td>" +
								"<td width=55><span id='nav3_"+id+"'><a href='"+page_href+"&list_page="+nav_to_index[3]+"'>" + nav_to_pages[3] + "</a></span>&nbsp;</td>" +
								"<td width=55><span id='nav4_"+id+"'><a href='"+page_href+"&list_page="+nav_to_index[4]+"'>" + nav_to_pages[4] + "</a></span>&nbsp;</td>" +
								"<td width=40><span id='next" +id+"'><a href='"+page_href+"&list_page="+next_index+"'>Next</a>&nbsp;<a href='"+page_href+"&list_page="+next_index+"'><img src='images/next.gif' border=0 align='top'></a></span></td>" +
								"<td width=60><span id='last" +id+"'><a href='"+page_href+"&list_page="+last_page+"'>Last page</a>&nbsp;<a href='"+page_href+"&list_page="+last_page+"'><img src='images/last.gif' border=0 align='top'></a></span></td>" +
							"</tr>" +
						"</table>" +
					"</td>" +
				"</tr>" +
			"</table>";
		document.write(html_output);
		
		// Highlight selected nav_link
		if (parseInt(selected_nav_to) >= 0)
		{
			var nav_to = document.getElementById("nav" + selected_nav_to + "_" + id);
			nav_to.innerHTML = nav_to_pages[selected_nav_to];
		}
		
		// Hide Prev - First page
		if (page_index == first_page)
		{
			var first_link	= document.getElementById("first" + id);
			var prev_link 	= document.getElementById("prev" + id);
			first_link.innerHTML = "&nbsp;";
			prev_link.innerHTML  = "&nbsp;";
		}
		
		// Hide Next - Last page
		if (page_index == last_page)
		{
			var last_link	= document.getElementById("last" + id);
			var next_link 	= document.getElementById("next" + id);
			last_link.innerHTML = "&nbsp;";
			next_link.innerHTML = "&nbsp;";
		}
	}
}





function show_prev_next_links(prev_id, next_id, prev_index, next_index, search_params)
{
	var re = new RegExp();
	
	// Get Prev/Next sections
	var prev_section	= document.getElementById("prev_link");
	var next_section	= document.getElementById("next_link");
	
	// Replace existing Property ID
	re = /property_id=(\d+)/i;
	search_params = String(search_params).replace(re, "");
	
	// Replace existing index
	re = /&index=(\d+)/i;
	search_params = String(search_params).replace(re, "");
	
	// Build Prev/Next links
	var prev_link 		= "<a href='show-property.asp?property_id="+prev_id+"&index="+prev_index + "&" + search_params+"'><img src='images/prev.gif' border='0' align='top'></a>&nbsp;<a href='show-property.asp?property_id="+prev_id+"&index="+prev_index + "&" + search_params+"'>Previous</a>";
	var next_link		= "<a href='show-property.asp?property_id="+next_id+"&index="+next_index + "&" + search_params+"'>Next</a>&nbsp;<a href='show-property.asp?property_id="+next_id+"&index="+next_index + "&" + search_params+"'><img src='images/next.gif' border='0' align='top'></a>";
	
	// Display Prev Link
	if (prev_index != "" && prev_id != "")
	{
		prev_section.innerHTML	= prev_link;
	}
	
	// Display Next Link
	if (next_index != "" && next_id != "")
	{
		next_section.innerHTML	= next_link;
	}
}





var locations = new Array(0,0,0,0);
var obj_list  = new LocationList();

if (document.images)
{
	map_01 = new Image(98,59); map_01.src 				= "images/map_01.gif"
	map_02 = new Image(129,59); map_02.src 				= "images/map_02.gif"
	map_03 = new Image(98,67); map_03.src 				= "images/map_03.gif"
	map_04 = new Image(129,67); map_04.src 				= "images/map_04.gif"
	map_01_over = new Image(98,59); map_01_over.src 	= "images/map_01_over.gif"
	map_02_over = new Image(129,59); map_02_over.src 	= "images/map_02_over.gif"
	map_03_over = new Image(98,67); map_03_over.src 	= "images/map_03_over.gif"
	map_04_over = new Image(129,67); map_04_over.src 	= "images/map_04_over.gif"
}





function set_location(location_str)
{
	var location_arr = location_str.split(",");
	if (location_arr[0] != 0)	{ toggle_district(1, 1); }
	if (location_arr[1] != 0)	{ toggle_district(2, 2); }
	if (location_arr[2] != 0)	{ toggle_district(3, 4); }
	if (location_arr[3] != 0)	{ toggle_district(4, 3); }
	
	var option_list = document.this_page.location_list;
	var d4_list = document.this_page.district4.value;
	
	// Select District4 options
	for (var i=0; i<option_list.length; i++)
	{
		var key = option_list[i].value;
		var re = new RegExp(key);
		
		if (d4_list.match(re) && option_list[i].value != "")
		{
			var re = new RegExp("[-]");
			if (String(option_list[i].value).match(re))
			{
				// Only Select D4
				option_list[i].selected = 1;
			}
		}
	}
}





function D3(id, text)
{
	obj_list.NewD3(id, text);
}





function LocationList()
{
	this.d3	= new Array();
	this.d3_selected = new Array();
	
	// District3 container
	this.d3[1]			= new Array();
	this.d3[2]			= new Array();
	this.d3[3]			= new Array();
	this.d3[4]			= new Array();
	
	// District3 selected container
	this.d3_selected[1]	= new Array();
	this.d3_selected[2]	= new Array();
	this.d3_selected[3]	= new Array();
	this.d3_selected[4]	= new Array();
	
	this.NewD3	= new_district;
	this.Update = update_district;
}





function new_district(id, text)
{
	// Split id
	var id_list = new Array();
	id_list	= String(id).split("-");
	
	// Get D3 id
	var d3_index = id_list[0];
	
	if (id_list.length == 1) { text = "&nbsp;&nbsp;&nbsp;" + text; } 					// Indent D3 with 2 spaces
	else					 { text = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + text; } 	// Indent D4 with 4 spaces
	
	// Update text value
	this.d3[d3_index][id] = text;
}





function update_district()
{
	var option_list = document.this_page.location_list;
	var location_list = new Array();
	var location_str = "";
	var option_str = "";
	
	// Check selected location options
	for (var i=0; i<option_list.length; i++)
	{
		if (option_list[i].selected == 1 && option_list[i].value != "")
		{
			var re = new RegExp("[-]");
			var value = option_list[i].value;
			
			// Add D4 to Location List
			if (value.match(re)) { location_list[location_list.length] = value; }
		}
	}
	location_str = location_list.join(",");
	
	// All Kent
	var location_start  = "<select multiple name='location_list' size=8 class='input' style='width:195px; padding-left:8px;'>" +
						  "<option value=''>All in Kent";
	var location_end	= "</select>";
	
	for (var i=0; i<locations.length; i++)
	{
		if (locations[i] != 0)
		{
			// Display selected District3 - District4
			for (var key in this.d3[locations[i]])
			{
				var re = new RegExp(key);
				var value = this.d3[locations[i]][key];
				
				// Select whole District3
				var selected = "";
				if (key == locations[i])
				{
					// But only if no District4 are already selected
					var d4_list = document.this_page.district4.value;
					var re = new RegExp(locations[i] + "[-]");
					if (!location_str.match(re) && !d4_list.match(re))
					{
						selected = "selected";
					}
				}
				// Select District4
				else if (location_str.match(re))
				{
					selected = "selected";
				}
				
				// Output option str
				option_str += "<option " + selected + " value='" + key + "'>" + value;
			}
		}
	}
	
	var list_section = document.getElementById("location_section");
	list_section.innerHTML = (location_start + option_str + location_end);
}





function toggle_district(section_id, d3_id)
{
	var selected_section = locations[section_id-1];
	if (selected_section == 0)
	{
		// Change images
		chgImg("map_0" + section_id, "map_0" + section_id + "_over");
		locations[section_id-1] = d3_id;
	}
	else
	{
		// Change images
		chgImg("map_0" + section_id, "map_0" + section_id);
		locations[section_id-1] = 0;
	}
	
	// Update Multi-Select
	obj_list.Update();
}





function change_image(image1, image2, section_id)
{
	if (locations[section_id-1] == 0)
	{
		chgImg(image1, image2);
	}

	return true;
}





function chgImg(imgField,newImg)
{
	if (document.images)
	{
		document.images[imgField].src= eval(newImg + ".src");
	}
}





function get_d3_list()
{
	var d3_list = locations;
	
	// loop selected locations and build the list
	location_list[0] = "2£UK£130£117££";
	
	return location_list;
}





function get_d4_list()
{
	var d4_list = new Array();
	var location_select = document.this_page.location_list;
	
	// Check whole of Kent
	if (location_select[0].selected == 1)
	{
		return "";
	}
	
	for (var i=0; i<location_select.length; i++)
	{
		// Check Selected locations
		if (location_select[i].selected == 1 && location_select[i].value != "")
		{
			var re = new RegExp("[-]");
			var value = location_select[i].value;
			
			// Get selected District4 values
			if (value.match(re))
			{
				d4_list[d4_list.length] = value;
			}
			// Whole District3 value selected
			else
			{
				var district3 = value;
				var re = new RegExp(district3 + "-");
				for (var j=i; j<location_select.length; j++)
				{
					// Remove Selected District4's
					if (String(location_select[j].value).match(re))
					{
						location_select[j].selected = 0;
					}
				}
			}
		}
	}
	
	return d4_list.join(",");
}





function validate_not_blank(field, name)
{
	// strip all spaces at start and end of line
	var regx_output = new String(field.value);
	var re1 = new RegExp("^[ ]*|([ ]*)\$", 'g');
	field.value = regx_output.replace(re1, "");
	
	if (field.value == "")
	{
		alert(format_str('The "%s" field cannot be blank.', name));
		focus_field(field);
		return false;
	}
	return true;
}





function validate_email_address(field, name, allow_name_in_address, display_error)
{
	if (typeof display_error == "undefined")
	{
		display_error = true;
	}
	
	// Get field value
	var fieldval = field.value;
	
	// Remove spaces before and after email
	fieldval = fieldval.replace(/^\\s*/, "");
	fieldval = fieldval.replace(/\\s*\$/, "");
	
	// Update field
	field.value = fieldval;
	
	// If "name <email>" format is available - get email address
	if (allow_name_in_address)
	{
		var a = fieldval.indexOf("<");
		var b = fieldval.indexOf(">");
		if (a < b)
		{
			fieldval = fieldval.substring(a + 1, b);
		}
	}
	
	// Initialize
	var msg		= "";
	var last_at	= fieldval.lastIndexOf("\@");
	var before	= fieldval.substr(0, last_at);
	var after	= fieldval.substr(last_at + 1, fieldval.length - last_at - 1);
	var reg;
	
	// CHECK: the @ character must exist
	if (last_at < 0)
	{
		msg = "There is no @ in your e-mail address.";
	}
	
	// CHECK: there must be at least one character preceeding and one character following @
	if (!msg)
	{
		if ((before.length < 1) || (after.length < 1))
		{
			msg = "Your e-mail address must contain at least 1 character in front of @.";
		}
	}
	
	// CHECK: characters below 32 are illegal
	if (!msg)
	{
		for (var i = 0; i < fieldval.length; i++)
		{
			var code = fieldval.charCodeAt(i);
			if (code < 32)
			{
				msg = "You have used an invalid character in your email address.";
				break;
			}
		}
	}
	
	// CHECK: the ".@" combination is illegal
	if (!msg)
	{
		if (before.substr(before.length - 1, 1) == ".")
		{
			msg = "Du har skrevet et ulovligt tegn før @.";
		}
	}
	
	// CHECK: the "@." combination is illegal
	if (!msg)
	{
		if (after.substr(0, 1) == ".")
		{
			msg = "A full stop cannot be the first character after @.";
		}
	}
	
	// CHECK: at least one "." is required in the host section
	if (!msg)
	{
		if (after.indexOf(".") < 0)
		{
			msg = "There is no full stop in your e-mail address.";
		}
	}
	
	// CHECK: "." cannot be the last character
	if (!msg)
	{
		if (after.lastIndexOf(".") == (after.length - 1))
		{
			msg = "A full stop cannot be the last character in an e-mail address.";
		}
	}
	
	// CHECK: the "-." combination is illegal following @
	if (!msg)
	{
		reg = /\\-{1}\\.{1}/;
		if (reg.test(after))
		{
			msg = "A dash  (-) cannot be placed in front of a full stop (.)";
		}
	}
	
	// CHECK: "-" cannot be the last character
	if (!msg)
	{
		if (after.lastIndexOf("-") == (after.length - 1))
		{
			msg = "A dash (-) cannot be the last character in an e-mail address.";
		}
	}
	
	// CHECK: certain characters preceeding @ must be escaped
	if (!msg)
	{
		// 1) remove all escaped characters
		// 2) all remaining special characters were not escaped - which is illegal
		before = before.replace(/\\\\{1}.{1}/g, "");
		reg = /[\\s<>()\\[\\]\\\\,;:@\\"]{1,}/;
		if (reg.test(before))
		{
			msg = "You have used a character that cannot be used in front of the @.";
		}
	}
	
	// CHECK: the characters following @ are restricted
	// ASCII Characters below 32, not allowed
	if (!msg)
	{
		reg = new RegExp("^[\\x00-\\x20]*\$");
		if (reg.test(after))
		{
			msg = "You have used a character that cannot be used after the @.";
		}
	}
	
	// If the address is illegal
	if ((msg) && (display_error = true))
	{
		alert(format_str("The e-mail address '%s' is incorrect:\n%s\n\nE-mail addresses are usually formatted in the following way:\n - name.surname@company.co.uk\n - username@internetserviceprovider.com\n - initials@serviceprovider.com\n   etc.", name, msg));
		focus_field(field);
		return false;
	}
	
	// The address seems to be in order
	return true;
}





function validate_username_password()
{
	var frm = document.this_page;
	var username_label = "Username";
	var password_1_label = "Password";
	var password_2_label = "Repeat password";
	
	// Define illegal characters for usr + pwd
	var illegal_char_array = new Array("<", ">", "'", '"', "\\\\");
	
	// USERNAME
	if (!validate_not_blank(frm.username, username_label))
		return false;
		
	if (frm.username.value.indexOf(" ") >= 0)
	{
		alert("User name cannot contain spaces.");
		focus_field(frm.username);
		return false;
	}
	
	if (frm.username.value.length > 20)
	{
		alert("Your user name is too long. Max. 20 characters.");
		focus_field(frm.username);
		return false;
	}
	
	if (frm.username.value.length < 6)
	{
		alert("Your username must contain at least 6 characters.");
		focus_field(frm.username);
		return false;
	}
	
	for (var i = 0; i < illegal_char_array.length; i++)
		if (frm.username.value.indexOf(illegal_char_array[i]) >= 0)
		{
			alert(format_str("Your user name cannot contain the character '%s'.", " " + illegal_char_array[i] + " "));
			focus_field(frm.username);
			return false;
		}
	
	// PASSWORD
	if (!validate_not_blank(frm.password_1, password_1_label))
		return false;
	if (!validate_not_blank(frm.password_2, password_2_label))
		return false;
	
	if (frm.password_1.value.indexOf(" ") >= 0)
	{
		alert("Password cannot contain spaces.");
		frm.password_1.value = "";
		frm.password_2.value = "";
		focus_field(frm.password_1);
		return false;
	}
	
	if (frm.password_1.value.length > 10)
	{
		alert("Your password is too long. Max. 10 characters.");
		frm.password_1.value = "";
		frm.password_2.value = "";
		focus_field(frm.password_1);
		return false;
	}
	
	if (frm.password_1.value.length < 6)
	{
		alert("Your password must contain at least 6 characters.");
		frm.password_1.value = "";
		frm.password_2.value = "";
		focus_field(frm.password_1);
		return false;
	}
	
	if (frm.password_1.value != frm.password_2.value)
	{
		alert("Passwords were not identical.");
		frm.password_1.value = "";
		frm.password_2.value = "";
		focus_field(frm.password_1);
		return false;
	}
	
	for (var i = 0; i < illegal_char_array.length; i++)
	{
		if (frm.password_1.value.indexOf(illegal_char_array[i]) >= 0)
		{
			alert(format_str("Your password cannot contain the character '%s'.", illegal_char_array[i]));
			frm.password_1.value = "";
			frm.password_2.value = "";
			focus_field(frm.password_1);
			return false;
		}
	}
	
	// CAPS-LOCK on both username and password is not accepted
	// - also handling extended characters like "æøå" which JavaScript ignores in Case functions
	if (frm.username.value == frm.username.value.toUpperCase())
		if (frm.username.value.toLowerCase() != frm.username.value.toUpperCase())
			if (frm.password_1.value == frm.password_1.value.toUpperCase())
				if (frm.password_1.value.toLowerCase() != frm.password_1.value.toUpperCase())
				{
					alert("Neither the user name nor the password can be written solely using upper-case letters.\\nTurn off the Caps-Lock facility by pressing the Caps-Lock key.");
					frm.password_1.value = "";
					frm.password_2.value = "";
					focus_field(frm.password_1);
					return false;
				}
	
	// USERNAME == PASSWORD
	if (frm.username.value.toUpperCase() == frm.password_1.value.toUpperCase())
	{
		alert("Your username and password cannot be identical.");
		frm.password_1.value = "";
		frm.password_2.value = "";
		focus_field(frm.password_1);
		return false;
	}
	
	// PASSWORD == "PASSWORD"
	if ( frm.password_1.value.toUpperCase() == "PASSWORD" )
	{
		alert("Your password cannot be \"password\".");
		frm.password_1.value = "";
		frm.password_2.value = "";
		focus_field(frm.password_1);
		return false;
	}
	
	return true;
}





function validate_user_data()
{
	var frm = document.this_page;
	var firstname_label = "Firstname";
	var surname_label = "Surname";
	var email_1_label = "Email";
	var email_2_label = "Repeat email";
	
	if (!validate_not_blank(frm.firstname, firstname_label))
		return false;
	if (!validate_not_blank(frm.surname, surname_label))
		return false;
	if (!validate_not_blank(frm.email_1, email_1_label))
		return false;
	if (!validate_not_blank(frm.email_2, email_2_label))
		return false;
	
	// Validate email address 1
	if (!validate_email_address(frm.email_1, frm.email_1.value))
		return false;
	
	// Compare with email address 2 (stripping spaces at start and end)
	var txt = frm.email_2.value;
	txt = txt.replace(/^\\s*/, "").replace(/\\s*\$/, "");
	if (frm.email_1.value != txt)
	{
		alert("The e-mail adresses were not identical");
		focus_field(frm.email_1);
		return false;
	}
	
	return true;
}





function user_terms_onkeypress(event)
{
	// Check if ENTER (and also SUBMIT on MAC)
	var char_code = (navigator.appName == "Netscape") ? event.which : event.keyCode;
	var isMac = (navigator.appVersion.indexOf("Mac") != -1)? 1 : 0;
	var is_ENTER = ((char_code == 13) || ((isMac == 1) && (char_code == 3)));
	if (is_ENTER)
	{
		return false;
	}
	
	// Netscape Navigator
	// - block all except extended keys (arrows, tab, return, etc)
	if (navigator.appName == "Netscape")
		return (event.which == 0);
	
	// Internet Explorer - block all keys
	return false;
}





function set_current_date()
{
	var currentDate = new Date();
	document.this_page.month.selectedIndex = currentDate.getMonth();
	
	set_days();
	document.this_page.day.selectedIndex = currentDate.getDate()-1;
}





function set_days()
{
	var currentDate = new Date();
	var y = currentDate.getYear();
	var m = document.this_page.month.selectedIndex;
	var d;
	
	if ( (m == 3) || (m == 5) || (m == 8) || (m == 10) )
	{
		days = 30;
	}
	else if (m == 1)
	{
		if ( (Math.floor(y/4) == (y/4)) && ((Math.floor(y/100) != (y/100)) || (Math.floor(y/400) == (y/400))) )
		{ days = 29; }
		else
		{ days = 28; }
	}
	else
	{
		days = 31;
	}
	
	if (days > document.this_page.day.length)
	{
		for (i=document.this_page.day.length; i<days; i++)
		{
			document.this_page.day.length = days;
			document.this_page.day.options[i].text = i + 1;
			document.this_page.day.options[i].value = i + 1;
		}
	}
	
	if (days < document.this_page.day.length)
	{
		document.this_page.day.length = days;
		if (document.this_page.day.selectedIndex == -1)
		{
			document.this_page.day.selectedIndex = days - 1;
		}
	}
}

function show_on_map(post_no, address, post_name)
{
	address = escape(address);
	post_name = escape(post_name);
	var map_string = "";
	map_string = "gmap.asp?post_no="+post_no+"&amp;address="+address+"%20"+post_no+"%20"+post_name;
	window.open(map_string);
}
