﻿var bolAutoLocate = true;

function LoadDivContentsNoPos(strURL, strDiv, strTextbox)
{
    bolAutoLocate = false;
    LoadDivContents(strURL, strDiv, strTextbox);
}
function LoadDivContents(strURL, strDiv, strTextbox) 
{
	var req;
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest && !(window.ActiveXObject)) 
    {
    	try {req = new XMLHttpRequest();} 
    	catch(e) {req = false;}
	}
    // branch for IE/Windows ActiveX version
    else if(window.ActiveXObject) 
    {
       	try {req = new ActiveXObject("Msxml2.XMLHTTP");} 
       	catch(e) 
       	{
        	try {req = new ActiveXObject("Microsoft.XMLHTTP");} 
        	catch(e) {req = false;}
		}
    }
    
	if(req) 
	{
		req.onreadystatechange = function processReqChange() 
			{
				if (req.readyState == 4 && req.status == 200) 
				{
					if (bolAutoLocate)
					{					
					document.getElementById(strDiv).style.top = getObjectPosition(strTextbox).y + 25;
					document.getElementById(strDiv).style.left = getObjectPosition(strTextbox).x;
					}
					document.getElementById(strDiv).innerHTML =  req.responseText; 
					if (req.responseText == "") {document.getElementById(strDiv).style.display = "none";}
					else {document.getElementById(strDiv).style.display = "";} 
				}
			}
			
		req.open("GET", strURL, true);
		req.send("");
	}
}

function getObjectPosition(strObjectName) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	
	// Logic to find position
 	if (use_gebi && document.all) {
		x=ObjectPosition_getPageOffsetLeft(document.all[strObjectName]);
		y=ObjectPosition_getPageOffsetTop(document.all[strObjectName]);
		}
	else if (use_gebi) {
		var o=document.getElementById(strObjectName);
		x=ObjectPosition_getPageOffsetLeft(o);
		y=ObjectPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=ObjectPosition_getPageOffsetLeft(document.all[strObjectName]);
		y=ObjectPosition_getPageOffsetTop(document.all[strObjectName]);
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
}

function ObjectPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function ObjectPosition_getWindowOffsetLeft (el) {
	return ObjectPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}	
function ObjectPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function ObjectPosition_getWindowOffsetTop (el) {
	return ObjectPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}


