function GL_checkBrowser(){
	this.dom= (document.getElementById);
	this.op=this.opera= (navigator.userAgent.indexOf("Opera")>-1);
	this.konq=  (navigator.userAgent.indexOf("Konq")>-1);
	this.ie4= (document.all && !this.dom && !this.op && !this.konq);
	this.ie5= (document.all && this.dom && !this.op && !this.konq);
	this.ns4= (document.layers && !this.dom && !this.konq);
	this.ns5= (!document.all && this.dom && !this.op && !this.konq);
	this.ns6= (this.ns5);
	this.bw=  (this.ie4 || this.ie5 || this.ns4 || this.ns6 || this.op || this.konq);
	return this;
}
bw= new GL_checkBrowser();

	//Returns css
function GL_getObjCss(obj){								
	return bw.dom? document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?document.layers[obj]:0;
};
function jsStyle(obj){								
	return bw.dom? document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?document.layers[obj]:0;
};
function jsObj(obj){								
	return bw.dom? document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?document.layers[obj]:0;
};

function showDiv(id)
{
	etat = GL_getObjCss(id).display;
	switch(etat)
	{
		case "none": GL_getObjCss(id).display="block"; break;
		case "block": GL_getObjCss(id).display="none"; break;
	}
}
function showDivForm(id, inputH)
{
	etat = GL_getObjCss(id).display;
	switch(etat)
	{
		case "none": GL_getObjCss(id).display="block"; document.forms[0].elements[inputH].value='0'; break;
		case "block": GL_getObjCss(id).display="none"; document.forms[0].elements[inputH].value='1'; break;
	}
	//alert(document.forms[0].elements[inputH].value);
}

function confirmation(text, wheretogo)
{
	if(confirm(text.replace('<br>', '\n'))) window.location.href= wheretogo;
}

function rechercher(text, wheretogo, pattern, getParam)
{
	var find;
	find=prompt(text, '');
	if(find)
	{
		find = find.replace("'", "\\'");
		window.location.href = wheretogo + "?find=" + escape(pattern.replace( "#VAL#", find))+ getParam;
	}
}

function ssaction(text, formname, val)
{
	if(!text || (text && confirm(text))) 
	{
		document.forms[formname].ssaction.value = val;
		pos = document.documentElement.scrollTop;
		document.forms[formname].posTop.value= pos;
		if(isDefined('isRichText')) updateRTEs();
		document.forms[formname].submit();
	}
}

function ajouteOption(formname, fieldname, stchaine, stid)
{
		var nb = document.forms[formname].elements[fieldname].options.length;
		//alert(nb);
		//var stchaine = new String('<?=addslashes($val)?>');
		//var stid = new String('<?=$id?>');
		//no = new Option( stchaine, stid, 0, 1);
		no = new Option( stchaine, stid, 0, 1);
		document.forms[formname].elements[fieldname].options[nb]= no;
		document.forms[formname].elements[fieldname].selectedIndex= nb;
}

function jsOpen(page, title, params)
{
	var w = window.open(page, title, params);
	w.focus();
}

function showDefault(div)
{
	jsStyle(div).display = 'block';
	if(tempX<850)
	{
		jsStyle(div).top = (tempY-20)+'px';
		jsStyle(div).left = (tempX+10)+'px';
	}
	else
	{
		jsStyle(div).top = (tempY-20)+'px';
		jsStyle(div).left = (tempX-160)+'px';
	}
}


//___________________________positionne un div par rapport à la souris
function showMouseDiv(div, dX, dY)
{
	jsStyle(div).display = 'block';
	jsStyle(div).top = (tempY+dY)+'px';
	jsStyle(div).left = (tempX+dX)+'px';
}

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
if(!isDefined('noMouseMoveEvent')) noMouseMoveEvent = 0;
if(!noMouseMoveEvent) document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s


