var pu_event = {

  add: function(obj, etype, fp, cap) {
    cap = cap || false;
    if (obj.addEventListener) obj.addEventListener(etype, fp, cap);
    else if (obj.attachEvent) obj.attachEvent("on" + etype, fp);
  }, 

  remove: function(obj, etype, fp, cap) {
    cap = cap || false;
    if (obj.removeEventListener) obj.removeEventListener(etype, fp, cap);
    else if (obj.detachEvent) obj.detachEvent("on" + etype, fp);
  }, 

  DOMit: function(e) { 
    e = e? e: window.event;
    e.tgt = e.srcElement? e.srcElement: e.target;
    
    if (!e.preventDefault) e.preventDefault = function () { return false; }
    if (!e.stopPropagation) e.stopPropagation = function () { if (window.event) window.event.cancelBubble = true; }
        
    return e;
  }  
}

var viewport = {
	
  getWinWidth: function () {
    this.width = 0;
    if (window.innerWidth) this.width = window.innerWidth - 18;
    else if (document.documentElement && document.documentElement.clientWidth) 
  		this.width = document.documentElement.clientWidth;
    else if (document.body && document.body.clientWidth) 
  		this.width = document.body.clientWidth;
  },
  
  getWinHeight: function () {
    this.height = 0;
    if (window.innerHeight) this.height = window.innerHeight - 18;
  	else if (document.documentElement && document.documentElement.clientHeight) 
  		this.height = document.documentElement.clientHeight;
  	else if (document.body && document.body.clientHeight) 
  		this.height = document.body.clientHeight;
  },
  
  getScrollX: function () {
    this.scrollX = 0;
  	if (typeof window.pageXOffset == "number") this.scrollX = window.pageXOffset;
  	else if (document.documentElement && document.documentElement.scrollLeft)
  		this.scrollX = document.documentElement.scrollLeft;
  	else if (document.body && document.body.scrollLeft) 
  		this.scrollX = document.body.scrollLeft; 
  	else if (window.scrollX) this.scrollX = window.scrollX;
  },
  
  getScrollY: function () {
    this.scrollY = 0;    
    if (typeof window.pageYOffset == "number") this.scrollY = window.pageYOffset;
    else if (document.documentElement && document.documentElement.scrollTop)
  		this.scrollY = document.documentElement.scrollTop;
  	else if (document.body && document.body.scrollTop) 
  		this.scrollY = document.body.scrollTop; 
  	else if (window.scrollY) this.scrollY = window.scrollY;
  },
  
  getAll: function () {
    this.getWinWidth(); this.getWinHeight();
    this.getScrollX();  this.getScrollY();
  }
}

