<!--
/*
WM_setCookie(), WM_readCookie(), WM_killCookie()
A set of functions that eases the pain of using cookies.

Source: Webmonkey Code Library
(http://www.hotwired.com/webmonkey/javascript/code_library/)
Author: Nadav Savio
Author Email: nadav@wired.com

Usage: 
WM_setCookie('name', 'value'[, hours, 'path', 'domain', secure]); 
where name, value, and path are strings, and secure is either true or null. Only name and value are required. Note: hours can be either a number of hours until the cookie expires or a GMT-formatted date string such as 'Fri, 13-Apr-1970 00:00:00 GMT'. 

WM_readCookie('name'); 
Returns the value associated with name. 

WM_killCookie('name'[, 'path', 'domain']); 
Remember that path and domain must be supplied if they were set with the cookie. 
*/
// This next little bit of code tests whether the user accepts cookies.
var WM_acceptsCookies = false;
if(document.cookie == '') {
    document.cookie = 'WM_acceptsCookies=yes'; // Try to set a cookie.
    if(document.cookie.indexOf('WM_acceptsCookies=yes') != -1) {
	WM_acceptsCookies = true; 
    }// If it succeeds, set variable
} else { // there was already a cookie
  WM_acceptsCookies = true;
}

function WM_setCookie (name, value, hours, path, domain, secure) {
    if (WM_acceptsCookies) { // Don't waste your time if the browser doesn't accept cookies.
	var not_NN2 = (navigator && navigator.appName 
		       && (navigator.appName == 'Netscape') 
		       && navigator.appVersion 
		       && (parseInt(navigator.appVersion) == 2))?false:true;

	if(hours && not_NN2) { // NN2 cannot handle Dates, so skip this part
	    if ( (typeof(hours) == 'string') && Date.parse(hours) ) { // already a Date string
		var numHours = hours;
	    } else if (typeof(hours) == 'number') { // calculate Date from number of hours
		var numHours = (new Date((new Date()).getTime() + hours*3600000)).toGMTString();
	    }
	}
	document.cookie = name + '=' + escape(value) + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':''); // Set the cookie, adding any parameters that were specified.
    }
} // WM_setCookie


function WM_readCookie(name) {
    if(document.cookie == '') { // there's no cookie, so go no further
	return false; 
    } else { // there is a cookie
	var firstChar, lastChar;
	var theBigCookie = document.cookie;
	firstChar = theBigCookie.indexOf(name);	// find the start of 'name'
	var NN2Hack = firstChar + name.length;
	if((firstChar != -1) && (theBigCookie.charAt(NN2Hack) == '=')) { // if you found the cookie
	    firstChar += name.length + 1; // skip 'name' and '='
	    lastChar = theBigCookie.indexOf(';', firstChar); // Find the end of the value string (i.e. the next ';').
	    if(lastChar == -1) lastChar = theBigCookie.length;
	    return unescape(theBigCookie.substring(firstChar, lastChar));
	} else { // If there was no cookie of that name, return false.
	    return false;
	}
    }	
} // WM_readCookie

function WM_killCookie(name, path, domain) {
  var theValue = WM_readCookie(name); // We need the value to kill the cookie
  if(theValue) {
      document.cookie = name + '=' + theValue + '; expires=Fri, 13-Apr-1970 00:00:00 GMT' + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:''); // set an already-expired cookie
  }
} // WM_killCookie

//Added by Nathan Morris UW Health
//use a global JS value is case no cookies
var defaultFontSize = 62;
var globalFontSize;
var globalFontSizeMax = 110;
var globalFontSizeMin = 56;
//initialization function called in body onLoad
function setFont(){
	if(WM_acceptsCookies && WM_readCookie('fontSize') && !isNaN(WM_readCookie('fontSize') ) ) {
		setFontSize(WM_readCookie('fontSize'));
	}else{
		//default font size is set here
		//default should also be set in style in case no JavaScript
		setFontSize(defaultFontSize);
	}
	//also set Google search text
	initSearch();
}
function changeFontSize(pct){
	globalFontSize = parseInt(globalFontSize) + parseInt(pct);
	setFontSize(globalFontSize);
}
function setFontSize(pct){
	//must change any styles at the highest or "base" level to make the page work correctly
	if( pct >= globalFontSizeMin && pct <= globalFontSizeMax ){
	var bod = document.getElementsByTagName('body')[0];
	bod.style.fontSize = pct+"%";
	globalFontSize = pct;
	WM_killCookie("fontSize","/",".uwhealth.org");
	//one year
	WM_setCookie("fontSize",pct,8760,"/",".uwhealth.org",false);
	}
	
}

