// ******************************************************************************************
// BEGIN SITE VERSION FUNCTIONS
// ******************************************************************************************
// Check for the existence of a site version cookie.
// If it exists, and this isn't the correct version, redirect.
// If it does not exist, do nothing. A link will allow for the setting to the preferred version.
/////////////////////////////////////////////////////////////////////////////////////////////

if (top != self) top.location=self.document.location;

// Site version cookie.
// Valid values: 2007 | 2008
var versionCookie = 'siteDefaultPref';

// Site home page locations.
var siteLocs = new Object();
siteLocs["2007"] = 'home.dhtml';
siteLocs["2008"] = '_home.dhtml';

// Misc. globals.
var expHours = 672; // ~4 weeks
var cookieExp = new Date((new Date()).getTime() + expHours*3600000);
var versionDomName = 'isagenix.com';


// Check to see if we're on the site specified as the parameter. Redirect if not.
// Parameter: curSite = passed value for current site version. Check valid values in "versionCookie".
function checkDefaultSite(curSite) {
	var cookieVal = getCookie(versionCookie);
	
	if (cookieVal != null && cookieVal != '') {
  	if (curSite != cookieVal) {
			window.location = siteLocs[cookieVal]; // cookieVal should always contain the desired default site.
	  }
	} // No cookie set, don't set one unless directed by user.
}


// Output the correct message to set the cookie when clicked.
// Parameter: curSite = passed value for current site version. Check valid values in "versionCookie".
function displayDefaultSiteCode(curSite) {
	var cookieVal = getCookie(versionCookie);

  if (cookieVal != null && cookieVal != '') {
		// Has a value.
		document.writeln('<a href="#" onClick="javascript:deleteCookie(versionCookie, \'/\', versionDomName); window.location.reload(true);">Restore previous Isagenix home page</a>');
  } else { // No value
		document.writeln('<a href="#" onClick="javascript:setDefaultSite(\'2008\'); return false;">Make this my default Isagenix home page</a> | <a href="home.dhtml">Return to the previous Isagenix home page</a>');
  }
}


// Set the cookie to the version passed in siteVer, then redirect to that version.
function setDefaultSite(siteVer) {
	setCookie(versionCookie, siteVer, cookieExp, '/', versionDomName, null);
	window.location = siteLocs[siteVer];
}
// ******************************************************************************************
// END SITE VERSION FUNCTIONS
// ******************************************************************************************
