var images = null;

function menuInit(defSearch) {
	var countryMenu = new countryMenuObj("switch");
	var searchBox = new searchBoxObj("search", defSearch);
	if(typeof callme == "function")
		callme();
}
function homeInit() {
	var chap = document.getElementsByTagName("div");
	for(var j=0; j<chap.length; j++) {
		if ((chap[j].className == "box_content") || (chap[j].className == "tabcontent")) {
			var elements = chap[j].getElementsByTagName("a");
			for(var i=0; i<elements.length; i++) {
			 if (elements[i].className == "targetBlank") elements[i].onclick = targetBlank;
			}
		}
	}
}
function chapterInit() {
	images = new Array();
	var chap = document.getElementById("chapter");
	var elements = chap.getElementsByTagName("a");
	for(var i=0; i<elements.length; i++) {
		switch (elements[i].className) {
		case "openIt": {
				if (!elements[i].onclick) elements[i].onclick = openImage;
				// add the zoom icon
				var zoomSpan = document.createElement("span");
				zoomSpan.setAttribute("class","zoomit");
				elements[i].appendChild(zoomSpan);
				var image = new Image();
				image.src = elements[i].href;
				images[images.length] = image;
				break; }
		case "videoIt": {
				if (!elements[i].onclick) elements[i].onclick = openVideo;
				break; }
		case "targetBlank": {
				elements[i].onclick = targetBlank;
				break; }
		}
	}
}
function openImage(param) {
	var evt;
	if (typeof(param)=="object" && param.type=="click")
		evt = param;
	evt = evt||event;
	evt.stopPropagation? evt.stopPropagation() : evt.cancelBubble = true;
	var url = (typeof(param)=="string") ? param : this.href;
	var srcElement = evt.target || evt.srcElement;
	var nodes = srcElement.parentNode.parentNode.parentNode.childNodes;
	var title = nodes[nodes.length-1].data;
	var image = new imageObj(url, title.replace(/\n/g,""));
	return false;
}
function openVideo(param){
	var url = (typeof(param)=="string") ? param : this.href;
	var video = new videoObj(url, getParam(url, "w=", "640"), getParam(url, "h=", "480"));
	return false;
}

/*
 * Handles country menu (hover and tracking)
 */
function countryMenuObj(id){
	this.init = initCountry;
	this.tag = null;
	var _self = this;
	_self.init(id);
	
	function initCountry (id){
		var ul = document.getElementById(id);
		_self.tag = ul.getElementsByTagName("li")[0];
		_self.tag.onmouseover = openMenu;
		_self.tag.onmouseout = closeMenu;
		if (ga_track){
			var links = ul.getElementsByTagName("a");
			for (var i=0; i<links.length; i++) {
				links[i].onclick = gotoCountry;
			}
		}
	}
	function gotoCountry (){
		var trackPath = this.pathname;
		if (trackPath.length>0){
			if (trackPath.charAt(0)=="/")
				trackPath = trackPath.substring(1);
			trackLocal("/goto_" + trackPath, ga_act, ga_reg);
			trackGlobal("/goto_" + trackPath, ga_reg);
		}
		return true;
	}
	function openMenu(e){
		_self.tag.className = "hover";
	}
	function closeMenu(e){
		_self.tag.className = "";
	}
}
function trackLocalEvent(category, action, label, value) {
	_gaq.push(['_trackEvent', category, action, label, value]);
}
function trackGlobalEvent(category, action, label) {
	_gaq.push(['global._trackEvent', category, action, label]);
}
function trackLocal(page, ga, reg) {
	var path = document.location.pathname;
	var rep = path.substring(path.indexOf('/'), path.lastIndexOf('/'));
	_gaq.push(
		['_setAccount', ga],
		['_setCookiePath', rep + '/'],
		['_setCustomVar', 1, 'reg', reg, 3],
		['_trackPageview', '/'+page]);
	_gaq.push(['_trackPageLoadTime']);
}
function trackGlobal(page, reg) {
		var path = document.location.pathname;
		var rep = path.substring(path.indexOf('/'), path.lastIndexOf('/'));
		_gaq.push(
			['global._setAccount', 'UA-11791018-1'],
			['global._setCustomVar', 1, 'reg', reg, 3],
			['global._trackPageview', rep + '/'+page]);
		_gaq.push(['_trackPageLoadTime']);
}

