/*
	CNA.org scripts
	Updated 11/2/06 by Saforian, Inc.
*/


// Generic popup window functions
function popup(URL, width, height) {
	popWin = window.open(URL, "popWin", "width=" + width + ",height=" + height + ",resizable=0,scrollbars=0,location=0,toolbar=0");
	popWin.focus();
	return false;
}

function popupResize(URL, width, height) {
	popWin = window.open(URL, "popWin", "width=" + width + ",height=" + height + ",resizable=1,scrollbars=1,location=0,toolbar=0");
	popWin.focus();
	return false;
}


/* IE transparency filter */

var isIE = (document.all && navigator.appName == "Microsoft Internet Explorer" &&
		(navigator.userAgent.indexOf("MSIE 5.5") >= 0 || navigator.userAgent.indexOf("MSIE 6.") >= 0));

if (isIE) { 
	//window.attachEvent("onload", alphaBackgrounds);
	window.attachEvent("onload", pngImages);
	window.attachEvent("onload", resizeSubnav);
	window.attachEvent("onload", cssFixes);
}

function alphaBackgrounds(){
	// Background PNG transparancy for IE (derived from allinthehead.com)
	var bg, pngFile;

	for (i=0; i<document.all.length; i++) {
		bg = document.all[i].currentStyle.backgroundImage;
		if (bg && bg.match(/\.png/i) != null) {
			pngFile = bg.substring(5, bg.length-2);
			document.all[i].runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + pngFile + "')";
			document.all[i].runtimeStyle.backgroundImage = "url('/images/spacer.gif')";
		}
	}
}

function pngImages() {
	// Inline image PNG transparency for IE (derived from youngpup.net)
	for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--)
		if (img.src.match(/\.png$/i) != null) {
			var src = img.src;
			var div = document.createElement("DIV");

			div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizing='scale')"
			div.style.width = img.width + "px";
			div.style.height = img.height + "px";
			img.replaceNode(div);
		}
}

function resizeSubnav() {
	// Resize subnavigation background layer for IE

	if (document.getElementById("subnavBack")) {
		var backLayer = document.getElementById("subnavBack");
		var listLayer = document.getElementById("subnavBack").nextSibling;

		backLayer.runtimeStyle.height = (listLayer.offsetHeight + "px");
	}
	if (document.body.id == "home" && document.getElementById("whatsnewBack")) {
		var backLayer = document.getElementById("whatsnewBack");
		var listLayer = document.getElementById("whatsnewBack").nextSibling;

		backLayer.runtimeStyle.height = (listLayer.offsetHeight + "px");
	}
}

function cssFixes() {
	// Fix missing CSS features for IE

	// Remove top border from subnavigation lists
	if (document.getElementById("sidebar")) {
		lists = document.getElementById("sidebar").getElementsByTagName("ul");
		for (var i = 0; i < lists.length; i++)
			    // Set redundant first child class
				if (lists[i].firstChild) lists[i].firstChild.className += " first-child";
	}


	// Remove top border from UL.thumbs:first-child
	var lists = document.getElementsByTagName("ul");
	for (var i = 0; i < lists.length; i++)
		if (lists[i].className == "thumbs")
		    // If a thumbnail list, set redundant first child class
			if (lists[i].firstChild) lists[i].firstChild.className += " first-child";
}




// Clear search keywords
function clearSearch() {
	if (document.getElementById('keywords')) {
		document.getElementById('keywords').onfocus = function() {
			if (this.value == this.defaultValue) this.value = ""; }

		document.getElementById('keywords').onblur = function() {
			if (this.value == "") this.value = this.defaultValue; }
	}
}

// Search button rollover color - Not used
function searchButton() {
	if (document.getElementById('searchGo')) {
		document.getElementById('searchGo').onmouseover = function() { this.style.backgroundColor = "#7193b2"; this.src = "/images/button_searchgo_over.gif"; }
		document.getElementById('searchGo').onmouseout = function() { this.style.backgroundColor = "#b9b9b1"; this.src = "/images/button_searchgo.gif"; }
	}
}
