// ------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------
// --   DOCVADIS DIALOGS
// ------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------
var docAlert = {};

docAlert.protection = null;
docAlert.ANSWER_NO = 0;
docAlert.ANSWER_YES = 1;
docAlert.ANSWER_NO_ALL = 2;
docAlert.ANSWER_YES_ALL = 3;

// attention si quelqu'un modifie une de ces valeurs il faut repercuter la modification dans deleteSubSection, 
// validateDeleteSubSection et cancelDeleteSubSection
docAlert.ANSWER_DELETE_DOCUMENTS = 4;
docAlert.ANSWER_MOVE_DOCUMENTS_IN_OTHER_SUB_SECTION = 5;
docAlert.ANSWER_MOVE_DOCUMENTS_IN_MY_DOCUMENTS = 6;


docAlert.ANSWER_DELETE_ONE_ADVICE = 7;



docAlert.answer = -1
docAlert.agt = navigator.userAgent.toLowerCase();
docAlert.is_ie = ((docAlert.agt.indexOf("msie") != -1) && (docAlert.agt.indexOf("opera") == -1));

docAlert.init = function()
{
	  if (docAlert.protection == null)
	  {
	    docAlert.protection = new SProtectLayer();
	    docAlert.protection.setLevel(20);
	    docAlert.protection.setStyle("backgroundColor", "#333333");
	    docAlert.protection.setOpacity(40);
	  }
}

// ------------------------------------------------------------------------------------
// --   MESSAGE BOX
// ------------------------------------------------------------------------------------
docAlert.message = function(title, message, callback)
{
  docAlert.init(); 
  var html =
      "<div class='layers_02_header'>"
    + "  <h2>" + title + "</h2>"
    + "  <a href='javascript:docAlert.messageOver();'><img src='/resources/img/layers_close.gif' id='image1'/></a>"
    
    + "</div>"
    + "<div class='layers_01_content'>"
    + "   <p>"
    + message
    + "   </p>"
    + "   <div class='layers_actions'>"
    + "     <a href='javascript:docAlert.messageOver();' class='alert_button'><span>" + msg.close + "</span></a>"
    + "   </div>"
    + "   <br style='clear:both;'/>"
    + "</div>"
    + "<div class='layers_01_bottom'></div>";

	bodyElt = document.getElementsByTagName('BODY')[0];
   
	var cont = document.createElement('div');
	cont.id = 'divContainer';
	cont.innerHTML = html;
	
	bodyElt.insertBefore(cont, document.body.childNodes[0]);
	document.getElementById('image1').alt=msg.close ;
	var divContainer = document.getElementById('divContainer');
	
	// center popup
	var scTop = parseInt(getScrollTop(),10);
	var scLeft = parseInt(bodyElt.scrollLeft,10);
	
	var fullHeight = getHeight(); 
	var fullWidth = (docAlert.is_ie ? bodyElt.offsetWidth : window.innerWidth);
		
	divContainer.style.position = "absolute";
    divContainer.style.display = "block";
    divContainer.style.top = scTop + (fullHeight) / 2 - (divContainer.offsetHeight) / 2 + "px";
    divContainer.style.left = ((fullWidth - 501) / 2) + "px";
    divContainer.style.zIndex = 21;
    if (Cufon)                                                                         
    {                                                                                          
    	Cufon.refresh();                                                       
    }
    if (docAlert.protection != null) {
    	docAlert.protection.show();
    }

    docAlert.callback = callback;	
}

// ------------------------------------------------------------------------------------
// --   PROGRESS DIALOG
// --   Utilisation de la barre de progression :
// --   // Affichage de la barre de progression
// --   window.setTimeout("docAlert.progressDialog(true)", 100);						    
// --	// envoi du formulaire
// --	sendForm();  <-- le sendForm doit absolument rester dans le thread principal (pas de window.setTimeout)
// --   // progression de la barre d'upload
// --   window.setTimeout("docAlert.progressBarStart()", 700);		
// ------------------------------------------------------------------------------------
docAlert.progressDialog = function()
{
	docAlert.progressDialogWithOptions(true);
}

