
window.onload = init

function init() {

	// homepage
	if(document.getElementById('quicksearch'))
	{
		// if sale is clicked
		document.getElementById('sale').onclick = function() {
			displayhide('leasetype');
			displayhide('leaseprice');
			displayshow('saletype');
			displayshow('saleprice');
		}

		// if lease is clicked
		document.getElementById('lease').onclick = function() {
			displayhide('saletype');
			displayhide('saleprice');
			displayshow('leasetype');
			displayshow('leaseprice');
		}
	}

    displayshow('find');
    displayshow('contact');
}

function requestChange(inp)
{
	displayhide('info');
	displayhide('inspect');
	displayhide('find');
	displayhide('enquiry');
	displayhide('solution');
	displayhide('contact');

	switch(inp.type.selectedIndex)
	{
		case 1:
			displayshow('find');
			displayshow('contact');
			break;
		case 2:
			displayshow('inspect');
			displayshow('contact');
			break;
		case 3:
			displayshow('info');
			displayshow('contact');
			break;
		case 4:
			displayshow('enquiry');
			displayshow('contact');
			break;
		case 5:
			displayshow('solution');
			displayshow('contact');
			break;
		default:

			break;
	}
}

function validateForm(inp)
{
	switch(inp.type.selectedIndex)
	{
		case 1:

			if(!inp.building.value) {
				alert('Please enter the building type you are looking for');
				inp.building.focus();
				return false;
			}
			if(!inp.area.value) {
				alert('Please enter the area you require');
				inp.area.focus();
				return false;
			}

			if(!inp.location.value) {
				alert('Please enter the location you require');
				inp.location.focus();
				return false;
			}
			break;
		case 2:
			if(!inp.address.value) {
				alert('Please enter the address of the property');
				inp.address.focus();
				return false;
			}
			break;
		case 3:
			if(!inp.addressinfo.value) {
				alert('Please enter the address of the property');
				inp.addressinfo.focus();
				return false;
			}
			break;
		case 4:
			break;
		case 5:
			break;
		default:
			// nothing is selected - fail
			alert('Please select an option');
			inp.type.focus();
			return false;
			break;
	}

	if(!inp.name.value) {
		alert('Please enter your name');
		inp.name.focus();
		return false;
	}
	if(!inp.number.value) {
		alert('Please enter a phone number');
		inp.number.focus();
		return false;
	}
	if(!validateEmail(inp.email.value,false)) {
		alert('Please enter a valid email');
		inp.email.focus();
		return false;
	}


	switch(inp.type.selectedIndex)
	{

		case 4:
			if(!inp.enquiryinfo.value) {
				if(confirm('There is no message.  Would you still like to send a request?'))
					break;
				inp.enquiryinfo.focus();
				return false;
			}
			break;
		case 5:
			if(!inp.solutioninfo.value) {
				if(confirm('There is no message.  Would you still like to send a request?'))
					break;
				inp.solutioninfo.focus();
				return false;
			}
			break;
	}

	return true;
}

function show(o) {
	var g = document.getElementById(o).style;
	g.visibility = 'visible';
}

function hide(o) {
	var g = document.getElementById(o).style;
	g.visibility = 'hidden';
}

function displayhide(o) {
	var g = document.getElementById(o).style;
	g.display = 'none';
}

function displayshow(o) {
	var g = document.getElementById(o).style;
	g.display = 'block';
}
