
/*This function opens a new window with minimal controls, specified width and maximum height needed. It is centered vertically and horizontally, and if the specified max width and max height will not fit, the window is set to fit comfortably on the screen with scrollbars. */

function openWindow (windContent,windName,maxWidth,maxHeight) {
	leftPos = 10
	topPos = 10
	windWidth = 500
	windHeight = 400
	if (screen) {
		if (maxWidth > (screen.width-20)) {
			windWidth = screen.width-20
		} else {
			windWidth = maxWidth
		}
		leftPos = (screen.width-windWidth)/2
		if (maxHeight > (screen.height-100)) {
			windHeight = screen.height-100
		} else {
			windHeight = maxHeight
		}
		topPos = ((screen.height-windHeight)/2)-40
	}
	newWindow = window.open(windContent,windName,"toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+windWidth+",height="+windHeight+",left="+leftPos+",top="+topPos+"") 
}
				

/*This function is the same as openWindow, except it includes a menubar */				
function openMenuWindow (windContent,windName,maxWidth,maxHeight) {
	leftPos = 10
	topPos = 10
	windWidth = 500
	windHeight = 400
	if (screen) {
		if (maxWidth > (screen.width-20)) {
			windWidth = screen.width-20
		} else {
			windWidth = maxWidth
		}
		leftPos = (screen.width-windWidth)/2
		if (maxHeight > (screen.height-150)) {
			windHeight = screen.height-150
		} else {
			windHeight = maxHeight
		}
		topPos = ((screen.height-windHeight)/2)-60
	}
	newWindow = window.open(windContent,windName,"toolbar=no,location=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,width="+windWidth+",height="+windHeight+",left="+leftPos+",top="+topPos+"") 
}

/*This function is the same as openWindow, except it includes full controls */				
function openFullWindow (windContent,windName,maxWidth,maxHeight) {
	leftPos = 10
	topPos = 10
	windWidth = 500
	windHeight = 400
	if (screen) {
		if (maxWidth > (screen.width-20)) {
			windWidth = screen.width-20
		} else {
			windWidth = maxWidth
		}
		leftPos = (screen.width-windWidth)/2
		if (maxHeight > (screen.height-220)) {
			windHeight = screen.height-220
		} else {
			windHeight = maxHeight
		}
		topPos = ((screen.height-windHeight)/2)-120
	}
	newWindow = window.open(windContent,windName,"toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width="+windWidth+",height="+windHeight+",left="+leftPos+",top="+topPos+"") 
}

 

// Sets a new cookie with desired name, value and number of months to expiry, valid for any path within the domain
 function setCookie(cookieName, cookieValue, noMonths) {
	expireDate = new Date  //get current date
	expireDate.setMonth(expireDate.getMonth()+noMonths)  //add desired number of months
	document.cookie = cookieName + "=" + (cookieValue)+ "; expires=" + expireDate.toGMTString() + "; path = /"
 }

// Returns value of named cookie, or "none" if cookie does not exist.
function getCookie(cookieName){
	if (document.cookie == "") {
		return "none"
	} else {
		cookieList = document.cookie.split("; ") // Get array of cookies
		for (i=0; i<cookieList.length; i++) {
			if (cookieName == cookieList[i].split("=")[0]){
				cookieValue = cookieList[i].split("=")[1]
				return cookieValue
			}
		}
		return "none"
	}
}