// ------------------------------------------------------------------------------------------------------ //
function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string') element = document.getElementById(element);
		if (arguments.length == 1) return element;
		elements.push(element);
		}
	return elements;
	}
// ------------------------------------------------------------------------------------------------------ //
function toggleOptions(id,opt){
	var m = $(id);
	if (opt){
		m.style.display = "";
		}
	else {
		m.style.display = "none";
		}
	}
// ------------------------------------------------------------------------------------------------------ //
function checkForm(){
var req, req2, req3, req4, curr, missed = new Array();

	// standard elements
	req = new Array("title","firstname","surname","address","town","postcode");
	for(i=0;i<req.length;i++){
		curr = $(req[i]);
		curr.style.backgroundColor="#ffffff";
		if (!curr.value){
			missed[missed.length] = curr.name;
			curr.style.backgroundColor="#FEAAAA";
			}
		}

	// appointment options
	req2 = new Array("speakmortgage","speakloans","speakinsurance","speaklife","speakother");
	if (!$(req2[0]).checked && !$(req2[1]).checked && !$(req2[2]).checked && !$(req2[3]).checked && !$(req2[4]).checked){
		for(i=0;i<req2.length;i++){
			curr = $(req2[i]);
			curr.style.backgroundColor="#FEAAAA";
			}
		missed[missed.length] = "What would you like to speak about?";
		}
	else {
		for(i=0;i<req2.length;i++){
			curr = $(req2[i]);
			curr.style.backgroundColor="#ffffff";
			}
		}

	// if selected mortgage
	if ($(req2[0]).checked){
		req3 = new Array("mtype","propvalue","mortgageamount","ccj");
		for(i=0;i<req3.length;i++){
			curr = $(req3[i]);
			curr.style.backgroundColor="#ffffff";
			if (!curr.value){
				missed[missed.length] = curr.name;
				curr.style.backgroundColor="#FEAAAA";
				}
			}
		}

	// if selected other
	if ($(req2[3]).checked){
		curr = $('speakotherspec');
		curr.style.backgroundColor="#ffffff";
		if (!curr.value){
			missed[missed.length] = curr.name;
			curr.style.backgroundColor="#FEAAAA";
			}
		}

	// appointment details
	req4 = new Array("btime","bdate","bnumber","bwhere");
	for(i=0;i<req4.length;i++){
		curr = $(req4[i]);
		curr.style.backgroundColor="#ffffff";
		if (!curr.value){
			missed[missed.length] = curr.name;
			curr.style.backgroundColor="#FEAAAA";
			}
		}

	if ($(req4[3]).selectedIndex == 3){
		curr = $('bloc');
		curr.style.backgroundColor="#ffffff";
		if (!curr.value){
			missed[missed.length] = curr.name;
			curr.style.backgroundColor="#FEAAAA";
			}
		}

	if (missed.length > 0){
		var alert_str = "Please make sure you have filled in the following fields:\n\n";
		for(i=0;i<missed.length;i++){
			alert_str += missed[i]+"\n";
			}
		alert(alert_str);
		return false;
		}
	else {
		$('realname').value = $('firstname').value + " " + $('surname').value;
		return true;
		}
	}

function checkFTBForm(){
var req, req2, req4, curr, missed = new Array();

	// standard elements
	req = new Array("title","firstname","surname","address","town","postcode");
	for(i=0;i<req.length;i++){
		curr = $(req[i]);
		curr.style.backgroundColor="#ffffff";
		if (!curr.value){
			missed[missed.length] = curr.name;
			curr.style.backgroundColor="#FEAAAA";
			}
		}

	// money details
	req2 = new Array("purchasers","income","deposit","pricerange");
	for(i=0;i<req2.length;i++){
		curr = $(req2[i]);
		curr.style.backgroundColor="#ffffff";
		if (!curr.value){
			missed[missed.length] = curr.name;
			curr.style.backgroundColor="#FEAAAA";
			}
		}

	// appointment details
	req4 = new Array("btime","bdate","bnumber","bwhere");
	for(i=0;i<req4.length;i++){
		curr = $(req4[i]);
		curr.style.backgroundColor="#ffffff";
		if (!curr.value){
			missed[missed.length] = curr.name;
			curr.style.backgroundColor="#FEAAAA";
			}
		}

	if ($(req4[3]).selectedIndex == 3){
		curr = $('bloc');
		curr.style.backgroundColor="#ffffff";
		if (!curr.value){
			missed[missed.length] = curr.name;
			curr.style.backgroundColor="#FEAAAA";
			}
		}

	if (missed.length > 0){
		var alert_str = "Please make sure you have filled in the following fields:\n\n";
		for(i=0;i<missed.length;i++){
			alert_str += missed[i]+"\n";
			}
		alert(alert_str);
		return false;
		}
	else {
		$('realname').value = $('firstname').value + " " + $('surname').value;
		return true;
		}
	}