var PopUp = {
	
    followMouse: true,
    offX: 8,
    offY: 12,
    tipID: "tipDiv",
    showDelay: 500,
    hideDelay: 100,
	Transparent: 100,
	ready:false,
	timer:null,
	tip:null,
	
	init:function(){
		if(document.createElement&&document.body&&typeof document.body.appendChild!="undefined"){
			if(!document.getElementById(this.tipID)){
				var el=document.createElement("DIV");
				el.id=this.tipID;
				document.body.appendChild(el);
			}
			this.ready=true;
		}
	},
	
	show:function(e,msg,w){
		if(this.timer){
			clearTimeout(this.timer);
			this.timer=0;
		}
		this.tip=document.getElementById(this.tipID);
		if(this.followMouse) pu_event.add(document,"mousemove",this.trackMouse,true);
		this.writeTip("");
		this.writeTip(msg);
		viewport.getAll();
		this.positionTip(e);
		this.tip.style.width=w+"px";
		this.timer=setTimeout("PopUp.toggleVis('"+this.tipID+"', 'visible')",this.showDelay);
	},
	
	writeTip:function(msg){
		if(this.tip&&typeof this.tip.innerHTML!="undefined")this.tip.innerHTML=msg;
	},
	
	positionTip:function(e){
		if(this.tip&&this.tip.style){
			var x=e.pageX?e.pageX:e.clientX+viewport.scrollX;
			var y=e.pageY?e.pageY:e.clientY+viewport.scrollY;
			if(x+this.tip.offsetWidth+this.offX>viewport.width+viewport.scrollX){
				x=x-this.tip.offsetWidth-this.offX;
				if(x<0)x=0;
			}else x=x+this.offX;
			if(y+this.tip.offsetHeight+this.offY>viewport.height+viewport.scrollY){
				y=y-this.tip.offsetHeight-this.offY;
				if(y<viewport.scrollY)y=viewport.height+viewport.scrollY-this.tip.offsetHeight;
			}else y=y+this.offY;
			this.tip.style.left=x+"px";
			this.tip.style.top=y+"px";
		}
	},
	
	hide:function(){
		if(this.timer){
			clearTimeout(this.timer);
			this.timer=0;
		}
		this.timer=setTimeout("PopUp.toggleVis('"+this.tipID+"', 'hidden')",this.hideDelay);
		if(this.followMouse)pu_event.remove(document,"mousemove",this.trackMouse,true);
		this.tip=null;
	},

	fadeout:function() {
		if(this.timer){
			clearTimeout(this.timer);
			this.timer=0;
		}
		this.tip = document.getElementById(this.tipID);
		this.Transparent -= 5;
		if (this.Transparent < 5) {
			//clearTimeout(this.timer);
			this.tip.style.visibility = "hidden";
			PopUp.setOpacity(100);
			if(this.followMouse)pu_event.remove(document,"mousemove",this.trackMouse,true);
			this.tip=null;
			return false;
		} else {
			PopUp.setOpacity(this.Transparent);
			this.timer=setTimeout("PopUp.fadeout()",50);
		}
	},
	
	toggleVis:function(id,vis){
		var el=document.getElementById(id);
		if(el) el.style.visibility=vis;
	},
	
	trackMouse:function(e){
		e=pu_event.DOMit(e);
		PopUp.positionTip(e);
	},
	
	setOpacity: function(e){
		if (this.tip) {
			this.tip.style.filter = "alpha(opacity="+ e +")";
			this.tip.style.opacity = e/100;
		}
		this.Transparent = e;
	}
};

PopUp.tipOutCheck = function(e) {
  e = pu_event.DOMit(e);
  // is element moused into contained by PopUp?
  var toEl = e.relatedTarget? e.relatedTarget: e.toElement;
  if ( this != toEl && !contained(toEl, this) ) PopUp.fadeout(); 
}

PopUp.timerId = 0;
PopUp.clearTimer = function() {
	if (PopUp.timerId) { clearTimeout(PopUp.timerId); PopUp.timerId = 0; }
	PopUp.setOpacity(100);
}

PopUp.unHookHover = function () {
    var tip = document.getElementById? document.getElementById(PopUp.tipID): null;
    if (tip) {
        tip.onmouseover = null; 
        tip.onmouseout = null;
        tip = null;
	}
}
// returns true of oNode is contained by oCont (container)
function contained(oNode, oCont) {
  if (!oNode) return; // in case alt-tab away while hovering (prevent error)
  while ( oNode = oNode.parentNode ) if ( oNode == oCont ) return true;
  return false;
}
// e=event, msg=one of the above variables, w=width of popup
function doPopUp(e, msg, w) {
  if ( typeof PopUp == "undefined" || !PopUp.ready ) return;
  PopUp.clearTimer();
  var tip = document.getElementById? document.getElementById(PopUp.tipID): null;
  if ( tip && tip.onmouseout == null ) {
		tip.onmouseout = PopUp.tipOutCheck;
		tip.onmouseover = PopUp.clearTimer;
  }
  PopUp.show(e, msg, w);
}

function hideTip() {
  if ( typeof PopUp == "undefined" || !PopUp.ready ) return;
  PopUp.timerId = setTimeout("PopUp.fadeout()", 100);
}

// Removes the titles from the hover links that appear when JS is disabled
function nullLinks() {
	hoverLinks = document.getElementsByTagName("a");
	for (var i=0; i < hoverLinks.length; i++)	{
		if (hoverLinks[i].className == "rollover") { 
			//alert(hoverLinks[i].getAttribute("title"));
			hoverLinks[i].setAttribute("title","");
		}
	}
}

pu_event.add(window, "unload", PopUp.unHookHover, true);

// adjust horizontal and vertical offsets here
// (distance from mouseover event which activates PopUp)
PopUp.offX = 20;  
PopUp.offY = -2;
PopUp.followMouse = false;  // must be turned off for hover-tip

