var phonePattern = /^[\+0-9-() ]+$/;var emailPattern = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;/* stupid ie6 */if (!Array.prototype.indexOf) {  Array.prototype.indexOf = function (obj, fromIndex) {    if (fromIndex == null) {        fromIndex = 0;    } else if (fromIndex < 0) {        fromIndex = Math.max(0, this.length + fromIndex);    }    for (var i = fromIndex, j = this.length; i < j; i++) {        if (this[i] === obj)            return i;    }    return -1;  };}google.load("jquery", "1.3");google.setOnLoadCallback(function() {	/* map for office page */	jQuery(function($) {		if ($('#location').size()) {			var mapsOnLoadCallback = function () {				var centre = new GLatLng(mapconf.lat, mapconf.long);						        if (GBrowserIsCompatible()) {			        $('#location').after('<div id="location_map"><h3>LOCATION MAP</h3><div id="map" style="width: 593px; height: 300px"></div></div>');			        var map = new GMap2($('#content #map').get(0));			        map.addControl(new GSmallMapControl());			        map.addControl(new GMapTypeControl());			        map.setCenter(centre, 14);			        var marker = new GMarker(map.getCenter());			        map.addOverlay(marker);			    }			}			google.load("maps", "2", {"callback" : mapsOnLoadCallback});		}	});	/* homepage navigation dropdowns */	if ($('#welcome form').size()) {			$('#welcome select').change( function() {			if ($(this).val()) {				document.location.href = $(this).val();			}			else {				return false;			}			});	}	/* global navigation dropdowns */	if ($('#navigation form').size()) {			$("#navigation select").change( function() {			if ($(this).val()) {				document.location.href = $(this).val();			}			else {				return false;			}			});	}	/* city search dropdowns on location pages */	if ($('#refine_city').size()) {			$("#refine_city select").change( function() {			if ($(this).val()) {				document.location.href = $(this).val();			}			else {				return false;			}			});	}		if ($("#sidebar #form form").length) {		$("#sidebar #form form").submit(checkCheckoutForm);		$("#checkout_form_status").hide();	}			/* Checkout form validation */		function checkCheckoutForm() {			$('#checkout_form_status').hide();		$('#sidebar form input').removeClass('error_field');		if ($("#first_name").val()=='' || $("#first_name").val()=='First name') {			formFail('checkout_form_status', 'Please enter your first name','first_name');return false;		}		else if ($("#last_name").val()=='' || $("#last_name").val()=='Last name') {			formFail('checkout_form_status', 'Please enter your last name','last_name');return false;		}		else if ($("#phone").val()=='' || !phonePattern.test($("#phone").val())) {			formFail('checkout_form_status', 'Please check your phone number is correct.','phone');			return false;		}		else if ($("#email").val()=='' || !emailPattern.test($("#email").val())) {			formFail('checkout_form_status', 'Please check your email is correct.','email');			return false;		}		else if ($("#num_people").val()=='') {			formFail('checkout_form_status', 'Please select the size requirements or choose "Not sure"','num_people');return false;		}		else if ($("#start_date").val()=='') {			formFail('checkout_form_status', 'Please select a preferred move-in date or choose "Not sure"','start_date');return false;		}		else if ($("#term_length").val()=='') {			formFail('checkout_form_status', 'Please select a term length or choose "Not sure"','term_length');return false;		}		formPassed('switch_form_status');	}		function formFail(messageContainer, problem, field) {		$('#'+field).addClass('error_field');		$('#'+messageContainer).html(problem);		$('#'+messageContainer).show();		return false;	}		function formPassed(messageContainer) {		$('#'+messageContainer).hide();	}			/* contact form */	if ($('#contact_form').size()) {			var enquiry_mode = 1;		$("#submit_btn").before('<span id="errors"></span>');		$("#type-rent").click( function() {			enquiry_mode=1;			$("#contact_form #comments dl").hide();			$("#contact_form #message").val('');			$("#contact_form #location_id").parent().prev().find('label').html('Approximate location you are looking in:');						$("#contact_form #location_id").parent().show().prev().show();			$("#contact_form #num_people").parent().show().prev().show();		});		$("#type-provide").click( function() {			enquiry_mode=2;					$("#contact_form #comments dl").hide();			$("#contact_form #message").val('');			$("#contact_form #location_id").parent().prev().find('label').html('Where is the office space located?');						$("#contact_form #location_id").parent().show().prev().show();			$("#contact_form #num_people").parent().hide().prev().hide();		});		$("#type-other").click( function() {			enquiry_mode=3;					$("#contact_form #comments dl").show();			$("#contact_form #location_id").parent().hide().prev().hide();			$("#contact_form #num_people").parent().hide().prev().hide();		});		$("#contact_form").submit( function() {			if ($("#contact_form #first_name").val()=='' || $("#contact_form #first_name").val()==' ') {				$("#errors").html('Please enter your first name or initial');				return false;			}			else if ($("#contact_form #last_name").val()=='' || $("#contact_form #last_name").val()==' ') {				$("#errors").html('Please enter your last name or initial');				return false;			}			else if ($("#contact_form #phone").val()=='' || $("#contact_form #phone").val()==' ') {				$("#errors").html('Please enter a phone number we can contact you on');				return false;			}			else if ($("#contact_form #email").val()=='' || !emailPattern.test($("#contact_form #email").val())) {				$("#errors").html('Please enter a valid email address');				return false;			}			else if (enquiry_mode==3 && ($("#contact_form #message").val()=='' || $("#contact_form #message").val()==' ')) {							$("#errors").html('Please enter a message');				return false;			}			else {				$("#errors").html('');			}		});	}			function form() {			$('.focus_label').each(function(){			$(this).prev('label').hide();		});		// check for compatible user agent		if (!document.getElementsByTagName) return false;		// first check there is a form		if (document.getElementById('first_name')) {			// define form fields			first_name_field=$('#first_name');			surname_field=$('#last_name');			// set initial default value			setDefault(first_name_field,$(this).prev('label').html());			setDefault(surname_field,$(this).prev('label').html());				// set behaviours for blur/focus			blurFirstname();blurSurname();			$(first_name_field).focus(function(){hideLabel(document.getElementById("first_name"), 'First name');});			$(first_name_field).blur(function(){blurFirstname()});			$(surname_field).focus(function(){				hideLabel(document.getElementById("last_name"), 'Last name');			});			$(surname_field).blur(function(){blurSurname()});		}				function setDefault(form_field, default_value) {			if ($(form_field).attr("value") == default_value) {				form_field.style.color = '#999';			}		}		function blurFirstname() {			showLabel(document.getElementById("first_name"), 'First name');		}				function blurSurname() {			showLabel(document.getElementById("last_name"), 'Last name');		}				function hideLabel(textField, initialValue) {			if (textField.value == initialValue) {				textField.style.color = '#000';				textField.value = '';			}		}				function showLabel(textField, initialValue) {			if (textField.value == '' || textField.value == ' ' || textField.value == initialValue) {				textField.style.color = '#999';				textField.value = initialValue;			}		}	}			jQuery(function($) {			form();				/* cart */		var bind, rebuild;				var action = window.location.href.replace(/#.*/, '')				bind = function () {			$('#list form, .cart_controls form').unbind('submit');			$('#list form, .cart_controls form').submit(function() {				var data = $(this).serialize();								$.ajax({					type: "POST", 					url: action, 					data: data, 					dataType: "json", 					success: function(json) {						rebuild(json, action, this);					}				});				return false;			});		};						rebuild = function(json, action, el) {			var html = [];						$('#list').remove();						if (json && json.length) {		        html.push('<div id="list"><strong>YOUR LIST</strong><ul>');		        		        $.each(json, function(index, item) {			        html.push('<li>');			        html.push('<a href="" title="view ' + item.name + '">' + item.name + ', ' + item.parent.name + '</a>');			        html.push('<form action="' + action + '" method="POST">');			        html.push('<input name="remove" type="hidden" value="' + item.office_id + '" />');			        html.push('<button name="button" type="submit"><span>Remove from list</span></button>');			        html.push('</form>'); 		    		html.push('</li>');		        });		        		        html.push('</ul></div>');		        		        $('#form').before(html.join(''));			}						$('.offices li').each(function() {				var id = $(this).attr('id').replace(/office_/, '');								if ($('#list [value="' + id + '"]').size()) {					if ($('form', this).size()) {						$(this).find('div.cart_controls').find('form').remove();						$(this).find('div.cart_controls').append('<div class="remove"><img src="/images/starofficespace/tick.gif" alt="check mark" class="tick" /> added to list. <strong>complete form</strong> <img src="/images/starofficespace/arrow-right.gif" alt="right-pointing arrow" /></div>');////////						$('.button[href="#checkout"]').click(function(){							$('#checkout #company_name').focus().addClass('focus');return false;						});////////					}				} else {					if (!$('form', this).size()) {						$(this).find('div.cart_controls').find('div').remove();						$(this).find('div.cart_controls').append('<div class="add"><form action="' + action + '#office_' + id + '" method="POST"><fieldset><input name="basket" type="hidden" value="' + id + '" />get full details and prices <img src="/images/starofficespace/arrow-right.gif" alt="right-pointing arrow" /><button name="button" type="submit"><span>add to list</span></button></fieldset></form></div>');					}				}			});						$('.cart_controls.listcontrol').each(function() {				var id = office_id;								if ($('#list [value="' + id + '"]').size()) {					if ($('form', this).size()) {						$(this).html('<div class="remove"><img src="/images/starofficespace/tick.gif" alt="check mark" class="tick" /> added to list. <strong>complete form</strong> <img src="/images/starofficespace/arrow-right.gif" alt="right-pointing arrow" /></div>');					}				} else {					if (!$('form', this).size()) {						$(this).html('<div class="add"><form action="' + action + '" method="POST"><fieldset><input name="basket" type="hidden" value="' + id + '" />get full details and prices <img src="/images/starofficespace/arrow-right.gif" alt="right-pointing arrow" /><button name="button" type="submit"><span>add to list</span></button></fieldset></form></div>');					}				}			});				        bind();		}				bind();	});});