var isSpanish;

//=================
function clickActiveSheet() 
//=================
// Name         : clickActiveSheet()
// Description  : Changes style sheet reference on the fly.
// Call         : clickActiveSheet()
// Parameters   : None
// Returns      : None
// Author       : Jeremy Malone
// Created      : 02/20/2004
// Copyright    : 2004, Catholic Healthcare West
// Notes        : Checks for current style sheet and bump to the next one
// Updates      :
// **************
{
var title = getActiveStyleSheet();
if(title=="small"){
setActiveStyleSheet("medium");
textBtnOver = new Image();
textBtnOver.src = g_HttpRelativeWebRoot + "groups/jsp/documents/webcontent/" + (isSpanish ? "sp_" : "") + "fontchangebuttonmediumaover.gif";
}
if(title=="medium"){
setActiveStyleSheet("large");
textBtnOver = new Image();
textBtnOver.src = g_HttpRelativeWebRoot + "groups/jsp/documents/webcontent/" + (isSpanish ? "sp_" : "") + "fontchangebuttonlargeaover.gif";
}
if(title=="large"){
setActiveStyleSheet("small");
textBtnOver = new Image();
textBtnOver.src = g_HttpRelativeWebRoot + "groups/jsp/documents/webcontent/" + (isSpanish ? "sp_" : "") + "fontchangebuttonsmallaover.gif";
}

}
//=================
function setActiveStyleSheet(title) 
//=================
// Name         : setActiveStyleSheet(title) 
// Description  : Changes style sheet reference 
// Call         : setActiveStyleSheet(string)
// Parameters   : title - title of the desired style sheet
// Returns      : 
// Author       : Jeremy Malone
// Created      : 02/20/2004
// Copyright    : 2004, Catholic Healthcare West
// Notes        :
// Updates      :
// **************

{
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }

}
//=================
function getActiveStyleSheet() 
//=================
// Name         : getActiveStyleSheet() 
// Description  : Gets style sheet reference 
// Call         : getActiveStyleSheet()
// Parameters   : none
// Returns      : Active stylesheet
// Author       : Jeremy Malone
// Created      : 02/20/2004
// Copyright    : 2004, Catholic Healthcare West
// Notes        :
// Updates      :
// **************
{
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}


//=================
function getPreferredStyleSheet() 
//=================
// Name         : getPreferredStyleSheet() 
// Description  : Gets preferred style sheet 
// Call         : getPreferredStyleSheet()
// Parameters   : none
// Returns      : Preferred stylesheet
// Author       : Jeremy Malone
// Created      : 02/20/2004
// Copyright    : 2004, Catholic Healthcare West
// Notes        :
// Updates      :
// **************