/*
 * Handles search interface
 */
function searchBoxObj(searchBoxId, defaultText){
	this.init = init_searchBox;
	this.defaultText = defaultText;
	this.searchBox = null;
	this.textBox = null;
	var _self = this;
	_self.init();
	
	function init_searchBox(){
		_self.searchBox = document.getElementById(searchBoxId);
		var mg = _self.searchBox.getElementsByTagName("img")[0];
		mg.onclick = mg_click;
		_self.textBox = _self.searchBox.getElementsByTagName("input")[1];
		_self.textBox.onfocus = clearSearch;
		_self.textBox.onblur = setSearch;
	}
	function mg_click() {
		if (_self.textBox.value != _self.defaultText)
			_self.searchBox.submit();
	}
	function clearSearch() {
		if (_self.textBox.value == _self.defaultText) 
			_self.textBox.value = "";
	}
	function setSearch() {
		if (_self.textBox.value == "")
			_self.textBox.value = _self.defaultText;
	}
}

/*
 * limits the length of text in textareas
 */
function limitTextareaObj(max, msg) {
	this.init = initTextarea;
	this.max = max;
	this.msg = msg;
	var _self = this;
	_self.init();
	
	function initTextarea () {
		var textarea = document.getElementsByTagName("textarea");
		for(var i=0; i<textarea.length; i++) {
			textarea[i].onblur = checkTextarea;
		}
	}
	function checkTextarea() {
		if (this.value.length>_self.max) {
			alert(_self.msg);
			field=this;
			setTimeout("field.focus()", 5); //for FF
			return false;
		}
		else return true;
	}
}

/*
 * Logos scrolling on home page
 */
function scroll_logosObj(div){
	this.init = scroll_init;
	this.timer = null;
	this.onleft = false;
	this.onright = false;
	this.scrollMax = 0;
	this.interval = 50;
	this.step = 20;
	var _self = this;
	_self.init(div);

	function scroll_init(div){
		_self.div = document.getElementById(div);
		var img = _self.div.getElementsByTagName("img");
		if (img[0].width > 800) scroll_start(img[0]);
		else img[0].onload = scroll_start;
	}
	function do_scroll(move) {
		if (_self.onright) move = _self.step;
		if (_self.onleft) move = -_self.step;
		var logos = document.getElementById("logos");
		if (move>0) {
			if (logos.scrollLeft + move > _self.scrollMax) move = _self.scrollMax - logos.scrollLeft;
		} else {
			if (logos.scrollLeft + move < 0) move = -logos.scrollLeft;
		}
		if (move!=0) {
			logos.scrollLeft = logos.scrollLeft + move;
			var left = document.getElementById("logos_arrow_l");
			var right = document.getElementById("logos_arrow_r");
		}
	}
	function start_left() {
		_self.onleft = true;
		_self.timer = setInterval(do_scroll, _self.interval);
	}
	function start_right() {
		_self.onright = true;
		_self.timer = setInterval(do_scroll, _self.interval);
	}
	function stop_scroll(){
		clearInterval(_self.timer);
		_self.onleft = false;
		onright = false;
	}
	function scroll_start(){
		var logos = document.getElementById("logos");
		var img = logos.getElementsByTagName("img");
		_self.scrollMax = img[0].width - logos.offsetWidth;
		var alea = Math.floor(Math.random()*(_self.scrollMax+logos.offsetWidth))-(logos.offsetWidth/2);
		if (alea<0) alea = 0;
		do_scroll(Math.round(alea));
		var logos_c = document.getElementById("logos_content");
		logos_c.style.visibility="visible";
		
		var left = document.getElementById("scroll_left");
		left.onmouseover = start_left;
		left.onmouseout = stop_scroll;
		var right = document.getElementById("scroll_right");
		right.onmouseover = start_right;
		right.onmouseout = stop_scroll; 
	}
}

