addEvent(window,'load',RegisterOnline_initialise,false);

function RegisterOnline_initialise(){
	// We are adding a property to the field we are checking the password of, this is the id of the element we want to update with results
	$('login_password').targetForStrength = 'PasswordStrength';
	addEvent($('login_password'),'keyup',reportStrength,false);
	addEvent($('login_password'),'change',reportStrength,false);

	//  Add event handler to the "Use Registered Office" checkboxes to disable input in the contact address details if it's checked
	addEvent($('contact_1_useRegOffice'),'change',toggleContact1Address,false);
	addEvent($('contact_2_useRegOffice'),'change',toggleContact2Address,false);
	
	// Add an event handler to all country selectors to only display their appropriate International Postcode box if United Kingdom is selected
	// Also hide the international postcodes by default
	// Also run them all on load!
	//$('regOffice_intPostcodeBox').style.display = 'none';
	//regOnline_checkIntPostcode($('regOffice_country'));
	//addEvent($('regOffice_country'),'change', regOnline_checkIntPostcodeCaller,false);

	//$('contact_1_intPostcodeBox').style.display = 'none';
	///regOnline_checkIntPostcode($('contact_1_country'));
	///addEvent($('contact_1_country'),'change', regOnline_checkIntPostcodeCaller,false);

	///$('contact_2_intPostcodeBox').style.display = 'none';
	///regOnline_checkIntPostcode($('contact_2_country'));
	///addEvent($('contact_2_country'),'change', regOnline_checkIntPostcodeCaller,false);

	// Event handlers for phone numbers
	addEvent($('contact_1_phone'),'blur', checkPhone, false);	
	addEvent($('contact_2_phone'),'blur', checkPhone, false);
	addEvent($('signUp_phone'),'blur', checkPhone, false);

	// Event handlers for postcodes
	addEvent($('regOffice_postcode'),'blur', checkPostcode, false);	
	addEvent($('contact_1_postcode'),'blur', checkPostcode, false);	
	addEvent($('contact_2_postcode'),'blur', checkPostcode, false);
	
	// Check on load what the state is.
	toggleContact1Address();
	toggleContact2Address();
	
	$('CopyContactDetails').setAttribute('href','javascript:void(0);');
	$('CopyContactDetails').style.display = 'inline';
	addEvent($('CopyContactDetails'),'click',copyContactDetailsFromSubmittedBy, false);
	
	
	
} // end RegisterOnline_initialise

function toggleContact1Address(){
	// This checks to see if the "Use Registered Office" checkbox is checked. If it is the address fields are disabled. Otherwise they are enabled.
	
	var fields = new Array('contact_1_buildingName', 'contact_1_streetName', 'contact_1_town', 'contact_1_county', 'contact_1_postcode', 'contact_1_country');
	
	// Get state
	if($('contact_1_useRegOffice').checked){
		for(i = 0;i < fields.length; i++){
			$(fields[i]).disabled = true;
			$(fields[i]).value = "";
			addClass($(fields[i]),"Disabled");
		}
	}else{
		for(i = 0;i < fields.length; i++){
			$(fields[i]).disabled = false;
			removeClass($(fields[i]),"Disabled");
		}
	}	
	
} // end toggleContact1Address

function toggleContact2Address(){
	// This checks to see if the "Use Registered Office" checkbox is checked. If it is the address fields are disabled. Otherwise they are enabled.
	
	var fields = new Array('contact_2_buildingName', 'contact_2_streetName', 'contact_2_town', 'contact_2_county', 'contact_2_postcode', 'contact_2_country');
	
	// Get state
	if($('contact_2_useRegOffice').checked){
		for(i = 0;i < fields.length; i++){
			$(fields[i]).disabled = true;
			$(fields[i]).value = "";
			addClass($(fields[i]),"Disabled");
		}
	}else{
		for(i = 0;i < fields.length; i++){
			$(fields[i]).disabled = false;
			removeClass($(fields[i]),"Disabled");
		}
	}	
	
} // end toggleContact2Address

function regOnline_checkIntPostcodeCaller(e){
if(!e) var e = window.event;
if(e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;

	regOnline_checkIntPostcode(targ);

} // end regOnline_checkIntPostcodeCaller

function regOnline_checkIntPostcode(targ){
	// set postcodeBox
	var chunks = new Array();
	chunks = targ.name.split('_');
	loseMe = chunks.pop();
	var postcodeBox = chunks.join('_') + '_intPostcodeBox';

	if(targ.value == 'UNITED KINGDOM'||targ.value == ''||targ.value == null||targ.value == 0){
		$(postcodeBox).style.display = 'none';
	}else{
		$(postcodeBox).style.display = 'block';
	}

} // end regOnline_checkIntPostcode

function copyContactDetailsFromSubmittedBy(){
	$('contact_1_jobTitle').value = $('signUp_jobTitle').value;
	$('contact_1_phone').value = $('signUp_phone').value;
	$('contact_1_email').value = $('signUp_email').value;
}