window.addEvent('domready', function() {


	/* DISABLE THE TABBING BETWEEN FIELDS - IT BREAKS THE SLIDING */

	document.onkeypress = function(event) {
		if (event.keyCode==13) {
			return false;
		}
	}
	
	function KeyTest() {
		if (event.keyCode==9) {
			return false;
		}
	}
	$$('input.notab').addEvents({
		keydown: function(event) {
			return KeyTest()
		}
	})
	$$('select.notab').addEvents({
		keydown: function(event) {
			return KeyTest()
		}
	})
	
	/* SET UP FORM FROM COOKIES */
	
		// slide 2
		
			if (val1 = notNull(Cookie.read('friend1_email'))) {$('form[friend1][email]').value = val1;}
			if (val1 = notNull(Cookie.read('friend1_name_first'))) {$('form[friend1][name_first]').value = val1;}
			if (val1 = notNull(Cookie.read('friend1_name_last'))) {$('form[friend1][name_last]').value = val1;}
			if (val1 = notNull(Cookie.read('friend1_address1'))) {$('form[friend1][address1]').value = val1;}
			if (val1 = notNull(Cookie.read('friend1_address2'))) {$('form[friend1][address2]').value = val1;}
			if (val1 = notNull(Cookie.read('friend1_town'))) {$('form[friend1][town]').value = val1;}
			if (val1 = notNull(Cookie.read('friend1_county'))) {
				selectMenu('form[friend1][county]',val1);
			}
			if (val1=='OTHER') {
				countyOtherToggle('friend1','on');
			}
			if (val1 = notNull(Cookie.read('friend1_county_extra'))) {$('form[friend1][county_extra]').value = val1;}
			if (val1 = notNull(Cookie.read('friend1_postcode'))) {$('form[friend1][postcode]').value = val1;}
			if (val1 = notNull(Cookie.read('friend1_country'))) {
				selectMenu('form[friend1][country]',val1);
			}
			if (val1 = notNull(Cookie.read('friend1_tel'))) {$('form[friend1][tel]').value = val1;}
		
		// slide 3
		
			if (val1 = notNull(Cookie.read('friend2_email'))) {$('form[friend2][email]').value = val1;}
			if (val1 = notNull(Cookie.read('friend2_name_first'))) {$('form[friend2][name_first]').value = val1;}
			if (val1 = notNull(Cookie.read('friend2_name_last'))) {$('form[friend2][name_last]').value = val1;}
			if (val1 = notNull(Cookie.read('friend2_address1'))) {$('form[friend2][address1]').value = val1;}
			if (val1 = notNull(Cookie.read('friend2_address2'))) {$('form[friend2][address2]').value = val1;}
			if (val1 = notNull(Cookie.read('friend2_town'))) {$('form[friend2][town]').value = val1;}
			if (val1 = notNull(Cookie.read('friend2_county'))) {
				selectMenu('form[friend2][county]',val1);
			}
			if (val1=='OTHER') {
				countyOtherToggle('friend2','on');
			}
			if (val1 = notNull(Cookie.read('friend2_county_extra'))) {$('form[friend2][county_extra]').value = val1;}
			if (val1 = notNull(Cookie.read('friend2_postcode'))) {$('form[friend2][postcode]').value = val1;}
			if (val1 = notNull(Cookie.read('friend2_country'))) {
				selectMenu('form[friend2][country]',val1);
			}
			if (val1 = notNull(Cookie.read('friend2_tel'))) {$('form[friend2][tel]').value = val1;}
			
		// slide 4
		
			if (val1 = notNull(Cookie.read('billing_donation'))) {$('form[billing][donation]').value = val1;}
			var billing_who = notNull(Cookie.read('billing_who'));
			if (billing_who) {
				choosePersonSwitch('billing',billing_who);
			}
			if (billing_who=='other') {
						
				if (val1 = notNull(Cookie.read('billing_email'))) {$('form[billing][email]').value = val1;}
				if (val1 = notNull(Cookie.read('billing_name_first'))) {$('form[billing][name_first]').value = val1;}
				if (val1 = notNull(Cookie.read('billing_name_last'))) {$('form[billing][name_last]').value = val1;}
				if (val1 = notNull(Cookie.read('billing_address1'))) {$('form[billing][address1]').value = val1;}
				if (val1 = notNull(Cookie.read('billing_address2'))) {$('form[billing][address2]').value = val1;}
				if (val1 = notNull(Cookie.read('billing_town'))) {$('form[billing][town]').value = val1;}
				if (val1 = notNull(Cookie.read('billing_county'))) {
					selectMenu('form[billing][county]',val1);
				}
				if (val1=='OTHER') {
					countyOtherToggle('billing','on');
				}
				if (val1 = notNull(Cookie.read('billing_county_extra'))) {$('form[billing][county_extra]').value = val1;}
				if (val1 = notNull(Cookie.read('billing_postcode'))) {$('form[billing][postcode]').value = val1;}
				if (val1 = notNull(Cookie.read('billing_country'))) {
					selectMenu('form[billing][country]',val1);
				}
				if (val1 = notNull(Cookie.read('billing_tel'))) {$('form[billing][tel]').value = val1;}
			
			} else {
				$$('.BillingName').set('disabled',true);
			}
		
		// slide 5
		
			var renewal_who = notNull(Cookie.read('renewal_who'));
			if (renewal_who) {
				choosePersonSwitch('renewal',renewal_who);
			}
			
		// slide 6
		
			var delivery_who = notNull(Cookie.read('delivery_who'));
			if (delivery_who) {
				choosePersonSwitch('delivery',delivery_who);
			}
			if (delivery_who=='other') {
			
				if (val1 = notNull(Cookie.read('delivery_email'))) {$('form[delivery][email]').value = val1;}
				if (val1 = notNull(Cookie.read('delivery_name_first'))) {$('form[delivery][name_first]').value = val1;}
				if (val1 = notNull(Cookie.read('delivery_name_last'))) {$('form[delivery][name_last]').value = val1;}
				if (val1 = notNull(Cookie.read('delivery_address1'))) {$('form[delivery][address1]').value = val1;}
				if (val1 = notNull(Cookie.read('delivery_address2'))) {$('form[delivery][address2]').value = val1;}
				if (val1 = notNull(Cookie.read('delivery_town'))) {$('form[delivery][town]').value = val1;}
				if (val1 = notNull(Cookie.read('delivery_county'))) {$('form[delivery][county]').value = val1;}
				if (val1 = notNull(Cookie.read('delivery_county'))) {
					selectMenu('form[delivery][county]',val1);
				}
				if (val1=='OTHER') {
					countyOtherToggle('delivery','on');
				}
				if (val1 = notNull(Cookie.read('delivery_county_extra'))) {$('form[delivery][county_extra]').value = val1;}
				if (val1 = notNull(Cookie.read('delivery_postcode'))) {$('form[delivery][postcode]').value = val1;}
				if (val1 = notNull(Cookie.read('delivery_country'))) {
					selectMenu('form[delivery][country]',val1);
				}
				if (val1 = notNull(Cookie.read('delivery_tel'))) {$('form[delivery][tel]').value = val1;}
			}
		
		// slide 7
		
			var giftaid_yes = notNull(Cookie.read('giftaid_yes'));
			if (giftaid_yes) {
				blocking('giftaid','on');
				$('form[giftaid][yes]').checked = true;
			}
			
			if (val1 = notNull(Cookie.read('giftaid_name_first'))) {$('form[giftaid][name_first]').value = val1;}
			if (val1 = notNull(Cookie.read('giftaid_name_last'))) {$('form[giftaid][name_last]').value = val1;}
			if (val1 = notNull(Cookie.read('giftaid_address1'))) {$('form[giftaid][address1]').value = val1;}
			if (val1 = notNull(Cookie.read('giftaid_address2'))) {$('form[giftaid][address2]').value = val1;}
			if (val1 = notNull(Cookie.read('giftaid_town'))) {$('form[giftaid][town]').value = val1;}
			if (val1 = notNull(Cookie.read('giftaid_county'))) {
				selectMenu('form[giftaid][county]',val1);
			}
			if (val1 = notNull(Cookie.read('giftaid_postcode'))) {$('form[giftaid][postcode]').value = val1;}
				
	
	/* PREV/NEXT BUTTONS */
	
		$$('a.prev').addEvents({
			mousedown: function(event) {
				var old_margin = $('slide_track').getStyle('margin-left');
				old_margin = old_margin.replace('px','');
				var slide = ((0-parseInt(old_margin))/500)+1;
				new_margin = parseInt(old_margin)+500;
				if (new_margin>0) {
					new_margin = 0;
				}
				//alert(old_margin+' : '+new_margin);
				eek = slider(old_margin,new_margin);
				eek = processSlide(slide);
			}
		});
		
		$$('a.next').addEvents({
			mousedown: function(event) {
				var old_margin = $('slide_track').getStyle('margin-left');
				old_margin = old_margin.replace('px','');
				var slide = ((0-parseInt(old_margin))/500)+1;
				
				// if the slide checks out, go to next stage
				var slideOK = checkSlide(slide);
				if (slideOK) {
					new_margin = parseInt(old_margin)-500;
					//alert(old_margin+' : '+new_margin);
					eek = slider(old_margin,new_margin);
					eek = processSlide(slide);
				} else {
					alert('Sorry, you might need to check all sections of the form are completed');
				}
			}
		});
		
		$$('a.gotopayment').addEvents({
			mousedown: function(event) {
				var slideOK = checkSlide('7');
				if (slideOK) {
					document.forms['giveusyamoney'].submit();
				} else {
					alert('Sorry, you might need to check all sections of the form are completed');
				}
			}
		});
	
	/* STEP 1,2,3 BUTTONS */
	
		var stepsCont = $$('.steps');
		var stepslength = stepsCont.length;
		
		for (i=0;i<stepslength;i++) {
			stepsLinks = stepsCont[i].getChildren('a');
			stepsLinks.addEvents({
				mousedown: function(event) {
					event.stop();
					var old_margin = $('slide_track').getStyle('margin-left');
					old_margin = old_margin.replace('px','');
					var thisSlide = this.getProperty('href');
					thisSlide = thisSlide.replace('#slide','');
					new_margin = 0-(thisSlide-1)*500
					slider(old_margin,new_margin);
				}
			})
		};
	
});


