﻿// call tab() once each page is fully loaded
window.onload = function() {
    tab();
};

// redirect to folder
var path = window.location.href;
if(path.indexOf("default.aspx") != -1) {
    window.location.href = path.substr(0, path.length - 12);
}

var donePreloading = false;
// preload DHTML Menu images
function preloadMenu() {

    var imageName = new Array(
        "bg_left_bottom",
        "bg_left_item",
        "bg_left_item_over",
        "bg_left_top",
        "bg_right_bottom",
        "bg_right_item",
        "bg_right_item_lastItem",
        "bg_right_item_lastItem_over",
        "bg_right_item_over",
        "bg_right_top",
        "root_bg_small",
        "root_bg_medium",
        "root_bg_big"
    );
    //"root_bg_home"
    
    var path, ext, len;
    
    if(navigator.appVersion.indexOf("MSIE 6.0") != -1){
        ext = ".gif";
        path = "/images/dhtmlMenu/ie6/";
    }
    else {
        ext = ".png";
        path = "/images/dhtmlMenu/";
    }

    len = imageName.length;
    var newImg = new Image();

    for(var i = 0; i < len; i++){
        newImg.src = path + imageName[i] + ext;
        newImg.onerror = function() {
            alert("The image path " + this.src + " does not exist.");
        }
    }
    donePreloading = true;
}

// show and hide tab-based divs
function tab(ID_to_show) {

    // the listOfTabs array must be created at the
    // bottom of every page that uses the tabs
    if(typeof listOfTabs != 'undefined' && listOfTabs) {
        var numberOfTabs = listOfTabs.length;
        
        // if an ID is passed in, create a deep linked URL
        if(ID_to_show) {
            window.location.hash = ID_to_show;
        }

        // now set the selected tab; check the URL for the deep link and
        // if there is one, set it as the selected tab;
        // if not, default to the first tab in the array
        if(window.location.hash) {
            // substr removes the #
            selectedTab = window.location.hash.substr(1);
        }
        else {
            selectedTab = listOfTabs[0];
        }
        
        // hide all tabs and set their CSS classes to nothing (not active)
        for(var i = 0; i < numberOfTabs; i++) {
            document.getElementById("section_" + listOfTabs[i]).style.display = "none";
            try {
                document.getElementById("link_" + listOfTabs[i]).className = "";
            }
            catch(err) {}
        }
        
        // show only the selected tab and set its CSS class to "active"
        document.getElementById("section_" + selectedTab).style.display = "block";
        try {
            document.getElementById("link_" + selectedTab).className= "active";
        }
        catch(err) {}
    }
}

function toggleDetails(id) {
    var details = document.getElementById("details_" + id);
    var row = document.getElementById("row_" + id);
    var className = details.className;
    if(className == "detailsClosed") {
        details.className = "details";
        if(row.className == "row even") {
            row.className = "row even expanded";
        } else {
            row.className = "row expanded";
        }
    }
    else {
        details.className = "detailsClosed";
        if(row.className == "row even expanded") {
            row.className = "row even";
        } else {
            row.className = "row";
        }
    }
}

function email(handle, domain){
    
    // default domain in none passed in
    if(typeof domain == 'undefined' && !domain) {
        domain = "aa.com";
    }
    
    var address = handle + "@" + domain;
    document.write("<a href=\"mailto:" + address + "\">" + address + "</a>");
}

function getEmail(handle, domain){
    
    // default domain in none passed in
    if(typeof domain == 'undefined' && !domain) {
        domain = "aa.com";
    }
    
    var address = handle + "@" + domain;
    return address;
}

counter = 0;
function toggleContact(id, sender) {
    
    if(id == "all") {
        var linkAll = document.getElementById("linkAll");
        
        //var arrDetail = document.getElementsByName("contactDetail");
        //var numberOfDetails = arrDetail.length;
        
        var anchors = document.getElementById("contactGroup").getElementsByTagName("a");
        var numberOfAnchors = anchors.length;
        
        if(counter % 2 == 0) {
            var arrDetail = getElementsByClassName("collapsed");
            var numberOfDetails = arrDetail.length;
            
            for(n = 0; n < numberOfDetails; n++) {
                arrDetail[n].className = "expanded";
            }
            linkAll.innerHTML = "Hide " + sender;
            for(n = 0; n < numberOfAnchors; n++) {
                anchors[n].className = "up";
            }
        } else {
            var arrDetail = getElementsByClassName("expanded");
            var numberOfDetails = arrDetail.length;
            
            for(n = 0; n < numberOfDetails; n++) {
                arrDetail[n].className = "collapsed";
            }
            linkAll.innerHTML = "Show " + sender;
            for(n = 0; n < numberOfAnchors; n++) {
                anchors[n].className = "down";
            }
        }
        counter++;
    }
    else {
        var contact = document.getElementById("contact_" + id);
        if(contact.className == "expanded") {
            contact.className = "collapsed";
            sender.className = "down";
        } else {
            contact.className = "expanded";
            sender.className = "up";
        }
    }
}

function getElementsByClassName(classname) {
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = document.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}