// JavaScript Document
// EMS 02.07.05

// function to encode mailto links
function safe_mailto(username,domain,text) {
	//var domain = ".berkeley.edu";
	var atsign = "&#64;";
	var addr = username + atsign + domain;
	if (!text) {
		var text = addr;
	}
	document.write( 
		"<" + "a" + " " + "h" + "r" + "e" + "f" + "=" + "m" + "a" + "i" + "l" + "t" + "o" + ":" + addr + ">" +
		text +
		"<\/a>");
}



// http://demo.1976design.com/image-captions/
function extractImageTitles()
{
	images = document.getElementsByTagName('img');
	for (var i = 0; i < images.length; i++)
	{
		var title = images[i].getAttribute('title');
		if ((title) && (title != ''))
		{
			var imagewidth = images[i].width;
			//alert(imagewidth);
			
			if (title.match('http://', 'i'))
			{
				newlink = document.createElement('a');
				newlink.setAttribute('href', title);
				newlink.setAttribute('title', ('Go to ' + title));
				newlink.appendChild(document.createTextNode('Image source'));
				var newdiv = document.createElement('div');
				newdiv.className = 'caption';
				
				var newdivstyle = newdiv.style;
				newdivstyle.width = imagewidth+10;
				
				newdiv.appendChild(newlink);
				images[i].parentNode.appendChild(newdiv);
				images[i].removeAttribute('title');
			}
			else
			{
				var newdiv = document.createElement('div');
				newdiv.className = 'caption';
				
				var newdivstyle = newdiv.style;
				newdivstyle.width = imagewidth+10;
				
				newdivstyle.border = "1px solid #000000";
				newdiv.appendChild(document.createTextNode(title));
				images[i].parentNode.appendChild(newdiv);
				images[i].removeAttribute('title');
			}
		}
	}
}


function openPopup(URL, name, ww, hh) {
	var xcoord, ycoord, popWidth, popHeight, popName;
	
	if(name != null) {
		popName = name;
	}
	else {
		popName = "popup";
	}
	
	if(ww != null) {
		popWidth = ww;
	}
	else {
		popWidth = 720;
	}
	
	if(hh != null) {
		popHeight = hh;
	}
	else {
		popHeight = 520;
	}
	
	if(document.getElementById) {
		xcoord = Math.round((screen.availWidth - popWidth) / 2);
		ycoord = Math.round((screen.availHeight - popHeight) / 2);
	}
	
    myPopup = window.open(URL,popName,'width=' + popWidth + ',height=' + popHeight + ',left=' + xcoord + ',top=' + ycoord + ',directories=no,menubar=yesn,status=no,resizable=1,scrollbars=yes');
    if (!myPopup.opener) {
         myPopup.opener = self;
	}
	
	myPopup.focus();
}


//function to pop up context sensitive help...
function showhelp(help_page) {
	var help_url = "http://www.indiana.edu/~inlet/hints/";
	var full_help_url = help_url + help_page;
	
	openPopup(full_help_url, "help", 500, 400);
}
