﻿/*----------------------------------------------------------------------
 * Pop-up window 
 *
 * author:    Michael van Runt, Mar 10 2003
 * modified:  Arkadiusz Gruszowski, Apr 28 2006
 *            Wojtek Tomalik, Feb 27, 2007
 */
var visibleProduct = null;
var visibleTopic = null;
var visibleCertification = null;
var currentLoc = "_NONE_";
var homepage = false;
function trainingInit()
{
    if ( homepage ) {
        
        evenColumnsHP();
        populateLocations( "_locSelect" );
        populateLocations( "_locSelect2" );
        showProduct( 'prod__NONE_' );
        showCertification( 'cert__NONE_' );
        showTopic( 'topic__NONE_' );
        //takeSurvey();
    } else {
        populateLocations( "_locSelect" );
        populateLocations( "_locSelect2" );
        //showProduct( 'prod__NONE_' );
        //showCertification( 'cert__NONE_' );
        //showTopic( 'topic__NONE_' );
        //takeSurvey();
        //evenColumns();
    }
}
function showLocations( loc )
{
    try {
        var t = document.getElementById( "classList" );
        var msg = document.getElementById( "classMsg" );
    } catch( e ) { alert( "error!" ); }
    if( !t || !msg )
        alert( "error!" );
    if( loc == "_NONE_" )
    {
        msg.style.display = "block";
        t.style.display = "none";
        return;
    }
    else if( currentLoc == "_NONE_" )
    {
        msg.style.display = "none";
        t.style.display = "block";
    }
    currentLoc = loc;
    var trs = t.getElementsByTagName( "TR" );
    for( var i=(trs.length-1); i >= 1; i-- )
    {
        if( trs[i].className == loc )
            trs[i].style.display = "block";
        else
            trs[i].style.display = "none";
    }
}
/* --------------------
 * Correct Page Height
 *
 * Michael G. Pifalo / 2007.03.05
 *
*/
function correctPgHt()
{
    /*
    if ((d.getElementById('tab_content').offsetHeight) > ((d.getElementById('ContentBody').offsetHeight)) - 150 ) {
        d.getElementById('Leftside').style.height = (d.getElementById('tab_content').offsetHeight) + 150 + 'px';
        d.getElementById('ContentBody').style.height = (d.getElementById('tab_content').offsetHeight) + 150 + 'px';
    }
    */
}
function showProduct( groupName )
{
    if( visibleProduct != null )
        visibleProduct.style.display = "none";
    try {
        var group = document.getElementById( groupName );
    } catch( e ) { return; }
    if( !group ) return;
    visibleProduct = group;
    group.style.display = "block";
    correctPgHt();
}
function showTopic( groupName )
{
    if( visibleTopic != null )
        visibleTopic.style.display = "none";
    try {
        var group = document.getElementById( groupName );
    } catch( e ) { return; }
    if( !group ) return;
    visibleTopic = group;
    group.style.display = "block";
    correctPgHt();
}
function showCertification( groupName )
{
    if( visibleCertification != null )
        visibleCertification.style.display = "none";
    try {
        var group = document.getElementById( groupName );
    } catch( e ) { return; }
    if( !group ) return;
    visibleCertification = group;
    group.style.display = "block";
    correctPgHt();
}
function populateLocations( fieldID )
{
    if( !fieldID )
        fieldID = "_locSelect";    
    try {
        var selectField = document.getElementById( fieldID );
    } catch( e ) { return; }
    if( !selectField ) return;
    var loc, i = 1;
    selectField.options[0] = new Option( "- Select Location -", "_NONE_" );
    for( loc in locations )
        selectField.options[i++] = new Option( locations[loc], loc );
}
function popWin(winURL, winName, winOptions, winSize) {
    // Get screen dimensions
    var scrW = 600, scrH = 400; // default sizes
    if (document.all || document.layers) {
        scrW = screen.availWidth;
        scrH = screen.availHeight;
    }
    
    // Set popup size
    var popW = 600, popH = 400; // default sizes
    if (window.screen) {
        popW = window.screen.availWidth * winSize / 100;
        popH = window.screen.availHeight * winSize / 100;
    }
    var leftPos = (scrW-popW)/2, topPos = (scrH-popH)/3;
    
    // Build window options
    winOptions += ",width=" + popW + ",height=" + popH + ",top=" + topPos + ",left=" + leftPos;
    
    // Generate window
    var win = window.open(winURL,winName,winOptions);
    
    if(win == null)
        alert("Error:: Cannot open new window. Unfortunately this site requires popup windows, please turn off any popup blocking software.");    
} // End function

