// http://www.websemantics.co.uk/resources/accessible_form_help/
function hideAll(){
  var obj,nextspan,anchor,content;

  // get all spans
  obj=document.getElementsByTagName('span');

  // run through them
  for (var i=0;i<obj.length;i++){

    // if it has a class of helpLink
    if(/helpLink/.test(obj[i].className)){

      // get the adjacent span
      nextspan=obj[i].nextSibling;
      while(nextspan.nodeType!=1) nextspan=nextspan.nextSibling;

       // hide it
      nextspan.style.display='none';
	  nextspan.onclick=function(){showHide(this);return false;}; // also close the help box when clicking it

      //create a new link
      anchor=document.createElement('a');

      // copy original helpLink text and add attributes
      content=document.createTextNode(obj[i].firstChild.nodeValue);
      anchor.appendChild(content);
      anchor.href='#help';
      anchor.title='Cliquez pour afficher l\'aide.';
      anchor.className=obj[i].className;
      anchor.nextspan=nextspan;
      anchor.onclick=function(){showHide(this.nextspan);changeTitle(this);return false;};

      // replace span with created link
      obj[i].replaceChild(anchor,obj[i].firstChild);
    }
  }
}

// used to flip helpLink title
function changeTitle(obj){
  if(obj)
    obj.title = obj.title=='Cliquez pour afficher l\'aide.' ? 'Cliquez pour cacher l\'aide.' : 'Cliquez pour afficher l\'aide.';
}

// used to toggle the display property
function showHide(obj){
  if(obj)
  {
	//obj.style.display = obj.style.display=='none' ? 'block' : 'none'
	if (obj.style.display == 'none')
	{
		obj.style.display = 'block';
		obj.className = 'helpBoxContainer';
		if (IsIE6())
		{
			showIEHack(obj);
		}
	}
	else
	{
		obj.style.display = 'none';
		obj.className = '';
		if (IsIE6())
		{
			hideIEHack();
		}
	}
  }
}

//ie6 hacks : http://xlib.wordpress.com/2006/04/12/bug-fix-select-box-displayed-through-dynamic-div-in-internet-explorer/
var g_PopupIFrame;

function IsIE6()
{

    return /MSIE 6/i.test(navigator.userAgent);

}

function hideIEHack()
{
	document.body.removeChild(g_PopupIFrame);
}

function showIEHack(popupContainer)
{

    //Increase default zIndex of div by 1, so that DIV appears before IFrame
    popupContainer.style.zIndex=popupContainer.style.zIndex+1;

    var iFrame;
    if(!g_PopupIFrame)
    {
    	iFrame= document.createElement("IFRAME");
    }
    else
    {
    	iFrame = g_PopupIFrame;
    }

	iFrame.setAttribute("src", "");
    	
    //Match IFrame position with divPopup
    iFrame.style.display = "block";
    iFrame.style.visibility = "hidden";
	iFrame.style.position="absolute";
    iFrame.style.left =popupContainer.offsetLeft + 'px';
    iFrame.style.top =popupContainer.offsetTop + 'px';
    iFrame.style.width =popupContainer.offsetWidth + 'px';
    iFrame.style.height =popupContainer.offsetHeight + 'px';

    if(!g_PopupIFrame)
    {
    	g_PopupIFrame = iFrame;
    }
    document.body.appendChild(g_PopupIFrame);
}
// end of ie6 hacks
addLoadEvent(hideAll);