/*
 * Tab rotation on home page
 */
function rotate_tabsObj(tablist, tabcontent){
	this.tablist = null;
	this.tab_timer = null;
	this.tabCount = 0;
	this.counter = 0;
	this.speed = 5;
	this.curTab = 1;
	this.intab = false;
	this.init = tab_init;
	var _self = this;
	_self.init(tablist, tabcontent);

	function tab_init(tablist, tabcontent){
		_self.tablist = document.getElementById(tablist);
		 var tabcontent = document.getElementById(tabcontent);
		var li = _self.tablist.getElementsByTagName("li");
		_self.tabCount = li.length;
		tabActive(_self.curTab);
		for (i=1; i < _self.tabCount + 1; i++)
			li[i-1].onclick = doClick;
		tabcontent.onmouseover = inTabContent;
		tabcontent.onmouseout = outTabContent;
		tab_rotate();
	}
	function inTabContent(){
		_self.intab = true;
	}
	function outTabContent(){
		_self.intab = false;		
	}
	function stop_rotate(){
		clearTimeout(_self.tab_timer);
		_self.counter = 0;
	}
	function doClick(){
		var li = _self.tablist.getElementsByTagName("li");
		for (i=1; i < _self.tabCount+1; i++){
			if (li[i-1] == this) tabActive(i);
		}
		stop_rotate();
	}
	function tabActive(num){
		var li = _self.tablist.getElementsByTagName("li");
		for (i=1; i < _self.tabCount+1; i++){
			if (num == i) {
				document.getElementById("tabcontent"+i).style.display = 'block';
				li[i-1].className = "tabactive";
			} else {
				document.getElementById("tabcontent"+i).style.display = 'none';
				li[i-1].className = "";
			}
		}
		_self.curTab = num;
	}
	function tab_rotate(){
		_self.counter = _self.counter + 1;
		_self.tab_timer = setTimeout(tab_rotate,1000);
		if (_self.counter >= _self.speed + 1) {
			if (!_self.intab){
				tabActive((_self.curTab == _self.tabCount) ? 1 : (_self.curTab + 1));
				clearTimeout(_self.tab_timer);
				_self.counter = 0;
				tab_rotate();
			}
		}
	}
}

/*
 * Popup object for video and large image display
 */
function popupObj(obj, x, y, w, h, title, body, hideBg){
	this.init = init;
	this.getDomTitleBar = getDomTitleBar;
	this.getDomBody = getDomBody;
	this.getDomObject = getDomObject;
	this.closeDlgBox = close;
	this.obj = obj;
	this.wLeft = x;
	this.wTop = y;
	this.wWidth = w;
	this.wHeight = h;
	this.wTitle = title;
	this.wBody = body;
	this.hideBg = hideBg;
	var _self = this;
	_self.init();

	function init(){
		_self.div = _self.getDomObject();
		document.getElementsByTagName("body")[0].appendChild(_self.div);
		if (_self.hideBg){
			var hideDiv = document.createElement("div");
			hideDiv.id = "hidePage";
			hideDiv.style.width = document.documentElement.scrollWidth + "px";
			hideDiv.style.height = Math.max(document.documentElement.scrollHeight, (document.documentElement.clientHeight||window.innerHeight)) + "px";
			hideDiv.style.display = "block";
			hideDiv.onclick = close;
			document.getElementsByTagName("body")[0].appendChild(hideDiv);
		}
	}
	function getDomObject() {
		var obj = document.createElement("div");
		obj.id = "popUpImage";
		obj.style.marginLeft = _self.wLeft + "px";
		obj.style.top = _self.wTop + "px";
		obj.style.width = _self.wWidth + "px";
		obj.style.height = _self.wHeight + "px";
		obj.appendChild(getDomTitleBar());
		obj.appendChild(getDomBody());
		return obj;
	}
	function getDomTitleBar() {
		var obj = document.createElement("div");
		obj.id = "titlePopup";
		var p = document.createElement("p");
		obj.appendChild(p);
		p.id = "closePopup";
		p.onclick = close;
		text = document.createTextNode("X");
		p.appendChild(text);
		var title = document.createElement("p");
		obj.appendChild(title);
		var text = document.createTextNode(_self.wTitle);
		title.appendChild(text);
		return obj;
	}
	function getDomBody() {
		return _self.wBody;
	}
	function close(){
		if (typeof(_self.obj.close) == "function")
			_self.obj.close();
		var node = null;
		if (this.id == "hidePage")
			node = this.previousSibling;
		else
			node = this.parentNode.parentNode;
		if (_self.hideBg)
			node.parentNode.removeChild(node.nextSibling);
		node.parentNode.removeChild(node);
	}
}

