// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function swapContributions (toShow, toHide, toZero) {
    contribToShow = document.getElementById(toShow)
    Element.show(toShow); 
    document.getElementById(toZero).value = 0; 
    Element.hide(toHide); 
    return false
}

function closeHelp(dom_id) {
    if (element = document.getElementById('current_hint')) {
        if(element && element.className != "off"){
            Effect.Fade('helpExplanation');
            if (document.getElementById(dom_id)) {
              new Effect.Highlight(dom_id, {startcolor:'#D2E7F2', restorecolor:'#FFFFFF'});
            }
            element.className = "off"
        }
    }
}


function turnErrorOff(dom_id) {
    //close any outstanding help elements (replaces the previous onblur: closehelp() that was closing too agressively)
    autoCloseHelp(dom_id);

    element = document.getElementById(dom_id);
    spanElements = element.getElementsByTagName("span");
    for(index in spanElements) {
        if (spanElements[index].className == "fieldWithErrors") {
            spanElements[index].className = "off";
        }
    }
    //do the same thing for the paragraph tags, once you've figured out how to give then a class
}

function closeError() {
    //close any outstanding help elements (replaces the previous onblur: closehelp() that was closing too agressively)
    
    Effect.Fade('errorExplanation');
    
    spanElements = document.getElementsByTagName("span");
    for(index in spanElements) {
        if (spanElements[index].className == "fieldWithErrors") {
            spanElements[index].className = "off";
        }
    }
    //do the same thing for the paragraph tags, once you've figured out how to give then a class
}

function autoCloseHelp(dom_id) {
    if (element = document.getElementById('current_hint')) {
        if(element && element.className != "off" && element.value != dom_id){
            Effect.Fade('helpExplanation');
            new Effect.Highlight(element.value, {startcolor:'#D2E7F2', restorecolor:'#FFFFFF'});
            element.className = "off"
        }
    }
}
