/*  Ajax style functions */

function siteInit(){
  // Called with the body onload event.
  // Customise according to site requirements.
}

function deleteRow(rowId){
    var row = document.getElementById(rowId);
    row.parentNode.removeChild(row);
    return false;
}

function moveRowUp(klassName, rowId){
    var row = document.getElementById(rowId);
    var prevRow = row.previousSibling;
    if(prevRow==null) return;
    while(prevRow.className==null || !prevRow.className.match(klassName)) {
        prevRow = prevRow.previousSibling;
        if(prevRow==null) return;
    }
    row.parentNode.insertBefore(row, prevRow);
}

function moveRowDown(klassName, rowId){
    var row = document.getElementById(rowId);
    var nextRow = row.nextSibling;
    if(nextRow==null) return;
    while(nextRow.className==null || !nextRow.className.match(klassName)) {
        nextRow = nextRow.nextSibling;
        if(nextRow==null) return;
    }
    row.parentNode.insertBefore(nextRow, row);
}

function getRows(parentId, rowTag, klassName) {
    var holder = document.getElementById(parentId);
    var rows = holder.getElementsByTagName(rowTag);
    var finalRows = [];
    for(var i=0; i<rows.length; i++){
        if(rows[i].className.match(klassName)){
            finalRows.push(rows[i]);
        }
    }
    return finalRows;
}

function addComponent(tagId, url, pars) {
    var myAjax = new Ajax.Updater(
        tagId,
        url,
        {
            method: 'get',
            parameters: pars,
            onComplete: redrawLayout
        });
}

