/* ---------------- HealthAllies ---
    Onload JavaScript functions
    Created by ideapark
    August 2007
--------------------------------- */

//the next 3 lines are browser detection for user-agent DOMS
ns4 = (document.layers) ? true:false //required for Functions to work
ie4 = (document.all) ? true:false //required for Functions to work
ng5 = (document.getElementById) ? true:false //required for Functions to work

// This will fix the image flicker problem caused with background images in IE6
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

// This is a method of running functions after the DOM had loaded, but before 
// images and other content is loaded. It is provided by jQuery.

$(document).ready(function(){
	forgotPassword();
	signIn();
	planTabs();
	sampleSavingsTable();
	fontSizeInit();
});

// findAdvancedInit, etc., show and hide the advanced search version of Find a Provider

function forgotPassword() {
	if (document.getElementById('pre_home-help')) {
		fLink = document.getElementById('pre_home-help').getElementsByTagName('a')[0];
		fLink.onclick = function() {
			$('#pre_home-forgotForm').fadeIn('slow');
			$('#pre_home-loginForm').fadeTo('slow',0.00);
		}
		rLink = document.getElementById('pre_home-return').getElementsByTagName('a')[0];
		rLink.onclick = function() {
			$('#pre_home-forgotForm').fadeOut('slow');
			$('#pre_home-loginForm').fadeTo('slow',1);
		}
	}
}

// signIn, etc., show and hide the Sign in DTC overlay

function signIn() {
	if (document.getElementById('signIn')) {
		var signIn = document.getElementById('signIn');
		var signInOpen = document.getElementById('signIn_open');
		var signInClose = document.getElementById('signIn_close');
		var signInLinks = signIn.getElementsByTagName('a');
		
		signInOpen.onclick = function() {
			signInShow(signIn);
			return false;
		}
		signInClose.getElementsByTagName('a')[0].onclick = function() {
			signInHide(signIn);
			return false;
		}
	}
}

function signInShow(signIn) {
	if ((navigator.appName=="Microsoft Internet Explorer") && (!(window.XMLHttpRequest))) {
		$(signIn).show();
	}
	else {
		$(signIn).fadeIn("fast");
	}
}

function signInHide(signIn) {
	if ((navigator.appName=="Microsoft Internet Explorer") && (!(window.XMLHttpRequest))) {
		$(signIn).hide();
	}
	else {
		$(signIn).fadeOut("fast");
	}
}

// planTabs

function planTabs() {
	if (document.getElementById('pre_homeDTC-enhancedTab')) {
		var enhanced = document.getElementById('pre_homeDTC-enhancedTab');
		var enhancedOpen = document.getElementById('enhancedLink');
		var enhancedClose = document.getElementById('basicLink');
		
		enhancedOpen.onclick = function() {
			if ((navigator.appName=="Microsoft Internet Explorer") && (!(window.XMLHttpRequest))) {
				$(enhanced).show();
			}
			else {
				$(enhanced).fadeIn("fast");
			}
			return false;
		}
		enhancedClose.onclick = function() {
			if ((navigator.appName=="Microsoft Internet Explorer") && (!(window.XMLHttpRequest))) {
				$(enhanced).hide();
			}
			else {
				$(enhanced).fadeOut("fast");
			}
			return false;
		}
	}
}

// sampleSavingsTable

function sampleSavingsTable(value) {
	
	if (document.getElementById('sampleSavings_category')) {
		
		menu = document.getElementById('sampleSavings_category');
		
		if (!value) {
			value = menu.value;
		}
		
		options = menu.getElementsByTagName('option');
		
		var tableFinal;
		
		for (i=0; i<options.length; i++) {
				
			table = document.getElementById(options[i].value + 'Table');
			
			if (value == options[i].value) {
				tableFinal = table;
			}
			else {
				
				$(table).hide();
			}
		}
		
		$(tableFinal).fadeIn('fast');
	
		menu.onchange = function() {
			if (menu.selectedIndex != 0) {
				sampleSavingsTable();
			}
		}
		
	}
	
}

