// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
} 

function returnDefault(theField, default_value){
	if (theField.value == '') 
		theField.value = default_value
}

function initHighlight() {
    if (!document.getElementsByTagName){ return; }
    var allfields = document.getElementsByTagName("input");

    // loop through all input tags and add events
    for (var i=0; i<allfields.length; i++){
        var field = allfields[i];
		var re = /highlightOff/;
		var reClearTextOn = /clearTextOn/;
		var reHighlightOn = /highlightOn/;
        if (((field.getAttribute("type") == "text") || (field.getAttribute("type") == "password")) && (reClearTextOn.test(field.className))) {
            field.onfocus = clearTextOn;
        }
		if (((field.getAttribute("type") == "text") || (field.getAttribute("type") == "password")) && (reHighlightOn.test(field.className))) {
            field.onfocus = highlightOn;
            field.onblur = highlightOff;
        }
		if (((field.getAttribute("type") == "text") || (field.getAttribute("type") == "password")) && (reHighlightOn.test(field.className)) && (reClearTextOn.test(field.className))) {
            field.onfocus = clearTextAndHighlightOn;
            field.onblur = highlightOff;
        }
        

    }
}


function clearTextOn() {
	clearText(this);
}

function clearTextAndHighlightOn(){
	clearText(this);
	this.style.border = '1px solid #9aebfd';
	this.style.backgroundColor = '#FFF';
}

function highlightOn() {
this.style.border = '1px solid #9aebfd';
this.style.backgroundColor = '#FFF';
}

function highlightOff() {
this.style.border = '1px solid #CCC';
this.style.backgroundColor = '#FFF';
}

// Nifty function to add onload events without overwriting
// ones already there courtesy of the lovely and talented
// Simon Willison http://simon.incutio.com/
function addLoadEvent(func) {   
    var oldonload = window.onload;
    if (typeof window.onload != 'function'){
        window.onload = func;
    } else {
        window.onload = function(){
        oldonload();
        func();
        }
    }
}
addLoadEvent(initHighlight);
