		
// - - - - Live RHS
function rhsCreateLabel(cid,name) {
	var dv=document.createElement("div");
	dv.className="rubric_title rbgen" + cid;
	dv.appendChild(document.createTextNode(name));
	return dv;
}


function rhsCreateListItemFromNode(node) {
	var li, texts, link, a, href;
	

	node.normalize();
	texts = node.getElementsByTagName("text");

	link = node.getElementsByTagName("a")[0];
	
	li=document.createElement("li");
	if (texts.length > 1) li.appendChild(document.createTextNode(texts[0].firstChild.nodeValue));
	a=li.appendChild(document.createElement("a"));
	href=document.createAttribute("href");
	href.nodeValue = link.attributes[0].nodeValue;
	a.setAttributeNode(href);
	a.appendChild(document.createTextNode(link.firstChild.nodeValue));
	li.appendChild(document.createTextNode(texts[texts.length - 1].firstChild.nodeValue));

	return li;
}


function rhsCreateMoreFromNode(node) {
	var dv, a, href, link;
	link = node.getElementsByTagName("a")[0];
	dv=document.createElement("p");
	dv.className="more";
	a=dv.appendChild(document.createElement("a"));
	href=document.createAttribute("href");
	href.nodeValue = link.attributes[0].nodeValue;
	a.setAttributeNode(href);
	a.appendChild(document.createTextNode(link.firstChild.nodeValue));
	return dv;
}