/*
 * Handles video with Flowplayer
 */
function videoObj(param, w, h){
	this.open = open;
	this.close = close;
	this.w = w;
	this.h = h;
	this.body = null;
	this.videoWidth = 640;
	this.videoHeight = 0;
	this.smallVideo = true;
	this.popup = null;
	this.tracker = null;
	
	this.titleBarHeight = 24;
	this.popupBorderWidth = 1;
	this.popupMinMargin = 10;
	this.playerBarHeight = 24;

	var _self = this;
	_self.open(param);
	
	function open(url) {
		_self.body = document.createElement("div");
		_self.body.id = "videoplayer";
		_self.body.className = "video";
		_self.body.style.width = _self.videoWidth + "px";
		_self.videoHeight = 24 + Math.round(parseInt(_self.h, 10) * _self.videoWidth / parseInt(_self.w, 10));
		_self.body.style.height = _self.videoHeight + "px";
		var top = (self.pageYOffset) ? self.pageYOffset : document.documentElement.scrollTop;
		var w = _self.videoWidth + (2 * _self.popupBorderWidth);
		var h = _self.videoHeight + (2 * _self.popupBorderWidth) + _self.titleBarHeight; 
		var x = parseInt(((window.innerWidth||document.documentElement.clientWidth) - (640)) / 2);
		_self.popup = new popupObj(_self, x, top + _self.popupMinMargin, _self.videoWidth, h, "video", _self.body, true);

		initVideoPlayer(_self.body.id, url);
		$f().play();
		smallVideo = true;
		_self.tracker = url.substring(url.lastIndexOf ("/"), url.indexOf("?",1));
		if (ga_track)
			trackLocalEvent("video", "play", _self.tracker);
	}
	
	function initVideoPlayer(player_id, video) {
		var format = video.substring(video.lastIndexOf(".")+1);
		if (format.indexOf("?")>0) format = format.substring(0,format.indexOf("?"));
		var url = video.substring(video.indexOf("/", 27) + 1, video.lastIndexOf("."));
		$f(player_id, "/flowplayer/flowplayer.commercial-3.1.5.swf", {
			key: '$8b48f85fd3245879b7d',
			clip: {
				url: ((format=="flv")?"":format + ":") + url,	
				provider: 'rtmp',
				accelerated: true,
				scaling: 'scale',
				onLastSecond: function(clip){
					if (ga_track)	
						trackLocalEvent("video", "end", _self.tracker);
        }
			},
			canvas: {
				backgroundColor: "#032e6c"
			},
			plugins: { 
				rtmp: {	
					url: '/flowplayer/flowplayer.rtmp-3.1.3.swf',	
					netConnectionUrl: 'rtmp://s1qf9vs6avnwf6.cloudfront.net/cfx/st'
				},
				controls: {
					backgroundColor: '#032e6c'
				}
			},
			onBeforeFullscreen: function(){
				if (_self.smallVideo) {
					var maxHeight = 16 * Math.round(((window.innerHeight||document.documentElement.clientHeight) - 24 - 26) / 16);
					maxHeight = Math.min((this.getClip().metaData.height + 24), maxHeight);
					var maxWidth = 1 + Math.round((maxHeight - 24) * this.getClip().metaData.width / this.getClip().metaData.height);
					setSize(maxWidth, maxHeight);
					_self.smallVideo = false;
				} else {
					setSize(_self.videoWidth, _self.videoHeight);
					_self.smallVideo = true;
				}
				return false;
				
				function setSize(w, h){
					_self.body.style.width = w + "px";
					_self.body.style.height = h + "px";
					_self.popup.div.style.width = 1 * (w + 2) +"px";
					_self.popup.div.style.height = 1 * (h + 26) +"px";
					_self.popup.div.style.marginLeft = parseInt(((window.innerWidth||document.documentElement.clientWidth) - (w)) / 2) + "px"; 
				}
			}
		});
	}
	function close(){
		if(typeof $f	== "function")
			if ($f()) $f().unload();
	}
}

