
/* Merged Plone Javascript file
 * This file is dynamically assembled from separate parts.
 * Some of these parts have 3rd party licenses or copyright information attached
 * Such information is valid for that section,
 * not for the entire composite file
 * originating files are separated by ----- filename.js -----
 */

/* ----- login.js ----- */
// Functions used by login pages

function cookiesEnabled() {
  // Test whether cookies are enabled by attempting to set a cookie and then change its value
  // set test cookie
  var c = "areYourCookiesEnabled=0";
  document.cookie = c;
  var dc = document.cookie;
  // cookie not set?  fail
  if (dc.indexOf(c) == -1) return 0;
  // change test cookie
  c = "areYourCookiesEnabled=1";
  document.cookie = c;
  dc = document.cookie;
  // cookie not changed?  fail
  if (dc.indexOf(c) == -1) return 0;
  // delete cookie
  document.cookie = "areYourCookiesEnabled=; expires=Thu, 01-Jan-70 00:00:01 GMT";
  return 1;
}

function setLoginVars(user_name_id, alt_user_name_id, password_id, empty_password_id, js_enabled_id, cookies_enabled_id) {
  // Indicate that javascript is enabled, set cookie status, copy username and password length info to 
  // alternative variables since these vars are removed from the request by zope's authentication mechanism.
  if (js_enabled_id) {
    el = document.getElementById(js_enabled_id);
    if (el) { el.value = 1; }
  }
  if (cookies_enabled_id) {
    el = document.getElementById(cookies_enabled_id);
    // Do a fresh cookies enabled test every time we press the login button
    //   so that we are up to date in case the user enables cookies after seeing
    //   the cookies message.
    if (el) { el.value = cookiesEnabled(); } 
  }
  if (user_name_id && alt_user_name_id) {
    user_name = document.getElementById(user_name_id)
    alt_user_name = document.getElementById(alt_user_name_id)
    if (user_name && alt_user_name) {
       alt_user_name.value = user_name.value;
    } 
  }
  if (password_id && empty_password_id) {
    password = document.getElementById(password_id)
    empty_password = document.getElementById(empty_password_id)
    if (password && empty_password) {
       if (password.value.length==0) {
          empty_password.value = '1';
       } else {
          empty_password.value = '0';
       }
    }
  }
  return 1;
}

function showCookieMessage(msg_id) {
  // Show the element with the given id if cookies are not enabled
  msg = document.getElementById(msg_id)
  if (msg) {
     if (cookiesEnabled()) {
        msg.style.display = 'none';
     } else {
        msg.style.display = 'block';
     }
  }
}

function showEnableCookiesMessage() {
  // Show the element with the id 'enable_cookies_message' if cookies are not enabled
  showCookieMessage('enable_cookies_message')
}
// Call showEnableCookiesMessage after the page loads
registerPloneFunction(showEnableCookiesMessage);


/* ----- formsubmithelpers.js ----- */
function inputSubmitOnClick(event) {
    if (!event) var event = window.event; // IE compatibility

    if (hasClassName(this, 'submitting')) {
        return confirm(window.form_resubmit_message);
    } else {
        addClassName(this, 'submitting');
    }
    return true;
}

function registerSubmitHandler() {
    var nodes = cssQuery('input[type=submit]');
    for (var i=0; i<nodes.length; i++) {
        var node = nodes[i];
        if (!node.onclick) {
            node.onclick = inputSubmitOnClick;
        }
    }
}
registerPloneFunction(registerSubmitHandler);


/* ----- bna_onload.js ----- */
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

