function blanketPopupToggle(id) {
	var el = document.getElementById(id);
	if (!el) {
		return;
	}
	if (el.style.display == 'none') {
		el.style.display = 'block';
	} else {
		el.style.display = 'none';
	}
}

function blanketPopupCenter(width, height) {

	var blanket       = document.getElementById('blanket');
	var blanket_popup = document.getElementById('blanket-popup');
	
	if (!blanket || !blanket_popup) {
		return;
	}
	
	// Offsets
	var offset_x = self.pageYOffset ? self.pageXOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollLeft : document.body ? document.body.scrollLeft : null;
	var offset_y = self.pageYOffset ? self.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop  : document.body ? document.body.scrollTop  : null;	
	
	
	// Height
	blanket_popup.style.height = height+'px';
	
	if (typeof window.innerWidth != 'undefined') {
		viewport_height = window.innerHeight;
	} else {
		viewport_height = document.documentElement.clientHeight;
	}
	if ((viewport_height > document.body.parentNode.scrollHeight) && (viewport_height > document.body.parentNode.clientHeight)) {
		blanket_height = viewport_height;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	blanket.style.height = blanket_height + 'px';

	blanket_popup_height = blanket_height/2 - height/2 + offset_y;
	blanket_popup.style.top = blanket_popup_height + 'px';


	// Width
	blanket_popup.style.width = width+'px';
	
	if (typeof window.innerWidth != 'undefined') {
		viewport_width = window.innerWidth;
	} else {
		viewport_width = document.documentElement.clientWidth;
	}
	if ((viewport_width > document.body.parentNode.scrollWidth) && (viewport_width > document.body.parentNode.clientWidth)) {
		window_width = viewport_width;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	window_width = window_width/2 - width/2 + offset_x;

	blanket_popup.style.left = window_width + 'px';

}


function blanketPopup(width, height, text) {
	
	if (text) {
		var el = document.getElementById('blanket-popup-content');
		if (el) {
			el.innerHTML = text;
		}
	}
	
	blanketPopupCenter(width, height);
	
	blanketPopupToggle('blanket');
	blanketPopupToggle('blanket-popup');

}

