

/* * * * * * * * * * * * * * * * * * * * * * *
 *                                           *
 *          Popup Window Functions           *
 *                                           *
 * * * * * * * * * * * * * * * * * * * * * * */

/* opens a url in the window's owner (if available)
   otherwise opens it in a new window. */
   
function OpenInParentWindow(url)
{
	if ( window.owner )
	{
		window.owner.location = url;
	}
	else
	{
		window.open(url);
	}
	window.close();
}


/*
 * Opens a URL in a new window and then closes the current window - used on the
 * exit page popup
 */
function OpenExternalLink(url) {
OmnitureTrackExternalLinks(url,url);
	newsitewindow=window.open(url, "", "toolbar=yes,location=yes,scrollbars=yes,status=yes,menubar=yes,resizable=yes,width=800,height=600,left=0,top=0")
	window.close();
}
// To find the position of the cursor
function findPos(obj)
 {
	   var curleft = curtop = 0;
	   if (obj.offsetParent) 
	   {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent)
		 {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		 }
		
		 curtop = curtop+20
		 curleft = curleft-100
	   }
	return [curleft,curtop];
}
function display_image(parent,named)
{
    if(named == "dropdown2")
    {
      hide_image('dropdown')
	  hide_image('dropdown1')
    }
    if(named == "dropdown1")
    {
      hide_image('dropdown')
	  hide_image('dropdown2')
    }
    if(named == "dropdown")
    {
     hide_image('dropdown1')
	 hide_image('dropdown2')
    } 
	// get the named menu
	var menu_element = document.getElementById(named);
	// override the 'display:none;' style attribute
	menu_element.style.display = "";
	// get the placement of the element that invoked the menu...
	var placement = findPos(parent);
	// ...and put the menu there
	menu_element.style.left = placement[0] + "px";
	menu_element.style.top = placement[1] + "px";
	
}
function hide_image(named)
{
	// get the named menu
	var menu_element = document.getElementById(named);
	// hide it with a style attribute
	menu_element.style.display = "none";
	
}
function clearhide(popUp)
{
 hide_image(popUp)
}



/* Opens the HCP confirmation page in a new window. */
function DoHCP(URL)
{
	var childwin;
	var winl = (screen.width - 450) / 2;
	var wint = (screen.height - 200) / 2;
	childwin = window.open("/boniva/hcp.htm?URL=" + URL,"","height=200,width=450,status=yes,toolbar=no,scrollbars=no,menubar=no,left=" + winl + ",top=" + wint);
	// childwin.owner = window;
	// childwin.parent = window;
}

/* this function opens a popup window to display an image */
function openPopupImage(imgSrc, altTitleTag) {
	window.open('/boniva/hcp/charts/popup.htm?imgSrc='+imgSrc+'&altTitleTag='+altTitleTag,'print','scrollbars=yes,width=600,height=520');
}

/* this function opens a popup window to display an image */
function openExitPopup(url) {
	window.open('/boniva/exit.htm?url='+url,'Exit','scrollbars=yes,width=600,height=520');
	
}

/*
 * this function finds the external links and sets up the exit page for them
 */
function initExitLinks() {

	var links=document.getElementsByTagName("a");
	for(i=0; i<links.length; i++) {
		a = links[i];
		var url = a.getAttribute("href");
		if(url.indexOf("gene.com") != -1)  {
			// links to rocheusa.com don't need an exit page
		}
		else if(url.indexOf("http://") != -1 ||
		   url.indexOf("https://") != -1) {
			// other external links do need an exit page
			a.href="/boniva/exit.htm?url=" + url;
			// a.href="javascript:openExitPopup('" + url + "');";
		}
    }
	
}


/*******************************************************************************
 * * * * * * * * * * * * * * * * * * * * * * * Image Functions * * * * * * * * * * * * * * * * * * * * * * *
 */

function MM_openBrWindow(theURL,winName,features) { // v2.0
		window.open(theURL,winName,features);
}

function MM_swapImgRestore() { // v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { // v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { // v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { // v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


/*******************************************************************************
 * * * * * * * * * * * * * * * * * * * * * * * Text Size Functions * * * * * * * * * * * * * * * * * * * * * * *
 */

// toggleStyleSheet toggles between stylesheets that have title="medium" and
// title="large".
function toggleStyleSheet() {
	var cookie = readCookie("style");  
	var title = cookie ? cookie : getPreferredStyleSheet();
	var newstyle;
	if (title == "medium")
		newstyle="large";
	else 
		newstyle="medium";
	OmnitureTrackFontSize(newstyle);
	setActiveStyleSheet(newstyle);
}

function setActiveStyleSheet(title) {
	// alert("setting style: " + title);
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			if(a.getAttribute("title") == title) {
				a.disabled = false;
				// alert("stylesheet " + a.getAttribute("title") + " is now
				// active");
			}
			else {
				a.disabled = true;
				// alert("stylesheet " + a.getAttribute("title") + " is now
				// disabled");
			}
		}
	}
	createCookie("style", title, 365);
}

function getPreferredStyleSheet() {
  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 "medium";
}

function createCookie(name,value,days) {
  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) {
  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;
}

window.onload = function(e) {
  var cookie = readCookie("style");  
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
  // MM_preloadImages('../template/images/home_over.gif','../template/images/about_over.gif','includes/images/treatment_over.gif','boniva_div/images/healthy_over.gif','boniva_div/images/rewards_over.gif','boniva_div/images/resources_over.gif','/boniva_div/images/hcpnav_efficacy_over.gif','/boniva_div/images/hcpnav_tolerability_over.gif','/boniva_div/images/hcpnav_myboniva_over.gif','/boniva_div/images/hcpnav_dosing_over.gif','/boniva_div/images/hcpnav_prescribing_over.gif','/boniva_div/images/hcpnav_resources_over.gif');
}
/* This function has to be called when the pages have other onload function */
function ChangeSize()
{
 var cookie = readCookie("style");  
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
  return;
}


