if ((navigator.appVersion.indexOf("Mac") != -1)) {
        document.write("<LINK REL=stylesheet HREF=\"/mac.css\" TYPE=\"text/css\">");
} else {
        document.write("<LINK REL=stylesheet HREF=\"/win.css\" TYPE=\"text/css\">");
}

function swapLang(n){
	var loc = window.location.href;
	var lng = "en";
	var rps = "fr";
	if (n == 1) {
		lng = "fr";
		rps = "en";
		loc = loc.replace("/english/", "/francais/");
	} else {
		loc = loc.replace("/francais/", "/english/");
	}

	if (loc.indexOf("languagePref") > 0){
		loc = loc.replace("languagePref="+rps, "languagePref="+lng);
	} else {
		if (loc.indexOf("?") > 0){
			loc += "&languagePref="+lng+"&";
		} else {
			loc += "?languagePref="+lng+"&";
		};
	}
	location.href = loc;
}

function popWin(theURL) {
	var newWin=open(theURL, 'pop', 'height=510,width=510,top=20,left=270,screenY=20,screenX=270,toolbar=no,scrollbars=1,location=0,menu=1');
	newWin.focus();
	
}

function donovanWin(theURL) {
	var newWin=open(theURL, 'pop', 'height=455,width=455,top=20,left=270,screenY=20,screenX=270,toolbar=no,scrollbars=1,location=0,menu=1');
	newWin.focus();
	
}

function auctiont(theURL) {
	var newWin=open(theURL, 'pop', 'height=900,width=450,top=20,left=270,screenY=20,screenX=270,toolbar=no,scrollbars=1,location=0,menu=1');
	newWin.focus();
	
}

function auctionw(theURL) {
	var newWin=open(theURL, 'pop', 'height=450,width=900,top=20,left=270,screenY=20,screenX=270,toolbar=no,scrollbars=1,location=0,menu=1');
	newWin.focus();
	
}

function garnet(theURL) {
	var newWin=open(theURL, 'pop', 'height=72,width=1224,top=20,left=270,screenY=20,screenX=270,toolbar=no,scrollbars=1,location=0,menu=1');
	newWin.focus();
	
}

function rayner(theURL) {
	var newWin=open(theURL, 'pop', 'height=450,width=1300,top=20,left=270,screenY=20,screenX=270,toolbar=no,scrollbars=1,location=0,menu=1');
	newWin.focus();
	
}


function popDetail(kv) {
        var newWin=open('alternate_views.html?mkey='+kv, 'detail', 'height=510,width=560,top=20,left=100,screenY=20,screenX=270,toolbar=no,scrollbars=1,location=0,menu=1');
        newWin.focus();
               
}

function perfWin(theURL) {
	var newWin=open(theURL, 'media', 'height=800,width=860,top=40,left=20,screenY=40,screenX=20,toolbar=1, resizable=1, status=1, scrollbars=auto, scrollbars=1,location=1,menu=1');
	newWin.focus();
}

function isaacsWin(theURL) {
	var newWin=open(theURL, 'media', 'height=570,width=860,top=40,left=20,screenY=40,screenX=20,toolbar=1, resizable=1, status=1, scrollbars=auto, scrollbars=1,location=1,menu=1');
	newWin.focus();
}

function quotWin(theURL) {
	var newWin=open(theURL, 'inuitwin', 'height=300,width=750,top=50,left=55,screenY=50,screenX=55,toolbar=no,scrollbars=1,location=0,menu=1,resizable=1');
	newWin.focus();
	
}
	
	function corbettWin(theURL) {
	var newWin=open(theURL, 'corbettwin', 'height=340,width=730,top=80,left=80,screenY=270,screenX=80,toolbar=no,scrollbars=0,location=0,status=1,menu=1,resizable=1');
	newWin.focus();
	
}

	function corbigWin(theURL) {
	var newWin=open(theURL, 'corbettwin', 'height=566,width=599,top=80,left=80,screenY=270,screenX=80,toolbar=no,scrollbars=0,location=0,status=1,menu=1,resizable=1');
	newWin.focus();
	
}

	function corbigWina(theURL) {
	var newWin=open(theURL, 'corbettwin', 'height=450,width=526,top=80,left=80,screenY=270,screenX=80,toolbar=no,scrollbars=0,location=0,status=1,menu=1,resizable=1');
	newWin.focus();
	
}


