﻿/* Clear the search box when it is clicked on */
function clearSearchBox(e)
{
    var txtSearch = e;

    if (txtSearch == null)
        return false;

    if (txtSearch.value == "Search here")
        txtSearch.value = '';
}

/* Disable enter key press on masked text field*/
document.onkeydown = function()
{
    var e = document.activeElement;

    if (e.tagName == "INPUT" 
        && (e.type == "text" || e.type == "password" || e.tagName == "SELECT") 
        && window.event.keyCode == 13) 
    {
        window.event.keyCode = 9;
    }
}

/*function SetAlternativeStyles(elementId) {
    var table = document.getElementById(elementId);
    var tableBodies = table.getElementsByTagName('tbody');
    // Loop through these tbodies

    for (var i = 0; i < tableBodies.length; i++) {
        // Take the tbody, and get all it's rows
        var tableRows = tableBodies[i].getElementsByTagName('tr');
        // Loop through these rows

        for (var j = 0; j < tableRows.length; j++) {
            // Check if j is even, and apply classes for both possible results
            if ((j % 2) != 0) {
                tableRows[j].className = 'alternatingStyle';
            }
        }
    }
}*/

function SetAlternativeStyles()
{
    var tableRows = document.getElementsByTagName('table');
    
    // Loop through these trs
    //for (var rowIndex = 0; rowIndex < tableRows.length; rowIndex++)
        //tableRows[rowIndex].style.width = "600px";
        
    var previousWasAlt = false;
    var tableRows = document.getElementsByTagName('tr');
    
    // Loop through these trs
    for (var rowIndex = 0; rowIndex < tableRows.length; rowIndex++)
    {
        //if (tableRows[rowIndex]
    
        if (!previousWasAlt)
        {
            tableRows[rowIndex].className = 'alternatingStyle';
            previousWasAlt = true;
        }
        else
        {
            tableRows[rowIndex].className = '';
            previousWasAlt = false;
        }
    }
    
    
}

// SetAlternativeStyles after every partial postback
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

function EndRequestHandler(sender, args)
{
    SetAlternativeStyles();
}


function showPanel(paneltoshow, panels) 
{
    var item;
    for (i = 0; i < panels.length; i++)
    {
        item = document.getElementById(panels[i]);
        item.style.visibility = (visiblepanel == panels[i]) ? 'visible' : 'hidden';
    }
}

function disableControl(controltodisable, readonly)
{
    var item = document.getElementById(controltodisable);
    if (controltodisable && item)
    {
        item.disabled = readonly;
    }
}

function showStatus(control)
{
    alert(control.disabled);
    /*onchange = "javascript:disableControl(txtIncidentDateClientID, this.value=='1'?true:false);return true;" */
}
