preloadArray('../images/menu/',new Array('home','mycoll','collections','bigsearch','help','about'),new Array('EN','DE','FR','ES'));
  
function preloadArray(dir,array,lang){
	if (document.images){
		for (var i=0; i<array.length; i++){
			CURR_ARRAY_ITEM = array[i];
			for (var j=0;j<lang.length;j++){
				eval(CURR_ARRAY_ITEM+'_'+lang[j]+'_on = new Image()');
				//alert(CURR_ARRAY_ITEM+'_'+lang[j]+'_on.src = dir+"'+CURR_ARRAY_ITEM+'_'+lang[j]+'_on.gif";');
				eval(CURR_ARRAY_ITEM+'_'+lang[j]+'_on.src = dir+"'+CURR_ARRAY_ITEM+'_'+lang[j]+'_on.gif";');
				eval(CURR_ARRAY_ITEM+'_'+lang[j]+'_off = new Image()');
				eval(CURR_ARRAY_ITEM+'_'+lang[j]+'_off.src = dir+"'+CURR_ARRAY_ITEM+'_'+lang[j]+'_off.gif";');
			}
		}
	}
}
 
  
 function test(Module, Moduleid) {
	document.sfq.profile.value=Module;
	document.sfq.moduleid.value=Moduleid;
 }
     
function rollIn(imgName,lang){
	if (document.images){
		document[imgName].src=eval(imgName + "_" + lang + "_on.src");
	}
}

function rollOut(imgName,lang){
	if (document.images){
		document[imgName].src=eval(imgName + "_" + lang + "_off.src");
	}
}

function f_getcookieval(offset){
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function f_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 f_getcookieval (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return '';
}

function f_setcookie (name, value, expires){
	document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString()));
}

function test4Cookies(){
	if (!test4CookieInt()){
		document.getElementById("cookietest").style.visibility='visible';
	}
}

function test4CookieInt(){
	f_setcookie("testcook","1",null)
	if (f_getcookie("testcook")=="1"){
		return true;
	}else{
		return false;;
	}
}

function clearNew(){
	//clear the 'new' values which are used for page navigation
	//(this protects against problems occuring when the user clicks the
	//browser 'back' button)

	//&newvalues=1 flags the beginning of any 'new' state values that get set for navigation
	//Clear out any existing before setting.
	document.frm.action=removeFromUrl(document.frm.action,'newvalues');
}

function linksearch(module,profile, fieldname, fieldvalue, style, searchdesc){
	checkForSelectedMyColls();
	clearNew();
	document.frm.emu_action.value = 'searchrequest';

	//Build the URL-encoded search string
	if (window.encodeURIComponent){
		document.frm.action += '&newvalues=1&rawsearch=' + encodeURIComponent(fieldname) + '/,/is/,/' + encodeURIComponent(fieldvalue) + '/,/false/,/true&newstyle=' + style + '&newprofile=' + profile + '&newsearchdesc=' + encodeURIComponent(searchdesc) + '&newcurrentrecord=1&module='+module;
	}else{
		document.frm.action += '&newvalues=1&rawsearch=' + escape(fieldname) + '/,/is/,/' + escape(fieldvalue) + '/,/false/,/true&newstyle=' + style + '&newprofile=' + profile + '&newsearchdesc=' + escape(searchdesc) + '&newcurrentrecord=1&module='+module;	
	}
	document.frm.submit();
}

function singleview(newpage){
	checkForSelectedMyColls();
	clearNew();
	document.frm.emu_action.value = 'newpage';
	document.frm.action += '&newvalues=1&newstyle=single&newcurrentrecord=' + newpage;
	document.frm.submit();
}

function submitpage(action,para){
	checkForSelectedMyColls();
	clearNew();
	document.frm.emu_action.value = action;
	var cS;
	if (document.frm.action.indexOf("?")==-1){cS='?'}else{cS='&'}
	switch (action){
	case 'newpage' :
		document.frm.action += cS + 'newvalues=1&newcurrentrecord=' + para;
		break
	case 'style' :
		document.frm.action += cS + 'newvalues=1&newstyle=' + para;
		break
	case 'sort' :
		document.frm.action += cS + 'newvalues=1&newcurrentrecord=1&newsortstring=' + para;
		break;
	case 'page' :
		document.frm.emu_action.value = 'newpage';
		document.frm.action += cS + 'newvalues=1&newpage=' + para;
		break;
	case 'profile' :
		document.frm.action += cS + 'newvalues=1&newprofile=' + para;
		break
	default :
		break
	}
	document.frm.submit();
	}

	
