/* Global variables for mouse position on the page */
var posx;
var posy;
/* Event fired when mouse is moving */
function mouseMove (evt) { 
	if (!e) var e = evt || window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
} 

/* Binding mouse events */
if (document.layers) 
	document.captureEvents(Event.MOUSEMOVE); 
if (document.layers || document.all) 
	document.onmousemove = mouseMove; 
if (document.addEventListener) 
	document.addEventListener('mousemove', mouseMove, true);


function OpenAJAXPopup(popupBehaviorID, postBackButtonUniqueID)
{
	$find(popupBehaviorID).show();
	__doPostBack(postBackButtonUniqueID, '');
}

function ValidEmail(emailString)
{
	if(emailString.length > 0)
	{
		var emailFormat = /^([a-zA-Z0-9\-\._]+)@(([a-zA-Z0-9\-_]+\.)+)([a-z]{2,3})$/;
		if (!emailString.match(emailFormat))
		{
			return false;
		}
		return true;
	}
	return false;
}

function Redirect(url)
{
	window.location.href = url;
}

function changeclass(objet, classe)
{ 
	objet.className = classe;
}

String.prototype.trim = function()
{
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
};

/* Jackben: returns the obj's actual left according to its parent's left (browses the DOM to do that) */
function getElementLeft(obj)
{
	var elem = document.getElementById(obj.id);
	var xPos = elem.offsetLeft;
	var tempEl = elem.offsetParent;
	while (tempEl != null)
	{
		xPos += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
	}
	return xPos;
}

/* Jackben: returns the obj's actual top according to its parent's top (browses the DOM to do that) */
function getElementTop(obj)
{
	var elem = document.getElementById(obj.id);
	var yPos = elem.offsetTop;
	var tempEl = elem.offsetParent;
	while (tempEl != null)
	{
		yPos += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
	}
	return yPos;
}

/* Jackben: adds the replaceAll method to the String class. Provides replacement of all occurences of a string inside another string */
String.prototype.replaceAll = function(from, to)
{
	var i = this.indexOf(from);
	var c = this;
	while (i > -1)
	{
		c = c.replace(from, to);
		i = c.indexOf(from);
	}
	return c;
}