//Fill Google search box code.
	function clearGoogle(){
		var q = document.getElementsByName("q")[0];
		if(q.value == "Search UW Health" && q.className=="googlite" ){
			q.className="goog";
			q.value = "";
		}
	}
	function fillGoogle(){
		var q = document.getElementsByName("q")[0];
		q.className="googlite";
		q.value="Search UW Health";
	}		
	function checkGoogle(){
		var q = document.getElementsByName("q")[0];
		if(q.value == "" && q.className=="goog" ){
			fillGoogle();
		}else if(q.value == "Search UW Health" && q.className=="googlite" ){
			clearGoogle();
		}
	}
	function initSearch(){
		var q = document.getElementsByName("q")[0];
		q.onfocus=checkGoogle;
		q.onblur=checkGoogle;
		fillGoogle();	
	}
	
	
	
	
	
/***********************************************
/**  Expandable IFrame Code ********************
/***********************************************
/***********************************************
/***********************************************
* IFrame SSI script II- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
***********************************************/

//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:

// I've hardcoded 8 potential iFrame "slots"
// TODO: add more here if we need more iFrames on a page.
var iframeids=["myframe0", "myframe1", "myframe2", "myframe3", "myframe4", "myframe5", "myframe6", "myframe7", "myframe8"]


//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide="yes"

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function resizeCaller() {	
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (document.getElementById)
resizeIframe(iframeids[i])
//reveal iframe for lower end browsers? (see var above):
if ((document.all || document.getElementById) && iframehide=="no"){
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
tempobj.style.display="block"
}
}
}

function resizeIframe(frameid){
var currentfr=document.getElementById(frameid)
if (currentfr && !window.opera){
currentfr.style.display="block"
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
if (currentfr.addEventListener)
currentfr.addEventListener("load", readjustIframe, false)
else if (currentfr.attachEvent){
currentfr.detachEvent("onload", readjustIframe) // Bug fix line
currentfr.attachEvent("onload", readjustIframe)
}
}
}

function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
if (iframeroot)
resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url){
if (document.getElementById)
document.getElementById(iframeid).src=url
}

if (window.addEventListener)
window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent)
window.attachEvent("onload", resizeCaller)
else
window.onload=resizeCaller



/***********************************************
/***********************************************
  This function/class will help count the number of javascript iFrame calls on the page 
  so that we may dynamically assign a number to each iFrame, keeping them unique
/***********************************************/

// Define a static variable counter class
function MyClass()
{
    // Initialize/Increase a static instance counter property
    if (MyClass.counter === undefined)
    {
        MyClass.counter = 0;
    }
    else
    {
        MyClass.counter++;
    }
}

MyClass.resetCounter = function()
{
    MyClass.counter = 0;
};


/***********************************************
/***********************************************
  This is the function call that will allow the expandable iFrame proxy page
  to be displayed on the page.  Because we are using the "count" as part of the name
  and id, we can call as many iFrames per page as allowed (see top of this script).
/***********************************************/
function showIFrame2(displayType, id, style) 
{
	// Get the iFrame number
	// To call the actual iFrame number use MyClass.counter
	var count = new MyClass();

	//alert("showIFrame number " + MyClass.counter + " called with " + displayType + ", " + id + ", " + style);
    document.write("<iframe name=\"myframe"+MyClass.counter+"\" id=\"myframe"+MyClass.counter+"\" src=\"_feed_proxy.asp?displayType="+displayType+"&id="+id+"&style="+style+"\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\" vspace=\"0\" hspace=\"0\" width=\"258\"></iframe>") 
}
	


/**************************************************/
/** This is ajax code for the NEW provider feed  **/
/**************************************************/

var divNumber = 1;  //need an order to the div tags, 1-?
var orderNumber = 1; //requests get processed in order, so make sure the first reuqest ends up in div 1
var myLayer = "";