docAlert.progressDialogWithOptions = function(showCloseButton, title)
{
   docAlert.init();
   var titleUsed = title ? title : msg.progress; 
   var html =
      "<div class='layers_02_header'>"
    + "  <h2>" + titleUsed + "</h2>";
   
    if (showCloseButton)
    {
    	html += "  <a href='javascript:docAlert.progressBarStop();'><img src='/resources/img/layers_close.gif' id='image3'/></a>"
    }
    html+=
	  "</div>"
    + "<div class='layers_01_content'>"
    + "   <div class='progress_bar'>"
    + "		 <div id='progress_bar_start' class='progress_bar_start'><span id='progressSpan' style='width:0px; float:left; overflow:hidden;'><img src='/resources/img/progress_bar_start.jpg'/></span><img style='float:left' src='/resources/img/progress_bar_end.jpg'/></div>"
    + "      <span class='progress_value' id='progress_value'>0%</span>"
    + "   </div>"
    + "   <div style='text-align: center; margin:auto;'>"
    + "     <span id='operation_message' style='display:block;'>&#160;</span>"  
    + "   </div>"
    + "   <br style='clear:both;'/>"
    + "</div>"
    + "<div class='layers_01_bottom'></div>";

	bodyElt = document.getElementsByTagName('BODY')[0];
   
	var cont = document.createElement('div');
	cont.id = 'divUpload';
	cont.innerHTML = html;
	
	bodyElt.insertBefore(cont, document.body.childNodes[0]);
	if (showCloseButton)
	{
		document.getElementById('image3').alt=msg.close ;
	}
	var divContainer = document.getElementById('divUpload');
	
	// center popup
	var scTop = parseInt(getScrollTop(),10);
	var scLeft = parseInt(bodyElt.scrollLeft,10);
	
	var fullHeight = getHeight(); 
	var fullWidth = (docAlert.is_ie ? bodyElt.offsetWidth : window.innerWidth);
		
	divContainer.style.position = "absolute";
    divContainer.style.display = "block";
    divContainer.style.top = scTop + (fullHeight) / 2 - (divContainer.offsetHeight) / 2 + "px";
    divContainer.style.left = ((fullWidth - 501) / 2) + "px";
    divContainer.style.zIndex = 21;
    if (window.pngFix)                                                                         
    {                                                                                          
    	pngFix.fixAllByTagName(["img"]);                                                       
    }
    
	if (typeof(HTMLArea) != "undefined" && HTMLArea.protection != null)
    {
    	HTMLArea.protection.show();	
    }
    else
    {
    	docAlert.protection.show();
    }
}

docAlert.timeoutId;

docAlert.progressBarStart = function()
{
	var total = "";
	var sent = "";
	var finished = "";

	var timestamp = new Date().getTime();

	var result = Tools.getFromUrl("/upload-progress-status?timestamp=" + timestamp);
	if (result != null)
	{
		sent = Tools.getFromXML(result,"sent");
		total = Tools.getFromXML(result,"total");
		finished = Tools.getFromXML(result,"finished");
		if (sent != null && total != null)
		{
			var ratio = sent / total;
			document.getElementById('progress_value').innerHTML = Math.floor(ratio * 100) + 1 + '%';
			document.getElementById('progressSpan').style.width = ratio * 434 + 'px';
		}
		else
		{
			finished = "true";
		}		
	}
	if (finished != 'true')
	{
		this.timeoutId = window.setTimeout("docAlert.progressBarStart()", 500);
	}
	else
	{
		window.setTimeout("docAlert.progressBarStop()", 20);	
	}
}

docAlert.fakeProgressBarStart = function(currentFakeRatio)
{
	// docAlert.protection.show();
	var newFakeRatio = currentFakeRatio + 0.1;
	newFakeRatio = newFakeRatio > 1 ? 0 : newFakeRatio;
	
	var progressValueSpan = document.getElementById('progress_value');
	if (progressValueSpan != null && typeof progressValueSpan != "undefined") {
		document.getElementById('progress_value').innerHTML = "";
		document.getElementById('progressSpan').style.width = newFakeRatio * 434 + 'px';
	}
	
	setTimeout("docAlert.fakeProgressBarStart(" + newFakeRatio + ");", "100");
}


