/*
Copyright © 2001 Canadian Heritage Information Network

Virtual Museum of Canada Community Memories JavaScript Functions

Last Updated: Aug 28, 2003.

This Javascript source file is included in this specific landmark.
*/

//COMMUNITY MEMORIES JAVASCRIPT

function openwindow(pageToOpen)
{
cmWindow = window.open(pageToOpen,"CM_Window_2","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=400,height=400")
}

function Get_CMTerms() {

	var myUrl = document.URL;
	if (myUrl.indexOf('PM.cgi') != -1) {
		var myTerms = "";
		var myCookie = document.cookie;
		if (myCookie == "") return false;
		var pos = myCookie.indexOf("lastVMCLocation=");
		if (pos == -1) return false;
		var start = pos + 16;
		var end = myCookie.indexOf(";", start);
		if (end == -1) end = myCookie.length;
		var cookieString = unescape(myCookie.substring(start, end));
		var names = cookieString.split('&');
		for (var i = 0; i < names.length; i++) {
			names[i] = names[i].split('=');
			if (names[i][0] == "cmTerms") {
				var myTerms = unescape(names[i][1]);
			}
		}
		myTerms = myTerms.replace(/\+/g, ' ');
		document.CMSEARCHFORM.cmTerms.value = myTerms;
	}
}

function doCMSearch (language, tab, checkTerms, formtype) {
	i = 8;
	options = 0;
	selectionsmade = 0;
	
        if (checkTerms == 'YES') {
		if (formtype == 'Simple') {
	                if (document.CMSEARCHFORM.cmTerms.value == "") {
	                        if (language == 'Francais') {
	                                alert("Vous devez préciser des critères de recherche");
	                        } else {
	                                alert("Search criteria must be entered");
	                        }
	                        return false;
			}
		} else {
			while (document.CMSEARCHFORM.elements[i]) {
				if(document.CMSEARCHFORM.elements[i].type != "select-one") { break; }
					options = document.CMSEARCHFORM.elements[i].length;
					if ((document.CMSEARCHFORM.elements[i].selectedIndex != 0) && (document.CMSEARCHFORM.elements[i].selectedIndex != (options -1))) {
						selectionsmade = 1;
						break;
					}
					i++;
			}
			if ((document.CMSEARCHFORM.cmTerms.value == "") && (selectionsmade == 0)){
				if (language == 'English') {
	                                alert("Search criteria must be entered");
				} else {
	                                alert("Vous devez préciser des critères de recherche");
				}
				return false;
			}
                }
        }        
        document.CMSEARCHFORM.tab.value = tab;
        document.CMSEARCHFORM.formtype.value = formtype;
        document.CMSEARCHFORM.submit();
        return;
}

function doCMTabChange (language, tab, formtype) {
	document.CMSEARCHFORM.action.value = "";
        document.CMSEARCHFORM.tab.value = tab;
        document.CMSEARCHFORM.formtype.value = formtype;
        document.CMSEARCHFORM.submit();
        return;
}

function doCMClear (d) {
        d.CMSEARCHFORM.reset();
}

function setVersion() {

	if (document.CMform.radiobutton[0].checked) {
//		HTML version selected
//		document.cookie = 'CMflash=' + '0; domain=.virtualmuseum.ca; path=/';	
		document.cookie = 'CMflash=' + '0; path=/';	
	}

	if (document.CMform.radiobutton[1].checked) {
//		FLASH version selected
//		document.cookie = 'CMflash=' + '1; domain=.virtualmuseum.ca; path=/';
		document.cookie = 'CMflash=' + '1; path=/';
	}
	return true;
}

function setVersionFR() {

	if (document.CMform.radiobutton[0].checked) {
//		HTML version selected
//		document.cookie = 'CMflash=' + '0; domain=.museevirtuel.ca; path=/';	
		document.cookie = 'CMflash=' + '0; path=/';	
	}

	if (document.CMform.radiobutton[1].checked) {
//		FLASH version selected
//		document.cookie = 'CMflash=' + '1; domain=.museevirtuel.ca; path=/';
		document.cookie = 'CMflash=' + '1; path=/';
	}
	return true;
}


