<!--
// Set of functions to copy elements across the form and update

// Globals - avoids passing arrays

rolist = new Array ('care_of_name', 'add1','add2','add3','town','county','postcode','country');
cclist = new Array ('name__surname', 'name__forenames', 'address__add1', 'address__add2',
		'address__add3', 'address__town', 'address__county', 'address__postcode', 'address__country',
		'email', 'phone');
cslist = new Array ('name__corporate_name', 'name__surname',
		'name__forenames', 'address__add1', 'address__add2', 'address__add3',
		'address__town', 'address__county', 'address__postcode', 'address__country',
		'email', 'phone', 'authentication__eye_colour', 'authentication__town_of_birth',
		'authentication__mothers_maiden_name');
dslist = new Array ('name__corporate_name', 'name__surname',
		'name__forenames', 'address__add1', 'address__add2', 'address__add3',
		'address__town', 'address__county', 'address__postcode', 'address__country',
		'email', 'phone', 'authentication__eye_colour', 'authentication__town_of_birth',
		'authentication__mothers_maiden_name');

//TODO - director-shareholders; corporate & individual switching on copy over

function changero()
{
	isinc = document.incorporate.registered_office__incwise_as_registered_office.checked;
	if (isinc) {
		for (i = 0; i < rolist.length; i++) {
			eval('document.incorporate.registered_office__' + rolist[i] + '.value = "";');
		}
	}
	document.getElementById('registered_office_details').style.display = isinc ? "none" : "block";
	calc();
	return true;
}

function changecsown()
{
	if (document.incorporate.company_secretary__cosec_service.checked)
		document.incorporate.company_secretary__incwise_as_company_secretary.checked = false;
	changecs();
}

function changecs()
{
	isinc = document.incorporate.company_secretary__incwise_as_company_secretary.checked;
	if (isinc) {
		for (i = 0; i < cslist.length; i++) {
			eval('document.incorporate.company_secretary__' + cslist[i] + '.value = "";');
		}
		prefix = 'document.incorporate.company_secretary__previous_names__previous_name__'
		eval('blocks = '+prefix+'blocks.value;');
		for (i = 1; i <= blocks; i++) {
			eval(prefix + i + '__surname.value = "";');
			eval(prefix + i + '__forenames.value = "";');
		}
	}
	document.getElementById('company_secretary_details').style.display = isinc ? "none" : "block";
	type = typeof(document.incorporate.company_secretary__cosec_service);
	if ('undefined' != type && isinc)
		document.incorporate.company_secretary__cosec_service.checked = false;
	calc();
	return true;
}

function changenom()
{
	i = 1;
	prefix = 'document.incorporate.dirsh__'
	while (true) {
		eval('type = typeof('+prefix + i + '__nominee);')
		if ('undefined' == type)
			break;

		eval('isnom = ' + prefix + i + '__nominee.checked;');
		eval('document.getElementById("dirsh__' + i + '__nomtext").style.display = isnom ? "block" : "none";');
		eval('isdir = ' + prefix + i + '__is_director.checked;');
		eval("document.getElementById('dirsh__" + i + "__nom').style.display = (isnom && !isdir) ? 'none' : 'block';");
		eval("document.getElementById('dirsh__" + i + "__otherdir').style.display = (isnom && !isdir) ? 'none' : 'block';");
		i++;
	}

	calc();
	return true;
}

function copydir(active)
{
	for (i = 0; i < cclist.length; i++) {
		txt = 'document.incorporate.contact__' + cclist[i]
			+ '.value = '
			+ (active ? 'document.incorporate.dirsh__1__' + cclist[i] + '.value;' : '""');
		eval(txt);
	}
	return true;
}

function copycs(active)
{
	if (document.incorporate.company_secretary__incwise_as_company_secretary.checked) return false;
	for (i = 0; i < cclist.length; i++) {
		txt = 'document.incorporate.contact__' + cclist[i]
			+ '.value = '
			+ (active ? 'document.incorporate.company_secretary__' + cclist[i] + '.value;' : '""');
		eval(txt);
	}
	return true;
}

function std2ro()
{
	for (i = 0; i < rolist.length; i++) {
		eval('document.incorporate.registered_office__' + rolist[i] + '.value = '
			+ 'document.incorporate.standard__registered_office__' + rolist[i] + '.value;');
	}
}

function calc()
{
	// Incorporation (includes VAT)
	total = Number(document.incorporate.fee__incorporation.value);
	dstype = typeof(document.incorporate.fee__inc_discsec);
	dsdiscount = ('undefined' == dstype) ? 0 : Number(document.incorporate.fee__inc_discsec.value);
	// RO and CS
	if (document.incorporate.company_secretary__incwise_as_company_secretary.checked)
		total += Number(document.incorporate.fee__cs.value) - dsdiscount;
	else if (document.incorporate.company_secretary__cosec_service.checked)
		total += Number(document.incorporate.fee__cs.value) - dsdiscount;
	if (document.incorporate.registered_office__incwise_as_registered_office.checked)
		total += Number(document.incorporate.fee__ro.value);
	// Nominees - check each box
	i = 1;
	prefix = 'document.incorporate.dirsh__'
	while (true) {
		eval('type = typeof('+prefix + i + '__nominee);')
		if ('undefined' == type)
			break;
		eval('isinc = ' + prefix + i + '__nominee.checked;');
		if (isinc) {
			total += Number(document.incorporate.fee__nom.value);
			break;
		}
		i++;
	}

	// Mem & Arts
//	if (document.incorporate.corporate_details__mem_and_arts__remove_chair_vote.checked)
//		total += Number(document.incorporate.fee__remove_chair_vote.value);
	if (document.incorporate.corporate_details__mem_and_arts__director_enhanced.checked)
		total += Number(document.incorporate.fee__director_enhanced.value);

	// Extra services
	extraservices = new Array(
//		'remove_chair_vote',
		'director_enhanced',
		'virtual_office',
		'logo_design',
		'stationery_design');
	prefix = 'document.incorporate.extra_services__'
	for (j = 0; j < extraservices.length; j++) {
		eval('type = typeof('+prefix + extraservices[j] + ');')
		if ('undefined' != type) {
			eval('add = ' + prefix + extraservices[j] + '.checked;');
			if (add) {
				eval('total += Number(document.incorporate.fee__' + extraservices[j] +'.value);');
			}
		}
	}
	document.getElementById('total_amount').innerHTML = String(total / 100);
	document.incorporate.fee__total.value = total / 100;
	return true;
}
//-->
