﻿function redBackground(e) {
    var clientId = GetClientId(e)
    var obj = document.getElementById(clientId);
    obj.style.backgroundColor = "#9f3539";
}

function noBackground(e) {
    var clientId = GetClientId(e)
    var obj = document.getElementById(clientId);
    obj.style.backgroundColor = "Transparent";
}

function GetClientId(strid) {
    var elements = document.getElementsByTagName("*");
    if (!elements) {
        elements = document.all;
    }
    if (!elements) {
        alert("Did not find any elements in document");
    }
    var count = elements.length;
    var i = 0;
    var eleName;
    for (i = 0; i < count; i++) {
        eleName = elements[i].id;
        pos = eleName.indexOf(strid);
        if (pos >= 0) break;
    }
    return eleName;
}

function changeImageMouseOver(id, ext) {
	if (!ext) ext = 'jpg';
    var clientID = GetClientId(id);
    var imagesrc = document.getElementById(clientID).src;
    imagesrc = imagesrc.substring(0, imagesrc.lastIndexOf('.' + ext));
    document.getElementById(clientID).src = imagesrc + "_mouseover."+ext;
}

function changeImageMouseOut(id, ext) {
	if (!ext) ext = 'jpg';
    var clientID = GetClientId(id);
    var imagesrc = document.getElementById(clientID).src;
    imagesrc = imagesrc.substring(0, imagesrc.lastIndexOf('_mouseover.'+ext));
    document.getElementById(clientID).src = imagesrc + "."+ext;
}

function changeButtonMouseOver(id) {
    var clientID = GetClientId(id);
    var button = document.getElementById(clientID);
    button.style.backgroundColor = "#9f3539";
}

function changeButtonMouseOut(id) {
    var clientID = GetClientId(id);
    var button = document.getElementById(clientID);
    button.style.backgroundColor = "#e18d19";
}

function setBackgroundRed(object) {
    object.setAttribute("style","background-color:#9f3539; color:White");
}

function setBackgroundOrange(object) {
    object.setAttribute("style","background-color:#e18d19; color:White");
}

function setBackgroundGreen(object) {
    object.setAttribute("style","background-color:#939e13; color:White");
}

function setBackgroundClear(object) {
    object.setAttribute("style","background-color:transparent; color:White");
}

var lastSelectedRow = null;

// unselect old selected row, select new row, highlight new row
function selectRow(row) {
    if (lastSelectedRow != null) {
        lastSelectedRow.style.backgroundColor = '#FFFFFF';
    }
    highlightRow(row);
    lastSelectedRow = row;
    alert(lastSelectedRow);
}

function unSelectRows() {
    if (lastSelectedRow != null) {
        lastSelectedRow.style.backgroundColor = '#FFFFFF';
    }
    lastSelectedRow = null;
}

// highlight a row
function highlightRow(row) {
    row.style.backgroundColor = '#EFEFEF';
}

// unhighlight a row
function unhighlightRow(row) {
    if (lastSelectedRow != row) {
        row.style.backgroundColor = '#FFFFFF';
    }
}