// -----------------------------------------------------------------------------------------------------
//  kds_init.js
// -----------------------------------------------------------------------------------------------------




function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

addLoadEvent(function() {
	// call whatever functions you would like executed on page load here:
	setActiveNav();
});




// -----------------------------------------------------------------------------------------------------

function setActiveNav() {
	var classToApply = 'active';
	var rootElement = document.getElementById('interior');
	var curPage = window.location.href;
	// apply "active" class name to the LI element containing the active link
	var links = rootElement.getElementsByTagName('A');
	var li, a;
	for (var i=0; i<links.length; i++) {
		a =  links[i].getAttribute('href');
		if (a) {
			if (a == curPage.substr(curPage.length - a.length)) {
				li = links[i].parentNode; 
				if (!li.className || li.className == '') {
					li.className = classToApply;
				}
				else {
					li.className = li.className + ' ' + classToApply;
				};
			};
		};
	};
};

// -----------------------------------------------------------------------------------------------------

// shareThisPagePopup - shows popup form for "Share this page" feature
function shareThisPagePopup(eLink, objOptions) {
	var wPopup = window.open (eLink.href, '', 'toolbar=no,menubar=no,status=yes,location=no,scrollbars=no,resizable=yes,width=460,height=300');
	
	// use custom window property "shareThisPageData" to pass information to popup
	if (!wPopup.shareThisPageData) {
		wPopup.shareThisPageData = {};
		
		// capture link to page
		wPopup.shareThisPageData.linkToPage = window.location.href;
		
		// copy any options provided
		if (objOptions) {
			wPopup.shareThisPageData.emailOptions = {};
			for (var strProp in objOptions) {
				wPopup.shareThisPageData.emailOptions[strProp] = objOptions[strProp];
			}
		}
	}
	
	wPopup.focus();
	
	return (false);
};
