/*
 * manipulation des liens decimaux
 *
 * (c) 2005-2007 Yannis Delmas
 */

/* suivi d'un lien decimal */

function _dc_prep() {
	if ( document.getElementById ) {
		document.getElementById('lien').select();
		document.getElementById('lien').focus();
	}
}

function _dc_hover() {
	var nom = this.id;
	if ( nom.substring(0,2) != 'dc' ) { return; }
	document.getElementById('dc').lien.value = nom.substring(2);
	_dc_prep();
}

function _dc_go() {
	var lien; // lien hypertexte a suivre
	if ( document.getElementById ) {
		lien = document.getElementById('dc'+document.getElementById('dc').lien.value);
		if ( lien ) {
			window.location.href = lien.href;
		}
	}
	return(false);
}

/* initialisations */

function _dc_init_dc() {
	if ( document.getElementsByTagName ) {
		/* preparation des liens */
		var liens = document.getElementsByTagName('a');
		var n = 0;
		for(var i=0; i<liens.length; i++) {
			var a = liens.item(i);
			if ( a.rel == 'dc' ) {
				a.id = 'dc' + n;
				a.name = 'dc' + n;
				if ( a.className == 'out' ) {
					a.className = 'lienDc out';
					a.target = '_blank';
				} else {
					a.className = 'lienDc';
				}
				a.onmouseover = _dc_hover;
				a.innerHTML += ' <span class="dcref">' + n + '</span>';
				n++;
			} else if ( a.rel == 'jigsaw' ) {
				a.href += '?uri=' + document.location.href;
				a.target = '_blank';
			} else if ( a.className == 'out' ) {
				a.target = '_blank';
			}
		}
		if ( n ) {
			/* preparation du formulaire */
			var f = document.getElementById('dc');
			f.onsubmit = _dc_go;
			f.parentNode.parentNode.style.display = '';
			_dc_prep();
		}
	}
}

function _dc_addLoadEvent(func) {	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}
}
_dc_addLoadEvent(_dc_init_dc);

/* texte d'information */

function dc_toggle_info() {
	if ( document.getElementById ) {
		if ( document.getElementById('dcInfo').style.display == 'none' ) {
			document.getElementById('dcInfo').style.display = '';
		} else {
			document.getElementById('dcInfo').style.display = 'none';
		}
	}
}
