/*
 function zwmClickElem (event){
	if(event.type==="click"){
        alert("Fa\356tes glisser l'\351l\351ment choisi (Section, Question, ...) vers l'endroit o\371 vous souhaitez l'ins\351rer dans le formulaire");
 	}
    event.stopPropagation();//sinon gere les td parents
}
*/
var urlDrop="";

function UrlDrop_set(){
	urlDrop="";
	return "";
}
function UrlDrop_get(){
	return urlDrop;
}
function zwmChangeText (zeTxt, zeId, zePct){
    var zeSelector_progress='#'+"tbl_progress";
    var zeSelector_barre="#"+"avancement";
	var zeSelector_td="#"+"td_progress";
	var zeSelector_menu='#'+"menu_elem";
	
    if(zeId!=''){
        var zeSelector='#'+zeId;
        if($(zeSelector).length>0){
        	$(zeSelector).empty();
			if(zeTxt=="_start_"){
				//$(zeSelector_barre).value="0";
				$(zeSelector_td).css("width", "0%");
				$(zeSelector).html("Conversion en cours");

				$(zeSelector_progress).removeClass("disp_none");
				$(zeSelector_menu).addClass("disp_none");
			}else if(zeTxt==="_end_"){
				//$(zeSelector_barre).value="100";
				$(zeSelector_td).css("width", "100%");

				$(zeSelector_progress).addClass("disp_none");
				$(zeSelector_menu).removeClass("disp_none");
				window.scrollTo(0,1); //update
				window.scrollTo(0,0); //update
			}else{
				//$(zeSelector_barre).value=""+zePct;
				$(zeSelector_td).css("width", ""+zePct+"%");
				$(zeSelector).html(zeTxt);
			}
		}
        return "ok";
    }
    return "err";
}

$(document).ready(function() {
    var bShowToolTip=true; // false : pour tester plantages
    var $tooltip;
                  
    var elemTrouve = function(zeElem){
                  if(typeof(zeElem) != "undefined"){
                    if(zeElem.length>0) return true;
                  }
                  return false;
    }

    if(bShowToolTip){
		  var $tooltipExist = $('#tooltip').eq(0);
		  if(elemTrouve($tooltipExist)){
			var $tooltip = $('#tooltip');
			$tooltip.hide();
		  }else{
			var $tooltip = $('<div id="tooltip"></div>').appendTo('body');
			$tooltip.hide();

		  }
		  var sMsg = "Glisser/d\351poser sur le formulaire";
		  $tooltip.html(sMsg);
    }
    var positionTooltip = function(event){
                if(bShowToolTip){
                    var tPosX = event.pageX;
                    var tPosY = event.pageY + 10;
					var wHeight = $( window ).height();

                  	var posXYElem = $(this).offset();
                	var posYElem = 0;

                  	if(posXYElem){
                		posYElem = posXYElem.top;
                  	}
                  	if(posYElem > 0){
                    	tPosY = posYElem + 17;
                    	if((tPosY + 20) > wHeight){
                    		tPosY = posXYElem.top - 35;
                    	}
                  	}
                  	$tooltip.css('top',tPosY);
                  	$tooltip.css('left',tPosX);
                }
            };//positionTooltip
                  
    var timeoutID;
    var showTooltip = function(event){
        if(bShowToolTip) {
            //var sMsg = "Glisser/d\351poser sur le formulaire";
            if(timeoutID) window.clearTimeout(timeoutID);

            $tooltip
                  .show();
            timeoutID = window.setTimeout(hideTooltip, 1500);
            positionTooltip(event);
        }//bShowToolTip
    };//showTooltip
                  
    var hideTooltip = function(){
        $tooltip.hide();
    };
    var zeSelector = "img"; //"td:not(:empty)";
    if(bShowToolTip){
            $(document).on('mouseenter',zeSelector, showTooltip);
            $(document).on('mousemove',zeSelector, positionTooltip);
            $(document).on('mouseleave',zeSelector, hideTooltip);
    }
              
	//$(document).on('click',zeSelector, zwmClickElem);
   // $(document).on('dblclick',zeSelector, zwmClickElem);
                 
	$(document).on('selectstart',function(){hideTooltip; return false;}); //interdit sel de texte
	//$(document).on('dragstart',function(){hideTooltip;});

	$(document).on('dragend',function(){
				var $img = $("td").find("img[src]");//.eq(0);
				if($img.length>0){
					var $td = $img.closest("td");//.eq(0);
					if($td.length>0){
						$td.each(function() {
							var zeHtml= $( this ).html();
							$( this ).html(zeHtml);
						});
					}
				}
				urlDrop="url";

				 return true;
				 });

});