generateObject = function()
{
	//create object ready for oAgency 
	 OAP = new oAgencyProperties();
	 OAA = new oAgencyAddress();
	 OAC = new oAgencyContact();		
	
	//fill in the values for oAgencyContact
	OAC.name = document.agencyRegistration.person;
	OAC.email = document.agencyRegistration.email;
	OAC.telephone = document.agencyRegistration.telephone;
	
	//fill in the values for oAgencyAddress
	OAA.line_1 = document.agencyRegistration.address_1;
	OAA.line_2 = document.agencyRegistration.address_2;
	OAA.town = document.agencyRegistration.town;
	OAA.county = document.agencyRegistration.county;
	OAA.country = document.agencyRegistration.country;
	OAA.postcode = document.agencyRegistration.postcode;

	//fill in the values for oAgencyProperties
	OAP.regions = document.agencyRegistration.regions;
	OAP.count = document.agencyRegistration.properties;

	//create oAgency object with previous objects
	var OA = new oAgency(OAC, OAA, OAP);
	
	//fill in the values for oAgency
	OA.name = document.agencyRegistration.name;
	OA.url = document.agencyRegistration.site_url;
	OA.vat_registered = document.agencyRegistration.registered;
	OA.vat_country = document.agencyRegistration.register_country;
	OA.vat_no = document.agencyRegistration.vat;
	
	return OA;
};

validateForm = function()
{
	var problems = Array();
	var problem_string = "";
	
	var valid_form_input = '#FFFFFF';
	var invalid_form_input = '#f1f1f1';
	
	var OA = this.generateObject();
	
	// validate agency name
	OA.name.style.backgroundColor = valid_form_input;
	if(OA.name.value.length <= 0) problems.push(OA.name);
	
	// validate agency country
	OA.address.country.style.backgroundColor = valid_form_input;
	if(OA.address.country.value.length <= 0) problems.push(OA.address.country);

	// validate agency postcode
	OA.address.postcode.style.backgroundColor = valid_form_input;
	if(OA.address.postcode.value.length <= 0) problems.push(OA.address.postcode);
	
	
	/* ------------------------------------------------
	 *  Agency Main Detail 
	 *-----------------------------------------------*/
	OA.vat_registered.style.backgroundColor = valid_form_input;
	OA.vat_country.style.backgroundColor = valid_form_input;
	OA.vat_no.style.backgroundColor = valid_form_input;
	
	if(OA.vat_registered.value == 'yes') 
	{ 
		if(OA.vat_country.value.length <= 0) problems.push(OA.vat_country);
		if(OA.vat_no.value.length <= 0) problems.push(OA.vat_no);
	}
	
	
	/* ------------------------------------------------
	 *  Agency Contact 
	 *-----------------------------------------------*/
	OA.contact.name.style.backgroundColor = valid_form_input;
	OA.contact.email.style.backgroundColor = valid_form_input;
	OA.contact.telephone.style.backgroundColor = valid_form_input;
	
	if(OA.contact.name.value.length <= 3) problems.push(OA.contact.name);
	if(OA.contact.email.value.length <= 3) problems.push(OA.contact.email);
	if(OA.contact.telephone.value.length <= 3) problems.push(OA.contact.telephone);	
	
	/* ------------------------------------------------
	 *  Parse Errors
	 *-----------------------------------------------*/
	for(error in problems)
	{
		try
		{
			problems[error].style.backgroundColor = invalid_form_input;
		}
		catch(e)
		{
			
		}
		
	}
	
	if(problems.length <= 0)
	{
		return true;
	}
	else
	{
		alert(	"Some of the manditory information required is either incorrect or not specified."+
			" Please add or amend the information highlights with a grey background\n\n"+
			"Certaines informations nécessaires à la création de votre compte sont soit incorrectes, soit manquantes. Veuillez renseigner ou modifier les informations contenues dans les champs surlignés en gris avant de continuer.");
		return false;			
	}
};

/**
 * Represents a single agency
 * @param {oAgencyContact} contact
 * @param {oAgencyAddress} address
 * @param {oAgencyProperties} regions
 */
oAgency = function(contact, address, regions)
{
	//Fields
	this.name = null;
	this.url = null;
	this.vat_registered = false;
	this.vat_country = null;
	this.vat_no = null;
	//objects
	this.contact = contact;
	this.address = address;
	this.regions = regions;
};

oAgencyContact = function()
{
	this.name = null;
	this.email = null;
	this.telephone = null;
};

oAgencyAddress = function()
{
	this.line_1 = null;
	this.line_2 = null;
	this.town = null;
	this.county = null;
	this.country = null;
	this.postcode = null;
};

oAgencyProperties = function()
{
	this.regions = null;
	this.count = 0;
};