/* EASY SELECT */


	function selectMenu(selName,selValue) {
	
		// check the select option is correct
		if (document.forms['giveusyamoney'].elements[selName].value != selValue) {
			var thisForm = document.forms['giveusyamoney'];
			options = document.forms['giveusyamoney'].elements[selName].options;
			optionsLength = options.length;
			for (i=0;i<optionsLength;i++) {
				if (thisForm.elements[selName].options[i].value == selValue) {
					thisForm.elements[selName].options[i].selected = true;
				} else {
					thisForm.elements[selName].options[i].selected = false;
				}
			}
		}
		
	}


/* SORT OUT "COUNTY EXTRA" INPUT */

	function countyOtherCheck(slideForm) {
	
		var thisSelection = $('form['+slideForm+'][county]').value;
		
		if (thisSelection=='OTHER') {
			countyOtherToggle(slideForm,'on');
		} else {
			countyOtherToggle(slideForm,'off');
		}
	
	}

	function countyOtherToggle(slideForm,onoff) {
	
		if (onoff=='on') {
			$('form['+slideForm+'][county_extra]').setStyle('display','inline');
		} else {
			$('form['+slideForm+'][county_extra]').value = '';
			$('form['+slideForm+'][county_extra]').setStyle('display','none');
		}
	
	}
		

