/* common.js should be included on every page after browserdetect_lite.js and nav.js */

//*******************************************************
// GLOBAL VARIABLES
//*******************************************************
    var navAbout, navPhysicians, navCenters, navWorking, navModel, bannerLeftOverlay, subNavContainer
    var topNav, subNav
    var moving = 0
    var homeURL = "/home.html"

//*******************************************************
// BROWSER SPECIFIC STYLES
//*******************************************************
    if (browser.isNS6up || browser.isSafari){
	document.write("<link href=\"/common/css/ns6style.css\" rel=\"stylesheet\" type=\"text/css\">");
    }
    else if (browser.isNS4x){
	document.write("<link href=\"/common/css/ns4style.css\" rel=\"stylesheet\" type=\"text/css\">");
    }
    if (browser.isMac){
	document.write("<link href=\"/common/css/macstyle.css\" rel=\"stylesheet\" type=\"text/css\">");
    }


//*******************************************************
// FUNCTION suppressError()
//*******************************************************
// suppressError() is called when a JavaScript error is thrown
//*******************************************************
function suppressError(msg,url,linenumber){return true;}
window.onerror=suppressError

//*******************************************************
// FUNCTION init()
//*******************************************************
// init() is called by every page by the body onload event to initialize the navigation sliders, the subnavigation, and the PNG images
//*******************************************************
    function init() {}


//*******************************************************
// FUNCTION createNav()
//*******************************************************
// createNav() is called by the init() function to initialize the navigation sliders
//*******************************************************
    function createNav(){
	navAbout = new navItem("navAbout",225,737,"/about/about.html")
	navPhysicians = new navItem("navPhysicians",202,715,"/physicians/physicians.html")
	navCenters = new navItem("navCenters",179,692,"/centers/centers.html")
	navWorking = new navItem("navWorking",156,669,"/working/working.html")
	navModel = new navItem("navModel",133,134,"/model/model.html")
    }

//*******************************************************
// FUNCTION setUpPNGs()
//*******************************************************
// setUpPNGs() is called by the init() function to initialize the PNG (Portable Network Graphic) images used on the site.  
// Because different browsers and platforms have implemented PNG support differently this function changes the display of 
// the graphic based on the client browser.
//
// arguments:
// item - the name of the image tag that will be affected
// img -  the common file name of the PNG and GIF images (ie, img.png and img.gif)
//*******************************************************
    function setUpPNGs(item,img) {
	var changeImg = ""
	changeImg = document.images[item]
	if(!changeImg) changeImg = ImgFind(document, item);
	if (changeImg) {
	    if (browser.isIE55up && browser.isWin) changeImg.src = '/images/nav/clear.gif';
	    else if (!(browser.isNS4x || browser.isIE4x || (browser.isIE50 && browser.isWin))) changeImg.src = img + '.png';
	}
    }

//*******************************************************
// FUNCTION swapPNGImg()
//*******************************************************
// swapPNGImg() is called by event handlers on the navigation images to create a mouseover effect.
// Because different browsers and platforms have implemented PNG support differently this function changes the display of 
// the graphic based on the client browser.
// All images calling this function should have the format <img src="/images/nav/X.png" name="XImg">
// Where X is the common name of the image that will be swapped.
//
// arguments: 
// img -  the name of the image tag that will be affected minus the Img  
// filename - the common file name of the PNG and GIF images (ie, filename.png, filename.gif, filename_on.gif, filename_over.gif)
// state - the new state the image should display.  
//	   "over" means the user's mouse is hovering over the image
//         "out" means the user's mous is no longer hovering over the image
//	   "on" means the user has clicked on the image and the "over" and "out" states will now be ignored
//*******************************************************
    function swapPNGImg(img,filename,state){
	var changeImg = document.images[img + 'Img']   
 	if(!changeImg) changeImg = ImgFind(document, img + 'Img');

	if (changeImg){
	    var currentSrc = changeImg.src
	    var arrCurrentSrc = currentSrc.split("/")
	    var currentImg = arrCurrentSrc[arrCurrentSrc.length-1]
	    var newImg = ""

	    if (state=="on"){newImg =  filename + "_on.gif";}
	    else if (state=="over"){if (moving==0) newImg =  filename + "_over.gif";}
	    else if (state=="out"){
		if (moving==0){
		    if (browser.isIE55up && browser.isWin) newImg = "clear.gif";
		    else if (browser.isNS4x || browser.isIE4x || (browser.isIE50 && browser.isWin)) newImg = filename + ".gif";
		    else newImg = filename + ".png";
		}
	    }
	    else if (state=="clear"){
		moving = 1;
		if (browser.isIE55up && browser.isWin) newImg = "clear.gif";
		else if (browser.isNS4x || browser.isIE4x || (browser.isIE50 && browser.isWin)) newImg = filename + ".gif";
		else newImg = filename + ".png";
	    }
	    if (newImg != "") changeImg.src = currentSrc.replace(currentImg,newImg)
	}
    }