function switchprofile(profile){
	checkForSelectedMyColls();
	clearNew();
	document.frm.action=appendOrReplace2Url(document.frm.action,'newprofile',profile);
	document.frm.action=appendOrReplace2Url(document.frm.action,'newvalues','1');
	document.frm.submit();
	}
	
function switchlang(lang){
	checkForSelectedMyColls();
		
	var loc=document.location.href;
	loc=appendOrReplace2Url(loc,'lang',lang);
	loc=appendOrReplace2Url(loc,'profile','');
	loc=appendOrReplace2Url(loc,'newprofile','');
	loc=appendOrReplace2Url(loc,'isnewlang','1');

	document.langswop.sessionid.value=document.frm.sessionid.value;
	document.langswop.searchxml.value=document.frm.searchxml.value;
	document.langswop.module.value=document.frm.module.value;
	document.langswop.moduleid.value=document.frm.moduleid.value;
	document.langswop.action=loc;
	document.langswop.submit();
}

function submitcollection(colname,colid){
	checkForSelectedMyColls();
	clearNew();
	document.frm.emu_action.value = 'collection'
	if (window.encodeURIComponent){
		document.frm.action = 'emuseum.asp?emu_action=collection&collection=' + colid + '&collectionname=' + encodeURIComponent(colname) + '&currentrecord=1&moduleid=1&module=';
	}else{
		document.frm.action = 'emuseum.asp?emu_action=collection&collection=' + colid + '&collectionname=' + escape(colname) + '&currentrecord=1&moduleid=1&module=';
	}
	document.frm.profile.value='';
	document.frm.submit();
}

function submitmycollection(colname,colid,isowner){
	checkForSelectedMyColls();
	clearNew();
	document.frm.emu_action.value = 'mycollection'
	if (window.encodeURIComponent){
		document.frm.action = 'emuseum.asp?emu_action=mycollection&mycollection=' + colid + '&mycollectionname=' + encodeURIComponent(colname) + '&currentrecord=1&isowner='+isowner;
	}else{
		document.frm.action = 'emuseum.asp?emu_action=mycollection&mycollection=' + colid + '&mycollectionname=' + escape(colname) + '&currentrecord=1&isowner='+isowner;
	
	}
  	document.frm.submit();
  	//window.history.back(1);
}

function activatemycollection(colname,colid){
	clearNew();
	document.frm.emu_action.value = 'mycollectionactivate'
	if (window.encodeURIComponent){
		document.frm.action = 'emuseum.asp?emu_action=mycollectionactivate&mycollection=' + colid + '&mycollectionname=' + encodeURIComponent(colname) + '&currentrecord=1';
	}else{
		document.frm.action = 'emuseum.asp?emu_action=mycollectionactivate&mycollection=' + colid + '&mycollectionname=' + escape(colname) + '&currentrecord=1';
	}
  	document.frm.submit();
  	//window.history.back(-1);
}