/* SLIDE ANIMATION */
			
	function jumpToSlide(slide) {
		var old_margin = $('slide_track').getStyle('margin-left');
		old_margin = old_margin.replace('px','');
		new_margin = 0-(slide-1)*500
		slider(old_margin,new_margin);
	}
	
	function slider(old_margin,new_margin) {
		var myFx = new Fx.Tween($('slide_track'));
		myFx.start('margin-left', old_margin, new_margin);
	}
	

/* CHECK A SLIDE */

		
	function checkSlide(slide) {
	
		function checkNow(fields) {
			var valNow = new validate('giveusyamoney', fields, { 
				useAjaxSubmit:false
			});
			$each(fields, function(type, el){
				if($(el) != null){
					valNow.check($(el), type);
				}
			}.bind(this));
						if (valNow.errorinform) {
				return false;
			}
			return true;
		}
		
		// validate 2
		
		if (slide==2) {
			var fields = {
				'form[friend1][email]':			'Required Email',
				'form[friend1][name_first]':	'Required',
				'form[friend1][name_last]':		'Required',
				'form[friend1][address1]':		'Required',
				'form[friend1][town]':			'Required',
				'form[friend1][county]':		'Required',
				'form[friend1][postcode]':		'Required',
				'form[friend1][country]':		'Required'
			};
			return checkNow(fields);
			
		// validate 3
		
		} else if (slide==3) {
			var fields = {
				'form[friend2][email]':			'Required Email',
				'form[friend2][name_first]':	'Required',
				'form[friend2][name_last]':		'Required',
				'form[friend2][address1]':		'Required',
				'form[friend2][town]':			'Required',
				'form[friend2][county]':		'Required',
				'form[friend2][postcode]':		'Required',
				'form[friend2][country]':		'Required'
			};
			return checkNow(fields);
			
		// validate 4
		
		} else if (slide==4) {
			if ($('form[billing][who]').value=='other') {
				var fields = {
					'form[billing][email]':			'Required Email',
					'form[billing][name_first]':	'Required',
					'form[billing][name_last]':		'Required',
					'form[billing][address1]':		'Required',
					'form[billing][town]':			'Required',
					'form[billing][county]':		'Required',
					'form[billing][postcode]':		'Required',
					'form[billing][country]':		'Required',
					'form[billing][donation]':		'Numeric'
				};
			} else {
				var fields = {
					'form[billing][who]':			'Required',
					'form[billing][donation]':		'Numeric'
				};
			}
			return checkNow(fields);
			
		// validate 5
		
		} else if (slide==5) {
			var fields = {
				'form[renewal][who]':			'Required',
				'form[billing][donation]':		'Numeric'
			};
			return checkNow(fields);
			
		// validate 6
		
		} else if (slide==6) {
			if ($('form[delivery][who]').value=='other') {
				var fields = {
					'form[delivery][email]':			'Required Email',
					'form[delivery][name_first]':	'Required',
					'form[delivery][name_last]':		'Required',
					'form[delivery][address1]':		'Required',
					'form[delivery][town]':			'Required',
					'form[delivery][county]':		'Required',
					'form[delivery][postcode]':		'Required',
					'form[delivery][country]':		'Required'
				};
			} else {
				var fields = {
					'form[delivery][who]':			'Required'
				};
			}
			return checkNow(fields);
			
		// validate 7
		
		} else if (slide==7) {
			if ($('form[giftaid][yes]').checked==true) {
				var fields = {
					'form[giftaid][name_first]':	'Required',
					'form[giftaid][name_last]':		'Required',
					'form[giftaid][address1]':		'Required',
					'form[giftaid][town]':			'Required',
					'form[giftaid][county]':		'Required',
					'form[giftaid][postcode]':		'Required'
				};
				return checkNow(fields);
			}
			
		}
		
		return true;
	
		
	}