{
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}
//=================
function createCookie(name,value,days) 
//=================
// Name         : createCookie(name,value,days) 
// Description  : Creates stylesheet cookie
// Call         : createCookie(name,value,days)
// Parameters   : ncookie name, value and days
// Returns      : NA
// Author       : Jeremy Malone
// Created      : 02/20/2004
// Copyright    : 2004, Catholic Healthcare West
// Notes        :
// Updates      :
// **************
{
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

//=================
function readCookie(name) 
//=================
// Name         : readCookie(name) 
// Description  : Reads stylesheet cookie
// Call         : readCookie(string)
// Parameters   : name of the cookie
// Returns      : Cookie info
// Author       : Jeremy Malone
// Created      : 02/20/2004
// Copyright    : 2004, Catholic Healthcare West
// Notes        :
// Updates      :
// **************

{
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

// **********************************************************************

//Retrieve cookie info and set stylesheet
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);

//Update cookie with stylesheet information
window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

//Set active stylesheet when apge loads
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

//Preload images
patientsBtn = new Image();
patientsBtn.src = g_HttpRelativeWebRoot + "groups/jsp/documents/webcontent/" + (isSpanish ? "sp_" : "") + "patientbuttonover.gif";
emailBtn = new Image();
emailBtn.src = g_HttpRelativeWebRoot + "groups/jsp/documents/webcontent/" + (isSpanish ? "sp_" : "") + "emailapagebuttonover.gif";
printBtn = new Image();
printBtn.src = g_HttpRelativeWebRoot + "groups/jsp/documents/webcontent/" + (isSpanish ? "sp_" : "") + "printapagebuttonover.gif";

// **********************************************************************

//=================
function changeFontImage() 
// Name         : changeFontImage() 
// Description  : Changes the font button
// Call         : changeFontImage()
// Parameters   : 
// Returns      : 
// Author       : Jeremy Malone
// Created      : 02/20/2004
// Copyright    : 2004, Catholic Healthcare West
// Notes        :
// Updates      :
// **************
{
var styletitle = getActiveStyleSheet();

//Added to resolve Mozilla 1.0 issue
if(styletitle !="small" && styletitle !="medium" && styletitle !="large"){
textBtn1 = new Image();
textBtn1.src = g_HttpRelativeWebRoot + "groups/jsp/documents/webcontent/" + (isSpanish ? "sp_" : "") + "fontchangebuttonsmalla.gif";
textBtnOver = new Image();
textBtnOver.src = g_HttpRelativeWebRoot + "groups/jsp/documents/webcontent/" + (isSpanish ? "sp_" : "") + "fontchangebuttonsmallaover.gif";
textBtnOn = new Image();
textBtnOn.src = g_HttpRelativeWebRoot + "groups/jsp/documents/webcontent/" + (isSpanish ? "sp_" : "") + "fontchangebuttonsmalla.gif";
document.images["textBtn"].src = textBtn1.src;
}

if(styletitle =="small"){
textBtn1 = new Image();
textBtn1.src = g_HttpRelativeWebRoot + "groups/jsp/documents/webcontent/" + (isSpanish ? "sp_" : "") + "fontchangebuttonsmalla.gif";
textBtnOver = new Image();
textBtnOver.src = g_HttpRelativeWebRoot + "groups/jsp/documents/webcontent/" + (isSpanish ? "sp_" : "") + "fontchangebuttonsmallaover.gif";
textBtnOn = new Image();
textBtnOn.src = g_HttpRelativeWebRoot + "groups/jsp/documents/webcontent/" + (isSpanish ? "sp_" : "") + "fontchangebuttonsmalla.gif";
document.images["textBtn"].src = textBtn1.src;
}

if(styletitle =="medium"){
textBtn1 = new Image();
textBtn1.src = g_HttpRelativeWebRoot + "groups/jsp/documents/webcontent/" + (isSpanish ? "sp_" : "") + "fontchangebuttonmediuma.gif";
textBtnOver = new Image();
textBtnOver.src = g_HttpRelativeWebRoot + "groups/jsp/documents/webcontent/" + (isSpanish ? "sp_" : "") + "fontchangebuttonmediumaover.gif";
textBtnOn = new Image();
textBtnOn.src = g_HttpRelativeWebRoot + "groups/jsp/documents/webcontent/" + (isSpanish ? "sp_" : "") + "fontchangebuttonmediuma.gif";
document.images["textBtn"].src = textBtn1.src;
}

if(styletitle =="large"){
textBtn1 = new Image();
textBtn1.src = g_HttpRelativeWebRoot + "groups/jsp/documents/webcontent/" + (isSpanish ? "sp_" : "") + "fontchangebuttonlargea.gif";
textBtnOver = new Image();
textBtnOver.src = g_HttpRelativeWebRoot + "groups/jsp/documents/webcontent/" + (isSpanish ? "sp_" : "") + "fontchangebuttonlargeaover.gif";
textBtnOn = new Image();
textBtnOn.src = g_HttpRelativeWebRoot + "groups/jsp/documents/webcontent/" + (isSpanish ? "sp_" : "") + "fontchangebuttonlargea.gif";
document.images["textBtn"].src = textBtn1.src;
}

}
//=================
function printView()
// Name         : printview() 
// Description  : Displays a printer friendly version of the content in a new window
// Call         : none
// Parameters   : HttpWebSitesRoot value
// Returns      : none
// Author       : John Slaughter
// Created      : 02/23/2004
// Copyright    : 2004, Catholic Healthcare West
// Notes        :
// Updates      :
// **************

{
  if (document.getElementById != null)
  {

//  Get Current page header elements for print view page

    var html = '<HTML>\n<HEAD>\n';
    if (document.getElementsByTagName != null)
    {
      var headTags = document.getElementsByTagName("head");
      if (headTags.length > 0)

// Add in required style sheet references

      html += '<link type="text/css" rel="stylesheet" href="/stellent/fragments/comStdIncludes/default.css" type="text/css" media="all" />';
      html += '<link type="text/css" rel="stylesheet" href="/stellent/fragments/comStdIncludes/main.css" type="text/css" media="all" />'; 
      html += '<link type="text/css" rel="stylesheet" href="/stellent/fragments/comStdIncludes/PrintFormat.css" title="print" media="all" />';

// The following is a pice of javascript that is used as a replacment on the 
//link HREFs to disable links

      html +='<SCRIPT type=text/javascript>g_navNode_Root=""; function DisplayNav(){DisplayNav.prototype.Display = DisplayNav_Display;} function DisplayNav_Display (){return;} function DoNothing(){return;}</SCRIPT>';
      html += '\n<TITLE>Printer Friendly View</TITLE>\n';
    }

// The following is a pice of javascript that will be executed when the page is displayed.  
// The code will unhide any of the hidden divs used in the detail pages for pagination so 
// the user will see all of the content and not just the virutal page they were looking at.
        
    html += '\n<Script Language="JavaScript">\n';   
    html += '\nfunction DetailPageFix(){\n';    
    html += '\nvar PageElem = document.getElementById("detailPageCount");\n';   
    html += '\nif (PageElem != null){\n';   
    html += '\nvar pageCnt = PageElem.innerHTML;\n';    
    html += '\nfor(var i=1;i <= pageCnt;i++){\n';   
    html += '\ndocument.getElementById("DetailPage"+i).style.display = "";\n';
    html += '\nif (document.getElementById("DetailPageHR"+i) != null) document.getElementById("DetailPageHR"+i).style.display = "";}\n';    
    html += '\ndocument.getElementById("DetailPageNavTop").style.display = "none";\n';  
    html += '\ndocument.getElementById("DetailPageNavBot").style.display = "none";}\n'; 
    html += '\n}</Script>\n';   

// Set the BASE element to insure addressability to included objects (i.e. images)

    html += '\n<base href="http://' + document.domain +'/stellent/">\n';
//    html += '\n<BASE href=' + document.domain + '/stellent/>\n';  

// Set the standed HTML BODY elements and config to call DetailPageFix on load

    html += '\n</HE' + 'AD>\n<BODY onload="DetailPageFix()">\n';

// Add in print and close button/link at top of page

    html += '<table width="100%" border="0" cellpadding="0">\n<tr class="remove">\n<td align="left">';
    html += '\n<form><input type="button" value="' + (isSpanish ? "Imprimir esta página" : "Print this page") + '" onClick="window.print()">\n</form>\n</td>';
    html += '\n<td align="right">\n<a href=javascript:window.close()>' + (isSpanish ? "Cerrar ventana" : "Close Window") + '</a>\n</td>\n</tr>';        
    html += '\n<tr>\n<td colspan="2">\n<br /><br />';

// Find the required PrintArea element
        
    var printPageElem = document.getElementById("PrintArea");
        
    if (printPageElem != null)
    {

//Remove Related Links from print page

    if (document.getElementById("relatedLinks") != null)
    {
       theDiv = document.getElementById("relatedLinks");
       theDiv.style.display = 'none';       
    }

// Get the HTML inside the PrintArea Element    

    str = printPageElem.innerHTML;

//Redisplay Related Links on original page

    if (document.getElementById("relatedLinks") != null)
    {
       theDiv = document.getElementById("relatedLinks");
       theDiv.style.display = 'block';      
    }   

// Run HTML thru Regexp to convert links to call dummy javascript routine 
// We don not want the links to work on the print view
    AnchorMatch = /href=.+?[\)|\/]\x22/g;

    str = str.replace(AnchorMatch, 'href="javascript:DoNothing();"');

// Run HTML thru Regexp to remove any target=blank settings on links 
// to prevent them from trying to open new windows.
    BlankMatch = /target=_blank/g;
    str = str.replace(BlankMatch, ' ');
        html += str;

    }
    else
    {
        alert("Could not find the printView section in the HTML");
    return;
    }


// Add in print and close button/link and Copyright at Bottom of page

    var currentDate = new Date();
    html += '\n<br /><br /></td>\n</tr>'
    html += '\n<tr class="remove">\n<td align="left">';
    html += '\n<form><input type="button" value="' + (isSpanish ? "Imprimir esta página" : "Print this page") + '" onClick="window.print()">\n</form>\n</td>';
    html += '\n<td align="right">\n<a href=javascript:window.close()>' + (isSpanish ? "Cerrar ventana" : "Close Window") + '</a>\n</td>\n</tr>';        
    html += '\n<td colspan="2" align="center">\n&copy; ' + currentDate.getFullYear() + ' Catholic Healthcare West\n</td>\n</tr>\n</table>';     

// Wrap up standard HTML for page
            
    html += '\n</BO' + 'DY>\n</HT' + 'ML>';

// Set window parameters then call open routing to open new browser window passing our changed HTML
        
    var winParms = "scrollbars=yes, resizable=yes, toolbar=no, menubar=no, location=no, directories=no";
    var printWin = window.open("","PrintView", winParms);
    printWin.document.open();
    printWin.document.write(html);
    printWin.document.close();
  }
  else
  {
    alert("Sorry, the print view feature works\nonly in javascript enabled browsers.");
  }
}

//=================
function popupEmailPage(url)
// Name         : popupEmailPage() 
// Description  : Displays the emailAPage form in a popup window, and moves the focus to that window
// Call         : none
// Parameters   : url The URL to display
// Returns      : always returns false
// Author       : Brian P. Harris
// Created      : 02/25/2004
// Copyright    : 2004, Catholic Healthcare West
// Notes        :
// Updates      : 04/30/2004 bph - Since Terms and Conditions links were removed from email a page, it's no
//          :                longer necessary to pass them in.
// **************
{   
    //construct the URL that we need to send to
//  urlQueryString = escape(location.search);
//  urlToSend = "http://" + hostName + "/intradoc-cgi/idc_cgi_isapi.dll" + urlQueryString;  
    urlToSend = escape(location.href);
    url = url + "?chwFN=" + escape(chwFacilityName) + "&chwPUrl=" + urlToSend + "&chwTitle=" + escape(document.title) + "&spanish=" + isSpanish;

    newwindow=window.open(url,'name','scrollbars=yes,status=no,width=650,height=540');
    if (window.focus) {newwindow.focus()}
    return false;
}



