/*
	@package hwis
	
	written by Sven Georgi
*/

onloads.push( registerAjaxStuff );

function registerAjaxStuff() {
	/* rating */
	ajaxEngine.registerAjaxElement( 'ratingbox');
	ajaxEngine.registerRequest( 'voteReport','index.php?site=internal&action=putpoint');
	ajaxEngine.registerRequest( 'removePoint','index.php?site=internal&action=removepoint');
	/* comments */
	ajaxEngine.registerRequest( 'putComment', 'index.php?site=internal&action=putcomment');
	ajaxEngine.registerRequest( 'removeComment', 'index.php?site=internal&action=removecomment');	
	ajaxEngine.registerAjaxElement( 'reportcomments' );
	ajaxEngine.registerAjaxElement( 'comment-new' );
	ajaxEngine.registerAjaxElement( 'comment_list' );
	/* search */
	ajaxEngine.registerRequest( 'doSearch', 'index.php?site=internal&action=xmlSearch' );
	ajaxEngine.registerAjaxElement( 'search' );	
}

function voteReport(index, id){

	ajaxEngine.sendRequest('voteReport','rid=' + id,'index=' + index);
}

function removePoint(id){
	ajaxEngine.sendRequest('removePoint','rid=' + id);
}

function putComment(id){
	if (!document.getElementById("comment_list")){
		// Liste existiert noch nicht (keine Kommentare vorhanden), also erstellen
		var ol_elem = document.createElement("ol");
		ol_elem.setAttribute("id","comment_list");
		ol_elem.setAttribute("class","commentlist");
		document.getElementById("reportcomments").appendChild(ol_elem);
	}
	var comment=document.getElementById('commenttext').value;
	document.getElementById("commenttext").value = "";
	var li_elem = document.createElement("li");
	var li_text = document.createTextNode(comment);
	li_elem.setAttribute("id", "comment-new");
	li_elem.setAttribute("class","commentbody");
	//li_elem.appendChild();
	li_elem.appendChild(li_text);	
	//li_elem.innerHtml ="<p>TESThtml</p>";	
	document.getElementById("comment_list").appendChild(li_elem);
	ajaxEngine.sendRequest('putComment','rid=' + id,'comment=' + comment);
}

function removeComment(id){
	/* Eintrag aus HTML entfernen */
	  if (document.getElementById('comment-' + id))
	  {
	    document.getElementById('comment_list').removeChild(document.getElementById('comment-' + id));
	  } else {
	  	
	  }
	ajaxEngine.sendRequest('removeComment','cid=' + id);
}


/*
function disableNewCity(){
	alert('test');
}
*/
/*
var onloads = new Array();
function bodyOnLoad() {
	for ( var i = 0 ; i < onloads.length ; i++ )
	onloads[i]();
}
*/

function doSearch() {
	var text=$F('search');
	//var text=document.getElementById("search").value;
	var pars='text=' + text;
	var url ='index.php?site=internal&action=xmlSearch';
	//var pars=	
	if (text.length >= 3 ){
		//alert(text);
		var myAjax = new Ajax.Request(
			url, 
			{
				method: 'get', 
				parameters: pars, 
				onComplete: showSearch
			});
		
		//ajaxEngine.sendRequest('doSearch','text='+text);
		
		}
}

function showSearch(originalRequest)
{
	//put returned XML in the search-form
	//document.getElementById('search').value = originalRequest.responseText;
}