function getMouseXY(e) {

  if (IE) { // grab the x-y pos.s if browser is IE
  tempX = event.clientX + document.documentElement.scrollLeft;
  tempY = event.clientY + document.documentElement.scrollTop;
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX;
    tempY = e.pageY;
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  return true;
}



var charArray = new Array(
	' ', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-',
	'.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';',
	'<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
	'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
	'X', 'Y', 'Z', '[', '\\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e',
	'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
	't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', '', 'Ç', 'ü',
	'é', 'â', 'ä', 'à', 'å', 'ç', 'ê', 'ë', 'è', 'ï', 'î', 'ì', 'Ä', 'Å',
	'É', 'æ', 'Æ', 'ô', 'ö', 'ò', 'û', 'ù', 'ÿ', 'Ö', 'Ü', 'ø', '£', 'Ø',
	'×', 'ƒ', 'á', 'í', 'ó', 'ú', 'ñ', 'Ñ', 'ª', 'º', '¿', '®', '¬', '½',
	'¼', '¡', '«', '»', '_', '_', '_', '¦', '¦', 'Á', 'Â', 'À', '©', '¦',
	'¦', '+', '+', '¢', '¥', '+', '+', '-', '-', '+', '-', '+', 'ã', 'Ã',
	'+', '+', '-', '-', '¦', '-', '+', '¤', 'ð', 'Ð', 'Ê', 'Ë', 'È', 'i',
	'Í', 'Î', 'Ï', '+', '+', '_', '_', '¦', 'Ì', '_', 'Ó', 'ß', 'Ô', 'Ò',
	'õ', 'Õ', 'µ', 'þ', 'Þ', 'Ú', 'Û', 'Ù', 'ý', 'Ý', '¯', '´', '­', '±',
	'_', '¾', '¶', '§', '÷', '¸', '°', '¨', '·', '¹', '³', '²', '_', ' ');

var hex_digits = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
		'A', 'B', 'C', 'D', 'E', 'F');


function charToByte(c)
{
	var i;
	for(i=0; i < charArray.length; i++) {
		if(c == charArray[i]) return i+32;
	}
	return 0;
}

function byteToChar(n)
{
	if(n < 32 || n > 255) return " ";
	return charArray[n-32];
}

function byteToHex(n)
{
	return hex_digits[(n >> 4) & 0xf] + hex_digits[n & 0xf];
}

function byteToBin(n)
{
	var ret_str = "";
	var i;
	for(i=7; i>=0; i--) {
		ret_str += (n >> i) & 1;
	}
	return ret_str;
}



function clean_numstr(raw_str, base)
{
	var ret_str = "";
	var c = "";
	var i;
	for(i=0; i < raw_str.length; i++) {
		c = raw_str.charAt(i);
		if(c == "0" || parseInt(c, base) > 0) {
			ret_str += c;
		}
	}
	return ret_str;
}

function isNothing(str, theForm, form_bit)
{
	if(str == "") {
		alert("This field evaluates to nothing!");
		return false;
	}
	eval(form_bit);
	return true;
}



function hex_from_dec(theForm)
{
	var dec_str = clean_numstr(theForm.dec.value, 10);
	var delimiter = theForm.delimiter.value;
	var hex_str = "";
	var num_str = "";
	var i = 0, n;

	while(i < dec_str.length) {
		n = 0;
		if(i > 0) hex_str += delimiter;
		for(; i < dec_str.length && (n < 25 || (n == 25 && dec_str.charAt(i) < 6)); i++) {
			n *= 10;
			n += parseInt(dec_str.charAt(i));
		}
		hex_str += byteToHex(n);
	}
	return isNothing(hex_str, theForm, "theForm.hex.value = str");
}

function chars_from_hex(theForm)
{
	var hex_str = clean_numstr(theForm.hex.value, 16);
	var char_str = "";
	var num_str = "";
	var i;
	for(i=0; i < hex_str.length; i+=2)
		char_str += byteToChar(parseInt(hex_str.substring(i, i+2), 16));
	return isNothing(char_str, theForm, "theForm.chars.value = str");
}

