﻿$(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('a:first').attr("class", "footerSelected");
	});
	$("#footer-nav > li").mouseleave(function(){
		$(this).find('a:first').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;
   	});


});

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");
	$("#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 MyHealthLoginSubmit(){
	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/web/user/home?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_pos=1&p_p_col_count=2&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";
	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);
}
