/* global.js - global Javascript file */

/* Function to change the background color of table rows */

/* Create array to remember which row has been clicked */
var marked_row = new Array;


/**
*
* @param 	object		the table row
* @param 	integer 	the row number
* @param 	string		the action calling this script (over, out or click)
* @param 	string		the default background color
* @param 	string		the color to use for mouseover
* @param 	string		the color to use for marking a row
*
* @return	boolean	whether pointer is set or not
*/

function showBranch(branch)
{
    var objBranch = document.getElementById(branch).style;
    if (objBranch.display == "block")
        objBranch.display = "none";
    else
        objBranch.display = "block";
}



function changeColor(theRow, theRowNum, theRowOrgColor, theAction)
{
    var theCells = null;
    var newColor = null;

    // 1. Gets the current row and exits if the browser can't get it
    if (typeof (document.getElementsByTagName) != 'undefined')
    {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof (theRow.cells) != 'undefined')
    {
        theCells = theRow.cells;
    }
    else
    {
        return false;
    } // end 1


    // 2. Declare vars
    var rowCellsCnt = theCells.length;
    var domDetect = null;
    var currentColor = null;
    var newColor = null;

    // The colors
    var highlightColor = '#FFFECC';
    var theClickColor = '#FEFDB5';
    // The original colors
    var grid_row_regbg = '#FFFFFF';
    var grid_row_dkbg = '#F5F5F5';
    // end 2


    // 3.1 ... with DOM compatible browsers except Opera that does not return
    // 	valid values with "getAttribute"
    if (typeof (window.opera) == 'undefined' && typeof (theCells[0].getAttribute) != 'undefined')
    {
        //currentColor = theCells[0].getAttribute('bgcolor');
        domDetect = true;
    }
    // 3.2 ... with other browsers
    else
    {
        //	currentColor = theCells[0].style.backgroundColor;
        domDetect = false;
    } // end 3


    // 4.1 Check theAction parameter from the function call -----> over
    if (theAction == 'over')
    {
        // MouseOver, then check to see if row is selected
        if (marked_row[theRowNum] == true)
        {
            // If so then change nothing
            //newColor = theClickColor;
        } else
        {
            // Otherwise then highlight
            newColor = highlightColor;
        }
    }
    // 4.2 Check theAction parameter from the function call -----> out
    else if (theAction == 'out')
    {
        // MouseOut, then check to see if row is selected
        if (marked_row[theRowNum] == true)
        {
            // If so then change nothing
            //newColor = theClickColor;
        } else
        {
            // Otherwise, then check to see what the original background color (class) was
            if (theRowOrgColor == 'grid_row_regbg')
            {
                // If it was the grid_row_regbg class...
                newColor = grid_row_regbg;
            } else
            {
                // ...or the grid_row_dkbg class
                newColor = grid_row_dkbg;
            }
        }
    }
    // 4.3 Check theAction parameter from the function call -----> click
    else if (theAction == 'click')
    {
        // MouseDown, then check to see if row is selected
        if (marked_row[theRowNum] == true)
        {
            // If it is then change to highlight...
            newColor = highlightColor;
            // ...and set indices to false
            marked_row[theRowNum] = false;
        } else
        {
            // Otherwise, set to clickColor...
            newColor = theClickColor;
            // ...and set indicis to true
            marked_row[theRowNum] = true;
        }
    } // 4


    // 5. Sets the new color...
    if (newColor)
    {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        /* if (domDetect) {
        for (c = 0; c < rowCellsCnt; c++) {
        theCells[c].setAttribute('bgcolor', newColor, 0);
        } // end for
        }
        // 5.2 ... with other browsers
        else {*/
        for (c = 0; c < rowCellsCnt; c++)
        {
            theCells[c].style.backgroundColor = newColor;
        }
        //	}
    } // end 5

    return true;
} // end of the 'changeColor()' function


function showDiv(divID)
{
    document.getElementById(divID).style.visibility = "visible";
    document.getElementById(divID).style.height = "auto";
}

function HideDiv(divID)
{
    document.getElementById(divID).style.visibility = "hidden";
    document.getElementById(divID).style.height = "0px";
}