/* PROCESS A SLIDE */


	function processSlide(slide) {
		
		if (slide==2) {
			
			// short term cookie it
			Cookie.write('friend1_email',$('form[friend1][email]').value);
			Cookie.write('friend1_name_first',$('form[friend1][name_first]').value);
			Cookie.write('friend1_name_last',$('form[friend1][name_last]').value);
			Cookie.write('friend1_address1',$('form[friend1][address1]').value);
			Cookie.write('friend1_address2',$('form[friend1][address2]').value);
			Cookie.write('friend1_town',$('form[friend1][town]').value);
			Cookie.write('friend1_county',$('form[friend1][county]').value);
			Cookie.write('friend1_county_extra',$('form[friend1][county_extra]').value);
			Cookie.write('friend1_postcode',$('form[friend1][postcode]').value);
			Cookie.write('friend1_country',$('form[friend1][country]').value);
			Cookie.write('friend1_tel',$('form[friend1][tel]').value);
	
			// set up all instances of this name
			var appending = ' (' + $('form[friend1][name_first]').value + ')';
			if ($$('.friend1Name').get('text')[0].indexOf(appending)<0) {
				$$('.friend1Name').appendText(appending);
			}	
	
			// pre fill the next form
			if ($('form[friend2][address1]').value=='') {
				$('form[friend2][address1]').value = $('form[friend1][address1]').value;
				$('form[friend2][address2]').value = $('form[friend1][address2]').value;
				$('form[friend2][town]').value = $('form[friend1][town]').value;
				selectMenu('form[friend2][county]',$('form[friend1][county]').value);
				if ($('form[friend1][county]').value=='OTHER') {
					countyOtherToggle('friend2','on');
				} else {
					countyOtherToggle('friend2','off');
				}
				$('form[friend2][county_extra]').value = $('form[friend1][county_extra]').value;
				$('form[friend2][postcode]').value = $('form[friend1][postcode]').value;
				selectMenu('form[friend2][country]',$('form[friend1][country]').value);
				$('form[friend2][tel]').value = $('form[friend1][tel]').value;
			}
			
		} else if (slide==3) {
			
			// short term cookie it
			Cookie.write('friend2_email',$('form[friend2][email]').value);
			Cookie.write('friend2_name_first',$('form[friend2][name_first]').value);
			Cookie.write('friend2_name_last',$('form[friend2][name_last]').value);
			Cookie.write('friend2_address1',$('form[friend2][address1]').value);
			Cookie.write('friend2_address2',$('form[friend2][address2]').value);
			Cookie.write('friend2_town',$('form[friend2][town]').value);
			Cookie.write('friend2_county',$('form[friend2][county]').value);
			Cookie.write('friend2_county_extra',$('form[friend2][county_extra]').value);
			Cookie.write('friend2_postcode',$('form[friend2][postcode]').value);
			Cookie.write('friend2_country',$('form[friend2][country]').value);
			Cookie.write('friend2_tel',$('form[friend2][tel]').value);
	
			// set up all instances of this name
			var appending = ' (' + $('form[friend2][name_first]').value + ')';
			if ($$('.friend2Name').get('text')[0].indexOf(appending)<0) {
				$$('.friend2Name').appendText(appending);
			}
			
		} else if (slide==4) {
		
			// short term cookie it
			var billing_who = $('form[billing][who]').value;
			Cookie.write('billing_who',billing_who);
			Cookie.write('billing_donation',$('form[billing][donation]').value);
		
			// save any new billing person
			if (billing_who=='other') {
			
				// enable all subsequent options to choose the billing address
				$$('.BillingName').set('disabled',false);
			
				// short term cookie it
				Cookie.write('billing_email',$('form[billing][email]').value);
				Cookie.write('billing_name_first',$('form[billing][name_first]').value);
				Cookie.write('billing_name_last',$('form[billing][name_last]').value);
				Cookie.write('billing_address1',$('form[billing][address1]').value);
				Cookie.write('billing_address2',$('form[billing][address2]').value);
				Cookie.write('billing_town',$('form[billing][town]').value);
				Cookie.write('billing_county',$('form[billing][county]').value);
				Cookie.write('billing_county_extra',$('form[billing][county_extra]').value);
				Cookie.write('billing_postcode',$('form[billing][postcode]').value);
				Cookie.write('billing_country',$('form[billing][country]').value);
				Cookie.write('billing_tel',$('form[billing][tel]').value);
			
				// tweak the variable of who we've picked to use in further routines
				billing_who = 'billing';
				
			} else {
			
				// disable all subsequent options to choose the billing address
				$$('.BillingName').set('disabled',true);
				
				// tweak the delivery page, so that if we were deliverying to another billing address, 
				// and now it's one of the friends, it doesn't give the option of deliverying to a non-existant person
				var delivery_who = Cookie.read('delivery_who');
				if (delivery_who=='billing') {
					choosePersonSwitch('delivery','');
				}
			
			}
			
			// set up the renewal form
			var renewal_who = Cookie.read('renewal_who');
			if (!renewal_who) {
				choosePersonSwitch('renewal',billing_who);
			} else if (renewal_who=='billing' && $('form[billing][who]').value!='billing') {
				choosePersonSwitch('renewal',billing_who);
			} else if (renewal_who=='billing' && Cookie.read('renewal_address1')!=$('form[billing][address1]').value) {
				choosePersonSwitch('renewal',billing_who);
			}
			
			// set up the giftaid form (if it's different from the person who's previously marked it as giftaid)
			
			if ($('form[giftaid][name_first]').value != $('form[' + billing_who + '][name_first]').value && $('form[' + billing_who + '][country]').value=='GBR') {
				$('form[giftaid][name_first]').value = $('form[' + billing_who + '][name_first]').value;
				$('form[giftaid][name_last]').value = $('form[' + billing_who + '][name_last]').value;
				$('form[giftaid][address1]').value = $('form[' + billing_who + '][address1]').value;
				$('form[giftaid][address2]').value = $('form[' + billing_who + '][address2]').value;
				$('form[giftaid][town]').value = $('form[' + billing_who + '][town]').value;
				selectMenu('form[giftaid][county]',$('form[' + billing_who + '][county]').value);
				$('form[giftaid][postcode]').value = $('form[' + billing_who + '][postcode]').value;
			} else if ($('form[' + billing_who + '][country]').value!='gbr') {
				blocking('giftaid','off');
				$('form[giftaid][yes]').checked = false;
			}
			
		} else if (slide==5) {
		
			Cookie.write('renewal_who',$('form[renewal][who]').value);
			
		} else if (slide==6) {
		
			// short term cookie it
			var delivery_who = $('form[delivery][who]').value;
			Cookie.write('delivery_who',delivery_who);
		
			// save any new delivery person
			if (delivery_who=='other') {
			
				Cookie.write('delivery_email',$('form[delivery][email]').value);
				Cookie.write('delivery_name_first',$('form[delivery][name_first]').value);
				Cookie.write('delivery_name_last',$('form[delivery][name_last]').value);
				Cookie.write('delivery_address1',$('form[delivery][address1]').value);
				Cookie.write('delivery_address2',$('form[delivery][address2]').value);
				Cookie.write('delivery_town',$('form[delivery][town]').value);
				Cookie.write('delivery_county',$('form[delivery][county]').value);
				Cookie.write('delivery_county_extra',$('form[delivery][county_extra]').value);
				Cookie.write('delivery_postcode',$('form[delivery][postcode]').value);
				Cookie.write('delivery_country',$('form[delivery][country]').value);
				Cookie.write('delivery_tel',$('form[delivery][tel]').value);
				
			}
		
		} else if (slide==7) {
		
			// short term cookie it
			
			Cookie.write('giftaid_yes',$('form[giftaid][yes]').value);
			Cookie.write('giftaid_name_first',$('form[giftaid][name_first]').value);
			Cookie.write('giftaid_name_last',$('form[giftaid][name_last]').value);
			Cookie.write('giftaid_address1',$('form[giftaid][address1]').value);
			Cookie.write('giftaid_address2',$('form[giftaid][address2]').value);
			Cookie.write('giftaid_town',$('form[giftaid][town]').value);
			Cookie.write('giftaid_county',$('form[giftaid][county]').value);
			Cookie.write('giftaid_postcode',$('form[giftaid][postcode]').value);
				
		
		}
		
	}