function introWin(theURL) {
	var newWin=open(theURL, 'introWin', 'height=580,width=580,top=50,left=55,screenY=50,screenX=55,toolbar=no,scrollbars=1,location=0,menu=1,resizable=1');
	newWin.focus();
	
	}


function introWin2(theURL) {
	var newWin=open(theURL, 'introWin2', 'height=640,width=580,top=50,left=55,screenY=50,screenX=55,toolbar=no,scrollbars=1,location=0,menu=1,resizable=1');
	newWin.focus();


	        
}

function inuitWin(theURL) {
	var newWin=open(theURL, 'inuitwin', 'height=600,width=714,top=0,left=15,screenY=10,screenX=15,toolbar=no,scrollbars=1,location=0,status=1,menu=1,resizable=1');
	newWin.focus();
	
	}
	

function osaWin(theURL) {
	var newWin=open(theURL, 'osawin', 'height=400,width=760,top=0,left=15,screenY=10,screenX=15,toolbar=no,scrollbars=1,location=0,status=1,menu=1,resizable=1');
	newWin.focus();
	
    }
    
function osabigWin(theURL) {
	var newWin=open(theURL, 'osabigwin', 'height=500,width=930,top=0,left=0,screenY=0,screenX=0,toolbar=no,scrollbars=1,location=0,status=1,menu=1,resizable=1');
	newWin.focus();
	
    }

function istWin(theURL) {
	var newWin=open(theURL, 'isttwin', 'height=700,width=1000,top=0,left=15,screenY=10,screenX=15,toolbar=no,scrollbars=1,location=0,menu=1,resizable=1');
	newWin.focus();
}

function bigvideoWin(theURL) {
	var newWin=open(theURL, 'videoWin', 'height=420,width=500,top=20,left=75,screenY=10,screenX=75,toolbar=no,status=1,scrollbars=0,location=0,menu=1,resizable=1');
	newWin.focus();
	
}

function largeVideoWin(theURL) {
	var fPath = theURL;
	if (navigator.plugins.length!=0){
		fPath = fPath.replace("wmv", "mov");
	}
        var newWin=open('/artists/media_large.html?file='+fPath, 'videoWin', 'height=420,width=500,top=20,left=75,screenY=10,screenX=75,toolbar=no,status=1,scrollbars=0,location=0,menu=1,resizable=1');
        newWin.focus();
        
}

function largeVideoMac(theURL) {        
	var newWin=open('/artists/media_large.html?file='+theURL, 'videoWin', 'height=420,width=500,top=20,left=75,screenY=10,screenX=75,toolbar=no,status=1,scrollbars=0,location=0,menu=1,resizable=1');
        newWin.focus();
}

function videoWin(theURL) {
	var newWin=open(theURL, 'videoWin', 'height=284,width=320,top=20,left=25,screenY=10,screenX=15,toolbar=no,status=1,scrollbars=0,location=0,menu=1,resizable=1');
	newWin.focus();
}

function danceWin(theURL) {
	var newWin=open(theURL, 'inuitwin', 'height=200,width=610,top=0,left=15,screenY=10,screenX=15,toolbar=no,scrollbars=1,location=0,menu=1,resizable=1');
	newWin.focus();
     }

function inuitWinshort(theURL) {
	var newWin=open(theURL, 'inuitwinshort', 'height=500,width=900,top=0,left=15,screenY=10,screenX=15,toolbar=no,scrollbars=1,location=0,menu=1,resizable=1');
	newWin.focus();
}

function mainWin(theURL) {
        var newWin=open(theURL, 'body', 'toolbar=1,scrollbars=1,location=0,status=1, menu=1,resizable=1');
        newWin.focus();
}

function footWin(theURL) {
	var newWin=open(theURL, 'foot', 'height=400,width=600,top=400,left=350,screenY=400,screenX=350,toolbar=no,scrollbars=1,location=0,menu=0,resizable=1');
	newWin.focus();
}