function rhsRefresh() {
var loc=''+document.location+'';

if(loc.indexOf('_en.h', 0) != -1){

xml_doc='_en';
lang='en';
	
		}
	
else if(loc.indexOf('_fr.h', 0) != -1){

xml_doc='_fr';
lang='fr';

	}

else if(loc.indexOf('_de.h', 0) != -1){

xml_doc='_de';
lang='de';

	}

else if(loc.indexOf('_bg.h', 0) != -1){

xml_doc='';
lang='bg';

	}

else if(loc.indexOf('_cs.h', 0) != -1){

xml_doc='';
lang='cs';

	}
	
else if(loc.indexOf('_da.h', 0) != -1){

xml_doc='';
lang='da';

	} 
	
else if(loc.indexOf('_de.h', 0) != -1){

xml_doc='';
lang='de';

	} 
	
else if(loc.indexOf('_et.h', 0) != -1){

xml_doc='';
lang='et';

	} 
	
else if(loc.indexOf('_el.h', 0) != -1){

xml_doc='';
lang='el';

	} 
	
else if(loc.indexOf('_es.h', 0) != -1){

xml_doc='';
lang='es';

	} 
	
else if(loc.indexOf('_fr.h', 0) != -1){

xml_doc='';
lang='fr';

	} 
	
else if(loc.indexOf('_ga.h', 0) != -1){

xml_doc='';
lang='ga';

	} 
	
else if(loc.indexOf('_it.h', 0) != -1){

xml_doc='';
lang='it';

	} 
	
else if(loc.indexOf('_lv.h', 0) != -1){

xml_doc='';
lang='lv';

	} 
	
else if(loc.indexOf('_it.h', 0) != -1){

xml_doc='';
lang='it';

	} 
	
else if(loc.indexOf('_hu.h', 0) != -1){

xml_doc='';
lang='hu';

	} 
	
else if(loc.indexOf('_mt.h', 0) != -1){

xml_doc='';
lang='mt';

	} 
	
else if(loc.indexOf('_nl.h', 0) != -1){

xml_doc='';
lang='nl';

	} 
	
else if(loc.indexOf('_pl.h', 0) != -1){

xml_doc='';
lang='pl';

	} 
	
else if(loc.indexOf('_pt.h', 0) != -1){

xml_doc='';
lang='pt';

	} 
	
else if(loc.indexOf('_ro.h', 0) != -1){

xml_doc='';
lang='ro';

	} 
	
else if(loc.indexOf('_sk.h', 0) != -1){

xml_doc='';
lang='sk';

	} 
	
else if(loc.indexOf('_sl.h', 0) != -1){

xml_doc='';
lang='sl';

	} 
	
else if(loc.indexOf('_fi.h', 0) != -1){

xml_doc='';
lang='fi';

	}

else if(loc.indexOf('_sv.h', 0) != -1){

xml_doc='';
lang='sv';

	} 
	
	
else {

xml_doc='';
lang='';

	}
	 if(document.location.href.indexOf('http://www.acceptance.ec.europa.eu',0) != -1){
var stub="http://www.acceptance.ec.europa.eu/enterprise/";
}else if(document.location.href.indexOf('www.development.ec.europa.eu',0) != -1){
var stub="http://www.development.ec.europa.eu/enterprise/";
}else if(document.location.href.indexOf('www.test.ec.europa.eu',0) != -1){
var stub="http://www.test.ec.europa.eu/enterprise/";
}else if(document.location.href.indexOf('http://europa.eu.int',0) != -1){
var stub="http://europa.eu.int/comm/enterprise/";
}else if(document.location.href.indexOf('http://ec.europa.eu/',0) != -1){
var stub="http://ec.europa.eu/enterprise/";
}else {

var stub="http://ec.europa.eu/enterprise/";
}
	var rc, i, cid, rcdlist;
	rc = document.getElementById("all_rubrics");
	if (rc) {
		rcdlist = rc.getElementsByTagName("DIV");
		cid="00";
		for (i=0;i<rcdlist.length;i++) {
			if (rcdlist[i].className.search(/\brbgen(\d+)*(\&\w+\=\d+([,]\d+)*)*(\&\w+\=\w+)*\b/) > -1) {
				cid = rcdlist[i].className.match(/\brbgen((\d+)*(\&\w+\=\d+([,]\d+)*)*(\&\w+\=\w+)*)\b/)[1];
				break;
			}
		}

if (cid.indexOf("lang=",0) != -1 || lang == '')
{
	var langid='';
	//alert(''+langid+' 1 '+cid);
}

else if(xml_doc == '_en.h' || xml_doc == '_de.h' || xml_doc == '_fr.h')

{
	var langid='';
	//alert(''+langid+' 2 '+cid);
}


else{
	
	var langid='&lang='+lang;
	//alert(''+langid+' 3 '+cid);
}

		if (cid=="00") return;
		new Ajax({
			url: ''+stub+'newsroom/cf/textnewrefresh'+xml_doc+'.cfm?format=2005&tpa=' + cid+langid,
			onSuccess:function(text) {
				for (i=rcdlist.length-1;i>=0;i--) {
					if (rcdlist[i].className.search(/\brbgen(\d+)*(\&\w+\=\d+([,]\d+)*)*(\&\w+\=\w+)*\b/) > -1) {
						rcdlist[i].parentNode.removeChild(rcdlist[i]);
					}
				}
				rc.innerHTML = text + rc.innerHTML;
				// displayRSNewsForm();
				//if (niftyfy) niftyfy();
			}
		});
	}
}

// - - - - addLoadEvent: add instructions to the windows onload event without replacing possible existing code
// thanks to Simon Willison for this one
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}



// - - - - All we want to do when something happens to the window object
addLoadEvent(function(e) {
	rhsRefresh();
});



// ------------------------------------------------ Leftovers

