<!--
// 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');

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)
	{
		type = typeof(document.incorporate.company_secretary__incwise_as_company_secretary);
		if ('undefined' != type)
			document.incorporate.company_secretary__incwise_as_company_secretary.checked = false;
	}
	changecs();
}

function changecs()
{
	type = typeof(document.incorporate.company_secretary__incwise_as_company_secretary);
	if ('undefined' != type)
		isinc = document.incorporate.company_secretary__incwise_as_company_secretary.checked;
	else
		isinc = false;

	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';");
		i++;
	}

	calc();
	return true;
}

function changema()
{
	cust = document.incorporate.corporate_details__mem_and_arts__customise.checked;
	document.getElementById('customise_ma').style.display = cust ? 'block' : 'none';

	if (!cust)
	{
		document.incorporate.corporate_details__mem_and_arts__options__remove_chair_vote.checked = false;
		document.incorporate.corporate_details__mem_and_arts__options__director_enhanced.checked = false;
		type = typeof(document.incorporate.corporate_details__mem_and_arts__options__limit_share_capital);
		if ('undefined' != type)
			document.incorporate.corporate_details__mem_and_arts__options__limit_share_capital.value = '';
		type = typeof(document.incorporate.corporate_details__mem_and_arts__options__limit_authority_to_allot);
		if ('undefined' != type)
			document.incorporate.corporate_details__mem_and_arts__options__limit_authority_to_allot.value = '';
		type = typeof(document.incorporate.corporate_details__mem_and_arts__options__disapply_preemption);
		if ('undefined' != type)
			document.incorporate.corporate_details__mem_and_arts__options__disapply_preemption.checked = false;
		type = typeof(document.incorporate.corporate_details__mem_and_arts__options__allow_partpaid_shares);
		if ('undefined' != type)
			document.incorporate.corporate_details__mem_and_arts__options__allow_partpaid_shares.checked = false;
	}
	calc();
	return true;
}

function switchma()
{
	// Get template name
	type = typeof(document.incorporate.corporate_details__mem_and_arts__template);
	if ('undefined' == type)
		return true;
	ma = document.incorporate.corporate_details__mem_and_arts__template.value;
	if ('0' == ma)
	{
		changema();
		document.incorporate.corporate_details__share_capital__share_value.value = '1';
		document.incorporate.corporate_details__share_capital__share_currency.value = 'GBP';
		document.getElementById('maoptiontext').innerHTML = '';
		document.getElementById('macustopts').style.display = 'block';
		document.getElementById('svtext').style.display = 'block';
		return true;
	}

	// Fill the share value
	code = 'document.incorporate.corporate_details__share_capital__share_value.value ='
		+ 'document.incorporate.corporate_details__mem_and_arts__shval__'
		+ ma + '.value;'
		+ 'document.incorporate.corporate_details__share_capital__share_currency.value ='
		+ 'document.incorporate.corporate_details__mem_and_arts__shcurr__'
		+ ma + '.value;';
	eval(code);

	// Switch the explanatory text
	eval ('txt = document.incorporate.corporate_details__mem_and_arts__text__' + ma + '.value;');
	document.getElementById('maoptiontext').innerHTML = txt;

	// Switch the visibility of sections
	document.incorporate.corporate_details__mem_and_arts__customise.checked = false;
	changema();
	document.getElementById('macustopts').style.display = 'none';
	document.getElementById('svtext').style.display = 'none';
	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 contactew()
{
	postcode = document.incorporate.contact__address__postcode.value;
	country = document.incorporate.contact__address__country.value;
callAsync('asyncew.php?country=uk&postcode=aa1 1aa', 'contactnotice', 'Checking...');
//	callAsync('asyncew.php?country='+country+'&postcode='+postcode, 'contactnotice', 'Checking...');
alert('Postcode: ' + postcode + '; Country: ' + country);
}
*/
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;');
	}
	return true;
}

function changesa(prefix, itemchanged)
{
	obj = document.incorporate;

	var code = 'checked = obj.' + prefix + 'use_service_address__' + itemchanged + '.checked;';
	code += 'document.getElementById("' + prefix + 'sa_details").style.display = (checked && ("own" == itemchanged)) ? "block" : "none";';
	code += 'obj.' + prefix + 'use_service_address__'
		+ (('own' == itemchanged) ? 'provider' : 'own') + '.checked = false;';
	eval(code);

	calc();
	return true;
}

function sadetails(prefix)
{
	obj = document.incorporate;
	var code = 'isdir = obj.'+prefix+'is_director.checked;';
	code += 'issa = obj.'+prefix+'use_service_address__own.checked;';
	code += 'document.getElementById("'+prefix+'sa_details").style.display = (isdir && issa) ? "block" : "none";';
	code += 'document.getElementById("'+prefix+'saopts").style.display = isdir ? "block" : "none";';
	eval(code);
	if (isdir)
		return true;

	code2 = 'obj.' + prefix + 'use_service_address__incwise.checked = false;';
	code2 += 'obj.' + prefix + 'use_service_address__own.checked = false;';
	eval(code2);
	calc();
	return true;
}

function cgs(apostille)
{
	type = typeof(document.incorporate.extra_services__cert_good_standing);
	typea = typeof(document.incorporate.extra_services__cert_good_standing_apostille);
	if ('undefined' != type && 'undefined' != typea)
	{
		if (apostille)
			document.incorporate.extra_services__cert_good_standing.checked = false;
		else
			document.incorporate.extra_services__cert_good_standing_apostille.checked = false;
	}
	calc();
}

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++;
	}

	// Service addresses
	j = 1;
	prefix = 'document.incorporate.dirsh__'
	while (true) {
		eval('type = typeof('+prefix + j + '__use_service_address__provider);')
		if ('undefined' == type)
			break;
		eval('isinc = ' + prefix + j + '__use_service_address__provider.checked;');
		if (isinc) {
			total += Number(document.incorporate.fee__service_address.value);
			break;
		}
		j++;
	}

	// Mem & Arts
	if (document.incorporate.corporate_details__mem_and_arts__customise.checked)
		total += Number(document.incorporate.fee__customise_arts.value);

	// Extra services
	extraservices = new Array(
//		'remove_chair_vote',
//		'director_enhanced',
		'virtual_office',
		'logo_design',
		'stationery_design',
		'cert_good_standing',
		'cert_good_standing_apostille');
	prefix = 'document.incorporate.extra_services__'
	for (k = 0; k < extraservices.length; k++) {
		eval('type = typeof('+prefix + extraservices[k] + ');')
		if ('undefined' != type) {
			eval('add = ' + prefix + extraservices[k] + '.checked;');
			if (add) {
				eval('total += Number(document.incorporate.fee__' + extraservices[k] +'.value);');
			}
		}
	}
	document.getElementById('total_amount').innerHTML = String(total / 100);
	document.incorporate.fee__total.value = total / 100;
	return true;
}
//-->