// Standard PopUp content variables that contain the actual HTML for the popup; add more as necessary.
var popup000="The appearance of this page and the sections above that you have opened or closed are stored in a small text file on your machine so that when you leave this page and later return, it looks the same.  No personally identifiable information is stored or transmitted.";
var popup001='Click to expand or collapse this section';
var popup002='Consumer-directed health plans give members more flexibility and control over their health care dollars.';
var popup003='Alternative care typically means services provided by chiropractors, naturopaths, acupuncturists, and massage therapists.';
// The 004 - 014 definitions below should be used on pages in states where we can use the word "member." Otherwise, use 015-020 for pages in states where must say "insured."
var popup004='The coinsurance maximum is the most a member would have to pay in a year for their portion of the covered expense. After that, Asuris pays 100% of all covered expenses, up to the lifetime maximum.';
var popup005='Preventive care services include routine services like well-child care, adult physicals and exams, lab and x-ray, immunizations and more.';
var popup006='To learn about life and disability plans, visit our partner, <a href="http://www.regencelife.com/" target="_blank">Regence Life & Health &raquo;</a>';
var popup007='A fixed, annual dollar amount that a member pays for medical services before Asuris begins paying for covered medical services.';
var popup008='The maximum amount Asuris pays for covered expenses across coverage years for each member.';
var popup009='A fixed dollar amount the member pays the provider when they receive a medical service.';
var popup010='The percentage Asuris pays toward the total negotiated charges for medical services.';
var popup011='A group of selected health care providers (such as hospitals and physicians) who agree to provide Asuris members with services at a negotiated rate.';
var popup012='Providers include hospitals, clinics, physicians, and other health care professionals (such as midwives and nurse practitioners).';
var popup013='Preferred Provider Organization (PPO) plans generally cover any provider. Members get more coverage and lower out-of-pocket costs for seeing "preferred" network providers.';
var popup014='No referrals means a member can go directly to a specialist without first seeing their regular doctor.';
// The 015 - 020 definitions below should be used in states where we must use the term "insured." Otherwise, use definitions above for states where we can use the word "member."
var popup015='The coinsurance maximum is the most an insured would have to pay in a year for their portion of the covered expenses, after meeting the deductible. After that, Asuris pays 100% of all covered expenses, up to the lifetime maximum.';
var popup016='A fixed, annual dollar amount that an insured pays for medical services before Asuris begins paying for covered medical services.';
var popup017='The maximum amount Asuris pays for covered expenses for each insured. This amount accumulates across coverage years, as long as an insured is enrolled on this health plan.';
var popup018='A fixed dollar amount the insured pays the provider when they receive a medical service.';
var popup019='Preferred Provider Organization (PPO) plans generally cover any provider. An insured gets more coverage and lower out-of-pocket costs for seeing "preferred" network providers.';
var popup020='No referrals means an insured can go directly to a specialist without first seeing their regular doctor.';

//more definitions for states where we can use "member"
var popup050='Annual Out-of-Pocket Maximum is the most you and your family will spend on coinsurance and deductible in a calendar year for covered services. After that, Asuris covers 100% of the allowed amount through year-end.<hr>Note: this definition varies with each of our products.';

// 100-108 definitions for dental
var popup100='A fixed, annual dollar amount that a member pays for medical services before Asuris begins paying for covered medical services.';
var popup101='A fixed, annual dollar amount that an insured pays for medical services before Asuris begins paying for covered medical services.';
var popup102='The maximum amount Asuris will pay for dental services in the plan year.';
var popup103='The maximum amount Asuris pays for covered expenses for each member. This amount accumulates across coverage years, as long as a member is enrolled on this dental plan.';
var popup104='The maximum amount Asuris pays for covered expenses for each insured. This amount accumulates across coverage years, as long as an insured is enrolled on this dental plan.';
var popup105='A fixed dollar amount the member pays the provider when they receive a service.';
var popup106='A fixed dollar amount the insured pays the provider when they receive a service.';
var popup107='The percentage Asuris pays toward the total negotiated charges for services.';
var popup108='Providers include dentists, orthodontists, dental surgeons and other licensed dental care professionals.';
var popup109='Endodontics is a restorative treatment for the center of a tooth, such as root-canal therapy.';
