/* Javascript Document - appliedadvantage.com - Global Functions
/*
/* version:   1.0
/* date:      9/19/2008
/* author:    brian.crumley@alliedpixel.com
/* website:   http://www.alliedpixel.com
/*
----------------------------------------------------------*/


/* Correct IE6 background-image Flicker
----------------------------------------------------------*/
try {
	document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}


/* Begin Image Preload and Rollover Functions
----------------------------------------------------------*/
function newImage(arg) {
	if(document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	};
};

function changeImages() {
	if(document.images && (preloadFlag == true)) {
		for(var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		};
	};
};

var preloadFlag = false;

function imageLoader() {
	if (document.images) {
		pre_banner_enroll_btn_ov = newImage('../image/index_banner_enroll_btn.gif');
		
		preloadFlag = true;
	};
};


/* Begin Footer Positioning Functions
----------------------------------------------------------*/
function getWindowHeight() {
	var windowHeight = 0;
	
	if(typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	} else {
		if(document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		} else {
			if(document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			};
		};
	};
	return windowHeight;
};

function setFooter() {
	if(document.getElementById) {
		var windowHeight = getWindowHeight();
		if(windowHeight > 0) {
			var contentHeight = document.getElementById('container').offsetHeight + 60;
			var footerElement = document.getElementById('footer-wrapper');
			var footerHeight  = footerElement.offsetHeight;
			
			if (windowHeight - ((contentHeight + footerHeight)) >= 0) {
				//alert(windowHeight - (contentHeight + footerHeight));
				
				footerElement.style.position = 'relative';
				footerElement.style.top = (windowHeight - contentHeight) + 'px';
				footerElement.style.marginTop = 0 + 'px';
				footerElement.style.marginBottom = 0 + 'px';
			} else {
				footerElement.style.position = 'static';
				footerElement.style.marginTop = 60 + 'px';
				footerElement.style.marginBottom = 0 + 'px';
			};
		};
	};
};

window.onload = function() { setFooter(); };
window.onresize = function() { setFooter(); };

function changeCat(){
	var catindex = document.cat.category.options[GetSelectedOption(document.cat.category)].value;
	location.href="showbenefitscategory.do?cat=" + catindex;
}

function GetSelectedOption(selectObj)
{
	if (selectObj == null) {
		return -1;
	}
	for (var i=0; i<selectObj.options.length; ++i) {
		if (selectObj.options[i].selected) {
			return i;
		}
	}
	return -1;
}

function SetSelectedOption(selectObj, index)
{
	if (selectObj != null && index != -1) {
		selectObj.options[index].selected = true;
	}
}