/*
 * Displays zoomable image
 */
function imageObj(param, title){
	this.open = open;
	this.title = title;
	this.url = param;
	this.body = null;
	this.ie = false;
	this.mouseX = null;
	this.mouseY = null;
	this.moved = false;
	this.posX = null;
	this.posY = null;
	this.imgH = null;
	this.imgW = null;
	this.popupImgH = null;
	this.popupImgW = null;
	
	this.titleBarHeight = 24;
	this.popupBorderWidth = 1;
	this.popupMinMargin = 10;
	
	var _self = this;
	_self.open();
	
	function open() {
		_self.ie = (/MSIE (\d+\.\d+);/.test(navigator.userAgent));
		_self.body = document.createElement("img");
		_self.body.id = "imgPopup";
		_self.body.onload = displayPopup;
		_self.body.src = _self.url;
		_self.body.style.clip = (_self.ie) ? "rect(0 auto auto 0)" : "auto";
		_self.body.style.top = "0";
		_self.body.style.left = "0";
	}
	function displayPopup() {
		// calculate top popup position
		var top = (self.pageYOffset) ? self.pageYOffset : document.documentElement.scrollTop;
		// calculate image size
		_self.imgH = getNaturalHeight(_self.body);
		_self.imgW = getNaturalWidth(_self.body);
		var maxHeight = (document.documentElement.clientHeight||window.innerHeight) - (2 * (_self.popupMinMargin + _self.popupBorderWidth) + _self.titleBarHeight);
		var maxWidth = (document.documentElement.clientWidth||window.innerWidth) - (2 * (_self.popupMinMargin + _self.popupBorderWidth));
		if ((maxWidth/maxHeight) > (_self.imgW/_self.imgH)){
			_self.popupImgH = maxHeight;
			_self.popupImgW = parseInt(maxHeight * _self.imgW / _self.imgH);
		} else {
			_self.popupImgH = parseInt(maxWidth * _self.imgH / _self.imgW);
			_self.popupImgW = maxWidth;
		}
		if ((_self.popupImgH > _self.imgH ) || (_self.popupImgW > _self.imgW)){
			_self.popupImgH = _self.imgH;
			_self.popupImgW = _self.imgW;
		}
		_self.body.style.height = _self.popupImgH +"px";
		_self.body.style.width = _self.popupImgW +"px";
		// zoom only if image is not at full size
		if (maxHeight < _self.imgH) {
			_self.body.onclick = zoomin;
			_self.body.style.cursor = "url(/image/common/new/zoomin.png), auto";
		}
		// calculate popup dimensions
		var h = _self.popupImgH + _self.titleBarHeight + (2 * _self.popupBorderWidth);
		var w = _self.popupImgW + (2 * _self.popupBorderWidth);
		var x = parseInt(((window.innerWidth||document.documentElement.clientWidth) - (_self.popupImgW)) / 2); 
		var image = new popupObj(_self, x, top + 10, w, h, _self.title, _self.body, true);
	}
	function zoomin(e){
		var evt = e ? e : window.event;
		_self.body.style.cursor = "url(/image/common/new/zoomout.png), auto";
		var posX = ((evt.pageX - _self.body.x)||evt.offsetX) * _self.imgW / _self.body.width;
		posY = parseInt(posY - (_self.body.height / 2));
		var posY = ((evt.pageY - _self.body.y)||evt.offsetY) * _self.imgH / _self.body.height;
		posX = parseInt(posX - (_self.body.width / 2));
		_self.body.style.width = _self.imgW + "px";
		_self.body.style.height = _self.imgH + "px";
		setImagePosition(posY, posX);
		_self.body.onclick = zoomout;
		if (_self.popupImgW < _self.imgW)
			_self.body.onmousedown = startDrag;
		return false;
	}
	function zoomout(){
		if (!_self.moved){
			_self.body.style.cursor = "url(/image/common/new/zoomin.png), auto";
			_self.body.onclick = zoomin;
			_self.body.onmousedown = null;
	
			_self.body.style.width = 1 * (_self.popupImgW) + "px";
			_self.body.style.height = 1 * (_self.popupImgH) + "px";
			_self.body.style.clip = (_self.ie) ? "rect(0 auto auto 0)" : "auto";
			_self.body.style.top= "0";
			_self.body.style.left= "0";
			return false;
		}
	}
	function startDrag(e) {
		var ev = e ? e : window.event;
		console.log("startDrag");
		ev.stopPropagation? ev.stopPropagation() : ev.cancelBubble = true;
		document.onmousemove = doDrag;
		document.onmouseup = stopDrag;
		_self.body.style.cursor = "move";
		_self.mouseX = ev.pageX;
		_self.mouseY = ev.pageY;
		_self.moved = false;
		return false;
	}
	function stopDrag() {
		_self.body.style.cursor = "url(/image/common/new/zoomout.png), auto";;
		document.onmousemove = null;
		document.onmouseup = null;
		_self.mouseX = null;
		_self.mouseY = null;
		return false;
	}
	function doDrag(e) {
		var ev = e ? e : window.event;
		_self.moved = true;
		setImagePosition(_self.posY - (ev.pageY - _self.mouseY), _self.posX - (ev.pageX - _self.mouseX));
		_self.mouseX = ev.pageX;
		_self.mouseY = ev.pageY;
		return false;
	}
	function setImagePosition(top, left){
		top = (top < 0) ? 0 : top;
		top = (_self.imgH < (top + _self.popupImgH)) ? (_self.imgH - _self.popupImgH) : top;
		left = (left < 0) ? 0 : left;
		left = (_self.imgW < (left + _self.popupImgW)) ? _self.imgW - _self.popupImgW : left;
		_self.posX = left;
		_self.posY = top;
		_self.body.style.top = (-top) + "px";
		_self.body.style.left = (-left) + "px";
		if (_self.ie)
			_self.body.style.clip = "rect(" + top + "px " + (left + _self.popupImgW) + "px " + (top + _self.popupImgH) + "px " + left + "px)";
		else
			_self.body.style.clip = "rect(" + top + "px, " + (left + _self.popupImgW) + "px, " + (top + _self.popupImgH) + "px, " + left + "px)";
	}
}

