function openWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
  return false;
}
function createMailLink() {
		$('mailLink').href=('mailto:?subject=Article from Touchmark - '+$("artTitle").innerHTML+'&body='+window.location);
}
function customPage() {
	var waas = new Array("Waterford at All Saints","Sioux Falls, South Dakota","http://waterfordsiouxfalls.com");
	var wafv = new Array("Waterford at Fairway Village","Vancouver, Washington","http://waterfordVancouver.com");
	var wbmt = new Array("Waterford on Elizabeth Warren", "Butte, Montana", "http://waterfordbutte.com");
	var teab = new Array("Touchmark at Wedgewood", "Edmonton, Alberta, Canada", "http://touchmarkwedgewood.com");
	var tawi = new Array("Touchmark on West Prospect", " Appleton, Wisconsin", "http://touchmarkappleton.com");
	var wfnd = new Array("Waterford at Harwood Groves", " Fargo, North Dakota", "http://waterfordfargo.com");
	var wbnd = new Array("Waterford on West Century", " Bismarck, North Dakota", "http://waterfordbismarck.com");
	var tbor = new Array("Touchmark at Mt. Bachelor Village ", "  Bend, Oregon", "http://touchmarkbend.com");
	var teok = new Array("Touchmark at Coffee Creek ", "  Edmond, Oklahoma", "http://touchmarkedmond.com");
	var tmlv = new Array("Touchmark at Meadow Lake Village ", "  Meridian, Idaho", "http://meadowlakevillage.com");
	var commData = new Array("WAAS", waas, "WAFV", wafv, "WBMT", wbmt, "TEAB", teab, "TAWI", tawi, "WFND", wfnd, "WBND", wbnd, "TBOR", tbor, "TEOK", teok, "TMLV", tmlv);
	temp = window.location;
	temp = temp +'';
	divider = temp.indexOf("=") + 1;
	comm = temp.slice(divider);
	comm = comm.toUpperCase();
	for (counter=0; counter <= commData.length; counter++) {
		if (comm == commData[counter]) {
			counter == counter++;
			i=0;
			$('cContact').href += comm; /* adds acro to end of contact us link */
			$('cName').innerHTML = commData[counter][i] + '&nbsp;&ndash;&nbsp;'; /* adds comm Name to header bar */
			$('cLogo').alt += ('&nbsp;&ndash;&nbsp;' + commData[counter][i]);
			i++;
			$('cLoc').innerHTML = commData[counter][i];
			i++;
			$('cLink').href = commData[counter][i];
			createMailLink();
			return false;
		}
	}
	createMailLink();
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
	document.writeln('<style type="text/css">img, input.image { visibility:hidden; } </style>');
	window.attachEvent("onload", fnLoadPngs);
}

function fnLoadPngs() {
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);

	for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--) {
		if (itsAllGood && img.src.match(/\.png$/i) != null) {
			fnFixPng(img);
			img.attachEvent("onpropertychange", fnPropertyChanged);
		}
		img.style.visibility = "visible";
	}

	var nl = document.getElementsByTagName("INPUT");
	for (var i = nl.length - 1, e = null; (e = nl[i]); i--) {
		if (e.className && e.className.match(/\bimage\b/i) != null) {
			if (e.src.match(/\.png$/i) != null) {
				fnFixPng(e);
				e.attachEvent("onpropertychange", fnPropertyChanged);
			}
			e.style.visibility = "visible";
		}
	}
}

function fnPropertyChanged() {
	if (window.event.propertyName == "src") {
		var el = window.event.srcElement;
		if (!el.src.match(/x\.gif$/i)) {
			el.filters.item(0).src = el.src;
			el.src = "x.gif";
		}
	}
}

function dbg(o) {
	var s = "";
	var i = 0;
	for (var p in o) {
		s += p + ": " + o[p] + "\n";
		if (++i % 10 == 0) {
			alert(s);
			s = "";
		}
	}
	alert(s);
}

function fnFixPng(img) {
	var src = img.src;
	img.style.width = img.width + "px";
	img.style.height = img.height + "px";
	img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')"
	img.src = "x.gif";
}
function tourFlyOut() {
	var flyDiv = document.getElementById('suppDropDown');
	var flyList =  document.getElementById('suppDropDownList');
	flyList.style.width = flyDiv.offsetWidth;
	flyDiv.onmouseout = crush;
	flyDiv.onmouseover = expand;
}	
function expand() {
	this.style.overflow = 'visible';
}
function crush() {
	this.style.overflow = 'hidden';
}
function autoDownload() { // at the moment used only to initiate an automatic download of a newsletter from a url with name/value pair 'm=november' or some such
    var urlVars = document.location.search;
    if ( !(newsletterList = document.getElementById("newsletters")) || urlVars == "" ) { return; }
    var downloadTags = ["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"];
    for (tagInc = 0; tagInc < downloadTags.length; tagInc++) {
        if (urlVars.indexOf(downloadTags[tagInc]) != -1) { 
			crawl(newsletterList, findDownload);
		}
    }
    function findDownload(x) {
        if ( x.tagName && x.tagName.toLowerCase() == "a" && x.href.toLowerCase().indexOf(downloadTags[tagInc]) != -1 ) { document.location = x.href; }
    } 
}
function crawl(el, fn) {  // takes an element and crawls every element inside and runs a specified function on it
	var level= 0;
	do {
		while ( el.firstChild ) {
			el = el.firstChild;
			fn(el);
			level++;
		}
		if ( el.nextSibling ) {
			el = el.nextSibling;
			
			fn(el);
		}
		else {
			climb:
			for ( i = level; i > 0; i-- ) {
				el = el.parentNode;
				
				level--;
				if ( el.nextSibling ) {
					el = el.nextSibling;
					
					fn(el);
					break climb;
				}
			}
		}
	} while ( level > 0 )
	return false;
}