var Core = function() {
	/*accommodate earlier browsers like ie5.01 and lower which don't support Array.push and Array.shift in order to allow such browsers to use the addDOMLoadEvent function */
	if (typeof Array.prototype.shift=="undefined") {Array.prototype.shift=function(){var A_s = 0;var response=this[0];for(A_s=0;A_s<this.length-1;A_s++){this[A_s]=this[A_s+1];}this.length--;return response;};}
	if (typeof Array.prototype.push=="undefined"){Array.prototype.push=function(){var A_p=0;for(A_p=0;A_p<arguments.length;A_p++){this[this.length]=arguments[A_p];}return this.length;};}
	return {
		/*(c)2006 Jesse Skinner/Dean Edwards/Matthias Miller/John Resig
		* Special thanks to Dan Webb's domready.js Prototype extension and Simon Willison's addLoadEvent*/
		//the "if(d.getElementById)" check following "if(!e[0])" added by Jason Kiss to help non-W3CDom-supporting browsers, eg, IE4
		//ie conditional compilation check for @_jscript_version>=5.5 added by Jason Kiss to force ie5.01 to use window.onload
		addDOMLoadEvent:(function(){var e=[],t,s,n,i,o,d=document,w=window,r='readyState',c='onreadystatechange',x=function(){n=1;clearInterval(t);while(i=e.shift())i();if(s)s[c]=''};return function(f){if(n)return f();if(!e[0]){if(d.getElementById){d.addEventListener&&d.addEventListener("DOMContentLoaded",x,false);/*@cc_on@*//*@if(@_win32&&@_jscript_version>=5.5)d.write("<script id=__ie_onload defer src=//0><\/scr"+"ipt>");s=d.getElementById("__ie_onload");s[c]=function(){s[r]=="complete"&&x()};/*@end@*/if(/WebKit/i.test(navigator.userAgent))t=setInterval(function(){/loaded|complete/.test(d[r])&&x()},10);o=w.onload;w.onload=function(){x();o&&o()}}}e.push(f)}})()
	};
}();

//newWindow() checks page for anchors with @class="newWin", sets onclick to load in new window, and appends warning icon
function newWindow() {
	//check for required DOM properties and method objects
	if (document.documentElement && document.getElementsByTagName && document.createTextNode && document.createElement) {
		//set default alt text for appended image
		var altTxt="S'ouvre dans une nouvelle fenêtre";
		var addedTitleTxt="S'ouvre dans une nouvelle fenêtre";

		//get the page language from the html element's lang attribute and change alt text to english if @lang="en"
		var htmlEl=document.documentElement;
		if (htmlEl.getAttribute("lang") && htmlEl.getAttribute("lang").indexOf("en")>=0)
		{
			altTxt="Opens in new window";
			addedTitleTxt="Opens in new window";
		}
		//get all anchors
		var anchors = document.getElementsByTagName("a");
		for (var i=0;i<anchors.length;i ++) {
			//check each anchor for @class="newWin"
			var anchorsClassName=anchors[i].className;
			if (anchorsClassName.length > 0)
			{
				var posNewWin=-1;
				var posNewWinNoImg=-1;
				posNewWin = anchorsClassName.indexOf("newWin");
				posNewWinNoImg = anchorsClassName.indexOf("newWinnoImg");
				if (posNewWin >=0 && posNewWinNoImg < 0) {
					//add onclick event to load href in new window
					anchors[i].onclick = function() {
						window.open(this.getAttribute("href"),'CHINAux','toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=800,height=600');
						return false;
					};
					//create img element for warning icon
					var imgEl=document.createElement("img");
					imgEl.className="newWin";
					imgEl.setAttribute("src", "/VMC/images/nouv-fen_new-win.gif");
					imgEl.setAttribute("alt", altTxt);
					//append span to anchor
					anchors[i].appendChild(imgEl);
					
					//check each anchor for @class="newWin"
					//add text to the title
					var titleTxt = anchors[i].title;
					if (titleTxt.length > 0) {
						titleTxt = addedTitleTxt + " - " +  titleTxt;
					}
					else {
						titleTxt = addedTitleTxt;
					}
					anchors[i].setAttribute("title",titleTxt);
				}
				//check each anchor for @class="newWinnoImg"
				if (posNewWinNoImg >= 0) {
					//add onclick event to load href in new window
					anchors[i].onclick = function() {
						window.open(this.getAttribute("href"),'CHINAux','toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=800,height=600');
						return false;
					};
					//add text to the title
					var titleTxt = anchors[i].title;
					if (titleTxt.length > 0) {
						titleTxt = addedTitleTxt + " - " +  titleTxt;
					}
					else {
						titleTxt = addedTitleTxt;
					}
					anchors[i].setAttribute("title",titleTxt);
				}
			}
		}
	} else {
		return false;
	}
}

Core.addDOMLoadEvent(newWindow);