function addobjects2mycoll(byuser){
	var oidtext='';
	var oids='';
	var otexts='';
	var surl='';
	var objids='';
	var pagesize=document.usercoll.pagesize.value;
	var colid=document.usercoll.currentusercollid.value;
	var colname=document.usercoll.currentusercollid[document.usercoll.currentusercollid.selectedIndex].text;
	var modid=document.usercoll.moduleid.value;
	var lang=document.usercoll.lang.value;
	var selectedIDs=document.frm.cachedmycollitems.value;
	var arr_selectedIDs=selectedIDs.split(",");
	
	if (colid=='' && byuser=='1'){
		alert("Please select a my Collection from the drop down list.");
	}else{
		for (var i=0;i<document.selected4mycoll.elements.length;i++) {
			if (document.selected4mycoll.elements[i].name=='add2mycoll'){
				if(document.selected4mycoll.elements[i].checked==1){
					oidtext=document.selected4mycoll.elements[i].value;
					var j = oidtext.indexOf(":::",0);
					if (j>-1){
						if (!isInCachedMyColls(arr_selectedIDs,modid,oidtext.substring(0,j))){
							oids+=','+modid+'^'+oidtext.substring(0,j);
							otexts+='/,/'+oidtext.substring(j+3);
						}
					}
					if (byuser=='1'){
						document.selected4mycoll.elements[i].checked=0;
					}
				}
			}
		}
		oids=oids.substring(1);
		otexts=otexts.substring(3);
		if (byuser=='1'){
			if (oids!='' || document.frm.cachedmycollitems.value!=''){
				if (window.encodeURIComponent){
					surl='AddObjToColl.asp?byuser=1&lang='+lang+'&objectid=' + oids + '&mycollectionid=' + colid + '&objtext=' + encodeURIComponent(otexts)+'&mycollectionname='+encodeURIComponent(colname);	
				}else{
					surl='AddObjToColl.asp?byuser=1&lang='+lang+'&objectid=' + oids + '&mycollectionid=' + colid + '&objtext=' + escape(otexts)+'&mycollectionname='+escape(colname);	
				}

				openWindow(surl,'Confirmation','width=400,height=300,scrollbars=yes,resizable=no,screenx=200,screeny=200,left=200,top=200,titlebar=0');
				document.frm.cachedmycollitems.value='';
			}
		}else{
			if (oids!=''){
				document.frm.cachedmycollset.value='1';
				document.frm.cachedmycollitems.value=oids;
				document.frm.cachedmycollitemstext.value=otexts;
			}
		}
	}
}

function checkForSelectedMyColls(){
	var anySelected=0;
	if (typeof(document.usercoll)!="undefined"){
		for (var i=0;i<document.selected4mycoll.elements.length;i++) {
			if (document.selected4mycoll.elements[i].name=='add2mycoll'){
				if(document.selected4mycoll.elements[i].checked==1){
					anySelected=1;
				}
			}
		}
		document.frm.currentusercollid.value=document.usercoll.currentusercollid.value;
		if (anySelected==1){
			addobjects2mycoll(0);
		}
	}
}

function checkCachedMyColls(){
	var arr_selectedIDs='';
	if (typeof(document.usercoll)!="undefined"){
		var modid=document.usercoll.moduleid.value;
		arr_selectedIDs=document.frm.cachedmycollitems.value.split(",");
	
		for (var i=0;i<document.selected4mycoll.elements.length;i++) {
			var current=document.selected4mycoll.elements[i].value;
			var j = current.indexOf(":::",0);
			if (j>-1){
				var oid=current.substring(0,j);
				if (isInCachedMyColls(arr_selectedIDs,modid,oid)){
					document.selected4mycoll.elements[i].checked=1;
				}
			}

		}
	}
}

function isInCachedMyColls(arr_selectedIDs,modid,oid){
	var to_return=false;
	for (var k=0;k<arr_selectedIDs.length;k++){
		var singleCached=arr_selectedIDs[k];
		var l=singleCached.indexOf("^",0);
		if (l>-1){
			var smodid=singleCached.substring(0,l);
			var soid=singleCached.substring(l+1);
			if (modid==smodid && soid==oid){
				to_return= true;
			}
		}
	}
	return to_return;
}

function addQSToURL(){
	checkForSelectedMyColls();
	clearNew();
	
	document.frm.action=appendOrReplace2Url(document.frm.action,'quicksearch',document.frm.quicksearch.value);
	
}

function appendOrReplace2Url(sUrl,sKey,sValue){
	sUrl=removeFromUrl(sUrl,sKey);
	if (sValue.length>0){
		var cS;
		if (sUrl.indexOf('?')==-1){
			cS='?';
		}else{
			cS='&';
		}
		return sUrl+cS+sKey+'='+sValue;
	}else{
		return sUrl;
	}
}

function removeFromUrl(sUrl,sKey){
	var i = sUrl.indexOf('?'+sKey+'=');
	if (i==-1){
		i = sUrl.indexOf('&'+sKey+'=');
	}
	if (i>-1){
		var j=sUrl.indexOf('&',i+1);
		if (j==-1){
			return sUrl.substr(0,i);
		}else{
			return sUrl.substr(0,i+1) + sUrl.substr(j+1);
		}
	}else{
		return sUrl;
	}
}