function footbigWin(theURL) {
	var newWin=open(theURL, 'footwin', 'height=450,width=500,top=400,left=350,screenY=400,screenX=350,toolbar=no,scrollbars=1,location=0,menu=1,resizable=1');
	newWin.focus();
	
}

function mediaWin(theURL) {
	var newWin=open(theURL, 'media', 'height=550,width=760,top=40,left=20,screenY=40,screenX=20,toolbar=1,resizable=1,status=1,scrollbars=auto,location=1,menu=1');
	newWin.focus();
}

function newWindow(note) {
	leftPos = 0
	if (screen){
		leftPos = screen.width /2-250
	}
        noteWindow = window.open(note,"noteWin","width=500,height=550,left="+leftPos+",top=40,scrollbars=yes,resizable")
}


function popHelp(theURL, inWd, inHt) {
	var winStr='scrollbars=no,resizable=yes,width=' + inWd + ',height=' + inHt + ',titlebar=no,status=no,location=no,toolbar=no';
	var newWin=open(theURL,'help',winStr);
	newWin.focus();
}

function showList(lName, langVal) {
		var newWin=open('/searchList.html?list=' + lName + '&languagePref=' + langVal, 'list', 'resizable=no,titlebar=0,status=no,location=no,toolbar=no,scrollbars=yes,width=350,height=350,screenX=270,screenY=20,left=270,top=20');
}

function pickValue(theValue, theField) {
	if (theField=="category" || theField=="event category") {
		var oldVal=opener.document.forms[0].qcategory.value;
			opener.document.forms[0].qcategory.value = theValue;
	}
	if (theField=="collection") {
                var oldVal=opener.document.forms[0].qcollection.value;
                        opener.document.forms[0].qcollection.value = theValue;
        }
	if (theField=="residence") {
                var oldVal=opener.document.forms[0].qresidence.value;
                        opener.document.forms[0].qresidence.value = theValue;
        }
	self.close();
}
function clearSearch(){
	window.document.forms[0].artist.value="";
	window.document.forms[0].qresidence.value="";
        window.document.forms[0].qcategory.value="";
        window.document.forms[0].qtitle.value="";
        window.document.forms[0].qcollection.value="";
        window.document.forms[0].qdate.value="";
        window.document.forms[0].materials.value="";
        window.document.forms[0].description.value="";
}

function clearForm(frm){
	for (i=0; i<frm.elements.length; i++){
		if (frm.elements[i].type=="text"){
			frm.elements[i].value = "";
		} else if (frm.elements[i].type=="select-one"){
			frm.elements[i].options[0].selected = true;
		};
	}
}

function sortBibSearch(sorder){
	window.document.forms[0].sortby.value=sorder;
	window.document.forms[0].submit();
}

function sortChronSearch(sorder){
        window.document.forms[0].sortby.value=sorder;
        window.document.forms[0].submit();
}

function newPage(startWith, ttlRecs) {
	window.document.forms[0].startRec.value=startWith;
       	window.document.forms[0].recordsFound.value=ttlRecs;
       	window.document.forms[0].submit();
}

function maxSize(){
	if (navigator.appName=="Netscape"){
		var x = window.innerWidth;
		var y = window.innerHeight;
	} else {
		var x = document.body.clientWidth;
		var y = document.body.clientHeight;
	}
	if (x < y) {
		return x;
	} else {
		return y;
	}
}

function playVideo(){
	var vid = document.getElementById("vidLayer");
	var d = vid.style.display;
	var b = document.getElementById("btns").style.display;
	if (d == "none"){
		vid.style.display = "block";
		document.getElementById("imgLayer").style.display = "none";
	} else {
		document.getElementById("MediaPlayer1").Play();
	};
	if (b == "none"){
		document.getElementById("quickStart").style.display = "none";
		document.getElementById("quickStop").style.display = "block";
	} else {
		document.playBtn.src="/images/play_lo.gif";
		document.pauseBtn.src="/images/pause.gif";
		document.stopBtn.src="/images/stop.gif";
	};
}

function pauseVideo(){
	var obj = document.getElementById("MediaPlayer1");
	obj.Pause();
	document.playBtn.src="/images/play.gif";
	document.pauseBtn.src="/images/pause_lo.gif";
}

