if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}
// Global variables
xMouse = 0; // From left position
yMouse = 0; // From top position
xMousePos = 0; // From left position with added scroll value
yMousePos = 0; // From top position with added scroll value
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has 
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMouse = e.pageX;
        yMouse = e.pageY;
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position 
        // reflects the position from the top/left of the screen the 
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no 
        // matter if the user has scrolled or not.
        xMouse = window.event.x;
        yMouse = window.event.y;
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) { // Netscape 6 behaves the same as Netscape 4 in this regard 
        xMouse = e.pageX; 
        yMouse = e.pageY;
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}

// Open popup with calendar to select a date from consultation
function OpenCalendar(obj, langue) {
	pWidth = 140;
	pHeight = 160;
	winCalendar = window.open("control/calendar.aspx?arg=" + obj + "&Langue=" + langue, "", "top=" + yMouse + ",left=" + xMouse + ",width=" + pWidth + ",height=" + pHeight);
	winCalendar.focus();
	return false;
}
// Open popup with calendar to select a date from admin
function OpenCalendarFromAdmin(obj, langue) {
pWidth = 140;
	pHeight = 160;
	winCalendar = window.open("../control/calendar.aspx?arg=" + obj + "&Langue=" + langue, "", "top=" + yMouse + ",left=" + xMouse + ",width=" + pWidth + ",height=" + pHeight);
	winCalendar.focus();
	return false;
}

// Open popup with send mail formular
function OpenMailWindow(pHeight, pWidth, pArg) {
	var sFeatures = "top="+(screen.availHeight-pHeight)/2+",left="+(screen.availWidth-pWidth)/2+",width="+pWidth+",height="+pHeight;
	//window.showModalDialog("send_Mail.aspx" + pArg, "", sfeatures);
	winMail = window.open("send_Mail.aspx" + pArg, "", sFeatures);
	winMail.focus();
}

// Open popup with send mail formular from the admin part
function OpenMailWindowFromAdmin(pHeight, pWidth, pArg) {
	var sFeatures = "top="+(screen.availHeight-pHeight)/2+",left="+(screen.availWidth-pWidth)/2+",width="+pWidth+",height="+pHeight;
	//window.showModalDialog("send_Mail.aspx" + pArg, "", sfeatures);
	winMail = window.open("../send_Mail.aspx" + pArg, "", sFeatures);
	winMail.focus();
}

// Open popup with choose contact list
function OpenChooseContact() {
	pHeight = 300;
	pWidth	= 400;
	var sFeatures = "top="+(screen.availHeight-pHeight)/2+",left="+(screen.availWidth-pWidth)/2+",width="+pWidth+",height="+pHeight+",scrollbars=1";
	winContact = window.open("chooseContact.aspx", "", sFeatures);
	winContact.focus();
}

// Open an image
function OpenImageMousePosition(pImage) {
	html =	"<HTML><HEAD><TITLE></TITLE></HEAD>" +
			"<BODY LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0 onclick=\"self.close();\"><CENTER>" +
			"<IMG SRC=\"" + pImage + "\" BORDER=0 NAME=image " +
			"onload=\"window.resizeTo(document.image.width,document.image.height)\"></CENTER>" +
			"</BODY></HTML>";
			
	popup = window.open("", "image", "top=" + yMousePos + ",left=" + xMousePos + ",toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=1");
	popup.document.open();
	popup.document.write(html);
	popup.document.focus();
	popup.document.close();
	popup.focus();
	return false;
}
function OpenImage(pImage) {
	html =	"<HTML><HEAD><TITLE></TITLE></HEAD>" +
			"<BODY LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0 onclick=\"self.close();\" onblur=\"self.focus();\"><CENTER>" +
			"<IMG SRC=\"" + pImage + "\" BORDER=0 NAME=image " +
			"onload=\"window.resizeTo(document.image.width,document.image.height);window.moveTo((screen.availHeight-document.image.height)/2, (screen.availWidth-document.image.width)/2);\"></CENTER>" +
			"</BODY></HTML>";
			
	popup = window.open("", "image", "toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=1");
	popup.document.open();
	popup.document.write(html);
	popup.document.focus();
	popup.document.close();
	popup.focus();
	return false;
}

// Write "txt" text in a openwindow result
function WriteInOpenWindow(txt) {
	top.consoleRef = window.open('','myconsole', 'width=350,height=250,top='+yMousePos+',left='+xMousePos+'menubar=0,toolbar=0,status=0,scrollbars=1,resizable=1');
	top.consoleRef.document.writeln(txt);
	top.consoleRef.document.close();
}

// Copy value from origin textbox to dest (if empty)
function CopyValueFromTo(origin, dest) {
	if (document.getElementById(dest).value == "")
		document.getElementById(dest).value = document.getElementById(origin).value;
}

// Open window in 800x600
function WindowOpen800(url) {
	win = window.open(url, "", "top=0,left=0,width=800,height=800,resizable=1,scrollbars=1,status=1");
	win.focus();
}

// Open window photos gallery
function WindowOpenGallery(url) {
	pWidth = 600;
	pHeight = 600;
	pTop = (screen.AvailHeight-pHeight)/2;
	pLeft = (screen.AvailWidth-pWidth)/2;
	win = window.open(url, "", "top=" + pTop + ",left=" + pLeft + ",width=" + pWidth + ",height=" + pHeight + ",scrollbars=1,status=1");
	win.focus();
}

// Launch pUrl after confirmation (for delete particulary)
function LaunchAfterConfirm(pUrl, pMsg) {
	if (confirm(pMsg)) {window.location = pUrl;}
	return false;
}