function OpenPrintPreview(strOpenMe) {
    features =  'toolbar=no,location=no,directories=no' +
                ',status=no,menubar=yes,' +
                'scrollbars=yes,resizable=yes,' +
                'width=700,height=465' ;

    dlg = window.open (strOpenMe,"",features)
}

function OpenEmailFriend(strOpenMe) {
    features =  'toolbar=no,location=no,directories=no' +
                ',status=no,menubar=no,' +
                'scrollbars=yes,resizable=yes,' +
                'width=530,height=375' ;

    dlg = window.open (strOpenMe,"",features)
}

/*
 * popupUpload - This function pops up a dialog to upload a file.
 *
 *	strUploadType - The valid upload types are specified in 
 *					Popup_FileUpload.php.
 * 
 *	strParams - This parameter is passed to the Popup_FileUpload.php file and
 *				is used there.
 *
 *	valid_extensions - This is a list of valid extensions to accept.
 */
function popupUpload(strUploadType, strParams, valid_extensions)
{
	strOpenMe = "/_header/FileUpload/Popup_FileUpload.php?UploadType=" + strUploadType + "&params=" +  strParams + "&valid_extensions=" + valid_extensions;
	features = "dialogWidth:620px; dialogHeight:484px;resizable: no; help: no; status: no; scroll: no"
	dlg = window.showModalDialog (strOpenMe,"",features)
}
function popupUploadNoNaming(strUploadType, strParams, file_name, valid_extensions)
{
	strOpenMe = "/_header/FileUpload/Popup_FileUpload.php?UploadType=" + strUploadType + "&params=" +  strParams + "&valid_extensions=" + valid_extensions + "&file_name=" + file_name ;
	features = "dialogWidth:561px; dialogHeight:284px;resizable: no; help: no; status: no; scroll: no"
	//window.open(strOpenMe);
	dlg = window.showModalDialog (strOpenMe,"",features)
}
function PopupArtOnDisplay(artwork_id) {
    features =  'toolbar=no,location=no,directories=no' +
                ',status=no,menubar=no,' +
                'scrollbars=yes,resizable=yes,' +
                'width=558,height=550' ;
	strOpenMe = '/ArtOnDisplay/Popup_DisplayArt/index.php?artwork_id=' + artwork_id;
    dlg = window.open (strOpenMe,"",features);
}


if(navigator.appName.indexOf("Microsoft") >= 0)
	attachEvent("onload", pageLoad);
else
	addEventListener("load", pageLoad, false);

/* This is attached to the window.onload event. It will run as soon as the page finishes loading */
function pageLoad() {
	pageLoad.resizeContent();
	pageLoad.windowRollovers();
}

/* Resize the mainArea or sidebar divs to match the one with the largest height */
pageLoad.resizeContent = function() {
	//The homepage has a separate solution for this; cancel
	var isIE6 = (navigator.appVersion.indexOf("MSIE 6") > 0);
	if(document.getElementById("content") && document.getElementById("content").className.indexOf("homepage") >= 0) return;

	var sidebar = document.getElementById("sidebar");
	var main = document.getElementById("mainArea");
	var col1C = document.getElementById("col1_content");
	var col3C = document.getElementById("col3_content");

	if(sidebar == undefined) return;
	if(main == undefined) return;
	if(isIE6)//IE6
	{
		if(sidebar.offsetHeight > main.offsetHeight)
			main.style.height = (sidebar.offsetHeight+4) + "px";
//		else if(sidebar.offsetHeight < main.offsetHeight)
//		alert("offsetTop: " + main.offsetTop + "\noffsetHeight: " + main.offsetHeight);
//			sidebar.style.height = (col1C.offsetHeight) + "px";//mainarea 10px padding
	}
	else
	{
		if(sidebar.offsetHeight > main.offsetHeight)
			main.style.height = (sidebar.offsetHeight) + "px";
	}
}