docAlert.progressBarStop = function()
{
	window.clearTimeout(docAlert.timeoutId);
	var divContainer = document.getElementById('divUpload');
  	divContainer.parentNode.removeChild(divContainer);
  	docAlert.protection.hide();	
  	if (typeof HTMLArea != "undefined" && HTMLArea.protection != null)
  	{
  		HTMLArea.protection.hide();
  	}
}

docAlert.messageOver = function()
{
  var divContainer = document.getElementById('divContainer');
	
  divContainer.parentNode.removeChild(divContainer);
  if (docAlert.protection != null) {
	  docAlert.protection.hide();
  }
  
  if (typeof (docAlert.callback) == "function")
  {
    docAlert.callback();
  }
}

docAlert.setProgressBarOperationMessage = function(message)
{	
	document.getElementById("operation_message").innerHTML = message;
}

// ------------------------------------------------------------------------------------
// --   CONFIRM BOX
// ------------------------------------------------------------------------------------
docAlert.confirm = function(title, message, forAllOptionDisplayed, callback, fixTop)
{
  docAlert.init(); 
  var html = 
      "<div class='layers_02_header'>"
    + "  <h2>" + title + "</h2>"
    + "  <a href='javascript:docAlert.confirmNok();'><img src='/resources/img/layers_close.gif' id='image4'/></a>"
    + "</div>"
    + "<div class='layers_01_content'>"
    + "   <p>"
    + message
    + "   </p>"
    + "   <div class='layers_actions'>"
    + "     <a href='javascript:docAlert.confirmNok();' class='alert_button'><span>" + msg.no + "</span></a>"
    + "     <a href='javascript:docAlert.confirmOk();' class='alert_button'><span>" + msg.yes + "</span></a>"
    + "   </div>"
    + "   <br style='clear:both;'/>"
    + "</div>"
    + "<div class='layers_01_bottom'></div>";

    bodyElt = document.getElementsByTagName('BODY')[0];
   
	var cont = document.createElement('div');
	cont.id = 'divContainer';
	cont.innerHTML = html;
	
	bodyElt.insertBefore(cont, document.body.childNodes[0]);
	
	var divContainer = document.getElementById('divContainer');
	document.getElementById('image4').alt = msg.close;
	
	// center popup
	var scTop = parseInt(getScrollTop(),10);
	var scLeft = parseInt(bodyElt.scrollLeft,10);
	
	var fullHeight = getHeight(); 
	var fullWidth = (docAlert.is_ie ? bodyElt.offsetWidth : window.innerWidth);
	
    divContainer.style.position = "absolute";
    divContainer.style.display = "block";
    if (fixTop > 0)
    {
    	divContainer.style.top = fixTop + "px";
    }
    else
    {
    	divContainer.style.top = scTop + (fullHeight) / 2 - (divContainer.offsetHeight) / 2 + "px";
    }
    divContainer.style.left = ((fullWidth - 501) / 2) + "px";
    divContainer.style.zIndex = 21;
    
    if (window.pngFix)
    {                                                                                          
    	pngFix.fixAllByTagName(["img"]);                                                       
    } 

    if (Cufon)
    {
    	Cufon.refresh();
    }

    docAlert.protection.show();

    docAlert.callback = callback;
}

docAlert.confirmOk = function()
{
	docAlert.answer = docAlert.ANSWER_YES;
	try {
		if (typeof (docAlert.callback) == "function")
	    {
	       docAlert.callback(docAlert.answer);
	    }
	} finally {
		var divContainer = document.getElementById('divContainer');
		divContainer.parentNode.removeChild(divContainer);
	    docAlert.protection.hide();
	}
}

