// Loading the browser class
browser = new browser();
function browser() {
	this.IE    = false;
	this.NS    = false
	agent = navigator.userAgent;
	if ((i = agent.indexOf("MSIE")) >= 0) {
		this.IE = true;
		return;
	}
	if ((i = agent.indexOf("Gecko")) >= 0) {
		this.NS = true;
		return;
	}
	if ((i = agent.indexOf("Netscape6/")) >= 0) {
		this.NS = true;
		return;
	}
}

// Resets the box
function resetBox(){
	var wiBox = document.getElementById("BOX");
	wiBox.innerHTML = "";
	wiBox.style.left = "-500px";
	wiBox.style.top = "-500px";
	wiBox.style.overflow = "hidden";
}

// Opens Box
var width = 200;
var height = 200;
function openBox(event, w, h){
	width = w;
	height = h;
	//move the what is box and set to loading 
	var wiBox =  document.getElementById("BOX");
	
	
	if(browser.IE){
		pre_obj = window.event.srcElement;	
	}
	else if(browser.NS){
		pre_obj = event.target;
	}
		
	var src;
	src = "<div style=\"width: 50px; height: 50px;\">";
	src += "<center><img src=\"images/loading.gif\" width=\"50\" height=\"50\" /></center>";
	src += "</div>";
	wiBox.innerHTML = src;
	
	// Setting the height of the box
	wiBox.style.width = '50px';
	wiBox.style.height = '50px';
	
	// Setting hte position of the box on the page.
	var tbody = (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
	ypos = (tbody.scrollTop + event.clientY) - h;
	xpos = event.clientX - w;

	wiBox.style.left = xpos+"px";
	wiBox.style.top = ypos+"px";
	
		
	// Resets the page and removes the box.
	wiBox.ondblclick = function(){
		resetBox();	
	}
	
	// The request varibale, thats the location where you get your data from.
	var rel = pre_obj.getAttribute('rel');
	GETData(rel);
	
}

// Loads the box based on GET Request
var req = false;
function GETData(rel){
	req=_initReq();
	if (req==null){
		msg("Browser does not support HTTP Request");
		return;
	} 
	
	req.onreadystatechange = loadAjax;
	alert (rel);
	var url = rel;
	req.open("GET",url,true);
	req.send(null);
}

function POSTData(rel) {
	return;	
}

function loadAjax(){
	/* ready state values 
	0 Uninitialized
	1 Request Opened
	2 Sent
	3 Receiving
	4 Loaded
	*/
	switch (req.readyState) {
		case 4 :
			if (req.status == 200) {
				//status = 200 = success		
				data = req.responseText;
				
				wiBox = document.getElementById("BOX");;
				wiBox.style.width = width+"px"; // 380
				wiBox.style.height = height+"px"; //300
				wiBox.style.overflow = "auto";
				//change the x and y positions		
				
				wiBox.innerHTML = data
			}
		break;
	}	
}

function _initReq(){
	var req=null;
	
	if (window.XMLHttpRequest){
	  req=new XMLHttpRequest()
	}else if(window.ActiveXObject){
		req=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return req;
}

