function toggleDiv(divid){
	if(document.getElementById(divid).style.display == 'none'){
		document.getElementById(divid).style.display = 'block';
	}else{
		document.getElementById(divid).style.display = 'none';
	}
}

//automatically submit form when user presses enter.
//taken from: http://www.htmlcodetutorial.com/forms/index_famsupp_157.html
function submitenter(myfield,e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13) {
	   myfield.form.submit();
	   return false;
	}
	else
	   return true;
}

//this is used by artistblog.asp
//width and height are optional and set the size of the pop up window.
//scrollbars is optional and is 1 for scrollbars, 0 for none. 0 is default.
function popUp(URL, width, height, scrollbars) {
	if (width == undefined)
		width = 400;
	if (height == undefined)
		height = 550;
	if (scrollbars == undefined)
		scrollbars = 0;

	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=" + scrollbars + ",location=0,statusbar=0,menubar=0,resizable=1,width=" + width + ",height=" + height + ",left = 520,top = 150');");
}

//This function hides email addresses in mailto: links to keep 
//your precious email address out of the hands of evil spammers.
function mailit(user, domain) {
    var email = "mailto:" + user + "@" + domain;
    location.href = email;
}

//loads the specified page into the element with id 'what_is'
var whatIsLoaded = false;
function loadWhatIs(url) {
	var pars = "";
	if (!whatIsLoaded) {
		var myAjax = new Ajax.Request( url, { method: 'get', parameters: pars, onComplete: showWhatIs });
	}
}
function showWhatIs(originalRequest) { 
	$('what_is').innerHTML = originalRequest.responseText;
	
	whatIsLoaded = true;
}

//shows the popup layer div with id id right below the mouse.
function showPopup(id) {
	div = document.getElementById(id);

	div.style.visibility = 'visible';
}

//hides the popup layer div with id id
function hidePopup(id) {
	div = document.getElementById(id);
	
	div.style.visibility = 'hidden';
}

function togglePopup(id) {
	div = document.getElementById(id);
	if (div.style.visibility == 'hidden')
		showPopup(id);
	else
		hidePopup(id);
}

////////////////////////////////////////////
//			Image Swapping Routines       //
////////////////////////////////////////////

//this changes the CSS border definition of the element div to borderDef.
function thumbSwap(div, borderDef){
	div.style.border = borderDef;
}  

//this handles thumbnail highlighting.
//div is the parent class of the whole thumbnail (tinythumb_image_letterbox)
function highlight(div) {
	thumbSwap(div, '1px solid #DB1A83');
	
	//find corner images and swap them to be pink ones.
	spans = div.getElementsByTagName("span");
	for (i = 0; i < spans.length; i++) {
		var span = spans[i];
			
		
		if (span.className == "corner_border_top")
			span.className = "corner_border_top_over";
			
		if (span.className == "corner_border_bottom") {
			span.className = "corner_border_bottom_over";
		}	
	}
}

//this handles thumbnail unhighlighting.
//div is the parent class of the whole thumbnail (tinythumb_image_letterbox)
function lowlight(div) {
	thumbSwap(div, '1px solid #CECECE');
	
	//find corner images and swap them to be pink ones.
	spans = div.getElementsByTagName("span");
	for (i = 0; i < spans.length; i++) {
		span = spans[i];
		
		if (span.className == "corner_border_top_over")
			span.className = "corner_border_top";
			
		if (span.className == "corner_border_bottom_over")
			span.className = "corner_border_bottom";		
	}
}

//this swaps the big main image for a new one specified by url.
function replaceMainImage(url, width, height) {
	replaceMainImageWBig(url, url, width, height);
}
//helper function for replaceMainImage
//this swaps the big main image for a new one specified by url, and sets up the zoomer correctly.
function replaceMainImageWBig(url, bigUrl, width, height) {
	newHTML = "<img id='mainImage' alt='main image' src='" + url + "' width='" + width + "' height='" + height + "' />";

	mainImg = document.getElementById("mainImage");
	
	mainImg.parentNode.innerHTML = newHTML;
	
	//now replace the zoom link
	zoomer = document.getElementById("zoomLink");
	zoomer.href = bigUrl;
}

//this is specifically for swapping out tombstone info in in_depth.asp 
function swapTombstone(artist, title, materials, link, objectNumber) {
	if (document.getElementById('tombstone')) {
		$('tombstoneName').innerHTML = artist;
		$('tombstoneTitle').innerHTML = title;
		$('tombstoneMaterials').innerHTML = materials;
		$('tombstoneLink').innerHTML = "<a href='" + link + "'>Main Object Record &gt;</a>";

		if (typeof(window['inDepthEssays']) != "undefined" && inDepthEssays[objectNumber])
			$('tombstoneEssay').innerHTML = inDepthEssays[objectNumber];
		else
			$('tombstoneEssay').innerHTML = "";
	}
}

