	function GetHTTPObject()
	{
		var xmlhttp=null;
		if(window.XMLHttpRequest){xmlhttp = new XMLHttpRequest();}
		else if(window.ActiveXObject)
		{
			try {xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');}
			catch(e){try {xmlhttp = new ActiveXObject("Msxml2.XMLHttp");}catch(e2) { }}
		}
		var fileContents;
		xmlhttp.onreadystatechange = function() 
		{
			if (xmlhttp.readyState == 4) 
			{
				document.getElementById("tab1").innerHTML = xmlhttp.responseText;
				fileContents = xmlhttp.responseText;
			}
		}
		return xmlhttp;
	}
	function load(the_url)
	{
		var load = window.open(the_url,'','scrollbars=yes,menubar=yes,height=600,width=800,resizable=yes,toolbar=yes,location=yes,status=yes');
	}
	//This stuff is used by the submit details form.
	function AppendValue(tag, object_name)
	{
		return "&"+tag+"=" + encodeURIComponent(document.getElementById(object_name).value );
	}
	/////////Rating Stuff
	var states= new Array();
	function SetRating(id, rating)
	{
		for(i=1;i<=5;i++)
		{
			if(rating >= i){$('#SPHERE_'+id+'_'+i).attr('src', '/images/voting_star.png');}
			else{$('#SPHERE_'+id+'_'+i).attr('src', '/images/voting_star_faded.png');}
		}
	}
	function MakeRating(id, rating)
	{
		var sphere=document.getElementById('BLAH');
		var itemo=document.getElementById('SPHERE_'+id);
		states[id]=rating;
		$.post("/set_vote.php", { ITEM: id, VOTE: rating },function(data){$('#SPHERE_'+id).html('<IMG SRC=/assets/stars-'+rating+'.jpg WIDTH=82 HEIGHT=16>');});
	}
	function ResetRating(id)
	{
		rating=states[id];
		SetRating(id, rating);
	}
	function ShowRating(id, rating)
	{
		states[id]=rating;
		document.write('<DIV CLASS=SPHERE ID=SPHERE_'+id+' onMouseOut="ResetRating('+id+');">');
		var i=0;
		for(i=1;i<=5;i++)
		{
			if(rating >= i){document.write('<IMG SRC=/images/voting_star.png ID=SPHERE_'+id+'_'+i+' onClick="MakeRating('+id+','+i+');" onMouseOver="SetRating('+id+','+i+');">');}
			else{document.write('<IMG SRC=/images/voting_star_faded.png ID=SPHERE_'+id+'_'+i+' onClick="MakeRating('+id+','+i+');" onMouseOver="SetRating('+id+','+i+');">');}
		}	
		document.write("</DIV>");
		SetRating(id, rating);
	}
///Cookie stuff

	function SetCookie (cookieName, cookieValue) 
	{
	  if (testSessionCookie()) 
	  {
		 document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
		 return true;
	  }
	  else return false;
	}
	function GetCookie (cookieName) 
	{
	  var exp = new RegExp (escape(cookieName) + "=([^;]+)");
	  if (exp.test (document.cookie + ";")) 
	  {
		 exp.exec (document.cookie + ";");
		 return unescape(RegExp.$1);
	  }
	  else return false;
	}
	function testSessionCookie () 
	{
	  document.cookie ="testSessionCookie=Enabled";
	  if (GetCookie ("testSessionCookie")=="Enabled")
		 return true 
	  else
		 return false;
	}
	function testPersistentCookie () 
	{
	  writePersistentCookie ("testPersistentCookie", "Enabled", "minutes", 1);
	  if (GetCookie ("testPersistentCookie")=="Enabled"){return true;}
	  else{return false;}
	}
	function writePersistentCookie (CookieName, CookieValue, periodType, offset) 
	{
	  var expireDate = new Date ();
	  offset = offset / 1;
	  var myPeriodType = periodType;
	  switch (myPeriodType.toLowerCase()) 
	  {
		 case "years":
			expireDate.setYear(expireDate.getFullYear()+offset);
			break;
		 case "months":
			expireDate.setMonth(expireDate.getMonth()+offset);
			break;
		 case "days":
			expireDate.setDate(expireDate.getDate()+offset);
			break;
		 case "hours":
			expireDate.setHours(expireDate.getHours()+offset);
			break;
		 case "minutes":
			expireDate.setMinutes(expireDate.getMinutes()+offset);
			break;
		 default:
			alert ("Invalid periodType parameter for writePersistentCookie()");
			break;
	  } 
	  document.cookie = escape(CookieName ) + "=" + escape(CookieValue) + "; expires=" + expireDate.toGMTString() + "; path=/";
	}  
	function DeleteCookie (cookieName) 
	{
	  if (GetCookie (cookieName)){writePersistentCookie (cookieName,"Pending delete","years", -1);}
	  return true;     
	}


///Some Stuff for poping the details in and out.
	function ToggleItemHeight(item_name)
	{
		var details_text=document.getElementById(item_name);
		var details_text_long=document.getElementById('LONG_'+item_name);
		if(details_text_long.style.height==0 || details_text_long.style.height==1 || details_text_long.style.height=='1pt' || details_text_long.style.height=='1px')
		{
			details_text_long.style.height='100%';
			details_text.style.height=1;
		}
		else
		{
			details_text.top=0;
			details_text.style.height=30;
			details_text_long.style.height=1;
		}
	}
	
	var panel_state=1;
	var panel_height=1;
	function AnimatePanel()
	{
		var panel=document.getElementById('PANEL');
		if(panel_state==1)
		{
			if(panel_height<500)
			{
				panel_height+=20;
				setTimeout('AnimatePanel()',50);
			}
			else{panel_state=3;panel_height=500;}
		}
		else if(panel_state==2)
		{
			if(panel_height>0)
			{
				panel_height-=20;
				setTimeout('AnimatePanel()',50);
			}
			else{panel_state=4;panel_height=0;}
		}
		if(panel_height<1)
		{
			panel_height=1;
			panel.style.visibility='hidden';
		}
		panel.style.height=panel_height;
	}

	function ShowPanel()
	{
		panel_state=1;
		var panel=document.getElementById('PANEL');
		panel.style.visibility='visible';
		AnimatePanel();
	}
	function HidePanel()
	{
		panel_state=2;
		AnimatePanel();
	}
	function EditDetailsPOST(url, parameters) 
	{
		http_request = GetHTTPObject();
		http_request.onreadystatechange = EditDetailsReturnData;
		http_request.open('POST', url, true);
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http_request.setRequestHeader("Content-length", parameters.length);
		http_request.setRequestHeader("Connection", "close");
		http_request.send(parameters);
	}
	function HoverMoveItem(item_id)
	{
		var main=document.getElementById('center-column');
		var move_area=document.getElementById('ITEM_MOVE_'+item_id);
		var icon_popover=document.getElementById('ICON_POPOVER');
		var coordinates=getAnchorPosition(move_area);
		icon_popover.style.top=coordinates.y-main.scrollTop;
		icon_popover.style.left=coordinates.x;
		icon_popover.style.visibility='visible';
		icon_popover.innerHTML="<DIV CLASS=ITEM_MOVE_POPOUT ID=ITEM_MOVE_POPOUT><TABLE WIDTH=100% HEIGHT=100% CELLPADDING=0 CELLSPACING=0><TD><A HREF=\"javascript:MoveItem("+item_id+")\"><IMG SRC=/images/item_move.png BORDER=0 ALIGN=LEFT></A></TD><TD>Move this item?</TD></TABLE></DIV>";
	}
	function LeaveDeleteItem(item_id)
	{
//		var icon_popover=document.getElementById('ICON_POPOVER');
//		icon_popover.style.visibility='hidden';
	}
	function LeaveMoveItem(item_id)
	{
//		var icon_popover=document.getElementById('ICON_POPOVER');
//		icon_popover.style.visibility='hidden';
	}
	function HoverDeleteItem(item_id)
	{
		var icon_popover=document.getElementById('ICON_POPOVER');
		var main=document.getElementById('center-column');
		var delete_area=document.getElementById('ITEM_DELETE_'+item_id);
		var coordinates=getAnchorPosition(delete_area);
		icon_popover.style.top=coordinates.y-main.scrollTop;
		icon_popover.style.left=coordinates.x;
		icon_popover.style.visibility='visible';
		icon_popover.innerHTML="<DIV CLASS=ITEM_MOVE_POPOUT ID=ITEM_MOVE_POPOUT><TABLE WIDTH=100% HEIGHT=100% CELLPADDING=0 CELLSPACING=0><TD><A HREF=\"javascript:DeleteItem("+item_id+")\"><IMG SRC=/images/item_delete.png BORDER=0 ALIGN=LEFT></A></TD><TD>Delete this item?</TD></TABLE></DIV>";
	}
	function LeaveIconPopover()
	{
		var icon_popover=document.getElementById('ICON_POPOVER');
		icon_popover.style.visibility='hidden';
		icon_popover.innerHTML='';
	}
	function getAnchorPosition(anchorname) 
	{
		// 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; }
		else if (document.layers) { use_layers=true; }
		// Logic to find position
		if (use_gebi && document.all) {
			x=AnchorPosition_getPageOffsetLeft(anchorname);
			y=AnchorPosition_getPageOffsetTop(anchorname);
			}
		else if (use_gebi) {
			x=AnchorPosition_getPageOffsetLeft(anchorname);
			y=AnchorPosition_getPageOffsetTop(anchorname);
			}
		else if (use_css) {
			x=AnchorPosition_getPageOffsetLeft(anchorname);
			y=AnchorPosition_getPageOffsetTop(anchorname);
			}
		else if (use_layers) {
			var found=0;
			for (var i=0; i<document.anchors.length; i++) {
				if (document.anchors[i].name==anchorname) { found=1; break; }
				}
			if (found==0) {
				coordinates.x=0; coordinates.y=0; return coordinates;
				}
			x=document.anchors[i].x;
			y=document.anchors[i].y;
			}
		else {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		coordinates.x=x;
		coordinates.y=y;
		return coordinates;
	}
	// Functions for IE to get position of an object
	function AnchorPosition_getPageOffsetLeft (el) {var ol=el.offsetLeft;while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }return ol;	}
	function AnchorPosition_getWindowOffsetLeft (el) {return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;}	
	function AnchorPosition_getPageOffsetTop (el) {var ot=el.offsetTop;while((el=el.offsetParent) != null) { ot += el.offsetTop; }return ot;}
	function AnchorPosition_getWindowOffsetTop (el) {return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;}
	function DeleteItem(item_id)
	{
		var answer=confirm('Are you sure that you would like to delete this item?'); // should name the item.
		if(answer){document.location='/index.php?ITEM_DELETE='+item_id;}
	}
	function MoveItem(item_id)
	{
		var node_panel = document.getElementById("MOVE_NODE");
		var fade_screen=document.getElementById('FADESCREEN');
		fade_screen.style.visibility='visible';
		form_data='<IFRAME src ="/admin/move_item.php?ITEM='+item_id+'" WIDTH="100%" HEIGHT="100%" SCROLL=NO frameborder=0 ID="the_frame" allowtransparency="true">';
		node_panel.innerHTML=form_data;
		node_panel.style.visibility='visible';
	}
	function SubmitComment(item_id)
	{
		var name=$('#COMMENT_NAME_'+item_id).attr('value');
		var details=$('#COMMENT_DETAILS_'+item_id).attr('value');
		$.post('/get_comments.php', {NAME:name, DETAILS:details, SUBMIT:'COMMENT', ITEM:item_id}, function(responseText) {$('#COMMENTS_'+item_id).html(responseText);});
	}
	function NavigateMain(url)
	{
		document.location=url;
	}
