		/* Break out of Frames */
		if(window.top != window) {
			window.top.location.href = location.href; 
		}
		var site_color = (location.href.match(/surreybiz\.net/))? "990099" : "cc9900";
		//var site_color = 990099;
		function urlencode(str) {
			str = escape(str);
			str = str.replace('+', '%2B');
			str = str.replace('%20', '+');
			str = str.replace('*', '%2A');
			str = str.replace('/', '%2F');
			str = str.replace('@', '%40');
			return str;
		}
		function link_out(obj) {
			// Function to log links leaving the site & their destination
			// Should send to 3rd Party eg. affiliates.4actions.co.uk
			// 3rd party script then sends the OK to proceed link_continue
			// Doesn't count new tabs / forced new window
			var c = location.href;
			var u = obj.href;
			var t = obj.title;
			var w = (obj.target && obj.target == "_blank")? "blank" : "self";
			var s = document.createElement('script');
			s.type = "text/javascript";
			s.src = "http://surrey-online.co.uk/stats/link.php?u=" + urlencode(u) + "&c=" + urlencode(c) + "&w=" + urlencode(w) + "&t=" + urlencode(t);
			document.getElementsByTagName('head').item(0).appendChild(s);
			if(w == "blank")
				return true;
			pause(2000);
			return true;
		}
		function link_continue(url, target) {
			if(target == "blank") {
				return false;
				w = screen.availWidth;
				h = screen.availHeight; 
				if(lwin = window.open(url,'_blank', 'height='+ h +', width='+ w +', top=0, left=0', false)) {
					return false;
				}
			}
			location.href = url;
			return false;
		}
		function show_window(url) {
			if(window.open(url,'_blank','height=500,width=500,top=250,left=250,resizable=0,location=no,scrollbars=1',false)) {
				return false;
			}
		}
		function $(id) {
			return document.getElementById(id);
		}
		function pause(millis) {
			var date = new Date();
			var curDate = null;
			
			do { curDate = new Date(); } 
			while(curDate-date < millis);
		}
		function expand_menu(obj, id) {
			if(obj.parentNode.className.match(/open/)) {
				obj.parentNode.className = obj.parentNode.className.replace(/\s?open$/, "");
				document.cookie = 'menu['+id+']=closed;path=/'; 
			} else {
				obj.parentNode.className += " open";
				document.cookie = 'menu['+id+']=open;path=/'; 
			}
		}
		// Expand / Collapse Registration Form
		var iExpandTimer = false;
		var register_box_status = 'closed';
		var contact_box_status = 'first_closed';
		function open_close_register_form() {
			box = $('register_form');
			current_height = box.style.height.replace(/[^0-9]/gi, "");
			clearTimeout(iExpandTimer);
			if(register_box_status == 'open') {
				box.style.overflow = 'hidden';
				box.style.display = 'block';
				register_box_status = 'closed';
				iExpandTimer = setTimeout('collapse(\'register_form\', \''+current_height+'\')', 10);
			} else {
				box.style.overflow = 'hidden';
				if(current_height == '' || current_height < 5) {
					box.style.height = '1px';
					current_height = 5;
				}
				box.style.display = 'block';
				register_box_status = 'open';
				iExpandTimer = setTimeout('expand(\'register_form\', \''+ current_height +'\', \'244\')', 10);
			}
			return false;
		}
		function set_captcha_url() {
			$('captcha_image').src = '/images/captcha.php?bg=e5e5e5&id=' + $('captcha_id').value;
			$('register_form_1').style.display='none';
			$('register_form_2').style.display='block';
			$('register_form_1').selectedIndex='0';
		}
		function open_close_contact_details(c) {
			// Restore if it's already been loaded
			if($('contact_details')) {
				if($('contact_details_bg')) {
					if($('contact_details_bg').style.display == '') {
						$('contact_details').style.display = 'none';
						$('contact_details_bg').style.display = 'none';
					} else {
						$('contact_details').style.display = 'block';
						$('contact_details_bg').style.display = '';
					}
					return false;
				} else {
					// Fade Out & Disable Everything Else
					var bg = document.createElement('div');
					bg.setAttribute('id', 'contact_details_bg');
					document.body.appendChild(bg);
					document.body.appendChild($('contact_details'));
				}
				$('contact_details').style.display = 'block';
				
				u = location.href;
				u = u.replace(/http:\/\/(www\.)?(localhost\/surrey-(online|biz)|surreybiz\.net|surrey-online\.co\.uk)/, '');
				t = "details";
				p = "landing";
				var s = document.createElement('script');
					s.type = "text/javascript";
					s.src = "http://surrey-online.co.uk/stats/contact.php?c=" + urlencode(c) + "&t=" + urlencode(t) + "&p=" + urlencode(p) + "&u=" + urlencode(u);
				document.getElementsByTagName('head').item(0).appendChild(s);
			}
			return false;
		}
		function expand(id, cur, max) {
			cur = parseInt(cur);
			max = parseInt(max);
			var box = $(id);
			if(cur == max) {
				box.style.height = cur + 'px';
				return;
			}
			box.style.height = cur + 'px';
			box.style.display = 'block';
			cur+=15;
			if(cur > max)
				cur = max;
			base_speed = (arguments[3])? arguments[3] : 100;
			percent = cur / max;
			speed = percent / base_speed;
			if(speed > 10)
				speed = 10;
			iExpandTimer = setTimeout('expand(\''+ id +'\', \''+ cur +'\', \''+ max +'\', \''+ base_speed +'\')',speed);
			
		}
		function collapse(id, cur) {
			var min = (arguments[2])? arguments[2] : -10;
			var box = $(id);
			cur = parseInt(cur);
			if(cur <= 1) {
				box.style.display = 'none';
				return;
			}
			box.style.height = cur + 'px';
			cur-=50;
			base_speed = (arguments[3])? arguments[3] : 150;
			speed = cur - min;
			if(speed > 10)
				speed = 10;
			speed = base_speed - speed;
			speed = base_speed;
			if(cur >= min)
				iExpandTimer = setTimeout('collapse(\''+ id +'\', \''+ cur +'\', \''+ min +'\', \''+ base_speed +'\')', speed);
			else
				box.style.height = min + 'px';
		}
		// Recent Posts - View Next / Previous
		var recent_posts_index = 1;
		function view_more_recent_posts(n) {
			if($('recent_' + (recent_posts_index+n))) {
				$('recent_' + recent_posts_index).style.display = 'none';
				recent_posts_index += n;
				$('recent_' + recent_posts_index).style.display = 'block';
			}
			return false;
		}
		function show_all_search_results(id, obj) {
			clearTimeout(iExpandTimer);
			var desired_height = ($(id).getElementsByTagName('li').length * 58) - 4;
			var current_height = $(id).style.height.replace(/[^0-9]/gi, "");
			if(desired_height == current_height) {
				$(id).style.height = '172px';
				location.href = location.href.replace(/(#\w+)?$/gi, '') + '#' + id.replace(/_ul$/gi, '');
				/* Switch Image */
				obj.firstChild.src = obj.firstChild.src.replace(/collapse/, 'expand');
				obj.firstChild.alt = 'View More Results like These';
				obj.firstChild.title = 'View More Results like These';
			} else {
				iExpandTimer = setTimeout('expand(\''+ id +'\', \''+ current_height +'\', \''+ desired_height +'\', \'10\')', 10);
				/* Switch Image */
				obj.firstChild.src = obj.firstChild.src.replace(/expand/, 'collapse');
				obj.firstChild.alt = 'View Less Results like These';
				obj.firstChild.title = 'View Less Results like These';
			}
		}

		function get_position(id) {
			var top = 0;
			var left = 0;
			if(typeof id == "string")
				var obj = get(id, 'id');
			else if(typeof id == "object")
				var obj = id;
			else
				return Array(0, 0);
			if (obj.offsetParent) {
				left = obj.offsetLeft;
				top = obj.offsetTop;
				while (obj = obj.offsetParent) {
					left += obj.offsetLeft;
					top += obj.offsetTop;
				}
			}
			return Array(top, left);
		}
		function validcontact(form) {
			errors = '';
			if(form.name.value=='') {
			  errors += "You have not entered your name\n";
			}
			 if(form.email.value=='') {
			  errors += "You have not entered your email address\n";
			}
			 if(form.message.value=='') {
			  errors += "You have not entered a message\n";
			}
			 if(form.terms.checked!=true) {
			  errors += "You have not agreed to our terms and conditions\n";
			}
			if(errors!='') { 
			  alert(errors);
			  return false; 
			}
			return true; 
		}
		function validfriend(form) {
			errors = '';
			if(form.name.value=='') {
			  errors += "You have not entered your name\n";
			}
			 if(form.email.value=='') {
			  errors += "You have not entered your email address\n";
			}
			 if(form.message.value=='') {
			  errors += "You have not entered a message\n";
			}
			   if(form.friendemail.value=='') {
			  errors += "You have not entered an email to send this page to\n";
			}
			if(form.terms.checked!=true) {
			  errors += "You have not agreed to our terms and conditions\n";
			}
			if(errors!='') { 
				alert(errors);
				return false; 
			}
			return true; 
		}
		var base_url = '/';
		function quick_contact_form(name, url, close) {
			type = (arguments[3])? arguments[3] : 'standard';
			contact_form = '<div class="quick_contact">';
			contact_form += '<div class="quick_contact_title" style="margin-left:19px!important;">';
			contact_form += 'Quick Contact <span id="quick_contact_company_name">'+ name +'</span>';
			contact_form += '</div>';
			contact_form += '</div>';
			contact_form += '<div class="quick_contact_message">';
			contact_form += '<form action="'+ url +'" method="post" id="quick_contact_form" onSubmit="return validcontact(this);">';
			if(type == 'wide')
				contact_form += '<div class="quick_contact_left">';
			contact_form += '<input type="hidden" name="position" value="'+ type +'" class="blank" />';
			contact_form += '<input type="hidden" name="page" value="'+ location.href +'" class="blank" />';
			contact_form += '<label for="name">your name</label>';
			contact_form += '<input type="text" name="name" id="name" value="'+ so_displayname +'" />';
			contact_form += '<label for="email">your email address</label>';
			contact_form += '<input type="text" name="email" id="email" value="'+ so_email +'" />';
			contact_form += '<label for="telephone">your telephone number</label>';
			contact_form += '<input type="text" name="telephone" id="telephone" value="" />';
			if(type == 'wide')
				contact_form += '</div><div class="quick_contact_right">';
			contact_form += '<label for="message">your message</label>';
			contact_form += '<textarea name="message" id="message" rows="5" cols="20"></textarea>';
			if(type == 'wide')
				contact_form += '</div>';
			contact_form += '<br style="clear: both;" />';
			contact_form += '<div class="terms_agree">';
			contact_form += '<input type="checkbox" name="terms" id="terms" value="1" class="checkbox" />';
			contact_form += '<a href="'+ base_url +'popup/terms-and-conditions" target="_blank" onclick="return show_window(this.href);">I agree with surrey-online.CO.UK<br />';
			contact_form += 'Terms &amp; Conditions</a>';
			contact_form += '</div>';
			contact_form += '<br style="line-height: 12px;" />';
			contact_form += '<input type="image" src="/images/contact/submit.png" class="blank" style="float: left;" />';
			if(close)
				contact_form += '<input type="image" src="/images/contact/contact-close.png" onclick="close_quick_contact(); return false;" class="blank" style="float: right; position: relative; right: 18px;" />';
			contact_form += '<br style="clear: both;" />';
			contact_form += '</form>';
			contact_form += '</div>';
			contact_form += '<div class="quick_contact_footer">&nbsp;</div>';
			return contact_form;
		}
		
		function quick_email_friend() {
			contact_form = '<div class="quick_contact">';
			contact_form += '<div class="quick_contact_title" style="margin-left:19px!important;">';
			contact_form += 'Email to a friend';
			contact_form += '</div>';
			contact_form += '</div>';
			contact_form += '<div class="quick_contact_message">';
			contact_form += '<form action="/contact/friend" method="post" id="quick_email_friend" onSubmit="return validfriend(this);">';
			contact_form += '<div class="quick_contact_left">';
			contact_form += '<input type="hidden" name="title" value="'+ document.title +'" class="blank" />';
			contact_form += '<input type="hidden" name="page" value="'+ location.href +'" class="blank" />';
			contact_form += '<label for="name">your name</label>';
			contact_form += '<input type="text" name="name" id="name" value="'+ so_displayname +'" />';
			contact_form += '<label for="email">your email address</label>';
			contact_form += '<input type="text" name="email" id="email" value="'+ so_email +'" />';
			contact_form += '<label for="email">friend\'s email</label>';
			contact_form += '<input type="text" name="friendemail" id="friendemail"  />';
			contact_form += '</div><div class="quick_contact_right">';
			contact_form += '<label for="message">your message</label>';
			contact_form += '<textarea name="message" id="message" rows="5" cols="20"></textarea>';
			contact_form += '</div>';
			contact_form += '<br style="clear: both;" />';
			contact_form += '<div class="terms_agree">';
			contact_form += '<input type="checkbox" name="terms" value="1" class="checkbox" />';
			contact_form += '<a href="/popup/terms-and-conditions" target="_blank" onclick="return show_window(this.href);">I agree with surrey-online.CO.UK<br />';
			contact_form += 'Terms &amp; Conditions</a>';
			contact_form += '</div>';
			contact_form += '<br style="line-height: 12px;" />';
			contact_form += '<input type="image" src="/images/contact/submit.png" class="blank" style="float: left;" />';
			contact_form += '<input type="image" src="/images/contact/contact-close.png" onclick="close_friend_contact(); return false;" class="blank" style="float: right; position: relative; right: 18px;" />';
			contact_form += '<br style="clear: both;" />';
			contact_form += '</form>';
			contact_form += '</div>';
			contact_form += '<div class="quick_contact_footer">&nbsp;</div>';
			return contact_form;
		}
		
		function quick_friend(obj, name, url) {
			var position = get_position(obj);
				position[0] += (arguments[3])? arguments[3] : 0;
				position[1] += (arguments[4])? arguments[4] : 0;
			if($('friend_contact_holder')) {
				// Update Existing Form
				form_holder = $('friend_contact_holder');
					form_holder.style.display = '';
					form_holder.style.top = position[0] + 'px';
					form_holder.style.left = position[1] + 'px';
			} else {
				// Append new form to the page & try to position it
				var form_holder = document.createElement('div');
					form_holder.setAttribute('id', 'friend_contact_holder');
					form_holder.style.top = position[0] + 'px';
					form_holder.style.left = position[1] + 'px';
					form_holder.innerHTML = quick_email_friend();
				document.body.appendChild(form_holder);
			}
			return false;
		}
		function close_friend_contact() {
			if($('friend_contact_holder')) {
				$('friend_contact_holder').style.display = 'none';
			}
		}

		function quick_contact(obj, name, url) {
			var position = get_position(obj);
				position[0] += (arguments[3])? arguments[3] : 0;
				position[1] += (arguments[4])? arguments[4] : 0;
				type = (arguments[5])? arguments[5] : 'wide';
			if($('quick_contact_holder_' + type)) {
				// Update Existing Form
				$('quick_contact_company_name').innerHTML = name + '&hellip;';
				$('quick_contact_form').action = url;
				form_holder = $('quick_contact_holder_' + type);
					form_holder.style.display = '';
					form_holder.style.top = position[0] + 'px';
					form_holder.style.left = position[1] + 'px';
			} else {
				// Append new form to the page & try to position it
				var form_holder = document.createElement('div');
					form_holder.setAttribute('id', 'quick_contact_holder_' + type);
					form_holder.style.top = position[0] + 'px';
					form_holder.style.left = position[1] + 'px';
					form_holder.innerHTML = quick_contact_form(name, url, true, type);
				document.body.appendChild(form_holder);
			}
			return false;
		}
		function close_quick_contact() {
			if($('quick_contact_holder_wide')) {
				$('quick_contact_holder_wide').style.display = 'none';
			}
			if($('quick_contact_holder_standard')) {
				$('quick_contact_holder_standard').style.display = 'none';
			}
		}
		
		// Town Page - Pop-up Map
		function show_town_map(town_id, lat, lng) {
			// Restore if it's already been loaded
			if($('town_map')) {
				$('town_map').style.display = '';
				$('town_map_bg').style.display = '';
				return;
			}
			// Fade Out & Disable Everything Else
			var bg = document.createElement('div');
				bg.setAttribute('id', 'town_map_bg');
				document.body.appendChild(bg);
			
			// Append a new div holding the map
			var m = document.createElement('div');
				m.setAttribute('id', 'town_map');
				m.innerHTML = '<iframe frameborder="0" scrolling="no" src="'+ base_url +'iframe.php?town='+town_id+'&lat='+ lat +'&lng='+ lng +'"></iframe><br style="clear: both;" /><div id="town_map_close"><a onclick="hide_town_map();">Close Map <img src="'+ base_url +'images/up-arrow.png" alt="Close Map" /></a></a></div>';
				document.body.appendChild(m);
		}
		function hide_town_map() {
			$('town_map').style.display = 'none';
			$('town_map_bg').style.display = 'none';
		}
		
		function pagesending(form) {
			if(document.getElementsByName(form) && document.getElementsByName(form).item(0)) {
				var bg = document.createElement('div');
					bg.setAttribute('id', 'town_map_bg');
					document.body.appendChild(bg);
				var div = document.createElement('div');
					div.setAttribute('id', 'town_map');
					div.style.position = 'absolute';
					window.scroll(0,0);
					div.style.top = '175px';
					div.style.zIndex = '1700';
					div.style.left = '50%';
					div.style.width = '300px';
					div.style.height = '150px';
					div.style.marginLeft = '-150px';
					div.style.padding = '0px';
					div.style.borderWidth = '4px';
					div.style.borderStyle = 'solid';
					div.style.borderColor = '#4C4C4C';
					div.style.backgroundColor = '#ccc';
					div.innerHTML = '<br /><br /><center><strong>Loading...</strong></center><br /><br /><center><img border="0" height="50" width="300" src="/images/loading.gif" /></center>';
				document.body.appendChild(div);
				document.body.style.overflow = 'hidden';
				document.getElementsByName(form).item(0).submit();
				return false;
			}
		}
		function loadimage(func, form) {
			img1 = new Image();
			img1.src = base_url + 'images/loading.gif';
			document.body.appendChild(img1);
			eval(func +"('"+form+"');");
			return true;
		}

function validate_registration(which) {
	errors = '';
	var formname = document.getElementById("the_amazing_reg_form" + which);
	var name = formname.username.value;
	var pass1 = formname.password1.value;
	var passlen = formname.password1.value.length;
	var pass2 = formname.password2.value;
	var email = formname.email.value;
	var tos = formname.tos.checked;
	var captcha_id = formname.captcha_id.value;
	if(captcha_id=='') { errors += 'Please fill in the captcha image field. This checks you are human.\n'; }
	if(name=='') { errors += 'Please enter your name.\n'; }
	if(email=='') { errors += 'Please enter your email address.\n'; }
	else if(!email.match(/^(\w|\.|-)+@(\w|-)+\.((\w|-)+\.)?(co|com|org|net|info|biz|tv|mobi|me|ws|fm|org|sch|ac|gov|us)(\.uk)?$/i)) { errors += 'Your email address is invalid.\n'; }
	if(tos!=true) { errors += 'Please agree to our terms and conditions.\n'; }
	if(pass1=='' || pass2=='') { errors += 'Please enter a password.\n'; } else {
		if(passlen < 5) { errors += 'Your password must be at least 6 characters long'; }
		if(pass1!=pass2) { errors += 'Your passwords do not match.\n'; }
	}
	if(errors=='') {
		return true;
	} else {
		alert(errors);
		return false;
	}
}
function validate_year(obj) {
	if(obj.value == '') {
		alert('Please enter your full date of birth. This is required for us to comply with COPPA');
		return false;
	} else if(isNaN(obj.value)) {
		alert('Please enter your full date of birth. This is required for us to comply with COPPA');
		return false;
	} else if(obj.value < 10) {
		obj.value = 20 + obj.value;
	} else if(obj.value < 100) {
		obj.value = 19 + obj.value;
	}
}

var highlighting = false;
var highlight_timer;
function clear_map_category_highlight() {
	var icons = $('map').getElementsByTagName('img');
	for(i=0; i<icons.length; i++) {
		icons.item(i).style.opacity = '1';
		icons.item(i).style.filter = 'Alpha(opacity=100);';
	}
}
function highlight_map_category(id) {
	clearTimeout(highlight_timer);
	highlighting = true;
	var icons = $('map').getElementsByTagName('img');
	map_icon_reg = new RegExp('map_icons\/(.+?)\.png', 'i');
	for(i=0; i<icons.length; i++) {
		if(icons.item(i).src.match(map_icon_reg)) {
			if(RegExp.$1 == id) {
				icons.item(i).style.opacity = '1';
				icons.item(i).style.filter = 'Alpha(opacity=100);';
				icons.item(i).style.zIndex = (1000 + parseInt(icons.item(i).style.zIndex));
				icons.item(i).parentNode.style.zIndex = (1000 + parseInt(icons.item(i).parentNode.style.zIndex));
			} else {
				icons.item(i).style.opacity = '0.35';
				icons.item(i).style.filter = 'Alpha(opacity=35);';
			}
		}
	}
}
function unhighlight_map_category(id) {
	highlight_timer = setTimeout("clear_map_category_highlight()", 3500);
}