/* fontSize() is a method of dynamically changing the size of text on a page. Instead of changing the text size directly, it adds/changes a class to the body tag.
The class ends in an integer, which is incremented or decremented, depending on whether you pass "larger" or "smaller" to the function. You can set a maximum and a minimum for the integer (can be positive or negative). The default integer is 0.
	"fontSize0" = natural font size (equivalent to no class in body tag)
	"fontSize1" = font size +1 larger
	"fontSize-1" = font size -1 smaller
The actual change in font size is accomplished through CSS. You'll need to add selectors to your style sheet for the range of possible classes (as determined by your min and max values). This means you can change other things besides font size (line height, spacing, etc.) or do fun things like gray-out the controls when you reach a maximum or minimum.
fontSize also sets a cookie with your preference and fontSizeInit reads it on page load. */

function fontSizeInit() {
	size = readCookie('fontSize');
	var body = document.getElementsByTagName('body')[0];
	if (size != null && size != '' && size != '0') {
		body.className = body.className.replace(/(.+)?( *fontSize-?\d*)?/,'$1 fontSize' + size);
	}
}

function fontSize(change) {
	var max = 1;
	var min = 0;
	
	var body = document.getElementsByTagName('body')[0];
	var reg = new RegExp(/fontSize-?\d/);
	
	if (reg.test(body.className)) {
		var size = body.className.replace(/.*fontSize(-?\d*).*/,'$1');
		
		if (change == 'larger') {
			if (size > max) {
				body.className = body.className.replace(/ *fontSize-?\d*/,' fontSize' + max);
			}
			
			else if (size < max) {
				size++;
				body.className = body.className.replace(/ *fontSize-?\d*/,' fontSize' + size);
			}
		}
		
		else if (change == 'smaller') {
			if (size < min) {
				body.className = body.className.replace(/ *fontSize-?\d*/,' fontSize' + min);
			}
			
			else if (size > min) {
				size--;
				body.className = body.className.replace(/ *fontSize-?\d*/,' fontSize' + size);
			}
		}
		
	}
	
	else {
		
		if (change == 'larger') {
			if (max > 0) {
				body.className += ' fontSize1';
			}
		}
		
		else if (change == 'smaller') {
			if (min < 0) {
				body.className += ' fontSize-1';
			}
		}
	}
	
	size = body.className.replace(/.*fontSize-?(\d*).*/,'$1');
	createCookie('fontSize',size);
}


// Functions for writing, reading, and erasing cookies
// http://www.quirksmode.org/js/cookies.html

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 
        var expires = "";
	document.cookie = name+"="+value+expires+"; path=/; domain=healthallies.com";
}

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;
}

function eraseCookie(name) 
{
	createCookie(name,"",-1);
}


// STILE 20071107
<!-- REMEMBER ME CHECKBOX -->

function toRemember(a)
{
    createCookie('username', document.getElementById('username').value, '365');     // add a new cookie as shown at left for every
//    newCookie('theEmail', document.form.email.value);   // field you wish to have the script remember
}

function deleteToRemember(a)
{
    eraseCookie('username');   // make sure to add the eraseCookie function for every field
//    eraseCookie('theEmail');
    
    document.getElementById('username').value = '';   // add a line for every field
//    document.form.email.value = '';
}

function popWin(file,width,height,scrollbars,menubar)
{
	window.open(file,'','toolbar=no,left=150,top=150,status=no,width='+width+',height='+height+',scrollbars='+scrollbars+',directories=no,location=no,resizable=yes,menubar='+menubar+'')
}
// ************************************************************************************************************
//(C) www.dhtmlgoodies.com, November 2005 This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website. Terms of use: You are free to use this script as long as the copyright message is kept intact. However, you may not redistribute, sell or repost it without our permission.	Thank you!	www.dhtmlgoodies.com	Alf Magne Kalleland
//************************************************************************************************************
// Alternate way of displaying faqs

