<!--

var mouse_x, mouse_y;

function _bodySize()
{
	var body = window.document.body;
	
	var bodySize = new Object();

	bodySize.w = _div_getWidth(body);
	bodySize.h = _div_getHeight(body);

	return bodySize;
}

function _viewportSize()
{
	var viewportSize = new Object();
		
	if (typeof window.innerWidth != 'undefined')
	{
	  viewportSize.w = window.innerWidth;
	  viewportSize.h = window.innerHeight;
	}	
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0)
	{
	   viewportSize.w = document.documentElement.clientWidth;
	   viewportSize.h = document.documentElement.clientHeight;
	}
	
	else
	{
	   viewportSize.w = document.getElementsByTagName('body')[0].clientWidth;
	   viewportSize.h = document.getElementsByTagName('body')[0].clientHeight;
	}
	
	return viewportSize;
}

function _popup(path,named)
{
	var windowWidth = window.innerWidth;
	var windowHeight = window.innerHeight;
	
	var windowX = window.screenX;
	var windowY = window.screenY;

	win = window.open(path,named,'width='+windowWidth+',height='+windowHeight+',screenX='+windowWidth+',screenY='+windowY+',left='+windowX+',top='+windowY+',resizable=no,location=no,toolbar=no,directories=no,status=no,scrollbars=no,menubar=no');
}


function _isOnline()
{
	return navigator.onLine;
}

function _isIPad()
{
	return navigator.userAgent.match(/iPad/i) != null;
}

function _getBrowser()
{
	var userAgent = navigator.userAgent;

	//alert(userAgent);

	if(userAgent.indexOf('Chrome')>-1)
	{
		return 'chrome';
	}	
	else if(userAgent.indexOf('Safari')>-1)
	{
		return 'safari';
	}
	else if(userAgent.indexOf('Opera')>-1)
	{
		return 'opera';
	}
	else if(userAgent.indexOf('MSIE')>-1)
	{
		return 'ie';
	}
	else if(userAgent.indexOf('Mozilla')>-1)
	{
		return 'firefox';
	}
	else
	{
		return 'unknown';
	}
}

function _getBrowserStylesPreffix()
{
	var browserName = _getBrowser();
	
	//alert(browserName);
	
	var browser_preffix = '';

	if(browserName=='safari' || browserName=='chrome')
	{
		browser_preffix = '-webkit-';
	}
	else if(browserName=='firefox')
	{
		browser_preffix = '-moz-';
	}
	else if(browserName=='opera')
	{
		browser_preffix = '-o-';
	}
	else if(browserName=='ie')
	{
		browser_preffix = '-ms-';
	}
	else
	{
		browser_preffix = '';
	}
		
	return browser_preffix;
}

function _linkToPage(pagename)
{
	window.location.href = 'index.php?pn='+pagename;
}

/* Validation du formulaire de connexion */
function form_key_validate(theevent,formname,todo)
{
	var thekey = window.event ? theevent.keyCode : theevent.which;
	var car = String.fromCharCode(thekey);

	if( thekey == 13 )
	{
		document.forms[formname].elements['todo'].value = todo;
		document.forms[formname].submit();
		return false;
	}
	
	return car;
}

/* Fonction de fermeture d'une popup avec rechargement de la page ouvrante */
function popup_refresh_and_close()
{
	//alert('refresh');
	window.opener.document.location.reload();
	//alert('close');
	window.close();
}


/* FONCTIONS PERMETTANT L'AFFICHAGE D'UNE IMAGE D'ILLUSTRATION */

/* Affichage d'une information contextuelle à droite */
function contextual_info_display_right(msg)
{
	//alert('coucou');
	div_setPosition('infobulle',mouse_x,mouse_y+20);
	div_unhide('infobulle');
	div_setContent('infobulle',msg);
}


/* Affichage d'une information contextuelle */
function contextual_info_display(msg)
{
	//alert('coucou');
	div_setPosition('infobulle',mouse_x-420,mouse_y+20);
	div_unhide('infobulle');
	div_setContent('infobulle',msg);
}

/* Afichage d'une image */
function contextual_picture(path)
{
	div_setContent('contextual-picture','<img src="'+path+'">');
	div_setPosition('contextual-picture',mouse_x,mouse_y+20);
	div_unhide('contextual-picture',false);
}

/* Lecture de la position de la souris */
function get_mouse_x()
{
	return mouse_x;
}

function get_mouse_y()
{
	return mouse_y;
}

/* Initialise la capture automatique de l'evenement */
function init_MouseCapture()
{
	if(navigator.appName.substring(0,3) == "Net")
	{
		document.captureEvents(Event.MOUSEMOVE);
	}
	
	document.onmousemove = getMousePosition;
}


/* Lecture de la position de la souris */
function _mouseCoordinates(evt)
{
	var coord = new Object();
	
	coord.x = 0;
	coord.y = 0;
	
	if(evt.pageX)
	{
		coord.x = evt.pageX;
		coord.y = evt.pageY;
	}
	else if(evt.clientX)
	{
		var offsetX = 0; var offsetY = 0;
		
		if(document.documentElement.scrollLeft)
		{
			offsetX = document.documentElement.scrollLeft;
			offsetY = document.documentElement.scrollTop;
		}
		else if(document.body)
		{
			offsetX = document.body.scrollLeft;
			offsetY = document.body.scrollTop;
		}
	
		coord.x = evt.clientX+offsetX;
		coord.y = evt.clientY+offsetY;
	}

	return coord;
}


