function go(selector_id) {
   box = $(selector_id);
   destination = box.options[box.selectedIndex].value;
   if (destination) location.href = destination;
}

function openWin(url) {
   var helpWin = window.open(url,"helpWin","statusbar,menubar,height=500,width=400,resizable,scrollbars=auto");
   helpWin.focus();
}

function popPlayer(url) {
   var playerWin = window.open(url,"playerWin","statusbar,menubar,height=310,width=270,resizable,scrollbars=no");
   playerWin.focus();
}


function repositionCaldetail(vOffset) {

	var caldetailHeightOffset = $('caldetail').viewportOffset()[1];
	var caldetailCumScrollOffset = $('caldetail').cumulativeScrollOffset()[1];
	
	// console.log("caldetailHeightOffset:", caldetailHeightOffset);
	// console.log("document viewport height:", document.viewport.getHeight());
	// console.log("caldetail viewport offset:", $('caldetail').viewportOffset());
	// console.log("caldetail viewport offset height:", $('caldetail').viewportOffset()[1]);
	// console.log("caldetail cumulative scroll offset:", $('caldetail').cumulativeScrollOffset());
	// console.log("caldetail cumulative scroll offset height:", caldetailCumScrollOffset);
	// console.log(" ");

	if (caldetailHeightOffset < 0) {
		// console.log("less than 0");
		var calculatedMargin = caldetailCumScrollOffset - vOffset;
		// console.log("calculatedMargin", calculatedMargin);

		if (calculatedMargin > 0) { 
			// console.log("calculatedMargin > 0");
			marginPx = calculatedMargin + 'px';
			Element.setStyle('caldetail', { position: 'relative', top: marginPx });
		} else {
			// console.log("calculatedMargin < 0");
			Element.setStyle('caldetail', { position: 'relative', top: '0px' });
		}

	} else {
		// console.log("not less than 0")
		Element.setStyle('caldetail', { position: 'relative', top: '0px' });
	}

}

/* cookie functions, used to tell the user to update their browser 
 * modified from public domain functions found at http://www.hidaho.com/cookies/
 */

// 'internal' function used by the other cookie functions
function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

//  Function to return the value of the cookie specified by "name".
//    name - String object containing the cookie name.
//    returns - String object containing the cookie value, or null if
//      the cookie does not exist.
//
function getCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

// sets a cookie. 
function setCookie (name,value,expires,path,domain,secure) {
	document.cookie = name + "=" + escape (value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}

// delete the cookie
function deleteCookie (name,path,domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}