var dhtmlgoodies_slideSpeed = 25;	// Higher value = faster
var dhtmlgoodies_timer = 5;	// Lower value = faster

var objectIdToSlideDown = false;
var dhtmlgoodies_activeId = false;
var dhtmlgoodies_slideInProgress = false;
function showHideContent(e,inputId)
{
	if(dhtmlgoodies_slideInProgress)return;
	dhtmlgoodies_slideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var answerDiv = document.getElementById('haFaq_a' + numericId);

	objectIdToSlideDown = false;
	
	if(!answerDiv.style.display || answerDiv.style.display=='none'){		
		if(dhtmlgoodies_activeId &&  dhtmlgoodies_activeId!=numericId){			
			objectIdToSlideDown = numericId;
			slideContent(dhtmlgoodies_activeId,(dhtmlgoodies_slideSpeed*-1));
		}else{
			
			answerDiv.style.display='block';
			answerDiv.style.visibility = 'visible';
			
			slideContent(numericId,dhtmlgoodies_slideSpeed);
		}
	}else{
		slideContent(numericId,(dhtmlgoodies_slideSpeed*-1));
		dhtmlgoodies_activeId = false;
	}	
}

function slideContent(inputId,direction)
{
	
	var obj =document.getElementById('haFaq_a' + inputId);
	var contentObj = document.getElementById('haFaq_ac' + inputId);
	height = obj.clientHeight;
	if(height==0)height = obj.offsetHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + inputId + ',' + direction + ')',dhtmlgoodies_timer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('haFaq_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('haFaq_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,dhtmlgoodies_slideSpeed);				
			}else{
				dhtmlgoodies_slideInProgress = false;
			}
		}else{
			dhtmlgoodies_activeId = inputId;
			dhtmlgoodies_slideInProgress = false;
		}
	}
}

function hideSec(n) {
if (ng5) document.getElementById('sec' + n).style.display = "none"
else if (ns4) document.sec1.display = "none"
else if (ie4) sec1.style.display ="none"
}

function showSec(n) {
if (ng5) document.getElementById('sec' + n).style.display = "block"
else if (ns4) document.sec1.display = "block"
else if (ie4) sec1.style.display ="block"
}

function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='haFaq_question'){
			divs[no].onclick = showHideContent;
			divs[no].id = 'haFaq_q'+divCounter;
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV'){
				answer = answer.nextSibling;
			}
			answer.id = 'haFaq_a'+divCounter;	
			contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px'; 	
			contentDiv.className='haFaq_answer_content';
			contentDiv.id = 'haFaq_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}		
	}	
}
window.onload = initShowHideDivs;


// jquery function to show/hide divs
$(document).ready(function(){

	$("span.toolTip").hover(function() {
	  $(this).next("div").animate({opacity: "show"}, "fast");
	}, function() {
	  $(this).next("div").animate({opacity: "hide"}, "fast");
	});

});   

function swapButtonWithDisabledOne(showDiv, hideDiv, imageID) 
{
	document.getElementById(showDiv).style.display = 'none';
	document.getElementById(hideDiv).style.display = 'block';
	document.getElementById(hideDiv).style.backgroundImage = 'url(/ha/images/btn-loginOnGrayBg.gif)';
	document.getElementById(hideDiv).style.background = 'no-repeat';
    tempString = 'document.images[\"' + imageID + '\"].src = document.images[\"' + imageID + '\"].src';
	setTimeout(tempString, 1);
}
function disableAnchor(linky)
{
    linky.removeAttribute('href');
    linky.removeAttribute('onClick');
    linky.style.textDecoration='none';
    linky.style.cursor='wait';
    linky.style.color='gray';
    this.onclick=function(){return;};
}