﻿var windowHandle = null;
var windowHandle_closed = true;

function Popup (link, width, height) {
    NewWindow (link.href, 'centerpopup1', width, height, 'yes');
    return false;
}

function NewWindow(mypage, myname, w, h, scroll) {
    //Close popup window if open
    if (windowHandle != null) {
        if (!windowHandle_closed) {
            windowHandle_closed = true;
            windowHandle.close();
        }
    }
    //Open popup window
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    var winprops = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',scrollbars=' + scroll + ',resizable';
    windowHandle = window.open(mypage, myname, winprops);
    windowHandle_closed = false;
    if (parseInt(navigator.appVersion) >= 4) {
        windowHandle.window.focus();
    }
}

function noteswindow () {
    window.open("","popup","width=470,height=540,left=0,top=90,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=no,copyhistory=0,")
}

function toggleLayer (whichLayer) {
    var elem, vis;
    elem = getElement (whichLayer);
    vis = elem.style;  // if the style.display value is blank we try to figure it out here
    if (vis.display == '' && elem.offsetWidth != undefined && elem.offsetHeight != undefined) {
        vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0) ? 'block' : 'none';
    }
    vis.display = (vis.display == '' || vis.display == 'block') ? 'none' : 'block';
    
    elem = getElement ("dyn_line");
    elem.getAttributeNode("class").value = (elem.getAttributeNode("class").value == "expand")?"minus" : "expand";
}

// the funtion hasClass and stripe is used to format tables
// this function is needed to work around 
// a bug in IE related to element attributes
function hasClass(obj) {
    var result = false;
    if (obj.getAttributeNode("class") != null) {
        result = obj.getAttributeNode("class").value;
    }
    return result;
}

// id = id of table to stripe, altflag = if true use dark colour first
function stripe (id, altflag) {
    if (altflag != true) {
        altflag = false;
    }
    var even = false;
    var evenColor = altflag ? "#DEEAF7" : "#F2F8FF";
    var oddColor = altflag ? "#F2F8FF" : "#DEEAF7";
    
    var table = document.getElementById(id);
    if (! table) { return; }
    var tbodies = table.getElementsByTagName("tbody");
    
    for (var h = 0; h < tbodies.length; h++) {
        
        var trs = tbodies[h].getElementsByTagName("tr");
        for (var i = 0; i < trs.length; i++) {
            
            if (! hasClass(trs[i]) && ! trs[i].style.backgroundColor) {
 		        
                var tds = trs[i].getElementsByTagName("td");
                for (var j = 0; j < tds.length; j++) {
                    
                    var mytd = tds[j];
                    if (! hasClass(mytd) && ! mytd.style.backgroundColor) {
                        
                        mytd.style.backgroundColor = even ? evenColor : oddColor;
                    }
                }
            }
            even = ! even;
        }
    }
}

function getElement (id) {
    var elem;
    if (document.getElementById) {
        elem = document.getElementById(id);
    } else if (document.all) {
        elem = document.all[id];
    } else if(document.layers) {
        elem = document.layers[id];
    }
    return elem;
}

var select_highlight_img = "";
function select_unhighlight(img_name) {
    img_name.src = select_highlight_img;
}

function select_highlight(img_name) {
    select_highlight_img = img_name.src;
    var xdex = img_name.src.indexOf ("_highlight");
    if (xdex == -1) {
        img_name.src = img_name.src.substr (0, img_name.src.lastIndexOf (".gif")) + "_highlight.gif";
    }
}

if (window.addEventListener) {
    window.addEventListener('load', replacePageHeader, false); 
}  else if (window.attachEvent) {
    window.attachEvent('onload', replacePageHeader);
}

function replacePageHeader () {
    var elem = getElement ("page-header");
    if (elem != null) {
        elem.innerHTML = '<span class="title-l"></span><span class="title-c"><span class="title-c-text">' + elem.innerHTML + '</span></span><span class="title-r"></span>';
    }
}

function bookmarkPage (title, url) {
    if (window.sidebar) {
        window.sidebar.addPanel(title, url, "");
    } else if (window.external) {
        window.external.AddFavorite(url, title);
    }
}

function showInfoBox(infoID) {
    jQuery(".info_table th a").stop(true, true);
    jQuery(".info_table th a").css({ "backgroundColor": "#FFFFB3", "font-weight": "normal" });
    jQuery("#header_" + infoID).css({ "backgroundColor": "#fee954", "font-weight": "bold" });


    var info_id_int = parseInt(infoID, 10);
    jQuery(".hidden_info_box").stop(true, true);
    jQuery(".hidden_info_box").hide();
    jQuery("#info_" + infoID).slideDown("slow");
}

function MentorObj(args) {
    this.width = '0';
    this.mentor = '';
    this.dynloc = '';
    if (args != null) {
        if (args["width"] != null) {
            this.width = args["width"];
        }
        if (args["mentor"] != null) {
            this.mentor = args["mentor"];
        } else {
            this.mentor = "1";
        }
        if (args["dynloc"] != null) {
            this.dynloc = args["dynloc"];
        }
    }
    var html = jQuery("div#mentor-wrap").html();
    var output = '<div id="mentor"><table><tr><th><a href="#"><img src="' + this.dynloc + '../generic_css/images/coach/' + this.mentor + '_small.jpg" alt="Coach" /></a></th><td><div id="mentor-text"><img src="' + this.dynloc + '../generic_css/images/quote_start.gif" alt="Quote symbol" style="position: absolute; top: 8px; left: 15px;" /><img src="' + this.dynloc + '../generic_css/images/quote_end.gif" alt="Quote symbol" style="position: absolute; bottom: 5px; right: 5px;" /><a href="#" class="close_btn"><img src="' + this.dynloc + '../generic_css/images/coach/close.png" alt="Close mentor" /></a>' + html + '</div></td></tr></table></div>';
    jQuery("div#mentor-wrap").html(output);
    jQuery("div#mentor-wrap div#mentor-text").css({ width: this.width + 'px' });
    jQuery("div#mentor-wrap th a").click(function() {
        if (jQuery("div#mentor-text").css("display") != "none") {
            jQuery("div#mentor-text").fadeOut("fast");
            jQuery("div#mentor table th a img").css("border", "0px");
        } else {
            jQuery("div#mentor-wrap div#mentor-text").fadeIn("slow");
            jQuery("div#mentor table th a img").css("border-right", "1px solid black");
            jQuery("div#mentor table th a img").css("border-bottom", "1px solid black");
        }
        return false;
    });
    jQuery("div#mentor-wrap").show();
    jQuery("html").click(function() {
        if (jQuery("div#mentor-text").css("display") != "none") {
            jQuery("div#mentor-text").fadeOut("fast");
            jQuery("div#mentor table th a img").css("border", "0px");
        }
    });
}