function stopVideo(){
	var obj = document.getElementById("MediaPlayer1");
	var b = document.getElementById("btns").style.display;
	document.getElementById("vidLayer").style.display = "none";
	document.getElementById("imgLayer").style.display = "block";
	if (b == "none"){
		document.getElementById("quickStart").style.display = "block";
                document.getElementById("quickStop").style.display = "none";
	} else {
		document.playBtn.src="/images/play.gif";
		document.pauseBtn.src="/images/pause_lo.gif";
		document.stopBtn.src = "/images/stop_lo.gif";
	};
        obj.Stop();
}

function checkVideoType(fname){
	if (navigator.plugins.length==0){
		document.write('<EMBED SRC="' + fname + '" ID="MediaPlayer1" ' +
		'TYPE="video/quicktime" width="320" height="240" LOOP="false" AUTOSTART="true" ' + 
		'ShowControls="false" ShowTracker="false"></EMBED>');
	} else {
		document.write('<EMBED SRC="' + fname.replace("wmv", "mov") + '" ID="MediaPlayer1" ' +
                'TYPE="video/quicktime" width="320" height="240" LOOP="false" AUTOSTART="true" ' + 
                'CONTROLS=false></EMBED>');
		document.getElementById("btns").style.display = "none";
		document.getElementById("quickStart").style.display = "block";
	};
}

function sendFeedback(){
	document.location = "mailto:kir" + "by@ccc" + "a.ca";
}

/*
 * This is the function that actually highlights a text string by
 * adding HTML tags before and after all occurrences of the search
 * term. You can pass your own tags if you'd like, or if the
 * highlightStartTag or highlightEndTag parameters are omitted or
 * are empty strings then the default <font> tags will be used.
 */
function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
{
  // the highlightStartTag and highlightEndTag parameters are optional
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<font style='color:white; background-color:#3f5f77;'>";
    highlightEndTag = "</font>";
  }
  
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
    
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
        }
      }
    }
  }
  
  return newText;
}


/*
 * This is sort of a wrapper function to the doHighlight function.
 * It takes the searchText that you pass, optionally splits it into
 * separate words, and transforms the text on the current web page.
 * Only the "searchText" parameter is required; all other parameters
 * are optional and can be omitted.
 */
function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
{
  // if the treatAsPhrase parameter is true, then we should search for 
  // the entire phrase that was entered; otherwise, we will split the
  // search string so that each word is searched for and highlighted
  // individually
  if (treatAsPhrase) {
    searchArray = [searchText];
  } else {
    searchArray = searchText.split("^");
  }
  
  if (!document.body || typeof(document.body.innerHTML) == "undefined") {
    if (warnOnFailure) {
      alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
    }
    return false;
  }
  
  var bodyText = document.body.innerHTML;
  for (var i = 0; i < searchArray.length; i++) {
    bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
  }
  
  document.body.innerHTML = bodyText;
  return true;
}

/* This function loads the appropriate player into a SPAN with the ID of thePalyer*/
function loadPlayer(fname,sz){
	var wd = 320;
	var ht = 255;
	if (sz == 5){
		fname = fname+'5';
		wd=500;
		ht=420;
	};

        var nm = fname+'.wmv';

        if (navigator.appVersion.indexOf("Mac") != -1) {
                nm =  fname+'.mov';
        };

        document.getElementById("thePlayer").innerHTML='<object id="video" width="'+wd+'" height="'+ht+'" border="0" classid="CLSID:05589FA1-C356-11CE-BF01-00AA0055595A"><param name="ShowDisplay" value="0"><param name="ShowControls" value="1"><param name="AutoStart" value="1"><param name="AutoRewind" value="0"><param name="PlayCount" value="0"><param name="Appearance" value="0"><param name="BorderStyle" value="0"><param name="MovieWindowHeight" value="'+ht+'"><param name="MovieWindowWidth" value="'+wd+'"><param name="FileName" value="'+nm+'"><embed src="'+nm+'" type="video/x-msvideo" width="'+wd+'" height="'+ht+'" loop="true" autostart="true" controls="true"></embed></object>';
}