/* ----- bna_popups.js ----- */
function prepPopUps() {
    var window_width, window_height;
	if (!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName("a");
	for (var i=0; i<links.length; i++) {
        if (links[i].className.match(new RegExp("(^|\\s)(popup|map|figure|photo|data|biblio|video-link|audio-link)(\\s|$)"))) {
            links[i].onclick = setPopUp;
            links[i].onkeypress = links[i].onclick;
        }
    }
}

function setPopUp() {
    var size, width, height, opts;
	if (this.className.match(new RegExp("(^|\\s)(video-link)(\\s|$)"))) {
		var page = this.getAttribute("src") + "?fn=" + this.getAttribute("href");
		width = 440;
		height = 525;
	} 
	else if (this.className.match(new RegExp("(^|\\s)(audio-link)(\\s|$)"))) {
		var page = this.getAttribute("src") + "/media_popup_view?t=audio&fn=" + this.getAttribute("href");
		width = 550;
		height = 750;
	}
	else if (this.className.match(new RegExp("(^|\\s)(biblio)(\\s|$)"))) {
		var path_ary = this.getAttribute("href").split("/");
		var id = path_ary.pop();
		var page = path_ary.join("/") + "/bibref_popup_view?bibref=" + id;
		width = 500;
		height = 200;
	} 
	else if (this.className.match(new RegExp("(^|\\s)(data)(\\s|$)"))) {
		var page = this.getAttribute("href") + "/data_popup_view";
		width = 750;
		height = 750;
	}
	else if (this.className.match(new RegExp("(^|\\s)(popup|map|figure|photo)(\\s|$)"))) {
		var page = this.getAttribute("href") + "/image_popup_view";
        if (this.getAttribute("imgsize")) {
            size = this.getAttribute("imgsize").split(",");
            width = parseInt(size[0]) + 45;
            height = parseInt(size[1]) + 275;
        }
        else {
            width = 600;
            height = 600;
        }
	}
	if (width > screen.availWidth) width = screen.availWidth;
	if (height > screen.availHeight) height = screen.availHeight;
	opts = 'width=' + width + ', height=' + height + ', resizable=1, scrollbars=1, status=0'
	window.open(page, '', opts);
	return false;
}

addLoadEvent(prepPopUps);


/* ----- bna_media_popup_controls.js ----- */
function init() {
    var temp, media_player, args, html, ihtml, file = new Object(), here = new Object();
    media_image = document.getElementById("media-image");
	media_player = document.getElementById("media-player");
    args = getArgs();
    file.path = args["fn"];
    temp = file.path.split("/");
    file.name = temp.pop();
    temp = file.name.split(".");
    file.type = temp.pop();
    //
    here.raw = window.location.href.split("?");
    here.url = here.raw[0].split("/");
    here.url.pop();
    here.thumb = here.url.join("/") + "/thumb_full";
    //
    ihtml = '';
    switch (file.type) {
        case ('mov'):
			html = '<object width="384" height="232" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab">';
			html+= '<param name="SRC" value="' + file.path + '"/>';
			html+= '<param name="AUTOPLAY" value="true"/>';
			html+= '<param name="CONTROLLER" value="true"/>';
			html+= '<param name="KIOSKMODE" value="true"/>';
			html+= '<embed src="' + file.path + '"  width="384" height="232" autoplay="true" controller="true" kioskmode="true" pluginspage="http://www.apple.com/quicktime/download/"></embed>';
			html+= '</object>';
            break;
        case ('rm'):
            html = '<object width="500" height="50" classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA">';
            html+= '<param name="SRC" value="' + file.path + '"/>';
            html+= '<param name="CONSOLE" value="one"/>';
            html+= '<param name="AUTOSTART" value="true"/>';
            html+= '<param name="SRC" value="http://bna.birds.cornell.edu/BNA/audio/TitmouseSong.ram"/>';
            html+= '<embed width="500" height="50" autostart="true" type="audio/x-pn-realaudio-plugin" src="' + file.path + '" console="one"/>';
            html+= '</object>';
            ihtml = '<img src="' + here.thumb + '"/>';
            break;
        case ('wav'):
            html = '<object width="500" height="50" classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA">';
            html+= '<param name="SRC" value="' + file.path + '"/>';
            html+= '<param name="CONSOLE" value="one"/>';
            html+= '<param name="AUTOSTART" value="true"/>';
            html+= '<param name="BACKGROUNDCOLOR" value="white"/>';
            html+= '<embed width="500" height="50" autostart="true" type="audio/x-pn-realaudio-plugin" src="' + file.path + '" console="one"/>';
            html+= '</object>';
            break;
    }
    media_image.innerHTML = ihtml;
	media_player.innerHTML = html;
} // init()

function getArgs() {
	// Query string variables
	var args = new Object();
	var query = location.search.substring(1);
	var pairs = query.split('&');
	for (var i=0; i<pairs.length; i++) {
		var pos = pairs[i].indexOf('=');
		if (pos == -1) continue;
		var argname = pairs[i].substring(0,pos);
		var value = pairs[i].substring(pos+1);
		value = decodeURIComponent(value);
		args[argname] = value;
	}
	return args;
} // getArgs()

addLoadEvent(init);