docAlert.confirmNok = function()
{
	var divContainer = document.getElementById('divContainer');
	
	divContainer.parentNode.removeChild(divContainer);
    docAlert.protection.hide();
	
	docAlert.answer = docAlert.ANSWER_NO;
	if (typeof (docAlert.callback) == "function")
    {
       docAlert.callback(docAlert.answer);
    }
}



// ------------------------------------------------------------------------------------
// --   ACCEPT-DECLINE BOX
// --   TODO : - créer des boutons "J'accepte" / "Je refuse"
// --          - Ajouter une checkBox pour se souvenir de la décision.
// ------------------------------------------------------------------------------------
docAlert.accept = function(title, message, showCheckbox, forAllOptionDisplayed, callback , type)
{
  docAlert.init(); 
  var html = 
      "<div class='layers_02_header'>"
    + "  <h2>" + title + "</h2>"
    + "  <a href='javascript:docAlert.acceptNok();'><img src='/resources/img/layers_close.gif' id='image7'/></a>"
    + "</div>"
    + "<div class='layers_01_content'>"
    + "   <div id='content-message' style='margin-right:15px'>"
    + "   </div>";
    if (showCheckbox)
    {
	  	html = html 
	    + "   <div class='layers_remember'>"
	    + "     <input id='check-remember' class='check' type='checkbox' name='" + type + "'/>"
	    + "     <label for='check-remember'>" + msg.windowHide + "</label>"
	    + "</div>";
    }
  	html = html
    + "   <div class='layers_actions'>"
    + "     <a href='javascript:docAlert.acceptNok();' class='alert_button'><span>" + msg.refuse + "</span></a>"
    + "     <a href='javascript:docAlert.setDecision();javascript:docAlert.acceptOk();' class='alert_button'><span>" + msg.accept + "</span></a>"
    + "   </div>"
    + "   <br style='clear:both;'/>"
    + "</div>"
    + "<div class='layers_01_bottom'></div>";

    bodyElt = document.getElementsByTagName('BODY')[0];
   
	var cont = document.createElement('div');
	cont.id = 'divContainer';
	cont.innerHTML = html;
	
	bodyElt.insertBefore(cont, document.body.childNodes[0]);
	
	if (message == "")
	{
		document.getElementById('content-message').innerHTML = document.getElementById('message').innerHTML + "<p> </p>";
	}
	else 
	{
		document.getElementById('content-message').innerHTML = message + "<p> </p>";
	}
	
	
	var divContainer = document.getElementById('divContainer');
	document.getElementById('image7').alt=msg.close;
	// center popup
	var scTop = parseInt(getScrollTop(),10);
	var scLeft = parseInt(bodyElt.scrollLeft,10);
	
	var fullHeight = getHeight(); 
	var fullWidth = (docAlert.is_ie ? bodyElt.offsetWidth : window.innerWidth);
	
    divContainer.style.position = "absolute";
    divContainer.style.top = scTop + (fullHeight) / 2 - (divContainer.offsetHeight) / 2 + "px";
    divContainer.style.left = ((fullWidth - 501) / 2) + "px";
    divContainer.style.zIndex = 21;
    if (window.pngFix)                                                                         
    {                                                                                          
    	pngFix.fixAllByTagName(["img"]);                                                       
    } 
    
    if (Cufon)
    {
    	Cufon.refresh();
    }
    
    docAlert.show = true;
	
	docAlert.callback = callback;

	
	var args = type+"=1";
    var result = Tools.postFromUrl("/load-show-dialog",args);
    
    if (result != null){

		docAlert.show = Tools.getFromXML(result, "decision");
		
	}else{
		docAlert.message("<i18n:text i18n:key='WORKSPACE_DIALOG_SERVER_ERROR'/>", "<i18n:text i18n:key='WORKSPACE_DIALOG_SERVER_ERROR_MSG'/>");
	}

	if (docAlert.show == '0')
	{
		docAlert.acceptOk();
	}
	else
	{
		divContainer.style.display = "block";
		docAlert.protection.show();
	}
}

