function reloadForm() {
	var selectedCountry = document.profile.country.options[document.profile.country.selectedIndex].value;
	
	if ((document.profile.formType.value == "manual") || (selectedCountry != 'United Kingdom' && document.profile.formType.value == 'auto')) {
		document.profile.gridN.value='';
		document.profile.gridE.value='';
	}
	
	//if ((document.profile.formType.value == "search2") && (document.profile.srh_postcode.value.length == 0)) {
	//	alert("Please enter a UK postcode to search for your address");
	//}
	//else {					
	//	document.profile.action = 'registration.aspx?fn=register&ReturnUrl=' + document.profile.ReturnUrl.value;
	//	document.profile.submit();
	//}
	
	//document.profile.action = 'registration.aspx?fn=register&country=' + selectedCountry  + '&ReturnUrl=' + document.profile.ReturnUrl.value;
	document.profile.action = 'title.mspx?fn=harvestResultsForm&showLookUp=true&country=' + selectedCountry  + '&ReturnUrl=' + document.profile.ReturnUrl.value;
	document.profile.submit();
}


function changeCountry() {
var selectedCountry = document.profile.country.options[document.profile.country.selectedIndex].value;
	
	if (selectedCountry = 'United Kingdom') {
		document.profile.formType.value = "search1";
	}
	//document.profile.action = 'registration.aspx?fn=register&ReturnUrl=' + document.profile.ReturnUrl.value;
	document.profile.action = 'title.mspx?fn=harvestResultsForm&showLookUp=true&country=' + selectedCountry  + '&ReturnUrl=' + document.profile.ReturnUrl.value;
	document.profile.submit();
}



function manualAddress() {
	document.profile.srh_postcode.value=""
	document.profile.action = 'title.mspx?fn=harvestResultsForm&manual=yes&ReturnUrl=' + document.profile.ReturnUrl.value;
	//document.profile.action = 'registration.aspx?fn=register&manual=yes&ReturnUrl=' + document.profile.ReturnUrl.value;
	document.profile.submit();
}

function modifyAddress(ReturnUrl) {
	//document.profile.action = 'registration.aspx?fn=register&modify=yes&ReturnUrl=' + document.profile.ReturnUrl.value;
	document.profile.action = 'title.mspx?fn=harvestResultsForm&modify=yes&ReturnUrl=' + document.profile.ReturnUrl.value;
	document.profile.submit();
}		
								
function saveForm() {
	if (document.profile.formType.value == "search1") {
		alert("Please select your country from the list");
	}
	
	else if (document.profile.formType.value == "search2" || document.profile.formType.value == "search3" ) {
		alert("please complete your address search by clicking 'Select Address' before saving this form");
	}
	
	else if ((document.profile.formType.value == "manual" && ((document.profile.postcode.value.length ==0) || document.profile.postTown.value.length ==0))) {
		alert("Please complete all fields marked with a * ");
	}

	else {
		if (document.profile.email.value != document.profile.cnf_email.value)
			alert("Your confirmation email must be the same as your email");
	
		else if (document.profile.password.value != document.profile.cnf_password.value)
			alert("Your confirmation password must be the same as your password"); 
			
		else if (document.profile.password.value.length < 5)
			alert("Your password must be at least 5 characters in length");
	
		else if (document.profile.prename.options[document.profile.prename.selectedIndex].value == '' || document.profile.firstname.value.length ==0 || document.profile.lastname.value.length ==0 || document.profile.email.value.length ==0 || document.profile.telephone.value.length ==0 || document.profile.password.value.length ==0   ) {
			alert("Please complete all fields marked with a * ");
		}		
		else {

			document.profile.action = 'registration.aspx?fn=save&ReturnUrl=' + document.profile.ReturnUrl.value;
			document.profile.submit();
		
		}
	}
}

function checkPostcode(fieldRef) {
	document.profile.gridN.value="";
	document.profile.gridE.value="";
	}
	
	
// update registration JS

function saveRegistrationUpdate() {


		if (document.profile.password.value.length > 0 && document.profile.password.value.length < 5) {
			alert("Your password must be at least 5 characters in length");
		}
		else if (document.profile.password.value.length > 0 && (document.profile.password.value != document.profile.cnf_password.value)) {
			alert("Your confirmation password must be the same as your password"); 
		}

		else if (document.profile.prename.options[document.profile.prename.selectedIndex].value == '' || document.profile.firstname.value.length ==0 || document.profile.lastname.value.length ==0 || document.profile.email.value.length ==0 || document.profile.telephone.value.length ==0 || document.profile.add1.value.length ==0 || document.profile.city.value.length ==0 || document.profile.postcode.value.length ==0) {
			alert("Please complete all fields marked with a * ");
		}		
		else {

		document.profile.action = 'registration.aspx?fn=saveUpdate&ReturnUrl=' + document.profile.ReturnUrl.value;
		document.profile.submit();
		
		//alertStr = 'gridN: ' + document.profile.gridN.value + ' gride: ' + document.profile.gridE.value + ' addressId: ' + document.profile.addressId.value;
		//alert(alertStr);
		
		
		}
}


function editPersonalDetails() {
	document.profile.action = 'registration.aspx?fn=registerUpdate&edit=yes&ReturnUrl=' + document.profile.ReturnUrl.value;
	document.profile.submit();
}	

function addressChange() {
	//document.profile.action = 'registration.aspx?fn=registerUpdate&edit=yes&newAddress=yes&ReturnUrl=' + document.profile.ReturnUrl.value;
	document.profile.action = 'title.mspx?fn=harvestResultsForm&country=United%20Kingdom&formType=search1&showLookUp=true&resubmit=true'
	document.profile.submit();
}
function getAddress1() {
	document.profile.action = 'registration.aspx?fn=registerUpdate&edit=yes&newAddress=yes&ReturnUrl=' + document.profile.ReturnUrl.value;
	document.profile.submit();
}

function getAddress2() {
	document.profile.action = 'registration.aspx?fn=registerUpdate&edit=yes&newAddress=yes&ReturnUrl=' + document.profile.ReturnUrl.value;
	document.profile.submit();
}



function manualUpdateAddress() {
	document.profile.srh_postcode.value=""
	document.profile.action = 'registration.aspx?fn=registerUpdate&newAddress=yes&manual=yes&ReturnUrl=' + document.profile.ReturnUrl.value;
	document.profile.submit();
}


function modifyUpdateAddress() {
	document.profile.action = 'registration.aspx?fn=registerUpdate&&newAddress=yes&modify=yes&manual=yes&ReturnUrl=' + document.profile.ReturnUrl.value;
	document.profile.submit();
}



// common registration JS	
	
function checkEmail(fieldRef) {
	if(fieldRef.value.length > 0 && (fieldRef.value.indexOf('.') == -1 | fieldRef.value.indexOf('@') == -1 | fieldRef.value.indexOf(' ') != -1)) {
		document.profile.emailActionCode.value = 0;
		fieldRef.value = '';
		window.alert("That is not a valid email address.\r\rPlease re-enter your full internet email address,\r\rin the form 'username@hostdomain' (e.g. john@mycompany.co.uk)."); 
		}
	else {
		document.profile.emailActionCode.value = 1;
	}

}
