var DEF_VAL   = "Search...";
var isSafari = (navigator.userAgent.indexOf("AppleWebKit") !=-1); // Detecting WebKit-based browsers
run();
function run()
{
	if (window.addEventListener) window.addEventListener("load",init,false);
}
function init() {
    if (!document.getElementById) return;
    var theSearchField = document.getElementById('s');
    if (isSafari) {
        // Changing type to 'search' from 'text'
        // and inserting 'autosave,' 'results,' 'placeholder' values for WebKit-based browsers
        theSearchField.setAttribute('type', 'search');
        theSearchField.setAttribute('autosave', 'net.geekthang.search');
        theSearchField.setAttribute('results', '5');
        theSearchField.setAttribute('placeholder', DEF_VAL);
        theSearchField.setAttribute('id', 'safsearch');
    } else {
        // Doing the 'Live Search'-displaying-&-hiding-stuff for non-WebKit-based browsers
        theSearchField.addEventListener("blur",blurSearch,true);
        theSearchField.addEventListener("focus",focusSearch,true);
        if (theSearchField.value=='') theSearchField.value = DEF_VAL;
    }
}
function focusSearch() {
    if (this.value==DEF_VAL) {
        this.value = '';
    }
}
function blurSearch() {
    if (this.value=='') {
        this.value = DEF_VAL;
    }
}