window.onload = function(e) {
        initGray("s", "Search");
}


function addEvent(obj, event, func, capture){
        if (obj.addEventListener){
                obj.addEventListener(event, func, capture);
        } else if (obj.attachEvent){
                obj.attachEvent("on"+event, func);
        }
}

function byId(id) {
        return document.getElementById(id);
}


function initGray(boxname, text) {
        var box = byId(boxname);
        if(!box) return;

        addEvent(box, "focus", function f() {cleargray(box, text);}, false);
        addEvent(box, "blur",  function f() {setgray(box, text);}, false);

        if(box.value == text) {
                box.style.color = "#999";
                box.style.textAlign = "right";
        }
        else {
                box.style.color = "#000";
                box.style.textAlign = "right";
        }
}

function cleargray(box, text) {
        if(box.value == text) {
                box.value = "";
                box.style.color = "#000";
                box.style.textAlign = "right";
        }
}
function setgray(box, text) {
        if(box.value == "") {
                box.style.textAlign = "right";
                box.style.color = "gray";
                box.value = text;
        }
}
