/* fonctions Java-script */
var undefined; /* make sure Java knows the undefined value*/
/* shut error reporting to users (return true)*/
onerror=function(){return true;} 

   function getObj(elemRef) {
    //convert elemRef into a valid object reference
    if (typeof elemRef == "string") {
     if (document.getElementById) {
      return document.getElementById(elemRef);
     } else {
      if (document.all) {
       return document.all[elemRef];
      } else
       return null;
     }
    } else
     return elemRef;
   } //
	
	function checkCR (evt){
		// disable carriage return (in input text but not textarea) to avoid submitting a form without clicking the submit button
		 var evt = evt || window.event;
		 var code = evt.charCode || evt.keyCode;
		 var node = evt.target || evt.srcElement;
		 if (code == 13 && node.type == "text") { return false; }
		} 


function setSelectionRange(event) {
	//The caret should be at the start of a textarea in a form. 
	
var e = event || window.event;
var input = e.target || e.srcElement;

if (input.createTextRange) {
//IE case
var range = input.createTextRange();
range.collapse(true);
range.moveEnd('character', 0);
range.moveStart('character', 0);
range.select();
}
else  {
//FireFox and Opera case
input.focus();
input.selectionStart = 0;
input.selectionEnd = 0;
}
}

function registerFocusTextarea(){
//Register the set cursor position handler on textarea elements in an unobstrusive way. Setting directly the onfocus attribute  doesn't work in Opera but this unobstrusive solution works.

	var textareaElts = document.getElementsByTagName("textarea");
	for (var i=0; i<textareaElts.length; i++){
		textareaElts[i].onfocus= setSelectionRange;
	}
}

function manageTips(){
  //When the document loads, all tips in a form are visible. This copes with the situation when javascript is disabled on the user agent (browser). If Javascript is enabled, this function is executed. It fetches all the tag elements named "tip" of the document. For each of these elements, it then registers the generic handlers for the events: onclick, onmouseover, and onmouseout. It also hides the tip which is supposed to be the next sibling element node in the document following the link elt named "tip". 
  
  var tipElts = new Array();
  var elt;
  
  tipElts = document.getElementsByName("tip");
  for (var i = 0; i < tipElts.length ; i++){
    tipElts[i].onclick = function(){
      //toggle the show/hide tip. For some reason we can't call a function here!
      //prevent default action (return false)
 	    var link = this;
	    var tip;
	    
	    elt = this;
      do{
        elt = elt.nextSibling;
      } while (elt.nodeType != 1); //search for the first sibling ELEMENT_NODE 
      tip = elt;
      if (tip.style.display == 'none'){
        tip.style.display = 'block';
        link.innerHTML = 'hide tip';
        link.title = '';
      }
      else{
        tip.style.display = 'none';
        link.title = 'show tip';
        link.innerHTML = '<img style="position:relative; top: 0px; margin-bottom:0px" src="images/icon_help_choose14.gif" />';
      }
      return false;
    };//function (onclick)
    
    
    //hide tips
    elt = tipElts[i];
    do{
      elt = elt.nextSibling;
    } while (elt.nodeType != 1); //search for the first sibling ELEMENT_NODE 
    elt.style.display = "none";
    tipElts[i].title = 'show tip';
  }//for

}//manageTips
      
      
  
  
function addOnLoadEvent(func) {
var oldQueue = (window.onload) ? window.onload : function( ) {};
window.onload = function( ) {
func( );
oldQueue( );
}
}//addOnLoadEvent(func)

/* functions for enlarging pictures at the bottom of the current window. This assumes the stactic markup has been introduced at the bottom of the page*/

function stripHashUrl(absUrl){
  var i = absUrl.lastIndexOf('#');
  if (i == -1) {return absUrl;} else {return absUrl.substr(0, i);}
}//stripHashUrl

function onLoadImage() {
	var eltImage = getObj("divImage");
	eltImage.style.display = "block";
	window.location.href= stripHashUrl(window.location.href)+"#enlarge";
}

function enlarge(picture, caption){
	var imagElt = getObj("bigImage");
	var descElt = getObj("caption");
	descElt.innerHTML = caption;
	imagElt.onload = onLoadImage;
	imagElt.src = picture;
	/*	var backAnchor = getObj("back");
	backAnchor.setAttribute("onclick", "javascript: backEnlarge();");*/
	return false;
}

function backEnlarge(){
	var eltImage = getObj("divImage");
	eltImage.style.display = "none";
	history.back();
}



