
// This script manipulates the DOM to show important messages. It should be modified only by authorized OWC staff.
// The message displayed is controlled by a web-based page.

lastUpdated = 'Friday, June 12  at 8:41:16 AM EDT';
OWC_message = 'No message';

// Cookies functions from http://www.w3schools.com/JS/js_cookies.asp
function getCookie(c_name) {
	if (document.cookie.length > 0) {
		//alert(document.cookie);
		c_start = document.cookie.indexOf(c_name + '=');
		if (c_start != -1) { 
			c_start = c_start + c_name.length + 1; 
			c_end = document.cookie.indexOf(';', c_start);
			if (c_end == -1) {c_end = document.cookie.length;}
			return unescape(document.cookie.substring(c_start, c_end));
		} 
	}
	return '';
}

function setCookie(c_name, value, expireminutes) {
	var expires = new Date();
	var expiremilliseconds = expireminutes * 60 * 1000;
	//alert(expiremilliseconds);
	expires.setTime(expires.getTime() + expiremilliseconds);
	var cookieStr = c_name + '=' + escape(value) + ((expireminutes == null) ? '' : ';expires=' + expires.toGMTString()+'; path=/');
	//alert(cookieStr);
	document.cookie = cookieStr;
}

function closeWarning() {
	document.getElementById("WarningBox").style.display="none";
	setCookie('CU_emer_banner', 'Clicked', 2);
}

function show_OWC_emergency_banner() {
	// Check for cookied to see if banner has already appeared and/or is expired.
	var showBanner = true;
	if (getCookie('CU_emer_banner') == 'Clicked') {
		showBanner = false;
		//alert(getCookie('CU_emer_banner'));
	}
	
	if ((OWC_message.indexOf('No message') == -1) && (showBanner)) {
		OWC_message = 'University Alert: ' + OWC_message;
		<!-- // Create a new DIV and set its attributes -->
		var newDiv = document.createElement('div'); 
		newDiv.style.border = '3px solid #b31b1b';
		newDiv.style.clear = 'both';
		newDiv.style.display = 'block';
		newDiv.style.visibility = 'visible';
		newDiv.style.backgroundColor = '#fff000';
		newDiv.style.width = '98%';
		newDiv.style.padding = '.5em';
		newDiv.style.textAlign = 'center';
		newDiv.style.marginBottom = '.8em';
		newDiv.style.position = 'absolute';
		newDiv.style.top = '0';
		newDiv.style.left = '0';
		newDiv.style.zIndex = '999';
		newDiv.id = 'WarningBox';

		newDiv.style.marginTop = '10%';
		newDiv.style.left = '25%';
		newDiv.style.right = 'auto';
		newDiv.style.width = '50%';

		<!-- // Set the icon -->
		var icon = document.createElement('img');
		icon.setAttribute('src', 'http://www.cornell.edu/img/layout/alert.gif');
		icon.style.marginRight = '10px';
		icon.style.marginBottom = '-3px';
		<!-- // Set the message paragraph -->
		var newMessage = document.createElement('p');
		newMessage.style.fontWeight = 'bold';
		newMessage.style.fontSize = '18px';
		newMessage.appendChild(icon);
		newMessage.appendChild(document.createTextNode(OWC_message));
		<!-- // Set the link paragraph -->
		var newLinkPara = document.createElement('p'); 
		var newLink = document.createElement('a'); 
		newLink.setAttribute('href', 'http://www.cornell.edu/about/status/index.cfm');
		newLink.style.color = '#b31b1b'; 
		newLink.appendChild(document.createTextNode('More information here.')); 
		newLinkPara.appendChild(newLink);
		<!-- // Set the last-updated paragraph -->
		var lastUpdatedPara = document.createElement('p');
		lastUpdatedPara.style.fontStyle = 'italic';
		lastUpdatedPara.style.fontSize = '11px';
		lastUpdatedPara.style.color = '#666666';
		lastUpdatedPara.appendChild(document.createTextNode('Last update: ' + lastUpdated)); 
		
		<!-- // Set the close paragraph -->
		var newClosePara = document.createElement('p'); 
		var newCloseLink = document.createElement('a'); 
		newCloseLink.setAttribute('href', 'JavaScript:closeWarning()');
		newCloseLink.style.color = '#b31b1b'; 
		newCloseLink.appendChild(document.createTextNode('Close')); 
		newClosePara.appendChild(newCloseLink);
		
		
		<!-- // Fill the div with the paragraphs -->
		newDiv.appendChild(newMessage);
		newDiv.appendChild(newLinkPara);
		newDiv.appendChild(lastUpdatedPara);
		newDiv.appendChild(newClosePara);
		<!-- // Insert the div into the page -->
		document.body.insertBefore(newDiv, document.body.firstChild);
		
		var DOMelements = document.getElementsByTagName('*');
		for (var i=0; i<DOMelements.length; i++) {
			if (DOMelements[i].id == 'kps1-test2') {
				//alert(DOMelements[i].style.position);
				//alert(DOMelements[i].style.top);
				//alert(DOMelements[i].style.left);
			}
			if (DOMelements[i].style.position == 'absolute') {
				//alert(DOMelements[i].id);
				//alert(DOMelements[i].style.top);
				//alert(DOMelements[i].style.left);
				DOMelements[i].style.top = '30px';
			}
		}
		
	}
}

window.onload = show_OWC_emergency_banner; 