/*******************************************************************************
 * * * * * * * * * * * * * * * * * * * * * * * Print Header Functions * * * * * * * * * * * * * * * * * * * * * * *
 */

 function getObj(name, nest) {
	if (document.getElementById){
		return document.getElementById(name).style;
	}else if (document.all){
		return document.all[name].style;
	}else if (document.layers){
		if (nest != ''){
			return eval('document.'+nest+'.document.layers["'+name+'"]');
		}
		}else{
			return document.layers[name];
		}
	}

	// Hide/show layers functions
	function showLayer(layerName, nest){
		var x = getObj(layerName, nest);
		x.visibility = "visible";
	}

	function hideLayer(layerName, nest){
		var x = getObj(layerName, nest);
		x.visibility = "hidden";
	}
	function CustomPrint()
	{
		hideLayer('Test');
		window.print();
		showLayer('Test');
	}

var editSection;

function confirmExit()
{
	 // disabled per PGM
	alert("disableExitPopup: " + disableExitPopup);
	if (changesMadeBool && !disableExitPopup)
    {
		disableExitPopup = false;
		// return "You have not saved your information. Please click the save
		// button on the MyBoniva Account page.";
		return "You have not saved your information. If you would like to save your changes, please click the Cancel button and then click the Save changes button on the MyBONIVA Account page. Your information will not be saved if you click the OK button";
    }
	// disableExitPopup = false;
 
}

function confirmSaveChanges()
{
	 // disabled per PGM
	// alert("disableExitPopup: " + disableExitPopup);
	if (changesMadeBool!=null){
	if (changesMadeBool)
    {
		
		var retval;
		disableExitPopup = false;
		// retval= confirm( "You have not saved your information. Please click
		// the save button on the MyBoniva Account page.");
		retval=	confirm( "You have not saved your information. If you would like to save your changes, please click the Cancel button and then click the Save changes button on the MyBONIVA Account page. Your information will not be saved if you click the OK button");
		if (retval)
		{
			return true ;
		}
		else
		{
			return false ;
    }
    }
    return false;     
    }
	// disableExitPopup = false;
 
}

function changesMade()
{
	changesMadeBool = true;
}

function changesSaved()
{
	changesMadeBool = false;
}    

function accountEdit()
{
}
function accountSave()
{
}
function personalEdit()
{
}
function personalSave()
{
}
function reminderEdit()
{
}
function reminderSave()
{
}

/*******************************************************************************
 * * * * * * * * * * * * * * * * * * * * * * * Other Functions * * * * * * * * * * * * * * * * * * * * * * *
 */

function verifyQuery1()
{
	var strQuery = document.querybox_top.query.value;
	var reNonSpace = /\S/g;
	if (reNonSpace.test(strQuery)) 
	{
		document.querybox_top.submit();
	} 
	else 
	{
		alert("Please enter a question and click 'Go'.");
		document.querybox_top.query.focus();
		return false;
	}
}	


/* bookmarks a URL */
function bookmark(url, description)
{
	netscape="Netscape users, hit CTRL+D to add a bookmark to this site."
	if (navigator.appName=='Microsoft Internet Explorer')
		window.external.AddFavorite(url, description); 
	else if (navigator.appName=='Netscape')
		alert(netscape); 
}
 // TO Show the registration options
function hidecheckonload()
		{
		  document.getElementById("show").style.visibility = 'hidden';
		  ChangeSize();
		  
		}
	function checktest()
		{
		if(document.Form1.Diagnosed_0.checked)
		{
		 document.getElementById("show").style.visibility = 'visible';
		 document.getElementById("show").style.display = 'block';
		}
		else if(document.Form1.Diagnosed_1.checked)
		{
		 document.getElementById("show").style.visibility = 'hidden';
		 document.getElementById("show").style.display = 'none';
		}
		
		}
	function checkUncheck(){
		alert("in check uncheck");
	/*
	 * cState = theBox.checked; bGroup = theBox.form[theBox.name]; for(i=0;i<bGroup.length;i++){
	 * bGroup[i].checked = false; } theBox.checked = cState;
	 */
	}

 function OpenPIBehind(url1,url2)
 {
   mywindow2= window.open(url2,"bonivaPI");  
   mywindow1= window.open(url1,"pdf"); 
   url1 = url1.substring(6);
   OmnitureTrackDownload(url1);
 }

// rollovers for images ... use <img class="imgover" ... /> or
// <input type="image" class="imgover" /> to invoke. Save the rollover
// image with "_over" suffix, and in the same folder as the non-rollover image.
// For example, menuitem.gif and menuitem_over.gif should be saved in the same
// folder.
function initRollovers() {
	// check for incompatible browser
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	
	// declare image and input element variables
	var aInputs = document.getElementsByTagName("input");
	var aImg = document.getElementsByTagName('img');
	var aImages = new Array();
	
	// loop that finds the input elements
	for(var i = 0; i < aInputs.length; i++)
	{
		aImages[i] = aInputs.item(i);
	}
	// loop that finds all image elements and adds to
	// inputs for total images that need swapping
	for(var i = 0; i < aImg.length; i++)
	{
		aImages[i + aInputs.length] = aImg.item(i);
	}

	// looks for images or inputs that have the imgover class and runs the
	// following methods
	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_over'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			// adds the mouseover event
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			// adds the mouseout event
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_over'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}
