﻿$(document).ready(function(){

	$("#main-nav li").mouseenter(function(){
		$(this).find('a:first').attr("class", "over");
		$(this).find('ul:first').toggle();
	});
	$("#main-nav li").mouseleave(function(){
		$(this).find('a:first').attr("class", "");
		$(this).find('ul:first').toggle();
	});

	$("#footer li").mouseenter(function(){
		$(this).find('ul:first').toggle();
	});
	$("#footer li").mouseleave(function(){
		$(this).find('ul:first').toggle();
	});

	$("#footer-nav > li").mouseenter(function(){
		$(this).find('span').attr("class", "footerSelected");
	});
	$("#footer-nav > li").mouseleave(function(){
		$(this).find('span').attr("class", "");
	});

	//Some custom forms change URL parameter Submitted=True after submission.  
	//This allows us to hide the rest of the page content and only show the success message after.
	var submitted = $.urlParam('Submitted');
	if (submitted!='') $(".hiddenOnSubmit").html('');
	
	//show right nav link box shading if there's webparts in the link area
	if ($("#rightArticleLinks").length!=0 && $("#rightArticleLinks").html().length!=0)
	{
		$("#rightShadow1").toggle();
		$("#rightShadow2").toggle();
	}

	changeCoverage("tab1");
	$("#insurance-coverage").show();
	
	// show/hide common questions drop down
	$("#questions-dd").click(function(){
		$("#questions-menu").show();
	});
	$("#questions-menu").mouseover(function(){
		$("#questions-menu").show();
	});
	$("#questions-menu").mouseout(function(){
		$("#questions-menu").hide();
	});
	$("#questions-dd").mouseout(function(){
		$("#questions-menu").hide();
	});
	
	$("a[name='track'][href$='pdf']").click(function(event){
	    trackLink(this, this.innerHTML);
   	});
   	   	
   	$("a[name='secure']").each(function(){
	    var url = $(this).attr("href");
	    if (url.indexOf("selecthealth.org") > 0)
	    	url = url.split("selecthealth.org")[1];
	    var url = "https://selecthealth.org" + url;
	    this.href = url;
   	});

	$("label").each(function(){
		var html = $(this).html();
		if (html == "Change:*")
		{
			$(this).html("First Name:*");
			return false;
		}
	});

});

var arrInsuranceLinks = new Array();
arrInsuranceLinks["tab1"] = "http://www.selecthealth.org";
arrInsuranceLinks["tab2"] = "http://www.google.com";
arrInsuranceLinks["tab3"] = "http://www.selecthealth.org";
function changeCoverage(id){
	// set class in containers to show insurance images
	$("#tab-right-imgtab1").attr("class", "tabHide");
//nasty front page link hack
	$("#tab-right-imgtab1").attr("innerHTML", "<a href='http://selecthealth.org/plans/Pages/home.aspx'>" + $("#tab-right-imgtab1").attr("innerHTML") + "</a>");
//end nasty
	$("#tab-right-imgtab2").attr("class", "tabHide");
	$("#tab-right-imgtab3").attr("class", "tabHide");
	$("#tab-right-img" + id ).attr("class", "tabDisplay");
	// reset all tabs
	$(".tab1-active").attr("class", "tab1");
	$(".tab2-active").attr("class", "tab2");
	$(".tab3-active").attr("class", "tab3");
	// highlight selected tab
	$("."+id).attr("class", id+"-active");
	// hide all left insurance containers
	$("#tab1-left").hide();
	$("#tab2-left").hide();
	$("#tab3-left").hide();
	// show selected insurance copy
	$("#"+id+"-left").show();
}

$.urlParam = function(name){ 
	var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href); 
	if (!results) {return 0;} 
	return results[1] || 0;
} 

function slam(){
var rx_param = snrg( 'rx' );
  if (rx_param=="y"){
  var allAs=document.getElementsByTagName('A');
    for (zz=0;zz<allAs.length;zz++){
      if (allAs[zz].innerHTML=="<SPAN class=listlink>Go to My Pharmacy Tools</SPAN>"){
allAs[zz].innerHTML="<SPAN class=listlink>Go to Pharmacy Tools</SPAN>";
      }
    }
  }
}