/*----------------------------------------------------------------------
 * Printer friendly popup generator, multiple CSS relies on ASP pre-exec
 *
 * author:    Michael van Runt, Feb 20 2005
 * modified:  Michael van Runt, Sep 29 2006
 */
var printFlag = 0; // Check for this flag in functions conflicting with print window
function printMe(divID,cssPaths,cssIEPath,jsPaths) {
  var divContent = document.getElementById(divID).innerHTML;
  var jsPathsArray = jsPaths.split(",");
  var cssPathsArray = cssPaths.split(",");  var printWinHTML = '<ht' + 'ml>\n';
  printWinHTML += '<he' + 'ad>\n';
  printWinHTML += '  <title>Print Window</title>\n';
  for (var i=0; i<jsPathsArray.length; i++) {
    if (jsPathsArray[i] != "") {
      printWinHTML += '  <script SRC="' + jsPathsArray[i] + '" type="text/javascript"></script>\n';
    }
  }
  printWinHTML += '  <script type="text/javascript">printFlag = 1;</script>\n';
  for (var i=0; i<cssPathsArray.length; i++) {
    if (cssPathsArray[i] != "") {
      printWinHTML += '  <link rel="stylesheet" HREF="' + cssPathsArray[i] + '" type="text/css">\n';
    }
  }
  if (cssIEPath) {
    printWinHTML += '<!--[if lte IE 6.0]>\n';
    printWinHTML += '  <link rel="stylesheet" HREF="' + cssIEPath + '" type="text/css">\n';
    printWinHTML += '<![endif]-->\n';
  }
  printWinHTML += '</he' + 'ad>\n';
  printWinHTML += '<bo' + 'dy style="margin: 10px;">\n';
  printWinHTML += '<div align="right"><a HREF="javascript: window.close();"><br>close window</a></div>\n';
  printWinHTML += '<div id="' + divID + '">\n\n';
  printWinHTML += divContent;
  printWinHTML += '\n\n</div>\n'
  printWinHTML += '<script language="JavaScript" type="text/javascript">self.focus();this.print();</script>\n';
  printWinHTML += '</bo' + 'dy>\n';
  printWinHTML += '</ht' + 'ml>';
  


  var printWin = window.open('','NULL','resizable,scrollbars,menubar,toolbar,status','70');
  printWin.document.open();
  printWin.document.write(printWinHTML);
  printWin.document.close();

} // End function

/*----------------------------------------------------------------------
 * Print friendly - Simple print
 *
 * author:    Michael van Runt, May 10 2006
 * modified:  
 */
function printSimple() {
    this.print();
}

/*----------------------------------------------------------------------
 * Printer friendly - ASP Method
 *
 * author:    Michael van Runt, Oct 16 2004
 * modified:  
 */
function printMeASP(currentPath) {
  var pageHref = currentPath;
  var pageHrefParam = '?print=1';
  var printHref = pageHref + pageHrefParam;
  if (checkRedDot()) {
    alert("This feature is disabled while working in SmartEdit mode.\nPlease select Show Page Preview from the Action menu to see the print friendly version of this page.");
  } else {
    popWin(printHref,'printWin','resizable,scrollbars,menubar,toolbar,status','70');
  }
}

/*----------------------------------------------------------------------
 * Change page URL  
 *
 * author:    Michael van Runt, Oct 16 2004
 * modified:  
 */
function changeURL(goToURL) {
    document.location.href = goToURL;
}

/*----------------------------------------------------------------------
 * Check for RedDot environment
 *
 * author:    Michael van Runt, Oct 16 2004
 * modified:  
 */
function checkRedDot() {
    if(document.location.href.indexOf("ioRD.asp") >= 0)
        return true;
    return false;
}

/*----------------------------------------------------------------------
 * setFocus( [Object o] )
 *   Sets the focus on the specified object, by 
 *   default the first element of the form on
 *   the page is selected. Ignores hidden fields.
 *
 * author:    Arkadiusz Gruszowski, Oct 11 2005
 * modified:  
 */
function setFocus( o ) {
    
    if( o != undefined )                                 // If object has been specified.
        try {                                            // Try the function in case object cannot be focused
            o.focus();
            o.select();
        } catch(e) {}
     else if( document.forms.length > 0) {               // If at least 1 form is present.
        var l = document.forms[0].elements.length;       // Store length for faster loop execution.
        for(var i=0; i < l; i++) {
            var element = document.forms[0].elements[i];
            if( element.type != "hidden" ) {             // If the element is hidden ignore.
                try {
                    element.focus();
                    element.select();
                } catch(e) {}
                break;                                   // Break if first focusable field is found.
            }
        }
    }
    
}
 