function openWindow(winURL,winName,winFlags){
    var myWindow=window.open(winURL,winName,winFlags);
    if (myWindow!=null){
    	myWindow.focus();
    }
}

function acrobatTest(){
	window.focus();
	if (document.getElementById) {
		if (!acrobat.installed){
			if (document.report.exportformat.value=="pdf"){
				document.getElementById('ppreview').innerHTML='<a href="http://www.adobe.com/products/acrobat/readstep2.html"><img src="../images/get_adobe_reader.gif" width="88" height="31" border="0" name="acrobat" alt="get acrobat reader"/></a>';
			}
		}
	}
}

function showReport(reportname){
	checkForSelectedMyColls();
	document.report.action = 'eMuseum.asp?emu_action=report&report=' + reportname + '&sessionid=' + document.frm.sessionid.value;
	//openWindow('','reportPopup','width=800,height=600,scrollbars=yes,resizable=yes');
	//document.report.submit(); as it submitted twice!
}

function changepage(page,profile){
	checkForSelectedMyColls();
	clearNew();
	document.frm.emu_action.value = 'newpage';
	document.frm.action=appendOrReplace2Url(document.frm.action,'newprofile',profile);
	document.frm.action=appendOrReplace2Url(document.frm.action,'newpage',page);
	document.frm.action=appendOrReplace2Url(document.frm.action,'newvalues','1');
	document.frm.submit();
}

function setMedia(filename,caption,title,lang,zoomify,mediaview){
	//selects a particular media record for enlarging
	document.media.filename.value = filename;
	document.media.caption.value = '';
	document.media.title.value = title;
	document.media.zoomify.value = zoomify;
	document.media.mediaview.value = mediaview;
	spawn('../html/media_enlarged_' + lang + '.html','popup','650','680');
}

function setSingleMedia(filename,caption,title,lang,zoomify,mediaview){
	//selects a particular media record for enlarging
	document.media.filename.value = filename;
	document.media.caption.value = '';
	document.media.title.value = title;
	document.media.zoomify.value = zoomify;
	document.media.mediaview.value = mediaview;
	spawn('../html/media_singleenlarged_' + lang + '.html','popup','650','680');
}

function spawn(url, nameW, w, h){
  	if (navigator.appVersion.indexOf('4') != -1) {
		// Vars for centering the new window on Version 4 Browsers
		x4 = screen.width/2 - (w/2);
		y4 = screen.height/2 - (h/2);
		window.open(url, nameW, 'height='+h+',width='+w+',scrollbars=yes,resizable=0,menubar=0,toolbar=0,status=0,location=0,directories=0,left=' + x4 + ',top=' + y4 + '');
  	}else{
    	window.open(url, nameW, 'height='+h+',width='+w+',scrollbars=yes,resizable=0,menubar=0,toolbar=0,status=0,location=0,directories=0,left=150,top=200');
	}
}

function openImage(imgName,sTitle,sCaption){
	var sHTML = "&lt;html&gt;&lt;head&gt;&lt;title&gt;"+sTitle+"&lt;/title&gt;&lt;link rel='stylesheet' href='../txtStyle.css' type='text/css'/&gt;&lt;/head&gt;&lt;body&gt;&lt;table cellpadding='0' cellspacing='0' border='0' width='100%'&gt;&lt;tr valign='top'&gt;&lt;td class='title'&gt;"+sTitle+"&lt;/td&gt;&lt;td align='right' class='txt'&gt;&lt;a href='javascript:window.close();'&gt;Close&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class='txt'&gt;"+sCaption+"&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br&gt;&lt;img src='getimage.asp?filename="+imgName+"&type=full' width='400' height='400' border='0' alt='"+sTitle+"'&gt;&lt;/body&gt;&lt;/html&gt;";
	var theWindow = "";
	theWindow = window.open("","","height=540,width=540,resizable,scrollbars");
	if(theWindow){
    	theWindow.document.write(sHTML);
    	theWindow.document.close();
  	}
}