
String.prototype.htmlentities = function () {   return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');};

Array.prototype.ar_remove=function(s){
  for(i=0;i<this .length;i++){
    if(s==this[i]) this.splice(i, 1);
  }
}

Array.prototype.ar_find=function(s){
  for(i=0;i<this .length;i++){
    if(s==this[i]) return true;
  }
  return false;
}

Array.prototype.find=function(s){
  for(i=0;i<this .length;i++){
    if(s==this[i]) return true;
  }
  return false;
}

function Randomize(from, to){
	return from + Math.floor(Math.random()*to);

}


function CreateCSS(css_path){

	if(document.createStyleSheet) {
		document.createStyleSheet(css_path);
	}

	else {

		//var styles = "@import url('" + css_path + "');";
		var newSS=document.createElement('link');

		newSS.rel	='stylesheet';
		newSS.type	='text/css';
		newSS.href	= css_path;
		//newSS.href='data:text/css,'+encodeURIComponent(styles);

		document.getElementsByTagName("head")[0].appendChild(newSS);
	}
}



function gById(id){

	return document.getElementById(id);

}

function showDiv(obj){

	if(obj.style.display == 'none')
		obj.style.display = 'block';
	else
		obj.style.display = 'none';

}

var gObj;
function showDivXml(obj, url, refresh){

	if(obj.style.display == 'none'){

		if(refresh || obj.innerHTML == ''){
			gObj = obj;
			loadXMLDoc(url, 'xmldivresponse');
		}
		else
			obj.style.display = 'block';
	}
	else
		obj.style.display = 'none';

}

function xmldivresponse(text){

	gObj.innerHTML = text;
	gObj.style.display = 'block';

}

function blinkElement(elem,time_milli,nbBlink){

	if(elem.style.visibility=='hidden'){
		elem.style.visibility='visible';
		time_milli *= 10;
	}
	else{
		elem.style.visibility='hidden';
		time_milli /= 10;
	}

	if(nbBlink)
		setTimeout('blinkElement(' + elem.id + ',' + time_milli + ',' + (--nbBlink) + ');',time_milli);
	else
		elem.style.visibility='visible';

}
		
function setMaxChar(elem,outputElem,nbChar){
	
	if(elem.value.length>nbChar)
		elem.value = elem.value.substring(0,nbChar);
	
	if(nbChar-elem.value.length>1)
		outputElem.innerHTML = '<b>' + (nbChar-elem.value.length) + '</b>caractères';
	else
		outputElem.innerHTML = '<b>' + (nbChar-elem.value.length) + '</b>caractère';
	
}

function row2color( tb, spos , row1, row2){

	if(spos == undefined) { spos = 0; }
	if(row1 == undefined){ row1 = 'listG';}
	if(row2 == undefined) { row2 = 'listW'; }

	k=0;
	for(i=spos; i< tb.rows.length; i++){
		
		if(k++%2)
			tb.rows[i].className = row2;
		else
			tb.rows[i].className = row1;
		
	}

}







function mouseX(e) {
		return  e.clientX + document.body.scrollLeft;

}

function mouseY(e) {
		return  e.clientY + document.body.scrollTop;

}






function getOffsetTop(element, deep) {
   return getOffsetProperty(element, 'Top', deep);
}

function getOffsetLeft(element, deep) {
   return getOffsetProperty(element, 'Left', deep);
}

function getOffsetProperty(element, property, deep) {
   var offsetValue = 0;
   offsetProperty = 'offset' + property;
   
   do {
      offsetValue += element[offsetProperty];
      element = element.offsetParent;
   } while (deep == true && element != document.body && element != null);
   return offsetValue;
}


function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


function BrowserInfo(){

	//id is the element id of the righ clicked object
	this.sAgent = navigator.userAgent.toLowerCase() ;

}

BrowserInfo.prototype.IsGecko = function(){ return(this.sAgent.indexOf("msie") == -1);};
BrowserInfo.prototype.IsIE = function(){ return(this.sAgent.indexOf("msie") != -1);};
BrowserInfo.prototype.IsNetscape = function(){ return(this.sAgent.indexOf("netscape") != -1);};
BrowserInfo.prototype.IsSafari = function(){ return(this.sAgent.indexOf("safari") != -1);};

