// publigen.js - novembre 2006
// Fourni par Frédéric Pigamo pour faciliter le remplissage du Publigen à partir du site web

function clickLogo() {
if (!processOpener()) parent.location.replace(defaultTop);
}
function processOpener() {
if (parent.parent.opener == null) return false;
var pos = parent.location.href.indexOf('&palette=');
if (pos == -1) return false;
var backurl = parent.location.href.substring(pos+9);
if ((pos=backurl.indexOf('&')) != -1) backurl=backurl.substring(0,pos);
pos=parent.location.href.indexOf('&nfield=');
if (pos == -1) return false;
var nfield = parent.location.href.substring(pos+8);
if ((pos=nfield.indexOf('&')) != -1) nfield=nfield.substring(0,pos);
var udata = null, ref, pref = '';
for (f = 0;f < parent.frames.length;f++)
 if (parent.frames[f].name == 'contenu')
  {
   if (parent.frames[f].window.popupW != null)
    if (!parent.frames[f].window.popupW.closed) {
    	parent.frames[f].window.popupW.focus();
    		udata=parent.frames[f].window.popupW.location.href; parent.frames[f].window.popupW.close(); break;
    	}    
   udata=parent.frames[f].location.href; break;
  }
if (udata == null) return false;
pos=udata.indexOf('accesParReference/');
if (pos != -1) ref=udata.substring(pos+18);
else {
pref='accesParIntranetID/';
if ((pos=udata.indexOf(pref)) != -1) ref=udata.substring(pos+pref.length);
else {
	if ((pos=udata.indexOf('_view/')) == -1) {alert('not found in '+udata); return true;}
	ref=udata.substring(pos+6); pref='accesParID/';	
 }
}
if ((pos=ref.indexOf('/')) != -1) ref=ref.substring(0,pos);
ref=pref+ref;
if (document == null) return true;
if ((document.createElement == null) || (document.getElementsByTagName == null)) return true;
var remoteScript=document.createElement('script');
remoteScript.id = 'rs';
remoteScript.setAttribute('type','text/javascript');
remoteScript.setAttribute('src',backurl+'&selected='+ref+'&nfield='+nfield);
var hd=document.getElementsByTagName('head')[0];
hd.appendChild(remoteScript);
return true;
}
