var addEvent = function(obj,evt,fn) {
	if (obj.addEventListener) {
		obj.addEventListener(evt,fn,false);
	} else if (obj.attachEvent) {
		obj.attachEvent('on'+evt,fn);
	}
};


// Print page
addEvent(window, 'load', function () {
	var printBtn = document.getElementById('print-page');
	if (window.opener && window.opener.location.href.match('pdver_')) {
		var printCSS = document.createElement('link');
		printCSS.href = 'css/print.css'
		printCSS.setAttribute('type', 'text/css');
		printCSS.setAttribute('rel', 'stylesheet');
		document.getElementsByTagName('head')[0].appendChild(printCSS);
		
		// Prevent IE png fix from adding background images
		if (document.getElementById('content')) {
			document.getElementById('content').style.background = 'none';
		}
		document.getElementById('wrap').style.background = 'none';
		
		window.print();
	} else if (printBtn){
		printBtn.onclick = function () {
			var printWindow = window.open(window.location, 'printwindow', 'resizable,width=800,height=800,scrollbars');
			return false;
		};
	}
});


// Text size
addEvent(window, 'load', function () {
	var textUp = document.getElementById('increase');
	var textDn = document.getElementById('decrease');
	var textSize = 1;
	
	if (textUp && textDn) {
		textUp.onclick = function () {
			if (textSize === 1) {
				textSize = 1.1;
			} else if (textSize === 1.1) {
				textSize = 1.2;
			} else if (textSize === 1.2) {
				textSize = 1.3;
			}
			document.body.style.fontSize = textSize + 'em';
			return false;
		};
	
		textDn.onclick = function () {
			if (textSize === 1.3) {
				textSize = 1.2;
			} else if (textSize === 1.2) {
				textSize = 1.1;
			} else if (textSize === 1.1) {
				textSize = 1;
			}
			document.body.style.fontSize = textSize + 'em';
			return false;
		};
	}

});


// Prescribing info nav option
addEvent(window, 'load', function () {
	var prescribe = document.getElementById('support-nav').getElementsByTagName('div')[0];
	prescribe.onclick = function () {
		this.parentNode.id = this.parentNode.id === 'open' ? '' : 'open';
		return false;
	};
});


// Force short pages to stretch to browser height
fixHeight = function () {
	var winHeight = document.documentElement.clientHeight;
	var docHeight = document.getElementById('wrap').clientHeight;
	
	if (winHeight > docHeight) {
		document.getElementById('wrap').style.height = winHeight + 'px';
	}
};

addEvent(window, 'load', fixHeight);
addEvent(window, 'resize', fixHeight);