function showIFrame(displayType, id, style){
	//we don't have to worry about style anymore
	displayFeed(displayType, id);
}

function displayFeed(displayType, id){
	setUpDiv(divNumber); //write out the needed div tags
	var url = "http://www.uwhealth.org/_fadfeed_proxy.asp?id="+id;
	ajaxObject("specialty"+divNumber, url, orderNumber);
	divNumber++;
	orderNumber++;
}

/**http://www.hunlock.com/blogs/Concurrent_Ajax**/
function ajaxObject(layer, url, order) {                                    // This is the object constructor
myLayer = layer;
//console.debug("ajaxObject - layer:"+myLayer);
   var that=this;                                                    // A workaround for some javascript idiosyncrocies
   var updating = false;                                             // Set to true if this object is already working on a request
                             
      if (updating==true) {return false; }                          // Abort if we're already processing a call.
      updating=true;                                                 // Set the updating flag.
      var AJAX = null;   
	  //console.debug("setting up xmlhttp");                         // Initialize the AJAX variable.
      if (window.XMLHttpRequest) {                                   // Are we working with mozilla?
         AJAX=new XMLHttpRequest();                                  //  Yes -- this is mozilla.
      } else {                                                       // Not Mozilla, must be IE
         AJAX=new ActiveXObject("Microsoft.XMLHTTP");                //  Wheee, ActiveX, how do we format c: again?
      }                                                              // End setup Ajax.
      if (AJAX==null) {                                              // If we couldn't initialize Ajax...
         alert("Your browser doesn't support AJAX.");                // Sorry msg.                                              
         return false                                                // Return false (WARNING - SAME AS ALREADY PROCESSING!)
      } else {
         AJAX.onreadystatechange = function() {                      // When the browser has the request info..
            if (AJAX.readyState==4 || AJAX.readyState=="complete") { //   see if the complete flag is set.
			   //console.debug("just about to populateFeed w/ AJAX obj");
               populateFeed(AJAX,order);
			   delete AJAX;                                          //   delete the AJAX object since it's done.
               updating=false;                                       //   Set the updating flag to false so we can do a new request
            }                                                        // End Ajax readystate check.
         }                                                           // End create post-process fucntion block.

         AJAX.open("GET", url, true);                                // Open the url this object was set-up with.
         AJAX.send(null);                                            // Send the request.             
   }
      
   // This area set up on constructor calls.
   var LayerID = document.getElementById(layer);                     // Remember the layer associated with this object.
   var urlCall = url;                                                // Remember the url associated with this object.
}                                                                    // End AjaxObject

/**
parse through the xml that was recieved and 
make it into the provider link to display
**/
function populateFeed(hRequest,order){
	//console.debug("in populateFeed");
	var resp = hRequest.responseText;
	var xmlDoc;
	if(window.ActiveXObject){
		//MS
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		xmlDoc.loadXML(resp);
	}else{
		//nonMS
		xmlDoc = document.implementation.createDocument("","",null);
		var parser = new DOMParser();
		var dom = parser.parseFromString(resp, "text/xml");
		xmlDoc = dom;
	}
	
	sizeVal = xmlDoc.getElementsByTagName('size');
	var size = sizeVal[0].firstChild.data;
	
	var provString = "";
	for(var i=0; i<size; i++){
		provVal = xmlDoc.getElementsByTagName('name');
		var prov = provVal[i].firstChild.data;
		idVal = xmlDoc.getElementsByTagName('id');
		var id = idVal[i].firstChild.data;
		
		provString += "<div style='border-bottom:8px solid #e6c398'><a href='http://findadoctor.uwhealth.org/findadoctor/profile.jsp?provider="+id+"'>"+prov +"</a><br/></div>";
	}
	provString += "<br/>";
	//output it to the screen
	myLayer = "specialty"+order;  //make sure we have the right div, starting at 1
	//console.debug("posting: "+myLayer);
	document.getElementById(myLayer).innerHTML = provString;
	//orderNumber++;

}
//write out the div tag
function setUpDiv(divNumber){
	//console.debug("set up div: specialty"+divNumber);
	document.write('<div id="specialty'+divNumber+'"></div>');
}

//check for search box
function search(value) {
	if (value == "Search UW Health" || value == "") {
		return false;
	}
		else {
			return true;
		}
}
// -->
