// Created: 19 July 2007 14:31
// Author: Adrian Jenkins
// Copyright © 2007 Cyber-Media Solutions

function validate_org_reg(form) {
	var pass = true;

	var el ='';
	var i = 0;

	while (pass && (el = form.elements[i++]) ) {
		if (el.type == 'text') {
			if ( el.value.substring(0, 13) == 'Please enter ' 
					&& el.name.substring(0,12) != 'AddressLine2' 
					&& el.name.substring(0,7) != 'Website' )
				pass = false;
		}
		else if ( el.type == 'select-one' ) {
			if ( el.options[el.selectedIndex].value == -1 )
				pass = false;
		}
	}

	if ( !pass ) {
		if ( el == '' ) 
			el = form.OrganisationName;

		errorMsg('Please complete all fields', el);
	}


	if ( pass ) { pass = TextBox(form.OrganisationName,		"Please enter an organisation name"); }
	if ( pass ) { pass = TextBox(form.AddressLine1,			"Please enter an address line 1"); }
	//if ( pass ) { pass = TextBox(form.AddressLine2,			"Please enter an address line 2"); }
	if ( pass ) { pass = TextBox(form.TownCity,				"Please enter a town or city"); }
	if ( pass ) { pass = TextBox(form.County,				"Please enter a county"); }
	if ( pass ) { pass = TextBox(form.Postcode,				"Please enter a postcode"); }
	if ( pass ) { pass = TextBox(form.Telephone,			"Please enter a telephone number"); }
	if ( pass ) { pass = TextBox(form.Email,				"Please enter an email address"); }
	//if ( pass ) { pass = TextBox(form.Website,				"Please enter a website address"); }
	if ( pass ) { pass = TextBox(form.ContactName,			"Please enter a contact name"); }
	if ( pass ) { pass = TextBox(form.Position,				"Please enter a position"); }
	if ( pass ) { pass = TextBox(form.ContactTel,			"Please enter a telephone number"); }
	if ( pass ) { pass = TextBox(form.ContactEmail,			"Please enter an email address"); }

	return pass;
}

function validate_proj_reg(form) {
	var pass = true;

	var el, i = 0;

	while (pass && (el = form.elements[i++]) ) {
		if (el.type == 'text' 
				&& el.name.substring(0,7) != 'Contact' 
				&& el.name.substring(0,12) != 'AddressLine2') {
			if ( el.value.substring(0, 13) == 'Please enter ' )
				pass = false;
		}
		else if ( el.type == 'select-one' 
				&& el.name.substring(0,7) != 'Contact'
				&& el.name.substring(0,20) != 'NeedsGroup_Secondary'
				&& el.name.substring(0,16) != 'NeedsGroup_Other' ) {
			if ( el.options[el.selectedIndex].value == -1 )
				pass = false;
		}
	}

	if ( !pass ) {
		if ( el == '' ) 
			el = form.ProjectName;

		errorMsg('Please complete all fields', el);
	}


	if ( pass ) { pass = TextBox(form.ProjectName,		"Please enter a project name"); }
	if ( pass ) { pass = TextBox(form.AddressLine1,		"Please enter an address line 1"); }
	//if ( pass ) { pass = TextBox(form.AddressLine2,		"Please enter an address line 2"); }
	if ( pass ) { pass = TextBox(form.TownCity,			"Please enter a town or city"); }
	if ( pass ) { pass = TextBox(form.County,			"Please enter a county"); }
	if ( pass ) { pass = TextBox(form.Postcode,			"Please enter a postcode"); }
	if ( pass ) { pass = TextBox(form.Telephone,		"Please enter a telephone number"); }
	if ( pass ) { pass = TextBox(form.CoordName,		"Please enter a coordinator name"); }
	if ( pass ) { pass = TextBox(form.CoordPosition,	"Please enter a coordinator position"); }
	if ( pass ) { pass = TextBox(form.CoordTel,			"Please enter a coordinator telephone number"); }
	if ( pass ) { pass = TextBox(form.CoordEmail,		"Please enter a coordinator email"); }
	//if ( pass ) { pass = TextBox(form.ContactName1,		"Please enter a contact 1 name"); }
	//if ( pass ) { pass = TextBox(form.ContactPosition1,	"Please enter a contact 1 position"); }
	//if ( pass ) { pass = TextBox(form.ContactTel1,		"Please enter a contact 1 telephone number"); }
	//if ( pass ) { pass = TextBox(form.ContactEmail1,	"Please enter a contact 1 email address"); }
	//if ( pass ) { pass = TextBox(form.ContactName2,		"Please enter a contact 2 name"); }
	//if ( pass ) { pass = TextBox(form.ContactPosition2,	"Please enter a contact 2 position"); }
	//if ( pass ) { pass = TextBox(form.ContactTel2,		"Please enter a contact 2 telephone number"); }
	//if ( pass ) { pass = TextBox(form.ContactEmail2,	"Please enter a contact 2 email address"); }

	return pass;
}

function updateAddress(form, auto_address1, auto_address2, auto_town, auto_county, auto_postcode, auto_telephone, auto_region) {

	if ( form.SameAddress.options[form.SameAddress.selectedIndex].value == 'Y' ) {
		// Fill address
		form.AddressLine1.value = unescape(auto_address1);
		form.AddressLine2.value = unescape(auto_address2);
		form.TownCity.value = unescape(auto_town);
		form.County.value = unescape(auto_county);
		form.Postcode.value = unescape(auto_postcode);
		form.Telephone.value = unescape(auto_telephone);

		for(i = 0; i < form.Region.length; i++) {
			if ( form.Region[i].value == auto_region )
				form.Region.selectedIndex = i;
		}
	}
	else {
		// Clear down address

		form.AddressLine1.value = 'Please enter your address';
		form.AddressLine2.value = 'Please enter your address';
		form.TownCity.value = 'Please enter your town or city';
		form.County.value = 'Please enter your county';
		form.Postcode.value = 'Please enter your postcode';
		form.Telephone.value = 'Please enter your telephone number';
		form.Region.selectedIndex = 0;
	}

}