/*
 * de-activate past dates in planning 
 */
function planning () {
		var tables = document.getElementsByTagName("table");
	var country = getParam(window.location.search.substring(1), "country=", "");
	for(var i=0; i<tables.length; i++) {
		if (tables[i].className=="interne") {
				var td=tables[i].getElementsByTagName("td");
			for(var j=0; j<td.length; j++) {
				var links = td[j].getElementsByTagName("a");
				if (links.length>0) {
					for (var k=0; k<links.length; k++) {
						var p = getParam(links[k].href, "sel=", "");
						if (p.length>0) {
							var date = p.substr(p.lastIndexOf("_")+1, 6);
							var d1 = new Date();
							var d2 = new Date(2000+(1*date.substr(0,2)), (date.substr(2,2)*1)-1, (date.substr(4,2)*1)+1);
							if (d2<d1) {
								for (var l=0; l<links[k].childNodes.length; l++) {
									td[j].insertBefore(links[k].childNodes[l],links[k]);
									l--;
								}
								td[j].removeChild(links[k]);
								k--;
							} else {
								if (country.length>0) links[k].href=links[k].href + "&country=" + country;
							}
						}
					}
				}
			}
		}
	}
}

/*
 * delete all past dates in menu select on quest page
 */
function planning_quest () {
		var select = document.getElementsByTagName("select");

		for(var i=0; i<select.length; i++) {
		if (select[i].name=="A1") {
				var option=select[i].getElementsByTagName("option");
			for(var j=0; j<option.length; j++) {
				var p = option[j].id;
				if (p.length>0) {
					var date = p.substr(p.lastIndexOf("_")+1, 6);
					var d1 = new Date();
					var d2 = new Date(2000+(1*date.substr(0,2)), (date.substr(2,2)*1)-1, date.substr(4,2));
					if (d2<d1) {
						option[j].parentNode.removeChild(option[j]);
						j--;
					}
				}
			}
			var optgroup=select[i].getElementsByTagName("optgroup");
			for(var j=0; j<optgroup.length; j++) {
				var option=optgroup[j].getElementsByTagName("option");
				if (option.length==0) {
					optgroup[j].parentNode.removeChild(optgroup[j]);
					j--;
				}
			}
		}
	}
}