function hideAllDivs(tot_count)
{
    for (i = 0; i < tot_count; i++)
    {
        HideDiv(i);
    }
}

function hideAll_product_features_Divs(divID)
{
    var div = new Array(5);
    div[0] = "introduction";
    div[1] = "instruction";
    div[2] = "functionality";
    div[3] = "faq";
    div[4] = "images";
    div[5] = "order_info";
    for (i = 0; i <= 5; i++)
    {
        var change = document.getElementById(div[i]);
        if (div[i] == divID)
        {
            showDiv(div[i]);
        } 
        else
        {
            HideDiv(div[i]);
        }
    }
}

function changeCssClass(divID)
{
    if (document.getElementById(divID).className == "prd_active_tab")
    {
        document.getElementById(divID).className = "prd_inactive_tab";
    }
    else if (document.getElementById(divID).className == "prd_inactive_tab")
    {
        document.getElementById(divID).className = "prd_active_tab";
    }
    else
    {
        document.getElementById(divID).className = "prd_active_tab";
    }
}

function changeOtherCssClass(divID)
{
    if (document.getElementById(divID).className == "prd_inactive_tab")
    {
        document.getElementById(divID).className = "prd_inactive_tab";
    }
    else if (document.getElementById(divID).className == "prd_active_tab")
    {
        document.getElementById(divID).className = "prd_inactive_tab";
    }
    else
    {
        document.getElementById(divID).className = "prd_inactive_tab";
    }
}

function changeAllCssClass(divID, tot_count)
{
    //alert(tot_count);
    var div = new Array(tot_count);
    div[0] = "ctl00_ContentPlaceHolder1_div_intro1";
    div[1] = "ctl00_ContentPlaceHolder1_div_instruction_fr_use1";
    div[2] = "ctl00_ContentPlaceHolder1_div_funct1";
    div[3] = "ctl00_ContentPlaceHolder1_div_faq1";
    div[4] = "ctl00_ContentPlaceHolder1_div_images1";
    div[5] = "ctl00_ContentPlaceHolder1_div_order1";
    for (i = 0; i <= tot_count; i++)
    {
        var change = document.getElementById(div[i]);
        if (div[i] == divID)
        {
            changeCssClass(div[i]);
        }
        else
        {
            changeOtherCssClass(div[i]);
        }
    }
}

function changeCss_product(divID)
{
    if (document.getElementById(divID).className == "prod-fmly-act")
    {
        document.getElementById(divID).className = "prod-fmly-dact";
    }
    else if (document.getElementById(divID).className == "prod-alpha-act")
    {
        document.getElementById(divID).className = "prod-alpha-dact";
    }
    else if (document.getElementById(divID).className == "prod-alpha-dact")
    {
        document.getElementById(divID).className = "prod-alpha-act";
    }
    else
    {
        document.getElementById(divID).className = "prod-fmly-act";
    }
}

function changeOtherCss_product(divID)
{
    if (document.getElementById(divID).className == "prod-alpha-dact")
    {
        document.getElementById(divID).className = "prod-alpha-dact";
    }
    else if (document.getElementById(divID).className == "prod-fmly-dact")
    {
        document.getElementById(divID).className = "prod-fmly-dact";
    }
    else if (document.getElementById(divID).className == "prod-fmly-act")
    {
        document.getElementById(divID).className = "prod-fmly-dact";
    }
    else
    {
        document.getElementById(divID).className = "prod-alpha-dact";
    }
}

function changeAllCss_product(divID, tot_count)
{
    //alert(tot_count);
    var div = new Array(tot_count);
    div[0] = "product_family";
    div[1] = "alpha";
    for (i = 0; i < tot_count; i++)
    {
        var change = document.getElementById(div[i]);
        if (div[i] == divID)
        {
            changeCss_product(div[i]);
        }
        else
        {
            changeOtherCss_product(div[i]);
        }
    }
}

function openwindow(as_id)
{
    window.open("../view_image.aspx?image=" + as_id, "mywindow", "toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1");
}


