function ValidateQuote() {
	var selQuote = document.getElementById('quote');
	var intQuote = selQuote.options[selQuote.selectedIndex].value;
	var strError = '';
	switch(intQuote) {
		case '1': // Remortgage
			strError += ValidateAmount('value_remortgage','');
			strError += ValidateTitle('title_remortgage','');
			strError += ValidateLocation('location_remortgage',' the property');
			strError += ValidatePeople();
			break;
		case '2': // Sale only
			strError += ValidateAmount('value_sale','');
			strError += ValidateTitle('title_sale','');
			strError += ValidateLocation('location_sale',' the sale property');
			strError += ValidatePeople();
			break;
		case '3': // Purchase only
		case '5': // Right to Buy
		case '6': // Shared ownership
			strError += ValidateAmount('value_purchase','');
			strError += ValidateTitle('title_purchase','');
			strError += ValidateLocation('location_purchase',' the purchase property');
			strError += ValidatePeople();
			break;
		case '4': // Sale and Purchase
			strError += ValidateAmount('value_sale','');
			strError += ValidateTitle('title_sale','');
			strError += ValidateLocation('location_sale',' the sale property');
			strError += ValidateAmount('value_purchase','');
			strError += ValidateTitle('title_purchase','');
			strError += ValidateLocation('location_purchase',' the purchase property');
			strError += ValidatePeople();
			break;
		default:
			strError += "Please select a valid quote type\n";
	}
	if(strError.length) {
		alert(strError);
		return false;
	}
	return true;
}
function ValidatePeople() {
	var txtPeople = document.getElementById('num_people');
	var bolValid = true;
	var intPeople = 0;
	txtPeople.value = txtPeople.value.replace(/[^\d]/,'');
	if(!txtPeople.value.match(/\d+/)) {
		bolValid = false;
	} else {
		intPeople = txtPeople.value - 0;
		if((intPeople < 1) || (intPeople > 4)) {
			bolValid = false;
		}
	}
	if(!bolValid)	{	return("Please enter a valid number of persons between 1 and 4\n");	}
	return('');
}
function SetQuoteType(intQuote) {
	var selQuote = document.getElementById('quote');
	var intOptions = selQuote.options.length;
	for(intLoop = 0;intLoop < intOptions;intLoop++) {
		if(selQuote.options[intLoop].value == intQuote) {
			selQuote.selectedIndex = intLoop;
			ShowHide(intQuote);
			return;
		}
	}
}
function ValidateAmount(strField,strText) {
	var txtValue = document.getElementById(strField);
	if(!txtValue.value.match(/\d+/)) {	return('Please enter a valid amount'+strText+"\n");	}
	return('');
}
function ValidateTitle(strField,strText) {
//	var selTitle = document.getElementById(strField);
//	if(selTitle.selectedIndex <= 0) {	return('Please select either freehold or leasehold as the title'+strText+"\n");	}
	return('');
}
function ValidateLocation(strField,strText) {
//	var selTitle = document.getElementById(strField);
//	if(selTitle.selectedIndex <= 0) {	return('Please select a valid location for'+strText+"\n");	}
	return('');
}
function ShowHide(intQuote) {
	intQuote = intQuote - 0;
	var sVisible = new Object();
	sVisible['divRemortgage'] = false;
	sVisible['divPurchase'] = false;
	sVisible['divSale'] = false;
	sVisible['divPurchaseOptions'] = false;
	sVisible['divAllOptions'] = true;
	switch(intQuote) {
		case 1: // Remortgage
			sVisible['divRemortgage'] = true;
			sVisible['divPurchaseOptions'] = true;
			break;
		case 2: // Sale only
			sVisible['divSale'] = true;
			break;
		case 3: // Purchase only
		case 5: // Right to Buy
		case 6: // Shared ownership
			sVisible['divPurchase'] = true;
			sVisible['divPurchaseOptions'] = true;
			break;
		case 4: // Sale and Purchase
			sVisible['divPurchase'] = true;
			sVisible['divPurchaseOptions'] = true;
			sVisible['divSale'] = true;
			break;
		default: // Should only be for initial load and reselecting "blank" option
			sVisible['divAllOptions'] = false;
	}
	for(strTarget in sVisible) {
		divTarget = document.getElementById(strTarget);
		if(sVisible[strTarget]) {
			divTarget.style.display = 'block';
		} else {
			divTarget.style.display = 'none';
		}
	}
}

