window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}


function GotoAffiliateURL(affiliateURL,gotoTitle)
{
	if (affiliateURL.length > 0) {	
		affiliateURL = URLEncode(affiliateURL);
	
		gotoTitle = URLEncode(gotoTitle);
		
		var urlstring = "?goto=" + affiliateURL + "&gototitle=" + gotoTitle;
		
		GotoURL(urlstring);
	}
}


function GotoURL(url)
{
window.location.href=url;
}


function SelectAll(id)
{
document.getElementById(id).focus();
document.getElementById(id).select();
}


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;
}

function ToggleContent(d) {
	if(d.length < 1) { return; }
	if(document.getElementById(d).style.display=="none"){ShowContent(d);return;}
	if(document.getElementById(d).style.display=="block"){HideContent(d);return;}
}

function HideContent(d) {
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "none";
}

function ShowContent(d) {
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "block";
}

function checkStoryIsCurrent(divid,start,end){

  enddate = new Date();
  startdate = new Date();
  today = new Date();

  //Set Start Date
  startday = start.split("/")[0];
  startmonth = start.split("/")[1]-1;
  startyear = today.getFullYear()

  //Set End Date
  endday = end.split("/")[0];
  endmonth = end.split("/")[1]-1;
  endyear = today.getFullYear()

  startdate.setFullYear(startyear,startmonth,startday);
  enddate.setFullYear(endyear,endmonth,endday);

  if ((startdate <= today) && (today <= enddate)){
    ShowContent(divid)
  }else{
    HideContent(divid)
  }
}

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

function getSelectedCheckbox(buttonGroup) {
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function

function getSelectedCheckboxValue(buttonGroup) {
   // return an array of values selected in the check box group. if no boxes
   // were checked, returned array will be empty (length will be zero)
   var retArr = new Array(); // set up empty array for the return values
   var selectedItems = getSelectedCheckbox(buttonGroup);
   if (selectedItems.length != 0) { // if there was something selected
      retArr.length = selectedItems.length;
      for (var i=0; i<selectedItems.length; i++) {
         if (buttonGroup[selectedItems[i]]) { // Make sure it's an array
            retArr[i] = buttonGroup[selectedItems[i]].value;
         } else { // It's not an array (there's just one check box and it's selected)
            retArr[i] = buttonGroup.value;// return that value
         }
      }
   }
   return retArr;
} // Ends the "getSelectedCheckBoxValue" function

function closeDivGroup(divprefix)
{
	var i=0;

	for (i=0;i<=brandcount;i++)
	{
		HideContent(divprefix+i);
	}
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);


Date.prototype.getDOY = function() {var onejan = new Date(this.getFullYear(),0,1);return Math.ceil((this - onejan) / 86400000);}
var today = new Date();
var doy = today.getDOY();
var time = today.getHours();
var todo = "Dream it - Do it - Welcome to a better future!";
if (doy<31) {var todo="Get in Shape and make More Money in the New Year."};
if (doy<70) {var todo="Get slim for Spring. Only "+(82-doy)+" days to go!"};
if (doy<160) {var todo="Get slim for Summer. Only "+(172-doy)+" days to go!"};
if (doy>265) {var todo="Get slim for Christmas. Only "+(358-doy)+" days to go!"};
if (doy>352) {var todo="Happy Holidays !"};
if (doy>358) {var todo="Get in Shape and make More Money in the New Year."};



