function chain(block) 
{
document.chainform.chainblockindex.value = block;
document.chainform.submit();
}


function recompute(block) 
{

// document.show[0].starting.value = block-1;
document.recomp.starting.value = block;
document.recomp.showing.value = document.show[0].showing.value;
document.recomp.startblock.value = block;
document.recomp.submit();
}



function showme(direction,speed)
{
var startingvalue = eval(document.show[0].starting.value);
startingvalue = startingvalue + eval(direction*document.show[0].showing.value)-speed;
if (startingvalue >= 0)	{	document.show[0].starting.value = startingvalue ;}
else {document.show[0].starting.value = 0 ;}
if (startingvalue >= numblocks)	{document.show[0].starting.value = numblocks - document.show[0].showing.value ;	}
document.show[0].submit();
}

function gothere(direction)
{
if (direction == "home")	
	{document.show[0].starting.value = 0 ;}
if (direction == "end")		
	{document.show[0].starting.value = numblocks -document.show[0].showing.value;}
document.show[0].submit();
}




  function moveHandler(e){
      if (e === null) { e = window.event;} 
	var target = e.target !== null ? e.target : e.srcElement;
      if (e.button<=1&&dragOK)
	{
		popup.style.left=e.clientX-dragXoffset+'px';
		popup.style.top=e.clientY-dragYoffset+'px';
	
	if ((target.tagName=="SPAN") && (target.parentNode.tagName == "DIV"))
	{
	target=target.parentNode;
	}
	if (  (target.tagName=="DIV")  && (target.lang=="lang")  && (target != savedTarget)   ) 
// &&  (target.id != "text")
		{
		if (document.getElementById("linkPopup"))  	{popuptargtext = document.getElementById("linkPopupTargText");}
		else 						{   popuptargtext = window.document["linkPopupTargText"];}   
		var targtext="to '"+target.firstChild.nodeValue.substr(0,25)+"...'";
			popuptargtext.firstChild.nodeValue=targtext;
			window.document.body.style.cursor = '-moz-grab';
		}
	else   {popuptargtext.firstChild.nodeValue="to corresponding paragraph";
			window.document.body.style.cursor = '-moz-grabbing';}
	
	return false;
      }
   }


   function cleanup(e) {

// 	var htype='-moz-grabbing';
	if (e === null) { e = window.event; /*htype='move';*/} 
	var target = e.target !== null ? e.target : e.srcElement;
	if ((target.tagName=="SPAN") && (target.parentNode.tagName == "DIV"))
	{
	target=target.parentNode;
	}
	if ((target.tagName=="DIV")&& (target.lang=="lang") && (target.id != savedTarget.id)  ) {
	orig = savedTarget.id.split("_");
	targ = target.id.split("_");
	
	document.dragparag.origla.value = orig[0];
	document.dragparag.origblo.value = orig[1];
	document.dragparag.origpar.value = orig[2];
	document.dragparag.targetla.value = targ[0];
	document.dragparag.targetblo.value = targ[1];
	document.dragparag.targetpar.value = targ[2];
	
	document.dragparag.submit();
}
	document.onmousemove=null;
	document.onmouseup=null;
	popup.style.visibility='hidden';	
	window.document.body.style.cursor = 'default';
	
	dragOK=false;
   }


	 
 function kimsDragHandler(e){

      var htype='-moz-grabbing';
      if (e === null) { e = window.event; htype='move';} 
      var target = e.target !== null ? e.target : e.srcElement;
//       orgCursor=target.style.cursor;

	if ((target.tagName=="SPAN") && (target.parentNode.tagName == "DIV"))
	{
	target=target.parentNode;
	}
      if (( target.tagName=="DIV"  )&& (target.lang=="lang")) { 

	
// && (target.id != "text")
         savedTarget=target;       
	window.document.body.style.cursor = '-moz-grabbing';
//          target.style.cursor=htype;

      if (document.getElementById("linkPopup"))   
	{
	popup = document.getElementById("linkPopup"); 
	popuporgtext = document.getElementById("linkPopupOrigText"); 
	popuptargtext = document.getElementById("linkPopupTargText"); 
	}
      else   
	{     
	popup =  window.document["linkPopup"];
	popuporgtext = window.document["linkPopupOrigText"];
	popuptargtext = window.document["linkPopupTargText"];
	}   
	
	if (popup)
	{	
		popup.style.visibility='hidden';	
		var x=e.clientX;
		var y=e.clientY;
		x=parseInt(e.clientX+document.body.scrollLeft);
		y=parseInt(e.clientY+document.body.scrollTop);

		var origtext="'"+savedTarget.firstChild.nodeValue.substr(0,25)+"...'";

		popuporgtext.firstChild.nodeValue=origtext;

		popup.style.left=x+10;
		popup.style.top=y;

		popup.style.visibility='visible';
	}

         dragOK=true;
         dragXoffset=e.clientX-parseInt(popup.style.left);
         dragYoffset=e.clientY-parseInt(popup.style.top);
         document.onmousemove=moveHandler;
         document.onmouseup=cleanup;
         return false;
      }
   }