function PBMLoginSubmit(which){
//check if two fields
if (which==1){

	var submitForm = document.createElement("form");
	submitForm.setAttribute("method", "post");
	submitForm.setAttribute("name", "_58_fm");
	submitForm.setAttribute("id", "login_form");
	submitForm.setAttribute("action", "https://myhealth.intermountainhealthcare.org/home?p_auth=xxl4DSR5&p_p_id=58&p_p_lifecycle=1&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=9&saveLastPath=0&_58_struts_action=%2Flogin%2Flogin&_58_redirect=%2Fweb%2Fuser%2Fpharmacy-tools?rx=y");
	var userNameElement = document.createElement("input");
	userNameElement.setAttribute("id", "_58_login");
	userNameElement.setAttribute("name", "_58_login");
	userNameElement.setAttribute("type", "hidden");
	userNameElement.value=$('#username').val();
	submitForm.appendChild(userNameElement);
	
	var passwordElement = document.createElement("input");
	passwordElement.setAttribute("id", "_58_password");
	passwordElement.setAttribute("name", "_58_password");
	passwordElement.setAttribute("type", "hidden");
	passwordElement.value = $('#password').val();
	submitForm.appendChild(passwordElement);
	
	
	
	//var realmElement = document.createElement("input");
	//realmElement.setAttribute("name", "_58_redirect");
	//realmElement.setAttribute("id", "_58_redirect");
	//realmElement.setAttribute("type", "hidden");
	//realmElement.value = "%2Fweb%2Fuser%2Fpharmacy-tools";
	//realmElement.value = "";
//serverElement.eyeStab.eyeStab("liferay," "homeSty");

	//submitForm.appendChild(realmElement);
	document.body.appendChild(submitForm);
	submitForm.submit();
	
	}else{
	
	var submitForm = document.createElement("form");
	submitForm.setAttribute("method", "post");
	submitForm.setAttribute("name", "_58_fm");
	submitForm.setAttribute("id", "login_form");
	submitForm.setAttribute("action", "https://myhealth.intermountainhealthcare.org/home?p_auth=xxl4DSR5&p_p_id=58&p_p_lifecycle=1&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=9&saveLastPath=0&_58_struts_action=%2Flogin%2Flogin&_58_redirect=%2Fweb%2Fuser%2Fpharmacy-tools?rx=y");
	var userNameElement = document.createElement("input");
	userNameElement.setAttribute("id", "_58_login");
	userNameElement.setAttribute("name", "_58_login");
	userNameElement.setAttribute("type", "hidden");
	userNameElement.value=$('#username2').val();
	submitForm.appendChild(userNameElement);
	
	var passwordElement = document.createElement("input");
	passwordElement.setAttribute("id", "_58_password");
	passwordElement.setAttribute("name", "_58_password");
	passwordElement.setAttribute("type", "hidden");
	passwordElement.value = $('#password2').val();
	submitForm.appendChild(passwordElement);
	
	
	

	//submitForm.appendChild(realmElement);
	document.body.appendChild(submitForm);
	submitForm.submit();
	
	}
}
$(function() {	
	$("#password").focus(function() {	
		if ($("#password").val()=='Password')
		{
			$("#password").val('');
		}
    });
    $("#username").focus(function() {	
		if ($("#username").val()=='Username')
		{
			$("#username").val('');
		}
    });

});



function MyHealthLoginSubmit(){
	//I SEE YOU PEEKER PEEKER PEEKER
	var submitForm = document.createElement("form");
	submitForm.setAttribute("method", "post");
	submitForm.setAttribute("name", "_58_fm");
	submitForm.setAttribute("id", "login_form");
	submitForm.setAttribute("action", "https://myhealth.intermountainhealthcare.org/home?p_auth=xxl4DSR5&p_p_id=58&p_p_lifecycle=1&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=9&saveLastPath=0&_58_struts_action=%2Flogin%2Flogin");
	var userNameElement = document.createElement("input");
	userNameElement.setAttribute("id", "_58_login");
	userNameElement.setAttribute("name", "_58_login");
	userNameElement.setAttribute("type", "hidden");
	userNameElement.value=$('#username').val();
	submitForm.appendChild(userNameElement);
	
	var passwordElement = document.createElement("input");
	passwordElement.setAttribute("id", "_58_password");
	passwordElement.setAttribute("name", "_58_password");
	passwordElement.setAttribute("type", "hidden");
	passwordElement.value = $('#password').val();
	submitForm.appendChild(passwordElement);
	
	var realmElement = document.createElement("input");
	realmElement.setAttribute("name", "_58_redirect");
	realmElement.setAttribute("id", "_58_redirect");
	realmElement.setAttribute("type", "hidden");
	//realmElement.value = "https://myhealth.intermountainhealthcare.org/web/user/home";
	realmElement.value = "";
//serverElement.eyeStab.eyeStab("liferay," "homeSty");

	submitForm.appendChild(realmElement);
	document.body.appendChild(submitForm);
	submitForm.submit();
}
$(function() {	
	$("#password").focus(function() {	
		if ($("#password").val()=='Password')
		{
			$("#password").val('');
		}
    });
    $("#username").focus(function() {	
		if ($("#username").val()=='Username')
		{
			$("#username").val('');
		}
    });

});

function srchGO(searchType) {
    var newLocation = "";
    if (searchType=="main") {
		newLocation = "/Pages/Results.aspx?k=";
		newLocation +=document.getElementById('searchInput').value;
		newLocation +="&s=SelectHealth";
	}
	else if (searchType=='form') {
		if (document.activeElement.id=="searchInput")
	 	{
	 		return false;
	 	} 
	 	else 
	 	{
	 		return _spFormOnSubmitWrapper();
	 	}
	}
	window.location.replace(newLocation);
}





