function DoClick(buttonName,e)
{
	//the purpose of this function is to allow the enter key to 
	//point to the correct button to click.
	var key;

	if(window.event)
		key = window.event.keyCode;     //IE
	else
		key = e.which;     //firefox

	if (key == 13)
	{
		//Get the button the user wants to have clicked
		var btn = document.getElementById(buttonName);
		if (btn != null)
		{ //If we find the button click it
			btn.click();
			event.keyCode = 0
		}
	}
}

function OpenLinkInNewWindow(link) 
{
    var load = window.open(link);
}

//*************************   Search Form Javascript   ************************************
 
//*************************   Search Form Javascript   ************************************
 



//var productNames = new Array("state", "hmo", "pos", "ppo", "med", "badger");
var productNames = new Array("hmo", "ppo", "badger");
var searchNames = new Array("location", "doctor", "pcp", "specialty");
var showMap = false;



function popupWarning(item)
{
	if (item.disabled)
		alert("Complete only one field in this section");
}

/* NOT NEEDED? */
function popupPage2(link, width, height)
{
	window.open(link, "newWindow", "width=" + width + ",height=" + height + ",scrollbars=yes");
}

function popupPage(link)
{
	window.open(link, "newWindow", "width=500,height=500,scrollbars=yes");
}

function OpenBehavioralHealth()
{
	window.open("BehavioralHealthInformation.aspx", "BehavioralHealth", "width=500,height=400,menubar=no,scrollbars=yes");
}

function OpenBadgerCare()
{
	window.open("BadgerCarePlus.aspx", "BadgerCare", "width=500,height=200,menubar=no,scrollbars=no");
}

function popupClaimNotice()
{
	window.open("notice_ppo_pos.htm", "notice", "width=500,height=500,scrollbars=yes");
}

function popupDisclaimer()
{
	window.open("disclaimer.htm", "disclaimer", "width=500,height=500");
}
/* END NOT NEEDED? */

function openPopupWindow(url)
{
    window.open(url, "popup", "width=500,height=500");
}

function showDetail(divName)
{
	// if not the same show, otherwise hide
	if (document.getElementById(divName + 'Details').style.display == "block")
	{
		document.getElementById(divName + 'Details').style.display = "none";
		document.getElementById(divName + 'DetailsArrow').src = "../FindADoctor/images/arrow_right.gif";
	}
	else
	{
		document.getElementById(divName + 'Details').style.display = "block";
		document.getElementById(divName + 'DetailsArrow').src = "../FindADoctor/images/arrow_down.gif";
		//currentName = pName;
	}
}

function showSearchDetail(sName)
{
	// if not the same show, otherwise hide
	if (document.getElementById(sName + 'Details').style.display == "block")
	{
		document.getElementById(sName + 'Details').style.display = "none";
		document.getElementById(sName + 'DetailsContainer').style.backgroundColor = "#ffffff";
		document.getElementById(sName + 'DetailsArrow').src = "../FindADoctor/images/arrow_right.gif";
	}
	else
	{
		document.getElementById(sName + 'Details').style.display = "block";
		document.getElementById(sName + 'DetailsContainer').style.backgroundColor = "#eeeeee";
		document.getElementById(sName + 'DetailsArrow').src = "../FindADoctor/images/arrow_down.gif";
	}
}

