/* here is test */
function SelectAll()
{
    s = document.getElementById("sForm");
    for(i=0;i<s.elements.length;i++)
    {
        s.elements[i].checked = true;
    }
}

function SelectOthers()
{
    s = document.getElementById("sForm");
    for(i=0;i<s.elements.length;i++)
    {
        s.elements[i].checked = !s.elements[i].checked;
    }
}

function v_change(clickDomId, toChangeId){
    toChangeDom = document.getElementById(toChangeId)
    clickDom = document.getElementById(clickDomId)
    if(toChangeDom.style.display == "none"){
        toChangeDom.style.display = "inline"
        clickDom.className = "folder_title expand"
    }else{
        toChangeDom.style.display = "none"
        clickDom.className = "folder_title collapse"
    }
}

function ajaxLoad() {
    // override this in view
}

function leavingPage() {
    // override this in view
}

function filterColumn(searchBox){
    searchBox = $(searchBox);
    var siblingSearchBoxes = searchBox.parentNode.siblings().collect(function(th){ return th.childElements().last(); })
    filterSingleColumn(searchBox, false);
    siblingSearchBoxes.each(function(box){ filterSingleColumn(box, true) });
}

function filterSingleColumn(searchBox, connectFilter){
    searchBox = $(searchBox);
    columnIndex = searchBox.up(1).childElements().indexOf(searchBox.up(0));
    tbody = searchBox.up(2).next();
    
    tbody.childElements().each(function(tr){
        content = tr.childElements()[columnIndex].innerHTML;
        content = content.replace(/<[^>]*>/g, "")
        if((new RegExp((searchBox.value || "").strip(), 'ig').test(content))){
            if(!connectFilter){
                tr.show();
            }
        }else{
            tr.hide();
        }
    })
}

function toggleSearchBox(fromDom){
    var target = $(fromDom).up(1).next();
    target.toggle();
}

function resetFilter(searchBox){
    searchBox = $(searchBox) ;
    searchBox.value = '';
    filterColumn(searchBox);
}

function toggleBlock(blockId){
    Element.toggle(blockId, 'slide')
    var block = document.getElementById("p_" + blockId)
    if(block.className == "hide"){
        block.className = "expand"
    }else{
        block.className = "hide"
    }

}