// for options opening and closing ################## 


// window.document.body.style.cursor = '-moz-grabbing';



var ouvert=0;
var glisse_timer;
var glisse_fermtimer;

function calculOuverture(ouvDemande) {

valmax = 0.75;

hautfen = window.innerHeight;
if (!hautfen) {hautfen = document.body.offsetHeight;}

hautfenmax = hautfen * valmax;
if (ouvDemande > hautfenmax) {return  hautfenmax - hautfenmax%25;}
else {return ouvDemande;}

}


function ouvre(i, hauteur) {

	hauteur = calculOuverture(hauteur);
	
  	if(ouvert!==0 && ouvert!=i) {
  		//si qqch déjà ouvert
		glisseferm(ouvert, hauteur, 0, 25, 'idRow' + ouvert);
		nameObj = (document.getElementById) ? document.getElementById('name' + ouvert) : eval("document.all['name" + ouvert + "']");
		nameObj.className="row";		
  	}

  	var trObj = (document.getElementById) ? document.getElementById('idRow' + i) : eval("document.all['idRow" + i + "']");
  	nameObj = (document.getElementById) ? document.getElementById('name' + i) : eval("document.all['name" + i + "']");
	//   var ifObj = (document.getElementById) ? document.getElementById('idIframe' + i) : eval("document.all['idIframe" + i + "']");

	if (trObj !== null) {
		if (trObj.style.display=="none") {
			trObj.style.display="";
				nameObj.className="rowopen";
			//       if (!ifObj.src) ifObj.src = href;
			glisse('idRow' + i, 0, hauteur, 25, 'o');
				ouvert = i;
		}
		else {
			nameObj.className="rowopen";
			glisse('idRow' + i, hauteur, 0, 25, 'idRow' + i);
				ouvert = 0;
		}
  	}    
}

function dessus(i) {  
  var nameObj = (document.getElementById) ? document.getElementById('name' + i) : eval("document.all['name" + i + "']");
  if (nameObj !== null) {nameObj.className="rowover";}	
}
function parti(i) {
 	if (i==ouvert) {return;}
  	var trObj = (document.getElementById) ? document.getElementById('idRow' + i) : eval("document.all['idRow" + i + "']");  
  	var nameObj = (document.getElementById) ? document.getElementById('name' + i) : eval("document.all['name" + i + "']");    
  	if (trObj === null || trObj.style.display=="none") {nameObj.className="row";}
}
function glisse(id, curH, targetH, stepH, mode) {
  diff = targetH - curH;
  if (diff !== 0) {
    newH = (diff > 0) ? curH + stepH : curH - stepH;
    ((document.getElementById) ? document.getElementById(id) : eval("document.all['" + id + "']")).style.height = newH + "px";
    if (glisse_timer) window.clearTimeout(glisse_timer);
    glisse_timer = window.setTimeout( "glisse('" + id + "'," + newH + "," + targetH + "," + stepH + ",'" + mode + "')", 20 );
  }
  else if (mode != "o") {((document.getElementById) ? document.getElementById(mode) : eval("document.all['" + mode + "']")).style.display="none";}
}
function glisseferm(i, curH, targetH, stepH, mode) {
  diff = targetH - curH;
  if (diff !== 0) {
  	id = "idRow" +  i;	
    newH = (diff > 0) ? curH + stepH : curH - stepH;
    ((document.getElementById) ? document.getElementById(id) : eval("document.all['" + id + "']")).style.height = newH + "px";
    if (glisse_fermtimer) {window.clearTimeout(glisse_fermtimer);}
    glisse_fermtimer = window.setTimeout( "glisseferm('" + i + "'," + newH + "," + targetH + "," + stepH + ",'" + mode + "')", 20 );
  }
  else if (mode != "o") {((document.getElementById) ? document.getElementById(mode) : eval("document.all['" + mode + "']")).style.display="none";}
}





document.onmousedown=kimsDragHandler;