/* Lecture de la position de la souris */
function getMousePosition(e)
{
	mouse_x = (navigator.appName.substring(0,3) == "Net") ? e.pageX : event.x+document.body.scrollLeft;
	mouse_y = (navigator.appName.substring(0,3) == "Net") ? e.pageY : event.y+document.body.scrollTop;	
}


/* Charge une url dans la page ouvrante */
function opener_seturl(url)
{
	window.opener.location.href = url;
}

/* Pre-chargement d'images */
function preloadImages()
{
    var d=document; 

    if(d.images)
    {
        if(!d.MM_p) d.MM_p=new Array();
        
        var i;
        var j=d.MM_p.length,a=preloadImages.arguments;
        
        for(i=0;i<a.length;i++)
        {
            if(a[i].indexOf("#")!=0)
            {
                d.MM_p[j]=new Image;
                d.MM_p[j++].src=a[i];
            }
        }
    }
}

// Roll over sur les menus ( fonction generique )
function xant(picture, alternate, picname){
       document.images[picname].src=picture;
       //document.images[picname].alt=alternate;
       document.images[picname].title=alternate;
}

// AFFICHE UNE FENETRE POPUP
function sPopup(path,width,height){
    
	var win, completepath;
	
	completepath = path;

	win = window.open(completepath,'spopup','width='+width+',height='+height+',screenX=100,screenY=80,left=100,top=80,resizable=yes,location=no,toolbar=no,directories=no,status=no,scrollbars=yes,menubar=no');

}

// AFFICHE UNE FENETRE POPUP + parametre nom
function sPopupNamed(path,width,height,name){
    
	var win, completepath;
	
	completepath = path;

	win = window.open(completepath,name,'width='+width+',height='+height+',screenX=60,screenY=40,left=60,top=40,resizable=yes,location=no,toolbar=no,directories=no,status=no,scrollbars=yes,menubar=no');

}

function pp(path,width,height,name){

    sPopupNamed(path,width,height,name);
}

/* Soumission du formulaire pour une action todo */
function form_todo( name_form, todo)
{
	document.forms[name_form].elements['todo'].value = todo;
	document.forms[name_form].submit();
}

/* Soumission du formulaire pour une action todo */
function form_todo_adv( name_form, todo, action, id_subitem)
{
	document.forms[name_form].elements['id_subitem'].value = id_subitem;
	document.forms[name_form].elements['todo'].value = todo;
	document.forms[name_form].submit();
}

/* Soumission du formulaire pour une action todo */
function tool_form_todo_adv( name_form, todo, action, id_subitem)
{
	document.forms[name_form].action = 'tool.php?keyname='+action;
	document.forms[name_form].elements['id_subitem'].value = id_subitem;
	document.forms[name_form].elements['todo'].value = todo;
	document.forms[name_form].submit();
}


/* Activation de tous les elements d'une boite de selection */
function select_selectall( form_name, select_name, select_or_not )
{
	var i = 0;
	var end = false;
	
	src_select = document.forms[form_name].elements[select_name];
	
	while( src_select.options[i] != null )
	{  	
		document.forms[form_name].elements[select_name].options[i].selected = select_or_not;
		i++;
    }
}

/* Activation d'un élément de la checklist */
function checklist_item_switch( basename, index )
{
		elt = document.getElementById( basename+index );
		if(elt.checked)
		{
			elt.checked = false;
		}
		else
		{
			elt.checked = true;
		}
}


/* Activation de tous les elements de la checklist */
function checklist_checkall( basename, check_or_not )
{
	i=0;
	var elt;
	
	while( typeof(document.forms['form_main'].elements[basename + i]) != 'undefined' )
	{  
		elt = document.getElementById( basename+i );
		elt.checked = check_or_not;
		i++;
    }
}


/* copie d'une selection d'elements d'un select vers un select destination */
function select2select( form_name, src_name, dst_name )
{
    var src_select = document.forms[form_name].elements[src_name];
	var dst_select = document.forms[form_name].elements[dst_name];

    var src_count  = src_select.length;
	var dst_count  = dst_select.length;

	//alert(src_count);

	var new_option;

	var end = false;
	var i = 0;

	while(!end)
	{
		if( src_select.options[i] == null )
		{
			end = true;
		}
		else
		{

    		//alert( 'copie de '+ src_select.options[i].text );
    
			if ( src_select.options[i].selected == true )
			{
				//alert( 'oui  > ' + dst_count);
				
				new_option = new Option;
				
				new_option.value = src_select.options[i].value;
				new_option.text = src_select.options[i].text;
				
				dst_select.options[dst_count++] = new_option;
				
				src_select.options[i] = null;
			}
			else
			{
				i++;
			}
        }
    }

    return true;
}


/* Lecture de la largeur de la fenêtre */
function getWindowWidth()
{
    var windowWidth=0;
    
    if (typeof(window.innerWidth)=='number')
    {
        windowWidth=window.innerWidth;
    }
    else
    {
     if (document.documentElement&&
       document.documentElement.clientWidth) {
         windowWidth = document.documentElement.clientWidth;
    }
    else
    {
     if (document.body&&document.body.clientWidth) {
         windowWidth=document.body.clientWidth;
      }
     }
    }
    
    return windowWidth;
}



/* Lecture de la hauteur de la fenêtre */
function getWindowHeight()
{
    var windowHeight=0;
    
    if (typeof(window.innerHeight)=='number')
    {
        windowHeight=window.innerHeight;
    }
    else
    {
     if (document.documentElement&&
       document.documentElement.clientHeight) {
         windowHeight = document.documentElement.clientHeight;
    }
    else
    {
     if (document.body&&document.body.clientHeight) {
         windowHeight=document.body.clientHeight;
      }
     }
    }
    
    return windowHeight;
}

//-->

