function formrecord(formelement, description) {

	this.formelement = formelement;

	this.description = description;

}



function checkfields() {  //  check mandatory text input fields

	/*

	*	list mandatory text input fields, take care of the index and check the names of the input fields

	*/

	var blankfields = "";

	var element = new Array();

	element[0] = new formrecord(document.CallToAction.x_PERS_FIRST_NAMES, "Nome");
  	element[1] = new formrecord(document.CallToAction.x_PERS_LAST_NAME, "Apelido");
  	element[2] = new formrecord(document.CallToAction.y_PERS_ADDRESS1, "R./Av./Pr./Prct./Estr.");
	element[3] = new formrecord(document.CallToAction.y_PERS_HOUSE_NR, "No.");
  	element[4] = new formrecord(document.CallToAction.y_PERS_POSTAL_CODE, "C%F3digo Postal");
  	element[5] = new formrecord(document.CallToAction.y_PERS_TOWN, "Localidade");
  	element[6] = new formrecord(document.CallToAction.y_PERS_EMAIL, "E-Mail");
	element[7] = new formrecord(document.CallToAction.y_PERS_TEL_HOME, "Tel./Tlmv.");

	var blank = "\n";
	var found = false;
	var drops = new Array();
	var dropsdesc = new Array();
	var str= "";

	
	drops[0] = document.getElementById("x_PERS_SALUTATION").value;
	drops[1] = document.getElementById("x_BIRTHDAY_DAY").value;
	drops[2] = document.getElementById("x_BIRTHDAY_MONTH").value;
	drops[3] = document.getElementById("x_BIRTHDAY_YEAR").value;
	drops[4] = document.getElementById("w_CAR_ERD_MONTH").value;
	drops[5] = document.getElementById("w_CAR_ERD_YEAR").value;
	
	dropsdesc[0] = "Forma de Tratamento";
	dropsdesc[1] = "Data de Nascimento - Dia";
	dropsdesc[2] = "Data de Nascimento - M%EAs";
	dropsdesc[3] = "Data de Nascimento - Ano";
	dropsdesc[4] = "Mudar de carro - M%EAs";
	dropsdesc[5] = "Mudar de carro - Ano";
	
//begin check Brochures
if(document.getElementById("ProductsRequested").value == "")
  blankfields += "\n - Seleccione o modelo para o qual pretende fazer a marca%E7%E3o do Test-drive.\n\n";
//end check Brochures

//check data direction agreement
if (!(document.CallToAction.a_DPAgreement.checked))
    blankfields += "\n - Por favor leia e d%EA o seu acordo %E0 nossa directiva de protec%E7%E3o de dados.\n\n";
//end check data direction agreement
	
	for(var i=0;i<=5;i++)
		{
		if(drops[i] == "" || drops[i] == null)  {
			found = true;
			blankfields += " - " + dropsdesc[i] + "\n";
			}
		}
// begin check radio buttons
	var buttons = new Array(); // form element names

	buttons[0] = document.CallToAction.y_PERS_ADDR_TYPE;

	var descriptions = new Array(); // strings for error message

	descriptions[0] = "Tipo de Morada";

	var anys = new Array(); // generate an array with an empty value, length according to number of form elements

	for(m=0;m<buttons.length;m++) {

		anys[m] = "";

	}



	for(var i=0;i<buttons.length;i++) { // loop through radio elements

		for(var k=0;k<buttons[i].length;k++) { // loop through options of each element

			if(buttons[i][k].checked) {

			anys[i] = 1; // if any of the options is checked, set the corresponding index in anys array to 1

			}

		}

		if(anys[i] == 0) { // compose only if none of the element options is checked (sort of makes sense)

			blankfields += "\n - " + descriptions[i] + "\n";

		}

	}



	

//end check radio buttons


	

	for (var inx=0; inx<element.length; inx++) {

		if ((element[inx].formelement.value == null) || (element[inx].formelement.value == "")) {

			found = true;

			blankfields += "\n - " + element[inx].description;

		}

	}

	if (!blankfields) {

		return true;

	}
	
	//element[index].formelement.focus();

	str += "________________________________________________\n\n";

   str += "O seu pedido n%E3o p%F4de ser processado.\n";

   str += "Preencha os campos assinalados com asterisco.\n";
   	str += "________________________________________________\n\n";

	str += blankfields + "\n";

	str += "________________________________________________\n";

	window.alert(unescape(str));

	return false;
	
}


function checkform() {

// main processing function

	var goon = true;

	if (goon) { goon = checkfields(); }

	if (goon) { return true; }

	else { return false; }

}