/* This function attaches rollover events to the header icons */
pageLoad.windowRollovers = function() {
	var ButtonLoc = "/_images/Buttons";
	pageLoad.ButtonLoc = ButtonLoc;

	pageLoad.SearchIcon = document.getElementById("headerSearchIcon");
	pageLoad.Search = document.getElementById("search");
	pageLoad.SearchText = document.getElementById("headerSearchText");
	var RSSIcon = document.getElementById("headerRSS");
	var PrintIcon = document.getElementById("headerPrint");
	var ShareIcon = document.getElementById("headerShare");

	if(!pageLoad.SearchIcon || !pageLoad.Search || !pageLoad.SearchText || !RSSIcon || !PrintIcon || !ShareIcon) return;

	if(navigator.appName.indexOf("Microsoft") >= 0) {
		pageLoad.SearchIcon.attachEvent("onmouseover", function() { pageLoad.searchSection(true); });
		pageLoad.Search.attachEvent("onmouseover", function() { pageLoad.searchSection(true); });
		pageLoad.SearchText.attachEvent("onmouseover", function() { pageLoad.searchSection(true); })
		RSSIcon.attachEvent("onmouseover", function() {	RSSIcon.src = ButtonLoc + "/RSSHover.gif"; });
		PrintIcon.attachEvent("onmouseover", function() {	PrintIcon.src = ButtonLoc + "/printHover.gif"; });
		ShareIcon.attachEvent("onmouseover", function() {	ShareIcon.src = ButtonLoc + "/shareHover.gif"; });

		pageLoad.SearchIcon.attachEvent("onmouseout", function() { pageLoad.searchSection(false); });
		pageLoad.Search.attachEvent("onmouseout", function() { pageLoad.searchSection(false); });
		pageLoad.SearchText.attachEvent("onmouseout", function() { pageLoad.searchSection(false); })
		RSSIcon.attachEvent("onmouseout", function() {	RSSIcon.src = ButtonLoc + "/RSS.gif"; });
		PrintIcon.attachEvent("onmouseout", function() {	PrintIcon.src = ButtonLoc + "/print.gif"; });
		ShareIcon.attachEvent("onmouseout", function() {	ShareIcon.src = ButtonLoc + "/share.gif"; });
	}
	else {
		pageLoad.SearchIcon.addEventListener("mouseover", function() { pageLoad.searchSection(true); }, false);
		pageLoad.Search.addEventListener("mouseover", function() { pageLoad.searchSection(true); }, false);
		pageLoad.SearchText.addEventListener("mouseover", function() { pageLoad.searchSection(true); }, false);
		RSSIcon.addEventListener("mouseover", function() {	RSSIcon.src = ButtonLoc + "/RSSHover.gif"; }, false);
		PrintIcon.addEventListener("mouseover", function() {	PrintIcon.src = ButtonLoc + "/printHover.gif"; }, false);
		ShareIcon.addEventListener("mouseover", function() {	ShareIcon.src = ButtonLoc + "/shareHover.gif"; }, false);

		pageLoad.SearchIcon.addEventListener("mouseout", function() { pageLoad.searchSection(false); }, false);
		pageLoad.Search.addEventListener("mouseout", function() { pageLoad.searchSection(false); }, false);
		pageLoad.SearchText.addEventListener("mouseout", function() { pageLoad.searchSection(false); }, false);
		RSSIcon.addEventListener("mouseout", function() {	RSSIcon.src = ButtonLoc + "/RSS.gif"; }, false);
		PrintIcon.addEventListener("mouseout", function() {	PrintIcon.src = ButtonLoc + "/print.gif"; }, false);
		ShareIcon.addEventListener("mouseout", function() {	ShareIcon.src = ButtonLoc + "/share.gif"; }, false);
	}

	//Preload the hover icons into images
	var RSSHoverIcon = new Image();
	RSSHoverIcon.src = ButtonLoc + "/RSSHover.gif";
	var PrintHoverIcon = new Image();
	PrintHoverIcon.src = ButtonLoc + "/printHover.gif";
	var ShareHoverIcon = new Image();
	ShareHoverIcon.src = ButtonLoc + "/shareHover.gif";

	var SearchIconHover = new Image();
	SearchIconHover.src = ButtonLoc + "/searchHover.gif";
}

pageLoad.searchSection = function(toggle) {
	if(toggle) {
		pageLoad.SearchIcon.getElementsByTagName("img")[0].src = pageLoad.ButtonLoc + "/searchHover.gif";
		pageLoad.SearchText.className = "hover";
	}
	else {
		pageLoad.SearchIcon.getElementsByTagName("img")[0].src = pageLoad.ButtonLoc + "/search.gif";;
		pageLoad.SearchText.className = "";
	}
}

pageLoad.shareClick = function(e) {
	try {
		props = new Object();
		props.title = document.title;
		props.url = document.URL.replace("#","");

		props.icon = "http://" + location.host + "/_images/favicon.png";
               if(console) console.log(props);

		var obj;

		/*if(obj = document.getElementById("GranteeStoryContent"))
			props.content = pageLoad.prepareForSharing(obj);
		else if(obj = document.getElementById("PressReleaseContent"))
			props.content = pageLoad.prepareForSharing(obj);*/

		elems = new Object();
		elems.button = false;
		elems.popup = true;

		SHARETHIS.addEntry(props, elems).popup(e);
	}
	catch(e) {
		if(console.error) console.error(e);
	}
}

pageLoad.prepareForSharing = function(obj) {
	obj = obj.cloneNode(true);

	images = obj.getElementsByTagName("img");

	for(var x = 0; x < images.length; x++) {
		if(images[x].src) {
			images[x].src = images[x].src.replace(/$[^h][^t][^t][^p]/, "http://" + window.location.host + "/" + images[x].src);
			console.log(images[x]);
		}
	}

	//var content = unescape(encodeURIComponent(obj.innerHTML));
	var content = obj.innerHTML;

	return content;
}