function hex_from_chars(theForm)
{
	var char_str = theForm.chars.value;
	var delimiter = theForm.delimiter.value;
	var hex_str = "";
	var i, n;
	for(i=0; i < char_str.length; i++) {
		n = charToByte(char_str.charAt(i));
		if(n != 0) {
			if(i > 0) hex_str += delimiter;
			hex_str += byteToHex(n);
		}
	}
	return isNothing(hex_str, theForm, "theForm.hex.value = str");
}

function dec_from_hex(theForm)
{
	var hex_str = clean_numstr(theForm.hex.value, 16);
	var delimiter = theForm.delimiter.value;
	var dec_str = "";
	var dec_byte = "";
	var i;
	for(i=0; i < hex_str.length-1; i+=2) {
		if(i > 0) dec_str += delimiter;
		dec_str += parseInt(hex_str.substring(i, i+2), 16);
	}
	return isNothing(dec_str, theForm, "theForm.dec.value = str");
}

function bin_from_hex(theForm)
{
	var hex_str = clean_numstr(theForm.hex.value, 16);
	var delimiter = theForm.delimiter.value;
	var bin_str = "";
	var bin_byte = "";
	var i;
	for(i=0; i < hex_str.length-1; i+=2) {
		if(i > 0) bin_str += delimiter;
		bin_str += byteToBin(parseInt(hex_str.substring(i, i+2), 16));
	}
	return isNothing(bin_str, theForm, "theForm.bin.value = str");
}

function hex_from_bin(theForm)
{
	var delimiter = theForm.delimiter.value;
	var bin_str = clean_numstr(theForm.bin.value, 2);
	var hex_str = "";
	var i;

	for (i=0; i < bin_str.length-7; i+=8) {
		if(i > 0) hex_str += delimiter;
		hex_str += byteToHex(parseInt(bin_str.substring(i, i+8), 2));
	}
	return isNothing(hex_str, theForm, "theForm.hex.value = str");
}

function from_dec(theForm)
{
	if (hex_from_dec(theForm)) {
		bin_from_hex(theForm);
		chars_from_hex(theForm);
	}
}

function from_hex(theForm)
{
	if(bin_from_hex(theForm)){
		dec_from_hex(theForm);
		chars_from_hex(theForm);
	}
}

function from_char(theForm)
{
	if(hex_from_chars(theForm)) {
		bin_from_hex(theForm);
		dec_from_hex(theForm);
	}
}

function from_bin(theForm)
{
	if(hex_from_bin(theForm)) {
		dec_from_hex(theForm);
		chars_from_hex(theForm);
	}
}

function isDefined(variable)
{
return eval('(typeof('+variable+') != "undefined");');
}

//________________________________________ scroll un div
var doscroll = 1;
function scrollzone(iddiv, decal)
{
	var t = isDefined(jsObj(iddiv).scrollTop)?jsObj(iddiv).scrollTop:0;
	
	jsObj(iddiv).scrollTop = t+decal;
	if(doscroll) setTimeout('scrollzone("'+iddiv+'", '+decal+')', 50);
}
function initscroll(iddiv, height)
{
	var h = jsObj('scroll'+iddiv).scrollHeight;
	//alert(h+' '+height+' '+jsObj('scroll'+iddiv).scrollHeight);
	if(h<=height)
	{
		jsStyle('scrollup'+iddiv).display = 'none';
		jsStyle('scrolldown'+iddiv).display = 'none';
	}
}

// ______________________ QueryString

function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object()
	this.get=Querystring_get
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value
}
var q_GET = new Querystring(window.location.search.substring(1));

// __________________GESTION DES COOKIES

function EcrireCookie(nom, valeur)
{
	var argv=EcrireCookie.arguments;
	var argc=EcrireCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=nom+"="+escape(valeur)+
	((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
	((path==null) ? "" : ("; path="+path))+
	((domain==null) ? "" : ("; domain="+domain))+
	((secure==true) ? "; secure" : "");
}

function getCookieVal(offset)
{
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1) endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
function LireCookie(nom)
{
	var arg=nom+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen)
	{
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) break;
	
	}
	return null;
}