/* CHOOSE WHO TO BILL/RENEW/SEND TO */

	function choosePerson(slideForm) {
	
		var thisForm = document.forms['giveusyamoney'];
		var thisSelection = thisForm.elements['form['+slideForm+'][who]'].value;
		choosePersonSwitch(slideForm,thisSelection);
	}
	
	function choosePersonSwitch(slideForm,thisSelection) {
	
		//alert(slideForm + ' : ' + thisSelection);
	
		// IF EMPTY OPTION - show nothing
		if (!thisSelection) {
		
			$(slideForm+'_friend').setStyle('display','none');
			$(slideForm+'_friend').setStyle('opacity','0');
			if ($(slideForm+'_other')) {
				$(slideForm+'_other').setStyle('display','none');
				$(slideForm+'_other').setStyle('opacity','0');
			}
			
		// IF OTHER OPTION - show form
		} else if (thisSelection=='other') {		
		
			$(slideForm+'_friend').setStyle('display','none');
			$(slideForm+'_friend').setStyle('opacity','0');
			blocking(slideForm+'_other','on');
			
		// IF FRIEND OPTION - show uneditable details
		} else {
		
			$(slideForm+'_email').set('text', $('form['+ thisSelection +'][email]').value );
			$(slideForm+'_name_first').set('text',$('form['+ thisSelection +'][name_first]').value );
			$(slideForm+'_name_last').set('text', $('form['+ thisSelection +'][name_last]').value );
			$(slideForm+'_address1').set('text', $('form['+ thisSelection +'][address1]').value );
			$(slideForm+'_address2').set('text', $('form['+ thisSelection +'][address2]').value );
			$(slideForm+'_town').set('text', $('form['+ thisSelection +'][town]').value );
			$(slideForm+'_county').set('text', $('form['+ thisSelection +'][county]').value );
			$(slideForm+'_county_extra').set('text', $('form['+ thisSelection +'][county_extra]').value );
			$(slideForm+'_postcode').set('text', $('form['+ thisSelection +'][postcode]').value );
			$(slideForm+'_country').set('text', $('form['+ thisSelection +'][country]').value );
			$(slideForm+'_tel').set('text', $('form['+ thisSelection +'][tel]').value );
			
			if ($(slideForm+'_other')) {
				$(slideForm+'_other').setStyle('display','none');
				$(slideForm+'_other').setStyle('opacity','0');
			}
			blocking(slideForm+'_friend','on');
		}
		
		// check the select option is correct
		selectMenu('form['+slideForm+'][who]',thisSelection);
		
	}
	

/* BLOCKING */

	function blocking(cssid,offon) {
	
		el = $(cssid);
		
		if (!offon) {
			offon = 'toggle';
		}
	
		var currentDisplay = el.getStyle('display');
		if (currentDisplay=='none') {
			el.setStyle('display','block');
		}
	
		if (offon=='on' || (offon=='toggle' && currentDisplay=='none')) {
			var blocking1 = new Fx.Morph(el,{ 'duration':'400' });
			blocking1.start({ 'opacity':1 });
		} else {
			var blocking2 = new Fx.Morph(el,{ 'duration':'400' });
			blocking2.start({ 'opacity':0 }).chain(function() {
				el.setStyle('display','none');
			});
		}
	
	}
	
/* IE COOKIE FIX */

	function notNull(value) {
		
		if (value=='null' || value==null) {
			value='';
		}
		return value;
		
	}