﻿// Function to find certain marked links to open a new window if 
// javascript is enabled.

function openNewWindow() {
    var newWindow = window.open(this.getAttribute('href'), 'InfoWindow', 'toolbar=0,menubar=0,scrollbars=1,width=600,height=600,resizable=1'); 
    newWindow.focus();
     
    var ran = Math.round(Math.random() * 100000);
    // This should help unwanted caching
    this.href+="&" + ran;
    
    return false; 
} 

function NewWindowLinks() {
 if (!document.getElementsByTagName) {return;}
 
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "new_window")
       {
        anchor.onclick = openNewWindow; 
        anchor.title+=" (opens new window)";
        anchor.target = "";
        var ran = Math.round(Math.random() * 100000);
        // This should help unwanted caching
        anchor.href+="&" + ran;
    }
 } 
}

function DisplayAltLanguage(cb) {
    if (!document.getElementsByTagName) {return;}
    if (!cb) {return;}

    var alt_divs = document.getElementsByTagName("div");
    for (var i=0; i<alt_divs.length; i++) {
        if (alt_divs[i].className == "alt_language")
        {
            if(cb.checked == true)
            {
                alt_divs[i].style.display = '';
            }
            else
            {
                alt_divs[i].style.display = 'none';
            }
        }
    }
}


function stripe_table(table) 
{
    // Set even and odd color using specified color strings, or defualt if nothing specified
    var evenColor = arguments[1] ? arguments[1] : "#fff";
    var oddColor = arguments[2] ? arguments[2] : "#eee";
    var border = arguments[3] ? arguments[3] : "none";
    var even = arguments[4] ? arguments[4] : false;
    
    if(!table) {return;}
    
    var rows = table.rows;
    if(!rows) {return;}
    for(var r = 0; r < rows.length; r++)
    {
        // Dont override an existing backgroundColor
        if(!rows[r].style.backgroundColor)
        {
            // Row must be visible
            if(rows[r].style.display != "none")
            {
                rows[r].style.backgroundColor = even ? evenColor : oddColor;
                var cells = rows[r].cells;
                for(var c = 0; c < cells.length; c++)
                {
                    // Does this cell have an embedded table?
                    if(cells[c].className == "embedded_table")
                    {
                        var em_table = cells[c].getElementsByTagName("table")[0];
                        if(em_table)
                        {
                            stripe_table(em_table,evenColor,oddColor,border,even);
                        }
                    }
                    else
                    {
                        // Dont override an existing backgroundColor
                        if(!cells[c].style.backgroundColor)
                        {
                            cells[c].style.backgroundColor = even ? evenColor : oddColor;
                            if(even && border != "none")
                            {
                                cells[c].style.borderTop = border;
                                cells[c].style.borderBottom = border;
                            }
                        }
                    }
                }
                even = !even;
            }
        }
    }
} 


