//  © 2002 Canadian Heritage Information Network/R&eacute;seau canadien
//  d'information sur le patrimoine
//  All rights reserved./Tous droits r&eacute;serv&eacute;s.

/*
/// OLD - Writing Power outage message.....


document.write('<span style="display:block;background-color:#5890A8;width:610px; padding: 5px; font-family: Arial; font-size: 10px; font-weight: bold;">L\'accès au site sera interrompu pour fin d\'entretien de samedi le 18 novembre à 8h00, à dimanche le 19 novembre à 20h00 (HNE)</span>');

*/

/// NEW - Writing power outage message.....
// call init() when the DOM is loaded
// onDomLoadEvent(init);
function writeOutageMessage() {
	var message = "L'accès au site sera interrompu de façon intermittente à des fins d'entretien ce samedi 1 novembre 2008 de 7 h  à 12 h (HAE).";
//	var message = "Due à des difficultés techniques, le site Agora n'est pas disponibles pour l'instant.  Nous sommes désolés des inconvénients et nous travaillons à rétablir la situation.";
	if (!document.createElement || !document.appendChild || !document.insertBefore) return;
	var messageElement = document.createElement("div");
	var subEl = document.createElement("strong");
	subEl.appendChild(document.createTextNode("Notez : "));
	messageElement.appendChild(subEl);
	messageElement.appendChild(document.createTextNode(message));
	messageElement.id = "powerOutage";
	messageElement.style.fontFamily="arial,sans-serif";
	messageElement.style.fontSize="0.75em";
	messageElement.style.fontWeight="normal";
	messageElement.style.color="#000";
	messageElement.style.backgroundColor="#5890a8";
	messageElement.style.width="595px";
	messageElement.style.padding="5px";
	document.body.insertBefore(messageElement, document.body.firstChild);

}

// add all the functions you want fired once the DOM loads, and before window.onload
function init() {
	// prevent this function from being called twice
	if (arguments.callee.done) return;
	arguments.callee.done = true;
	
	//do stuff  -  in this case, just write the Power Outage Message
	writeOutageMessage();
}

	
// onDomLoadEvent adapted from Dean Edwards/Matthias Miller/John Resig: http://dean.edwards.name/weblog/2006/06/again/?full
// Author: J. Kiss, CHIN, Dec. 08, 2006
// ====================================
function onDomLoadEvent(func){
	/*@cc_on @*/
	/*@if (@_win32)
		var protoc = "src=javascript:void(0)";
		if (location.protocol == "https:") protoc = "src=//0";
	    document.write("<script id=__ie_onload defer " + protoc + "><\/script>");
	    var script = document.getElementById("__ie_onload");
	    script.onreadystatechange = function() {
			if (this.readyState == "complete") {
				func(); // call the function
				//script=null;
			}
	    };
	    return;
	/*@end @*/
	if (/WebKit|KHTML/i.test(navigator.userAgent)) { 
	    var _timer = setInterval(function() {
			if (/loaded|complete/.test(document.readyState)) {
				func();
				clearInterval(_timer);
				delete _timer;
			}
		}, 10);
		return;
	} else if (document.addEventListener) { 
	    document.addEventListener("DOMContentLoaded", func, false);
	} 
	window.onload = func;
}


/// JavaScript for mouseOvers

top.name = 'CHINHomePage';
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr;

  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
     x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


/// End of JavaScript for mouseOvers

/// Function for CSZS search form

function append(f) {
	if (f.LOCATION.value.length > 0) {
		f.LOCATION.value += "*" ;
	}
	f.submit() ;
}


/// Function to open URL in new browser

function CHIN_Aux(URL)
{
var the_string = /map/;
var map = URL.match(the_string);

if (map == null)
	{
        // make window for others....
        var serv=window.open(URL,'CHINAux','toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=690,height=320');
        }
        else
	{
	// make window for maps....
	var serv=window.open(URL,'CHINAux','toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=643,height=530');
        }
}

// Used by the feedback.cgi script
function CHIN_Aux2(URL) {

	var myURL = URL + '?open="' + escape(location.href) + '"' + '&port=' + location.port ;

 	var serv=window.open(myURL,'CHINAux2','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=500,height=330');
}