function showSelectedDoctors(url, frm, newWindow)
{
	var dsel = '';
	var fsel = '';
	var dselarray = new Array();
	var fselarray = new Array();
	var loc = url;
	var csel = 0;
	for (var i = 0; i < frm.length; i++)
	{
		if (frm.elements[i].checked)
		{
			if (frm.elements[i].value == 'd')
				dselarray[dselarray.length] = frm.elements[i].name;
			else if (frm.elements[i].value == 'f')
				fselarray[fselarray.length] = frm.elements[i].name;
		}
	} 
	
	if (dselarray.length > 0)
	{
		dsel = dselarray[0];
		for (var i = 1; i < dselarray.length; i++)
			dsel += ',' + dselarray[i];
	}
	
	if (fselarray.length > 0)
	{
		fsel = fselarray[0];
		for (var i = 1; i < fselarray.length; i++)
			fsel += ',' + fselarray[i];
	}
	
	
	if (dsel != "")
		url += "&dSel=" + dsel;
	else if (selDoctors != "" && fsel == "")
		url += "&dSel=" + selDoctors;
	if (fsel != "")
		url += "&fSel=" + fsel;
	else if (selFacilities != "" && dsel == "")
		url += "&fSel=" + selFacilities;
	
	if (fsel == "" && dsel == "" && fId > 0)
		url += "&fId=" + fId;
		
	//alert(url);
	
	if (newWindow)
	{
		window.open(url, 'newWin', 'width=700,height=600,scrollbars=yes,menubar=yes,resizable=yes');
	}
	else
	{
		if (dsel != '' || fsel != '')
			window.location = url;
		else
			alert('Please select at least one Practitioner/Provider.');
	}
}

function showSelectedPharmacies(url, frm, newWindow)
{
	var fsel = '';
	var fselarray = new Array();
	var loc = url;
	var csel = 0;
	for (var i = 0; i < frm.length; i++)
	{
		if (frm.elements[i].checked)
		{
			if (frm.elements[i].value == 'p')
				fselarray[fselarray.length] = frm.elements[i].name;
		}
	}
	
	if (fselarray.length > 0)
	{
		fsel = fselarray[0];
		for (var i = 1; i < fselarray.length; i++)
			fsel += ',' + fselarray[i];
	}
	
	
	if (fsel != "")
		url += "&pSel=" + fsel;
	else if (selFacilities != "")
		url += "&pSel=" + selFacilities;
	
	if (fsel == "" && fId > 0)
		url += "&pId=" + fId;
		
	//alert(url);
	
	if (newWindow)
	{
		window.open(url, 'newWin', 'width=700,height=600,scrollbars=yes,menubar=yes,resizable=yes');
	}
	else
	{
		if (fsel != '')
			window.location = url;
		else
			alert('Please select at least one pharmacy location.');
	}
}

var IE = document.all?true:false;
var posX = 0;
var posY = 0;

function setMousePosition(e)
{
    if (IE)
    {
        posX = event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
		posY = event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    }
	else
	{
		posX = e.pageX;
		posY = e.pageY;
	}
}

document.onmousemove = setMousePosition;


function showHoverBox(text)
{
	var hb = document.getElementById('hoverBox');
	
	if (posX > 500)
		posX = posX - 360;
	
	hb.innerHTML = text;
	hb.style.left = posX + "px";
	hb.style.top = posY + 10 + "px";
	hb.style.display = "block";
}

function hideHoverBox()
{
	var hb = document.getElementById('hoverBox');
	
	hb.style.display = "none";
}

function showNewPatientHelp()
{
	showHoverBox("<b>No:</B><br />PCPs that are only accepting Unity members who are existing patients.<br /><br /><B>Limited Panel:</B><br />Some primary care physicians in our network may be close to having a full practice. Because they have limited availability, you may experience delays in scheduling appointments. You should call the clinic to see if the PCP is accepting new patients.");
	
	return false;
}




// GOOGLE MAP API
var g_points = new Array();

// open google map
function startGoogleMap()
{
	showMap = true;
}

// google map point object to hold data needed
function gPoint(tag, title, body, lon, lat) 
{
	this.tag = tag;
	this.title = title;
	this.body = body;
	this.lon = lon;
	this.lat = lat;
}

// add point
function addPoint(tag, title, body, lon, lat)
{
	g_points.push(new gPoint(tag, title, body, lon, lat));
}


// STYLESHEET SWAPPING
// FROM: http://alistapart.com/stories/alternate/
function setActiveStyleSheet(title) {
  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;
    }
  }
  
  createCookie("pl_stylesheet", title, 365);
}

function getActiveStyleSheet() {
  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 "default";
}

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 "default";
}



// set preferred stylesheet
var cookie = readCookie("pl_stylesheet");
var title = cookie ? cookie : "default";
setActiveStyleSheet(title);