function ajax()
{
  //IE6 check
	if(navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.indexOf("6.")>-1)
	{
		ajaxobj = new ActiveXObject("Microsoft.XMLHTTP")
	} else {
		ajaxobj = new XMLHttpRequest()
	}
	return(ajaxobj);
}

function getForm(form)
{
	var string="";
	var valarr=null;
	var val="";
	for(var i=0;i<form.length;i++)
	{
		switch(form.elements[i].type)
		{
			case "select-one":
			string+=form.elements[i].name+"="+form.elements[i].options[form.elements[i].selectedIndex].value+"&";
			break;
			case "checkbox":
			if(form.elements[i].checked==true)
			{
				string+=form.elements[i].name+"=on&"
			} else {
				string+=form.elements[i].name+"=&"
			}
			break;
			default:
			string+=form.elements[i].name +"="+escape(form.elements[i].value)+"&";
			break;
		}
	}
	string=string.substr(0,(string.length - 1));
	return(string);
}

function createBox(id,url) {
	//Set the cursor
	oldcursor=document.body.style.cursor;
	document.body.style.cursor='progress';
	
	http=ajax();
	http.open('get',url);
	http.onreadystatechange=function() {
		if(http.readyState==4) {
			//Reset the cursor
			document.body.style.cursor=oldcursor;
			
			if(http.responseText=="autherror") {
				alert("Authentication error. Did you log out in another window?");
				return;
			}
			
			block=document.createElement('div');
			block.id="block";
			block.ondblclick=function() {
				closeBox(id);
			}
			block.style.position="fixed";
			block.style.top=0;
			block.style.left=0;
			block.style.bottom=0;
			block.style.right=0;
			block.style.backgroundColor="white";
			setOpacity(block,0);
			document.body.appendChild(block);

			box=document.createElement('div');
			box.id=id;
			box.className="cboxholder";
			box.ondblclick=block.ondblclick;
			box.innerHTML="<div class=\"cbox\">"+http.responseText+"</div>";
			setOpacity(box,0);
			document.body.appendChild(box);
			
			//Position
			size=docSize();
			width=size[0];
			height=size[1];
			box.style.width=width+"px";
			
			y=height/2-box.offsetHeight/2;
			y*=.8;
			box.style.top=y+"px";
			
			//Fade in
			time=300;
			steps=4;
			i=1;
			interval=setInterval(function() {
				setOpacity(box,i/steps);
				setOpacity(block,(i/steps)*.45);
				i++;
				
				if(i>steps) clearInterval(interval);
			},time/steps);
		}
	}
	http.send(null);
}

function docSize() {
	width=document.body.offsetWidth;
	height=window.innerHeight;
	
	if(height==null) { //IE hack
		dot=document.createElement('div');
		dot.style.position='absolute';
		dot.style.top='100%';
		document.body.appendChild(dot);
		height=dot.offsetTop;
		dot.parentNode.removeChild(dot);
	}
	
	return [width,height];
}

function setOpacity(el,val) {
	if(window.innerHeight==null) { //IE
		el.style.filter="alpha(opacity="+Math.round(val*100)+")";
	} else { //Real browsers
		el.style.opacity=val;
	}
}

function closeBox(id) {
	block=document.getElementById('block');
	block.parentNode.removeChild(block);
	box=document.getElementById(id);
	box.parentNode.removeChild(box);
}