/* THIS HAS BEEN DEFINED WITH MORE FUNCTIONALITY BELOW
AND IT'S ALWAYS NICE TO HAVE ONE DELCARATION OF A FUNCTION
function VMCAux(URL)
{
var serv=window.open(URL,'VMCAux','toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=643,height=530');
}
*/


/// End of function to open URL in new browser

// Forum stuff

function move_in(img_name,img_src) {
document[img_name].src=img_src;
}

function move_out(img_name,img_src) {
document[img_name].src=img_src;
}

function setStatus(msg){
     status = msg
     return true
     }

// End of Forum Stuff

// Bob's addition for inline links on search results
function inlineLink(anchorName) { 
	location.hash=anchorName;
}

// Set a Cookie to remember the last Search Term(s)
function setSearchTerm(form) {
	if (typeof document.search.DTqb1!="undefined") {
		document.cookie = 'lastSearch=' + escape(form.DTqb1.value) + '; domain=.chin.gc.ca; path=/';
	}
	else
	{
		document.cookie = 'lastSearch=; domain=.chin.gc.ca; path=/';
	}
	//window.alert("Trying to set " + document.cookie + "!");
	}

// Search term carry over
function Get_Terms() {

	var defaultSearchValue = "< Recherche - site >";
	if (typeof document.search.DTqb1!="undefined") {
		document.search.DTqb1.value = defaultSearchValue;
	}
	var myTerms = "";
	var myCookie = document.cookie;
	if (myCookie == "") return false;
	var pos = myCookie.indexOf("lastSearch=");
	if (pos == -1) return false;
	var start = pos + 11;
	var end = myCookie.indexOf(";", start);
	if (end == -1) end = myCookie.length;
	var cookieString = unescape(myCookie.substring(start, end));

	var myTerms = cookieString;

	myTerms = myTerms.replace(/\+/g, ' ');
	myTerms = myTerms.replace(/#.*/, '');
	if (myTerms.length > 0) {
		if (typeof document.search.DTqb1!="undefined") {
			document.search.DTqb1.value = myTerms;
		}
		if (typeof document.searchCentre.DTqb1!="undefined") {
			if (document.searchCentre) {
				document.searchCentre.DTqb1.value = myTerms;
			}
		}
	}
//	window.alert("The terms I recieved were " + myTerms + "!");
	return true;
}

//BMUSE JAVASCRIPT

function openbmuse(keyprefix,language)
	{
//	var myurl ='http://www.chin.gc.ca/Bmuse/openbmuse.cgi?submit=submit&Chinkey='+keyprefix+''
	var myurl ='http://www.chin.gc.ca/Bmuse/openbmuse.cgi?submit=submit&Chinkey='+keyprefix+'&Language='+language+''
	var vmcwindow=window.open(myurl,'BMUSE','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=630,height=400');
	vmcwindow.focus();
	}

var checkflag = "false";



function check(field)
	{
	if (checkflag == "false")
		{
		for (i = 0; i < field.length; i++)
			{
			field[i].checked = true;}
			checkflag = "true";
			return "Deselect All";
			}
	else
		{
		for (i = 0; i < field.length; i++)
			{
			field[i].checked = false;
			}
	checkflag = "false";
	return "Select All"; }
	}



function history2()
	{
	history.go(-1);
	}
	
function VMCAux(URL)
	{
	var the_string = /map/;
	var map = URL.match(the_string);

	if (map == null)
		{
	        // make window for others....
	        var serv=window.open(URL,'VMCAux','toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=690,height=320');
	        }
	        else
		{
		// make window for maps....
		var serv=window.open(URL,'VMCAux','toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=643,height=530');
	        }
	}




function VMCAux2(URL)
	{
	var serv=window.open(URL,'VMCAux2','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=500,height=330');
	}

function VMCAux3(URL)
	{
	var serv=window.open(URL,'VMCAux3','toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=600,height=400');
	}



function ClearForm()
	{
	document.BMUSE.Lastname.value="";
	document.BMUSE.Firstname.value="";
	}


//END OF BMUSE JAVASCRIPT

//SCRIPT FOR CHIN SEARCH BOX

function setfocus() {
	if (typeof document.search.DTqb1!="undefined") {
		document.search.DTqb1.focus();
	}
}


function DelText()
{
	if (typeof document.search.DTqb1!="undefined") {
		if (document.search.DTqb1.value == "<Recherche - site>")
		{
			document.search.DTqb1.value = "";
		}
	}
}
	
	


