<!--
// Set of functions to copy elements across the form
// and to enable / disable buttons where required

// Globals - avoids passing arrays

rolist = new Array ('add1','add2','add3','town','county','postcode','country');
cclist = new Array ('title','othtitle','surname','firstname','add1','add2',
		'add3','town','county','postcode','country','email','phone');
cslist = new Array ('title','othtitle','surname','firstname','add1','add2',
		'add3','town','county','postcode','country','email','phone','eye',
		'townbirth','mname','ni',
		'prevsurname1','prevsurname2','prevfirstname1','prevfirstname2');


function fillblock(blockto, blockfrom) {
// Fills one entry block with data from another
// @param blockto / blockfrom - by shorthand "ro", "dir", "cs", "cc"
// Also copies dummy data if blockfrom is "incwise", or blanks if "blank"
// No return; operates directly in document

	var tohandle; var fromhandle; var fieldlist;

// Change handles to cope with number of director blocks
	fromhandle = gethandle (blockfrom);
	tohandle = gethandle (blockto);

// Work out list of fields we are filling
// This may need customising
	if (blockfrom == 'incwise' || blockfrom == 'blank') {
		fieldlist = blockto;
	} else if (blockfrom == 'ro') {
		fieldlist = 'ro';
	} else {
		fieldlist = 'cc'
	}
	eval ('fields = '+fieldlist+'list.length');

	for (i=0; i<fields; i++) {
// Work out object to copy to
		listobj = eval(fieldlist+'list['+i+']');
		switch (tohandle) {
			case 'cs':
			case 'cc':
				// Fieldnames are of the format csadd1
				objto = eval ("contactb."+tohandle+listobj);
				break;
			default:
				// Fieldnames are of the format add1ro
				objto = eval ("contactb."+listobj+tohandle);
		}
		if (fromhandle == 'incwise') {
// Fill with "IncWise"
			objto.value = '*** IncWise ***';
		} else if (fromhandle == 'blank') {
			objto.value = '';
		} else {
// Work out object to copy from & fill
			switch (fromhandle) {
				case 'cs':
				case 'cc':
					// Fieldnames are of the format csadd1
					objfrom = eval ("contactb."+fromhandle+listobj);
					break;
				default:
					// Fieldnames are of the format add1ro
					objfrom = eval ("contactb."+listobj+fromhandle);
			}
			objto.value = objfrom.value;
		}
	}
}


function gethandle(bl) {
var handle;
	switch (bl) {
		case 'dir':
			return ('dir1');
		default:
			return (bl);
	};
}


function clearblock(block) {
	switch (block) {
		case 'ro':
			disablero(false);
			break;
		case 'cs':
			disablecs(false);
			if (contactb.type.value != "account") contactb.cc_sec.disabled = false;
			break;
// Functions needed if we want to clear other blocks
// because they may need to be unlocked
		default:
			return false;
	}
	fillblock(block,'blank');
}

function roincwise()
// Inserts registered office details as IncWise
{
	disablero(false);
	fillblock('ro','incwise');
	disablero(true);
	contactb.dirro.checked = false;
	contactb.dirro.disabled = true;
	document.getElementById('divdirro').style.display = 'none';
}

function robelow()
// Effectively undoes roincwise()
{
	disablero(false);
	contactb.dirro.disabled = false;
	document.getElementById('divdirro').style.display = 'block';
	if (contactb.add1ro.value == "*** IncWise ***") {
		fillblock('ro','blank');
	}
}

function changero()
// Called if RO details change
{
	contactb.ro_below.checked = true;
	if (contactb.dirro.checked) {
		fillblock('dir','ro');
	}
}

function incwisecs()
// Insert company secretary details as IncWise
{
	disablecs(false);
	fillblock('cs','incwise')
	cc=getcc();
	if (cc == "as CS") {
		fillblock('cc', 'blank');
		contactb.cc_below.checked = true;
	}
	// Disable copy down
	if ((contactb.type.value != "account") || (contactb.account.value == 'APAC ESF')) {
		contactb.cc_sec.disabled = true;
		document.getElementById('spancc_sec').style.display = 'none';
	}
	disablecs(true);
}

function disablero(state)
// Enable or disable registered office boxes
// Called when IncWise reg office is switched on or off
{
	for (i=0; i<rolist.length; i++) {
		objto = eval ("contactb."+rolist[i]+"ro");
		objto.disabled = state;
	}
}

function disablecs(state)
// Enable or disable company secretary boxes
// Called when IncWise company secretary is switched on or off
{
	for (i=0; i<cslist.length; i++) {
		objto = eval ("contactb.cs"+cslist[i]);
		objto.disabled = state;
	}
// Toggle visibility of other fields
	if (state) {
		document.getElementById('cspersonal').style.display = 'none';
		document.getElementById('cspreviousnames').style.display = 'none';
		if (contactb.type.value != "account") {
			document.getElementById('spancc_sec').style.display = 'none';
		}
	} else {
		document.getElementById('cspersonal').style.display = 'block';
		document.getElementById('cspreviousnames').style.display = 'block';
		if (contactb.type.value != "account") {
			document.getElementById('spancc_sec').style.display = 'block';
		}
	}
}

function changedir(dir) {
// Handle changes to director 1 - update appropriate contact details
// & selections.  Ignores changes to other directors

	cc=getcc();
	if (dir == 'dir1') {
		if (contactb.dirro.checked) {
			contactb.dirro.checked = false;
		}
		contactb.client_dir1.checked = false;
		if (cc == "as director") {
			fillblock('cc','dir');
		}
	}
}

function changecs() {
// Handle changes to company secretary - update appropriate contact details

	cc=getcc();
	if (cc == "as CS") {
		fillblock('cc','cs');
		contactb.cosec_below.checked = true;
	}
}

function changecc() {
// Handle changes to contact details
	contactb.cc_below.checked = true;
}

function getcc() {
// Get status of radio button for copying down to contact details
// Note that it is not a radio button if it's an account customer

	if (contactb.type.value == "account") {
		return '';
	} else {
		for (i=0;i<contactb.cc.length;i++)
		{
			if (contactb.cc[i].checked)
			{
				str = contactb.cc[i].value;
			}
		}
		return str;
	}
}
//-->