//*******************************************************
// FUNCTION swapImg()
//*******************************************************
// swapImg() is called by event handlers on images to create a mouseover effect.
//
// arguments: 
// img -  the name of the image tag that will be affected
// state - the new state the image should display.  
//	   "over" means the user's mouse is hovering over the image
//         "out" means the user's mous is no longer hovering over the image
//	   "on" means the user has clicked on the image and the "over" and "out" states will now be ignored
//*******************************************************
    function swapImg(img,state){
	var changeImg = document.images[img]   
 	if(!changeImg) changeImg = ImgFind(document, img);

	if (changeImg){
	    var currentSrc = changeImg.src
	    if (state=="over"){changeImg.src=currentSrc.replace("_off.gif","_over.gif");}
	    else if (state=="off"){changeImg.src=currentSrc.replace("_over.gif","_off.gif");}
	}
    }

//*******************************************************
// FUNCTION preloadimages()
//*******************************************************
// preloadimages() takes an array of image urls and preloads the images that will be used on the page for mouseover effects
//*******************************************************
    function preloadimages(){
	var temp
	for (i=0;i<preloadimages.arguments.length;i++){temp=new Image();temp.src=preloadimages.arguments[i];}
    }


//*******************************************************
// FUNCTION ImgFind()
//*******************************************************
// ImgFind() is used for Netscape 4 support for images that are nested within layers.
//*******************************************************
    function ImgFind(doc, imgName){
	if (doc.layers) for (var i=0; i < doc.layers.length; i++){var img = doc.layers[i].document.images[imgName];if (!img) img = ImgFind(doc.layers[i], imgName);if (img) return img;}
	return null;
    }

//*******************************************************
// FUNCTION NS4fix()
//*******************************************************
// NS4fix() is used for Netscape 4 support to force the correct width of div tags containing text.
//*******************************************************
    function NS4fix(){
	if (browser.isNS4x){
	    if (topNav == "Model") document.write("<img src=\"/images/clear.gif\" width=\"500\" height=\"1\">")
	    else if (topNav == "Working") document.write("<img src=\"/images/clear.gif\" width=\"400\" height=\"1\">")
	    else if (topNav == "Centers") document.write("<img src=\"/images/clear.gif\" width=\"480\" height=\"1\">")
	    else if (topNav == "About") document.write("<img src=\"/images/clear.gif\" width=\"385\" height=\"1\">")
	    else if (topNav == "Home") document.write("<img src=\"/images/clear.gif\" width=\"460\" height=\"1\">")
	}
    }

//*******************************************************
// FUNCTION showPopUp()
//*******************************************************
// showPopUp() launches a pop up window.  By default, the new window has no menus, toolbars, scrollbars, and is not resizeable
//
// arguments: 
// url -  the url of the new window
// w - the width of the new window  
// h - the height of the new window
// to change the default window settings, pass in the value true or false in the order resizeable, scrollbars, menus
// ex: showPopUp("http://www.google.com",800,600,false,true,false) will create a 800x600 window that is not resizeable, has scrollbars, has no menus
//*******************************************************
    function showPopUp(url,w,h){
	var argv = showPopUp.arguments;
	var argc = showPopUp.arguments.length;

	var resizeable = (3< argc) ? argv[3] : "no";
	var scrollbars = (4< argc) ? argv[4] : "no";
	var menus = (5 < argc) ? argv[5] : "no";

	var iTop,iLeft,settings
	var popWin
			
	iLeft=(screen.width)?(screen.width-w)/2:100;
	iTop=(screen.height)?(screen.height-h)/2:100;
		
	settings='width='+w+',height='+h+',top='+iTop+',left='+iLeft+',scrollbars='+scrollbars+',location=no,directories=no,status=no,menubar='+menus+',toolbar='+menus+',resizable='+ resizeable
		
	popWin = window.open(url,"",settings);
	popWin.focus();
    }


    var bExpandDD = bOnDD = 0
    function showDiv(divName){if (document.getElementById) document.getElementById(divName).style.visibility="visible";else if (document.all) document.all[divName].style.visibility="visible";else if (document.layers && document.layers[divName]) document.layers[divName].style.visibility="show";}
    function hideDiv(divName){if (document.getElementById) document.getElementById(divName).style.visibility="hidden";else if (document.all) document.all[divName].style.visibility="hidden";else if (document.layers && document.layers[divName]) document.layers[divName].style.visibility="hide";}
    function activateDropDown(){
        if (bExpandDD==1) {bExpandDD=0;hideDiv("centersDropDownList");}
        else {bExpandDD=1;showDiv("centersDropDownList")}
    }
    function deactivateDropDown(){
        if (bExpandDD==1 && bOnDD==0) {bExpandDD=0;hideDiv("centersDropDownList")}
    }

    function writeYear(){
	var today = new Date()
	document.write(today.getFullYear())
    }