
function nav_collapse()
{
	// firstly, get the NAV div
	nav_div = document.getElementById('nav_collapse');

	alert(nav_div.childNodes.length);

/*	var divs = document.getElementsByTagName('div');
	var rel;
	var x;
	for(x = 0; x < divs.length; x++) {
		if((id = divs[x].getAttribute('id'))) {
			myRE = new RegExp("nav_collapse")
			results = id.match(myRE)
			if(results) {	// match to our select
				nav_div = divs[x];

				alert(nav_div.child.length);
			}
		}
	}
*/
}

var loadscript = '';
function get_http()
{
	var http = false;
	if (window.XMLHttpRequest) {
		http = new XMLHttpRequest();
		if(http) {
			return http;
		}
		return false;
		//http.overrideMimeType('text/xml');
	} else if (window.ActiveXObject) {
		http = new ActiveXObject("Microsoft.XMLHTTP");
		if(!http) {
			http = new ActiveXObject("Msxml2.XMLHTTP");
			if(!http) {
				return false;
			}
		}
	}
	return http;
}

function delete_comment(id)
{
	function delete_comment_handler(http, id)
	{
		if(http.readyState != 4) {
			return;
		}
		if(http.status != 200) {
			alert('Error deleting comment.');
			return;
		}
		el = document.getElementById('comment_'.id);
		el.parent.removeChild(el);
	}
	if(window.confirm('Are you sure you want to delete this message?')) {
		return ajax_call('delete_comment',delete_comment_handler,{id: id},id);
	}
	return false;
}

function ajax_available()
{
	if(http = get_http()) {
		http = undefined;
		return true;
	}
	return false;
}

function ajax_call(func,callback,obj,pass)
{
	function ajax_respond()
	{
		if(callback) {
			callback(http, pass);
		}
	}

	var http = get_http();
	if(!http) {
		return false;
	}
	http.onreadystatechange = ajax_respond;
	http.open('POST','?ajax_func='+func, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	var data = new Array();
	for(var key in obj) {
		if(encodeURIComponent != undefined) {
			data.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]));
		} else {
			data.push(escape(key) + '=' + escape(obj[key]));
		}
	}
	http.send(data.join('&'));
	return true;
}

function article_rating_set(aid, rating)
{
	function response(http, obj)
	{
		if(http.readyState != 4) {
			return;
		}
		document.body.style.cursor = '';
		if(http.status != 200) {
			alert('Error: '.http.status);
			return;
		}
		// rating has been set, update interface
		//eval();
	}
	if(!ajax_call('article_set_rating',response,{aid: aid, rating: rating},this)) {
		return false;
	}
	document.body.style.cursor = 'wait';
	return true;
}

function CreateBookmarkLink() {
	title = document.title; 
	url = location.href;;
	
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true;
	}
}

function DisplayBookmarkLink() {
	if (window.external) {
		document.write('<a href = "javascript:CreateBookmarkLink()");">Add to Favorites</a>'); 
	} else  if (window.sidebar) {
		document.write('<a href = "javascript:CreateBookmarkLink()");">Bookmark Page</a>'); 
	} else if (window.opera && window.print) {	
		document.write('<a href = "javascript:CreateBookmarkLink()");">Add Bookmark</a>');
	} 
}

function preload_image(src) {
	
//	if (document.images) {
//		preload_image = new Image(); 
//		preload_image.src = 'aoeu';
//	}
}
