window.onload=function() { prepareSidebar() }

function prepareSidebar()
{
	if( document.getElementById && document.getElementsByTagName )
	{
    	if( document.getElementById( 'sidebar' ) )
		{
      		var sidebar = document.getElementById( 'sidebar' );
      		var links = sidebar.getElementsByTagName( 'a' );
      		for( var i=0; i < links.length; i++ )
			{
				/*
        		links[i].onclick = function (){ 
				href = this.href;
				document.getElementById('content').innerHTML = "whatever"+href;
				chooseOption(href);
				return false; 
				
				};
				*/
			}
		}
  	}
}

function chooseOption(address)
{
	mainContent = $('content');
	mainContent.innerHTML = address;
}
/*
function loadContent()
{
	mainContent = $('content');
	setTimeout ("mainContent.innerHTML = 'test';", 5000 ); 
    var choice = "";
    var cookie1=readCookie('username');
	
	if (cookie1!=null)
	{
		var cookie2=readCookie('password');
		choice="name=";
		choice+=cookie1;
		choice+="&pass=";
		choice+=cookie2;
	}

}

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = ";expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) 
{
	createCookie(name,"",-1);
}
*/
/*
function loadContent(choice)
{
	//check for cookie, if set, change choice variable to include username/password 
	
	var cookie1=readCookie('username');
	if (cookie1!=null)
	{
		var cookie2=readCookie('password');
		choice="name=";
		choice+=cookie1;
		choice+="&pass=";
		choice+=cookie2;
	}
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="boxes/load_content.php";
	xmlHttp.onreadystatechange=drawContent;
	xmlHttp.open('POST',url,true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(choice); 	
}

function parseForm(form)
{	
	var requestString="";
	for (i=0;i<(form.elements.length-1);i++)
	{
		requestString+=form.elements[i].name;
		requestString+="=";
		requestString+=form.elements[i].value;
		if (i<(form.elements.length-2)) {requestString+="&"};
	}
	return requestString;
}

function logInForm(form)
{
	var logInInfo=parseForm(form);

	if (form.elements[2].checked==true) //set cookie?
	{
		createCookie('username',form.elements[0].value,'30');
		createCookie('password',form.elements[1].value,'30');
	}
	loadContent(logInInfo);
}

function newUser(form)
{
	var userInfo=parseForm(form);
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="boxes/new_user.php";
	xmlHttp.onreadystatechange=drawContent;
	xmlHttp.open('POST',url,true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(userInfo);
}

function submitUser(form)
{	
	var userInfo=parseForm(form);
	if (form.elements[1].value==form.elements[2].value)
	{
		if (form.elements[3].checked==true) //set cookie?
		{
			createCookie('username',form.elements[0].value,'30');
			createCookie('password',form.elements[1].value,'30');
		}
	}
	xmlHttp=GetXmlHttpObject();
	var url="boxes/submit_user.php";
	xmlHttp.onreadystatechange=drawContent;
	xmlHttp.open('POST',url,true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(userInfo);	
}

function forgetMe()
{
	eraseCookie('username');
	eraseCookie('password');
	loadContent('choice=1');
}


function drawContent()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{		
		document.getElementById("mainContent").innerHTML=xmlHttp.responseText;
	}
}

var element = "";

function expand(id,name,classtype)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	element="id"+id;
	requestString="id="+id+"&name="+name+"&class="+classtype;
	var url="boxes/expand.php";
	xmlHttp.onreadystatechange = reDrawElement;
	xmlHttp.open('POST',url,true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(requestString);
}

function contract(id,name,classtype)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	element="id"+id;
	requestString="id="+id+"&name="+name+"&class="+classtype;
	var url="boxes/contract.php";
	xmlHttp.onreadystatechange = reDrawElement;
	xmlHttp.open('POST',url,true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(requestString);
}

function reDrawElement()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{		
		document.getElementById(element).innerHTML=xmlHttp.responseText;
	}
	if (element=="hiddenPane")
	{
		obj = document.getElementById('hiddenPane');
		obj.style.visibility = 'visible';
		document.getElementById('admin').style.zIndex = 1;
		document.getElementById('hiddenPane').style.zIndex = 100;
	*//*	obj.style.zIndex = 25;
		document.getElementById('admin').style.z-index = 1;  *//*
	}
}

function showDetail(id)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	element="hiddenPane";
	requestString="id="+id;
	var url="boxes/detail.php";
	xmlHttp.onreadystatechange = reDrawElement;
	xmlHttp.open('POST',url,true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(requestString);
}

function admin()
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="boxes/admin_panel.php";
	xmlHttp.onreadystatechange = drawAdmin;
	xmlHttp.open('POST',url,true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(null);
}

function drawAdmin()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{		
		document.getElementById('admin').innerHTML=xmlHttp.responseText;
		document.getElementById('admin').style.visibility = 'visible';
		document.getElementById('admin').style.zIndex = 100;
		document.getElementById('hiddenPane').style.zIndex = 1;
	}
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		//Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

/*
	var whatever = document.getElementById("list").getElementsByTagName("li");
	var a = document.createElement('div');
	whatever[node].appendChild(a);
	a.innerHTML = '<ul><li>sub list 1</li><li>more garbage</li></ul>';
	*/
/*	
	list=document.getElementById("list").getElementsByTagName("li");
	
	var newElement = document.createElement('li');
	newElementText = document.createTextNode("some crap here...");
	newElement.appendChild(newElementText);  
	
	list[node].appendChild(newElement);
	
	
	newElement.appendChild(newElementText);
	
	
	list=document.getElementById("list");
	listElements=list.getElementsByTagName("li");
	var newElement = document.createElement('<li>more crap!</li>');
	listElements[node].appendChild(newElement);
	*/