/*
 * Misc utily functions
 */
function load_images() {
	var img = document.getElementsByTagName("img");
	for (i=1; i < img.length; i++){
		if (img[i].className.substr(0,7) == "/image/") {
			img[i].src = img[i].className;
			img[i].className = "";
		}
	}
}
function targetBlank(e) {
	var ev = (e==null) ? window.event : e;
	if(ev.ctrlKey) return true;
	var config = "menubar=yes,toolbar=yes,location=yes,directories=yes,fullscreen=no,titlebar=yes," +
		"hotkeys=yes,status=yes,scrollbars=yes,resizable=yes";
	window.open(this.href,"_blank", config);
	return false;
}
function setParam(param) {
	var sel = getParam(window.location.search.substring(1), param + "=", "");
	if (sel.length > 0) {
		var opt = document.getElementById(sel);
		if(opt!=null) opt.selected = "selected";
	}
}	
function getParam(query, param, defValue) {
	var index = query.indexOf(param);
	var end = null;
	if(index!=-1) {
		end = query.indexOf ("&" , index);
		if (end == -1) end = query.length;
		return query.substr(index+param.length, end-index-param.length);
	}
	else return defValue;
}
function getNaturalHeight(img){
	if(typeof img.naturalHeight == "undefined") {
		var temp_image = new Image();
		temp_image.src = img.src;
		return temp_image.height;
	} else {
		return img.naturalHeight;	
	}
}
function getNaturalWidth(img){
	if(typeof img.naturalWidth == "undefined") {
		var temp_image = new Image();
		temp_image.src = img.src;
		return temp_image.width;
	} else {
		return img.naturalWidth;
	}
}

/*
 * Forbids the return key in forms
 */
function initStopReturnKey (id) {
	var stop = document.getElementById(id);
	var fields = stop.getElementsByTagName("input");
	for(var i=0; i<fields.length; i++) {
		fields[i].onkeypress = stopReturnKey;
	}
}
function stopReturnKey(evt) {
	evt = (evt) ? evt : ((event) ? event : null);
	if (evt.keyCode == 13)	return false;
	else return true;
}
/*
 * Gets the browser specific XmlHttpRequest Object
 */	
function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) 
		return new XMLHttpRequest();
	else if(window.ActiveXObject)
		return new ActiveXObject("Microsoft.XMLHTTP");
	else 
		alert("Cound not create XmlHttpRequest Object.\nConsider upgrading your browser.");
		return null;
}
function formAjax(formAjaxURL, formAjaxParam) {
	var req = getXmlHttpRequestObject();
	req.open("POST", formAjaxURL, true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", formAjaxParam.length);
	req.setRequestHeader("Connection", "close");
	req.send(formAjaxParam);
	return false;
}

