/* cookie functions */

function getExpDate(days, hours, minutes) {
    var expDate = new Date();
    if (typeof days == "number" && typeof hours == "number" && typeof hours == "number") {
        expDate.setDate(expDate.getDate() + parseInt(days));
        expDate.setHours(expDate.getHours() + parseInt(hours));
        expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
        return expDate.toGMTString();
    }
}

// utility function called by getCookie()
function getCookieVal(offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}

// primary function to retrieve cookie by name
function getCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) {
            return getCookieVal(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
    }
    return "";
}

// store cookie value with optional details as needed
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

// remove the cookie by setting ancient expiration date
function deleteCookie(name,path,domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

/* textSizer functions */

//Specify affected tags. Add or remove from list:
var tgs = new Array( 'body');
function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (isUndefined(v) && isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}
//Specify spectrum of different font sizes:
var szs = new Array( '62.5%','72.5%','82.5%' );
function checkCookie() {
	var tempVal = getCookie("fontSize");
	if(tempVal=="") {
		startSz = 0;
		setCookie("fontSize", startSz, getExpDate(360, 0, 0));
		setSize('body', startSz);
	} else {
		stringSz = getCookie("fontSize");
		startSz = parseInt(stringSz);
		setSize('body', startSz);
	}
}


function setSize( trgt,startSz ) {
	if (!document.getElementById) return
	var d = document,cEl = null,sz = startSz,i,j,cTags;
	startSz = sz;
	setCookie("fontSize", startSz, getExpDate(360, 0, 0));

	if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];

	cEl.style.fontSize = szs[ sz ];

	for ( i = 0 ; i < tgs.length ; i++ ) {
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
	}
}
function ts( trgt,inc ) {
	if (document.getElementById) 
	{
		var d = document,cEl = null,sz = startSz,i,j,cTags;
		sz = inc;
		if ( sz < 0 ) sz = 0;
		if ( sz > 2 ) sz = 2;
		startSz = sz;
		setCookie("fontSize", startSz, getExpDate(360, 0, 0));
		if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];
	
		cEl.style.fontSize = szs[ sz ];
	
		for ( i = 0 ; i < tgs.length ; i++ ) {
			cTags = cEl.getElementsByTagName( tgs[ i ] );
			for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
		}
	}
}

function jumpArchive(){
	var date = new Date();
	var currYear = date.getFullYear();
	var yearSelector = document.getElementById('archiveYears');
	var yearTarget = yearSelector.options[yearSelector.selectedIndex].value;
	
	// change baseURL value as needed
	//var baseURL = "http://www.medi-carefirst.com/partd/NewsArchives/NewsArchives";
	var baseURL = "NewsArchives";
	if((yearTarget == currYear) || (yearTarget == "")) {
		var targetURL = baseURL + ".html";
	} else {		
		var targetURL = baseURL + "_" + yearTarget + ".html";		
	}
	location.href = targetURL;
}



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;
    }
  }
}

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 null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

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 null;
}

window.onload = function(e) {
  // Get Font-size cookie
  checkCookie();
  
  // Get stylesheet cookie
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet(); //
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);


/* --- Last Updated Function just above footer ED ---*/
function savedDate(){

  var days = new Array(8);
	days[1] = "Sunday";
	days[2] = "Monday";
	days[3] = "Tuesday";
	days[4] = "Wednesday";
	days[5] = "Thursday";
	days[6] = "Friday";
	days[7] = "Saturday";

  var months = new Array(13);
	months[1] = "January";
	months[2] = "February";
	months[3] = "March";
	months[4] = "April";
	months[5] = "May";
	months[6] = "June";
	months[7] = "July";
	months[8] = "August";
	months[9] = "September";
	months[10] = "October";
	months[11] = "November";
	months[12] = "December";

  var dateObj = new Date(document.lastModified);
  var dayName = days[dateObj.getDay() + 1];
  var monthName = months[dateObj.getMonth() + 1];
  var date = dateObj.getDate();
  var year4 = dateObj.getYear();
  if (year4 < 2000) 
  year4 += 1900
  
  document.write(dayName + ", " + monthName + " " + date + ", " + year4);

  return;  
}

/* --- END Last Updated Function just above footer ED ---*/

//----ED---begin function Magazine --------

function MagazineDP(Form)
{

 var dalert = "";
 dalert = "If you wish to proceed to additional information about this program, click the 'OK' button below.  When you click on the 'OK' link below, please be aware that you are leaving the Medi-CareFirst Web site and entering the Healthways WholeHealth Networks, Inc. (HWHN) site, governed by HWHN's privacy policy. HWHN tracks user traffic patterns throughout its site. However, it does not correlate this information with data about individual users. Users remain anonymous in the tracking process. HWHN uses this information to determine which areas of the site are most popular with users, based on traffic to those areas. HWHN does not track what individual users read, but rather how well each page performs overall. This helps HWHN continue to build a better service for the consumer.";

 if (confirm (dalert)){
    if (Form == true)
		{
			location = "Magazine.html";
			window.open('http://options.wholehealthmd.com/cfhealthyreading.asp','_blank','');

		}
	else 
		{
			location = "Magazine.html";
			window.open('http://options.wholehealthmd.com/cfhealthyreading.asp','_blank','');
		}
	return true;
  }
  else{
  location ="/mcf/options/OptionsLanding.html";
  return false;
  }
} //end function Magazine