docAlert.acceptOk = function()
{
	var divContainer = document.getElementById('divContainer');
		
	divContainer.parentNode.removeChild(divContainer);
    docAlert.protection.hide();
  	
	docAlert.answer = docAlert.ANSWER_YES;
	if (typeof (docAlert.callback) == "function")
    {
       docAlert.callback(docAlert.answer);
    }
}

docAlert.setDecision = function()
{
	if(document.getElementById('check-remember') && document.getElementById('check-remember').checked){
		var args = document.getElementById('check-remember').name+"=1";
		var result = Tools.getFromUrl("/update-show-dialog?"+args);
	}
}

docAlert.acceptNok = function()
{
	var divContainer = document.getElementById('divContainer');
	
	divContainer.parentNode.removeChild(divContainer);
    docAlert.protection.hide();
	
	docAlert.answer = docAlert.ANSWER_NO;
	if (typeof (docAlert.callback) == "function")
    {
       docAlert.callback(docAlert.answer);
    }
}




// 
// ------------------------------------------------------------------------------------
// --   INLINE HELP
// ------------------------------------------------------------------------------------
docAlert.showInlineHelp = function(eltId, e)
{
    docAlert.init(); 
    
    if(e == undefined)
       e = event;
	
	// now : let's replace help's content by the default message if no content
	var inlineHelpContent = document.getElementById(eltId + '-content');
	if (inlineHelpContent.getElementsByTagName("p").length == 0)
	{
		var html = "   <p>"
				    + inlineHelpContent.getAttribute('default_message')
				    + " </p>";
		inlineHelpContent.innerHTML = html;
	} 
	
	var divContainer = document.getElementById('dialog-' + eltId);
	var inlineHelpWidget = document.getElementById(eltId);
	
	// place popup
	var absoluteY = e.clientY;
	var absoluteX = e.clientX;//parseInt(bodyElt.scrollLeft,10);
	
	// save widget position for ie6 
	docAlert.isIeSix = Tools.agt.indexOf("msie 6") != -1;
	docAlert.inlinehelp = {};
	docAlert.inlinehelp.minX = absoluteX - inlineHelpWidget.width;
	docAlert.inlinehelp.maxX = absoluteX + inlineHelpWidget.width;
	docAlert.inlinehelp.minY = absoluteY - inlineHelpWidget.height;
	docAlert.inlinehelp.maxY = absoluteY + inlineHelpWidget.height;
	docAlert.inlinehelp.eltId = eltId;
	
		
	divContainer.style.position = "absolute";
    divContainer.style.display = "block";
    docAlert.moveInlineHelp(divContainer, absoluteX, absoluteY);
    divContainer.style.zIndex = 21;
	if (docAlert.isIeSix)
	{
    	// traitement spécial ie6 : utilisation du protect layer pour preserver de certains bugs d'affichage 
    	docAlert.protection.setEventListener("onmousemove", docAlert.mousemoveIeSixInlineHelp);
    	docAlert.protection.setOpacity(0);
   	 	docAlert.protection.show();
	}
	else
	{
	    // save old listener before setting new one
	    docAlert._oldDocumentOnmousemove = document.onmousemove;
	    document.onmousemove = docAlert.mousemoveInlineHelp;
    }

}

docAlert.moveInlineHelp = function(divContainer, absoluteX, absoluteY)
{
	bodyElt = document.getElementsByTagName('BODY')[0];
	var fullHeight = getHeight(); 
	var fullWidth = (docAlert.is_ie ? bodyElt.offsetWidth : window.innerWidth);
	var scTop = parseInt(getScrollTop(),10);
	
    // top of the popup
    var popupTop = scTop + absoluteY + 5;
    if (popupTop > scTop + fullHeight - divContainer.offsetHeight)  // popup dépasse en bas
    	popupTop = popupTop - divContainer.offsetHeight - 10;
    if (popupTop < scTop)  // popup dépasse en haut
    	popupTop = scTop;
    divContainer.style.top = popupTop + "px";
    // left of the popup
    var popupLeft = absoluteX + 5;// - (divContainer.offsetWidth / 2);
    if (popupLeft + divContainer.offsetWidth > fullWidth - 20) // popup depasse à droite
    	popupLeft = fullWidth - divContainer.offsetWidth - 20;
    if (popupLeft < 0) // popup dépasse à gauche
    	popupLeft = 0;
    divContainer.style.left = popupLeft + "px";
}
    	