// Anyone uses any of these any more?
if (document.layers) {browserType = "nn4"}
if (document.all) {browserType = "ie"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {browserType= "gecko"}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

/* Ajax library
 * This a very raw Ajax library, only supporting for the time being
 * the GET method.
 * Things to do:
 * - Better Error handling using the javascript error object
(properties: message (description in IE5), number))
 *   Possibly create own error object to return, say as second
argument which should merge javascript error and
 *   XMLHttpRequest status (properties statusText and status).
 *   Probably, openHttpRequest should return (or set) my own status
property object, allowing sendHttp to
 *   return something more informative
 * - Make sure there are no memory leaks
 * - Add POST method handling.
 * - Create a simple Updater object sending retrieved info to an
indetified target
 * - Create a simple PeriodicalUpdater object repeating a call every X seconds
 * 
 * UPDATE 4/1/2007: added a stripWddx boolean (default is false) property to the parameter object.
 * If set to true, the returned text will be stripped of the wddx tags before it is passed to the Success callback function
 * Use with remote calls to cf components.
 * 
 * UPDATE 22/2/2007: added a onEnd function (default is a function that does nothing) property to the paramater object.
 * The function will be invoked always, whatever the result is (success or failure), after the onSuccess/onError function
 * the onSuccess parameter becomes optional: both because you can simply use onEnd to respond to ANY call result
 * and because this enables you to issue a 'send-and-forget' call.
 * 
**/

function Ajax(ob) {
	this.method = (ob.method || "GET");
	this.allowCache = (ob.allowCache || false);
	this.url = ob.url;
	if ((typeof this.allowCache) == 'number') {
		this.url = this.url + (this.url.indexOf("?")==-1 ? "?" : "&") + "ajaxtime=" + Math.round((new Date()).getTime()/(1000*this.allowCache));
	} else if (!this.allowCache) {
		this.url = this.url + (this.url.indexOf("?")==-1 ? "?" : "&") + "ajaxtime=" + (new Date()).getTime();
	}
	this.onSuccess = (ob.onSuccess ? ob.onSuccess : function() {});
	this.mode = (ob.mode ? ob.mode : "text");
	this.onError = (ob.onError ? ob.onError : function() {});
	this.onEnd = (ob.onEnd ? ob.onEnd : function() {});
	this.onBegin = (ob.onBegin ? ob.onBegin : function() {});
	this.httpRequest = null;
	this.errorNumber = 0;
	this.errorMessage = "";
	this.stripWddx = ob.stripWddx || false;
	this.treat = function(text) {return this.stripWddx ? this.wddxStripper(text) : text};
	this.sendHttp();
}

Ajax.prototype.wddxStripper = function (text) {
	return text.replace(/<.*?>/gi,'').replace(/[\t\r\n]/g,'').trim();
}

Ajax.prototype.sendHttp = function() {
	this.openHttpRequest();
	if (this.httpRequest) {
			//have the 'wait' here?
			try {
				this.httpRequest.open(this.method, this.url, true);
				this.httpRequest.send(null);
			}
			catch(er) {
				this.httpRequest = null;
				this.errorNumber = er.number;
				this.errorMessage = er.message || er.description || "Undescribed error";
				this.onError(this.errorMessage + " (" + this.errorNumber + ")");
				this.onEnd(this);
			}
	}
	else {
		this.onError(this.errorMessage + " (" + this.errorNumber + ")");
		this.onEnd(this);
	}
}

Ajax.prototype.openHttpRequest = function() {
	var me=this;
	this.httpRequest = this.createXMLHttpRequest();
	if (this.httpRequest) {
		this.httpRequest.onreadystatechange = function() {me.receiveHttp();};
	}
	return;
}

Ajax.prototype.createXMLHttpRequest = function() {
	try { return new XMLHttpRequest( ); } catch(e) {}
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	this.errorNumber = -1;
	this.errorMessage = "XMLHttpRequest is not supported";
	return null;
}

Ajax.prototype.receiveHttp = function() {
	if ( this.httpRequest.readyState != 4 ) return ;
	if ( this.httpRequest.status != 200 )
		this.onError(this.httpRequest.statusText + " (" + this.httpRequest.status + ")");
	else if (this.mode == "xml")
		this.onSuccess(this.httpRequest.responseXML);
	else
		this.onSuccess(this.treat(this.httpRequest.responseText));
	this.onEnd(this);
	delete this.httpRequest;
}