var body = null;
function findPosYHere(elem) {
	var curTop = 0;
	if (elem.offsetParent) {
		do {
			curTop += elem.offsetTop;
		} while (elem = elem.offsetParent);
	}
	else if (elem.y) {
		curTop += elem.y;
	}
	return curTop;
}
// ********************** Ajax Stuff... ********************** 
var req;
//var errMsg;
var sStringEmail;
var emailExists = '0';
function getIds() {
//	errMsg = getEl("errormessage");
	sStringEmail = getEl("emailWeb");
}
function goCheckEmail() {
	var strSearch = sStringEmail.value;
//	errMsg.innerHTML = '';
	emailExists = '0';
	if (strSearch != '') {
		if (initRequest() == false) {return;}
		req.onreadystatechange = processRequest;
		req.open('POST', ReplicaId + 'EmailSearch?OpenAgent', true);
		req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		req.send(escape(strSearch)); // Use escape to get the danish characters right! Part 1.
	}
}
function initRequest() {
	req = null;
	if (window.XMLHttpRequest) req = new XMLHttpRequest( );
	else if (window.ActiveXObject) req = new ActiveXObject("Msxml2.XMLHTTP");
	if (req == null) req = new ActiveXObject("Microsoft.XMLHTTP");
	if (req == null) {
		return false;
	} else {
		return true;
	}
}
function processRequest() {
	if ((req.readyState == 4) && (req.status == 200)) {
		var msg = req.responseText;
		if (msg.indexOf('No match!') == -1) {
			//errMsg.innerHTML = msg;
			alert(msg);
			emailExists = '1';
		}
	}
}
// ********************** Help Text Stuff... ********************** 
function getHelpImages() {
	body = document.getElementsByTagName('body')[0];
	var allImages = document.getElementsByTagName('img');
	for (i = 0; i < allImages.length; i++) {
		theImage = allImages[i];
		if (theImage.className == 'helpImage') {
			addEvent(theImage, 'mouseover', showHelpText, false);
			addEvent(theImage, 'mouseout', showHelpText, false);
		}
	}
}
function showHelpText(ev) {
	var theHyperDiv = null;
	theHyperDiv = getEl('hyperDiv');
	if (theHyperDiv)
		body.removeChild(theHyperDiv);
	var e = window.event ? window.event : ev;
	var t = e.target ? e.target : e.srcElement;
	var theMouseLeft = (e.pageX) ? e.pageX : e.clientX;
	if (e.type == 'mouseover') {
		theDiv = document.createElement('div');
		theDiv.id = 'hyperDiv';
		theDiv.style.position = 'absolute';
		theDiv.style.left = theMouseLeft + 20 + 'px';
		theDiv.style.top = (findPosYHere(t) - 2) + 'px';
		var theImage = document.createElement('img');
		theImage.src = '../Info.gif';
		theImage.width = 15;
		theImage.height = 16;
		theImage.style.position = 'absolute';
		theImage.style.right = '5px';
		theImage.style.top = '-10px';
		theDiv.appendChild(theImage);
		var theDivInside = document.createElement('div');
		theDivInside.className = 'helpPopup';
		theDivInside.innerHTML = getHelpText(t.id);
		theDiv.appendChild(theDivInside);
		body.appendChild(theDiv);
	} else if (e.type == 'mouseout') {
		theHyperDiv = getEl('hyperDiv');
		if (theHyperDiv)
			body.removeChild(theHyperDiv);
	}
}
addEvent(window, 'load', getIds, false);
addEvent(window, 'load', getHelpImages, false);

