var xmlHttp

function replace_html(id, content) {
	document.getElementById(id).innerHTML = content;
}

function show_progressbar(id) {
	replace_html(id, '<span class="loadbar"><img src="images/bits/loading.gif" alt="Loading, please wait..." /> Loading </span>');
}

function comment(id, type, page, submitted) {
	
	// Get the correct object for browser
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Sorry, your browser does not support AJAX.");
		return;
	} 

	// If submitted is 1 check there is a username, if not return, if so show progress bar and continue.
	if (submitted=='1'){
		var comment = document.getElementById('thecomment').value
		comment = comment.replace(/\n/g, "~*~");
		show_progressbar('comments');
	}
	
	var url="addcomment.php";
	url=url+"?i=" + id + "&t=" + type + "&c=" + comment + "&page=" + page + "&s=" + submitted;
 	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged2;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function stateChanged2() { 
	if (xmlHttp.readyState==4) { 
	document.getElementById('comments').innerHTML=xmlHttp.responseText;
	}
}


function getGall(type, page) {
	
	// Get the correct object for browser
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Sorry, your browser does not support AJAX.");
		return;
	} 
	
	// If type not passed get it from typeholder span
	if (type.length==0){
		var type2="?type=" + document.getElementById('typeholder').innerHTML;
	}else{
		var type2="?type=" + type;
	}
	
	// Load bar AFTER selecting the type from typeholder
	show_progressbar('gallery');
	
	var url="getgall.php";
	url=url+ type2 + "&l=" + document.getElementById('userlevel').value + "&p=" + document.getElementById('project').value + "&page=" + page;
 	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function stateChanged() { 
	if (xmlHttp.readyState==4) { 
	document.getElementById('gallery').innerHTML=xmlHttp.responseText;
	}
}


function flag(id, del){
	// Get the correct object for browser
	xmlHttp=GetXmlHttpObject();
	var url="flagcomment.php";
	url=url+"?id="+id+"&del="+del;
 	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=function() { 
		if (xmlHttp.readyState==4) { 
		document.getElementById(id).innerHTML=xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}



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;
}