function detectingFLASH() {
	var browser = navigator.userAgent.toLowerCase();

  flashVersion = 0;
	// NS3+, Opera3+, IE5+ Mac
	if ( navigator.plugins != null && navigator.plugins.length > 0 ) {
		var flashPlugin = navigator.plugins['Shockwave Flash'];
		if ( typeof flashPlugin == 'object' ) {
			if ( flashPlugin.description.indexOf('7.') != -1 ) flashVersion = 7;
			else if ( flashPlugin.description.indexOf('6.') != -1 ) flashVersion = 6;
			else if ( flashPlugin.description.indexOf('5.') != -1 ) flashVersion = 5;
			else if ( flashPlugin.description.indexOf('4.') != -1 ) flashVersion = 4;
			else if ( flashPlugin.description.indexOf('3.') != -1 ) flashVersion = 3;
		}
	} // IE4+ Win32 (VBscript)
	else if ( browser.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && browser.indexOf("win")!= -1 && browser.indexOf("16bit")== -1 ) {
	  document.write('<scr' + 'ipt language="VBScript"\> \n');
		document.write('on error resume next \n');
		document.write('DIM obFlash \n');
		document.write('SET obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.7") \n');
		document.write('IF IsObject(obFlash) THEN \n');
		document.write('flashVersion = 7 \n');
		document.write('ELSE SET obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.6") END IF \n');
		document.write('IF flashVersion < 7 and IsObject(obFlash) THEN \n');
		document.write('flashVersion = 6 \n');
		document.write('ELSE SET obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.5") END IF \n');
		document.write('IF flashVersion < 6 and IsObject(obFlash) THEN \n');
		document.write('flashVersion = 5 \n');
		document.write('ELSE SET obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.4") END IF \n');
		document.write('IF flashVersion < 5 and IsObject(obFlash) THEN \n');
		document.write('flashVersion = 4 \n');
		document.write('ELSE SET obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.3") END IF \n');
		document.write('IF flashVersion < 4 and IsObject(obFlash) THEN \n');
		document.write('flashVersion = 3 \n');
		document.write('END IF');
	  document.write('</scr' + 'ipt\> \n');
	  
	  
  } // no Flash
  else {
	flashVersion = -1;
  }
return flashVersion;


}


function languageSwitch () {
	
	alert(cookieVersion);

}


function getVersionFromCookie() {

	cookieVersion = -1;
	var myCookie = document.cookie;
	if (myCookie == "") return cookieVersion;
	var pos = myCookie.indexOf("CMflash=");
	if (pos == -1) return cookieVersion;
	var start = pos + 8;
	var end = myCookie.indexOf(";", start);
	if (end == -1) end = myCookie.length;
	var cookieString = unescape(myCookie.substring(start, end));
	if (cookieString == '0') {
		cookieVersion = 0;
	}
	if (cookieString == '1') {
		cookieVersion = 1;
	}
return cookieVersion;
}




function myfunction()
{
if (flashVersion >= 6)
	{
	}
else
	{
		flashWindow = window.open('flash.html', 'flashWindow', 'width=400,height=150,toolbar=no,location=no,scrollbars=no,resizable=yes');
		document.CMform.radiobutton[1].checked = false;
		document.CMform.radiobutton[0].checked = true;
	}
}


function vmcAuxCM(cmURL)

{
// var serv=window.open(cmURL,'cmWindow','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes')
var serv=window.open(cmURL,'VMCAux','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes')
}

function vmcAuxCMFlash(cmURL)

{
// var serv=window.open(cmURL,'cmWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=yes,width=775,height=581')
var serv=window.open(cmURL,'VMCAux','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=yes,width=775,height=581')
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}



