// Loading the browser class
browser = new browserOption();
function browserOption() {
	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 resetAjaxBox(box){
	var wiBox = document.getElementById(box);
	wiBox.innerHTML = "";
	wiBox.style.left = "-1000px";
	wiBox.style.top = "-1000px";
}

// Opens Box
var width = 640;
var height = 480;
var boxId;
function openAjaxBox(event, w, h, box){
	width = w;
	height = h;
	boxId = box;
	//move the what is box and set to loading 
	
	var wiBox =  document.getElementById(boxId);
	
	
	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;
	xpos = event.clientX;

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

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

function POSTData(rel) {
	return;	
}

function loadAjaxData(){
	/* 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(boxId);;
				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;
}


