function addEvent(element, eventname, func, use_capture)
{
	if (element.addEventListener) 
	{
		element.addEventListener(eventname, func, use_capture);
		return true;
	}
	else if (element.attachEvent)
	{
		var r=element.attachEvent('on'+eventname, func);
		return r;
	}
	else
	{
		element['on'+eventname]=func;
		return true;
	}

	return false;
}

function focusWords()
{
	var words;
	words=document.getElementById('words');

	if (words.value == words.defaultvalue)
		words.value='';
}

function blurWords()
{
	var words;
	words=document.getElementById('words');

	if (words.value == '')
		words.value=words.defaultvalue;
}

function loadEvents()
{
	var words;
	words=document.getElementById('words');
	
	if (words)
	{
		var labels=document.getElementsByTagName('label');
		var label;
		for (var i=0; i < labels.length; i++)
		{
			if (labels[i].htmlFor == 'words')
			{
				label=labels[i];
			}
		}
		if (label)
		{
			label.style.display='none';
			words.defaultvalue=label.childNodes[0].nodeValue;
		}
		else words.defaultvalue='Search';
		blurWords();
		addEvent(words, 'focus', focusWords, false);
		addEvent(words, 'blur', blurWords, false);
	}

	var regarding=document.getElementById('Regarding');

	if (regarding && regarding.nodeName == 'select')
	{
		prev_reg_value=regarding.selectedIndex;
		addEvent(regarding, 'change', updateEnquiry, false);
	}
}

if (document.addEventListener) 
	document.addEventListener("DOMContentLoaded", loadEvents, false);
else {
	addEvent(window, 'load', loadEvents, false);
}

var default_texts=['',
'I need to put my business/organisation online as quickly and cheaply as possible!\n\nI don\'t, however, know enough about the web to know what would work best for me. Please can you send me more information/call me to discuss my requirements?',
'I am looking for website design for a small business.\n\nWe can provide some branding, content and materials for you to work with but this will need to be supplemented by you. The website will need to consist of around 6-10 pages, perhaps as follows:\nIntroduction\nAbout Us\nProducts/Services\nOnline Enquiries\nLocation\nContact Us\n\nPlease can you give me an estimate for this design?',
'I am looking for website design for a medium-sized business.\n\nWe can provide branding, content and materials for you to work with. The website will need to consist of around 20 pages, perhaps with the following sections:\nWelcome\nAbout Us\nPages for products and services\nOnline Enquiries\nLocation\nContact Us\n\nPlease can you give me an estimate for this design?',
'I am looking for website design for a large business.\n\nIt will need a content management system for potentially hundreds of pages in many different sections, and it will need to adhere to strict corporate guidelines. We have extensive photography for you to draw on. Please can you give an estimate of the cost and timescale for this kind of project?',
'I am looking for web application development.\n\nMy business/organisation requires a web application to <describe task>.\n\nPlease contact me by phone/email to discuss the features it will need so that you can come back to me with an estimate.',
'We are intending to open a new e-Commerce shop and require design, software and hosting.\n\nPlease can you provide more information about your software and costs?',
'We are a startup business and I am very interested in your offer for 15% off website design!\n\nPlease call me back on the above telephone number to discuss my requirements.'
];
var prev_reg_value=0;

function updateEnquiry(e)
{
	var regarding=document.getElementById('Regarding');
	var enquiry=document.getElementById('Enquiry');

	if (!regarding || !enquiry)
		return;

	if (regarding.selectedIndex != prev_reg_value
	    && (enquiry.value == default_texts[prev_reg_value] || enquiry.value == ''))
	{
		if (regarding.selectedIndex < default_texts.length)
			enquiry.value=default_texts[regarding.selectedIndex];
	}
	prev_reg_value=regarding.selectedIndex;
}
