/**********************************************************
 * search.form.php
 *
 * Stuart Connolly
 * http://stuconnolly.com/
 *
 * Copyright (c) 2009 Stuart Connolly. All rights reserved.
 **********************************************************/

var DEFAULT_VAL = 'Search';
var isSafari    = (navigator.userAgent.indexOf("AppleWebKit") != -1);

run();

function run() 
{
	var oldOnload = window.onload;

	if (typeof(window.onload) != "function") {
		window.onload = init;
	} 
	else {
		window.onload = function() {
			oldOnload();
			init();
		}
	}
}

function init() 
{
	if (!document.getElementById) return;

	var theSearchField = document.getElementById('s');

	if (isSafari) {
		theSearchField.setAttribute('type', 'search');
		theSearchField.setAttribute('autosave', 'saved.data');
		theSearchField.setAttribute('results', '5');
		theSearchField.setAttribute('placeholder', DEFAULT_VAL);
	} 
	else {
		theSearchField.onfocus = focusSearch;
		theSearchField.onblur  = blurSearch;

		if (theSearchField.value == '') {
			theSearchField.value = DEFAULT_VAL;
		}
	}
}

function focusSearch()
{
	if (this.value == DEFAULT_VAL) {
		this.value = '';
	}
}

function blurSearch() 
{
	if (this.value == '') {
		this.value = DEFAULT_VAL;
	}
}