var activeTabID = "";
/*----------------------------------------------------------------------
 * selectTab( [Object o] )
 *   Clear old active tab and make current tab active.
 *
 * author:    Arkadiusz Gruszowski, Oct 26 2006
 * modified:  
 */
function selectTab( o ) {
    if( typeof(o) == "string" && o != activeTabID ) {
        var t_new = document.getElementById( o );
        var t_old = document.getElementById( activeTabID );
        
        var c_new = document.getElementById( "content_" + o );
        var c_old = document.getElementById( "content_" + activeTabID );
        
        t_new.className = "active";
        c_new.style.display = "";
        
        t_old.className = "";
        c_old.style.display = "none";
        
        activeTabID = o;
    }
}
/*----------------------------------------------------------------------
 * initTabs( [Object o] )
 *   Show First occurance in the list as active tab, and display its 
 *   content. Needs to be called AFTER the tabs and tab content is
 *   displayed.
 *
 * author:    Arkadiusz Gruszowski, Oct 26 2006
 * modified:  
 */
function initTabs() {
    var tabs = document.getElementById("tabs");
    var te = tabs.getElementsByTagName( "li" );
    
    var l = te.length;
    for( var i=0; i < l; i++ ) {
        if( i == 0 ) {                                        // Set first tab to be active.
            te[i].className = "active";
            activeTabID = te[i].id;
        } else {                                            // Hide all other content.
            var tmp = document.getElementById("content_" + te[i].id);
            tmp.style.display = "none";
        }
    }
    
}
 



/*        
from Navigation.js
*/

homepage = false;
// onresize for ns4
var origWidth, origHeight;
if (document.layers) {
    origWidth = window.innerWidth; origHeight = window.innerHeight;
    window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}
var toHide=0;
var onSub=0;
var cur_lyr="secondNav";    // holds id of currently visible layer
var cur_lyr_color;
var cur_sub_lyr;
function swapLayers(id,idColor,subLyr) {
  if (cur_lyr) hideLayer(cur_lyr, idColor,subLyr);
  if(cur_lyr_color) changeColor(cur_lyr_color);
  if(cur_sub_lyr) changeColor(cur_sub_lyr);
  showLayer(id,idColor,subLyr);
  cur_lyr = id;
  cur_lyr_color = idColor;
  cur_sub_lyr=subLyr;
}
function showLayer(id,idColor,subLyr) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) {
  //lyr.css.visibility = "visible";
  lyr.style.display = "block";
  }
  var iColor = getElemRefs(idColor);
  iColor.style.background = "#f4f5f9";
  var iColor1 = getElemRefs(subLyr);
  iColor1.style.background = "#f4f5f9";
}
function hideLayer(id,idColor,subLyr) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css)
  //lyr.css.visibility = "hidden";
  lyr.style.display = "none";
    var iColor = getElemRefs(idColor);
    iColor.style.background = "#D7DCE8";
    var iColor1 = getElemRefs(subLyr);
    iColor1.style.background = "#D7DCE8";
}
function changeColor(id) {
  var iColor = getElemRefs(id);
  iColor.style.background = "#D7DCE8";
}
function getElemRefs(id) {
    var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
    if (el) el.css = (el.style)? el.style: el;
    return el;
}
function showDefalut() {
    baseLyr = getElemRefs("secondNav");
    baseLyr.style.display = "block";
    cur_lyr="secondNav";
    baseLyr.style.background = "#D7DCE8";
}
function closeSub() {
    //alert('fired');
    subNav1.style.display = "none";
    subNav2.style.display = "none";
    subNav3.style.display = "none";
    subNav4.style.display = "none";
    subNav5.style.display = "none";
    subNav6.style.display = "none";
    subNav7.style.display = "none";
    Products.style.background = "#D7DCE8";
    Products1.style.background = "#D7DCE8";
    showDefalut();
}
function doSwap() {
    eval(myVar);
}
function setState(var1, var2, var3){
    myVar = 'swapLayers(\''+var1+'\',\''+var2+'\',\''+var3+'\')';
    myTimer=setTimeout('doSwap()',menuDelay);
}
function resetState(){
    clearTimeout(myTimer);
}
var myVar;
var menuDelay=250;