/*----------------------------------------------------------------------
 * Pop-up window 
 *
 * author:    Michael van Runt, Mar 10 2003
 * modified:  Arkadiusz Gruszowski, Apr 28 2006
 */

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.
            }
        }
    }
    
}


/*----------------------------------------------------------------------
 * Generic tab show/hide function.
 * Uses "tab_" ids for tabs, "page_" ids for pages shown by tabs
 *
 * author:    David Clark
 * modified:  
 */

function ShowTab(id)
{
    var aDivs = document.body.getElementsByTagName("div");
    for(i in aDivs)
    {
        if(aDivs[i].id)
        {
            n = aDivs[i].id;
            if(n.indexOf('page_')>-1)
                aDivs[i].style.display='none';
        }
    }
    document.getElementById('page_' + id).style.display = "";
    var aLi = document.body.getElementsByTagName("li");
    for(i in aLi)
    {
        if(aLi[i].id)
        {
            n = aLi[i].id;
            if(n.indexOf('tab_')>-1)
                aLi[i].className="";
        }
    }
    document.getElementById('tab_' + id).className = "active";
}