// used if not ie6
docAlert.mousemoveInlineHelp = function(e)
{
    if(e == undefined)
       e = event;
	var ih = docAlert.inlinehelp;
	var divContainer = document.getElementById('dialog-' + ih.eltId);
	var mouseX = e.clientX;
	var mouseY = e.clientY;

	docAlert.moveInlineHelp(divContainer, mouseX, mouseY);	
}
    	
// move under ie6 -> detect if mouse out of widget
docAlert.mousemoveIeSixInlineHelp = function(e)
{
    if(e == undefined)
       e = event;
	var ih = docAlert.inlinehelp;
	var divContainer = document.getElementById('dialog-' + ih.eltId);
	var mouseX = e.clientX;
	var mouseY = e.clientY;

	if (mouseX < ih.minX  || mouseX > ih.maxX || mouseY < ih.minY || mouseY > ih.maxY)
	{
		// for i6 we use saved widget-position to know if mouse's out of the widget and must be hidden
		docAlert.hideInlineHelp();
	}
	else
	{
   		docAlert.moveInlineHelp(divContainer, mouseX, mouseY);	
	}
}

docAlert.mouseoutInlineHelp = function(e)
{
    if(e == undefined)
       e = event;
     
     // hide only not ie6. ie6 hides in mousemove  
	if (!docAlert.isIeSix)
	{ 
		docAlert.hideInlineHelp(e);
	}
}


docAlert.hideInlineHelp = function(e)
{
    if(e == undefined)
       e = event;
	var ih = docAlert.inlinehelp;
	var divContainer = document.getElementById('dialog-' + ih.eltId);
	var inlineHelpWidget = document.getElementById(ih.eltId);
	if (divContainer != null)
	{
	   		divContainer.style.display = "none";
	}
	// detach events
	if (docAlert.isIeSix)
	{
	    docAlert.protection.removeEventListener("onmousemove", docAlert.mousemoveIeSixInlineHelp);
		docAlert.protection.hide();
	    docAlert.protection.setOpacity(40);
    }
    else
    {
    	document.onmousemove = docAlert._oldDocumentOnmousemove;
    }
      //SUtilities.detachEvent(inlineHelpWidget, "mousemove", docAlert.mousemoveInlineHelp);
}



// ------------------------------------------------------------------------------------
// --   UTILS
// ------------------------------------------------------------------------------------
function getScrollTop() {
	if (self.pageYOffset) // sauf IE
	{
		return self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6
	{
		return document.documentElement.scrollTop;
	}
	else if (document.body) // autres IE
	{
		return document.body.scrollTop;
	}
}

function getScrollLeft() {
	if (self.pageXOffset) // sauf IE
	{
		return self.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.scrollLeft)
	{	// Explorer 6 
		return document.documentElement.scrollLeft;
	}
	else if (document.body) // autres IE
	{
		return document.body.scrollLeft;
	}
}

function getHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 

	return window.undefined; 
}

