// JavaScript Document

// depends absolutely on file naming scheme, with all espanol pages
// named same as english, but with "esp_" prepended.
function goLang(lang) {
	var tmpurl = location.toString();
	var tmpstart = tmpurl.substring(0, tmpurl.lastIndexOf('/')+1);
	var tmpend = tmpurl.substring(tmpstart.length, tmpurl.length);

	var tmpmid = "";
	if (lang) tmpmid = lang+'_';
	else tmpend = tmpend.substr(tmpend.indexOf('_')+1);
	var newurl = tmpstart+tmpmid+tmpend;
	window.location = newurl;
}

var toolWindow = null;
function launchTool(name, num) {
	var page = name+ "/" +name+ "_pop" +num+ ".htm";
	popWindow = window.open(page, name+num, 'width=688, height=480, toolbar=no, menubar=yes, scrollbars=yes, status=no');
	}

function toggleBright(obj, state) {
	state == 1 ? obj.style.color = "#FFFFFF" : obj.style.color = "";
	}

// standard functions
function _blurLinks() {
   for (i=0; i<document.links.length; i++) {
      if (document.links[i].blur!=null) {
         document.links[i].blur();
         }
      }
   }

function _OpenWin(wURL, wName, wWidth, wHeight) {
   wFeatures = 'width='+wWidth+',height='+wHeight+',menubar=yes,toolbar=no,location=no,scrollbars=yes,status=no,resizable=yes';
   var nw = window.open(wURL,wName,wFeatures);
   nw.focus();
   }

// checks for cookie
function seenBefore() {

	var theCookies;
	var tc = "t" + Math.floor(Math.random()*10000) + "=1";
	document.cookie = tc;	// assume if seesion cookie works that all cookies work;
	theCookies = document.cookie;
//	alert("seenBefore cookie: "+theCookies);
	if (theCookies==null || theCookies.indexOf(tc)<0) return(true);
	if (theCookies.indexOf("seenBefore")>=0) return(true);
	return(false);
	}

// sets cookie
function setHaveSeenBefore() {

	var theCookies;
	var d = new Date();

	d.setFullYear(d.getFullYear()+10);
	var expStr = d.toGMTString();

	theCookies = "seenBefore=1; path=/; expires=" + expStr;
//	alert("setSeen cookie: "+theCookies);
	document.cookie = theCookies;
	}

// works with cookie info
function showAd() {
	var seen = seenBefore();
	if (!seen) {
		launchAd();
		}
	}

function launchAd() {
	if (ad == null) {
		wFeatures = 'width=450,height=520,menubar=no,toolbar=no,location=no,scrollbars=no,status=no,resizable=no';
		var ad = window.open("https://ss.geosite.com/healthmark/sunsafety/asc_updates.htm","updates_ad",wFeatures);
		ad.opener.focus();
		}
	}

function launchUpdates(orig) {
	if (ad == null) {
		wFeatures = 'width=450,height=480,menubar=no,toolbar=no,location=no,scrollbars=no,status=no,resizable=no';
		var ad = window.open("https://ss.geosite.com/healthmark/sunsafety/pop_updates.htm","updates_ad",wFeatures);
		if (!orig) ad.opener.focus();
		else ad.focus();
		}
	else {
		ad.focus();
		}
	}
