function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
// Ajax Engine
var MAXIMUM_WAITING_TIME = 10000;

function createXMLHttpRequest() {
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	try { return new XMLHttpRequest(); } catch(e) {}
	alert("XMLHttpRequest not supported");
	return null;
}

function GetXML()
{
	var args = GetXML.arguments;
	var url = args[0];
	var ReturnFunction = args[1];
	var ajaxRequest = createXMLHttpRequest();
		ajaxRequest.open("GET", url, true);
		
		var requestTimer = setTimeout(function() {
			ajaxRequest.abort();
			// Handle timeout situation, e.g. Retry or inform user.
			alert("Operation Timeout : " + MAXIMUM_WAITING_TIME + "ms...\nOperation abort.");
		}, MAXIMUM_WAITING_TIME);
		
		ajaxRequest.onreadystatechange = function() {
			if (ajaxRequest.readyState != 4) {return;}
			clearTimeout(requestTimer);
			if (ajaxRequest.status != 200)
			{
				// Handle error, e.g. Display error message on page
				alert(ajaxRequest.statusText)
				return;
			}
			var XMLResponse = null;
			if (args.length > 2)
			{
				if (args[2] == "ReturnText")
				{
					XMLResponse = ajaxRequest.responseText;
				}
			}
			if (XMLResponse == null)
			{
				XMLResponse = ajaxRequest.responseXML;
			}
			
			if (args.length == 3)
			{
				ReturnFunction(XMLResponse,args);
			}
			elses
			{
				ReturnFunction(XMLResponse);
			}
		};
		ajaxRequest.send(null);
}
function XmlRequest(url, Method, returnType, ReturnFunction, ErrorFunction, TimeOutFunction)
{
	var ajaxRequest = createXMLHttpRequest();
		ajaxRequest.open(Method, url, true);
		
		var requestTimer = setTimeout(function() { // Handle timeout situation, e.g. Retry or inform user.
			ajaxRequest.abort();
			TimeOutFunction(UPS_MAXIMUM_WAITING_TIME);
		}, UPS_MAXIMUM_WAITING_TIME);
		
		ajaxRequest.onreadystatechange = function() {
			if (ajaxRequest.readyState != 4) {return;}
			clearTimeout(requestTimer);
			if (ajaxRequest.status != 200) // Handle error, e.g. Display error message on page
			{
				ErrorFunction(ajaxRequest.status, ajaxRequest.statusText);
				return;
			}
			
			var XMLResponse;
			if (returnType == "Text") // Handle response type, e.g. Text Or Xml
			{
				XMLResponse = ajaxRequest.responseText;
			}
			else
			{
				XMLResponse = ajaxRequest.responseXML;
			}
			
			ReturnFunction(XMLResponse);
		};
		ajaxRequest.send(null);
}

function ObjWorker()
{
	var obj = document.getElementById(ObjWorker.arguments[0]);
	if (obj != null)
	{
		if (ObjWorker.arguments[1] == "write")
		{
			obj.innerHTML = ObjWorker.arguments[2];
		}
		else if (ObjWorker.arguments[1] == "append")
		{
			obj.innerHTML = obj.innerHTML + ObjWorker.arguments[2];
		}
		else if (ObjWorker.arguments[1] == "get")
		{
			return eval("obj." + ObjWorker.arguments[2]);
		}
		else if (ObjWorker.arguments[1] == "set")
		{
			eval("obj." + ObjWorker.arguments[2] + "=" + ObjWorker.arguments[3]);
		}
		else
		{
			obj.style.display = ObjWorker.arguments[1];
		}
	}
}

// Example:
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}

// Example:
// var b = new BrowserInfo();
// alert(b.version); 
var b = new BrowserInfo();
function BrowserInfo()
{
  this.name = navigator.appName;
  this.codename = navigator.appCodeName;
  this.version = navigator.appVersion.substring(0,4);
  this.platform = navigator.platform;
  this.javaEnabled = navigator.javaEnabled();
  this.screenWidth = screen.width;
  this.screenHeight = screen.height;
}

//	
//	Count Down dans le panel des boutton de Gestion Live
//	
var InactivityCounter_div, InactivityCounter, MaxSec=1190;
//
//<div id="InactivityCounter"></div>
//
function InactivityCounter_Load()
{
	InactivityCounter_div = document.getElementById("InactivityCounter");
	InactivityCounter = setInterval(InactivityCounter_Update,1000)
}

function InactivityCounter_Update()
{
	var Min = Math.floor(MaxSec/60);
	var Sec = (MaxSec % 60);
	if ((MaxSec % 60) == 0) {
		Sec = "00";
	} else if ((MaxSec % 60) < 10) {
		Sec = "0" + (MaxSec % 60);
	}
	
	MaxSec--
	if (MaxSec < 0)
	{
		clearInterval(InactivityCounter);
		InactivityCounter_div.innerHTML = "<span class=\"error\">Session Expirée !</span>";
	}
	else
	{
		InactivityCounter_div.innerHTML = Min + ":" + Sec;
	}
}
function IsIE()
{
	return ("Microsoft Internet Explorer" == b.name);
}
function IsNumeric(val)
{
	var myNumRegex = new RegExp("^[0-9]+$")
	return myNumRegex.test(val);
}


/*** Open Dialog ***/

function modelessDialogShow(url,width,height)
{
	if (windowOpen == undefined)
	{
		if (IsIE())
		{
			window.showModelessDialog(url,window,"dialogWidth:"+width+"px;dialogHeight:"+height+"px;edge:Raised;center:1;help:0;resizable:1;");
		}
		else
		{
			left = (screen.width-width)/2;
			top = (screen.height-height)/2;
			window.open(url, "dependent=yes,width="+width+",height="+height+",left="+left+",top="+top);
		}
	}
	else
	{
		windowOpen(url,width,height);
	}
}

function modalDialogShow(url,width,height)
{
	if (windowOpen == undefined)
	{
		if (IsIE())
		{
			window.showModalDialog(url,window,"dialogWidth:"+width+"px;dialogHeight:"+height+"px;edge:Raised;center:1;help:0;resizable:1;maximize:1");
		}
		else
		{
			left = (screen.width-width)/2;
			top = (screen.height-height)/2;
			window.open(url, "dependent=yes,width="+width+",height="+height+",left="+left+",top="+top);
		}
	}
	else
	{
		windowOpen(url,width,height);
	}
}


function OpenAspxUploaderPopUp(URL)
{
	var left = (screen.width-width)/2
	var top = (screen.height-height)/2
	var width = 425;
	var height = 150;
	window.open(URL, 'AspxUploaderPopUp', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'')
}