function showToolTip(eltId, e)
{
	eltId = eltId.id;
    docAlert.init(); 
    
    if(e == undefined)
       e = event;
	var divId = eltId.split("-");
	eltId = divId[0];
	var divContainer = document.getElementById('dialog-' + eltId);
	var toolTipWidget = document.getElementById(eltId);
	
	// place popup
	var absoluteY = e.clientY;
	var absoluteX = e.clientX;//parseInt(bodyElt.scrollLeft,10);
	
	// save widget position for ie6 
	docAlert.isIeSix = Tools.agt.indexOf("msie 6") != -1;
	docAlert.inlinehelp = {};
	docAlert.inlinehelp.minX = absoluteX - toolTipWidget.clientWidth;
	docAlert.inlinehelp.maxX = absoluteX + toolTipWidget.clientWidth;
	docAlert.inlinehelp.minY = absoluteY - toolTipWidget.clientHeight;
	docAlert.inlinehelp.maxY = absoluteY + toolTipWidget.clientHeight;
	docAlert.inlinehelp.eltId = eltId;
	
		
	divContainer.style.position = "absolute";
    divContainer.style.display = "block";
    docAlert.moveInlineHelp(divContainer, absoluteX, absoluteY);
    divContainer.style.zIndex = 21;
	if (docAlert.isIeSix)
	{
    	// traitement spécial ie6 : utilisation du protect layer pour preserver de certains bugs d'affichage 
    	docAlert.protection.setEventListener("onmousemove", docAlert.mousemoveIeSixInlineHelp);
    	docAlert.protection.setOpacity(0);
   	 	docAlert.protection.show();
	}
	else
	{
	    // save old listener before setting new one
	    docAlert._oldDocumentOnmousemove = document.onmousemove;
	    document.onmousemove = docAlert.mousemoveInlineHelp;
    }

}

function mouseoutToolTip(e)
{
    if(e == undefined)
       e = event;
     
     // hide only not ie6. ie6 hides in mousemove  
	if (!docAlert.isIeSix)
	{ 
		docAlert.hideInlineHelp(e);
	}
}

/*
 * callback(choiceValue) if ok, callback(null) if cancel or close
 * 
 */
docAlert.askChoiceWithSelect = function(title, message, choices, callback)
{
	var optionsHtml = '';
    for (var choiceIndex in choices)
    {
      var choice = choices[choiceIndex];
      optionsHtml += "<option value='" + choice.value + "'>" + choice.text + "</option>";
    }
	   
    var messageHtml = (message != null && (typeof message != 'undefined')) ? ("<p>" + message + "</p>") : "";
    var selectHtml = "<select id='binary-dialog-select' name='binary-dialog-select' class='supression_rubrique'>" + optionsHtml + "</select>"; 
    var wholeHtml = messageHtml + selectHtml;

    docAlert.confirm(title, wholeHtml, null, function () {
    	if (this.answer == 0) {
    		// cancel
    		callback(null);
    	} else if (this.answer == 1) {
    		// ok
        	var select = document.getElementById('binary-dialog-select');
        	var selectedChoiceValue = select.options[select.selectedIndex].value; 
        	callback(selectedChoiceValue);
    	}
    });
    
}

docAlert.askChoiceWithList = function(title, message, choices, callback)
{
	var optionsHtml = '';
    for (var choiceIndex in choices)
    {
      var choice = choices[choiceIndex];
      if (typeof choice == "object")
      {
    	  var checkedString = (choiceIndex == 0) ? " checked='true' " : '';
    	  optionsHtml += "<li style='cursor: pointer'><input style='float:left; margin-top:-2px;' type='radio' class='radio_layer' name='choice-dialog-li' " + checkedString + " value='" + choice.value + "' /><div onclick='this.parentNode.getElementsByTagName(\"input\")[0].checked=\"checked\"; return false;'>" + choice.text + "</div></li>"
      }
    }
    
    var messageHtml = (message != null && (typeof message != 'undefined')) ? ("<p>" + message + "</p>") : "";
    var selectHtml = "<div class='layer_list'>" + "<ul>" + optionsHtml +  "</ul> </div>"; 
    var wholeHtml = messageHtml + selectHtml;
    	
    docAlert.confirm(title, wholeHtml, null, function () {
    	if (this.answer == 0) {
    		// cancel
    		callback(null);
    	} else if (this.answer == 1) {
    		// ok
    		var liElements = document.getElementsByName("choice-dialog-li");
    		var selectedValue = null;
    		
	        var i = 0;
	        while (i < liElements.length)
	        {
	            if (liElements.item(i).checked == true)
	            {
	            	selectedValue = liElements.item(i).value;
	                break;
	            }
	            i++;
	        }
        	
        	callback(selectedValue);
    	}
    });
    
}


