function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

function set_id_display(id,display){
	document.getElementById(id).style.display = display;
}

function set_id_content(id,content){
	a = document.getElementById(id);
	if(a.innerHTML!=content) a.innerHTML = content;
}

function show_id(id,x,y)	{
	a = document.getElementById(id);
	a.style.top=y;
	a.style.left=x;
	a.style.visibility='visible';
}

function show_id_nextto(id,e)	{
	var IE = document.all?true:false;
	if (IE) { 
      sheet_x = event.clientX + document.body.scrollLeft;
      sheet_y = event.clientY + document.body.scrollTop;
	} else {
      sheet_x = e.pageX;
	  sheet_y = e.pageY;
	}
	win_x = sheet_x-document.body.scrollLeft;
	//win_x = sheet_x+window.pageXOffset;
	//win_y = sheet_y+window.pageYOffset;
	win_y = sheet_y-document.body.scrollTop;
	wh = window.innerHeight;
	ww = window.innerWidth;
	
	ow = document.getElementById(id).offsetWidth;
	oh = document.getElementById(id).offsetHeight;
	
	//document.title = "w:"+ow+"  h:"+oh;

	if(win_x<(ww/2)){
	  //On affiche a droite
	  tx = sheet_x+12;
	}else{
	  //On affiche a gauche
	  tx = sheet_x-ow-1;
	}
	if(win_y<(wh/2)){
	  //On affiche en bas
	  ty = sheet_y+1;
	}else{
	  //On affiche en haut
	  ty = sheet_y-oh-1;
	}
	document.getElementById(id).style.top=ty;
	document.getElementById(id).style.left=tx;
	document.getElementById(id).style.visibility='visible';
}

function hide_id(id)	{
	document.getElementById(id).style.visibility='hidden';
}

function midi_show(id,x,y)	{
	document.getElementById(id).style.top=y;
	document.getElementById(id).style.left=x;
	document.getElementById(id).style.visibility='visible';
}

function midi_hide(id)	{
	document.getElementById(id).style.visibility='hidden';
}

function progressBar_show(id,x,y)	{
	document.getElementById(id).style.top=y;
	document.getElementById(id).style.left=x;
	document.getElementById(id).style.visibility='visible';
}

function progressBar_hide(id)	{
	document.getElementById(id).style.visibility='hidden';
}

function progressBar_set(id,percent) {
	document.getElementById(id+'_leftc').width=percent+'%';
	document.getElementById(id+'_rightc').width=(100-percent)+'%';
}

function form_confirm_submit(txt,form_id) {
	var del=confirm(txt);
	if (del) document.getElementById(form_id).submit();
}

function getAbsX(objectId) {
	// Get an object left position from the upper left viewport corner
	// Tested with relative and nested objects
	o = objectId;
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
			oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	// Return left postion
	return oLeft
}

function getAbsY(objectId) {
	// Get an object top position from the upper left viewport corner
	// Tested with relative and nested objects
	o = objectId;
	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	// Return top position
	return oTop
}

function show_hover(txt,x,y){
	set_id_content("render_hover",txt);
	show_id("render_hover",x,y);
}

function show_hover_mouse(txt,mx,my){
	
	a = document.getElementById("render_hover");
	set_id_content("render_hover",txt);
	//set_id_content("render_hover",a.offsetWidth);
	x = mx-a.offsetWidth/2;
	y = my-2-a.offsetHeight;
	show_id("render_hover",x,y);
}

function show_hover_nextto(txt,e){
	set_id_content("render_hover",txt);
	show_id_nextto("render_hover",e);
}

function hide_hover(){
	hide_id("render_hover");
}

function seek_hover(parent){
	//return;
	//sti++;
	//oDbg.log(parent.nodeName+ ' Lvl:'+sti,1);
	//if(!parent.hasChildNodes()) return;
	var a = parent.getElementsByTagName('*');
	//a = parent.childNodes;
	var nb = a.length;
	for(var i=0;i<nb;++i){
		if(a[i].nodeName=="hover"){
			alert(a[i]);
		}
	  if(a[i].nodeType!=3){
	    //alert(a[i].nodeType);
	    var txt = a[i].getAttribute("title");
		
	    if(txt != null){
		  txt = trim(txt);
		  if(txt.length>0){
	  	    //alert(txt);
		    a[i].setAttribute("onmouseover","Tip(\""+txt+"\")");
			//a[i].setAttribute("onMouseOver","alert('bouh');");
	  	    //a[i].setAttribute("onmouseover","show_hover_mouse(\""+txt+"\",event.clientX,event.clientY)");
		    //a[i].setAttribute("onmousemove","show_hover_mouse(\""+txt+"\",event.clientX,event.clientY)");
	  	    //a[i].setAttribute("onmouseout","hide_hover()");
		    //a[i].setAttribute("title","");
		  }
	    }
	  }
	  //seek_hover(a[i],sti);
	}
	
}
